@rocicorp/zero 0.18.2025032401 → 0.18.2025032800

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 (234) hide show
  1. package/out/advanced.js +0 -1
  2. package/out/{chunk-5WXONOGR.js → chunk-3S3SDA44.js} +205 -140
  3. package/out/chunk-3S3SDA44.js.map +7 -0
  4. package/out/{chunk-2B2QE5AT.js → chunk-MB3DEFRC.js} +25 -2
  5. package/out/{chunk-2B2QE5AT.js.map → chunk-MB3DEFRC.js.map} +2 -2
  6. package/out/{chunk-DSUPSGE4.js → chunk-NBZURO2P.js} +81 -26
  7. package/out/{chunk-DSUPSGE4.js.map → chunk-NBZURO2P.js.map} +4 -4
  8. package/out/{inspector-ROITQB3J.js → inspector-SH2ZK7O3.js} +253 -102
  9. package/out/inspector-SH2ZK7O3.js.map +7 -0
  10. package/out/react.js +2 -3
  11. package/out/react.js.map +2 -2
  12. package/out/shared/src/sentinels.d.ts +3 -0
  13. package/out/shared/src/sentinels.d.ts.map +1 -0
  14. package/out/solid.js +3 -4
  15. package/out/solid.js.map +2 -2
  16. package/out/z2s/src/compiler.d.ts +5 -3
  17. package/out/z2s/src/compiler.d.ts.map +1 -1
  18. package/out/z2s/src/compiler.js +116 -16
  19. package/out/z2s/src/compiler.js.map +1 -1
  20. package/out/z2s/src/sql.d.ts +8 -0
  21. package/out/z2s/src/sql.d.ts.map +1 -1
  22. package/out/z2s/src/sql.js +205 -11
  23. package/out/z2s/src/sql.js.map +1 -1
  24. package/out/zero/src/zero-cache-dev.d.ts +1 -1
  25. package/out/zero/src/zero-cache-dev.d.ts.map +1 -1
  26. package/out/zero/src/zero-cache-dev.js +1 -1
  27. package/out/zero/src/zero-cache-dev.js.map +1 -1
  28. package/out/zero-cache/src/auth/load-permissions.d.ts.map +1 -1
  29. package/out/zero-cache/src/auth/load-permissions.js +2 -1
  30. package/out/zero-cache/src/auth/load-permissions.js.map +1 -1
  31. package/out/zero-cache/src/config/zero-config.d.ts +1 -1
  32. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  33. package/out/zero-cache/src/config/zero-config.js +6 -3
  34. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  35. package/out/zero-cache/src/db/migration-lite.d.ts.map +1 -1
  36. package/out/zero-cache/src/db/migration-lite.js +9 -9
  37. package/out/zero-cache/src/db/migration-lite.js.map +1 -1
  38. package/out/zero-cache/src/scripts/deploy-permissions.d.ts +1 -1
  39. package/out/zero-cache/src/scripts/deploy-permissions.d.ts.map +1 -1
  40. package/out/zero-cache/src/scripts/deploy-permissions.js +1 -1
  41. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  42. package/out/zero-cache/src/server/multi/config.d.ts +1 -1
  43. package/out/zero-cache/src/server/multi/main.d.ts +1 -1
  44. package/out/zero-cache/src/server/multi/main.d.ts.map +1 -1
  45. package/out/zero-cache/src/server/multi/main.js +1 -1
  46. package/out/zero-cache/src/server/multi/main.js.map +1 -1
  47. package/out/zero-cache/src/server/multi/run-worker.d.ts +1 -1
  48. package/out/zero-cache/src/server/multi/run-worker.d.ts.map +1 -1
  49. package/out/zero-cache/src/server/multi/run-worker.js +1 -1
  50. package/out/zero-cache/src/server/multi/run-worker.js.map +1 -1
  51. package/out/zero-cache/src/server/syncer.js +1 -1
  52. package/out/zero-cache/src/server/syncer.js.map +1 -1
  53. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +1 -1
  54. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  55. package/out/zero-cache/src/services/change-source/pg/change-source.js +96 -42
  56. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  57. package/out/zero-cache/src/services/change-source/pg/decommission.d.ts.map +1 -1
  58. package/out/zero-cache/src/services/change-source/pg/decommission.js +16 -5
  59. package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
  60. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +1 -2
  61. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
  62. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +18 -31
  63. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  64. package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts +7 -35
  65. package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts.map +1 -1
  66. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +42 -74
  67. package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -1
  68. package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts +1 -1
  69. package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
  70. package/out/zero-cache/src/services/change-source/pg/schema/init.js +69 -21
  71. package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
  72. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +54 -27
  73. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
  74. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +53 -16
  75. package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
  76. package/out/zero-cache/src/services/mutagen/mutagen.d.ts +7 -5
  77. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  78. package/out/zero-cache/src/services/mutagen/mutagen.js +20 -5
  79. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  80. package/out/zero-cache/src/services/mutagen/pusher.d.ts +1 -1
  81. package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
  82. package/out/zero-cache/src/services/mutagen/pusher.js +24 -10
  83. package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
  84. package/out/zero-cache/src/services/replicator/change-processor.d.ts.map +1 -1
  85. package/out/zero-cache/src/services/replicator/change-processor.js +25 -14
  86. package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
  87. package/out/zero-cache/src/services/view-syncer/client-handler.d.ts +8 -4
  88. package/out/zero-cache/src/services/view-syncer/client-handler.d.ts.map +1 -1
  89. package/out/zero-cache/src/services/view-syncer/client-handler.js +47 -23
  90. package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
  91. package/out/zero-cache/src/services/view-syncer/client-schema.d.ts.map +1 -1
  92. package/out/zero-cache/src/services/view-syncer/client-schema.js +8 -2
  93. package/out/zero-cache/src/services/view-syncer/client-schema.js.map +1 -1
  94. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +2 -0
  95. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  96. package/out/zero-cache/src/services/view-syncer/cvr-store.js +35 -0
  97. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  98. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +3 -0
  99. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  100. package/out/zero-cache/src/services/view-syncer/view-syncer.js +32 -20
  101. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  102. package/out/zero-cache/src/types/bigint-json.d.ts +1 -1
  103. package/out/zero-cache/src/types/bigint-json.d.ts.map +1 -1
  104. package/out/zero-cache/src/types/bigint-json.js.map +1 -1
  105. package/out/zero-cache/src/types/lite.d.ts.map +1 -1
  106. package/out/zero-cache/src/types/lite.js +4 -3
  107. package/out/zero-cache/src/types/lite.js.map +1 -1
  108. package/out/zero-cache/src/types/shards.d.ts +4 -0
  109. package/out/zero-cache/src/types/shards.d.ts.map +1 -1
  110. package/out/zero-cache/src/types/shards.js +1 -1
  111. package/out/zero-cache/src/types/shards.js.map +1 -1
  112. package/out/zero-cache/src/workers/connection.d.ts +1 -2
  113. package/out/zero-cache/src/workers/connection.d.ts.map +1 -1
  114. package/out/zero-cache/src/workers/connection.js +64 -21
  115. package/out/zero-cache/src/workers/connection.js.map +1 -1
  116. package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
  117. package/out/zero-cache/src/workers/replicator.js +4 -8
  118. package/out/zero-cache/src/workers/replicator.js.map +1 -1
  119. package/out/zero-cache/src/workers/syncer-ws-message-handler.d.ts.map +1 -1
  120. package/out/zero-cache/src/workers/syncer-ws-message-handler.js +16 -7
  121. package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
  122. package/out/zero-client/src/client/custom.d.ts +9 -11
  123. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  124. package/out/zero-client/src/client/inspector/inspector.d.ts +2 -1
  125. package/out/zero-client/src/client/inspector/inspector.d.ts.map +1 -1
  126. package/out/zero-client/src/client/inspector/types.d.ts +7 -2
  127. package/out/zero-client/src/client/inspector/types.d.ts.map +1 -1
  128. package/out/zero-client/src/client/mutation-tracker.d.ts +23 -8
  129. package/out/zero-client/src/client/mutation-tracker.d.ts.map +1 -1
  130. package/out/zero-client/src/client/options.d.ts +7 -2
  131. package/out/zero-client/src/client/options.d.ts.map +1 -1
  132. package/out/zero-client/src/client/query-manager.d.ts +2 -1
  133. package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
  134. package/out/zero-client/src/client/zero.d.ts +1 -1
  135. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  136. package/out/zero-client/src/mod.d.ts +7 -1
  137. package/out/zero-client/src/mod.d.ts.map +1 -1
  138. package/out/zero-pg/src/custom.d.ts +2 -13
  139. package/out/zero-pg/src/custom.d.ts.map +1 -1
  140. package/out/zero-pg/src/custom.js +11 -14
  141. package/out/zero-pg/src/custom.js.map +1 -1
  142. package/out/zero-pg/src/mod.d.ts +1 -2
  143. package/out/zero-pg/src/mod.d.ts.map +1 -1
  144. package/out/zero-pg/src/mod.js +1 -1
  145. package/out/zero-pg/src/mod.js.map +1 -1
  146. package/out/zero-pg/src/query.d.ts +2 -2
  147. package/out/zero-pg/src/query.d.ts.map +1 -1
  148. package/out/zero-pg/src/query.js +8 -15
  149. package/out/zero-pg/src/query.js.map +1 -1
  150. package/out/zero-pg/src/web.d.ts +3 -7
  151. package/out/zero-pg/src/web.d.ts.map +1 -1
  152. package/out/zero-pg/src/web.js +9 -15
  153. package/out/zero-pg/src/web.js.map +1 -1
  154. package/out/zero-protocol/src/client-schema.d.ts +1 -1
  155. package/out/zero-protocol/src/client-schema.d.ts.map +1 -1
  156. package/out/zero-protocol/src/client-schema.js +1 -1
  157. package/out/zero-protocol/src/client-schema.js.map +1 -1
  158. package/out/zero-protocol/src/down.d.ts +19 -4
  159. package/out/zero-protocol/src/down.d.ts.map +1 -1
  160. package/out/zero-protocol/src/down.js +2 -2
  161. package/out/zero-protocol/src/down.js.map +1 -1
  162. package/out/zero-protocol/src/inspect-down.d.ts +59 -0
  163. package/out/zero-protocol/src/inspect-down.d.ts.map +1 -0
  164. package/out/zero-protocol/src/inspect-down.js +23 -0
  165. package/out/zero-protocol/src/inspect-down.js.map +1 -0
  166. package/out/zero-protocol/src/inspect-up.d.ts +21 -0
  167. package/out/zero-protocol/src/inspect-up.d.ts.map +1 -0
  168. package/out/zero-protocol/src/inspect-up.js +12 -0
  169. package/out/zero-protocol/src/inspect-up.js.map +1 -0
  170. package/out/zero-protocol/src/mutation-type-enum.d.ts +1 -0
  171. package/out/zero-protocol/src/mutation-type-enum.d.ts.map +1 -1
  172. package/out/zero-protocol/src/protocol-version.d.ts +1 -1
  173. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  174. package/out/zero-protocol/src/protocol-version.js +3 -1
  175. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  176. package/out/zero-protocol/src/push.d.ts +31 -6
  177. package/out/zero-protocol/src/push.d.ts.map +1 -1
  178. package/out/zero-protocol/src/push.js +7 -2
  179. package/out/zero-protocol/src/push.js.map +1 -1
  180. package/out/zero-protocol/src/up.d.ts +5 -1
  181. package/out/zero-protocol/src/up.d.ts.map +1 -1
  182. package/out/zero-protocol/src/up.js +2 -1
  183. package/out/zero-protocol/src/up.js.map +1 -1
  184. package/out/zero-react/src/use-query.d.ts +1 -2
  185. package/out/zero-react/src/use-query.d.ts.map +1 -1
  186. package/out/zero-schema/src/builder/table-builder.d.ts +13 -0
  187. package/out/zero-schema/src/builder/table-builder.d.ts.map +1 -1
  188. package/out/zero-schema/src/builder/table-builder.js +17 -0
  189. package/out/zero-schema/src/builder/table-builder.js.map +1 -1
  190. package/out/zero-schema/src/permissions.d.ts.map +1 -1
  191. package/out/zero-schema/src/table-schema.d.ts +3 -1
  192. package/out/zero-schema/src/table-schema.d.ts.map +1 -1
  193. package/out/zero-schema/src/table-schema.js.map +1 -1
  194. package/out/zero-solid/src/create-zero.d.ts.map +1 -1
  195. package/out/zero-solid/src/solid-view.d.ts +1 -2
  196. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  197. package/out/zero-solid/src/use-query.d.ts +1 -2
  198. package/out/zero-solid/src/use-query.d.ts.map +1 -1
  199. package/out/zero.js +7 -4
  200. package/out/zql/src/mutate/custom.d.ts +0 -1
  201. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  202. package/out/zql/src/mutate/custom.js.map +1 -1
  203. package/out/zql/src/query/query-impl.d.ts +9 -6
  204. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  205. package/out/zql/src/query/query-impl.js +16 -18
  206. package/out/zql/src/query/query-impl.js.map +1 -1
  207. package/out/zql/src/query/query-internal.d.ts +2 -9
  208. package/out/zql/src/query/query-internal.d.ts.map +1 -1
  209. package/out/zql/src/query/query.d.ts +5 -0
  210. package/out/zql/src/query/query.d.ts.map +1 -1
  211. package/out/zql/src/query/static-query.d.ts +1 -1
  212. package/out/zql/src/query/static-query.d.ts.map +1 -1
  213. package/out/zql/src/query/static-query.js +2 -2
  214. package/out/zql/src/query/static-query.js.map +1 -1
  215. package/out/zql/src/query/ttl.d.ts +1 -1
  216. package/out/zql/src/query/ttl.d.ts.map +1 -1
  217. package/out/zql/src/query/ttl.js +1 -1
  218. package/out/zql/src/query/ttl.js.map +1 -1
  219. package/out/zqlite/src/table-source.d.ts.map +1 -1
  220. package/out/zqlite/src/table-source.js +8 -0
  221. package/out/zqlite/src/table-source.js.map +1 -1
  222. package/package.json +4 -5
  223. package/out/chunk-5WXONOGR.js.map +0 -7
  224. package/out/chunk-ULOTOBTC.js +0 -1
  225. package/out/chunk-ULOTOBTC.js.map +0 -7
  226. package/out/inspector-ROITQB3J.js.map +0 -7
  227. package/out/zero-protocol/src/warm.d.ts +0 -10
  228. package/out/zero-protocol/src/warm.d.ts.map +0 -1
  229. package/out/zero-protocol/src/warm.js +0 -6
  230. package/out/zero-protocol/src/warm.js.map +0 -1
  231. package/out/zero-schema/src/mod.d.ts +0 -5
  232. package/out/zero-schema/src/mod.d.ts.map +0 -1
  233. package/out/zql/src/query/query-internal.js +0 -2
  234. package/out/zql/src/query/query-internal.js.map +0 -1
