tinybase 6.0.0-beta.1 → 6.0.0-beta.3

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 (386) hide show
  1. package/@types/_internal/queries/with-schemas/index.d.cts +6 -6
  2. package/@types/_internal/queries/with-schemas/index.d.ts +6 -6
  3. package/@types/_internal/store/with-schemas/index.d.cts +1 -1
  4. package/@types/_internal/store/with-schemas/index.d.ts +1 -1
  5. package/@types/_internal/ui-react/with-schemas/index.d.cts +13 -13
  6. package/@types/_internal/ui-react/with-schemas/index.d.ts +13 -13
  7. package/@types/checkpoints/index.d.cts +0 -1
  8. package/@types/checkpoints/index.d.ts +0 -1
  9. package/@types/checkpoints/with-schemas/index.d.cts +0 -1
  10. package/@types/checkpoints/with-schemas/index.d.ts +0 -1
  11. package/@types/indexes/index.d.cts +1 -2
  12. package/@types/indexes/index.d.ts +1 -2
  13. package/@types/indexes/with-schemas/index.d.cts +6 -7
  14. package/@types/indexes/with-schemas/index.d.ts +6 -7
  15. package/@types/mergeable-store/index.d.cts +1 -2
  16. package/@types/mergeable-store/index.d.ts +1 -2
  17. package/@types/mergeable-store/with-schemas/index.d.cts +1 -2
  18. package/@types/mergeable-store/with-schemas/index.d.ts +1 -2
  19. package/@types/metrics/index.d.cts +1 -2
  20. package/@types/metrics/index.d.ts +1 -2
  21. package/@types/metrics/with-schemas/index.d.cts +1 -2
  22. package/@types/metrics/with-schemas/index.d.ts +1 -2
  23. package/@types/persisters/index.d.cts +22 -23
  24. package/@types/persisters/index.d.ts +22 -23
  25. package/@types/persisters/persister-automerge/index.d.cts +6 -7
  26. package/@types/persisters/persister-automerge/index.d.ts +6 -7
  27. package/@types/persisters/persister-automerge/with-schemas/index.d.cts +5 -6
  28. package/@types/persisters/persister-automerge/with-schemas/index.d.ts +5 -6
  29. package/@types/persisters/persister-browser/index.d.cts +5 -6
  30. package/@types/persisters/persister-browser/index.d.ts +5 -6
  31. package/@types/persisters/persister-browser/with-schemas/index.d.cts +5 -6
  32. package/@types/persisters/persister-browser/with-schemas/index.d.ts +5 -6
  33. package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +7 -8
  34. package/@types/persisters/persister-cr-sqlite-wasm/index.d.ts +7 -8
  35. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +10 -11
  36. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.ts +10 -11
  37. package/@types/persisters/persister-durable-object-storage/index.d.cts +5 -6
  38. package/@types/persisters/persister-durable-object-storage/index.d.ts +5 -6
  39. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +5 -6
  40. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.ts +5 -6
  41. package/@types/persisters/persister-electric-sql/index.d.cts +7 -8
  42. package/@types/persisters/persister-electric-sql/index.d.ts +7 -8
  43. package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +10 -11
  44. package/@types/persisters/persister-electric-sql/with-schemas/index.d.ts +10 -11
  45. package/@types/persisters/persister-expo-sqlite/index.d.cts +8 -9
  46. package/@types/persisters/persister-expo-sqlite/index.d.ts +8 -9
  47. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +11 -12
  48. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.ts +11 -12
  49. package/@types/persisters/persister-file/index.d.cts +3 -4
  50. package/@types/persisters/persister-file/index.d.ts +3 -4
  51. package/@types/persisters/persister-file/with-schemas/index.d.cts +3 -4
  52. package/@types/persisters/persister-file/with-schemas/index.d.ts +3 -4
  53. package/@types/persisters/persister-indexed-db/index.d.cts +3 -4
  54. package/@types/persisters/persister-indexed-db/index.d.ts +3 -4
  55. package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +2 -3
  56. package/@types/persisters/persister-indexed-db/with-schemas/index.d.ts +2 -3
  57. package/@types/persisters/persister-libsql/index.d.cts +4 -5
  58. package/@types/persisters/persister-libsql/index.d.ts +4 -5
  59. package/@types/persisters/persister-libsql/with-schemas/index.d.cts +7 -8
  60. package/@types/persisters/persister-libsql/with-schemas/index.d.ts +7 -8
  61. package/@types/persisters/persister-partykit-client/index.d.cts +4 -5
  62. package/@types/persisters/persister-partykit-client/index.d.ts +4 -5
  63. package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +3 -4
  64. package/@types/persisters/persister-partykit-client/with-schemas/index.d.ts +3 -4
  65. package/@types/persisters/persister-partykit-server/index.d.cts +1 -2
  66. package/@types/persisters/persister-partykit-server/index.d.ts +1 -2
  67. package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +1 -2
  68. package/@types/persisters/persister-partykit-server/with-schemas/index.d.ts +1 -2
  69. package/@types/persisters/persister-pglite/index.d.cts +5 -6
  70. package/@types/persisters/persister-pglite/index.d.ts +5 -6
  71. package/@types/persisters/persister-pglite/with-schemas/index.d.cts +8 -9
  72. package/@types/persisters/persister-pglite/with-schemas/index.d.ts +8 -9
  73. package/@types/persisters/persister-postgres/index.d.cts +8 -9
  74. package/@types/persisters/persister-postgres/index.d.ts +8 -9
  75. package/@types/persisters/persister-postgres/with-schemas/index.d.cts +11 -12
  76. package/@types/persisters/persister-postgres/with-schemas/index.d.ts +11 -12
  77. package/@types/persisters/persister-powersync/index.d.cts +7 -8
  78. package/@types/persisters/persister-powersync/index.d.ts +7 -8
  79. package/@types/persisters/persister-powersync/with-schemas/index.d.cts +10 -11
  80. package/@types/persisters/persister-powersync/with-schemas/index.d.ts +10 -11
  81. package/@types/persisters/persister-remote/index.d.cts +3 -4
  82. package/@types/persisters/persister-remote/index.d.ts +3 -4
  83. package/@types/persisters/persister-remote/with-schemas/index.d.cts +2 -3
  84. package/@types/persisters/persister-remote/with-schemas/index.d.ts +2 -3
  85. package/@types/persisters/persister-sqlite-wasm/index.d.cts +7 -8
  86. package/@types/persisters/persister-sqlite-wasm/index.d.ts +7 -8
  87. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +11 -12
  88. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.ts +11 -12
  89. package/@types/persisters/persister-sqlite3/index.d.cts +5 -6
  90. package/@types/persisters/persister-sqlite3/index.d.ts +5 -6
  91. package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +8 -9
  92. package/@types/persisters/persister-sqlite3/with-schemas/index.d.ts +8 -9
  93. package/@types/persisters/persister-yjs/index.d.cts +4 -5
  94. package/@types/persisters/persister-yjs/index.d.ts +4 -5
  95. package/@types/persisters/persister-yjs/with-schemas/index.d.cts +3 -4
  96. package/@types/persisters/persister-yjs/with-schemas/index.d.ts +3 -4
  97. package/@types/persisters/with-schemas/index.d.cts +26 -27
  98. package/@types/persisters/with-schemas/index.d.ts +26 -27
  99. package/@types/queries/index.d.cts +1 -2
  100. package/@types/queries/index.d.ts +1 -2
  101. package/@types/queries/with-schemas/index.d.cts +10 -11
  102. package/@types/queries/with-schemas/index.d.ts +10 -11
  103. package/@types/relationships/index.d.cts +25 -2
  104. package/@types/relationships/index.d.ts +25 -2
  105. package/@types/relationships/with-schemas/index.d.cts +25 -2
  106. package/@types/relationships/with-schemas/index.d.ts +25 -2
  107. package/@types/store/index.d.cts +1 -2
  108. package/@types/store/index.d.ts +1 -2
  109. package/@types/store/with-schemas/index.d.cts +0 -1
  110. package/@types/store/with-schemas/index.d.ts +0 -1
  111. package/@types/synchronizers/index.d.cts +6 -7
  112. package/@types/synchronizers/index.d.ts +6 -7
  113. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +3 -4
  114. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.ts +3 -4
  115. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +3 -4
  116. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.ts +3 -4
  117. package/@types/synchronizers/synchronizer-local/index.d.cts +2 -3
  118. package/@types/synchronizers/synchronizer-local/index.d.ts +2 -3
  119. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +2 -3
  120. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.ts +2 -3
  121. package/@types/synchronizers/synchronizer-ws-client/index.d.cts +5 -6
  122. package/@types/synchronizers/synchronizer-ws-client/index.d.ts +5 -6
  123. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +5 -6
  124. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +5 -6
  125. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +30 -32
  126. package/@types/synchronizers/synchronizer-ws-server/index.d.ts +30 -32
  127. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +34 -36
  128. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +34 -36
  129. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +2 -3
  130. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +2 -3
  131. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +6 -7
  132. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +6 -7
  133. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.cts +4 -5
  134. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.ts +4 -5
  135. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.cts +4 -5
  136. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.ts +4 -5
  137. package/@types/synchronizers/with-schemas/index.d.cts +10 -11
  138. package/@types/synchronizers/with-schemas/index.d.ts +10 -11
  139. package/@types/ui-react/index.d.cts +489 -490
  140. package/@types/ui-react/index.d.ts +489 -490
  141. package/@types/ui-react/with-schemas/index.d.cts +494 -495
  142. package/@types/ui-react/with-schemas/index.d.ts +494 -495
  143. package/@types/ui-react-dom/index.d.cts +39 -40
  144. package/@types/ui-react-dom/index.d.ts +39 -40
  145. package/@types/ui-react-dom/with-schemas/index.d.cts +39 -40
  146. package/@types/ui-react-dom/with-schemas/index.d.ts +39 -40
  147. package/@types/ui-react-inspector/index.d.cts +2 -3
  148. package/@types/ui-react-inspector/index.d.ts +2 -3
  149. package/@types/ui-react-inspector/with-schemas/index.d.cts +41 -42
  150. package/@types/ui-react-inspector/with-schemas/index.d.ts +41 -42
  151. package/checkpoints/index.js +9 -9
  152. package/checkpoints/with-schemas/index.js +9 -9
  153. package/index.js +110 -110
  154. package/indexes/index.js +3 -3
  155. package/indexes/with-schemas/index.js +3 -3
  156. package/mergeable-store/index.js +150 -150
  157. package/mergeable-store/with-schemas/index.js +150 -150
  158. package/metrics/index.js +3 -3
  159. package/metrics/with-schemas/index.js +3 -3
  160. package/min/checkpoints/index.js +1 -1
  161. package/min/checkpoints/index.js.gz +0 -0
  162. package/min/checkpoints/with-schemas/index.js +1 -1
  163. package/min/checkpoints/with-schemas/index.js.gz +0 -0
  164. package/min/index.js +1 -1
  165. package/min/index.js.gz +0 -0
  166. package/min/indexes/index.js +1 -1
  167. package/min/indexes/index.js.gz +0 -0
  168. package/min/indexes/with-schemas/index.js +1 -1
  169. package/min/indexes/with-schemas/index.js.gz +0 -0
  170. package/min/mergeable-store/index.js +1 -1
  171. package/min/mergeable-store/index.js.gz +0 -0
  172. package/min/mergeable-store/with-schemas/index.js +1 -1
  173. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  174. package/min/metrics/index.js +1 -1
  175. package/min/metrics/index.js.gz +0 -0
  176. package/min/metrics/with-schemas/index.js +1 -1
  177. package/min/metrics/with-schemas/index.js.gz +0 -0
  178. package/min/persisters/index.js +1 -1
  179. package/min/persisters/index.js.gz +0 -0
  180. package/min/persisters/persister-automerge/index.js +1 -1
  181. package/min/persisters/persister-automerge/index.js.gz +0 -0
  182. package/min/persisters/persister-automerge/with-schemas/index.js +1 -1
  183. package/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
  184. package/min/persisters/persister-browser/index.js +1 -1
  185. package/min/persisters/persister-browser/index.js.gz +0 -0
  186. package/min/persisters/persister-browser/with-schemas/index.js +1 -1
  187. package/min/persisters/persister-browser/with-schemas/index.js.gz +0 -0
  188. package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
  189. package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
  190. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
  191. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
  192. package/min/persisters/persister-durable-object-storage/index.js +1 -1
  193. package/min/persisters/persister-durable-object-storage/index.js.gz +0 -0
  194. package/min/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
  195. package/min/persisters/persister-durable-object-storage/with-schemas/index.js.gz +0 -0
  196. package/min/persisters/persister-electric-sql/index.js +1 -1
  197. package/min/persisters/persister-electric-sql/index.js.gz +0 -0
  198. package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
  199. package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
  200. package/min/persisters/persister-expo-sqlite/index.js +1 -1
  201. package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
  202. package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
  203. package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
  204. package/min/persisters/persister-file/index.js +1 -1
  205. package/min/persisters/persister-file/index.js.gz +0 -0
  206. package/min/persisters/persister-file/with-schemas/index.js +1 -1
  207. package/min/persisters/persister-file/with-schemas/index.js.gz +0 -0
  208. package/min/persisters/persister-indexed-db/index.js +1 -1
  209. package/min/persisters/persister-indexed-db/index.js.gz +0 -0
  210. package/min/persisters/persister-indexed-db/with-schemas/index.js +1 -1
  211. package/min/persisters/persister-indexed-db/with-schemas/index.js.gz +0 -0
  212. package/min/persisters/persister-libsql/index.js +1 -1
  213. package/min/persisters/persister-libsql/index.js.gz +0 -0
  214. package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
  215. package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
  216. package/min/persisters/persister-partykit-client/index.js +1 -1
  217. package/min/persisters/persister-partykit-client/index.js.gz +0 -0
  218. package/min/persisters/persister-partykit-client/with-schemas/index.js +1 -1
  219. package/min/persisters/persister-partykit-client/with-schemas/index.js.gz +0 -0
  220. package/min/persisters/persister-partykit-server/index.js +1 -1
  221. package/min/persisters/persister-partykit-server/index.js.gz +0 -0
  222. package/min/persisters/persister-partykit-server/with-schemas/index.js +1 -1
  223. package/min/persisters/persister-partykit-server/with-schemas/index.js.gz +0 -0
  224. package/min/persisters/persister-pglite/index.js +1 -1
  225. package/min/persisters/persister-pglite/index.js.gz +0 -0
  226. package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
  227. package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
  228. package/min/persisters/persister-postgres/index.js +1 -1
  229. package/min/persisters/persister-postgres/index.js.gz +0 -0
  230. package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
  231. package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
  232. package/min/persisters/persister-powersync/index.js +1 -1
  233. package/min/persisters/persister-powersync/index.js.gz +0 -0
  234. package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
  235. package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
  236. package/min/persisters/persister-remote/index.js +1 -1
  237. package/min/persisters/persister-remote/index.js.gz +0 -0
  238. package/min/persisters/persister-remote/with-schemas/index.js +1 -1
  239. package/min/persisters/persister-remote/with-schemas/index.js.gz +0 -0
  240. package/min/persisters/persister-sqlite-wasm/index.js +1 -1
  241. package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
  242. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
  243. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
  244. package/min/persisters/persister-sqlite3/index.js +1 -1
  245. package/min/persisters/persister-sqlite3/index.js.gz +0 -0
  246. package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
  247. package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
  248. package/min/persisters/persister-yjs/index.js +1 -1
  249. package/min/persisters/persister-yjs/index.js.gz +0 -0
  250. package/min/persisters/persister-yjs/with-schemas/index.js +1 -1
  251. package/min/persisters/persister-yjs/with-schemas/index.js.gz +0 -0
  252. package/min/persisters/with-schemas/index.js +1 -1
  253. package/min/persisters/with-schemas/index.js.gz +0 -0
  254. package/min/queries/index.js +1 -1
  255. package/min/queries/index.js.gz +0 -0
  256. package/min/queries/with-schemas/index.js +1 -1
  257. package/min/queries/with-schemas/index.js.gz +0 -0
  258. package/min/relationships/index.js +1 -1
  259. package/min/relationships/index.js.gz +0 -0
  260. package/min/relationships/with-schemas/index.js +1 -1
  261. package/min/relationships/with-schemas/index.js.gz +0 -0
  262. package/min/store/index.js +1 -1
  263. package/min/store/index.js.gz +0 -0
  264. package/min/store/with-schemas/index.js +1 -1
  265. package/min/store/with-schemas/index.js.gz +0 -0
  266. package/min/synchronizers/index.js +1 -1
  267. package/min/synchronizers/index.js.gz +0 -0
  268. package/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -1
  269. package/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
  270. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -1
  271. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
  272. package/min/synchronizers/synchronizer-local/index.js +1 -1
  273. package/min/synchronizers/synchronizer-local/index.js.gz +0 -0
  274. package/min/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
  275. package/min/synchronizers/synchronizer-local/with-schemas/index.js.gz +0 -0
  276. package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  277. package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  278. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  279. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  280. package/min/synchronizers/synchronizer-ws-server/index.js +1 -1
  281. package/min/synchronizers/synchronizer-ws-server/index.js.gz +0 -0
  282. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
  283. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js.gz +0 -0
  284. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
  285. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  286. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
  287. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  288. package/min/synchronizers/synchronizer-ws-server-simple/index.js +1 -1
  289. package/min/synchronizers/synchronizer-ws-server-simple/index.js.gz +0 -0
  290. package/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +1 -1
  291. package/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js.gz +0 -0
  292. package/min/synchronizers/with-schemas/index.js +1 -1
  293. package/min/synchronizers/with-schemas/index.js.gz +0 -0
  294. package/min/ui-react/index.js +1 -1
  295. package/min/ui-react/index.js.gz +0 -0
  296. package/min/ui-react/with-schemas/index.js +1 -1
  297. package/min/ui-react/with-schemas/index.js.gz +0 -0
  298. package/min/ui-react-dom/index.js +1 -1
  299. package/min/ui-react-dom/index.js.gz +0 -0
  300. package/min/ui-react-dom/with-schemas/index.js +1 -1
  301. package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
  302. package/min/ui-react-inspector/index.js +1 -1
  303. package/min/ui-react-inspector/index.js.gz +0 -0
  304. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  305. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  306. package/min/with-schemas/index.js +1 -1
  307. package/min/with-schemas/index.js.gz +0 -0
  308. package/package.json +4 -44
  309. package/persisters/index.js +120 -120
  310. package/persisters/persister-automerge/index.js +8 -8
  311. package/persisters/persister-automerge/with-schemas/index.js +8 -8
  312. package/persisters/persister-browser/index.js +8 -8
  313. package/persisters/persister-browser/with-schemas/index.js +8 -8
  314. package/persisters/persister-cr-sqlite-wasm/index.js +119 -119
  315. package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +119 -119
  316. package/persisters/persister-durable-object-storage/index.js +12 -12
  317. package/persisters/persister-durable-object-storage/with-schemas/index.js +12 -12
  318. package/persisters/persister-electric-sql/index.js +119 -119
  319. package/persisters/persister-electric-sql/with-schemas/index.js +119 -119
  320. package/persisters/persister-expo-sqlite/index.js +119 -119
  321. package/persisters/persister-expo-sqlite/with-schemas/index.js +119 -119
  322. package/persisters/persister-file/index.js +10 -10
  323. package/persisters/persister-file/with-schemas/index.js +10 -10
  324. package/persisters/persister-indexed-db/index.js +8 -8
  325. package/persisters/persister-indexed-db/with-schemas/index.js +8 -8
  326. package/persisters/persister-libsql/index.js +119 -119
  327. package/persisters/persister-libsql/with-schemas/index.js +119 -119
  328. package/persisters/persister-partykit-client/index.js +23 -23
  329. package/persisters/persister-partykit-client/with-schemas/index.js +23 -23
  330. package/persisters/persister-partykit-server/index.js +13 -9
  331. package/persisters/persister-partykit-server/with-schemas/index.js +13 -9
  332. package/persisters/persister-pglite/index.js +128 -128
  333. package/persisters/persister-pglite/with-schemas/index.js +128 -128
  334. package/persisters/persister-postgres/index.js +128 -128
  335. package/persisters/persister-postgres/with-schemas/index.js +128 -128
  336. package/persisters/persister-powersync/index.js +119 -119
  337. package/persisters/persister-powersync/with-schemas/index.js +119 -119
  338. package/persisters/persister-remote/index.js +8 -8
  339. package/persisters/persister-remote/with-schemas/index.js +8 -8
  340. package/persisters/persister-sqlite-wasm/index.js +119 -119
  341. package/persisters/persister-sqlite-wasm/with-schemas/index.js +119 -119
  342. package/persisters/persister-sqlite3/index.js +119 -119
  343. package/persisters/persister-sqlite3/with-schemas/index.js +119 -119
  344. package/persisters/persister-yjs/index.js +14 -14
  345. package/persisters/persister-yjs/with-schemas/index.js +14 -14
  346. package/persisters/with-schemas/index.js +120 -120
  347. package/queries/index.js +16 -16
  348. package/queries/with-schemas/index.js +16 -16
  349. package/readme.md +3 -22
  350. package/relationships/index.js +3 -3
  351. package/relationships/with-schemas/index.js +3 -3
  352. package/releases.md +6 -6
  353. package/store/index.js +43 -43
  354. package/store/with-schemas/index.js +43 -43
  355. package/synchronizers/index.js +31 -31
  356. package/synchronizers/synchronizer-broadcast-channel/index.js +31 -31
  357. package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +31 -31
  358. package/synchronizers/synchronizer-local/index.js +31 -31
  359. package/synchronizers/synchronizer-local/with-schemas/index.js +31 -31
  360. package/synchronizers/synchronizer-ws-client/index.js +25 -25
  361. package/synchronizers/synchronizer-ws-client/with-schemas/index.js +25 -25
  362. package/synchronizers/synchronizer-ws-server/index.js +65 -65
  363. package/synchronizers/synchronizer-ws-server/with-schemas/index.js +65 -65
  364. package/synchronizers/synchronizer-ws-server-durable-object/index.js +25 -25
  365. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +25 -25
  366. package/synchronizers/synchronizer-ws-server-simple/index.js +3 -3
  367. package/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +3 -3
  368. package/synchronizers/with-schemas/index.js +31 -31
  369. package/ui-react/index.js +31 -34
  370. package/ui-react/with-schemas/index.js +31 -34
  371. package/ui-react-dom/index.js +24 -24
  372. package/ui-react-dom/with-schemas/index.js +24 -24
  373. package/ui-react-inspector/index.js +3066 -3067
  374. package/ui-react-inspector/with-schemas/index.js +3066 -3067
  375. package/with-schemas/index.js +110 -110
  376. package/@types/tools/index.d.cts +0 -588
  377. package/@types/tools/index.d.ts +0 -588
  378. package/@types/tools/with-schemas/index.d.cts +0 -599
  379. package/@types/tools/with-schemas/index.d.ts +0 -599
  380. package/cli/index.js +0 -93
  381. package/min/tools/index.js +0 -1
  382. package/min/tools/index.js.gz +0 -0
  383. package/min/tools/with-schemas/index.js +0 -1
  384. package/min/tools/with-schemas/index.js.gz +0 -0
  385. package/tools/index.js +0 -3301
  386. package/tools/with-schemas/index.js +0 -3301
