on-zero 0.7.2 → 0.7.3-1784533014336

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 (355) hide show
  1. package/dist/cjs/helpers/createMutators.cjs +4 -3
  2. package/dist/cjs/helpers/createMutators.native.js +6 -3
  3. package/dist/cjs/helpers/createMutators.native.js.map +1 -1
  4. package/dist/cjs/index.cjs +0 -1
  5. package/dist/cjs/index.native.js +0 -1
  6. package/dist/cjs/index.native.js.map +1 -1
  7. package/dist/cjs/orez.cjs +231 -0
  8. package/dist/cjs/orez.native.js +324 -0
  9. package/dist/cjs/orez.native.js.map +1 -0
  10. package/dist/cjs/orez.test.cjs +268 -0
  11. package/dist/cjs/orez.test.native.js +288 -0
  12. package/dist/cjs/orez.test.native.js.map +1 -0
  13. package/dist/cjs/run.cjs +1 -1
  14. package/dist/cjs/run.native.js +1 -1
  15. package/dist/cjs/state.cjs +1 -1
  16. package/dist/cjs/state.native.js +1 -1
  17. package/dist/cjs/zeroRunner.cjs +1 -1
  18. package/dist/cjs/zeroRunner.native.js +1 -1
  19. package/dist/esm/cli.native.js +1 -1
  20. package/dist/esm/cli.native.js.map +1 -1
  21. package/dist/esm/combineZeroClients.native.js +2 -2
  22. package/dist/esm/combineZeroClients.native.js.map +1 -1
  23. package/dist/esm/createPermissions.native.js +4 -4
  24. package/dist/esm/createPermissions.native.js.map +1 -1
  25. package/dist/esm/createSchemaFromDrizzle.native.js +1 -1
  26. package/dist/esm/createSchemaFromDrizzle.native.js.map +1 -1
  27. package/dist/esm/createUseQuery.native.js +2 -2
  28. package/dist/esm/createUseQuery.native.js.map +1 -1
  29. package/dist/esm/createUseQueryDirect.native.js +2 -2
  30. package/dist/esm/createUseQueryDirect.native.js.map +1 -1
  31. package/dist/esm/createZeroClient.authData.test.native.js +2 -2
  32. package/dist/esm/createZeroClient.authData.test.native.js.map +1 -1
  33. package/dist/esm/createZeroClient.connection.test.native.js +1 -1
  34. package/dist/esm/createZeroClient.connection.test.native.js.map +1 -1
  35. package/dist/esm/createZeroClient.native.js +15 -15
  36. package/dist/esm/createZeroClient.native.js.map +1 -1
  37. package/dist/esm/createZeroClient.recovery.test.native.js +1 -1
  38. package/dist/esm/createZeroClient.recovery.test.native.js.map +1 -1
  39. package/dist/esm/generate-helpers.native.js.map +1 -1
  40. package/dist/esm/generate-lite.native.js +1 -1
  41. package/dist/esm/generate-lite.native.js.map +1 -1
  42. package/dist/esm/generate-lite.test.native.js +1 -1
  43. package/dist/esm/generate-lite.test.native.js.map +1 -1
  44. package/dist/esm/generate.native.js +1 -1
  45. package/dist/esm/generate.native.js.map +1 -1
  46. package/dist/esm/generate.test.native.js +1 -1
  47. package/dist/esm/generate.test.native.js.map +1 -1
  48. package/dist/esm/helpers/batchQuery.native.js.map +1 -1
  49. package/dist/esm/helpers/clearZeroClientData.native.js.map +1 -1
  50. package/dist/esm/helpers/createMutators.mjs +4 -3
  51. package/dist/esm/helpers/createMutators.mjs.map +1 -1
  52. package/dist/esm/helpers/createMutators.native.js +8 -5
  53. package/dist/esm/helpers/createMutators.native.js.map +1 -1
  54. package/dist/esm/helpers/createMutators.test.native.js +1 -1
  55. package/dist/esm/helpers/createMutators.test.native.js.map +1 -1
  56. package/dist/esm/helpers/ensureLoggedIn.native.js +1 -1
  57. package/dist/esm/helpers/ensureLoggedIn.native.js.map +1 -1
  58. package/dist/esm/helpers/getAuth.native.js +3 -3
  59. package/dist/esm/helpers/getAuth.native.js.map +1 -1
  60. package/dist/esm/helpers/mutatorContext.native.js.map +1 -1
  61. package/dist/esm/helpers/prettyFormatZeroQuery.native.js.map +1 -1
  62. package/dist/esm/helpers/queryContext.native.js.map +1 -1
  63. package/dist/esm/helpers/recoverZeroClient.native.js.map +1 -1
  64. package/dist/esm/helpers/recoverZeroClient.test.native.js +1 -1
  65. package/dist/esm/helpers/recoverZeroClient.test.native.js.map +1 -1
  66. package/dist/esm/helpers/showZeroClientError.native.js +1 -1
  67. package/dist/esm/helpers/showZeroClientError.native.js.map +1 -1
  68. package/dist/esm/helpers/useMutation.native.js.map +1 -1
  69. package/dist/esm/helpers/useMutation.test.native.js +1 -1
  70. package/dist/esm/helpers/useMutation.test.native.js.map +1 -1
  71. package/dist/esm/helpers/useZeroDebug.native.js +1 -1
  72. package/dist/esm/helpers/useZeroDebug.native.js.map +1 -1
  73. package/dist/esm/httpPull/fixtureSchema.native.js.map +1 -1
  74. package/dist/esm/httpPull/transport.test.native.js +3 -3
  75. package/dist/esm/httpPull/transport.test.native.js.map +1 -1
  76. package/dist/esm/httpPullTransport.native.js.map +1 -1
  77. package/dist/esm/index.js +0 -1
  78. package/dist/esm/index.js.map +1 -1
  79. package/dist/esm/index.mjs +0 -1
  80. package/dist/esm/index.mjs.map +1 -1
  81. package/dist/esm/index.native.js +22 -23
  82. package/dist/esm/index.native.js.map +1 -1
  83. package/dist/esm/instanceRegistry.native.js +1 -1
  84. package/dist/esm/instanceRegistry.native.js.map +1 -1
  85. package/dist/esm/modelRegistry.native.js.map +1 -1
  86. package/dist/esm/multi.native.js +3 -3
  87. package/dist/esm/multi.native.js.map +1 -1
  88. package/dist/esm/multiInstance.test.native.js +8 -8
  89. package/dist/esm/multiInstance.test.native.js.map +1 -1
  90. package/dist/esm/multiInstanceNested.test.native.js +3 -3
  91. package/dist/esm/multiInstanceNested.test.native.js.map +1 -1
  92. package/dist/esm/multiPartition.test.native.js +1 -1
  93. package/dist/esm/multiPartition.test.native.js.map +1 -1
  94. package/dist/esm/mutations.native.js +1 -1
  95. package/dist/esm/mutations.native.js.map +1 -1
  96. package/dist/esm/mutations.test.native.js +2 -2
  97. package/dist/esm/mutations.test.native.js.map +1 -1
  98. package/dist/esm/orez.mjs +205 -0
  99. package/dist/esm/orez.mjs.map +1 -0
  100. package/dist/esm/orez.native.js +295 -0
  101. package/dist/esm/orez.native.js.map +1 -0
  102. package/dist/esm/orez.test.mjs +245 -0
  103. package/dist/esm/orez.test.mjs.map +1 -0
  104. package/dist/esm/orez.test.native.js +262 -0
  105. package/dist/esm/orez.test.native.js.map +1 -0
  106. package/dist/esm/provideZero.hydration.test.native.js +1 -1
  107. package/dist/esm/provideZero.hydration.test.native.js.map +1 -1
  108. package/dist/esm/queryRegistry.native.js.map +1 -1
  109. package/dist/esm/resolveQuery.native.js +1 -1
  110. package/dist/esm/resolveQuery.native.js.map +1 -1
  111. package/dist/esm/run.mjs +1 -1
  112. package/dist/esm/run.mjs.map +1 -1
  113. package/dist/esm/run.native.js +5 -5
  114. package/dist/esm/run.native.js.map +1 -1
  115. package/dist/esm/serverWhere.native.js +1 -1
  116. package/dist/esm/serverWhere.native.js.map +1 -1
  117. package/dist/esm/serverWhere.test.native.js +3 -3
  118. package/dist/esm/serverWhere.test.native.js.map +1 -1
  119. package/dist/esm/state.mjs +1 -1
  120. package/dist/esm/state.native.js +1 -1
  121. package/dist/esm/state.native.js.map +1 -1
  122. package/dist/esm/testSetup.native.js.map +1 -1
  123. package/dist/esm/types.native.js.map +1 -1
  124. package/dist/esm/usePermission.test.native.js +3 -3
  125. package/dist/esm/usePermission.test.native.js.map +1 -1
  126. package/dist/esm/useQuery.empty.test.native.js +2 -2
  127. package/dist/esm/useQuery.empty.test.native.js.map +1 -1
  128. package/dist/esm/useQuery.ssr.test.native.js +2 -2
  129. package/dist/esm/useQuery.ssr.test.native.js.map +1 -1
  130. package/dist/esm/vite-plugin.native.js +1 -1
  131. package/dist/esm/vite-plugin.native.js.map +1 -1
  132. package/dist/esm/where.native.js +2 -2
  133. package/dist/esm/where.native.js.map +1 -1
  134. package/dist/esm/zeroRunner.mjs +1 -1
  135. package/dist/esm/zeroRunner.mjs.map +1 -1
  136. package/dist/esm/zeroRunner.native.js +2 -2
  137. package/dist/esm/zeroRunner.native.js.map +1 -1
  138. package/dist/esm/zql.native.js +1 -1
  139. package/dist/esm/zql.native.js.map +1 -1
  140. package/package.json +7 -23
  141. package/readme.md +40 -65
  142. package/src/createZeroClient.tsx +1 -1
  143. package/src/helpers/createMutators.ts +6 -2
  144. package/src/index.ts +0 -1
  145. package/src/orez.test.ts +266 -0
  146. package/src/orez.ts +344 -0
  147. package/src/run.ts +1 -1
  148. package/src/state.ts +1 -1
  149. package/src/types.ts +0 -5
  150. package/src/zeroRunner.ts +1 -1
  151. package/test-fixtures/server-return-types.ts +21 -58
  152. package/types/helpers/createMutators.d.ts +2 -1
  153. package/types/helpers/createMutators.d.ts.map +1 -1
  154. package/types/httpPull/fixtureSchema.d.ts +1 -1
  155. package/types/index.d.ts +0 -1
  156. package/types/index.d.ts.map +1 -1
  157. package/types/orez.d.ts +54 -0
  158. package/types/orez.d.ts.map +1 -0
  159. package/types/orez.test.d.ts +2 -0
  160. package/types/orez.test.d.ts.map +1 -0
  161. package/types/types.d.ts +0 -4
  162. package/types/types.d.ts.map +1 -1
  163. package/dist/cjs/asyncTasks.cjs +0 -51
  164. package/dist/cjs/asyncTasks.native.js +0 -84
  165. package/dist/cjs/asyncTasks.native.js.map +0 -1
  166. package/dist/cjs/createZeroDirectServer.cjs +0 -269
  167. package/dist/cjs/createZeroDirectServer.native.js +0 -287
  168. package/dist/cjs/createZeroDirectServer.native.js.map +0 -1
  169. package/dist/cjs/createZeroSQLiteServer.cjs +0 -50
  170. package/dist/cjs/createZeroSQLiteServer.native.js +0 -58
  171. package/dist/cjs/createZeroSQLiteServer.native.js.map +0 -1
  172. package/dist/cjs/createZeroSQLiteServer.test.cjs +0 -595
  173. package/dist/cjs/createZeroSQLiteServer.test.native.js +0 -647
  174. package/dist/cjs/createZeroSQLiteServer.test.native.js.map +0 -1
  175. package/dist/cjs/createZeroServer.cjs +0 -82
  176. package/dist/cjs/createZeroServer.native.js +0 -93
  177. package/dist/cjs/createZeroServer.native.js.map +0 -1
  178. package/dist/cjs/createZeroServer.test.cjs +0 -378
  179. package/dist/cjs/createZeroServer.test.native.js +0 -448
  180. package/dist/cjs/createZeroServer.test.native.js.map +0 -1
  181. package/dist/cjs/createZeroServerCore.cjs +0 -211
  182. package/dist/cjs/createZeroServerCore.native.js +0 -355
  183. package/dist/cjs/createZeroServerCore.native.js.map +0 -1
  184. package/dist/cjs/httpPull/auth.test.cjs +0 -197
  185. package/dist/cjs/httpPull/auth.test.native.js +0 -279
  186. package/dist/cjs/httpPull/auth.test.native.js.map +0 -1
  187. package/dist/cjs/httpPull/churn.test.cjs +0 -132
  188. package/dist/cjs/httpPull/churn.test.native.js +0 -155
  189. package/dist/cjs/httpPull/churn.test.native.js.map +0 -1
  190. package/dist/cjs/httpPull/completeAck.test.cjs +0 -69
  191. package/dist/cjs/httpPull/completeAck.test.native.js +0 -76
  192. package/dist/cjs/httpPull/completeAck.test.native.js.map +0 -1
  193. package/dist/cjs/httpPull/fixtureServer.cjs +0 -340
  194. package/dist/cjs/httpPull/fixtureServer.native.js +0 -534
  195. package/dist/cjs/httpPull/fixtureServer.native.js.map +0 -1
  196. package/dist/cjs/httpPull/integration.test.cjs +0 -53
  197. package/dist/cjs/httpPull/integration.test.native.js +0 -60
  198. package/dist/cjs/httpPull/integration.test.native.js.map +0 -1
  199. package/dist/cjs/httpPull/rebase.test.cjs +0 -360
  200. package/dist/cjs/httpPull/rebase.test.native.js +0 -420
  201. package/dist/cjs/httpPull/rebase.test.native.js.map +0 -1
  202. package/dist/cjs/httpPull/relations.test.cjs +0 -107
  203. package/dist/cjs/httpPull/relations.test.native.js +0 -119
  204. package/dist/cjs/httpPull/relations.test.native.js.map +0 -1
  205. package/dist/cjs/httpPull/testHarness.cjs +0 -100
  206. package/dist/cjs/httpPull/testHarness.native.js +0 -112
  207. package/dist/cjs/httpPull/testHarness.native.js.map +0 -1
  208. package/dist/cjs/server.cjs +0 -22
  209. package/dist/cjs/server.native.js +0 -4
  210. package/dist/cjs/server.native.js.map +0 -1
  211. package/dist/cjs/sqliteRuntime.cjs +0 -318
  212. package/dist/cjs/sqliteRuntime.native.js +0 -438
  213. package/dist/cjs/sqliteRuntime.native.js.map +0 -1
  214. package/dist/cjs/syncHost.cjs +0 -179
  215. package/dist/cjs/syncHost.native.js +0 -388
  216. package/dist/cjs/syncHost.native.js.map +0 -1
  217. package/dist/cjs/syncHost.test.cjs +0 -240
  218. package/dist/cjs/syncHost.test.native.js +0 -290
  219. package/dist/cjs/syncHost.test.native.js.map +0 -1
  220. package/dist/esm/asyncTasks.mjs +0 -26
  221. package/dist/esm/asyncTasks.mjs.map +0 -1
  222. package/dist/esm/asyncTasks.native.js +0 -56
  223. package/dist/esm/asyncTasks.native.js.map +0 -1
  224. package/dist/esm/createZeroDirectServer.mjs +0 -241
  225. package/dist/esm/createZeroDirectServer.mjs.map +0 -1
  226. package/dist/esm/createZeroDirectServer.native.js +0 -256
  227. package/dist/esm/createZeroDirectServer.native.js.map +0 -1
  228. package/dist/esm/createZeroSQLiteServer.mjs +0 -24
  229. package/dist/esm/createZeroSQLiteServer.mjs.map +0 -1
  230. package/dist/esm/createZeroSQLiteServer.native.js +0 -29
  231. package/dist/esm/createZeroSQLiteServer.native.js.map +0 -1
  232. package/dist/esm/createZeroSQLiteServer.test.mjs +0 -596
  233. package/dist/esm/createZeroSQLiteServer.test.mjs.map +0 -1
  234. package/dist/esm/createZeroSQLiteServer.test.native.js +0 -645
  235. package/dist/esm/createZeroSQLiteServer.test.native.js.map +0 -1
  236. package/dist/esm/createZeroServer.mjs +0 -57
  237. package/dist/esm/createZeroServer.mjs.map +0 -1
  238. package/dist/esm/createZeroServer.native.js +0 -65
  239. package/dist/esm/createZeroServer.native.js.map +0 -1
  240. package/dist/esm/createZeroServer.test.mjs +0 -379
  241. package/dist/esm/createZeroServer.test.mjs.map +0 -1
  242. package/dist/esm/createZeroServer.test.native.js +0 -446
  243. package/dist/esm/createZeroServer.test.native.js.map +0 -1
  244. package/dist/esm/createZeroServerCore.mjs +0 -186
  245. package/dist/esm/createZeroServerCore.mjs.map +0 -1
  246. package/dist/esm/createZeroServerCore.native.js +0 -327
  247. package/dist/esm/createZeroServerCore.native.js.map +0 -1
  248. package/dist/esm/httpPull/auth.test.mjs +0 -198
  249. package/dist/esm/httpPull/auth.test.mjs.map +0 -1
  250. package/dist/esm/httpPull/auth.test.native.js +0 -277
  251. package/dist/esm/httpPull/auth.test.native.js.map +0 -1
  252. package/dist/esm/httpPull/churn.test.mjs +0 -133
  253. package/dist/esm/httpPull/churn.test.mjs.map +0 -1
  254. package/dist/esm/httpPull/churn.test.native.js +0 -153
  255. package/dist/esm/httpPull/churn.test.native.js.map +0 -1
  256. package/dist/esm/httpPull/completeAck.test.mjs +0 -70
  257. package/dist/esm/httpPull/completeAck.test.mjs.map +0 -1
  258. package/dist/esm/httpPull/completeAck.test.native.js +0 -74
  259. package/dist/esm/httpPull/completeAck.test.native.js.map +0 -1
  260. package/dist/esm/httpPull/fixtureServer.mjs +0 -315
  261. package/dist/esm/httpPull/fixtureServer.mjs.map +0 -1
  262. package/dist/esm/httpPull/fixtureServer.native.js +0 -506
  263. package/dist/esm/httpPull/fixtureServer.native.js.map +0 -1
  264. package/dist/esm/httpPull/integration.test.mjs +0 -54
  265. package/dist/esm/httpPull/integration.test.mjs.map +0 -1
  266. package/dist/esm/httpPull/integration.test.native.js +0 -58
  267. package/dist/esm/httpPull/integration.test.native.js.map +0 -1
  268. package/dist/esm/httpPull/rebase.test.mjs +0 -361
  269. package/dist/esm/httpPull/rebase.test.mjs.map +0 -1
  270. package/dist/esm/httpPull/rebase.test.native.js +0 -418
  271. package/dist/esm/httpPull/rebase.test.native.js.map +0 -1
  272. package/dist/esm/httpPull/relations.test.mjs +0 -108
  273. package/dist/esm/httpPull/relations.test.mjs.map +0 -1
  274. package/dist/esm/httpPull/relations.test.native.js +0 -117
  275. package/dist/esm/httpPull/relations.test.native.js.map +0 -1
  276. package/dist/esm/httpPull/testHarness.mjs +0 -72
  277. package/dist/esm/httpPull/testHarness.mjs.map +0 -1
  278. package/dist/esm/httpPull/testHarness.native.js +0 -81
  279. package/dist/esm/httpPull/testHarness.native.js.map +0 -1
  280. package/dist/esm/server.mjs +0 -4
  281. package/dist/esm/server.mjs.map +0 -1
  282. package/dist/esm/server.native.js +0 -2
  283. package/dist/esm/server.native.js.map +0 -1
  284. package/dist/esm/sqliteRuntime.mjs +0 -289
  285. package/dist/esm/sqliteRuntime.mjs.map +0 -1
  286. package/dist/esm/sqliteRuntime.native.js +0 -406
  287. package/dist/esm/sqliteRuntime.native.js.map +0 -1
  288. package/dist/esm/syncHost.mjs +0 -153
  289. package/dist/esm/syncHost.mjs.map +0 -1
  290. package/dist/esm/syncHost.native.js +0 -359
  291. package/dist/esm/syncHost.native.js.map +0 -1
  292. package/dist/esm/syncHost.test.mjs +0 -217
  293. package/dist/esm/syncHost.test.mjs.map +0 -1
  294. package/dist/esm/syncHost.test.native.js +0 -264
  295. package/dist/esm/syncHost.test.native.js.map +0 -1
  296. package/src/asyncTasks.ts +0 -36
  297. package/src/createZeroDirectServer.ts +0 -411
  298. package/src/createZeroSQLiteServer.test.ts +0 -614
  299. package/src/createZeroSQLiteServer.ts +0 -56
  300. package/src/createZeroServer.test.ts +0 -421
  301. package/src/createZeroServer.ts +0 -105
  302. package/src/createZeroServerCore.ts +0 -296
  303. package/src/httpPull/auth.test.ts +0 -208
  304. package/src/httpPull/churn.test.ts +0 -147
  305. package/src/httpPull/completeAck.test.ts +0 -80
  306. package/src/httpPull/fixtureServer.ts +0 -391
  307. package/src/httpPull/integration.test.ts +0 -57
  308. package/src/httpPull/rebase.test.ts +0 -368
  309. package/src/httpPull/relations.test.ts +0 -135
  310. package/src/httpPull/testHarness.ts +0 -95
  311. package/src/server.native.ts +0 -3
  312. package/src/server.ts +0 -4
  313. package/src/sqliteRuntime.ts +0 -512
  314. package/src/syncHost.test.ts +0 -223
  315. package/src/syncHost.ts +0 -294
  316. package/types/asyncTasks.d.ts +0 -11
  317. package/types/asyncTasks.d.ts.map +0 -1
  318. package/types/createZeroDirectServer.d.ts +0 -80
  319. package/types/createZeroDirectServer.d.ts.map +0 -1
  320. package/types/createZeroSQLiteServer.d.ts +0 -12
  321. package/types/createZeroSQLiteServer.d.ts.map +0 -1
  322. package/types/createZeroSQLiteServer.test.d.ts +0 -2
  323. package/types/createZeroSQLiteServer.test.d.ts.map +0 -1
  324. package/types/createZeroServer.d.ts +0 -18
  325. package/types/createZeroServer.d.ts.map +0 -1
  326. package/types/createZeroServer.test.d.ts +0 -2
  327. package/types/createZeroServer.test.d.ts.map +0 -1
  328. package/types/createZeroServerCore.d.ts +0 -256
  329. package/types/createZeroServerCore.d.ts.map +0 -1
  330. package/types/httpPull/auth.test.d.ts +0 -2
  331. package/types/httpPull/auth.test.d.ts.map +0 -1
  332. package/types/httpPull/churn.test.d.ts +0 -2
  333. package/types/httpPull/churn.test.d.ts.map +0 -1
  334. package/types/httpPull/completeAck.test.d.ts +0 -2
  335. package/types/httpPull/completeAck.test.d.ts.map +0 -1
  336. package/types/httpPull/fixtureServer.d.ts +0 -14
  337. package/types/httpPull/fixtureServer.d.ts.map +0 -1
  338. package/types/httpPull/integration.test.d.ts +0 -2
  339. package/types/httpPull/integration.test.d.ts.map +0 -1
  340. package/types/httpPull/rebase.test.d.ts +0 -2
  341. package/types/httpPull/rebase.test.d.ts.map +0 -1
  342. package/types/httpPull/relations.test.d.ts +0 -2
  343. package/types/httpPull/relations.test.d.ts.map +0 -1
  344. package/types/httpPull/testHarness.d.ts +0 -32
  345. package/types/httpPull/testHarness.d.ts.map +0 -1
  346. package/types/server.d.ts +0 -5
  347. package/types/server.d.ts.map +0 -1
  348. package/types/server.native.d.ts +0 -1
  349. package/types/server.native.d.ts.map +0 -1
  350. package/types/sqliteRuntime.d.ts +0 -71
  351. package/types/sqliteRuntime.d.ts.map +0 -1
  352. package/types/syncHost.d.ts +0 -42
  353. package/types/syncHost.d.ts.map +0 -1
  354. package/types/syncHost.test.d.ts +0 -2
  355. package/types/syncHost.test.d.ts.map +0 -1
