on-zero 0.7.2-1784530701923 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/dist/cjs/asyncTasks.cjs +51 -0
  2. package/dist/cjs/asyncTasks.native.js +84 -0
  3. package/dist/cjs/asyncTasks.native.js.map +1 -0
  4. package/dist/cjs/createZeroDirectServer.cjs +269 -0
  5. package/dist/cjs/createZeroDirectServer.native.js +287 -0
  6. package/dist/cjs/createZeroDirectServer.native.js.map +1 -0
  7. package/dist/cjs/createZeroSQLiteServer.cjs +50 -0
  8. package/dist/cjs/createZeroSQLiteServer.native.js +58 -0
  9. package/dist/cjs/createZeroSQLiteServer.native.js.map +1 -0
  10. package/dist/cjs/createZeroSQLiteServer.test.cjs +595 -0
  11. package/dist/cjs/createZeroSQLiteServer.test.native.js +647 -0
  12. package/dist/cjs/createZeroSQLiteServer.test.native.js.map +1 -0
  13. package/dist/cjs/createZeroServer.cjs +82 -0
  14. package/dist/cjs/createZeroServer.native.js +93 -0
  15. package/dist/cjs/createZeroServer.native.js.map +1 -0
  16. package/dist/cjs/createZeroServer.test.cjs +378 -0
  17. package/dist/cjs/createZeroServer.test.native.js +448 -0
  18. package/dist/cjs/createZeroServer.test.native.js.map +1 -0
  19. package/dist/cjs/createZeroServerCore.cjs +211 -0
  20. package/dist/cjs/createZeroServerCore.native.js +355 -0
  21. package/dist/cjs/createZeroServerCore.native.js.map +1 -0
  22. package/dist/cjs/helpers/createMutators.cjs +3 -4
  23. package/dist/cjs/helpers/createMutators.native.js +3 -6
  24. package/dist/cjs/helpers/createMutators.native.js.map +1 -1
  25. package/dist/cjs/httpPull/auth.test.cjs +197 -0
  26. package/dist/cjs/httpPull/auth.test.native.js +279 -0
  27. package/dist/cjs/httpPull/auth.test.native.js.map +1 -0
  28. package/dist/cjs/httpPull/churn.test.cjs +132 -0
  29. package/dist/cjs/httpPull/churn.test.native.js +155 -0
  30. package/dist/cjs/httpPull/churn.test.native.js.map +1 -0
  31. package/dist/cjs/httpPull/completeAck.test.cjs +69 -0
  32. package/dist/cjs/httpPull/completeAck.test.native.js +76 -0
  33. package/dist/cjs/httpPull/completeAck.test.native.js.map +1 -0
  34. package/dist/cjs/httpPull/fixtureServer.cjs +340 -0
  35. package/dist/cjs/httpPull/fixtureServer.native.js +534 -0
  36. package/dist/cjs/httpPull/fixtureServer.native.js.map +1 -0
  37. package/dist/cjs/httpPull/integration.test.cjs +53 -0
  38. package/dist/cjs/httpPull/integration.test.native.js +60 -0
  39. package/dist/cjs/httpPull/integration.test.native.js.map +1 -0
  40. package/dist/cjs/httpPull/rebase.test.cjs +360 -0
  41. package/dist/cjs/httpPull/rebase.test.native.js +420 -0
  42. package/dist/cjs/httpPull/rebase.test.native.js.map +1 -0
  43. package/dist/cjs/httpPull/relations.test.cjs +107 -0
  44. package/dist/cjs/httpPull/relations.test.native.js +119 -0
  45. package/dist/cjs/httpPull/relations.test.native.js.map +1 -0
  46. package/dist/cjs/httpPull/testHarness.cjs +100 -0
  47. package/dist/cjs/httpPull/testHarness.native.js +112 -0
  48. package/dist/cjs/httpPull/testHarness.native.js.map +1 -0
  49. package/dist/cjs/index.cjs +1 -0
  50. package/dist/cjs/index.native.js +1 -0
  51. package/dist/cjs/index.native.js.map +1 -1
  52. package/dist/cjs/run.cjs +1 -1
  53. package/dist/cjs/run.native.js +1 -1
  54. package/dist/cjs/server.cjs +22 -0
  55. package/dist/cjs/server.native.js +4 -0
  56. package/dist/cjs/server.native.js.map +1 -0
  57. package/dist/cjs/sqliteRuntime.cjs +318 -0
  58. package/dist/cjs/sqliteRuntime.native.js +438 -0
  59. package/dist/cjs/sqliteRuntime.native.js.map +1 -0
  60. package/dist/cjs/state.cjs +1 -1
  61. package/dist/cjs/state.native.js +1 -1
  62. package/dist/cjs/syncHost.cjs +179 -0
  63. package/dist/cjs/syncHost.native.js +388 -0
  64. package/dist/cjs/syncHost.native.js.map +1 -0
  65. package/dist/cjs/syncHost.test.cjs +240 -0
  66. package/dist/cjs/syncHost.test.native.js +290 -0
  67. package/dist/cjs/syncHost.test.native.js.map +1 -0
  68. package/dist/cjs/zeroRunner.cjs +1 -1
  69. package/dist/cjs/zeroRunner.native.js +1 -1
  70. package/dist/esm/asyncTasks.mjs +26 -0
  71. package/dist/esm/asyncTasks.mjs.map +1 -0
  72. package/dist/esm/asyncTasks.native.js +56 -0
  73. package/dist/esm/asyncTasks.native.js.map +1 -0
  74. package/dist/esm/createZeroDirectServer.mjs +241 -0
  75. package/dist/esm/createZeroDirectServer.mjs.map +1 -0
  76. package/dist/esm/createZeroDirectServer.native.js +256 -0
  77. package/dist/esm/createZeroDirectServer.native.js.map +1 -0
  78. package/dist/esm/createZeroSQLiteServer.mjs +24 -0
  79. package/dist/esm/createZeroSQLiteServer.mjs.map +1 -0
  80. package/dist/esm/createZeroSQLiteServer.native.js +29 -0
  81. package/dist/esm/createZeroSQLiteServer.native.js.map +1 -0
  82. package/dist/esm/createZeroSQLiteServer.test.mjs +596 -0
  83. package/dist/esm/createZeroSQLiteServer.test.mjs.map +1 -0
  84. package/dist/esm/createZeroSQLiteServer.test.native.js +645 -0
  85. package/dist/esm/createZeroSQLiteServer.test.native.js.map +1 -0
  86. package/dist/esm/createZeroServer.mjs +57 -0
  87. package/dist/esm/createZeroServer.mjs.map +1 -0
  88. package/dist/esm/createZeroServer.native.js +65 -0
  89. package/dist/esm/createZeroServer.native.js.map +1 -0
  90. package/dist/esm/createZeroServer.test.mjs +379 -0
  91. package/dist/esm/createZeroServer.test.mjs.map +1 -0
  92. package/dist/esm/createZeroServer.test.native.js +446 -0
  93. package/dist/esm/createZeroServer.test.native.js.map +1 -0
  94. package/dist/esm/createZeroServerCore.mjs +186 -0
  95. package/dist/esm/createZeroServerCore.mjs.map +1 -0
  96. package/dist/esm/createZeroServerCore.native.js +327 -0
  97. package/dist/esm/createZeroServerCore.native.js.map +1 -0
  98. package/dist/esm/helpers/createMutators.mjs +3 -4
  99. package/dist/esm/helpers/createMutators.mjs.map +1 -1
  100. package/dist/esm/helpers/createMutators.native.js +3 -6
  101. package/dist/esm/helpers/createMutators.native.js.map +1 -1
  102. package/dist/esm/httpPull/auth.test.mjs +198 -0
  103. package/dist/esm/httpPull/auth.test.mjs.map +1 -0
  104. package/dist/esm/httpPull/auth.test.native.js +277 -0
  105. package/dist/esm/httpPull/auth.test.native.js.map +1 -0
  106. package/dist/esm/httpPull/churn.test.mjs +133 -0
  107. package/dist/esm/httpPull/churn.test.mjs.map +1 -0
  108. package/dist/esm/httpPull/churn.test.native.js +153 -0
  109. package/dist/esm/httpPull/churn.test.native.js.map +1 -0
  110. package/dist/esm/httpPull/completeAck.test.mjs +70 -0
  111. package/dist/esm/httpPull/completeAck.test.mjs.map +1 -0
  112. package/dist/esm/httpPull/completeAck.test.native.js +74 -0
  113. package/dist/esm/httpPull/completeAck.test.native.js.map +1 -0
  114. package/dist/esm/httpPull/fixtureServer.mjs +315 -0
  115. package/dist/esm/httpPull/fixtureServer.mjs.map +1 -0
  116. package/dist/esm/httpPull/fixtureServer.native.js +506 -0
  117. package/dist/esm/httpPull/fixtureServer.native.js.map +1 -0
  118. package/dist/esm/httpPull/integration.test.mjs +54 -0
  119. package/dist/esm/httpPull/integration.test.mjs.map +1 -0
  120. package/dist/esm/httpPull/integration.test.native.js +58 -0
  121. package/dist/esm/httpPull/integration.test.native.js.map +1 -0
  122. package/dist/esm/httpPull/rebase.test.mjs +361 -0
  123. package/dist/esm/httpPull/rebase.test.mjs.map +1 -0
  124. package/dist/esm/httpPull/rebase.test.native.js +418 -0
  125. package/dist/esm/httpPull/rebase.test.native.js.map +1 -0
  126. package/dist/esm/httpPull/relations.test.mjs +108 -0
  127. package/dist/esm/httpPull/relations.test.mjs.map +1 -0
  128. package/dist/esm/httpPull/relations.test.native.js +117 -0
  129. package/dist/esm/httpPull/relations.test.native.js.map +1 -0
  130. package/dist/esm/httpPull/testHarness.mjs +72 -0
  131. package/dist/esm/httpPull/testHarness.mjs.map +1 -0
  132. package/dist/esm/httpPull/testHarness.native.js +81 -0
  133. package/dist/esm/httpPull/testHarness.native.js.map +1 -0
  134. package/dist/esm/index.js +1 -0
  135. package/dist/esm/index.js.map +1 -1
  136. package/dist/esm/index.mjs +1 -0
  137. package/dist/esm/index.mjs.map +1 -1
  138. package/dist/esm/index.native.js +1 -0
  139. package/dist/esm/index.native.js.map +1 -1
  140. package/dist/esm/run.mjs +1 -1
  141. package/dist/esm/run.mjs.map +1 -1
  142. package/dist/esm/run.native.js +1 -1
  143. package/dist/esm/server.mjs +4 -0
  144. package/dist/esm/server.mjs.map +1 -0
  145. package/dist/esm/server.native.js +2 -0
  146. package/dist/esm/server.native.js.map +1 -0
  147. package/dist/esm/sqliteRuntime.mjs +289 -0
  148. package/dist/esm/sqliteRuntime.mjs.map +1 -0
  149. package/dist/esm/sqliteRuntime.native.js +406 -0
  150. package/dist/esm/sqliteRuntime.native.js.map +1 -0
  151. package/dist/esm/state.mjs +1 -1
  152. package/dist/esm/state.native.js +1 -1
  153. package/dist/esm/syncHost.mjs +153 -0
  154. package/dist/esm/syncHost.mjs.map +1 -0
  155. package/dist/esm/syncHost.native.js +359 -0
  156. package/dist/esm/syncHost.native.js.map +1 -0
  157. package/dist/esm/syncHost.test.mjs +217 -0
  158. package/dist/esm/syncHost.test.mjs.map +1 -0
  159. package/dist/esm/syncHost.test.native.js +264 -0
  160. package/dist/esm/syncHost.test.native.js.map +1 -0
  161. package/dist/esm/zeroRunner.mjs +1 -1
  162. package/dist/esm/zeroRunner.mjs.map +1 -1
  163. package/dist/esm/zeroRunner.native.js +1 -1
  164. package/package.json +23 -8
  165. package/readme.md +65 -40
  166. package/src/asyncTasks.ts +36 -0
  167. package/src/createZeroClient.tsx +1 -1
  168. package/src/createZeroDirectServer.ts +411 -0
  169. package/src/createZeroSQLiteServer.test.ts +614 -0
  170. package/src/createZeroSQLiteServer.ts +56 -0
  171. package/src/createZeroServer.test.ts +421 -0
  172. package/src/createZeroServer.ts +105 -0
  173. package/src/createZeroServerCore.ts +296 -0
  174. package/src/helpers/createMutators.ts +2 -6
  175. package/src/httpPull/auth.test.ts +208 -0
  176. package/src/httpPull/churn.test.ts +147 -0
  177. package/src/httpPull/completeAck.test.ts +80 -0
  178. package/src/httpPull/fixtureServer.ts +391 -0
  179. package/src/httpPull/integration.test.ts +57 -0
  180. package/src/httpPull/rebase.test.ts +368 -0
  181. package/src/httpPull/relations.test.ts +135 -0
  182. package/src/httpPull/testHarness.ts +95 -0
  183. package/src/index.ts +1 -0
  184. package/src/run.ts +1 -1
  185. package/src/server.native.ts +3 -0
  186. package/src/server.ts +4 -0
  187. package/src/sqliteRuntime.ts +512 -0
  188. package/src/state.ts +1 -1
  189. package/src/syncHost.test.ts +223 -0
  190. package/src/syncHost.ts +294 -0
  191. package/src/types.ts +5 -0
  192. package/src/zeroRunner.ts +1 -1
  193. package/test-fixtures/server-return-types.ts +58 -21
  194. package/types/asyncTasks.d.ts +11 -0
  195. package/types/asyncTasks.d.ts.map +1 -0
  196. package/types/createZeroDirectServer.d.ts +80 -0
  197. package/types/createZeroDirectServer.d.ts.map +1 -0
  198. package/types/createZeroSQLiteServer.d.ts +12 -0
  199. package/types/createZeroSQLiteServer.d.ts.map +1 -0
  200. package/types/createZeroSQLiteServer.test.d.ts +2 -0
  201. package/types/createZeroSQLiteServer.test.d.ts.map +1 -0
  202. package/types/createZeroServer.d.ts +18 -0
  203. package/types/createZeroServer.d.ts.map +1 -0
  204. package/types/createZeroServer.test.d.ts +2 -0
  205. package/types/createZeroServer.test.d.ts.map +1 -0
  206. package/types/createZeroServerCore.d.ts +256 -0
  207. package/types/createZeroServerCore.d.ts.map +1 -0
  208. package/types/helpers/createMutators.d.ts +1 -2
  209. package/types/helpers/createMutators.d.ts.map +1 -1
  210. package/types/httpPull/auth.test.d.ts +2 -0
  211. package/types/httpPull/auth.test.d.ts.map +1 -0
  212. package/types/httpPull/churn.test.d.ts +2 -0
  213. package/types/httpPull/churn.test.d.ts.map +1 -0
  214. package/types/httpPull/completeAck.test.d.ts +2 -0
  215. package/types/httpPull/completeAck.test.d.ts.map +1 -0
  216. package/types/httpPull/fixtureSchema.d.ts +1 -1
  217. package/types/httpPull/fixtureServer.d.ts +14 -0
  218. package/types/httpPull/fixtureServer.d.ts.map +1 -0
  219. package/types/httpPull/integration.test.d.ts +2 -0
  220. package/types/httpPull/integration.test.d.ts.map +1 -0
  221. package/types/httpPull/rebase.test.d.ts +2 -0
  222. package/types/httpPull/rebase.test.d.ts.map +1 -0
  223. package/types/httpPull/relations.test.d.ts +2 -0
  224. package/types/httpPull/relations.test.d.ts.map +1 -0
  225. package/types/httpPull/testHarness.d.ts +32 -0
  226. package/types/httpPull/testHarness.d.ts.map +1 -0
  227. package/types/index.d.ts +1 -0
  228. package/types/index.d.ts.map +1 -1
  229. package/types/server.d.ts +5 -0
  230. package/types/server.d.ts.map +1 -0
  231. package/types/server.native.d.ts +1 -0
  232. package/types/server.native.d.ts.map +1 -0
  233. package/types/sqliteRuntime.d.ts +71 -0
  234. package/types/sqliteRuntime.d.ts.map +1 -0
  235. package/types/syncHost.d.ts +42 -0
  236. package/types/syncHost.d.ts.map +1 -0
  237. package/types/syncHost.test.d.ts +2 -0
  238. package/types/syncHost.test.d.ts.map +1 -0
  239. package/types/types.d.ts +4 -0
  240. package/types/types.d.ts.map +1 -1
  241. package/dist/cjs/orez.cjs +0 -227
  242. package/dist/cjs/orez.native.js +0 -314
  243. package/dist/cjs/orez.native.js.map +0 -1
  244. package/dist/cjs/orez.test.cjs +0 -211
  245. package/dist/cjs/orez.test.native.js +0 -226
  246. package/dist/cjs/orez.test.native.js.map +0 -1
  247. package/dist/esm/orez.mjs +0 -202
  248. package/dist/esm/orez.mjs.map +0 -1
  249. package/dist/esm/orez.native.js +0 -286
  250. package/dist/esm/orez.native.js.map +0 -1
  251. package/dist/esm/orez.test.mjs +0 -188
  252. package/dist/esm/orez.test.mjs.map +0 -1
  253. package/dist/esm/orez.test.native.js +0 -200
  254. package/dist/esm/orez.test.native.js.map +0 -1
  255. package/src/orez.test.ts +0 -195
  256. package/src/orez.ts +0 -331
  257. package/types/orez.d.ts +0 -53
  258. package/types/orez.d.ts.map +0 -1
  259. package/types/orez.test.d.ts +0 -2
  260. package/types/orez.test.d.ts.map +0 -1