@@ -1,3301 +0,0 @@
1
- const getTypeOf = (thing) => typeof thing;
2
- const TINYBASE = 'tinybase';
3
- const EMPTY_STRING = '';
4
- const COMMA = ',';
5
- const STRING = getTypeOf(EMPTY_STRING);
6
- const BOOLEAN = getTypeOf(true);
7
- const NUMBER = getTypeOf(0);
8
- const TYPE = 'type';
9
- const DEFAULT = 'default';
10
- const LISTENER = 'Listener';
11
- const GET = 'get';
12
- const ADD = 'add';
13
- const HAS = 'Has';
14
- const IDS = 'Ids';
15
- const TABLE = 'Table';
16
- const TABLES = TABLE + 's';
17
- const TABLE_IDS = TABLE + IDS;
18
- const ROW = 'Row';
19
- const ROW_IDS = ROW + IDS;
20
- const SORTED_ROW_IDS = 'Sorted' + ROW + IDS;
21
- const CELL = 'Cell';
22
- const CELL_IDS = CELL + IDS;
23
- const VALUE = 'Value';
24
- const VALUES = VALUE + 's';
25
- const VALUE_IDS = VALUE + IDS;
26
- const TRANSACTION = 'Transaction';
27
- const PARTIAL = 'Partial';
28
- const strSplit = (str, separator = EMPTY_STRING, limit) =>
29
- str.split(separator, limit);
30
-
31
- const promise = Promise;
32
- const isFiniteNumber = isFinite;
33
- const isUndefined = (thing) => thing == void 0;
34
- const ifNotUndefined = (value, then, otherwise) =>
35
- isUndefined(value) ? otherwise?.() : then(value);
36
- const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
37
- const isString = (thing) => getTypeOf(thing) == STRING;
38
- const isArray = (thing) => Array.isArray(thing);
39
- const slice = (arrayOrString, start, end) => arrayOrString.slice(start, end);
40
- const size = (arrayOrString) => arrayOrString.length;
41
- const promiseAll = async (promises) => promise.all(promises);
42
-
43
- const getCellOrValueType = (cellOrValue) => {
44
- const type = getTypeOf(cellOrValue);
45
- return isTypeStringOrBoolean(type) ||
46
- (type == NUMBER && isFiniteNumber(cellOrValue))
47
- ? type
48
- : void 0;
49
- };
50
-
51
- const arrayEvery = (array, cb) => array.every(cb);
52
- const arraySort = (array, sorter) => array.sort(sorter);
53
- const arrayForEach = (array, cb) => array.forEach(cb);
54
- const arrayJoin = (array, sep = EMPTY_STRING) => array.join(sep);
55
- const arrayMap = (array, cb) => array.map(cb);
56
- const arrayFilter = (array, cb) => array.filter(cb);
57
- const arrayPush = (array, ...values) => array.push(...values);
58
- const arrayPop = (array) => array.pop();
59
- const arrayUnshift = (array, ...values) => array.unshift(...values);
60
- const arrayShift = (array) => array.shift();
61
-
62
- const object = Object;
63
- const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
64
- const objEntries = object.entries;
65
- const isObject = (obj) =>
66
- !isUndefined(obj) &&
67
- ifNotUndefined(
68
- getPrototypeOf(obj),
69
- (objPrototype) =>
70
- objPrototype == object.prototype ||
71
- isUndefined(getPrototypeOf(objPrototype)),
72
-
73
- /* istanbul ignore next */
74
- () => true,
75
- );
76
- const objIds = object.keys;
77
- const objFreeze = object.freeze;
78
- const objToArray = (obj, cb) =>
79
- arrayMap(objEntries(obj), ([id, value]) => cb(value, id));
80
- const objSize = (obj) => size(objIds(obj));
81
- const objIsEmpty = (obj) => isObject(obj) && objSize(obj) == 0;
82
-
83
- const collHas = (coll, keyOrValue) => coll?.has(keyOrValue) ?? false;
84
- const collValues = (coll) => [...(coll?.values() ?? [])];
85
- const collForEach = (coll, cb) => coll?.forEach(cb);
86
- const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
87
-
88
- const mapNew = (entries) => new Map(entries);
89
- const mapGet = (map, key) => map?.get(key);
90
- const mapForEach = (map, cb) =>
91
- collForEach(map, (value, key) => cb(key, value));
92
- const mapMap = (coll, cb) =>
93
- arrayMap([...(coll?.entries() ?? [])], ([key, value]) => cb(value, key));
94
- const mapSet = (map, key, value) =>
95
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
96
- const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
97
- if (!collHas(map, key)) {
98
- mapSet(map, key, getDefaultValue());
99
- }
100
- return mapGet(map, key);
101
- };
102
-
103
- const upper = (str) => str.toUpperCase();
104
- const lower = (str) => str.toLowerCase();
105
- const A = 'a ';
106
- const A_FUNCTION_FOR = 'A function for';
107
- const AND_REGISTERS =
108
- ', and registers a listener so that any changes to that result will cause a re-render';
109
- const CALLBACK = 'Callback';
110
- const CHANGES = 'Changes';
111
- const COUNT = 'Count';
112
- const DEL = 'Del';
113
- const DEPS = 'Deps';
114
- const DEPS_SUFFIX = DEPS + '?: React.DependencyList';
115
- const DO_ROLLBACK_PARAM = 'doRollback?: DoRollback';
116
- const DO_ACTIONS_AND_ROLLBACK_PARAMS =
117
- 'actions: () => Return, ' + DO_ROLLBACK_PARAM;
118
- const EXPORT = 'export';
119
- const ID = 'Id';
120
- const INVALID = 'Invalid';
121
- const JSON$1 = 'Json';
122
- const LISTENER_ = lower(LISTENER);
123
- const OPTIONAL_COLON = '?: ';
124
- const OR_UNDEFINED = ' | undefined';
125
- const NON_NULLABLE = 'NonNullable';
126
- const PROPS = 'Props';
127
- const PROVIDER = 'Provider';
128
- const REGISTERS_A_LISTENER = `Registers a ${LISTENER_} that will be called`;
129
- const REPRESENTS = 'Represents';
130
- const ROW_ID_PARAM = 'rowId: ' + ID;
131
- const SCHEMA = 'Schema';
132
- const SET = 'Set';
133
- const SORTED_ARGS = ', descending?: boolean, offset?: number, limit?: number';
134
- const SQUARE_BRACKETS = '[]';
135
- const THE_STORE = 'the Store';
136
- const TRANSACTION_ = lower(TRANSACTION);
137
- const TRANSACTION_DOC =
138
- 'Execute a ' + TRANSACTION_ + ' to make multiple mutations';
139
- const START_TRANSACTION_DOC = 'Explicitly starts a ' + TRANSACTION_;
140
- const FINISH_TRANSACTION_DOC = 'Explicitly finishes a ' + TRANSACTION_;
141
- const THE_END_OF_THE_TRANSACTION = 'the end of the ' + TRANSACTION_;
142
- const VOID = 'void';
143
- const RETURNS_VOID = ' => ' + VOID;
144
- const WHEN_SET = 'WhenSet';
145
- const WHEN_SETTING_IT = ' when setting it';
146
- const A_STRING_SERIALIZATION_OF = A + 'string serialization of';
147
- const SPACE = ' ';
148
- const GETS_A_CALLBACK_THAT_CAN = 'Gets a callback that can ';
149
- const THE = 'the ';
150
- const THE_SCHEMA_FOR = ' the schema for';
151
- const getHasDoc = (has = 0) => (has ? 'the existence of ' : '');
152
- const getTheContentOfDoc = (content = 0, theStore = 0, has = 0) =>
153
- getHasDoc(has) +
154
- `the ${CONTENT[content]}content of` +
155
- (theStore ? SPACE + THE_STORE : EMPTY_STRING);
156
- const getTheContentOfTheStoreDoc = (content = 0, verb, set = 0, has = 0) =>
157
- VERBS[verb] +
158
- SPACE +
159
- getHasDoc(has) +
160
- getTheContentOfDoc(content, 1) +
161
- (set ? ' when setting it' : EMPTY_STRING);
162
- const getRowTypeDoc = (tableId, set = 0) =>
163
- REPRESENTS +
164
- ` a Row when ${set ? 's' : 'g'}etting ${getTheContentOfDoc()} the '${tableId}' ` +
165
- TABLE;
166
- const getIdsDoc = (idsNoun, parentNoun, sorted = 0) =>
167
- `Gets ${sorted ? 'sorted, paginated' : 'the'} Ids of the ${idsNoun}s in ` +
168
- parentNoun;
169
- const getForEachDoc = (childNoun, parentNoun) =>
170
- `Calls a function for each ${childNoun} in ` + parentNoun;
171
- const getPropsDoc = (childNoun) =>
172
- 'The props passed to a component that renders ' + childNoun;
173
- const getCallbackDoc = (takes) => 'A function that takes ' + takes;
174
- const getListenerTypeDoc = (childNoun, parentNoun = 0, has = 0) =>
175
- A_FUNCTION_FOR +
176
- ' listening to changes to ' +
177
- getHasDoc(has) +
178
- NOUNS[childNoun] +
179
- ' in ' +
180
- NOUNS[parentNoun];
181
- const getListenerDoc = (childNoun, parentNoun, pluralChild = 0, has = 0) =>
182
- REGISTERS_A_LISTENER +
183
- ' whenever ' +
184
- getHasDoc(has) +
185
- NOUNS[childNoun] +
186
- ' in ' +
187
- NOUNS[parentNoun] +
188
- ' change' +
189
- (pluralChild ? EMPTY_STRING : 's');
190
- const getTableDoc = (tableId) => `the '${tableId}' ` + TABLE;
191
- const getRowDoc = (tableId) => 'the specified Row in ' + getTableDoc(tableId);
192
- const getTableContentDoc = (tableId, verb = 0, has = 0) =>
193
- VERBS[verb] +
194
- SPACE +
195
- getTheContentOfDoc(0, 0, has) +
196
- SPACE +
197
- getTableDoc(tableId);
198
- const getRowContentDoc = (tableId, verb = 0, has = 0) =>
199
- VERBS[verb] + ` ${getTheContentOfDoc(0, 0, has)} ` + getRowDoc(tableId);
200
- const getCellContentDoc = (tableId, cellId, verb = 0, has = 0) =>
201
- VERBS[verb] +
202
- SPACE +
203
- getHasDoc(has) +
204
- `the '${cellId}' Cell for ` +
205
- getRowDoc(tableId);
206
- const getValueContentDoc = (valueId, verb = 0, has = 0) =>
207
- VERBS[verb] + SPACE + getHasDoc(has) + `the '${valueId}' Value`;
208
- const VERBS = [
209
- 'Gets',
210
- 'Checks existence of',
211
- 'Sets',
212
- 'Deletes',
213
- 'Sets part of',
214
- REPRESENTS,
215
- 'Gets ' + A_STRING_SERIALIZATION_OF,
216
- 'Sets ' + A_STRING_SERIALIZATION_OF,
217
- REGISTERS_A_LISTENER + ' whenever',
218
- GETS_A_CALLBACK_THAT_CAN + 'set',
219
- GETS_A_CALLBACK_THAT_CAN + 'add',
220
- GETS_A_CALLBACK_THAT_CAN + 'set part of',
221
- GETS_A_CALLBACK_THAT_CAN + 'delete',
222
- 'Renders',
223
- 'Gets ' + A_STRING_SERIALIZATION_OF + THE_SCHEMA_FOR,
224
- 'Sets' + THE_SCHEMA_FOR,
225
- 'Deletes' + THE_SCHEMA_FOR,
226
- ];
227
- const METHOD_PREFIX_VERBS = [
228
- GET,
229
- 'has',
230
- 'set',
231
- 'del',
232
- 'set',
233
- // partial
234
- 'forEach',
235
- ADD,
236
- EMPTY_STRING,
237
- ];
238
- const NOUNS = [
239
- THE_STORE,
240
- TABLES,
241
- THE + TABLE + SPACE + IDS,
242
- A + TABLE,
243
- THE + ROW + SPACE + IDS,
244
- A + ROW,
245
- THE + CELL + SPACE + IDS,
246
- A + CELL,
247
- 'invalid Cell changes',
248
- VALUES,
249
- THE + VALUE + SPACE + IDS,
250
- A + VALUE,
251
- 'invalid Value changes',
252
- THE + 'sorted ' + ROW + SPACE + IDS,
253
- THE + CELL + SPACE + IDS + ' anywhere',
254
- THE + 'number of Rows',
255
- A + CELL + ' anywhere',
256
- ];
257
- const CONTENT = [EMPTY_STRING, 'tabular ', 'keyed value '];
258
-
259
- const setNew = (entryOrEntries) =>
260
- new Set(
261
- isArray(entryOrEntries) || isUndefined(entryOrEntries)
262
- ? entryOrEntries
263
- : [entryOrEntries],
264
- );
265
- const setAdd = (set, value) => set?.add(value);
266
-
267
- const NON_ALPHA = /[^A-Za-z]+/;
268
- const NON_ALPHANUMERIC = /[^A-Za-z0-9]+/;
269
- const JSDOC = /^( *)\/\*\* *(.*?) *\*\/$/gm;
270
- const stringHasComma = (str) => str.includes(COMMA);
271
- const mapUnique = (map, id, value, index = 1) => {
272
- const uniqueId = `${id}${index == 1 ? '' : index}`;
273
- if (collHas(map, uniqueId)) {
274
- return mapUnique(map, id, value, index + 1);
275
- } else {
276
- mapSet(map, uniqueId, value);
277
- return uniqueId;
278
- }
279
- };
280
- const formatJsDoc = (file) =>
281
- file.replace(JSDOC, (_, indent, text) => {
282
- const lineLength = 77 - size(indent);
283
- return `${indent}/**
284
- ${text.replace(
285
- new RegExp(`([^\\n]{1,${lineLength}})(\\s|$)`, 'g'),
286
- `${indent} * $1
287
- `,
288
- )}${indent} */`;
289
- });
290
- const flat = (array) => array.flat(1e3);
291
- const camel = (str, firstCap = 0) =>
292
- arrayJoin(
293
- arrayMap(
294
- strSplit(str, NON_ALPHANUMERIC),
295
- (word, w) =>
296
- (w > 0 || firstCap ? upper : lower)(slice(word, 0, 1)) + slice(word, 1),
297
- ),
298
- );
299
- const snake = (str) =>
300
- upper(
301
- arrayJoin(
302
- strSplit(
303
- str && !NON_ALPHA.test(str[0]) ? str : ' ' + str,
304
- NON_ALPHANUMERIC,
305
- ),
306
- '_',
307
- ),
308
- );
309
- const comment = (doc) => `/** ${doc}. */`;
310
- const getParameterList = (...params) =>
311
- arrayJoin(
312
- arrayFilter(params, (param) => param),
313
- ', ',
314
- );
315
- const getFieldTypeList = (...props) => '{' + arrayJoin(props, '; ') + '}';
316
- const getPropTypeList = (...props) =>
317
- getFieldTypeList(...arrayMap(props, (prop) => 'readonly ' + prop));
318
- const getCodeFunctions = () => {
319
- const allImports = [mapNew(), mapNew(), mapNew(), mapNew()];
320
- const types = mapNew();
321
- const constants = mapNew();
322
- const build = (...lines) => arrayJoin(flat(lines), '\n');
323
- const addImport = (location, source, ...items) =>
324
- arrayForEach(items, (item) =>
325
- arrayForEach([0, 1], (eachLocation) =>
326
- (location ?? eachLocation) == eachLocation
327
- ? setAdd(mapEnsure(allImports[eachLocation], source, setNew), item)
328
- : 0,
329
- ),
330
- );
331
- const addType = (name, body, doc, generic = EMPTY_STRING, exported = 1) =>
332
- mapUnique(types, name, [body, doc, generic, exported]);
333
- const addInternalFunction = (name, parameters, body) =>
334
- mapUnique(
335
- constants,
336
- name,
337
- isArray(body)
338
- ? [`(${parameters}) => {`, body, '}']
339
- : [`(${parameters}) => ${body}`],
340
- );
341
- const addConstant = (name, body) =>
342
- mapGet(constants, name) === body ? name : mapUnique(constants, name, body);
343
- const getSortableImport = (importMaybeAs) => {
344
- const as = importMaybeAs.indexOf(' as ');
345
- return as != -1 ? slice(importMaybeAs, as + 4) : importMaybeAs;
346
- };
347
- const getImports = (location = 0) =>
348
- arrayMap(
349
- [
350
- ...arraySort(
351
- mapMap(
352
- allImports[location],
353
- (items, source) =>
354
- `import {${arrayJoin(
355
- arraySort(collValues(items), (import1, import2) =>
356
- getSortableImport(import1) > getSortableImport(import2)
357
- ? 1
358
- : -1,
359
- ),
360
- ', ',
361
- )}} from '${source}';`,
362
- ),
363
- (import1, import2) =>
364
- stringHasComma(import1) != stringHasComma(import2)
365
- ? stringHasComma(import1)
366
- ? -1
367
- : 1
368
- : import1 > import2
369
- ? 1
370
- : -1,
371
- ),
372
- EMPTY_STRING,
373
- ],
374
- (line) => line.replace('{React}', 'React'),
375
- // sigh
376
- );
377
- const getTypes = () =>
378
- mapMap(types, ([body, doc, generic, exported], name) => [
379
- comment(doc),
380
- `${exported ? EXPORT + ' ' : EMPTY_STRING}type ${name}${generic} = ${body};`,
381
- EMPTY_STRING,
382
- ]);
383
- const getConstants = () =>
384
- mapMap(constants, (body, name) => {
385
- body = isArray(body) ? body : [body];
386
- arrayPush(body, `${arrayPop(body)};`);
387
- return [`const ${name} = ${arrayShift(body)}`, body, EMPTY_STRING];
388
- });
389
- return [
390
- build,
391
- addImport,
392
- addType,
393
- addInternalFunction,
394
- addConstant,
395
- getImports,
396
- getTypes,
397
- getConstants,
398
- ];
399
- };
400
-
401
- const getCreateFunction = (getFunction, initFunction) => {
402
- const thingsByStore = /* @__PURE__ */ new WeakMap();
403
- return (store) => {
404
- if (!thingsByStore.has(store)) {
405
- thingsByStore.set(store, getFunction(store));
406
- }
407
- const thing = thingsByStore.get(store);
408
- return thing;
409
- };
410
- };
411
-
412
- const getSchemaFunctions = (tablesSchema, valuesSchema, addConstant) => {
413
- const mapTablesSchema = (callback) =>
414
- objToArray(tablesSchema, (_, tableId) =>
415
- callback(
416
- tableId,
417
- camel(tableId, 1),
418
- addConstant(snake(tableId), `'${tableId}'`),
419
- ),
420
- );
421
- const mapCellSchema = (tableId, callback) =>
422
- objToArray(tablesSchema[tableId], (cellSchema, cellId) =>
423
- callback(
424
- cellId,
425
- cellSchema[TYPE],
426
- cellSchema[DEFAULT],
427
- addConstant(snake(cellId), `'${cellId}'`),
428
- camel(cellId, 1),
429
- ),
430
- );
431
- const mapValuesSchema = (callback) =>
432
- objToArray(valuesSchema, (valueSchema, valueId) =>
433
- callback(
434
- valueId,
435
- valueSchema[TYPE],
436
- valueSchema[DEFAULT],
437
- addConstant(snake(valueId), `'${valueId}'`),
438
- camel(valueId, 1),
439
- ),
440
- );
441
- return [mapTablesSchema, mapCellSchema, mapValuesSchema];
442
- };
443
-
444
- const getTypeFunctions = (
445
- addType,
446
- mapTablesSchema,
447
- mapCellSchema,
448
- mapValuesSchema,
449
- ) => {
450
- const getTablesTypes = (storeInstance, storeType) => {
451
- const storeParam = storeInstance + ': ' + storeType;
452
- const tablesType = addType(
453
- TABLES,
454
- getFieldTypeList(
455
- ...mapTablesSchema(
456
- (tableId) =>
457
- `'${tableId}'?: {[rowId: Id]: ` +
458
- getFieldTypeList(
459
- ...mapCellSchema(
460
- tableId,
461
- (cellId, type, defaultValue) =>
462
- `'${cellId}'${isUndefined(defaultValue) ? '?' : EMPTY_STRING}: ${type}`,
463
- ),
464
- ) +
465
- '}',
466
- ),
467
- ),
468
- getTheContentOfTheStoreDoc(1, 5),
469
- );
470
- const tablesWhenSetType = addType(
471
- TABLES + WHEN_SET,
472
- getFieldTypeList(
473
- ...mapTablesSchema(
474
- (tableId) =>
475
- `'${tableId}'?: {[rowId: Id]: ` +
476
- getFieldTypeList(
477
- ...mapCellSchema(
478
- tableId,
479
- (cellId, type) => `'${cellId}'?: ${type}`,
480
- ),
481
- ) +
482
- '}',
483
- ),
484
- ),
485
- getTheContentOfTheStoreDoc(1, 5, 1),
486
- );
487
- const tableIdType = addType(
488
- TABLE + ID,
489
- 'keyof ' + tablesType,
490
- 'A ' + TABLE + ' Id in ' + THE_STORE,
491
- );
492
- const tIdGeneric = `<TId extends ${tableIdType}>`;
493
- const tableType = addType(
494
- TABLE,
495
- NON_NULLABLE + `<${tablesType}[TId]>`,
496
- 'A ' + TABLE + ' in ' + THE_STORE,
497
- tIdGeneric,
498
- );
499
- const tableWhenSetType = addType(
500
- TABLE + WHEN_SET,
501
- NON_NULLABLE + `<${tablesWhenSetType}[TId]>`,
502
- 'A ' + TABLE + ' in ' + THE_STORE + WHEN_SETTING_IT,
503
- tIdGeneric,
504
- );
505
- const rowType = addType(
506
- ROW,
507
- tableType + '<TId>[Id]',
508
- 'A ' + ROW + ' in a ' + TABLE,
509
- tIdGeneric,
510
- );
511
- const rowWhenSetType = addType(
512
- ROW + WHEN_SET,
513
- tableWhenSetType + '<TId>[Id]',
514
- 'A ' + ROW + ' in a ' + TABLE + WHEN_SETTING_IT,
515
- tIdGeneric,
516
- );
517
- const cellIdType = addType(
518
- CELL + ID,
519
- `Extract<keyof ${rowType}<TId>, Id>`,
520
- 'A ' + CELL + ' Id in a ' + ROW,
521
- tIdGeneric,
522
- );
523
- const cellType = addType(
524
- CELL,
525
- NON_NULLABLE + `<${tablesType}[TId]>[Id][CId]`,
526
- 'A ' + CELL + ' in a ' + ROW,
527
- `<TId extends ${tableIdType}, CId extends ${cellIdType}<TId>>`,
528
- );
529
- const cellIdCellArrayType = addType(
530
- 'CellIdCellArray',
531
- `CId extends ${cellIdType}<TId> ? [cellId: CId, cell: ${cellType}<TId, CId>] : never`,
532
- CELL + ' Ids and types in a ' + ROW,
533
- `<TId extends ${tableIdType}, CId = ${cellIdType}<TId>>`,
534
- 0,
535
- );
536
- const cellCallbackType = addType(
537
- CELL + CALLBACK,
538
- `(...[cellId, cell]: ${cellIdCellArrayType}<TId>)` + RETURNS_VOID,
539
- getCallbackDoc(A + CELL + ' Id, and ' + CELL),
540
- tIdGeneric,
541
- );
542
- const rowCallbackType = addType(
543
- ROW + CALLBACK,
544
- '(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) ' +
545
- RETURNS_VOID +
546
- ') ' +
547
- RETURNS_VOID,
548
- getCallbackDoc(A + ROW + ' Id, and a ' + CELL + ' iterator'),
549
- tIdGeneric,
550
- );
551
- const tableCellCallbackType = addType(
552
- TABLE + CELL + CALLBACK,
553
- `(cellId: ${cellIdType}<TId>, count: number) ` + RETURNS_VOID,
554
- getCallbackDoc(A + CELL + ' Id, and count of how many times it appears'),
555
- tIdGeneric,
556
- );
557
- const tableIdForEachRowArrayType = addType(
558
- 'TableIdForEachRowArray',
559
- `TId extends ${tableIdType} ? [tableId: TId, forEachRow: (rowCallback: ${rowCallbackType}<TId>)${RETURNS_VOID}] : never`,
560
- TABLE + ' Ids and callback types',
561
- `<TId = ${tableIdType}>`,
562
- 0,
563
- );
564
- const tableCallbackType = addType(
565
- TABLE + CALLBACK,
566
- `(...[tableId, forEachRow]: ${tableIdForEachRowArrayType})` +
567
- RETURNS_VOID,
568
- getCallbackDoc(A + TABLE + ' Id, and a ' + ROW + ' iterator'),
569
- EMPTY_STRING,
570
- );
571
- const tableIdRowIdCellIdArrayType = addType(
572
- 'TableIdRowIdCellIdArray',
573
- `TId extends ${tableIdType} ? [tableId: TId, rowId: Id, cellId: ${cellIdType}<TId>] : never`,
574
- 'Ids for GetCellChange',
575
- `<TId = ${tableIdType}>`,
576
- 0,
577
- );
578
- const getCellChangeType = addType(
579
- 'GetCellChange',
580
- `(...[tableId, rowId, cellId]: ${tableIdRowIdCellIdArrayType}) => CellChange`,
581
- A_FUNCTION_FOR +
582
- ` returning information about any Cell's changes during a ` +
583
- TRANSACTION_,
584
- );
585
- const hasTablesListenerType = addType(
586
- HAS + TABLES + LISTENER,
587
- `(${storeParam}, hasTables: boolean)` + RETURNS_VOID,
588
- getListenerTypeDoc(1, 0, 1),
589
- );
590
- const tablesListenerType = addType(
591
- TABLES + LISTENER,
592
- `(${storeParam}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
593
- RETURNS_VOID,
594
- getListenerTypeDoc(1),
595
- );
596
- const tableIdsListenerType = addType(
597
- TABLE_IDS + LISTENER,
598
- `(${storeParam})` + RETURNS_VOID,
599
- getListenerTypeDoc(2),
600
- );
601
- const hasTableListenerType = addType(
602
- HAS + TABLE + LISTENER,
603
- `(${storeParam}, tableId: ${tableIdType}, hasTable: boolean)` +
604
- RETURNS_VOID,
605
- getListenerTypeDoc(3, 0, 1),
606
- );
607
- const tableListenerType = addType(
608
- TABLE + LISTENER,
609
- `(${storeParam}, tableId: ${tableIdType}, getCellChange: ${getCellChangeType}${OR_UNDEFINED})` +
610
- RETURNS_VOID,
611
- getListenerTypeDoc(3),
612
- );
613
- const tableCellIdsListenerType = addType(
614
- TABLE + CELL_IDS + LISTENER,
615
- `(${storeParam}, tableId: ${tableIdType})` + RETURNS_VOID,
616
- getListenerTypeDoc(14, 3),
617
- );
618
- const hasTableCellListenerArgsArrayInnerType = addType(
619
- 'HasTableCellListenerArgsArrayInner',
620
- `CId extends ${cellIdType}<TId> ? [${storeParam}, tableId: TId, cellId: CId, hasTableCell: boolean] : never`,
621
- 'Cell args for HasTableCellListener',
622
- `<TId extends ${tableIdType}, CId = ${cellIdType}<TId>>`,
623
- 0,
624
- );
625
- const hasTableCellListenerArgsArrayOuterType = addType(
626
- 'HasTableCellListenerArgsArrayOuter',
627
- `TId extends ${tableIdType} ? ` +
628
- hasTableCellListenerArgsArrayInnerType +
629
- '<TId> : never',
630
- 'Table args for HasTableCellListener',
631
- `<TId = ${tableIdType}>`,
632
- 0,
633
- );
634
- const hasTableCellListenerType = addType(
635
- HAS + TABLE + CELL + LISTENER,
636
- `(...[${storeInstance}, tableId, cellId, hasTableCell]: ` +
637
- hasTableCellListenerArgsArrayOuterType +
638
- ')' +
639
- RETURNS_VOID,
640
- getListenerTypeDoc(16, 3, 1),
641
- );
642
- const rowCountListenerType = addType(
643
- ROW + 'Count' + LISTENER,
644
- `(${storeParam}, tableId: ${tableIdType})` + RETURNS_VOID,
645
- getListenerTypeDoc(15, 3),
646
- );
647
- const rowIdsListenerType = addType(
648
- ROW_IDS + LISTENER,
649
- `(${storeParam}, tableId: ${tableIdType})` + RETURNS_VOID,
650
- getListenerTypeDoc(4, 3),
651
- );
652
- const sortedRowIdsListenerType = addType(
653
- SORTED_ROW_IDS + LISTENER,
654
- '(' +
655
- getParameterList(
656
- storeParam,
657
- 'tableId: ' + tableIdType,
658
- 'cellId: Id' + OR_UNDEFINED,
659
- 'descending: boolean',
660
- 'offset: number',
661
- 'limit: number' + OR_UNDEFINED,
662
- 'sortedRowIds: Ids',
663
- ) +
664
- ')' +
665
- RETURNS_VOID,
666
- getListenerTypeDoc(13, 3),
667
- );
668
- const hasRowListenerType = addType(
669
- HAS + ROW + LISTENER,
670
- '(' +
671
- getParameterList(
672
- `${storeParam}`,
673
- 'tableId: ' + tableIdType,
674
- ROW_ID_PARAM,
675
- `hasRow: boolean`,
676
- ) +
677
- ')' +
678
- RETURNS_VOID,
679
- getListenerTypeDoc(5, 3, 1),
680
- );
681
- const rowListenerType = addType(
682
- ROW + LISTENER,
683
- '(' +
684
- getParameterList(
685
- `${storeParam}`,
686
- 'tableId: ' + tableIdType,
687
- ROW_ID_PARAM,
688
- `getCellChange: ${getCellChangeType}${OR_UNDEFINED}`,
689
- ) +
690
- ')' +
691
- RETURNS_VOID,
692
- getListenerTypeDoc(5, 3),
693
- );
694
- const cellIdsListenerType = addType(
695
- CELL_IDS + LISTENER,
696
- '(' +
697
- getParameterList(
698
- `${storeParam}`,
699
- 'tableId: ' + tableIdType,
700
- ROW_ID_PARAM,
701
- ) +
702
- ')' +
703
- RETURNS_VOID,
704
- getListenerTypeDoc(6, 5),
705
- );
706
- const hasCellListenerArgsArrayInnerType = addType(
707
- 'HasCellListenerArgsArrayInner',
708
- `CId extends ${cellIdType}<TId> ? [${storeParam}, tableId: TId, ${ROW_ID_PARAM}, cellId: CId, hasCell: boolean] : never`,
709
- 'Cell args for HasCellListener',
710
- `<TId extends ${tableIdType}, CId = ${cellIdType}<TId>>`,
711
- 0,
712
- );
713
- const hasCellListenerArgsArrayOuterType = addType(
714
- 'HasCellListenerArgsArrayOuter',
715
- `TId extends ${tableIdType} ? ` +
716
- hasCellListenerArgsArrayInnerType +
717
- '<TId> : never',
718
- 'Table args for HasCellListener',
719
- `<TId = ${tableIdType}>`,
720
- 0,
721
- );
722
- const hasCellListenerType = addType(
723
- HAS + CELL + LISTENER,
724
- `(...[${storeInstance}, tableId, rowId, cellId, hasCell]: ` +
725
- hasCellListenerArgsArrayOuterType +
726
- ')' +
727
- RETURNS_VOID,
728
- getListenerTypeDoc(7, 5, 1),
729
- );
730
- const cellListenerArgsArrayInnerType = addType(
731
- 'CellListenerArgsArrayInner',
732
- `CId extends ${cellIdType}<TId> ? [${storeParam}, tableId: TId, ${ROW_ID_PARAM}, cellId: CId, newCell: ${cellType}<TId, CId> ${OR_UNDEFINED}, oldCell: ${cellType}<TId, CId> ${OR_UNDEFINED}, getCellChange: ${getCellChangeType} ${OR_UNDEFINED}] : never`,
733
- 'Cell args for CellListener',
734
- `<TId extends ${tableIdType}, CId = ${cellIdType}<TId>>`,
735
- 0,
736
- );
737
- const cellListenerArgsArrayOuterType = addType(
738
- 'CellListenerArgsArrayOuter',
739
- `TId extends ${tableIdType} ? ` +
740
- cellListenerArgsArrayInnerType +
741
- '<TId> : never',
742
- 'Table args for CellListener',
743
- `<TId = ${tableIdType}>`,
744
- 0,
745
- );
746
- const cellListenerType = addType(
747
- CELL + LISTENER,
748
- `(...[${storeInstance}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${cellListenerArgsArrayOuterType})` +
749
- RETURNS_VOID,
750
- getListenerTypeDoc(7, 5),
751
- );
752
- const invalidCellListenerType = addType(
753
- INVALID + CELL + LISTENER,
754
- `(${storeParam}, tableId: Id, ${ROW_ID_PARAM}, cellId: Id, invalidCells: any[])` +
755
- RETURNS_VOID,
756
- getListenerTypeDoc(8),
757
- );
758
- return [
759
- tablesType,
760
- tablesWhenSetType,
761
- tableIdType,
762
- tableType,
763
- tableWhenSetType,
764
- rowType,
765
- rowWhenSetType,
766
- cellIdType,
767
- cellType,
768
- cellCallbackType,
769
- rowCallbackType,
770
- tableCellCallbackType,
771
- tableCallbackType,
772
- hasTablesListenerType,
773
- tablesListenerType,
774
- tableIdsListenerType,
775
- hasTableListenerType,
776
- tableListenerType,
777
- tableCellIdsListenerType,
778
- hasTableCellListenerType,
779
- rowCountListenerType,
780
- rowIdsListenerType,
781
- sortedRowIdsListenerType,
782
- hasRowListenerType,
783
- rowListenerType,
784
- cellIdsListenerType,
785
- hasCellListenerType,
786
- cellListenerType,
787
- invalidCellListenerType,
788
- ];
789
- };
790
- const getValuesTypes = (storeInstance, storeType) => {
791
- const storeParam = storeInstance + ': ' + storeType;
792
- const valuesType = addType(
793
- VALUES,
794
- getFieldTypeList(
795
- ...mapValuesSchema(
796
- (valueId, type, defaultValue) =>
797
- `'${valueId}'${isUndefined(defaultValue) ? '?' : EMPTY_STRING}: ${type}`,
798
- ),
799
- ),
800
- getTheContentOfTheStoreDoc(2, 5),
801
- );
802
- const valuesWhenSetType = addType(
803
- VALUES + WHEN_SET,
804
- getFieldTypeList(
805
- ...mapValuesSchema((valueId, type) => `'${valueId}'?: ${type}`),
806
- ),
807
- getTheContentOfTheStoreDoc(2, 5, 1),
808
- );
809
- const valueIdType = addType(
810
- VALUE + ID,
811
- 'keyof ' + valuesType,
812
- 'A ' + VALUE + ' Id in ' + THE_STORE,
813
- );
814
- const valueType = addType(
815
- VALUE,
816
- NON_NULLABLE + `<${valuesType}[VId]>`,
817
- 'A ' + VALUE + ' Id in ' + THE_STORE,
818
- `<VId extends ${valueIdType}>`,
819
- );
820
- const valueIdValueArrayType = addType(
821
- 'ValueIdValueArray',
822
- `VId extends ${valueIdType} ? [valueId: VId, value: ${valueType}<VId>] : never`,
823
- VALUE + ' Ids and types in ' + THE_STORE,
824
- `<VId = ${valueIdType}>`,
825
- 0,
826
- );
827
- const valueCallbackType = addType(
828
- VALUE + CALLBACK,
829
- `(...[valueId, value]: ${valueIdValueArrayType})` + RETURNS_VOID,
830
- getCallbackDoc(A + VALUE + ' Id, and ' + VALUE),
831
- );
832
- const getValueChangeType = addType(
833
- 'GetValueChange',
834
- `(valueId: ${valueIdType}) => ValueChange`,
835
- A_FUNCTION_FOR +
836
- ` returning information about any Value's changes during a ` +
837
- TRANSACTION_,
838
- );
839
- const hasValuesListenerType = addType(
840
- HAS + VALUES + LISTENER,
841
- `(${storeParam}, hasValues: boolean)` + RETURNS_VOID,
842
- getListenerTypeDoc(9, 0, 1),
843
- );
844
- const valuesListenerType = addType(
845
- VALUES + LISTENER,
846
- `(${storeParam}, getValueChange: ${getValueChangeType}${OR_UNDEFINED})` +
847
- RETURNS_VOID,
848
- getListenerTypeDoc(9),
849
- );
850
- const valueIdsListenerType = addType(
851
- VALUE_IDS + LISTENER,
852
- `(${storeParam})` + RETURNS_VOID,
853
- getListenerTypeDoc(10),
854
- );
855
- const hasValueListenerType = addType(
856
- HAS + VALUE + LISTENER,
857
- `(${storeParam}, valueId: ValueId, hasValue: boolean)` + RETURNS_VOID,
858
- getListenerTypeDoc(11, 0, 1),
859
- );
860
- const valueListenerArgsArrayType = addType(
861
- 'ValueListenerArgsArray',
862
- `VId extends ${valueIdType} ? [${storeParam}, valueId: VId, newValue: ${valueType}<VId> ${OR_UNDEFINED}, oldValue: ${valueType}<VId> ${OR_UNDEFINED}, getValueChange: ${getValueChangeType} ${OR_UNDEFINED}] : never`,
863
- 'Value args for ValueListener',
864
- `<VId = ${valueIdType}>`,
865
- 0,
866
- );
867
- const valueListenerType = addType(
868
- VALUE + LISTENER,
869
- `(...[${storeInstance}, valueId, newValue, oldValue, getValueChange]: ` +
870
- valueListenerArgsArrayType +
871
- ')' +
872
- RETURNS_VOID,
873
- getListenerTypeDoc(11),
874
- );
875
- const invalidValueListenerType = addType(
876
- INVALID + VALUE + LISTENER,
877
- `(${storeParam}, valueId: Id, invalidValues: any[])` + RETURNS_VOID,
878
- getListenerTypeDoc(12),
879
- );
880
- return [
881
- valuesType,
882
- valuesWhenSetType,
883
- valueIdType,
884
- valueType,
885
- valueCallbackType,
886
- hasValuesListenerType,
887
- valuesListenerType,
888
- valueIdsListenerType,
889
- hasValueListenerType,
890
- valueListenerType,
891
- invalidValueListenerType,
892
- ];
893
- };
894
- const getTransactionListenerType = (storeInstance, storeType) =>
895
- addType(
896
- TRANSACTION + LISTENER,
897
- `(${storeInstance}: ${storeType})` + RETURNS_VOID,
898
- A_FUNCTION_FOR + ' listening to the completion of a ' + TRANSACTION_,
899
- );
900
- return [getTablesTypes, getValuesTypes, getTransactionListenerType];
901
- };
902
-
903
- const storeMethod = (method, parameters = EMPTY_STRING, cast = EMPTY_STRING) =>
904
- `store.${method}(${parameters})` + (cast ? ' as ' + cast : EMPTY_STRING);
905
- const fluentStoreMethod = (method, parameters = EMPTY_STRING) =>
906
- `fluent(() => ${storeMethod(method, parameters)})`;
907
- const storeListener = (
908
- method,
909
- beforeParameters = EMPTY_STRING,
910
- afterParameters = EMPTY_STRING,
911
- ) =>
912
- `store.${method}(${beforeParameters ? beforeParameters + ', ' : EMPTY_STRING}proxy(listener)${afterParameters ? ', ' + afterParameters : EMPTY_STRING})`;
913
- const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
914
- const [
915
- build,
916
- addImport,
917
- addType,
918
- addInternalFunction,
919
- addConstant,
920
- getImports,
921
- getTypes,
922
- getConstants,
923
- ] = getCodeFunctions();
924
- const [mapTablesSchema, mapCellSchema, mapValuesSchema] = getSchemaFunctions(
925
- tablesSchema,
926
- valuesSchema,
927
- addConstant,
928
- );
929
- const [getTablesTypes, getValuesTypes, getTransactionListenerType] =
930
- getTypeFunctions(addType, mapTablesSchema, mapCellSchema, mapValuesSchema);
931
- const methods = mapNew();
932
- const getMethods = (location = 0) =>
933
- mapMap(methods, ([parameters, returnType, body, doc, generic], name) => {
934
- const lines = location
935
- ? [name + `: ${generic}(${parameters}): ${returnType} => ${body},`]
936
- : [name + generic + `(${parameters}): ${returnType};`];
937
- if (!location) {
938
- arrayUnshift(lines, comment(doc));
939
- }
940
- arrayPush(lines, EMPTY_STRING);
941
- return lines;
942
- });
943
- const addMethod = (
944
- name,
945
- parameters,
946
- returnType,
947
- body,
948
- doc,
949
- generic = EMPTY_STRING,
950
- ) => mapUnique(methods, name, [parameters, returnType, body, doc, generic]);
951
- const addProxyMethod = (
952
- prefixVerb,
953
- prefix,
954
- underlyingName,
955
- returnType,
956
- doc,
957
- params = EMPTY_STRING,
958
- paramsInCall = EMPTY_STRING,
959
- generic = EMPTY_STRING,
960
- ) =>
961
- addMethod(
962
- METHOD_PREFIX_VERBS[prefixVerb] +
963
- prefix +
964
- (prefixVerb == 4 ? PARTIAL : EMPTY_STRING) +
965
- underlyingName,
966
- params,
967
- returnType,
968
- (returnType == storeType ? fluentStoreMethod : storeMethod)(
969
- METHOD_PREFIX_VERBS[prefixVerb] +
970
- (prefixVerb == 4 ? PARTIAL : EMPTY_STRING) +
971
- underlyingName,
972
- paramsInCall,
973
- prefixVerb ? void 0 : returnType,
974
- ),
975
- doc,
976
- generic,
977
- );
978
- const addProxyListener = (
979
- underlyingName,
980
- listenerType,
981
- doc,
982
- params = EMPTY_STRING,
983
- paramsInCall = EMPTY_STRING,
984
- mutator = 1,
985
- generic = EMPTY_STRING,
986
- ) =>
987
- addMethod(
988
- ADD + underlyingName + LISTENER,
989
- (params ? params + ', ' : EMPTY_STRING) +
990
- LISTENER_ +
991
- ': ' +
992
- listenerType +
993
- (mutator ? ', mutator?: boolean' : EMPTY_STRING),
994
- ID,
995
- storeListener(
996
- ADD + underlyingName + LISTENER,
997
- paramsInCall,
998
- mutator ? 'mutator' : EMPTY_STRING,
999
- ),
1000
- doc,
1001
- generic,
1002
- );
1003
- const moduleDefinition = `./${camel(module)}.d`;
1004
- const storeType = camel(module, 1);
1005
- const storeInstance = camel(storeType);
1006
- const createSteps = [];
1007
- const mapCellOrValueTypes = mapNew();
1008
- let sharedTableTypes = [];
1009
- let sharedValueTypes = [];
1010
- addImport(
1011
- 1,
1012
- moduleDefinition,
1013
- storeType,
1014
- `create${storeType} as create${storeType}Decl`,
1015
- );
1016
- if (!objIsEmpty(tablesSchema)) {
1017
- addImport(0, TINYBASE, 'CellChange');
1018
- addImport(null, TINYBASE, IDS);
1019
- const [
1020
- tablesType,
1021
- tablesWhenSetType,
1022
- tableIdType,
1023
- tableType,
1024
- tableWhenSetType,
1025
- rowType,
1026
- rowWhenSetType,
1027
- cellIdType,
1028
- _cellType,
1029
- cellCallbackType,
1030
- rowCallbackType,
1031
- tableCellCallbackType,
1032
- tableCallbackType,
1033
- hasTablesListenerType,
1034
- tablesListenerType,
1035
- tableIdsListenerType,
1036
- hasTableListenerType,
1037
- tableListenerType,
1038
- tableCellIdsListenerType,
1039
- hasTableCellListenerType,
1040
- rowCountListenerType,
1041
- rowIdsListenerType,
1042
- sortedRowIdsListenerType,
1043
- hasRowListenerType,
1044
- rowListenerType,
1045
- cellIdsListenerType,
1046
- hasCellListenerType,
1047
- cellListenerType,
1048
- invalidCellListenerType,
1049
- ] = getTablesTypes(storeInstance, storeType);
1050
- const tablesTypes = mapNew();
1051
- mapTablesSchema((tableId, tableName) => {
1052
- const tableIdGeneric = `<'${tableId}'>`;
1053
- const tableTypes = [
1054
- // Table
1055
- addType(
1056
- tableName + TABLE,
1057
- tableType + tableIdGeneric,
1058
- REPRESENTS + ` the '${tableId}' ` + TABLE,
1059
- ),
1060
- // TableWhenSet
1061
- addType(
1062
- tableName + TABLE + WHEN_SET,
1063
- tableWhenSetType + tableIdGeneric,
1064
- REPRESENTS + ` the '${tableId}' ` + TABLE + WHEN_SETTING_IT,
1065
- ),
1066
- // Row
1067
- addType(
1068
- tableName + ROW,
1069
- rowType + tableIdGeneric,
1070
- getRowTypeDoc(tableId),
1071
- ),
1072
- // RowWhenSet
1073
- addType(
1074
- tableName + ROW + WHEN_SET,
1075
- rowWhenSetType + tableIdGeneric,
1076
- getRowTypeDoc(tableId, 1),
1077
- ),
1078
- // CellId
1079
- addType(
1080
- tableName + CELL + ID,
1081
- cellIdType + tableIdGeneric,
1082
- `A Cell Id for the '${tableId}' ` + TABLE,
1083
- ),
1084
- // CellCallback
1085
- addType(
1086
- tableName + CELL + CALLBACK,
1087
- cellCallbackType + tableIdGeneric,
1088
- getCallbackDoc(
1089
- `a Cell Id and value from a Row in the '${tableId}' ` + TABLE,
1090
- ),
1091
- ),
1092
- // RowCallback
1093
- addType(
1094
- tableName + ROW + CALLBACK,
1095
- rowCallbackType + tableIdGeneric,
1096
- getCallbackDoc(
1097
- `a Row Id from the '${tableId}' Table, and a Cell iterator`,
1098
- ),
1099
- ),
1100
- // TableCellCallbackType
1101
- addType(
1102
- tableName + TABLE + CELL + CALLBACK,
1103
- tableCellCallbackType + tableIdGeneric,
1104
- getCallbackDoc(
1105
- `a Cell Id from anywhere in the '${tableId}' Table, and a count of how many times it appears`,
1106
- ),
1107
- ),
1108
- ];
1109
- mapSet(tablesTypes, tableId, tableTypes);
1110
- addImport(1, moduleDefinition, ...tableTypes);
1111
- });
1112
- addImport(
1113
- 1,
1114
- moduleDefinition,
1115
- tablesType,
1116
- tablesWhenSetType,
1117
- tableIdType,
1118
- cellIdType,
1119
- tableCallbackType,
1120
- hasTablesListenerType,
1121
- tablesListenerType,
1122
- tableIdsListenerType,
1123
- hasTableListenerType,
1124
- tableListenerType,
1125
- tableCellIdsListenerType,
1126
- hasTableCellListenerType,
1127
- rowCountListenerType,
1128
- rowIdsListenerType,
1129
- sortedRowIdsListenerType,
1130
- hasRowListenerType,
1131
- rowListenerType,
1132
- cellIdsListenerType,
1133
- hasCellListenerType,
1134
- cellListenerType,
1135
- invalidCellListenerType,
1136
- );
1137
- sharedTableTypes = [
1138
- tablesType,
1139
- tablesWhenSetType,
1140
- tableIdType,
1141
- cellIdType,
1142
- hasTablesListenerType,
1143
- tablesListenerType,
1144
- tableIdsListenerType,
1145
- hasTableListenerType,
1146
- tableListenerType,
1147
- tableCellIdsListenerType,
1148
- hasTableCellListenerType,
1149
- rowCountListenerType,
1150
- rowIdsListenerType,
1151
- sortedRowIdsListenerType,
1152
- hasRowListenerType,
1153
- rowListenerType,
1154
- cellIdsListenerType,
1155
- hasCellListenerType,
1156
- cellListenerType,
1157
- tablesTypes,
1158
- ];
1159
- arrayForEach(
1160
- [
1161
- [tablesType],
1162
- [BOOLEAN],
1163
- [storeType, 'tables: ' + tablesWhenSetType, 'tables'],
1164
- [storeType],
1165
- ],
1166
- ([returnType, params, paramsInCall], verb) =>
1167
- addProxyMethod(
1168
- verb,
1169
- EMPTY_STRING,
1170
- TABLES,
1171
- returnType,
1172
- getTheContentOfTheStoreDoc(1, verb),
1173
- params,
1174
- paramsInCall,
1175
- ),
1176
- );
1177
- addProxyMethod(
1178
- 0,
1179
- EMPTY_STRING,
1180
- TABLE_IDS,
1181
- tableIdType + SQUARE_BRACKETS,
1182
- getIdsDoc(TABLE, THE_STORE),
1183
- );
1184
- addProxyMethod(
1185
- 5,
1186
- EMPTY_STRING,
1187
- TABLE,
1188
- VOID,
1189
- getForEachDoc(TABLE, THE_STORE),
1190
- 'tableCallback: ' + tableCallbackType,
1191
- 'tableCallback as any',
1192
- );
1193
- mapTablesSchema((tableId, tableName, TABLE_ID) => {
1194
- const [
1195
- tableType2,
1196
- tableWhenSetType2,
1197
- rowType2,
1198
- rowWhenSetType2,
1199
- cellIdType2,
1200
- cellCallbackType2,
1201
- rowCallbackType2,
1202
- tableCellCallbackType2,
1203
- ] = mapGet(tablesTypes, tableId);
1204
- arrayForEach(
1205
- [
1206
- [tableType2],
1207
- [BOOLEAN],
1208
- [storeType, 'table: ' + tableWhenSetType2, ', table'],
1209
- [storeType],
1210
- ],
1211
- ([returnType, params, paramsInCall = EMPTY_STRING], verb) =>
1212
- addProxyMethod(
1213
- verb,
1214
- tableName,
1215
- TABLE,
1216
- returnType,
1217
- getTableContentDoc(tableId, verb),
1218
- params,
1219
- TABLE_ID + paramsInCall,
1220
- ),
1221
- );
1222
- addProxyMethod(
1223
- 0,
1224
- tableName,
1225
- TABLE + CELL_IDS,
1226
- IDS,
1227
- getIdsDoc(CELL, 'the whole of ' + getTableDoc(tableId)),
1228
- EMPTY_STRING,
1229
- TABLE_ID,
1230
- );
1231
- addProxyMethod(
1232
- 5,
1233
- tableName,
1234
- TABLE + CELL,
1235
- VOID,
1236
- getForEachDoc(TABLE + CELL, 'the whole of ' + getTableDoc(tableId)),
1237
- 'tableCellCallback: ' + tableCellCallbackType2,
1238
- TABLE_ID + ', tableCellCallback as any',
1239
- );
1240
- addProxyMethod(
1241
- 0,
1242
- tableName,
1243
- ROW + COUNT,
1244
- 'number',
1245
- 'Gets the number of Rows in the ' + getTableDoc(tableId),
1246
- EMPTY_STRING,
1247
- TABLE_ID,
1248
- );
1249
- addProxyMethod(
1250
- 0,
1251
- tableName,
1252
- ROW_IDS,
1253
- IDS,
1254
- getIdsDoc(ROW, getTableDoc(tableId)),
1255
- EMPTY_STRING,
1256
- TABLE_ID,
1257
- );
1258
- addProxyMethod(
1259
- 0,
1260
- tableName,
1261
- SORTED_ROW_IDS,
1262
- IDS,
1263
- getIdsDoc(ROW, getTableDoc(tableId), 1),
1264
- 'cellId?: ' + cellIdType2 + SORTED_ARGS,
1265
- TABLE_ID + ', cellId, descending, offset, limit',
1266
- );
1267
- addProxyMethod(
1268
- 5,
1269
- tableName,
1270
- ROW,
1271
- VOID,
1272
- getForEachDoc(ROW, getTableDoc(tableId)),
1273
- 'rowCallback: ' + rowCallbackType2,
1274
- TABLE_ID + ', rowCallback as any',
1275
- );
1276
- arrayForEach(
1277
- [
1278
- [rowType2],
1279
- [BOOLEAN],
1280
- [storeType, ', row: ' + rowWhenSetType2, ', row'],
1281
- [storeType],
1282
- [storeType, ', partialRow: ' + rowWhenSetType2, ', partialRow'],
1283
- ],
1284
- (
1285
- [returnType, params = EMPTY_STRING, paramsInCall = EMPTY_STRING],
1286
- verb,
1287
- ) =>
1288
- addProxyMethod(
1289
- verb,
1290
- tableName,
1291
- ROW,
1292
- returnType,
1293
- getRowContentDoc(tableId, verb),
1294
- ROW_ID_PARAM + params,
1295
- TABLE_ID + ', rowId' + paramsInCall,
1296
- ),
1297
- );
1298
- addProxyMethod(
1299
- 6,
1300
- tableName,
1301
- ROW,
1302
- ID + OR_UNDEFINED,
1303
- 'Add a new Row to ' + getTableDoc(tableId),
1304
- 'row: ' + rowWhenSetType2 + ', reuseIds?: boolean',
1305
- TABLE_ID + ', row, reuseIds',
1306
- );
1307
- addProxyMethod(
1308
- 0,
1309
- tableName,
1310
- CELL_IDS,
1311
- cellIdType2 + SQUARE_BRACKETS,
1312
- getIdsDoc(CELL, getRowDoc(tableId)),
1313
- ROW_ID_PARAM,
1314
- TABLE_ID + ', rowId',
1315
- );
1316
- addProxyMethod(
1317
- 5,
1318
- tableName,
1319
- CELL,
1320
- VOID,
1321
- getForEachDoc(CELL, getRowDoc(tableId)),
1322
- ROW_ID_PARAM + ', cellCallback: ' + cellCallbackType2,
1323
- TABLE_ID + ', rowId, cellCallback as any',
1324
- );
1325
- mapCellSchema(
1326
- tableId,
1327
- (cellId, type, defaultValue, CELL_ID, cellName) => {
1328
- const mapCellType = 'Map' + camel(type, 1);
1329
- mapSet(mapCellOrValueTypes, type, mapCellType);
1330
- const returnCellType =
1331
- type + (isUndefined(defaultValue) ? OR_UNDEFINED : EMPTY_STRING);
1332
- arrayForEach(
1333
- [
1334
- [returnCellType],
1335
- [BOOLEAN],
1336
- [storeType, `, cell: ${type} | ` + mapCellType, ', cell as any'],
1337
- [storeType],
1338
- ],
1339
- (
1340
- [returnType, params = EMPTY_STRING, paramsInCall = EMPTY_STRING],
1341
- verb,
1342
- ) =>
1343
- addProxyMethod(
1344
- verb,
1345
- tableName + cellName,
1346
- CELL,
1347
- returnType,
1348
- getCellContentDoc(tableId, cellId, verb),
1349
- ROW_ID_PARAM + params,
1350
- TABLE_ID + ', rowId, ' + CELL_ID + paramsInCall,
1351
- ),
1352
- );
1353
- addProxyMethod(
1354
- 1,
1355
- tableName + cellName,
1356
- TABLE + CELL,
1357
- BOOLEAN,
1358
- VERBS[1] +
1359
- ` the '${cellId}' Cell anywhere in ` +
1360
- getTableDoc(tableId),
1361
- EMPTY_STRING,
1362
- TABLE_ID + ', ' + CELL_ID,
1363
- );
1364
- },
1365
- );
1366
- });
1367
- addProxyMethod(
1368
- 0,
1369
- EMPTY_STRING,
1370
- TABLES + JSON$1,
1371
- JSON$1,
1372
- getTheContentOfTheStoreDoc(1, 6),
1373
- );
1374
- addProxyMethod(
1375
- 2,
1376
- EMPTY_STRING,
1377
- TABLES + JSON$1,
1378
- storeType,
1379
- getTheContentOfTheStoreDoc(1, 7),
1380
- 'tablesJson: ' + JSON$1,
1381
- 'tables' + JSON$1,
1382
- );
1383
- addProxyListener(
1384
- HAS + TABLES,
1385
- hasTablesListenerType,
1386
- getTheContentOfTheStoreDoc(1, 8, 0, 1) + ' changes',
1387
- );
1388
- addProxyListener(
1389
- TABLES,
1390
- tablesListenerType,
1391
- getTheContentOfTheStoreDoc(1, 8) + ' changes',
1392
- );
1393
- addProxyListener(TABLE_IDS, tableIdsListenerType, getListenerDoc(2, 0, 1));
1394
- addProxyListener(
1395
- HAS + TABLE,
1396
- hasTableListenerType,
1397
- getListenerDoc(3, 0, 0, 1),
1398
- `tableId: ${tableIdType} | null`,
1399
- 'tableId',
1400
- );
1401
- addProxyListener(
1402
- TABLE,
1403
- tableListenerType,
1404
- getListenerDoc(3, 0),
1405
- `tableId: ${tableIdType} | null`,
1406
- 'tableId',
1407
- );
1408
- addProxyListener(
1409
- TABLE + CELL_IDS,
1410
- tableCellIdsListenerType,
1411
- getListenerDoc(14, 3, 1),
1412
- `tableId: ${tableIdType} | null`,
1413
- 'tableId',
1414
- );
1415
- addProxyListener(
1416
- HAS + TABLE + CELL,
1417
- hasTableCellListenerType,
1418
- getListenerDoc(16, 3, 0, 1),
1419
- `tableId: ${tableIdType} | null, cellId: ${arrayJoin(
1420
- mapTablesSchema(
1421
- (tableId) => mapGet(tablesTypes, tableId)?.[4] ?? EMPTY_STRING,
1422
- ),
1423
- ' | ',
1424
- )} | null`,
1425
- 'tableId, cellId',
1426
- );
1427
- addProxyListener(
1428
- ROW + COUNT,
1429
- rowCountListenerType,
1430
- getListenerDoc(15, 3),
1431
- `tableId: ${tableIdType} | null`,
1432
- 'tableId',
1433
- );
1434
- addProxyListener(
1435
- ROW_IDS,
1436
- rowIdsListenerType,
1437
- getListenerDoc(4, 3, 1),
1438
- `tableId: ${tableIdType} | null`,
1439
- 'tableId',
1440
- );
1441
- addProxyListener(
1442
- SORTED_ROW_IDS,
1443
- sortedRowIdsListenerType,
1444
- getListenerDoc(13, 3, 1),
1445
- getParameterList(
1446
- 'tableId: TId',
1447
- `cellId: ${cellIdType}<TId>` + OR_UNDEFINED,
1448
- 'descending: boolean',
1449
- 'offset: number',
1450
- 'limit: number' + OR_UNDEFINED,
1451
- ),
1452
- getParameterList('tableId', 'cellId', 'descending', 'offset', 'limit'),
1453
- 1,
1454
- '<TId extends TableId>',
1455
- );
1456
- addProxyListener(
1457
- HAS + ROW,
1458
- hasRowListenerType,
1459
- getListenerDoc(5, 3, 0, 1),
1460
- `tableId: ${tableIdType} | null, rowId: IdOrNull`,
1461
- 'tableId, rowId',
1462
- );
1463
- addProxyListener(
1464
- ROW,
1465
- rowListenerType,
1466
- getListenerDoc(5, 3),
1467
- `tableId: ${tableIdType} | null, rowId: IdOrNull`,
1468
- 'tableId, rowId',
1469
- );
1470
- addProxyListener(
1471
- CELL_IDS,
1472
- cellIdsListenerType,
1473
- getListenerDoc(6, 5, 1),
1474
- `tableId: ${tableIdType} | null, rowId: IdOrNull`,
1475
- 'tableId, rowId',
1476
- );
1477
- addProxyListener(
1478
- HAS + CELL,
1479
- hasCellListenerType,
1480
- getListenerDoc(7, 5, 0, 1),
1481
- `tableId: ${tableIdType} | null, rowId: IdOrNull, cellId: ${arrayJoin(
1482
- mapTablesSchema(
1483
- (tableId) => mapGet(tablesTypes, tableId)?.[4] ?? EMPTY_STRING,
1484
- ),
1485
- ' | ',
1486
- )} | null`,
1487
- 'tableId, rowId, cellId',
1488
- );
1489
- addProxyListener(
1490
- CELL,
1491
- cellListenerType,
1492
- getListenerDoc(7, 5),
1493
- `tableId: ${tableIdType} | null, rowId: IdOrNull, cellId: ${arrayJoin(
1494
- mapTablesSchema(
1495
- (tableId) => mapGet(tablesTypes, tableId)?.[4] ?? EMPTY_STRING,
1496
- ),
1497
- ' | ',
1498
- )} | null`,
1499
- 'tableId, rowId, cellId',
1500
- );
1501
- addProxyListener(
1502
- INVALID + CELL,
1503
- invalidCellListenerType,
1504
- REGISTERS_A_LISTENER + ' whenever an invalid Cell change was attempted',
1505
- `tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull`,
1506
- 'tableId, rowId, cellId',
1507
- );
1508
- addImport(1, moduleDefinition, ...collValues(mapCellOrValueTypes));
1509
- arrayPush(
1510
- createSteps,
1511
- '.set' + TABLES + SCHEMA + '({',
1512
- flat(
1513
- mapTablesSchema((tableId, _, TABLE_ID) => [
1514
- `[${TABLE_ID}]: {`,
1515
- ...mapCellSchema(
1516
- tableId,
1517
- (_2, type, defaultValue, CELL_ID) =>
1518
- `[${CELL_ID}]: {[${addConstant(
1519
- snake(TYPE),
1520
- `'${TYPE}'`,
1521
- )}]: ${addConstant(snake(type), `'${type}'`)}${isUndefined(defaultValue) ? EMPTY_STRING : `, [${addConstant(snake(DEFAULT), `'${DEFAULT}'`)}]: ` + (isString(defaultValue) ? addConstant(snake(defaultValue), `'${defaultValue}'`) : defaultValue)}},`,
1522
- ),
1523
- `},`,
1524
- ]),
1525
- ),
1526
- '})',
1527
- );
1528
- } else {
1529
- addImport(null, TINYBASE, TABLES);
1530
- }
1531
- if (!objIsEmpty(valuesSchema)) {
1532
- const [
1533
- valuesType,
1534
- valuesWhenSetType,
1535
- valueIdType,
1536
- _valueType,
1537
- valueCallbackType,
1538
- hasValuesListenerType,
1539
- valuesListenerType,
1540
- valueIdsListenerType,
1541
- hasValueListenerType,
1542
- valueListenerType,
1543
- invalidValueListenerType,
1544
- ] = getValuesTypes(storeInstance, storeType);
1545
- addImport(
1546
- 1,
1547
- moduleDefinition,
1548
- valuesType,
1549
- valuesWhenSetType,
1550
- valueIdType,
1551
- valueCallbackType,
1552
- hasValuesListenerType,
1553
- valuesListenerType,
1554
- valueIdsListenerType,
1555
- hasValueListenerType,
1556
- valueListenerType,
1557
- invalidValueListenerType,
1558
- );
1559
- sharedValueTypes = [
1560
- valuesType,
1561
- valuesWhenSetType,
1562
- valueIdType,
1563
- hasValuesListenerType,
1564
- valuesListenerType,
1565
- valueIdsListenerType,
1566
- hasValueListenerType,
1567
- valueListenerType,
1568
- ];
1569
- arrayForEach(
1570
- [
1571
- [valuesType],
1572
- [BOOLEAN],
1573
- [storeType, 'values: ' + valuesWhenSetType, 'values'],
1574
- [storeType],
1575
- [storeType, 'partialValues: ' + valuesWhenSetType, 'partialValues'],
1576
- ],
1577
- ([returnType, params, paramsInCall], verb) =>
1578
- addProxyMethod(
1579
- verb,
1580
- EMPTY_STRING,
1581
- VALUES,
1582
- returnType,
1583
- getTheContentOfTheStoreDoc(2, verb),
1584
- params,
1585
- paramsInCall,
1586
- ),
1587
- );
1588
- addProxyMethod(
1589
- 0,
1590
- EMPTY_STRING,
1591
- VALUE_IDS,
1592
- valueIdType + SQUARE_BRACKETS,
1593
- getIdsDoc(VALUE, THE_STORE),
1594
- );
1595
- addProxyMethod(
1596
- 5,
1597
- EMPTY_STRING,
1598
- VALUE,
1599
- `void`,
1600
- getForEachDoc(VALUE, THE_STORE),
1601
- `valueCallback: ${valueCallbackType}`,
1602
- 'valueCallback as any',
1603
- );
1604
- mapValuesSchema((valueId, type, _, VALUE_ID, valueName) => {
1605
- const mapValueType = 'Map' + camel(type, 1);
1606
- mapSet(mapCellOrValueTypes, type, mapValueType);
1607
- arrayForEach(
1608
- [
1609
- [type],
1610
- [BOOLEAN],
1611
- [storeType, `value: ${type} | ` + mapValueType, ', value as any'],
1612
- [storeType],
1613
- ],
1614
- ([returnType, params, paramsInCall = EMPTY_STRING], verb) =>
1615
- addProxyMethod(
1616
- verb,
1617
- valueName,
1618
- VALUE,
1619
- returnType,
1620
- getValueContentDoc(valueId, verb),
1621
- params,
1622
- VALUE_ID + paramsInCall,
1623
- ),
1624
- );
1625
- });
1626
- addProxyMethod(
1627
- 0,
1628
- EMPTY_STRING,
1629
- VALUES + JSON$1,
1630
- JSON$1,
1631
- getTheContentOfTheStoreDoc(2, 6),
1632
- );
1633
- addProxyMethod(
1634
- 2,
1635
- EMPTY_STRING,
1636
- VALUES + JSON$1,
1637
- storeType,
1638
- getTheContentOfTheStoreDoc(2, 7),
1639
- 'valuesJson: ' + JSON$1,
1640
- 'values' + JSON$1,
1641
- );
1642
- addProxyListener(
1643
- HAS + VALUES,
1644
- hasValuesListenerType,
1645
- getTheContentOfTheStoreDoc(2, 8, 0, 1) + ' changes',
1646
- );
1647
- addProxyListener(
1648
- VALUES,
1649
- valuesListenerType,
1650
- getTheContentOfTheStoreDoc(2, 8) + ' changes',
1651
- );
1652
- addProxyListener(VALUE_IDS, valueIdsListenerType, getListenerDoc(10, 0, 1));
1653
- addProxyListener(
1654
- HAS + VALUE,
1655
- hasValueListenerType,
1656
- getListenerDoc(11, 0, 0, 1),
1657
- `valueId: ${valueIdType} | null`,
1658
- 'valueId',
1659
- );
1660
- addProxyListener(
1661
- VALUE,
1662
- valueListenerType,
1663
- getListenerDoc(11, 0),
1664
- `valueId: ${valueIdType} | null`,
1665
- 'valueId',
1666
- );
1667
- addProxyListener(
1668
- INVALID + VALUE,
1669
- invalidValueListenerType,
1670
- REGISTERS_A_LISTENER + ' whenever an invalid Value change was attempted',
1671
- `valueId: IdOrNull`,
1672
- 'valueId',
1673
- );
1674
- addImport(1, moduleDefinition, ...collValues(mapCellOrValueTypes));
1675
- addImport(0, TINYBASE, 'ValueChange');
1676
- arrayPush(
1677
- createSteps,
1678
- '.set' + VALUES + SCHEMA + '({',
1679
- mapValuesSchema((_, type, defaultValue, VALUE_ID) => [
1680
- `[${VALUE_ID}]: {[${addConstant(
1681
- snake(TYPE),
1682
- `'${TYPE}'`,
1683
- )}]: ${addConstant(snake(type), `'${type}'`)}${isUndefined(defaultValue) ? EMPTY_STRING : `, [${addConstant(snake(DEFAULT), `'${DEFAULT}'`)}]: ` + (isString(defaultValue) ? addConstant(snake(defaultValue), `'${defaultValue}'`) : defaultValue)}},`,
1684
- ]),
1685
- '})',
1686
- );
1687
- } else {
1688
- addImport(null, TINYBASE, VALUES);
1689
- }
1690
- addProxyMethod(
1691
- 0,
1692
- EMPTY_STRING,
1693
- 'Content',
1694
- `[${TABLES}, ${VALUES}]`,
1695
- getTheContentOfTheStoreDoc(0, 0),
1696
- );
1697
- addProxyMethod(
1698
- 2,
1699
- EMPTY_STRING,
1700
- 'Content',
1701
- storeType,
1702
- getTheContentOfTheStoreDoc(0, 2),
1703
- `[tables, values]: [${TABLES}, ${VALUES}]`,
1704
- '[tables, values]',
1705
- );
1706
- addProxyMethod(
1707
- 7,
1708
- EMPTY_STRING,
1709
- 'applyChanges',
1710
- storeType,
1711
- `Applies a set of ${CHANGES} to the Store`,
1712
- 'changes: ' + CHANGES,
1713
- 'changes',
1714
- );
1715
- mapForEach(mapCellOrValueTypes, (type, mapCellType) =>
1716
- addType(
1717
- mapCellType,
1718
- `(cell: ${type}${OR_UNDEFINED}) => ` + type,
1719
- `Takes a ${type} Cell value and returns another`,
1720
- ),
1721
- );
1722
- addImport(
1723
- null,
1724
- TINYBASE,
1725
- 'DoRollback',
1726
- ID,
1727
- 'IdOrNull',
1728
- JSON$1,
1729
- 'Store',
1730
- CHANGES,
1731
- );
1732
- addProxyMethod(
1733
- 0,
1734
- EMPTY_STRING,
1735
- JSON$1,
1736
- JSON$1,
1737
- getTheContentOfTheStoreDoc(0, 6),
1738
- );
1739
- addProxyMethod(
1740
- 2,
1741
- EMPTY_STRING,
1742
- JSON$1,
1743
- storeType,
1744
- getTheContentOfTheStoreDoc(0, 7),
1745
- 'tablesAndValuesJson: ' + JSON$1,
1746
- 'tablesAndValuesJson',
1747
- );
1748
- addProxyMethod(
1749
- 7,
1750
- EMPTY_STRING,
1751
- TRANSACTION_,
1752
- 'Return',
1753
- TRANSACTION_DOC,
1754
- DO_ACTIONS_AND_ROLLBACK_PARAMS,
1755
- 'actions, doRollback',
1756
- '<Return>',
1757
- );
1758
- addProxyMethod(
1759
- 7,
1760
- EMPTY_STRING,
1761
- 'start' + TRANSACTION,
1762
- storeType,
1763
- START_TRANSACTION_DOC,
1764
- );
1765
- addProxyMethod(
1766
- 7,
1767
- EMPTY_STRING,
1768
- 'finish' + TRANSACTION,
1769
- storeType,
1770
- FINISH_TRANSACTION_DOC,
1771
- DO_ROLLBACK_PARAM,
1772
- 'doRollback',
1773
- );
1774
- const transactionListenerType = getTransactionListenerType(
1775
- storeInstance,
1776
- storeType,
1777
- );
1778
- addProxyListener(
1779
- 'Start' + TRANSACTION,
1780
- transactionListenerType,
1781
- REGISTERS_A_LISTENER + ' just before the start of the ' + TRANSACTION_,
1782
- EMPTY_STRING,
1783
- EMPTY_STRING,
1784
- 0,
1785
- );
1786
- addProxyListener(
1787
- 'WillFinish' + TRANSACTION,
1788
- transactionListenerType,
1789
- REGISTERS_A_LISTENER + ' just before ' + THE_END_OF_THE_TRANSACTION,
1790
- EMPTY_STRING,
1791
- EMPTY_STRING,
1792
- 0,
1793
- );
1794
- addProxyListener(
1795
- 'DidFinish' + TRANSACTION,
1796
- transactionListenerType,
1797
- REGISTERS_A_LISTENER + ' just after ' + THE_END_OF_THE_TRANSACTION,
1798
- EMPTY_STRING,
1799
- EMPTY_STRING,
1800
- 0,
1801
- );
1802
- addProxyMethod(
1803
- 7,
1804
- EMPTY_STRING,
1805
- 'call' + LISTENER,
1806
- storeType,
1807
- 'Manually provoke a listener to be called',
1808
- 'listenerId: Id',
1809
- 'listenerId',
1810
- );
1811
- addProxyMethod(
1812
- 3,
1813
- EMPTY_STRING,
1814
- LISTENER,
1815
- storeType,
1816
- 'Remove a listener that was previously added to ' + THE_STORE,
1817
- 'listenerId: Id',
1818
- 'listenerId',
1819
- );
1820
- addMethod(
1821
- 'getStore',
1822
- EMPTY_STRING,
1823
- 'Store',
1824
- 'store',
1825
- VERBS[0] + ' the underlying Store object',
1826
- );
1827
- addImport(1, TINYBASE, 'createStore');
1828
- addImport(
1829
- 1,
1830
- moduleDefinition,
1831
- storeType,
1832
- `create${storeType} as create${storeType}Decl`,
1833
- transactionListenerType,
1834
- );
1835
- addConstant('store', ['createStore()', ...createSteps]);
1836
- addInternalFunction('fluent', 'actions: () => Store', [
1837
- 'actions();',
1838
- `return ${storeInstance};`,
1839
- ]);
1840
- addInternalFunction(
1841
- 'proxy',
1842
- `listener: any`,
1843
- `(_: Store, ...params: any[]) => listener(${storeInstance}, ...params)`,
1844
- );
1845
- addConstant(storeInstance, ['{', ...getMethods(1), '}']);
1846
- return [
1847
- build(
1848
- ...getImports(0),
1849
- ...getTypes(),
1850
- EXPORT + ' interface ' + storeType + ' {',
1851
- ...getMethods(0),
1852
- '}',
1853
- EMPTY_STRING,
1854
- comment(`Creates a ${storeType} object`),
1855
- EXPORT + ' function create' + storeType + '(): ' + storeType + ';',
1856
- ),
1857
- build(
1858
- ...getImports(1),
1859
- EXPORT +
1860
- ' const create' +
1861
- storeType +
1862
- ': typeof create' +
1863
- storeType +
1864
- 'Decl = () => {',
1865
- ...getConstants(),
1866
- `return Object.freeze(${storeInstance});`,
1867
- '};',
1868
- ),
1869
- sharedTableTypes,
1870
- sharedValueTypes,
1871
- ];
1872
- };
1873
-
1874
- const getGet = (noun) => GET + noun;
1875
- const getGetAndGetDeps = (noun) =>
1876
- getParameterList(getGet(noun), getGet(noun) + DEPS);
1877
- const DEBUG_IDS_PROP_TYPE = 'debugIds?: boolean';
1878
- const DEBUG_IDS_PROP = 'debugIds={debugIds}';
1879
- const THEN_DEPS = 'then' + DEPS_SUFFIX;
1880
- const PARAMETER = 'Parameter';
1881
- const GETTER_ARGS = ': (parameter: ' + PARAMETER + ', store: Store) => ';
1882
- const USE_CONTEXT = 'const contextValue = useContext(Context);';
1883
- const BASED_ON_A_PARAMETER = ', based on a parameter';
1884
- const COLON_SPACE = ': ';
1885
- const GENERIC_PARAMETER = '<' + PARAMETER + ',>';
1886
- const PARAMETERIZED_CALLBACK =
1887
- PARAMETER + 'ized' + CALLBACK + '<' + PARAMETER + '>';
1888
- const ROW_ID = 'rowId';
1889
- const ROW_ID_PROP = 'rowId={rowId}';
1890
- const SEPARATOR_AND_DEBUG_IDS = ', separator, debugIds';
1891
- const SEPARATOR_PROP_TYPE = 'separator?: ReactElement | string';
1892
- const THEN_PREFIX = 'then?: (store: Store';
1893
- const THEN_AND_THEN_DEPS = getParameterList(
1894
- THEN_PREFIX + ')' + RETURNS_VOID,
1895
- THEN_DEPS,
1896
- );
1897
- const THEN_AND_THEN_DEPS_IN_CALL = 'then, then' + DEPS;
1898
- const TYPED_ROW_ID = ROW_ID + COLON_SPACE + ID;
1899
- const VIEW = 'View';
1900
- const getListenerHookParams = (listenerType, ...extraParams) =>
1901
- getParameterList(
1902
- ...extraParams,
1903
- LISTENER_ + ': ' + listenerType,
1904
- LISTENER_ + DEPS_SUFFIX,
1905
- 'mutator?: boolean',
1906
- );
1907
- const getListenerHookParamsInCall = (...extraParams) =>
1908
- getParameterList(...extraParams, LISTENER_, LISTENER_ + DEPS, 'mutator');
1909
- const getStoreUiReactApi = (
1910
- tablesSchema,
1911
- valuesSchema,
1912
- module,
1913
- sharedTableTypes,
1914
- sharedValueTypes,
1915
- ) => {
1916
- const [
1917
- build,
1918
- addImport,
1919
- addType,
1920
- addInternalFunction,
1921
- addConstant,
1922
- getImports,
1923
- getTypes,
1924
- getConstants,
1925
- ] = getCodeFunctions();
1926
- const [mapTablesSchema, mapCellSchema, mapValuesSchema] = getSchemaFunctions(
1927
- tablesSchema,
1928
- valuesSchema,
1929
- addConstant,
1930
- );
1931
- const moduleDefinition = `./${camel(module)}.d`;
1932
- const uiReactModuleDefinition = `./${camel(module)}-ui-react.d`;
1933
- const tinyBaseUiReact = 'tinybase/ui-react';
1934
- const storeType = camel(module, 1);
1935
- const storeInstance = camel(storeType);
1936
- const StoreOrStoreId = storeType + 'Or' + storeType + ID;
1937
- const storeOrStoreId = storeInstance + 'Or' + storeType + ID;
1938
- const storeProp = storeInstance + `={${storeInstance}}`;
1939
- const functions = mapNew();
1940
- const addFunction = (
1941
- name,
1942
- parameters,
1943
- returnType,
1944
- body,
1945
- doc,
1946
- generic = EMPTY_STRING,
1947
- ) => {
1948
- addImport(1, uiReactModuleDefinition, name + ' as ' + name + 'Decl');
1949
- return mapUnique(functions, name, [
1950
- parameters,
1951
- returnType,
1952
- body,
1953
- doc,
1954
- generic,
1955
- ]);
1956
- };
1957
- const addHook = (
1958
- name,
1959
- parameters,
1960
- returnType,
1961
- body,
1962
- doc,
1963
- generic = EMPTY_STRING,
1964
- ) => addFunction(`use${name}`, parameters, returnType, body, doc, generic);
1965
- const addProxyHook = (
1966
- name,
1967
- underlyingName,
1968
- returnType,
1969
- doc,
1970
- preParameters = EMPTY_STRING,
1971
- preParametersInCall = EMPTY_STRING,
1972
- generic = EMPTY_STRING,
1973
- postParameters = EMPTY_STRING,
1974
- postParametersInCall = EMPTY_STRING,
1975
- ) => {
1976
- addImport(
1977
- 1,
1978
- tinyBaseUiReact,
1979
- `use${underlyingName} as use${underlyingName}Core`,
1980
- );
1981
- return addHook(
1982
- name,
1983
- getParameterList(preParameters, storeOrStoreIdParameter, postParameters),
1984
- returnType,
1985
- useHook +
1986
- `(${storeOrStoreId}, use${underlyingName}Core, [` +
1987
- (preParametersInCall ? preParametersInCall : EMPTY_STRING) +
1988
- (postParametersInCall ? '], [' + postParametersInCall : EMPTY_STRING) +
1989
- ']);',
1990
- doc,
1991
- generic,
1992
- );
1993
- };
1994
- const addComponent = (name, parameters, body, doc) =>
1995
- addFunction(name, parameters, 1, body, doc);
1996
- const getFunctions = (location = 0) =>
1997
- mapMap(functions, ([parameters, returnType, body, doc, generic], name) => {
1998
- const lines = location
1999
- ? [
2000
- EXPORT +
2001
- ` const ${name}: typeof ${name}Decl = ${generic}(${parameters}): ${returnType == 1 ? 'any' : returnType} =>`,
2002
- body,
2003
- ]
2004
- : [
2005
- EXPORT +
2006
- ` function ${name}${generic}(${parameters}): ${returnType == 1 ? 'ComponentReturnType' : returnType};`,
2007
- ];
2008
- if (!location) {
2009
- arrayUnshift(lines, comment(doc));
2010
- }
2011
- arrayPush(lines, EMPTY_STRING);
2012
- return lines;
2013
- });
2014
- addImport(
2015
- null,
2016
- TINYBASE,
2017
- ID,
2018
- 'Store',
2019
- CALLBACK,
2020
- PARAMETER + 'ized' + CALLBACK,
2021
- );
2022
- addImport(0, tinyBaseUiReact, 'ComponentReturnType');
2023
- addImport(1, tinyBaseUiReact, 'useCellIds');
2024
- addImport(null, tinyBaseUiReact, 'ExtraProps');
2025
- addImport(0, moduleDefinition, storeType);
2026
- const storeOrStoreIdType = addType(
2027
- StoreOrStoreId,
2028
- storeType + ' | ' + ID,
2029
- `Used when you need to refer to a ${storeType} in a React hook or component`,
2030
- );
2031
- const providerPropsType = addType(
2032
- PROVIDER + PROPS,
2033
- getPropTypeList(
2034
- storeInstance + OPTIONAL_COLON + storeType,
2035
- storeInstance + `ById?: {[${storeInstance}Id: Id]: ${storeType}}`,
2036
- ),
2037
- `Used with the ${PROVIDER} component, so that a ` +
2038
- storeType +
2039
- ' can be passed into the context of an application',
2040
- );
2041
- addImport(0, 'react', 'ReactElement', 'ComponentType');
2042
- addImport(1, 'react', 'React');
2043
- addImport(1, uiReactModuleDefinition, storeOrStoreIdType, providerPropsType);
2044
- const storeOrStoreIdParameter =
2045
- storeOrStoreId + OPTIONAL_COLON + storeOrStoreIdType;
2046
- addConstant('{createContext, useContext, useMemo}', 'React');
2047
- addConstant(
2048
- 'Context',
2049
- `createContext<[${storeType}?, {[${storeInstance}Id: Id]: ${storeType}}?]>([])`,
2050
- );
2051
- addHook(
2052
- `Create${storeType}`,
2053
- `create: () => ${storeType}, create` + DEPS_SUFFIX,
2054
- storeType,
2055
- '\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)',
2056
- `Create a ${storeType} within a React application with convenient memoization`,
2057
- );
2058
- const getStoreHook = addHook(
2059
- storeType,
2060
- `id?: Id`,
2061
- storeType + OR_UNDEFINED,
2062
- [
2063
- '{',
2064
- USE_CONTEXT,
2065
- 'return id == null ? contextValue[0] : contextValue[1]?.[id];',
2066
- '}',
2067
- ],
2068
- `Get a reference to a ${storeType} from within a ${PROVIDER} component context`,
2069
- );
2070
- const useHook = addInternalFunction(
2071
- `useHook`,
2072
- storeOrStoreId +
2073
- `: ${storeOrStoreIdType} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,
2074
- [
2075
- `const ${storeInstance} = ${getStoreHook}(${storeOrStoreId} as Id);`,
2076
- `return hook(...preParams, ((${storeOrStoreId} == null || typeof ${storeOrStoreId} == 'string')`,
2077
- `? ${storeInstance} : ${storeOrStoreId})?.getStore(), ...postParams)`,
2078
- ],
2079
- );
2080
- const getProps = addInternalFunction(
2081
- 'getProps',
2082
- 'getProps: ((id: any) => ExtraProps) | undefined, id: Id',
2083
- '(getProps == null) ? ({} as ExtraProps) : getProps(id)',
2084
- );
2085
- const wrap = addInternalFunction(
2086
- 'wrap',
2087
- getParameterList(
2088
- 'children: any',
2089
- 'separator?: any',
2090
- 'encloseWithId?: boolean',
2091
- 'id?: Id',
2092
- ),
2093
- [
2094
- 'const separated = separator==null || !Array.isArray(children)',
2095
- ' ? children',
2096
- ' : children.map((child, c) => (c > 0 ? [separator, child] : child));',
2097
- `return encloseWithId ? [id, ':{', separated, '}'] : separated;`,
2098
- ],
2099
- );
2100
- const useCustomOrDefaultCellIds = addInternalFunction(
2101
- 'useCustomOrDefaultCellIds',
2102
- getParameterList(
2103
- 'customCellIds: Ids | undefined',
2104
- 'tableId: Id',
2105
- 'rowId: Id',
2106
- `${storeOrStoreId}?: ${storeOrStoreIdType} | undefined`,
2107
- ),
2108
- [
2109
- `const defaultCellIds = ${useHook}(${storeOrStoreId}, useCellIds, [tableId, rowId]);`,
2110
- 'return customCellIds ?? defaultCellIds;',
2111
- ],
2112
- );
2113
- const NullComponent = addConstant('NullComponent', `() => null`);
2114
- if (!objIsEmpty(tablesSchema)) {
2115
- const [
2116
- tablesType,
2117
- tablesWhenSetType,
2118
- tableIdType,
2119
- cellIdType,
2120
- hasTablesListenerType,
2121
- tablesListenerType,
2122
- tableIdsListenerType,
2123
- hasTableListenerType,
2124
- tableListenerType,
2125
- tableCellIdsListenerType,
2126
- hasTableCellListenerType,
2127
- rowCountListenerType,
2128
- rowIdsListenerType,
2129
- sortedRowIdsListenerType,
2130
- hasRowListenerType,
2131
- rowListenerType,
2132
- cellIdsListenerType,
2133
- hasCellListenerType,
2134
- cellListenerType,
2135
- tablesTypes,
2136
- ] = sharedTableTypes;
2137
- addImport(
2138
- null,
2139
- moduleDefinition,
2140
- tablesType,
2141
- tablesWhenSetType,
2142
- tableIdType,
2143
- hasTablesListenerType,
2144
- tablesListenerType,
2145
- tableIdsListenerType,
2146
- hasTableListenerType,
2147
- tableListenerType,
2148
- tableCellIdsListenerType,
2149
- hasTableCellListenerType,
2150
- rowCountListenerType,
2151
- rowIdsListenerType,
2152
- sortedRowIdsListenerType,
2153
- hasRowListenerType,
2154
- rowListenerType,
2155
- cellIdsListenerType,
2156
- cellListenerType,
2157
- hasCellListenerType,
2158
- );
2159
- addImport(0, moduleDefinition, cellIdType);
2160
- addImport(1, moduleDefinition, storeType);
2161
- addImport(null, TINYBASE, IDS, 'IdOrNull');
2162
- const tableView = addInternalFunction(
2163
- 'tableView',
2164
- `{${storeInstance}, rowComponent, getRowComponentProps, customCellIds` +
2165
- SEPARATOR_AND_DEBUG_IDS +
2166
- '}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>',
2167
- [
2168
- 'const Row = rowComponent ?? defaultRowComponent;',
2169
- `return ${wrap}(rowIds.map((rowId) => (`,
2170
- '<Row',
2171
- '{...' + getProps + '(getRowComponentProps, rowId)}',
2172
- 'key={rowId}',
2173
- 'tableId={tableId}',
2174
- ROW_ID_PROP,
2175
- 'customCellIds={customCellIds}',
2176
- storeProp,
2177
- DEBUG_IDS_PROP,
2178
- '/>',
2179
- '))',
2180
- SEPARATOR_AND_DEBUG_IDS,
2181
- ', tableId,',
2182
- ');',
2183
- ],
2184
- );
2185
- const getDefaultTableComponent = addInternalFunction(
2186
- 'getDefaultTableComponent',
2187
- 'tableId: Id',
2188
- arrayJoin(
2189
- mapTablesSchema(
2190
- (_, tableName, TABLE_ID) =>
2191
- `tableId == ${TABLE_ID} ? ${tableName}TableView : `,
2192
- ),
2193
- ) + NullComponent,
2194
- );
2195
- const getDefaultCellComponent = addInternalFunction(
2196
- 'getDefaultCellComponent',
2197
- 'tableId: Id, cellId: Id',
2198
- arrayJoin(
2199
- mapTablesSchema(
2200
- (tableId, tableName, TABLE_ID) =>
2201
- `tableId == ${TABLE_ID} ? ${
2202
- arrayJoin(
2203
- mapCellSchema(
2204
- tableId,
2205
- (_, _2, _3, CELL_ID, cellName) =>
2206
- `cellId == ${CELL_ID} ? ` +
2207
- tableName +
2208
- cellName +
2209
- 'CellView : ',
2210
- ),
2211
- ) + NullComponent
2212
- } : `,
2213
- ),
2214
- ) + NullComponent,
2215
- );
2216
- addProxyHook(
2217
- HAS + TABLES,
2218
- HAS + TABLES,
2219
- BOOLEAN,
2220
- getTheContentOfTheStoreDoc(1, 0, 0, 1) + AND_REGISTERS,
2221
- );
2222
- addProxyHook(
2223
- TABLES,
2224
- TABLES,
2225
- tablesType,
2226
- getTheContentOfTheStoreDoc(1, 0) + AND_REGISTERS,
2227
- );
2228
- const useTableIds = addProxyHook(
2229
- TABLE_IDS,
2230
- TABLE_IDS,
2231
- tableIdType + SQUARE_BRACKETS,
2232
- getIdsDoc(TABLE, THE_STORE) + AND_REGISTERS,
2233
- );
2234
- addProxyHook(
2235
- SET + TABLES + CALLBACK,
2236
- SET + TABLES + CALLBACK,
2237
- PARAMETERIZED_CALLBACK,
2238
- getTheContentOfTheStoreDoc(1, 9) + BASED_ON_A_PARAMETER,
2239
- getParameterList(
2240
- getGet(TABLES) + GETTER_ARGS + tablesWhenSetType,
2241
- getGet(TABLES) + DEPS_SUFFIX,
2242
- ),
2243
- getGetAndGetDeps(TABLES),
2244
- GENERIC_PARAMETER,
2245
- getParameterList(
2246
- THEN_PREFIX,
2247
- `tables: ${tablesWhenSetType})` + RETURNS_VOID,
2248
- THEN_DEPS,
2249
- ),
2250
- THEN_AND_THEN_DEPS_IN_CALL,
2251
- );
2252
- addProxyHook(
2253
- DEL + TABLES + CALLBACK,
2254
- DEL + TABLES + CALLBACK,
2255
- CALLBACK,
2256
- getTheContentOfTheStoreDoc(1, 12),
2257
- EMPTY_STRING,
2258
- EMPTY_STRING,
2259
- EMPTY_STRING,
2260
- THEN_AND_THEN_DEPS,
2261
- THEN_AND_THEN_DEPS_IN_CALL,
2262
- );
2263
- const cellPropsType = addType(
2264
- CELL + PROPS,
2265
- getPropTypeList(
2266
- 'tableId?: TId',
2267
- 'rowId: Id',
2268
- 'cellId?: CId',
2269
- storeInstance + OPTIONAL_COLON + storeType,
2270
- DEBUG_IDS_PROP_TYPE,
2271
- ),
2272
- getPropsDoc(A + CELL),
2273
- `<TId extends ${tableIdType}, CId extends ${cellIdType}<TId>>`,
2274
- );
2275
- const rowPropsType = addType(
2276
- ROW + PROPS,
2277
- getPropTypeList(
2278
- `tableId?: TId`,
2279
- 'rowId: Id',
2280
- storeInstance + OPTIONAL_COLON + storeType,
2281
- 'cellComponents?: {readonly [CId in ' +
2282
- cellIdType +
2283
- `<TId>]?: ComponentType<${cellPropsType}<TId, CId>>;}`,
2284
- `getCellComponentProps?: (cellId: ${cellIdType}<TId>) => ExtraProps`,
2285
- `customCellIds?: ${cellIdType}<TId>[]`,
2286
- SEPARATOR_PROP_TYPE,
2287
- DEBUG_IDS_PROP_TYPE,
2288
- ),
2289
- getPropsDoc(A + ROW),
2290
- `<TId extends ${tableIdType}>`,
2291
- );
2292
- const tablePropsType = addType(
2293
- TABLE + PROPS,
2294
- getPropTypeList(
2295
- `tableId?: TId`,
2296
- storeInstance + OPTIONAL_COLON + storeType,
2297
- `rowComponent?: ComponentType<${rowPropsType}<TId>>`,
2298
- `getRowComponentProps?: (rowId: Id) => ExtraProps`,
2299
- `customCellIds?: CellId<TId>[]`,
2300
- SEPARATOR_PROP_TYPE,
2301
- DEBUG_IDS_PROP_TYPE,
2302
- ),
2303
- getPropsDoc(A + TABLE),
2304
- `<TId extends ${tableIdType}>`,
2305
- );
2306
- const sortedTablePropsType = addType(
2307
- 'Sorted' + TABLE + PROPS,
2308
- getPropTypeList(
2309
- `tableId?: TId`,
2310
- 'cellId?: ' + cellIdType + '<TId>',
2311
- 'descending?: boolean',
2312
- 'offset?: number',
2313
- 'limit?: number',
2314
- storeInstance + OPTIONAL_COLON + storeType,
2315
- `rowComponent?: ComponentType<${rowPropsType}<TId>>`,
2316
- `getRowComponentProps?: (rowId: Id) => ExtraProps`,
2317
- `customCellIds?: CellId<TId>[]`,
2318
- SEPARATOR_PROP_TYPE,
2319
- DEBUG_IDS_PROP_TYPE,
2320
- ),
2321
- getPropsDoc(A + 'sorted ' + TABLE),
2322
- `<TId extends ${tableIdType}>`,
2323
- );
2324
- const tablesPropsType = addType(
2325
- TABLES + PROPS,
2326
- getPropTypeList(
2327
- storeInstance + OPTIONAL_COLON + storeType,
2328
- 'tableComponents?: {readonly [TId in ' +
2329
- tableIdType +
2330
- `]?: ComponentType<${tablePropsType}<TId>>;}`,
2331
- `getTableComponentProps?: (tableId: ${tableIdType}) => ExtraProps`,
2332
- SEPARATOR_PROP_TYPE,
2333
- DEBUG_IDS_PROP_TYPE,
2334
- ),
2335
- getPropsDoc(getTheContentOfDoc(1, 1)),
2336
- );
2337
- addImport(
2338
- 1,
2339
- uiReactModuleDefinition,
2340
- tablesPropsType,
2341
- tablePropsType,
2342
- sortedTablePropsType,
2343
- rowPropsType,
2344
- cellPropsType,
2345
- );
2346
- addComponent(
2347
- TABLES + VIEW,
2348
- '{' +
2349
- storeInstance +
2350
- ', tableComponents, getTableComponentProps' +
2351
- SEPARATOR_AND_DEBUG_IDS +
2352
- '}: ' +
2353
- tablesPropsType,
2354
- [
2355
- wrap + `(${useTableIds}(${storeInstance}).map((tableId) => {`,
2356
- 'const Table = (tableComponents?.[tableId] ?? ' +
2357
- getDefaultTableComponent +
2358
- `(tableId)) as React.ComponentType<TableProps<typeof tableId>>;`,
2359
- 'return <Table',
2360
- `{...${getProps}(getTableComponentProps, tableId)}`,
2361
- 'tableId={tableId}',
2362
- 'key={tableId}',
2363
- storeProp,
2364
- DEBUG_IDS_PROP,
2365
- '/>;',
2366
- '}), separator)',
2367
- ],
2368
- getTheContentOfTheStoreDoc(1, 13) + AND_REGISTERS,
2369
- );
2370
- mapTablesSchema((tableId, tableName, TABLE_ID) => {
2371
- const [
2372
- tableType,
2373
- tableWhenSetType,
2374
- rowType,
2375
- rowWhenSetType,
2376
- cellIdType2,
2377
- ] = mapGet(tablesTypes, tableId);
2378
- addImport(
2379
- null,
2380
- moduleDefinition,
2381
- tableType,
2382
- tableWhenSetType,
2383
- rowType,
2384
- rowWhenSetType,
2385
- cellIdType2,
2386
- );
2387
- addProxyHook(
2388
- HAS + tableName + TABLE,
2389
- HAS + TABLE,
2390
- BOOLEAN,
2391
- getTableContentDoc(tableId, 0, 1) + AND_REGISTERS,
2392
- EMPTY_STRING,
2393
- TABLE_ID,
2394
- );
2395
- addProxyHook(
2396
- tableName + TABLE,
2397
- TABLE,
2398
- tableType,
2399
- getTableContentDoc(tableId) + AND_REGISTERS,
2400
- EMPTY_STRING,
2401
- TABLE_ID,
2402
- );
2403
- addProxyHook(
2404
- tableName + TABLE + CELL_IDS,
2405
- TABLE + CELL_IDS,
2406
- IDS,
2407
- getIdsDoc(CELL, 'the whole of ' + getTableDoc(tableId)) + AND_REGISTERS,
2408
- EMPTY_STRING,
2409
- TABLE_ID,
2410
- );
2411
- addProxyHook(
2412
- tableName + ROW + COUNT,
2413
- ROW + COUNT,
2414
- NUMBER,
2415
- 'Gets the number of Rows in ' + getTableDoc(tableId) + AND_REGISTERS,
2416
- EMPTY_STRING,
2417
- TABLE_ID,
2418
- );
2419
- const useRowIds = addProxyHook(
2420
- tableName + ROW_IDS,
2421
- ROW_IDS,
2422
- IDS,
2423
- getIdsDoc(ROW, getTableDoc(tableId)) + AND_REGISTERS,
2424
- EMPTY_STRING,
2425
- TABLE_ID,
2426
- );
2427
- const useSortedRowIds = addProxyHook(
2428
- tableName + SORTED_ROW_IDS,
2429
- SORTED_ROW_IDS,
2430
- IDS,
2431
- getIdsDoc(ROW, getTableDoc(tableId), 1) + AND_REGISTERS,
2432
- 'cellId?: ' +
2433
- cellIdType2 +
2434
- ', descending?: boolean, offset?: number, limit?: number',
2435
- TABLE_ID + ', cellId, descending, offset, limit',
2436
- );
2437
- addProxyHook(
2438
- HAS + tableName + ROW,
2439
- HAS + ROW,
2440
- BOOLEAN,
2441
- getRowContentDoc(tableId, 0, 1) + AND_REGISTERS,
2442
- TYPED_ROW_ID,
2443
- getParameterList(TABLE_ID, ROW_ID),
2444
- );
2445
- addProxyHook(
2446
- tableName + ROW,
2447
- ROW,
2448
- rowType,
2449
- getRowContentDoc(tableId) + AND_REGISTERS,
2450
- TYPED_ROW_ID,
2451
- getParameterList(TABLE_ID, ROW_ID),
2452
- );
2453
- addProxyHook(
2454
- tableName + CELL_IDS,
2455
- CELL_IDS,
2456
- cellIdType2 + SQUARE_BRACKETS,
2457
- getIdsDoc(CELL, getRowDoc(tableId)) + AND_REGISTERS,
2458
- TYPED_ROW_ID,
2459
- getParameterList(TABLE_ID, ROW_ID),
2460
- );
2461
- addProxyHook(
2462
- SET + tableName + TABLE + CALLBACK,
2463
- SET + TABLE + CALLBACK,
2464
- PARAMETERIZED_CALLBACK,
2465
- getTableContentDoc(tableId, 9) + BASED_ON_A_PARAMETER,
2466
- getParameterList(
2467
- getGet(TABLE) + GETTER_ARGS + tableWhenSetType,
2468
- getGet(TABLE) + DEPS_SUFFIX,
2469
- ),
2470
- getParameterList(TABLE_ID, getGetAndGetDeps(TABLE)),
2471
- GENERIC_PARAMETER,
2472
- getParameterList(
2473
- THEN_PREFIX,
2474
- `table: ${tableWhenSetType})` + RETURNS_VOID,
2475
- THEN_DEPS,
2476
- ),
2477
- THEN_AND_THEN_DEPS_IN_CALL,
2478
- );
2479
- addProxyHook(
2480
- DEL + tableName + TABLE + CALLBACK,
2481
- DEL + TABLE + CALLBACK,
2482
- CALLBACK,
2483
- getTableContentDoc(tableId, 12),
2484
- EMPTY_STRING,
2485
- TABLE_ID,
2486
- EMPTY_STRING,
2487
- THEN_AND_THEN_DEPS,
2488
- THEN_AND_THEN_DEPS_IN_CALL,
2489
- );
2490
- addProxyHook(
2491
- SET + tableName + ROW + CALLBACK,
2492
- SET + ROW + CALLBACK,
2493
- PARAMETERIZED_CALLBACK,
2494
- getRowContentDoc(tableId, 9) + BASED_ON_A_PARAMETER,
2495
- getParameterList(
2496
- TYPED_ROW_ID,
2497
- getGet(ROW) + GETTER_ARGS + rowWhenSetType,
2498
- getGet(ROW) + DEPS_SUFFIX,
2499
- ),
2500
- getParameterList(TABLE_ID, ROW_ID, getGetAndGetDeps(ROW)),
2501
- GENERIC_PARAMETER,
2502
- getParameterList(
2503
- THEN_PREFIX,
2504
- `row: ${rowWhenSetType})` + RETURNS_VOID,
2505
- THEN_DEPS,
2506
- ),
2507
- THEN_AND_THEN_DEPS_IN_CALL,
2508
- );
2509
- addProxyHook(
2510
- 'Add' + tableName + ROW + CALLBACK,
2511
- 'Add' + ROW + CALLBACK,
2512
- PARAMETERIZED_CALLBACK,
2513
- getRowContentDoc(tableId, 10) + BASED_ON_A_PARAMETER,
2514
- getParameterList(
2515
- getGet(ROW) + GETTER_ARGS + rowWhenSetType,
2516
- getGet(ROW) + DEPS_SUFFIX,
2517
- ),
2518
- getParameterList(TABLE_ID, getGetAndGetDeps(ROW)),
2519
- GENERIC_PARAMETER,
2520
- 'then?: (' +
2521
- getParameterList(
2522
- TYPED_ROW_ID + OR_UNDEFINED,
2523
- 'store: Store',
2524
- 'row: ' + rowWhenSetType + ')' + RETURNS_VOID,
2525
- 'then' + DEPS_SUFFIX,
2526
- ) +
2527
- ', reuseRowIds?: boolean',
2528
- THEN_AND_THEN_DEPS_IN_CALL + ', reuseRowIds',
2529
- );
2530
- addProxyHook(
2531
- SET + tableName + PARTIAL + ROW + CALLBACK,
2532
- SET + PARTIAL + ROW + CALLBACK,
2533
- PARAMETERIZED_CALLBACK,
2534
- getRowContentDoc(tableId, 11) + BASED_ON_A_PARAMETER,
2535
- getParameterList(
2536
- TYPED_ROW_ID,
2537
- getGet(PARTIAL + ROW) + GETTER_ARGS + rowWhenSetType,
2538
- getGet(PARTIAL + ROW) + DEPS_SUFFIX,
2539
- ),
2540
- getParameterList(TABLE_ID, ROW_ID, getGetAndGetDeps(PARTIAL + ROW)),
2541
- GENERIC_PARAMETER,
2542
- getParameterList(
2543
- THEN_PREFIX,
2544
- `partialRow: ${rowWhenSetType})` + RETURNS_VOID,
2545
- THEN_DEPS,
2546
- ),
2547
- THEN_AND_THEN_DEPS_IN_CALL,
2548
- );
2549
- addProxyHook(
2550
- DEL + tableName + ROW + CALLBACK,
2551
- DEL + ROW + CALLBACK,
2552
- CALLBACK,
2553
- getRowContentDoc(tableId, 12),
2554
- TYPED_ROW_ID,
2555
- getParameterList(TABLE_ID, ROW_ID),
2556
- EMPTY_STRING,
2557
- THEN_AND_THEN_DEPS,
2558
- THEN_AND_THEN_DEPS_IN_CALL,
2559
- );
2560
- const rowView = addComponent(
2561
- tableName + ROW + VIEW,
2562
- '{rowId, ' +
2563
- storeInstance +
2564
- ', cellComponents, getCellComponentProps, customCellIds' +
2565
- SEPARATOR_AND_DEBUG_IDS +
2566
- `}: ${rowPropsType}<'${tableId}'>`,
2567
- [
2568
- wrap +
2569
- `(${useCustomOrDefaultCellIds}(customCellIds, ` +
2570
- TABLE_ID +
2571
- `, rowId, ${storeInstance}).map((cellId: ${cellIdType2}) => {`,
2572
- 'const Cell = (cellComponents?.[cellId] ?? ' +
2573
- getDefaultCellComponent +
2574
- `(${TABLE_ID}, cellId)) as React.ComponentType<CellProps<typeof ` +
2575
- TABLE_ID +
2576
- ', typeof cellId>>;',
2577
- 'return <Cell',
2578
- `{...${getProps}(getCellComponentProps, cellId)} `,
2579
- 'key={cellId}',
2580
- `tableId={${TABLE_ID}}`,
2581
- ROW_ID_PROP,
2582
- 'cellId={cellId}',
2583
- storeProp,
2584
- DEBUG_IDS_PROP,
2585
- '/>;',
2586
- '})' + SEPARATOR_AND_DEBUG_IDS + ', rowId)',
2587
- ],
2588
- getRowContentDoc(tableId, 13) + AND_REGISTERS,
2589
- );
2590
- addComponent(
2591
- tableName + 'Sorted' + TABLE + VIEW,
2592
- '{cellId, descending, offset, limit, ...props}: ' +
2593
- sortedTablePropsType +
2594
- `<'${tableId}'>`,
2595
- tableView +
2596
- '(props, ' +
2597
- useSortedRowIds +
2598
- `(cellId, descending, offset, limit, props.${storeInstance}), ${TABLE_ID}, ${rowView});`,
2599
- getTableContentDoc(tableId, 13) + ', sorted' + AND_REGISTERS,
2600
- );
2601
- addComponent(
2602
- tableName + TABLE + VIEW,
2603
- `props: ${tablePropsType}<'${tableId}'>`,
2604
- tableView +
2605
- '(props, ' +
2606
- useRowIds +
2607
- `(props.${storeInstance}), ${TABLE_ID}, ${rowView});`,
2608
- getTableContentDoc(tableId, 13) + AND_REGISTERS,
2609
- );
2610
- mapCellSchema(
2611
- tableId,
2612
- (cellId, type, defaultValue, CELL_ID, cellName) => {
2613
- const mapCellType = 'Map' + camel(type, 1);
2614
- addImport(0, moduleDefinition, mapCellType);
2615
- addImport(1, moduleDefinition, mapCellType);
2616
- addProxyHook(
2617
- HAS + tableName + cellName + TABLE + CELL,
2618
- HAS + TABLE + CELL,
2619
- BOOLEAN,
2620
- `Gets ${getHasDoc(1)}the '${cellId}' Cell anywhere in ` +
2621
- getTableDoc(tableId) +
2622
- AND_REGISTERS,
2623
- EMPTY_STRING,
2624
- getParameterList(TABLE_ID, CELL_ID),
2625
- );
2626
- addProxyHook(
2627
- HAS + tableName + cellName + CELL,
2628
- HAS + CELL,
2629
- BOOLEAN,
2630
- getCellContentDoc(tableId, cellId, 0, 1) + AND_REGISTERS,
2631
- TYPED_ROW_ID,
2632
- getParameterList(TABLE_ID, ROW_ID, CELL_ID),
2633
- );
2634
- const useCell = addProxyHook(
2635
- tableName + cellName + CELL,
2636
- CELL,
2637
- type + (isUndefined(defaultValue) ? OR_UNDEFINED : EMPTY_STRING),
2638
- getCellContentDoc(tableId, cellId) + AND_REGISTERS,
2639
- TYPED_ROW_ID,
2640
- getParameterList(TABLE_ID, ROW_ID, CELL_ID),
2641
- );
2642
- addProxyHook(
2643
- SET + tableName + cellName + CELL + CALLBACK,
2644
- SET + CELL + CALLBACK,
2645
- PARAMETERIZED_CALLBACK,
2646
- getCellContentDoc(tableId, cellId, 9) + BASED_ON_A_PARAMETER,
2647
- getParameterList(
2648
- TYPED_ROW_ID,
2649
- getGet(CELL) + GETTER_ARGS + type + ' | ' + mapCellType,
2650
- getGet(CELL) + DEPS_SUFFIX,
2651
- ),
2652
- getParameterList(TABLE_ID, ROW_ID, CELL_ID, getGetAndGetDeps(CELL)),
2653
- GENERIC_PARAMETER,
2654
- getParameterList(
2655
- THEN_PREFIX,
2656
- `cell: ${type} | ${mapCellType})` + RETURNS_VOID,
2657
- THEN_DEPS,
2658
- ),
2659
- THEN_AND_THEN_DEPS_IN_CALL,
2660
- );
2661
- addProxyHook(
2662
- DEL + tableName + cellName + CELL + CALLBACK,
2663
- DEL + CELL + CALLBACK,
2664
- CALLBACK,
2665
- getCellContentDoc(tableId, cellId, 12),
2666
- getParameterList(TYPED_ROW_ID, 'forceDel?: boolean'),
2667
- getParameterList(TABLE_ID, ROW_ID, CELL_ID, 'forceDel'),
2668
- EMPTY_STRING,
2669
- THEN_AND_THEN_DEPS,
2670
- THEN_AND_THEN_DEPS_IN_CALL,
2671
- );
2672
- addComponent(
2673
- tableName + cellName + CELL + VIEW,
2674
- `{rowId, ${storeInstance}, debugIds}: ` +
2675
- cellPropsType +
2676
- `<'${tableId}', '${cellId}'>`,
2677
- [
2678
- wrap +
2679
- `('' + ${useCell}(rowId, ` +
2680
- storeInstance +
2681
- `) ?? '', undefined, debugIds, ${CELL_ID})`,
2682
- ],
2683
- getCellContentDoc(tableId, cellId, 13) + AND_REGISTERS,
2684
- );
2685
- },
2686
- );
2687
- });
2688
- const cellIdsType = arrayJoin(
2689
- mapTablesSchema(
2690
- (tableId) => mapGet(tablesTypes, tableId)?.[4] ?? EMPTY_STRING,
2691
- ),
2692
- ' | ',
2693
- );
2694
- addProxyHook(
2695
- HAS + TABLES + LISTENER,
2696
- HAS + TABLES + LISTENER,
2697
- VOID,
2698
- getTheContentOfTheStoreDoc(1, 8, 0, 1) + ' changes',
2699
- getListenerHookParams(hasTablesListenerType),
2700
- getListenerHookParamsInCall(),
2701
- );
2702
- addProxyHook(
2703
- TABLES + LISTENER,
2704
- TABLES + LISTENER,
2705
- VOID,
2706
- getTheContentOfTheStoreDoc(1, 8) + ' changes',
2707
- getListenerHookParams(tablesListenerType),
2708
- getListenerHookParamsInCall(),
2709
- );
2710
- addProxyHook(
2711
- TABLE_IDS + LISTENER,
2712
- TABLE_IDS + LISTENER,
2713
- VOID,
2714
- getListenerDoc(2, 0, 1),
2715
- getListenerHookParams(tableIdsListenerType),
2716
- getListenerHookParamsInCall(),
2717
- );
2718
- addProxyHook(
2719
- HAS + TABLE + LISTENER,
2720
- HAS + TABLE + LISTENER,
2721
- VOID,
2722
- getListenerDoc(3, 0, 0, 1),
2723
- getListenerHookParams(
2724
- hasTableListenerType,
2725
- `tableId: ${tableIdType} | null`,
2726
- ),
2727
- getListenerHookParamsInCall('tableId'),
2728
- );
2729
- addProxyHook(
2730
- TABLE + LISTENER,
2731
- TABLE + LISTENER,
2732
- VOID,
2733
- getListenerDoc(3, 0),
2734
- getListenerHookParams(
2735
- tableListenerType,
2736
- `tableId: ${tableIdType} | null`,
2737
- ),
2738
- getListenerHookParamsInCall('tableId'),
2739
- );
2740
- addProxyHook(
2741
- TABLE + CELL_IDS + LISTENER,
2742
- TABLE + CELL_IDS + LISTENER,
2743
- VOID,
2744
- getListenerDoc(14, 3, 1),
2745
- getListenerHookParams(
2746
- tableCellIdsListenerType,
2747
- `tableId: ${tableIdType} | null`,
2748
- ),
2749
- getListenerHookParamsInCall('tableId'),
2750
- );
2751
- addProxyHook(
2752
- HAS + TABLE + CELL + LISTENER,
2753
- HAS + TABLE + CELL + LISTENER,
2754
- VOID,
2755
- getListenerDoc(16, 3, 0, 1),
2756
- getListenerHookParams(
2757
- hasTableCellListenerType,
2758
- `tableId: ${tableIdType} | null`,
2759
- `cellId: ${cellIdsType} | null`,
2760
- ),
2761
- getListenerHookParamsInCall('tableId', 'cellId'),
2762
- );
2763
- addProxyHook(
2764
- ROW + COUNT + LISTENER,
2765
- ROW + COUNT + LISTENER,
2766
- VOID,
2767
- getListenerDoc(15, 3),
2768
- getListenerHookParams(
2769
- rowCountListenerType,
2770
- `tableId: ${tableIdType} | null`,
2771
- ),
2772
- getListenerHookParamsInCall('tableId'),
2773
- );
2774
- addProxyHook(
2775
- ROW_IDS + LISTENER,
2776
- ROW_IDS + LISTENER,
2777
- VOID,
2778
- getListenerDoc(4, 3, 1),
2779
- getListenerHookParams(
2780
- rowIdsListenerType,
2781
- `tableId: ${tableIdType} | null`,
2782
- ),
2783
- getListenerHookParamsInCall('tableId'),
2784
- );
2785
- addProxyHook(
2786
- SORTED_ROW_IDS + LISTENER,
2787
- SORTED_ROW_IDS + LISTENER,
2788
- VOID,
2789
- getListenerDoc(13, 3, 1),
2790
- getListenerHookParams(
2791
- sortedRowIdsListenerType,
2792
- `tableId: ${tableIdType} | null`,
2793
- 'cellId: ' + cellIdsType + OR_UNDEFINED,
2794
- 'descending: boolean',
2795
- 'offset: number',
2796
- 'limit: number' + OR_UNDEFINED,
2797
- ),
2798
- getListenerHookParamsInCall(
2799
- 'tableId',
2800
- 'cellId',
2801
- 'descending',
2802
- 'offset',
2803
- 'limit',
2804
- ),
2805
- );
2806
- addProxyHook(
2807
- HAS + ROW + LISTENER,
2808
- HAS + ROW + LISTENER,
2809
- VOID,
2810
- getListenerDoc(5, 3, 0, 1),
2811
- getListenerHookParams(
2812
- hasRowListenerType,
2813
- `tableId: ${tableIdType} | null`,
2814
- ROW_ID + `: IdOrNull`,
2815
- ),
2816
- getListenerHookParamsInCall('tableId', ROW_ID),
2817
- );
2818
- addProxyHook(
2819
- ROW + LISTENER,
2820
- ROW + LISTENER,
2821
- VOID,
2822
- getListenerDoc(5, 3),
2823
- getListenerHookParams(
2824
- rowListenerType,
2825
- `tableId: ${tableIdType} | null`,
2826
- ROW_ID + `: IdOrNull`,
2827
- ),
2828
- getListenerHookParamsInCall('tableId', ROW_ID),
2829
- );
2830
- addProxyHook(
2831
- CELL_IDS + LISTENER,
2832
- CELL_IDS + LISTENER,
2833
- VOID,
2834
- getListenerDoc(6, 5, 1),
2835
- getListenerHookParams(
2836
- cellIdsListenerType,
2837
- `tableId: ${tableIdType} | null`,
2838
- ROW_ID + `: IdOrNull`,
2839
- ),
2840
- getListenerHookParamsInCall('tableId', ROW_ID),
2841
- );
2842
- addProxyHook(
2843
- HAS + CELL + LISTENER,
2844
- HAS + CELL + LISTENER,
2845
- VOID,
2846
- getListenerDoc(7, 5, 0, 1),
2847
- getListenerHookParams(
2848
- hasCellListenerType,
2849
- `tableId: ${tableIdType} | null`,
2850
- ROW_ID + `: IdOrNull`,
2851
- `cellId: ${cellIdsType} | null`,
2852
- ),
2853
- getListenerHookParamsInCall('tableId', ROW_ID, 'cellId'),
2854
- );
2855
- addProxyHook(
2856
- CELL + LISTENER,
2857
- CELL + LISTENER,
2858
- VOID,
2859
- getListenerDoc(7, 5),
2860
- getListenerHookParams(
2861
- cellListenerType,
2862
- `tableId: ${tableIdType} | null`,
2863
- ROW_ID + `: IdOrNull`,
2864
- `cellId: ${cellIdsType} | null`,
2865
- ),
2866
- getListenerHookParamsInCall('tableId', ROW_ID, 'cellId'),
2867
- );
2868
- }
2869
- if (!objIsEmpty(valuesSchema)) {
2870
- const [
2871
- valuesType,
2872
- valuesWhenSetType,
2873
- valueIdType,
2874
- hasValuesListenerType,
2875
- valuesListenerType,
2876
- valueIdsListenerType,
2877
- hasValueListenerType,
2878
- valueListenerType,
2879
- ] = sharedValueTypes;
2880
- addImport(null, moduleDefinition, ...sharedValueTypes);
2881
- addImport(1, moduleDefinition, storeType);
2882
- const getDefaultValueComponent = addInternalFunction(
2883
- 'getDefaultValueComponent',
2884
- 'valueId: Id',
2885
- arrayJoin(
2886
- mapValuesSchema(
2887
- (_, _2, _3, VALUE_ID, valueName) =>
2888
- `valueId == ${VALUE_ID} ? ` + valueName + 'ValueView : ',
2889
- ),
2890
- ) + NullComponent,
2891
- );
2892
- addProxyHook(
2893
- HAS + VALUES,
2894
- HAS + VALUES,
2895
- BOOLEAN,
2896
- getTheContentOfTheStoreDoc(2, 0, 0, 1) + AND_REGISTERS,
2897
- );
2898
- addProxyHook(
2899
- VALUES,
2900
- VALUES,
2901
- valuesType,
2902
- getTheContentOfTheStoreDoc(2, 0) + AND_REGISTERS,
2903
- );
2904
- const useValueIds = addProxyHook(
2905
- VALUE_IDS,
2906
- VALUE_IDS,
2907
- valueIdType + SQUARE_BRACKETS,
2908
- getIdsDoc(VALUE, THE_STORE) + AND_REGISTERS,
2909
- );
2910
- addProxyHook(
2911
- SET + VALUES + CALLBACK,
2912
- SET + VALUES + CALLBACK,
2913
- PARAMETERIZED_CALLBACK,
2914
- getTheContentOfTheStoreDoc(2, 9) + BASED_ON_A_PARAMETER,
2915
- getParameterList(
2916
- getGet(VALUES) + GETTER_ARGS + valuesWhenSetType,
2917
- getGet(VALUES) + DEPS_SUFFIX,
2918
- ),
2919
- getGetAndGetDeps(VALUES),
2920
- GENERIC_PARAMETER,
2921
- getParameterList(
2922
- THEN_PREFIX,
2923
- `values: ${valuesWhenSetType})` + RETURNS_VOID,
2924
- THEN_DEPS,
2925
- ),
2926
- THEN_AND_THEN_DEPS_IN_CALL,
2927
- );
2928
- addProxyHook(
2929
- SET + PARTIAL + VALUES + CALLBACK,
2930
- SET + PARTIAL + VALUES + CALLBACK,
2931
- PARAMETERIZED_CALLBACK,
2932
- getTheContentOfTheStoreDoc(2, 11) + BASED_ON_A_PARAMETER,
2933
- getParameterList(
2934
- getGet(PARTIAL + VALUES) + GETTER_ARGS + valuesWhenSetType,
2935
- getGet(PARTIAL + VALUES) + DEPS_SUFFIX,
2936
- ),
2937
- getGetAndGetDeps(PARTIAL + VALUES),
2938
- GENERIC_PARAMETER,
2939
- getParameterList(
2940
- THEN_PREFIX,
2941
- `partialValues: ${valuesWhenSetType})` + RETURNS_VOID,
2942
- THEN_DEPS,
2943
- ),
2944
- THEN_AND_THEN_DEPS_IN_CALL,
2945
- );
2946
- addProxyHook(
2947
- DEL + VALUES + CALLBACK,
2948
- DEL + VALUES + CALLBACK,
2949
- CALLBACK,
2950
- getTheContentOfTheStoreDoc(2, 12),
2951
- EMPTY_STRING,
2952
- EMPTY_STRING,
2953
- EMPTY_STRING,
2954
- THEN_AND_THEN_DEPS,
2955
- THEN_AND_THEN_DEPS_IN_CALL,
2956
- );
2957
- const valuePropsType = addType(
2958
- VALUE + PROPS,
2959
- getPropTypeList(
2960
- `valueId?: VId`,
2961
- storeInstance + OPTIONAL_COLON + storeType,
2962
- DEBUG_IDS_PROP_TYPE,
2963
- ),
2964
- getPropsDoc('a Value'),
2965
- `<VId extends ${valueIdType}>`,
2966
- );
2967
- const valuesPropsType = addType(
2968
- VALUES + PROPS,
2969
- getPropTypeList(
2970
- storeInstance + OPTIONAL_COLON + storeType,
2971
- 'valueComponents?: {readonly [VId in ' +
2972
- valueIdType +
2973
- `]?: ComponentType<${valuePropsType}<VId>>;}`,
2974
- `getValueComponentProps?: (valueId: ${valueIdType}) => ExtraProps`,
2975
- SEPARATOR_PROP_TYPE,
2976
- DEBUG_IDS_PROP_TYPE,
2977
- ),
2978
- getPropsDoc(getTheContentOfDoc(2, 1)),
2979
- );
2980
- addImport(1, uiReactModuleDefinition, valuesPropsType, valuePropsType);
2981
- addComponent(
2982
- VALUES + VIEW,
2983
- '{' +
2984
- storeInstance +
2985
- ', valueComponents, getValueComponentProps' +
2986
- SEPARATOR_AND_DEBUG_IDS +
2987
- '}: ' +
2988
- valuesPropsType,
2989
- [
2990
- wrap + `(${useValueIds}(${storeInstance}).map((valueId) => {`,
2991
- 'const Value = valueComponents?.[valueId] ?? ' +
2992
- getDefaultValueComponent +
2993
- '(valueId);',
2994
- 'return <Value',
2995
- `{...${getProps}(getValueComponentProps, valueId)}`,
2996
- 'key={valueId}',
2997
- storeProp,
2998
- DEBUG_IDS_PROP,
2999
- '/>;',
3000
- '}), separator)',
3001
- ],
3002
- getTheContentOfTheStoreDoc(2, 13) + AND_REGISTERS,
3003
- );
3004
- mapValuesSchema((valueId, type, _, VALUE_ID, valueName) => {
3005
- const mapValueType = 'Map' + camel(type, 1);
3006
- addImport(0, moduleDefinition, mapValueType);
3007
- addImport(1, moduleDefinition, mapValueType);
3008
- addProxyHook(
3009
- HAS + valueName + VALUE,
3010
- HAS + VALUE,
3011
- BOOLEAN,
3012
- getValueContentDoc(valueId, 0, 1) + AND_REGISTERS,
3013
- EMPTY_STRING,
3014
- VALUE_ID,
3015
- );
3016
- const useValue = addProxyHook(
3017
- valueName + VALUE,
3018
- VALUE,
3019
- type,
3020
- getValueContentDoc(valueId) + AND_REGISTERS,
3021
- EMPTY_STRING,
3022
- VALUE_ID,
3023
- );
3024
- addProxyHook(
3025
- SET + valueName + VALUE + CALLBACK,
3026
- SET + VALUE + CALLBACK,
3027
- PARAMETERIZED_CALLBACK,
3028
- getValueContentDoc(valueId, 9) + BASED_ON_A_PARAMETER,
3029
- getParameterList(
3030
- getGet(VALUE) + GETTER_ARGS + type + ' | ' + mapValueType,
3031
- getGet(VALUE) + DEPS_SUFFIX,
3032
- ),
3033
- getParameterList(VALUE_ID, getGetAndGetDeps(VALUE)),
3034
- GENERIC_PARAMETER,
3035
- getParameterList(
3036
- THEN_PREFIX,
3037
- `value: ${type} | ${mapValueType})` + RETURNS_VOID,
3038
- THEN_DEPS,
3039
- ),
3040
- THEN_AND_THEN_DEPS_IN_CALL,
3041
- );
3042
- addProxyHook(
3043
- DEL + valueName + VALUE + CALLBACK,
3044
- DEL + VALUE + CALLBACK,
3045
- CALLBACK,
3046
- getValueContentDoc(valueId, 12),
3047
- EMPTY_STRING,
3048
- VALUE_ID,
3049
- EMPTY_STRING,
3050
- THEN_AND_THEN_DEPS,
3051
- THEN_AND_THEN_DEPS_IN_CALL,
3052
- );
3053
- addComponent(
3054
- valueName + VALUE + VIEW,
3055
- `{${storeInstance}, debugIds}: ${valuePropsType}<'${valueId}'>`,
3056
- [
3057
- wrap +
3058
- `('' + ${useValue}(` +
3059
- storeInstance +
3060
- `) ?? '', undefined, debugIds, ${VALUE_ID})`,
3061
- ],
3062
- getValueContentDoc(valueId, 13) + AND_REGISTERS,
3063
- );
3064
- });
3065
- addProxyHook(
3066
- HAS + VALUES + LISTENER,
3067
- HAS + VALUES + LISTENER,
3068
- VOID,
3069
- getTheContentOfTheStoreDoc(2, 8, 0, 1) + ' changes',
3070
- getListenerHookParams(hasValuesListenerType),
3071
- getListenerHookParamsInCall(),
3072
- );
3073
- addProxyHook(
3074
- VALUES + LISTENER,
3075
- VALUES + LISTENER,
3076
- VOID,
3077
- getTheContentOfTheStoreDoc(2, 8) + ' changes',
3078
- getListenerHookParams(valuesListenerType),
3079
- getListenerHookParamsInCall(),
3080
- );
3081
- addProxyHook(
3082
- VALUE_IDS + LISTENER,
3083
- VALUE_IDS + LISTENER,
3084
- VOID,
3085
- getListenerDoc(10, 0, 1),
3086
- getListenerHookParams(valueIdsListenerType),
3087
- getListenerHookParamsInCall(),
3088
- );
3089
- addProxyHook(
3090
- HAS + VALUE + LISTENER,
3091
- HAS + VALUE + LISTENER,
3092
- VOID,
3093
- getListenerDoc(11, 0, 0, 1),
3094
- getListenerHookParams(
3095
- hasValueListenerType,
3096
- `valueId: ${valueIdType} | null`,
3097
- ),
3098
- getListenerHookParamsInCall('valueId'),
3099
- );
3100
- addProxyHook(
3101
- VALUE + LISTENER,
3102
- VALUE + LISTENER,
3103
- VOID,
3104
- getListenerDoc(11, 0),
3105
- getListenerHookParams(
3106
- valueListenerType,
3107
- `valueId: ${valueIdType} | null`,
3108
- ),
3109
- getListenerHookParamsInCall('valueId'),
3110
- );
3111
- }
3112
- addComponent(
3113
- PROVIDER,
3114
- `{${storeInstance}, ${storeInstance}ById, children}: ` +
3115
- providerPropsType +
3116
- ' & {readonly children: React.ReactNode}',
3117
- [
3118
- '{',
3119
- USE_CONTEXT,
3120
- 'return (',
3121
- '<Context.' + PROVIDER,
3122
- 'value={useMemo(',
3123
- `() => [${storeInstance} ?? contextValue[0], {...contextValue[1], ...${storeInstance}ById}],`,
3124
- `[${storeInstance}, ${storeInstance}ById, contextValue],`,
3125
- ')}>',
3126
- '{children}',
3127
- `</Context.${PROVIDER}>`,
3128
- ');',
3129
- '}',
3130
- ],
3131
- 'Wraps part of an application in a context that provides default objects to be used by hooks and components within',
3132
- );
3133
- return [
3134
- build(...getImports(0), ...getTypes(), ...getFunctions(0)),
3135
- build(...getImports(1), ...getConstants(), ...getFunctions(1)),
3136
- ];
3137
- };
3138
-
3139
- const getStoreApi = (tablesSchema, valuesSchema, module) => {
3140
- if (objIsEmpty(tablesSchema) && objIsEmpty(valuesSchema)) {
3141
- return [EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING];
3142
- }
3143
- const [dTsCore, tsCore, sharedTableTypes, sharedValueTypes] = getStoreCoreApi(
3144
- tablesSchema,
3145
- valuesSchema,
3146
- module,
3147
- );
3148
- return [
3149
- dTsCore,
3150
- tsCore,
3151
- ...getStoreUiReactApi(
3152
- tablesSchema,
3153
- valuesSchema,
3154
- module,
3155
- sharedTableTypes,
3156
- sharedValueTypes,
3157
- ),
3158
- ];
3159
- };
3160
-
3161
- const jsonParse = JSON.parse;
3162
-
3163
- const PRETTIER = 'prettier/';
3164
- const PRETTIER_PLUGINS = PRETTIER + 'plugins/';
3165
- const prettierConfig = {
3166
- parser: 'typescript',
3167
- singleQuote: true,
3168
- trailingComma: 'all',
3169
- bracketSpacing: false,
3170
- jsdocSingleLineComment: false,
3171
- };
3172
- const createTools = getCreateFunction((store) => {
3173
- const getStoreStats = (detail) => {
3174
- let totalTables = 0;
3175
- let totalRows = 0;
3176
- let totalCells = 0;
3177
- const tables = {};
3178
- store.forEachTable((tableId, forEachRow) => {
3179
- totalTables++;
3180
- let tableRows = 0;
3181
- let tableCells = 0;
3182
- const rows = {};
3183
- forEachRow((rowId, forEachCell) => {
3184
- tableRows++;
3185
- let rowCells = 0;
3186
- forEachCell(() => rowCells++);
3187
- tableCells += rowCells;
3188
- if (detail) {
3189
- rows[rowId] = {rowCells};
3190
- }
3191
- });
3192
- totalRows += tableRows;
3193
- totalCells += tableCells;
3194
- if (detail) {
3195
- tables[tableId] = {tableRows, tableCells, rows};
3196
- }
3197
- });
3198
- return {
3199
- totalTables,
3200
- totalRows,
3201
- totalCells,
3202
- totalValues: size(store.getValueIds()),
3203
- jsonLength: size(store.getJson()),
3204
- ...(detail ? {detail: {tables}} : {}),
3205
- };
3206
- };
3207
- const getStoreTablesSchema = () => {
3208
- const tablesSchema = jsonParse(store.getTablesSchemaJson());
3209
- if (
3210
- !objIsEmpty(tablesSchema) ||
3211
- arrayEvery(store.getTableIds(), (tableId) => {
3212
- const rowIds = store.getRowIds(tableId);
3213
- const cellsMeta = mapNew();
3214
- if (
3215
- arrayEvery(rowIds, (rowId) =>
3216
- arrayEvery(store.getCellIds(tableId, rowId), (cellId) => {
3217
- const value = store.getCell(tableId, rowId, cellId);
3218
- const cellMeta = mapEnsure(cellsMeta, cellId, () => [
3219
- getCellOrValueType(value),
3220
- mapNew(),
3221
- [0],
3222
- 0,
3223
- ]);
3224
- const [type, values, [maxCount]] = cellMeta;
3225
- const count = mapEnsure(values, value, () => 0) + 1;
3226
- if (count > maxCount) {
3227
- cellMeta[2] = [count, value];
3228
- }
3229
- mapSet(values, value, count);
3230
- cellMeta[3]++;
3231
- return type == getCellOrValueType(value);
3232
- }),
3233
- )
3234
- ) {
3235
- tablesSchema[tableId] = {};
3236
- collForEach(cellsMeta, ([type, , [, maxValue], count], cellId) => {
3237
- tablesSchema[tableId][cellId] = {
3238
- [TYPE]: type,
3239
- ...(count == size(rowIds) ? {[DEFAULT]: maxValue} : {}),
3240
- };
3241
- });
3242
- return 1;
3243
- }
3244
- })
3245
- ) {
3246
- return tablesSchema;
3247
- }
3248
- return {};
3249
- };
3250
- const getStoreValuesSchema = () => {
3251
- const valuesSchema = jsonParse(store.getValuesSchemaJson());
3252
- if (objIsEmpty(valuesSchema)) {
3253
- store.forEachValue((valueId, value) => {
3254
- valuesSchema[valueId] = {
3255
- [TYPE]: getCellOrValueType(value),
3256
- };
3257
- });
3258
- }
3259
- return valuesSchema;
3260
- };
3261
- const getStoreApi$1 = (module) =>
3262
- getStoreApi(getStoreTablesSchema(), getStoreValuesSchema(), module);
3263
- const getPrettyStoreApi = async (module) => {
3264
- const extensions = ['d.ts', 'ts', 'd.ts', 'tsx'];
3265
- const plugins = [];
3266
- let format;
3267
- try {
3268
- format = (await import(PRETTIER + 'standalone')).format;
3269
- arrayPush(
3270
- plugins,
3271
- await import(PRETTIER_PLUGINS + 'estree'),
3272
- await import(PRETTIER_PLUGINS + 'typescript'),
3273
- );
3274
- } catch {
3275
- format = async (str) => str;
3276
- }
3277
- return await promiseAll(
3278
- arrayMap(getStoreApi$1(module), async (file, f) =>
3279
- formatJsDoc(
3280
- await format(file, {
3281
- ...prettierConfig,
3282
- plugins,
3283
- filepath: `_.${extensions[f]}`,
3284
- }),
3285
- ),
3286
- ),
3287
- );
3288
- };
3289
- const getStore = () => store;
3290
- const tools = {
3291
- getStoreStats,
3292
- getStoreTablesSchema,
3293
- getStoreValuesSchema,
3294
- getStoreApi: getStoreApi$1,
3295
- getPrettyStoreApi,
3296
- getStore,
3297
- };
3298
- return objFreeze(tools);
3299
- });
3300
-
3301
- export {createTools};