package/out/advanced.js CHANGED
@@ -1,4 +1,3 @@
1
- import "./chunk-ULOTOBTC.js";
2
1
  import {
3
2
  applyChange
4
3
  } from "./chunk-2NCGIK6G.js";
@@ -46,6 +46,7 @@ import {
46
46
  deepEqual,
47
47
  deepFreeze,
48
48
  deepFreezeAllowUndefined,
49
+ defaultFormat,
49
50
  desiredQueriesPrefixForClient,
50
51
  diff,
51
52
  diff2,
@@ -59,11 +60,13 @@ import {
59
60
  getClientGroupIDForClient,
60
61
  getClientGroups,
61
62
  getClients,
63
+ getNonCryptoRandomValues,
62
64
  getSizeOfValue,
63
65
  h64,
64
66
  hasClientState,
65
67
  hashOfAST,
66
68
  initClientV6,
69
+ inspectDownMessageSchema,
67
70
  isLocalMetaDD31,
68
71
  isProd,
69
72
  joinIterables,
@@ -78,6 +81,7 @@ import {
78
81
  mustGetChunk,
79
82
  mustGetClient,
80
83
  mustGetHeadHash,
84
+ nanoid,
81
85
  newQuery,
82
86
  newRandomHash,
83
87
  newWriteLocal,
@@ -112,12 +116,12 @@ import {
112
116
  withWrite,
113
117
  withWriteNoImplicitCommit,
114
118
  wrapIterable
115
- } from "./chunk-DSUPSGE4.js";
119
+ } from "./chunk-NBZURO2P.js";
116
120
  import {
117
121
  compareTTL,
118
122
  hasOwn,
119
123
  parseTTL
120
- } from "./chunk-2B2QE5AT.js";
124
+ } from "./chunk-MB3DEFRC.js";
121
125
  import {
122
126
  assert,
123
127
  assertArray,
@@ -4124,17 +4128,6 @@ function diffBinarySearch(diff3, prefix, compareKey) {
4124
4128
  );
4125
4129
  }
4126
4130
 
4127
- // ../shared/src/random-values.ts
4128
- function getNonCryptoRandomValues(array5) {
4129
- if (array5 === null) {
4130
- throw new TypeError("array cannot be null");
4131
- }
4132
- for (let i = 0; i < array5.length; i++) {
4133
- array5[i] = Math.floor(Math.random() * 256);
4134
- }
4135
- return array5;
4136
- }
4137
-
4138
4131
  // ../replicache/src/sync/request-id.ts
4139
4132
  var sessionID = "";
4140
4133
  function getSessionID() {
@@ -5558,7 +5551,9 @@ var valueTypeSchema = valita_exports.union(
5558
5551
  valita_exports.literal("number"),
5559
5552
  valita_exports.literal("boolean"),
5560
5553
  valita_exports.literal("null"),
5561
- valita_exports.literal("json")
5554
+ valita_exports.literal("json"),
5555
+ valita_exports.literal("date"),
5556
+ valita_exports.literal("timestamp")
5562
5557
  );
5563
5558
  var columnSchemaSchema = valita_exports.object({
5564
5559
  type: valueTypeSchema
@@ -5817,7 +5812,9 @@ async function definePermissions(schema, definer) {
5817
5812
  for (const name of Object.keys(schema.tables)) {
5818
5813
  expressionBuilders[name] = new StaticQuery(
5819
5814
  schema,
5820
- name
5815
+ name,
5816
+ { table: name },
5817
+ defaultFormat
5821
5818
  ).expressionBuilder();
5822
5819
  }
5823
5820
  const config = await definer();
@@ -6288,13 +6285,18 @@ var mutationIDSchema = valita_exports.object({
6288
6285
  clientID: valita_exports.string()
6289
6286
  });
6290
6287
  var appErrorSchema = valita_exports.object({
6291
- error: valita_exports.literal("app")
6292
- // the user can add any additional fields in their API server
6288
+ error: valita_exports.literal("app"),
6289
+ // The user can return any additional data here
6290
+ details: jsonSchema.optional()
6293
6291
  });
6294
6292
  var zeroErrorSchema = valita_exports.object({
6295
- error: valita_exports.literal("ooo-mutation")
6293
+ error: valita_exports.literal("ooo-mutation"),
6294
+ details: jsonSchema.optional()
6295
+ });
6296
+ var mutationOkSchema = valita_exports.object({
6297
+ // The user can return any additional data here
6298
+ data: jsonSchema.optional()
6296
6299
  });
6297
- var mutationOkSchema = valita_exports.object({});
6298
6300
  var mutationErrorSchema = valita_exports.union(appErrorSchema, zeroErrorSchema);
6299
6301
  var mutationResultSchema = valita_exports.union(mutationOkSchema, mutationErrorSchema);
6300
6302
  var mutationResponseSchema = valita_exports.object({
@@ -6355,16 +6357,9 @@ function mapCRUD(arg, map) {
6355
6357
  };
6356
6358
  }
6357
6359
 
6358
- // ../zero-protocol/src/warm.ts
6359
- var warmBodySchema = valita_exports.object({
6360
- payload: valita_exports.string()
6361
- });
6362
- var warmMessageSchema = valita_exports.tuple([valita_exports.literal("warm"), warmBodySchema]);
6363
-
6364
6360
  // ../zero-protocol/src/down.ts
6365
6361
  var downstreamSchema = valita_exports.union(
6366
6362
  connectedMessageSchema,
6367
- warmMessageSchema,
6368
6363
  errorMessageSchema,
6369
6364
  pongMessageSchema,
6370
6365
  pokeStartMessageSchema,
@@ -6372,11 +6367,12 @@ var downstreamSchema = valita_exports.union(
6372
6367
  pokeEndMessageSchema,
6373
6368
  pullResponseMessageSchema,
6374
6369
  deleteClientsMessageSchema,
6375
- pushResponseMessageSchema
6370
+ pushResponseMessageSchema,
6371
+ inspectDownMessageSchema
6376
6372
  );
6377
6373
 
6378
6374
  // ../zero-protocol/src/protocol-version.ts
6379
- var PROTOCOL_VERSION = 9;
6375
+ var PROTOCOL_VERSION = 12;
6380
6376
  var MIN_SERVER_SUPPORTED_SYNC_PROTOCOL = 6;
6381
6377
  assert(MIN_SERVER_SUPPORTED_SYNC_PROTOCOL < PROTOCOL_VERSION);
6382
6378
 
@@ -6387,24 +6383,6 @@ function customMutatorKey(namespace, name) {
6387
6383
  return `${namespace}|${name}`;
6388
6384
  }
6389
6385
 
6390
- // ../zero-client/src/util/nanoid.ts
6391
- function nanoid(size = 21) {
6392
- const randomBytes = getNonCryptoRandomValues(new Uint8Array(size));
6393
- return randomBytes.reduce((id, byte) => {
6394
- byte &= 63;
6395
- if (byte < 36) {
6396
- id += byte.toString(36);
6397
- } else if (byte < 62) {
6398
- id += (byte - 26).toString(36).toUpperCase();
6399
- } else if (byte > 62) {
6400
- id += "-";
6401
- } else {
6402
- id += "_";
6403
- }
6404
- return id;
6405
- }, "");
6406
- }
6407
-
6408
6386
  // ../zero-client/src/util/socket.ts
6409
6387
  function send(ws, data) {
6410
6388
  ws.send(JSON.stringify(data));
@@ -7909,6 +7887,11 @@ async function deleteImpl(tx, arg, schema, ivmBranch) {
7909
7887
  }
7910
7888
  }
7911
7889
 
7890
+ // ../shared/src/sentinels.ts
7891
+ function emptyFunction() {
7892
+ }
7893
+ var emptyObject = Object.freeze({});
7894
+
7912
7895
  // ../zero-client/src/client/custom.ts
7913
7896
  var TransactionImpl = class {
7914
7897
  constructor(lc, repTx, schema, slowMaterializeThreshold) {
@@ -7943,14 +7926,16 @@ var TransactionImpl = class {
7943
7926
  token;
7944
7927
  };
7945
7928
  function makeReplicacheMutator(lc, mutationTracker, mutator, schema, slowMaterializeThreshold) {
7946
- return (repTx, args) => {
7929
+ return async (repTx, args) => {
7947
7930
  const tx = new TransactionImpl(lc, repTx, schema, slowMaterializeThreshold);
7948
- const clientPromise = mutator(tx, args);
7931
+ await mutator(tx, args);
7949
7932
  if (repTx.reason === "initial") {
7950
7933
  const serverPromise = mutationTracker.trackMutation(repTx.mutationID);
7951
- clientPromise.server = serverPromise;
7934
+ return {
7935
+ server: serverPromise
7936
+ };
7952
7937
  }
7953
- return clientPromise;
7938
+ return {};
7954
7939
  };
7955
7940
  }
7956
7941
  function makeSchemaCRUD(schema, tx, ivmBranch) {
@@ -7971,8 +7956,7 @@ function makeSchemaQuery(lc, schema, ivmBranch, slowMaterializeThreshold) {
7971
7956
  const context = new ZeroContext(
7972
7957
  lc,
7973
7958
  ivmBranch,
7974
- () => () => {
7975
- },
7959
+ () => emptyFunction,
7976
7960
  () => {
7977
7961
  },
7978
7962
  (applyViewUpdates) => applyViewUpdates(),
@@ -8321,7 +8305,7 @@ function makeMessage(message, context, logLevel) {
8321
8305
  }
8322
8306
 
8323
8307
  // ../zero-client/src/client/version.ts
8324
- var version2 = "0.18.2025032401";
8308
+ var version2 = "0.18.2025032800";
8325
8309
 
8326
8310
  // ../zero-client/src/client/log-options.ts
8327
8311
  var LevelFilterLogSink = class {
@@ -8615,6 +8599,140 @@ var State = class {
8615
8599
  }
8616
8600
  };
8617
8601
 
8602
+ // ../zero-client/src/client/mutation-tracker.ts
8603
+ import { resolver as resolver7 } from "@rocicorp/resolver";
8604
+ var transientPushErrorTypes = [
8605
+ "zero-pusher",
8606
+ "http",
8607
+ // These should never actually be received as they cause the websocket
8608
+ // connection to be closed.
8609
+ "unsupported-push-version",
8610
+ "unsupported-schema-version"
8611
+ ];
8612
+ var MutationTracker = class {
8613
+ #outstandingMutations;
8614
+ #allMutationsConfirmedListeners;
8615
+ #clientID;
8616
+ constructor() {
8617
+ this.#outstandingMutations = /* @__PURE__ */ new Map();
8618
+ this.#allMutationsConfirmedListeners = /* @__PURE__ */ new Set();
8619
+ }
8620
+ set clientID(clientID) {
8621
+ this.#clientID = clientID;
8622
+ }
8623
+ trackMutation(id) {
8624
+ assert(!this.#outstandingMutations.has(id));
8625
+ const mutationResolver = resolver7();
8626
+ this.#outstandingMutations.set(id, {
8627
+ resolver: mutationResolver
8628
+ });
8629
+ return mutationResolver.promise;
8630
+ }
8631
+ processPushResponse(response) {
8632
+ if ("error" in response) {
8633
+ this.#processPushError(response);
8634
+ } else {
8635
+ this.#processPushOk(response);
8636
+ }
8637
+ }
8638
+ /**
8639
+ * When we reconnect to zero-cache, we resolve all outstanding mutations
8640
+ * whose ID is less than or equal to the lastMutationID.
8641
+ *
8642
+ * The reason is that any responses the API server sent
8643
+ * to those mutations have been lost.
8644
+ *
8645
+ * An example case: the API server responds while the connection
8646
+ * is down. Those responses are dropped.
8647
+ *
8648
+ * Mutations whose LMID is > the lastMutationID are not resolved
8649
+ * since they will be retried by the client, giving us another chance
8650
+ * at getting a response.
8651
+ *
8652
+ * The only way to ensure that all API server responses are
8653
+ * received would be to have the API server write them
8654
+ * to the DB while writing the LMID.
8655
+ *
8656
+ * This would have the downside of not being able to provide responses to a
8657
+ * mutation with data gathered after the transaction.
8658
+ */
8659
+ onConnected(lastMutationID) {
8660
+ for (const [id, entry] of this.#outstandingMutations) {
8661
+ if (id <= lastMutationID) {
8662
+ this.#settleMutation(id, entry, "resolve", emptyObject);
8663
+ } else {
8664
+ break;
8665
+ }
8666
+ }
8667
+ }
8668
+ get size() {
8669
+ return this.#outstandingMutations.size;
8670
+ }
8671
+ #processPushError(error) {
8672
+ if (transientPushErrorTypes.includes(error.error)) {
8673
+ return;
8674
+ }
8675
+ const mids = error.mutationIDs;
8676
+ if (!mids) {
8677
+ return;
8678
+ }
8679
+ for (const mid of mids) {
8680
+ this.#processMutationError(mid, error);
8681
+ }
8682
+ }
8683
+ #processPushOk(ok) {
8684
+ for (const mutation of ok.mutations) {
8685
+ if ("error" in mutation.result) {
8686
+ this.#processMutationError(mutation.id, mutation.result);
8687
+ } else {
8688
+ this.#processMutationOk(mutation.result, mutation.id);
8689
+ }
8690
+ }
8691
+ }
8692
+ #processMutationError(mid, error) {
8693
+ assert(
8694
+ mid.clientID === this.#clientID,
8695
+ "received mutation for the wrong client"
8696
+ );
8697
+ const entry = this.#outstandingMutations.get(mid.id);
8698
+ assert(entry);
8699
+ this.#settleMutation(mid.id, entry, "reject", error);
8700
+ }
8701
+ #processMutationOk(result, mid) {
8702
+ assert(
8703
+ mid.clientID === this.#clientID,
8704
+ "received mutation for the wrong client"
8705
+ );
8706
+ const entry = this.#outstandingMutations.get(mid.id);
8707
+ assert(entry);
8708
+ this.#settleMutation(mid.id, entry, "resolve", result);
8709
+ }
8710
+ #settleMutation(mutationID, entry, type, result) {
8711
+ switch (type) {
8712
+ case "resolve":
8713
+ assert(!("error" in result));
8714
+ entry.resolver.resolve(result);
8715
+ break;
8716
+ case "reject":
8717
+ assert("error" in result);
8718
+ entry.resolver.reject(result);
8719
+ break;
8720
+ }
8721
+ const removed = this.#outstandingMutations.delete(mutationID);
8722
+ if (removed && this.#outstandingMutations.size === 0) {
8723
+ this.#notifyAllMutationsConfirmedListeners();
8724
+ }
8725
+ }
8726
+ onAllMutationsConfirmed(listener) {
8727
+ this.#allMutationsConfirmedListeners.add(listener);
8728
+ }
8729
+ #notifyAllMutationsConfirmedListeners() {
8730
+ for (const listener of this.#allMutationsConfirmedListeners) {
8731
+ listener();
8732
+ }
8733
+ }
8734
+ };
8735
+
8618
8736
  // ../zero-client/src/client/ping-result-enum.ts
8619
8737
  var TimedOut = 0;
8620
8738
  var Success = 1;
@@ -8628,11 +8746,24 @@ var QueryManager = class {
8628
8746
  #recentQueriesMaxSize;
8629
8747
  #recentQueries = /* @__PURE__ */ new Set();
8630
8748
  #gotQueries = /* @__PURE__ */ new Set();
8631
- constructor(clientID, tables, send2, experimentalWatch, recentQueriesMaxSize) {
8749
+ #mutationTracker;
8750
+ #pendingRemovals = [];
8751
+ constructor(mutationTracker, clientID, tables, send2, experimentalWatch, recentQueriesMaxSize) {
8632
8752
  this.#clientID = clientID;
8633
8753
  this.#clientToServer = clientToServer(tables);
8634
8754
  this.#recentQueriesMaxSize = recentQueriesMaxSize;
8635
8755
  this.#send = send2;
8756
+ this.#mutationTracker = mutationTracker;
8757
+ this.#mutationTracker.onAllMutationsConfirmed(() => {
8758
+ if (this.#pendingRemovals.length === 0) {
8759
+ return;
8760
+ }
8761
+ const pendingRemovals = this.#pendingRemovals;
8762
+ this.#pendingRemovals = [];
8763
+ for (const removal of pendingRemovals) {
8764
+ removal();
8765
+ }
8766
+ });
8636
8767
  experimentalWatch(
8637
8768
  (diff3) => {
8638
8769
  for (const diffOp of diff3) {
@@ -8746,6 +8877,12 @@ var QueryManager = class {
8746
8877
  return;
8747
8878
  }
8748
8879
  removed = true;
8880
+ if (this.#mutationTracker.size > 0) {
8881
+ this.#pendingRemovals.push(
8882
+ () => this.#remove(entry, astHash, gotCallback)
8883
+ );
8884
+ return;
8885
+ }
8749
8886
  this.#remove(entry, astHash, gotCallback);
8750
8887
  };
8751
8888
  }
@@ -9295,84 +9432,6 @@ var ZeroRep = class {
9295
9432
  };
9296
9433
  };
9297
9434
 
9298
- // ../zero-client/src/client/mutation-tracker.ts
9299
- import { resolver as resolver7 } from "@rocicorp/resolver";
9300
- var MutationTracker = class {
9301
- #outstandingMutations;
9302
- #clientID;
9303
- constructor() {
9304
- this.#outstandingMutations = /* @__PURE__ */ new Map();
9305
- }
9306
- set clientID(clientID) {
9307
- this.#clientID = clientID;
9308
- }
9309
- trackMutation(id) {
9310
- assert(!this.#outstandingMutations.has(id));
9311
- const mutationResolver = resolver7();
9312
- this.#outstandingMutations.set(id, mutationResolver);
9313
- return mutationResolver.promise;
9314
- }
9315
- /**
9316
- * Called if the mutation is never able to be sent to the server
9317
- * and abandoned before persisted.
9318
- * In that case, we have no `pushResponse` to process.
9319
- */
9320
- rejectMutation(id, e) {
9321
- const resolver9 = this.#outstandingMutations.get(id);
9322
- assert(resolver9);
9323
- resolver9.reject(e);
9324
- this.#outstandingMutations.delete(id);
9325
- }
9326
- processPushResponse(response) {
9327
- if ("error" in response) {
9328
- this.#processPushError(response);
9329
- } else {
9330
- this.#processPushOk(response);
9331
- }
9332
- }
9333
- get size() {
9334
- return this.#outstandingMutations.size;
9335
- }
9336
- #processPushError(error) {
9337
- const mids = error.mutationIDs;
9338
- if (!mids) {
9339
- return;
9340
- }
9341
- for (const mid of mids) {
9342
- this.#processMutationError(mid, error);
9343
- }
9344
- }
9345
- #processPushOk(ok) {
9346
- for (const mutation of ok.mutations) {
9347
- if ("error" in mutation.result) {
9348
- this.#processMutationError(mutation.id, mutation.result);
9349
- } else {
9350
- this.#processMutationOk(mutation.result, mutation.id);
9351
- }
9352
- }
9353
- }
9354
- #processMutationError(mid, error) {
9355
- assert(
9356
- mid.clientID === this.#clientID,
9357
- "received mutation for the wrong client"
9358
- );
9359
- const resolver9 = this.#outstandingMutations.get(mid.id);
9360
- assert(resolver9);
9361
- resolver9.reject(error);
9362
- this.#outstandingMutations.delete(mid.id);
9363
- }
9364
- #processMutationOk(result, mid) {
9365
- assert(
9366
- mid.clientID === this.#clientID,
9367
- "received mutation for the wrong client"
9368
- );
9369
- const resolver9 = this.#outstandingMutations.get(mid.id);
9370
- assert(resolver9);
9371
- resolver9.resolve(result);
9372
- this.#outstandingMutations.delete(mid.id);
9373
- }
9374
- };
9375
-
9376
9435
  // ../zero-client/src/client/zero.ts
9377
9436
  var onSetConnectionStateSymbol = Symbol();
9378
9437
  var exposedToTestingSymbol = Symbol();
@@ -9586,6 +9645,8 @@ var Zero = class {
9586
9645
  mutatorOrMutators,
9587
9646
  schema,
9588
9647
  slowMaterializeThreshold
9648
+ // Replicache expects mutators to only be able to return JSON
9649
+ // but Zero wraps the return with: `{server?: Promise<MutationResult>, client?: T}`
9589
9650
  );
9590
9651
  continue;
9591
9652
  }
@@ -9642,6 +9703,8 @@ var Zero = class {
9642
9703
  const replicacheImplOptions = {
9643
9704
  enableClientGroupForking: false,
9644
9705
  enableMutationRecovery: false,
9706
+ enablePullAndPushInOpen: false,
9707
+ // Zero calls push in its connection management code
9645
9708
  onClientsDeleted: (clientIDs, clientGroupIDs) => this.#deleteClientsManager.onClientsDeleted(clientIDs, clientGroupIDs),
9646
9709
  zero: new ZeroRep(
9647
9710
  this.#zeroContext,
@@ -9678,10 +9741,8 @@ var Zero = class {
9678
9741
  });
9679
9742
  this.#onClientStateNotFound = onClientStateNotFoundCallback;
9680
9743
  this.#rep.onClientStateNotFound = onClientStateNotFoundCallback;
9681
- let { mutate, mutateBatch } = makeCRUDMutate(schema, rep.mutate);
9744
+ const { mutate, mutateBatch } = makeCRUDMutate(schema, rep.mutate);
9682
9745
  if (options.mutators) {
9683
- mutate = {};
9684
- mutateBatch = void 0;
9685
9746
  for (const [namespaceOrKey, mutatorsOrMutator] of Object.entries(
9686
9747
  options.mutators
9687
9748
  )) {
@@ -9704,6 +9765,7 @@ var Zero = class {
9704
9765
  this.mutate = mutate;
9705
9766
  this.mutateBatch = mutateBatch;
9706
9767
  this.#queryManager = new QueryManager(
9768
+ this.#mutationTracker,
9707
9769
  rep.clientID,
9708
9770
  schema.tables,
9709
9771
  (msg) => this.#sendChangeDesiredQueries(msg),
@@ -9928,14 +9990,14 @@ var Zero = class {
9928
9990
  return this.#handlePokeEnd(lc, downMessage);
9929
9991
  case "pull":
9930
9992
  return this.#handlePullResponse(lc, downMessage);
9931
- case "warm":
9932
- break;
9933
9993
  case "deleteClients":
9934
9994
  return this.#deleteClientsManager.clientsDeletedOnServer(
9935
9995
  downMessage[1]
9936
9996
  );
9937
9997
  case "push-response":
9938
9998
  return this.#mutationTracker.processPushResponse(downMessage[1]);
9999
+ case "inspect":
10000
+ break;
9939
10001
  default:
9940
10002
  msgType;
9941
10003
  rejectInvalidMessage();
@@ -10161,6 +10223,9 @@ var Zero = class {
10161
10223
  try {
10162
10224
  l.debug?.("Waiting for connection to be acknowledged");
10163
10225
  await this.#connectResolver.promise;
10226
+ this.#mutationTracker.onConnected(this.#lastMutationIDReceived);
10227
+ this.#rep.push().catch(() => {
10228
+ });
10164
10229
  } finally {
10165
10230
  clearTimeout(timeoutID);
10166
10231
  this.#closeAbortController.signal.removeEventListener(
@@ -10614,8 +10679,8 @@ var Zero = class {
10614
10679
  */
10615
10680
  async inspect() {
10616
10681
  BUNDLE_SIZE: {
10617
- const m = await import("./inspector-ROITQB3J.js");
10618
- return m.newInspector(this.#rep, this.#schema);
10682
+ const m = await import("./inspector-SH2ZK7O3.js");
10683
+ return m.newInspector(this.#rep, this.#schema, () => this.#socket);
10619
10684
  }
10620
10685
  }
10621
10686
  };
@@ -10733,4 +10798,4 @@ export {
10733
10798
  escapeLike,
10734
10799
  Zero
10735
10800
  };
10736
- //# sourceMappingURL=chunk-5WXONOGR.js.map
10801
+ //# sourceMappingURL=chunk-3S3SDA44.js.map