@@ -0,0 +1,264 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ import { defineQueries, defineQuery } from "@rocicorp/zero";
3
+ import * as v from "valibot";
4
+ import { afterEach, beforeEach, describe, expect, test } from "vitest";
5
+ import { getScopedAuthData } from "./helpers/mutatorContext.native.js";
6
+ import { zeroHttpFixtureSchema } from "./httpPull/fixtureSchema.native.js";
7
+ import { createZeroSyncHostAdapter } from "./syncHost.native.js";
8
+ import { zql } from "./zql.native.js";
9
+ var queries = defineQueries({
10
+ project: {
11
+ byOwner: defineQuery(v.object({
12
+ ownerId: v.string()
13
+ }), function (param) {
14
+ var {
15
+ args
16
+ } = param;
17
+ return zql.project.where("ownerId", args.ownerId);
18
+ })
19
+ }
20
+ });
21
+ describe("createZeroSyncHostAdapter", function () {
22
+ var db;
23
+ var executor;
24
+ var transaction;
25
+ var lastQueryFormat;
26
+ var statements;
27
+ beforeEach(function () {
28
+ db = new DatabaseSync(":memory:");
29
+ db.exec("CREATE TABLE project (id TEXT PRIMARY KEY, ownerId TEXT NOT NULL, name TEXT NOT NULL)");
30
+ statements = [];
31
+ executor = {
32
+ exec(sql) {
33
+ var params = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [],
34
+ metadata = arguments.length > 2 ? arguments[2] : void 0;
35
+ if (metadata) statements.push(metadata);
36
+ var result = db.prepare(sql).run(...params);
37
+ return {
38
+ changes: Number(result.changes)
39
+ };
40
+ },
41
+ query(sql) {
42
+ var params = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
43
+ return db.prepare(sql).all(...params);
44
+ },
45
+ queryAst(_ast, format) {
46
+ lastQueryFormat = format;
47
+ var rows = db.prepare("SELECT * FROM project ORDER BY id").all();
48
+ return format.singular ? rows[0] : rows;
49
+ }
50
+ };
51
+ transaction = async function (work) {
52
+ var effects = [];
53
+ db.exec("BEGIN");
54
+ try {
55
+ var value = await work(executor, {
56
+ defer(effect2) {
57
+ effects.push(effect2);
58
+ }
59
+ });
60
+ db.exec("COMMIT");
61
+ var _iteratorNormalCompletion = true,
62
+ _didIteratorError = false,
63
+ _iteratorError = void 0;
64
+ try {
65
+ for (var _iterator = effects[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
66
+ var effect = _step.value;
67
+ await effect();
68
+ }
69
+ } catch (err) {
70
+ _didIteratorError = true;
71
+ _iteratorError = err;
72
+ } finally {
73
+ try {
74
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
75
+ _iterator.return();
76
+ }
77
+ } finally {
78
+ if (_didIteratorError) {
79
+ throw _iteratorError;
80
+ }
81
+ }
82
+ }
83
+ return value;
84
+ } catch (error) {
85
+ db.exec("ROLLBACK");
86
+ throw error;
87
+ }
88
+ };
89
+ });
90
+ afterEach(function () {
91
+ db.close();
92
+ });
93
+ test("adapts pipe-named mutators, auth, validation, and deferred effects", async function () {
94
+ var effectAuthID;
95
+ var validatedAuthID;
96
+ var adapter = createZeroSyncHostAdapter({
97
+ schema: zeroHttpFixtureSchema,
98
+ models: {
99
+ project: {
100
+ mutate: {
101
+ create: async function (param, value) {
102
+ var {
103
+ authData,
104
+ server,
105
+ tx
106
+ } = param;
107
+ expect(authData === null || authData === void 0 ? void 0 : authData.id).toBe("u1");
108
+ await tx.mutate.project.insert(value);
109
+ server === null || server === void 0 ? void 0 : server.enqueueTask(async function () {
110
+ var _getScopedAuthData;
111
+ effectAuthID = (_getScopedAuthData = getScopedAuthData()) === null || _getScopedAuthData === void 0 ? void 0 : _getScopedAuthData.id;
112
+ });
113
+ }
114
+ }
115
+ }
116
+ },
117
+ createServerActions: function () {
118
+ return {};
119
+ },
120
+ queries,
121
+ transaction,
122
+ validateMutation(param) {
123
+ var {
124
+ authData
125
+ } = param;
126
+ validatedAuthID = authData === null || authData === void 0 ? void 0 : authData.id;
127
+ }
128
+ });
129
+ expect(Object.keys(adapter.mutators)).toEqual(["project|create", "_zero_cleanupResults"]);
130
+ await transaction(function (tx, context) {
131
+ return adapter.mutators["project|create"](tx, {
132
+ id: "p1",
133
+ ownerId: "u1",
134
+ name: "first"
135
+ }, mutationContext(context));
136
+ });
137
+ expect(db.prepare("SELECT * FROM project").all()).toEqual([{
138
+ id: "p1",
139
+ ownerId: "u1",
140
+ name: "first"
141
+ }]);
142
+ expect(validatedAuthID).toBe("u1");
143
+ expect(effectAuthID).toBe("u1");
144
+ expect(statements).toEqual([{
145
+ table: "project",
146
+ publicTable: "project",
147
+ kind: "insert"
148
+ }]);
149
+ });
150
+ test("returns a structural application error and drops rolled-back effects", async function () {
151
+ var effectRuns = 0;
152
+ var adapter = createZeroSyncHostAdapter({
153
+ schema: zeroHttpFixtureSchema,
154
+ models: {
155
+ project: {
156
+ mutate: {
157
+ reject: async function (param, value) {
158
+ var {
159
+ server,
160
+ tx
161
+ } = param;
162
+ await tx.mutate.project.insert(value);
163
+ server === null || server === void 0 ? void 0 : server.enqueueTask(async function () {
164
+ effectRuns++;
165
+ });
166
+ throw new Error("denied");
167
+ }
168
+ }
169
+ }
170
+ },
171
+ createServerActions: function () {
172
+ return {};
173
+ },
174
+ transaction
175
+ });
176
+ var error = await transaction(function (tx, context) {
177
+ return adapter.mutators["project|reject"](tx, {
178
+ id: "p1",
179
+ ownerId: "u1",
180
+ name: "must roll back"
181
+ }, mutationContext(context));
182
+ }).catch(function (caught) {
183
+ return caught;
184
+ });
185
+ expect(error).toMatchObject({
186
+ name: "MutationApplicationError",
187
+ message: "denied",
188
+ details: "denied"
189
+ });
190
+ expect(db.prepare("SELECT * FROM project").all()).toEqual([]);
191
+ expect(effectRuns).toBe(0);
192
+ });
193
+ test("uses the host queryAst compiler surface for direct server queries", async function () {
194
+ db.prepare("INSERT INTO project (id, ownerId, name) VALUES (?, ?, ?)").run("p1", "u1", "first");
195
+ var adapter = createZeroSyncHostAdapter({
196
+ schema: zeroHttpFixtureSchema,
197
+ models: {},
198
+ createServerActions: function () {
199
+ return {};
200
+ },
201
+ transaction
202
+ });
203
+ await expect(adapter.server.query(function (q) {
204
+ return q.project.one();
205
+ })).resolves.toEqual({
206
+ id: "p1",
207
+ ownerId: "u1",
208
+ name: "first"
209
+ });
210
+ expect(lastQueryFormat).toEqual({
211
+ relationships: {},
212
+ singular: true
213
+ });
214
+ });
215
+ test("resolves auth-sensitive named queries and runs query validation", async function () {
216
+ var validation;
217
+ var adapter = createZeroSyncHostAdapter({
218
+ schema: zeroHttpFixtureSchema,
219
+ models: {},
220
+ createServerActions: function () {
221
+ return {};
222
+ },
223
+ queries,
224
+ transaction,
225
+ validateQuery(args) {
226
+ validation = args;
227
+ }
228
+ });
229
+ var ast = await adapter.resolveQuery("project|byOwner", [{
230
+ ownerId: "u1"
231
+ }], {
232
+ userID: "u1",
233
+ role: "member"
234
+ });
235
+ expect(ast).toMatchObject({
236
+ table: "project"
237
+ });
238
+ expect(JSON.stringify(ast)).toContain("ownerId");
239
+ expect(JSON.stringify(ast)).toContain("u1");
240
+ expect(validation).toEqual({
241
+ authData: {
242
+ id: "u1",
243
+ role: "member",
244
+ userID: "u1"
245
+ },
246
+ queryName: "project|byOwner",
247
+ params: {
248
+ ownerId: "u1"
249
+ }
250
+ });
251
+ });
252
+ });
253
+ function mutationContext(context) {
254
+ return {
255
+ ...context,
256
+ claims: {
257
+ userID: "u1",
258
+ role: "member"
259
+ },
260
+ clientID: "client-a",
261
+ mutationID: "1"
262
+ };
263
+ }
264
+ //# sourceMappingURL=syncHost.test.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DatabaseSync","defineQueries","defineQuery","v","afterEach","beforeEach","describe","expect","test","getScopedAuthData","zeroHttpFixtureSchema","createZeroSyncHostAdapter","zql","queries","project","byOwner","object","ownerId","string","param","args","where","db","executor","transaction","lastQueryFormat","statements","exec","sql","params","arguments","length","metadata","push","result","prepare","run","changes","Number","query","all","queryAst","_ast","format","rows","singular","work","effects","value","defer","effect2","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","effect","err","return","error","close","effectAuthID","validatedAuthID","adapter","schema","models","mutate","create","authData","server","tx","id","toBe","insert","enqueueTask","_getScopedAuthData","createServerActions","validateMutation","Object","keys","mutators","toEqual","context","name","mutationContext","table","publicTable","kind","effectRuns","reject","Error","catch","caught","toMatchObject","message","details","q","one"],"sources":["../../src/syncHost.test.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,YAAA,QAAwC;AAEjD,SAASC,aAAA,EAAeC,WAAA,QAAmB;AAC3C,YAAYC,CAAA,MAAO;AACnB,SAASC,SAAA,EAAWC,UAAA,EAAYC,QAAA,EAAUC,MAAA,EAAQC,IAAA,QAAY;AAE9D,SAASC,iBAAA,QAAyB;AAClC,SAASC,qBAAA,QAA6B;AACtC,SAASC,yBAAA,QAAiC;AAC1C,SAASC,GAAA,QAAW;AASpB,IAAAC,OAAM,GAAAZ,aAAU;EACda,OAAA,EAAS;IACPC,OAAA,EAASb,WAAA,CAAAC,CAAA,CAAAa,MAAA;MAAYC,OAAE,EAAOd,CAAA,CAAEe,MAAA;IAAqB,EAAG,EAAC,UAAOC,KAC9D,EAAI;MACN;QAAAC;MAAA,IAAAD,KAAA;MACF,OAAAP,GAAA,CAAAE,OAAA,CAAAO,KAAA,YAAAD,IAAA,CAAAH,OAAA;IACD;EAED;AACE;AACAX,QAAI;EACJ,IAAIgB,EAAA;EACJ,IAAIC,QAAA;EACJ,IAAIC,WAAA;EAEJ,IAAAC,eAAiB;EACf,IAAAC,UAAS;EACTrB,UAAG;IAAAiB,EACD,OAAAtB,YAAA;IACFsB,EAAA,CAAAK,IAAA;IACAD,UAAA,GAAa,EAAC;IACdH,QAAA,GAAW;MACTI,KAAKC,GAAA,EAAK;QACR,IAAIC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A;MAC7B,OAAAnB,OAAA,CAAAiB,QAAA,mBAAAV,EAAA;QACAC,EAAA;QACA1D,OAAA,MAAc;QACZsE,IAAA;MACF,GAAAC,eAAA,CAAAF,OAAA;IACF,CAAC,EAAAS,KAAA,WAAAC,MAAA;MAED,OAAMA,MAAM;IAAmE,EAC7E;IAAQzF,MACR,CAAAwD,KAAM,EAAAkC,aAAA;MACPV,IAAA;MAEDW,OAAO,EAAG,QAAE;MACZC,OAAO;IACP;IACA5F,MAAA,CAAOe,EAAA,CAAAa,OAAU,wBAAU,EAAAK,GAAA,IAAA6C,OAAA;IAAA9E,MACzB,CAAAqF,UAAY,CAAI,CAAAhB,IAAA,CAAM;EAA6B;EACxCpE,IACX,oEAAwB;IAC1Bc,EAAC,CAAAa,OAAA,6DAAAC,GAAA;IACF,IAAA+B,OAAA,GAAAxD,yBAAA;MACFyD,MAAA,EAAA1D,qBAAA;MAED2D,MAAS;MAGPW,mBAAO,WAAAA,CAAA;QACF;MACH;MACAxD;IACA;IACF,MAAAjB,MAAA,CAAA4D,OAAA,CAAAM,MAAA,CAAAlC,KAAA,WAAA6D,CAAA;MACF,OAAAA,CAAA,CAAAtF,OAAA,CAAAuF,GAAA","ignoreList":[]}
@@ -14,7 +14,7 @@ function getAmbientRunner(instance) {
14
14
  return instance.runner;
15
15
  }