@@ -1,614 +0,0 @@
1
- import { DatabaseSync, type SQLInputValue } from 'node:sqlite'
2
-
3
- import { boolean, createSchema, json, relationships, string, table } from '@rocicorp/zero'
4
- import { asQueryInternals } from '@rocicorp/zero/bindings'
5
- import { afterEach, beforeEach, describe, expect, test } from 'vitest'
6
-
7
- import { createZeroSQLiteServer } from './createZeroSQLiteServer'
8
- import { zeroHttpFixtureSchema } from './httpPull/fixtureSchema'
9
- import { mutations } from './mutations'
10
- import { serverWhere } from './serverWhere'
11
-
12
- import type {
13
- SqlStatementMetadata,
14
- SQLiteTransactionExecutor,
15
- SQLiteTransactionProvider,
16
- } from './createZeroSQLiteServer'
17
-
18
- const note = table('note')
19
- .from('note_records')
20
- .columns({
21
- id: string().from('note_id'),
22
- done: boolean(),
23
- data: json<{ label: string }>().optional(),
24
- })
25
- .primaryKey('id')
26
-
27
- const sqliteTypesSchema = createSchema({
28
- tables: [note],
29
- relationships: [],
30
- enableLegacyQueries: true,
31
- })
32
-
33
- const person = table('person').columns({ id: string() }).primaryKey('id')
34
- const membership = table('membership')
35
- .columns({ personId: string(), teamId: string() })
36
- .primaryKey('personId', 'teamId')
37
- const team = table('team')
38
- .from('team_records')
39
- .columns({
40
- id: string().from('team_id'),
41
- active: boolean().from('is_active'),
42
- metadata: json<{ label: string }>().from('metadata_json'),
43
- })
44
- .primaryKey('id')
45
- const twoHopSchema = createSchema({
46
- tables: [person, membership, team],
47
- relationships: [
48
- relationships(person, ({ many }) => ({
49
- teams: many(
50
- {
51
- sourceField: ['id'],
52
- destSchema: membership,
53
- destField: ['personId'],
54
- },
55
- {
56
- sourceField: ['teamId'],
57
- destSchema: team,
58
- destField: ['id'],
59
- },
60
- ),
61
- })),
62
- ],
63
- })
64
-
65
- function pushRequest(id: number, name: string, args: unknown) {
66
- return new Request('http://localhost/push?schema=zero_0&appID=zero', {
67
- method: 'POST',
68
- headers: { 'content-type': 'application/json' },
69
- body: JSON.stringify({
70
- clientGroupID: 'cg1',
71
- mutations: [
72
- {
73
- type: 'custom',
74
- id,
75
- clientID: 'client-a',
76
- name,
77
- args: [args],
78
- timestamp: 1,
79
- },
80
- ],
81
- pushVersion: 1,
82
- timestamp: 1,
83
- requestID: 'req-' + id,
84
- }),
85
- })
86
- }
87
-
88
- function cleanupRequest() {
89
- return new Request('http://localhost/push?schema=zero_0&appID=zero', {
90
- method: 'POST',
91
- headers: { 'content-type': 'application/json' },
92
- body: JSON.stringify({
93
- clientGroupID: 'cg1',
94
- mutations: [
95
- {
96
- type: 'custom',
97
- id: 2,
98
- clientID: 'client-a',
99
- name: '_zero_cleanupResults',
100
- args: [
101
- {
102
- clientGroupID: 'cg1',
103
- clientID: 'client-a',
104
- upToMutationID: 1,
105
- },
106
- ],
107
- timestamp: 1,
108
- },
109
- ],
110
- pushVersion: 1,
111
- timestamp: 1,
112
- requestID: 'cleanup',
113
- }),
114
- })
115
- }
116
-
117
- describe('createZeroSQLiteServer', () => {
118
- let db: DatabaseSync
119
- let retryNextTransaction: boolean
120
- let transactionProvider: SQLiteTransactionProvider
121
- let statements: SqlStatementMetadata[]
122
-
123
- beforeEach(() => {
124
- db = new DatabaseSync(':memory:')
125
- db.exec(
126
- [
127
- 'CREATE TABLE project (id TEXT PRIMARY KEY, ownerId TEXT NOT NULL, name TEXT NOT NULL);',
128
- 'CREATE TABLE note_records (note_id TEXT PRIMARY KEY, done INTEGER NOT NULL, data TEXT);',
129
- ].join('\n'),
130
- )
131
-
132
- retryNextTransaction = false
133
- statements = []
134
- const executor: SQLiteTransactionExecutor = {
135
- async exec(sql, params = [], metadata) {
136
- if (metadata) statements.push(metadata)
137
- const result = db.prepare(sql).run(...(params as SQLInputValue[]))
138
- return { changes: Number(result.changes) }
139
- },
140
- async query<Row extends Record<string, unknown>>(sql, params = []) {
141
- return db.prepare(sql).all(...(params as SQLInputValue[])) as Row[]
142
- },
143
- async queryAst<Result>(ast, format) {
144
- let rows: Record<string, unknown>[]
145
- if (ast.table === 'project') {
146
- rows = db.prepare('SELECT * FROM project ORDER BY id').all()
147
- } else if (ast.table === 'note') {
148
- rows = db
149
- .prepare('SELECT note_id, done, data FROM note_records ORDER BY note_id')
150
- .all()
151
- .map((row) => ({
152
- id: row.note_id,
153
- done: row.done !== 0,
154
- data: typeof row.data === 'string' ? JSON.parse(row.data) : row.data,
155
- }))
156
- } else if (ast.table === 'person') {
157
- rows = [
158
- {
159
- id: 'p1',
160
- teams: [
161
- {
162
- id: 't1',
163
- active: true,
164
- metadata: { label: 'core' },
165
- },
166
- ],
167
- },
168
- ]
169
- } else {
170
- throw new Error('unexpected table ' + ast.table)
171
- }
172
- return (format.singular ? rows[0] : rows) as Result
173
- },
174
- }
175
- const run = async <R>(
176
- callback: (tx: SQLiteTransactionExecutor) => R | Promise<R>,
177
- ) => {
178
- db.exec('BEGIN')
179
- try {
180
- const value = await callback(executor)
181
- db.exec('COMMIT')
182
- return value
183
- } catch (error) {
184
- db.exec('ROLLBACK')
185
- throw error
186
- }
187
- }
188
- transactionProvider = async <R>(
189
- callback: (tx: SQLiteTransactionExecutor) => R | Promise<R>,
190
- ) => {
191
- if (retryNextTransaction) {
192
- retryNextTransaction = false
193
- db.exec('BEGIN')
194
- await callback(executor)
195
- db.exec('ROLLBACK')
196
- }
197
- return run(callback)
198
- }
199
- })
200
-
201
- afterEach(() => {
202
- db.close()
203
- })
204
-
205
- test('commits CRUD, the mutation ledger, and one retry-safe async task', async () => {
206
- let effectRuns = 0
207
- const server = createZeroSQLiteServer({
208
- schema: zeroHttpFixtureSchema,
209
- models: {
210
- project: {
211
- mutate: {
212
- create: async ({ tx, server }, value: Record<string, unknown>) => {
213
- await tx.mutate.project.insert(value as never)
214
- server?.enqueueTask(
215
- async () => {
216
- effectRuns++
217
- },
218
- { barrier: true },
219
- )
220
- },
221
- },
222
- },
223
- },
224
- createServerActions: () => ({}),
225
- transactionProvider,
226
- })
227
-
228
- retryNextTransaction = true
229
- const result = await server.handleMutationRequest({
230
- authData: null,
231
- request: pushRequest(1, 'project.create', {
232
- id: 'p1',
233
- ownerId: 'u1',
234
- name: 'first',
235
- }),
236
- skipAsyncTasks: true,
237
- })
238
-
239
- expect((result.response as any).mutations[0].result).toEqual({})
240
- expect(db.prepare('SELECT * FROM project').all()).toEqual([
241
- { id: 'p1', ownerId: 'u1', name: 'first' },
242
- ])
243
- expect(db.prepare('SELECT * FROM zero_0_clients').all()).toEqual([
244
- { clientGroupID: 'cg1', clientID: 'client-a', lastMutationID: 1 },
245
- ])
246
- expect(result.asyncTasks).toHaveLength(1)
247
- expect(result.asyncTasks[0]!.barrier).toBe(true)
248
- await result.asyncTasks[0]!.task()
249
- expect(effectRuns).toBe(1)
250
- })
251
-
252
- test('keeps later writes after inserting an existing primary key', async () => {
253
- db.prepare('INSERT INTO project (id, ownerId, name) VALUES (?, ?, ?)').run(
254
- 'p1',
255
- 'u1',
256
- 'original',
257
- )
258
- db.prepare('INSERT INTO project (id, ownerId, name) VALUES (?, ?, ?)').run(
259
- 'p2',
260
- 'u1',
261
- 'before',
262
- )
263
- const server = createZeroSQLiteServer({
264
- schema: zeroHttpFixtureSchema,
265
- models: {
266
- project: {
267
- mutate: {
268
- converge: async ({ tx }) => {
269
- await tx.mutate.project.insert({
270
- id: 'p1',
271
- ownerId: 'u2',
272
- name: 'replacement',
273
- })
274
- await tx.mutate.project.update({ id: 'p2', name: 'after' })
275
- },
276
- },
277
- },
278
- },
279
- createServerActions: () => ({}),
280
- transactionProvider,
281
- })
282
-
283
- const result = await server.handleMutationRequest({
284
- authData: null,
285
- request: pushRequest(1, 'project.converge', {}),
286
- })
287
-
288
- expect((result.response as any).mutations[0].result).toEqual({})
289
- expect(db.prepare('SELECT * FROM project ORDER BY id').all()).toEqual([
290
- { id: 'p1', ownerId: 'u1', name: 'original' },
291
- { id: 'p2', ownerId: 'u1', name: 'after' },
292
- ])
293
- })
294
-
295
- test('rolls back row writes and persists an application error with its LMID', async () => {
296
- const server = createZeroSQLiteServer({
297
- schema: zeroHttpFixtureSchema,
298
- models: {
299
- project: {
300
- mutate: {
301
- fail: async ({ tx }, value: Record<string, unknown>) => {
302
- await tx.mutate.project.insert(value as never)
303
- throw new Error('rejected')
304
- },
305
- },
306
- },
307
- },
308
- createServerActions: () => ({}),
309
- transactionProvider,
310
- })
311
-
312
- const result = await server.handleMutationRequest({
313
- authData: null,
314
- request: pushRequest(1, 'project.fail', {
315
- id: 'p1',
316
- ownerId: 'u1',
317
- name: 'first',
318
- }),
319
- })
320
-
321
- expect((result.response as any).mutations[0].result).toMatchObject({
322
- error: 'app',
323
- message: 'rejected',
324
- })
325
- expect(db.prepare('SELECT * FROM project').all()).toEqual([])
326
- expect(db.prepare('SELECT lastMutationID FROM zero_0_clients').get()).toEqual({
327
- lastMutationID: 1,
328
- })
329
- const stored = db.prepare('SELECT result FROM zero_0_mutations').get() as {
330
- result: string
331
- }
332
- expect(JSON.parse(stored.result)).toMatchObject({
333
- error: 'app',
334
- message: 'rejected',
335
- })
336
- })
337
-
338
- test('allows a custom CRUD mutation to no-op without an automatic permission check', async () => {
339
- const projectPermission = serverWhere('project', (q) => q.cmp('ownerId', 'u1'))
340
- const projectMutations = mutations('project', projectPermission, {
341
- insert: async () => {},
342
- })
343
- const server = createZeroSQLiteServer({
344
- schema: zeroHttpFixtureSchema,
345
- models: {
346
- project: { mutate: projectMutations },
347
- },
348
- createServerActions: () => ({}),
349
- transactionProvider,
350
- })
351
-
352
- const result = await server.handleMutationRequest({
353
- authData: { id: 'u1', role: 'user' },
354
- request: pushRequest(1, 'project.insert', {
355
- id: 'p1',
356
- ownerId: 'u1',
357
- name: 'skip',
358
- }),
359
- })
360
-
361
- expect((result.response as any).mutations[0].result).toEqual({})
362
- expect(db.prepare('SELECT * FROM project').all()).toEqual([])
363
- })
364
-
365
- test('rolls back when a custom CRUD mutation throws', async () => {
366
- const projectPermission = serverWhere('project', (q) => q.cmp('ownerId', 'u1'))
367
- const projectMutations = mutations('project', projectPermission, {
368
- insert: async ({ tx }, value: { id: string; ownerId: string; name: string }) => {
369
- await tx.mutate.project.insert(value)
370
- throw new Error('denied by custom validation')
371
- },
372
- })
373
- const server = createZeroSQLiteServer({
374
- schema: zeroHttpFixtureSchema,
375
- models: {
376
- project: { mutate: projectMutations },
377
- },
378
- createServerActions: () => ({}),
379
- transactionProvider,
380
- })
381
-
382
- const result = await server.handleMutationRequest({
383
- authData: { id: 'u2', role: 'user' },
384
- request: pushRequest(1, 'project.insert', {
385
- id: 'p2',
386
- ownerId: 'u2',
387
- name: 'unauthorized',
388
- }),
389
- })
390
-
391
- expect((result.response as any).mutations[0].result).toMatchObject({
392
- error: 'app',
393
- message: 'denied by custom validation',
394
- })
395
- expect(db.prepare('SELECT * FROM project').all()).toEqual([])
396
- })
397
-
398
- test('permission-checks generated CRUD mutations', async () => {
399
- let inserted: Record<string, unknown> | undefined
400
- let permissionChecks = 0
401
- const projectPermission = serverWhere('project', (q) => q.cmp('ownerId', 'u1'))
402
- const projectMutations = mutations('project', projectPermission)
403
- const value = { id: 'p3', ownerId: 'u2', name: 'unauthorized' }
404
-
405
- await expect(
406
- projectMutations.insert(
407
- {
408
- tx: {
409
- mutate: {
410
- project: {
411
- insert: async (row: Record<string, unknown>) => {
412
- inserted = row
413
- },
414
- },
415
- },
416
- },
417
- can: async (_where, row) => {
418
- permissionChecks++
419
- expect(row).toEqual(value)
420
- throw new Error('denied')
421
- },
422
- } as never,
423
- value,
424
- ),
425
- ).rejects.toThrow('denied')
426
- expect(inserted).toEqual(value)
427
- expect(permissionChecks).toBe(1)
428
- })
429
-
430
- test('recovers duplicate results and deletes them through the cleanup mutation', async () => {
431
- const server = createZeroSQLiteServer({
432
- schema: zeroHttpFixtureSchema,
433
- models: {
434
- project: {
435
- mutate: {
436
- create: async ({ tx }, value: Record<string, unknown>) => {
437
- await tx.mutate.project.insert(value as never)
438
- },
439
- },
440
- },
441
- },
442
- createServerActions: () => ({}),
443
- transactionProvider,
444
- })
445
- const value = {
446
- id: 'p1',
447
- ownerId: 'u1',
448
- name: 'first',
449
- }
450
-
451
- await server.handleMutationRequest({
452
- authData: null,
453
- request: pushRequest(1, 'project.create', value),
454
- })
455
- const duplicate = await server.handleMutationRequest({
456
- authData: null,
457
- request: pushRequest(1, 'project.create', value),
458
- })
459
-
460
- expect((duplicate.response as any).mutations[0].result).toMatchObject({
461
- error: 'alreadyProcessed',
462
- })
463
- expect(db.prepare('SELECT lastMutationID FROM zero_0_clients').get()).toEqual({
464
- lastMutationID: 1,
465
- })
466
- expect(db.prepare('SELECT COUNT(*) AS count FROM zero_0_mutations').get()).toEqual({
467
- count: 1,
468
- })
469
-
470
- await server.handleMutationRequest({
471
- authData: null,
472
- request: cleanupRequest(),
473
- })
474
- expect(db.prepare('SELECT COUNT(*) AS count FROM zero_0_mutations').get()).toEqual({
475
- count: 0,
476
- })
477
- })
478
-
479
- test('supports direct CRUD, server names, value codecs, and query AST execution', async () => {
480
- const server = createZeroSQLiteServer({
481
- schema: sqliteTypesSchema,
482
- models: {
483
- note: {
484
- mutate: {
485
- insert: async ({ tx }, value: Record<string, unknown>) => {
486
- await tx.mutate.note.insert(value as never)
487
- },
488
- upsert: async ({ tx }, value: Record<string, unknown>) => {
489
- await tx.mutate.note.upsert(value as never)
490
- },
491
- update: async ({ tx }, value: Record<string, unknown>) => {
492
- await tx.mutate.note.update(value as never)
493
- },
494
- delete: async ({ tx }, value: Record<string, unknown>) => {
495
- await tx.mutate.note.delete(value as never)
496
- },
497
- },
498
- },
499
- },
500
- createServerActions: () => ({}),
501
- transactionProvider,
502
- })
503
-
504
- await server.mutate.note.insert({
505
- id: 'n1',
506
- done: false,
507
- data: { label: 'first' },
508
- })
509
- await server.mutate.note.upsert({
510
- id: 'n1',
511
- done: true,
512
- data: { label: 'second' },
513
- })
514
- await server.mutate.note.update({
515
- id: 'n1',
516
- done: false,
517
- })
518
-
519
- expect(db.prepare('SELECT * FROM note_records').get()).toEqual({
520
- note_id: 'n1',
521
- done: 0,
522
- data: JSON.stringify({ label: 'second' }),
523
- })
524
- await expect(server.query((q) => q.note)).resolves.toEqual([
525
- {
526
- id: 'n1',
527
- done: false,
528
- data: { label: 'second' },
529
- },
530
- ])
531
- await server.transaction(async (tx) => {
532
- if (tx.location !== 'server') throw new Error('expected server transaction')
533
- await expect((tx.query as any).note.one().run()).resolves.toEqual({
534
- id: 'n1',
535
- done: false,
536
- data: { label: 'second' },
537
- })
538
- await expect(
539
- tx.dbTransaction.query('SELECT * FROM note_records', []),
540
- ).resolves.toEqual([
541
- {
542
- note_id: 'n1',
543
- done: 0,
544
- data: JSON.stringify({ label: 'second' }),
545
- },
546
- ])
547
- })
548
-
549
- await server.mutate.note.delete({ id: 'n1' })
550
- expect(db.prepare('SELECT * FROM note_records').all()).toEqual([])
551
- expect(statements).toEqual([
552
- { table: 'note_records', publicTable: 'note', kind: 'insert' },
553
- { table: 'note_records', publicTable: 'note', kind: 'upsert' },
554
- { table: 'note_records', publicTable: 'note', kind: 'update' },
555
- { table: 'note_records', publicTable: 'note', kind: 'delete' },
556
- ])
557
- })
558
-
559
- test('decodes destination rows through a hidden two-hop junction', async () => {
560
- const server = createZeroSQLiteServer({
561
- schema: twoHopSchema,
562
- models: {},
563
- createServerActions: () => ({}),
564
- transactionProvider,
565
- })
566
-
567
- await expect(server.query((q: any) => q.person.related('teams'))).resolves.toEqual([
568
- {
569
- id: 'p1',
570
- teams: [
571
- {
572
- id: 't1',
573
- active: true,
574
- metadata: { label: 'core' },
575
- },
576
- ],
577
- },
578
- ])
579
- })
580
-
581
- test('accepts a hydrated singular query result from the transaction executor', async () => {
582
- const hydrated = {
583
- id: 'n1',
584
- done: false,
585
- data: { label: 'already decoded' },
586
- }
587
- let receivedQueryName: string | undefined
588
- const hydratedExecutor = {
589
- async exec() {
590
- return { changes: 0 }
591
- },
592
- async query() {
593
- return []
594
- },
595
- async queryAst(_ast: unknown, _format: unknown, queryName?: string) {
596
- receivedQueryName = queryName
597
- return hydrated
598
- },
599
- } as unknown as SQLiteTransactionExecutor
600
- const hydratedProvider: SQLiteTransactionProvider = async (callback) =>
601
- callback(hydratedExecutor)
602
- const server = createZeroSQLiteServer({
603
- schema: sqliteTypesSchema,
604
- models: {},
605
- createServerActions: () => ({}),
606
- transactionProvider: hydratedProvider,
607
- })
608
-
609
- await expect(
610
- server.query((q) => asQueryInternals(q.note.one()).nameAndArgs('noteByID', ['n1'])),
611
- ).resolves.toEqual(hydrated)
612
- expect(receivedQueryName).toBe('noteByID')
613
- })
614
- })
@@ -1,56 +0,0 @@
1
- import { createZeroServerCore } from './createZeroServerCore'
2
- import {
3
- createSQLiteDatabase,
4
- defaultLedgerTables,
5
- encodeSQLiteValue,
6
- persistAlreadyProcessedMutationResults,
7
- type SQLiteLedgerTables,
8
- type SQLiteTransactionProvider,
9
- type SQLiteValueContext,
10
- } from './sqliteRuntime'
11
-
12
- import type { ZeroServer, ZeroServerCommonOptions } from './createZeroServerCore'
13
- import type { GenericModels } from './types'
14
- import type { Schema as ZeroSchema } from '@rocicorp/zero'
15
-
16
- export type CreateZeroSQLiteServerOptions<
17
- Schema extends ZeroSchema,
18
- Models extends GenericModels,
19
- ServerActions extends Record<string, unknown>,
20
- > = ZeroServerCommonOptions<Schema, Models, ServerActions> & {
21
- transactionProvider: SQLiteTransactionProvider
22
- ledgerTables?: (upstreamSchema: string) => SQLiteLedgerTables
23
- encodeValue?: (value: unknown, context: SQLiteValueContext) => unknown
24
- }
25
-
26
- export function createZeroSQLiteServer<
27
- Schema extends ZeroSchema,
28
- Models extends GenericModels,
29
- ServerActions extends Record<string, unknown>,
30
- >({
31
- encodeValue = encodeSQLiteValue,
32
- ledgerTables = defaultLedgerTables,
33
- transactionProvider,
34
- ...options
35
- }: CreateZeroSQLiteServerOptions<Schema, Models, ServerActions>): ZeroServer<
36
- Schema,
37
- Models,
38
- ServerActions
39
- > {
40
- const databaseOptions = {
41
- encodeValue,
42
- initializedLedgers: new Set<string>(),
43
- ledgerTables,
44
- schema: options.schema,
45
- transactionProvider,
46
- }
47
-
48
- return createZeroServerCore({
49
- ...options,
50
- createDatabase: () => createSQLiteDatabase(databaseOptions),
51
- persistAlreadyProcessed: (args) =>
52
- persistAlreadyProcessedMutationResults(databaseOptions, args),
53
- })
54
- }
55
-
56
- export * from './sqliteRuntime'