16
16
  if (!runner) {
17
- throw new Error("Zero runner not initialized. Ensure ProvideZero is mounted or server bindings are active.");
17
+ throw new Error("Zero runner not initialized. Ensure ProvideZero is mounted (client) or createZeroServer is called (server).");
18
18
  }
19
19
  return runner;
20
20
  }
@@ -1 +1 @@
1
- {"version":3,"names":["isInZeroMutation","mutatorContext","runner","setRunner","r","getRunner","instance","q","o","tx","run","getAmbientRunner","Error"],"sources":["../../src/zeroRunner.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,gBAAA,EAAkBC,cAAA,QAAsB;AAgBjD,IAAIC,MAAA,GAA4B;AAEzB,SAASC,UAAUC,CAAA,EAAsB;EAC9CF,MAAA,GAASE,CAAA;AACX;AAEO,SAASC,UAAUC,QAAA,EAAsD;EAC9E,IAAIN,gBAAA,CAAiB,GAAG;IACtB,OAAO,CAACO,CAAA,EAAGC,CAAA,KAAMP,cAAA,CAAe,EAAEQ,EAAA,CAAGC,GAAA,CAAIH,CAAA,EAAGC,CAAC;EAC/C;EAEA,OAAOG,gBAAA,CAAiBL,QAAQ;AAClC;AAEO,SAASK,iBAAiBL,QAAA,EAAsD;EAGrF,IAAIA,QAAA,EAAUJ,MAAA,EAAQ;IACpB,OAAOI,QAAA,CAASJ,MAAA;EAClB;EAEA,IAAI,CAACA,MAAA,EAAQ;IACX,MAAM,IAAIU,KAAA,CACR,2FACF;EACF;EAEA,OAAOV,MAAA;AACT","ignoreList":[]}
1
+ {"version":3,"names":["isInZeroMutation","mutatorContext","runner","setRunner","r","getRunner","instance","q","o","tx","run","getAmbientRunner","Error"],"sources":["../../src/zeroRunner.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,gBAAA,EAAkBC,cAAA,QAAsB;AAgBjD,IAAIC,MAAA,GAA4B;AAEzB,SAASC,UAAUC,CAAA,EAAsB;EAC9CF,MAAA,GAASE,CAAA;AACX;AAEO,SAASC,UAAUC,QAAA,EAAsD;EAC9E,IAAIN,gBAAA,CAAiB,GAAG;IACtB,OAAO,CAACO,CAAA,EAAGC,CAAA,KAAMP,cAAA,CAAe,EAAEQ,EAAA,CAAGC,GAAA,CAAIH,CAAA,EAAGC,CAAC;EAC/C;EAEA,OAAOG,gBAAA,CAAiBL,QAAQ;AAClC;AAEO,SAASK,iBAAiBL,QAAA,EAAsD;EAGrF,IAAIA,QAAA,EAAUJ,MAAA,EAAQ;IACpB,OAAOI,QAAA,CAASJ,MAAA;EAClB;EAEA,IAAI,CAACA,MAAA,EAAQ;IACX,MAAM,IAAIU,KAAA,CACR,6GACF;EACF;EAEA,OAAOV,MAAA;AACT","ignoreList":[]}
@@ -16,7 +16,7 @@ function getAmbientRunner(instance) {
16
16
  return instance.runner;
17
17
  }
18
18
  if (!runner) {
19
- throw new Error("Zero runner not initialized. Ensure ProvideZero is mounted or server bindings are active.");
19
+ throw new Error("Zero runner not initialized. Ensure ProvideZero is mounted (client) or createZeroServer is called (server).");
20
20
  }
21
21
  return runner;
22
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "on-zero",
3
- "version": "0.7.2-1784530701923",
3
+ "version": "0.7.2",
4
4
  "description": "A typed layer over @rocicorp/zero with queries, mutations, and permissions",
5
5
  "sideEffects": false,
6
6
  "source": "src/index.ts",
@@ -56,10 +56,21 @@
56
56
  "require": "./dist/cjs/index.cjs",
57
57
  "default": "./dist/esm/index.mjs"
58
58
  },
59
- "./orez": {
60
- "types": "./types/orez.d.ts",
61
- "import": "./dist/esm/orez.mjs",
62
- "require": "./dist/cjs/orez.cjs"
59
+ "./server": {
60
+ "react-native": "./dist/esm/server.native.js",
61
+ "types": "./types/server.d.ts",
62
+ "import": "./dist/esm/server.mjs",
63
+ "require": "./dist/cjs/server.cjs"
64
+ },
65
+ "./sqlite": {
66
+ "types": "./types/createZeroSQLiteServer.d.ts",
67
+ "import": "./dist/esm/createZeroSQLiteServer.mjs",
68
+ "require": "./dist/cjs/createZeroSQLiteServer.cjs"
69
+ },
70
+ "./sync-host": {
71
+ "types": "./types/syncHost.d.ts",
72
+ "import": "./dist/esm/syncHost.mjs",
73
+ "require": "./dist/cjs/syncHost.cjs"
63
74
  },
64
75
  "./http-pull": {
65
76
  "types": "./types/httpPullTransport.d.ts",
@@ -89,16 +100,16 @@
89
100
  }
90
101
  },
91
102
  "dependencies": {
92
- "@take-out/helpers": "0.7.2-1784530701923",
103
+ "@take-out/helpers": "0.7.2",
93
104
  "chokidar": "^4.0.3",
94
105
  "citty": "^0.1.6",
95
- "orez": ">=0.5.31",
96
106
  "valibot": "^1.1.0"
97
107
  },
98
108
  "peerDependencies": {
99
- "@rocicorp/zero": ">=1.7.0",
109
+ "@rocicorp/zero": ">=1.5.0",
100
110
  "drizzle-orm": ">=1.0.0-beta.0 <2",
101
111
  "drizzle-zero-sqlite": "^0.5.20",
112
+ "pg": ">=8.0.0",
102
113
  "react": "*",
103
114
  "react-native": "*"
104
115
  },
@@ -106,6 +117,9 @@
106
117
  "react-native": {
107
118
  "optional": true
108
119
  },
120
+ "pg": {
121
+ "optional": true
122
+ },
109
123
  "drizzle-orm": {
110
124
  "optional": true
111
125
  },
@@ -116,6 +130,7 @@
116
130
  "devDependencies": {
117
131
  "@tamagui/build": "2.3.1",
118
132
  "@types/node": "25.2.0",
133
+ "@types/pg": "^8.11.10",
119
134
  "@types/react": "^19.0.0",
120
135
  "jsdom": "29.1.1",
121
136
  "oxfmt": "^0.16.0",
package/readme.md CHANGED
@@ -501,57 +501,77 @@ export const { ProvideZero, useQuery, zero, usePermission } = createZeroClient({
501
501
  </ProvideZero>
502
502
  ```
503
503
 
504
- server bindings:
504
+ server:
505
505
 
506
506
  ```ts
507
- import { createOrezBindings } from 'on-zero/orez'
508
- import {
509
- createPostgreSQLApplicationDatabase,
510
- createSyncExecutor,
511
- handleSyncExecutorPushRequest,
512
- } from 'orez/sync-executor'
507
+ import { createZeroServer } from 'on-zero/server'
513
508
  import { syncedQueries } from '~/data/generated/syncedQueries'
514
509
  import { mutationValidators } from '~/data/generated/syncedMutations'
515
510
 
516
- export const zeroBindings = createOrezBindings({
511
+ export const zeroServer = createZeroServer({
517
512
  schema,
518
513
  models,
519
- queries: syncedQueries,
520
- mutations: mutationValidators,
514
+ database: process.env.DATABASE_URL,
515
+ queries: syncedQueries, // required for synced queries / pull endpoint
516
+ mutations: mutationValidators, // auto-validates mutation args with valibot
521
517
  createServerActions: () => ({
522
518
  sendEmail: async (to, subject, body) => { ... }
523
519
  })
524
520
  })
525
521
 
526
- export const zeroExecutor = createSyncExecutor({
527
- schema,
528
- mutators: zeroBindings.mutators,
529
- database: createPostgreSQLApplicationDatabase(pool, {
530
- schema,
531
- internalSchema: 'zero_0',
532
- }),
533
- effects: {
534
- runBackground: (promise) => host.waitUntil(promise),
535
- report: (error) => console.error(error),
536
- },
522
+ // push endpoint for mutations
523
+ app.post('/api/zero/push', async (req) => {
524
+ const authData = await getAuthFromRequest(req)
525
+ const { response } = await zeroServer.handleMutationRequest({
526
+ authData,
527
+ request: req,
528
+ scheduleBackgroundTask: (promise) => host.waitUntil(promise)
529
+ })
530
+ return response
537
531
  })
538
532
 
539
- export const zeroServer = zeroBindings.server(zeroExecutor)
540
-
541
- app.post('/api/zero/push', async (request) => {
542
- const claims = await getClaimsFromRequest(request)
543
- return handleSyncExecutorPushRequest({ executor: zeroExecutor, request, claims })
533
+ // pull endpoint for synced queries
534
+ app.post('/api/zero/pull', async (req) => {
535
+ const authData = await getAuthFromRequest(req)
536
+ const { response } = await zeroServer.handleQueryRequest({
537
+ authData,
538
+ request: req
539
+ })
540
+ return response
544
541
  })
542
+ ```
543
+
544
+ `scheduleBackgroundTask` is the request host's lifetime hook, such as
545
+ Cloudflare Workers' `ctx.waitUntil`. on-zero passes it one promise that settles
546
+ after every non-barrier mutator task settles, including when a sibling rejects.
547
+ Without a scheduler, `handleMutationRequest` waits for those tasks before it
548
+ returns.
545
549
 
546
- app.post('/api/zero/pull', async (request) => {
547
- const authData = await getAuthFromRequest(request)
548
- return Response.json(await zeroBindings.transformQueryRequest({ authData, request }))
550
+ SQLite uses the same handler surface through a separate entrypoint that does
551
+ not import the PostgreSQL adapter:
552
+
553
+ ```ts
554
+ import { createZeroSQLiteServer } from 'on-zero/sqlite'
555
+
556
+ export const zeroServer = createZeroSQLiteServer({
557
+ schema,
558
+ models,
559
+ queries: syncedQueries,
560
+ mutations: mutationValidators,
561
+ createServerActions: () => ({ ... }),
562
+ transactionProvider: (callback) =>
563
+ storage.transaction(() => callback(sqliteExecutor)),
549
564
  })
550
565
  ```
551
566
 
552
- Orez owns the transaction, CRUD SQL, client ledger, replay, and effect
553
- scheduling. on-zero supplies the mutator registry, auth/query helpers, and typed
554
- direct-call facade.
567
+ `sqliteExecutor` implements `exec`, `query`, and `queryAst`. `queryAst` receives
568
+ the query format and returns the fully materialized logical result, including
569
+ nested relationships and singular shaping. The provider must run the callback
570
+ inside the authoritative SQLite transaction. If the storage engine retries the
571
+ callback, on-zero discards tasks from the abandoned attempt and returns only
572
+ tasks from the committed attempt. The first push creates the `<schema>_clients`
573
+ and `<schema>_mutations` ledger tables in that transaction; for example,
574
+ `schema=zero_0` creates `zero_0_clients` and `zero_0_mutations`.
555
575
 
556
576
  ### multiple client instances
557
577
 
@@ -611,7 +631,7 @@ constraints:
611
631
  - a mutator may only read/write tables owned by its own instance. its
612
632
  transaction runs on that instance alone; cross-instance writes are not
613
633
  detectable at registration and will silently miss the other store.
614
- - the server stays single: one Orez executor and binding registry per database.
634
+ - the server stays single: one `createZeroServer` per backend process.
615
635
  - omitting `instanceName` keeps the exact single-instance behavior.
616
636
 
617
637
  **guarding the partition against drift.** a generated namespace that ends up in
@@ -639,9 +659,10 @@ assertZeroInstancePartition('model namespace', models, {
639
659
  add custom validation for all queries and mutations:
640
660
 
641
661
  ```ts
642
- export const zeroBindings = createOrezBindings({
662
+ export const zeroServer = createZeroServer({
643
663
  schema,
644
664
  models,
665
+ database: process.env.DATABASE_URL,
645
666
  queries: syncedQueries,
646
667
  createServerActions: () => ({ ... }),
647
668
 
@@ -666,6 +687,9 @@ export const zeroBindings = createOrezBindings({
666
687
  // - 'off': no admin bypass, normal permission checks apply
667
688
  defaultAllowAdminRole: 'all',
668
689
 
690
+ // default authData for zeroServer.mutate when none is provided or in scope
691
+ // defaults to {}
692
+ defaultMutateAuthData: { id: 'system', email: 'system@example.com' },
669
693
  })
670
694
  ```
671
695
 
@@ -676,12 +700,12 @@ generator uses the TypeScript type checker to deeply resolve param types -
676
700
  including imported types, aliases, and cross-file references - then converts them
677
701
  to valibot schemas.
678
702
 
679
- pass the generated `mutationValidators` to `createOrezBindings`:
703
+ pass the generated `mutationValidators` to `createZeroServer`:
680
704
 
681
705
  ```ts
682
706
  import { mutationValidators } from '~/data/generated/syncedMutations'
683
707
 
684
- export const zeroBindings = createOrezBindings({
708
+ export const zeroServer = createZeroServer({
685
709
  // ...
686
710
  mutations: mutationValidators,
687
711
  })
@@ -939,17 +963,21 @@ await zeroServer.mutate.user.insert(user)
939
963
  // with explicit auth (optional - authData auto-resolves from context)
940
964
  await zeroServer.mutate.user.insert(user, { authData: { id: userId, email } })
941
965
 
966
+ // await async tasks (effects) before returning
967
+ await zeroServer.mutate.user.insert(user, { awaitEffects: true })
942
968
  ```
943
969
 
944
970
  the second argument is an options object:
945
971
 
946
972
  - `authData` — override auth for this call (optional, auto-resolves from context)
973
+ - `awaitEffects` — if `true`, awaits async tasks before returning (default: fire-and-forget)
947
974
 
948
975
  authData is automatically resolved in this order:
949
976
 
950
977
  1. explicit `authData` in options (if passed)
951
978
  2. current mutation context (inside a mutation)
952
979
  3. auth scope (inside async tasks - automatically inherited)
980
+ 4. `defaultMutateAuthData` from `createZeroServer` config (defaults to `{}`)
953
981
 
954
982
  **one-off queries with `run()`:**
955
983
 
@@ -1018,10 +1046,7 @@ useful for prefetching data before navigation to avoid loading states.
1018
1046
  for ad-hoc queries that don't use query functions:
1019
1047
 
1020
1048
  ```ts
1021
- const user = await zeroServer.query(
1022
- { userID: userId },
1023
- (q) => q.user.where('id', userId).one(),
1024
- )
1049
+ const user = await zeroServer.query((q) => q.user.where('id', userId).one())
1025
1050
  ```
1026
1051
 
1027
1052
  **controlling queries with `ControlQueries`:**
@@ -0,0 +1,36 @@
1
+ type AsyncTaskEntry = {
2
+ task: () => Promise<void>
3
+ barrier: boolean
4
+ }
5
+
6
+ export type RunAsyncTaskEntriesOptions = {
7
+ /** Receives the background-task promise. Omit this to await all entries. */
8
+ background?: (promise: Promise<void>) => void
9
+ }
10
+
11
+ export async function runAsyncTaskEntries(
12
+ entries: readonly AsyncTaskEntry[],
13
+ { background }: RunAsyncTaskEntriesOptions = {},
14
+ ): Promise<void> {
15
+ const barriers = entries.filter((entry) => entry.barrier)
16
+ const backgroundEntries = entries.filter((entry) => !entry.barrier)
17
+
18
+ await Promise.all(barriers.map(({ task }) => task()))
19
+ if (backgroundEntries.length === 0) return
20
+
21
+ const promise = Promise.allSettled(
22
+ backgroundEntries.map(({ task }) => Promise.resolve().then(task)),
23
+ ).then((results) => {
24
+ for (const result of results) {
25
+ if (result.status === 'rejected') {
26
+ console.error('[on-zero] async task failed', result.reason)
27
+ }
28
+ }
29
+ })
30
+
31
+ if (background) {
32
+ background(promise)
33
+ } else {
34
+ await promise
35
+ }
36
+ }
@@ -144,7 +144,7 @@ export function createZeroClientInternal<
144
144
  setSchema(schema, createBuilder(schema))
145
145
 
146
146
  // only set environment to 'client' if server hasn't already claimed it
147
- // server bindings may set this first during SSR
147
+ // (during SSR, createZeroServer runs first and sets 'server')
148
148
  if (getEnvironment() === null) {
149
149
  setEnvironment('client')
150
150
  }