@evolu/common 8.6.2 → 8.8.0

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 (303) hide show
  1. package/dist/src/Array.d.ts +21 -21
  2. package/dist/src/Array.js +5 -5
  3. package/dist/src/Assert.d.ts +478 -141
  4. package/dist/src/Assert.d.ts.map +1 -1
  5. package/dist/src/Assert.js +644 -99
  6. package/dist/src/Binary.d.ts +254 -0
  7. package/dist/src/Binary.d.ts.map +1 -0
  8. package/dist/src/Binary.js +958 -0
  9. package/dist/src/Console.d.ts +2 -10
  10. package/dist/src/Console.d.ts.map +1 -1
  11. package/dist/src/Console.js +6 -12
  12. package/dist/src/Crypto.d.ts +5 -5
  13. package/dist/src/Crypto.js +1 -1
  14. package/dist/src/Eq.d.ts +35 -40
  15. package/dist/src/Eq.d.ts.map +1 -1
  16. package/dist/src/Eq.js +51 -87
  17. package/dist/src/Function.d.ts +9 -14
  18. package/dist/src/Function.d.ts.map +1 -1
  19. package/dist/src/Function.js +7 -9
  20. package/dist/src/Http.d.ts +6 -7
  21. package/dist/src/Http.d.ts.map +1 -1
  22. package/dist/src/LeakDetector.d.ts.map +1 -1
  23. package/dist/src/LeakDetector.js +1 -0
  24. package/dist/src/LockManager.d.ts +1 -1
  25. package/dist/src/LockManager.js +1 -1
  26. package/dist/src/Lookup.d.ts +3 -2
  27. package/dist/src/Lookup.d.ts.map +1 -1
  28. package/dist/src/Lookup.js +4 -3
  29. package/dist/src/Number.d.ts +1 -1
  30. package/dist/src/Number.d.ts.map +1 -1
  31. package/dist/src/Number.js +1 -1
  32. package/dist/src/Object.d.ts +4 -4
  33. package/dist/src/Object.d.ts.map +1 -1
  34. package/dist/src/Object.js +5 -4
  35. package/dist/src/Option.d.ts +1 -2
  36. package/dist/src/Option.d.ts.map +1 -1
  37. package/dist/src/Option.js +1 -2
  38. package/dist/src/Platform.js +2 -0
  39. package/dist/src/Polyfills.js +4 -1
  40. package/dist/src/Random.d.ts +1 -1
  41. package/dist/src/Result.d.ts +49 -54
  42. package/dist/src/Result.d.ts.map +1 -1
  43. package/dist/src/Result.js +17 -22
  44. package/dist/src/Set.d.ts +6 -6
  45. package/dist/src/Set.js +2 -2
  46. package/dist/src/Sqlite.js +1 -1
  47. package/dist/src/String.js +3 -2
  48. package/dist/src/Task.d.ts +32 -32
  49. package/dist/src/Task.d.ts.map +1 -1
  50. package/dist/src/Task.js +20 -22
  51. package/dist/src/Test.d.ts +31 -3
  52. package/dist/src/Test.d.ts.map +1 -1
  53. package/dist/src/Test.js +46 -3
  54. package/dist/src/Time.d.ts +3 -11
  55. package/dist/src/Time.d.ts.map +1 -1
  56. package/dist/src/Time.js +10 -18
  57. package/dist/src/Type.d.ts +87 -85
  58. package/dist/src/Type.d.ts.map +1 -1
  59. package/dist/src/Type.js +70 -63
  60. package/dist/src/Types.d.ts +12 -12
  61. package/dist/src/Types.js +1 -1
  62. package/dist/src/WebSocket.d.ts +4 -7
  63. package/dist/src/WebSocket.d.ts.map +1 -1
  64. package/dist/src/Worker.d.ts +1 -1
  65. package/dist/src/Worker.js +7 -7
  66. package/dist/src/index.d.ts +1 -1
  67. package/dist/src/index.js +1 -1
  68. package/dist/src/intl/_en.d.ts.map +1 -1
  69. package/dist/src/intl/_en.js +1 -1
  70. package/dist/src/intl/ar.d.ts.map +1 -1
  71. package/dist/src/intl/ar.js +1 -1
  72. package/dist/src/intl/bn.d.ts.map +1 -1
  73. package/dist/src/intl/bn.js +1 -1
  74. package/dist/src/intl/ca.d.ts.map +1 -1
  75. package/dist/src/intl/ca.js +1 -1
  76. package/dist/src/intl/cs.d.ts.map +1 -1
  77. package/dist/src/intl/cs.js +1 -1
  78. package/dist/src/intl/da.d.ts.map +1 -1
  79. package/dist/src/intl/da.js +1 -1
  80. package/dist/src/intl/de.d.ts.map +1 -1
  81. package/dist/src/intl/de.js +1 -1
  82. package/dist/src/intl/el.d.ts.map +1 -1
  83. package/dist/src/intl/el.js +1 -1
  84. package/dist/src/intl/es.d.ts.map +1 -1
  85. package/dist/src/intl/es.js +1 -1
  86. package/dist/src/intl/fa.d.ts.map +1 -1
  87. package/dist/src/intl/fa.js +1 -1
  88. package/dist/src/intl/fi.d.ts.map +1 -1
  89. package/dist/src/intl/fi.js +1 -1
  90. package/dist/src/intl/fil.d.ts.map +1 -1
  91. package/dist/src/intl/fil.js +1 -1
  92. package/dist/src/intl/fr.d.ts.map +1 -1
  93. package/dist/src/intl/fr.js +1 -1
  94. package/dist/src/intl/he.d.ts.map +1 -1
  95. package/dist/src/intl/he.js +1 -1
  96. package/dist/src/intl/hi.d.ts.map +1 -1
  97. package/dist/src/intl/hi.js +1 -1
  98. package/dist/src/intl/hr.d.ts.map +1 -1
  99. package/dist/src/intl/hr.js +1 -1
  100. package/dist/src/intl/hu.d.ts.map +1 -1
  101. package/dist/src/intl/hu.js +1 -1
  102. package/dist/src/intl/id.d.ts.map +1 -1
  103. package/dist/src/intl/id.js +1 -1
  104. package/dist/src/intl/it.d.ts.map +1 -1
  105. package/dist/src/intl/it.js +1 -1
  106. package/dist/src/intl/ja.d.ts.map +1 -1
  107. package/dist/src/intl/ja.js +1 -1
  108. package/dist/src/intl/ko.d.ts.map +1 -1
  109. package/dist/src/intl/ko.js +1 -1
  110. package/dist/src/intl/ml.d.ts.map +1 -1
  111. package/dist/src/intl/ml.js +1 -1
  112. package/dist/src/intl/mr.d.ts.map +1 -1
  113. package/dist/src/intl/mr.js +1 -1
  114. package/dist/src/intl/ms.d.ts.map +1 -1
  115. package/dist/src/intl/ms.js +1 -1
  116. package/dist/src/intl/nb.d.ts.map +1 -1
  117. package/dist/src/intl/nb.js +1 -1
  118. package/dist/src/intl/nl.d.ts.map +1 -1
  119. package/dist/src/intl/nl.js +1 -1
  120. package/dist/src/intl/pa.d.ts.map +1 -1
  121. package/dist/src/intl/pa.js +1 -1
  122. package/dist/src/intl/pl.d.ts.map +1 -1
  123. package/dist/src/intl/pl.js +1 -1
  124. package/dist/src/intl/pt-BR.d.ts.map +1 -1
  125. package/dist/src/intl/pt-BR.js +1 -1
  126. package/dist/src/intl/pt.d.ts.map +1 -1
  127. package/dist/src/intl/pt.js +1 -1
  128. package/dist/src/intl/ro.d.ts.map +1 -1
  129. package/dist/src/intl/ro.js +1 -1
  130. package/dist/src/intl/sk.d.ts.map +1 -1
  131. package/dist/src/intl/sk.js +1 -1
  132. package/dist/src/intl/sl.d.ts.map +1 -1
  133. package/dist/src/intl/sl.js +1 -1
  134. package/dist/src/intl/sv.d.ts.map +1 -1
  135. package/dist/src/intl/sv.js +1 -1
  136. package/dist/src/intl/sw.d.ts.map +1 -1
  137. package/dist/src/intl/sw.js +1 -1
  138. package/dist/src/intl/ta.d.ts.map +1 -1
  139. package/dist/src/intl/ta.js +1 -1
  140. package/dist/src/intl/te.d.ts.map +1 -1
  141. package/dist/src/intl/te.js +1 -1
  142. package/dist/src/intl/th.d.ts.map +1 -1
  143. package/dist/src/intl/th.js +1 -1
  144. package/dist/src/intl/tr.d.ts.map +1 -1
  145. package/dist/src/intl/tr.js +1 -1
  146. package/dist/src/intl/uk.d.ts.map +1 -1
  147. package/dist/src/intl/uk.js +1 -1
  148. package/dist/src/intl/ur.d.ts.map +1 -1
  149. package/dist/src/intl/ur.js +1 -1
  150. package/dist/src/intl/vi.d.ts.map +1 -1
  151. package/dist/src/intl/vi.js +1 -1
  152. package/dist/src/intl/zh-CN.d.ts.map +1 -1
  153. package/dist/src/intl/zh-CN.js +1 -1
  154. package/dist/src/intl/zh-TW.d.ts.map +1 -1
  155. package/dist/src/intl/zh-TW.js +1 -1
  156. package/dist/src/local-first/Evolu.d.ts +12 -12
  157. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  158. package/dist/src/local-first/Evolu.js +2 -2
  159. package/dist/src/local-first/Protocol.d.ts +28 -76
  160. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  161. package/dist/src/local-first/Protocol.js +45 -229
  162. package/dist/src/local-first/Query.d.ts +11 -11
  163. package/dist/src/local-first/Query.js +6 -6
  164. package/dist/src/local-first/Relay.d.ts +2 -2
  165. package/dist/src/local-first/Schema.d.ts +3 -5
  166. package/dist/src/local-first/Schema.d.ts.map +1 -1
  167. package/dist/src/local-first/Schema.js +2 -4
  168. package/dist/src/local-first/Shared.d.ts.map +1 -1
  169. package/dist/src/local-first/Shared.js +5 -5
  170. package/dist/src/local-first/Storage.js +4 -4
  171. package/dist/src/local-first/Timestamp.d.ts +9 -0
  172. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  173. package/dist/src/local-first/Timestamp.js +13 -10
  174. package/package.json +7 -5
  175. package/src/Array.test.ts +809 -0
  176. package/src/Array.ts +21 -21
  177. package/src/Assert.test.ts +1181 -0
  178. package/src/Assert.ts +971 -227
  179. package/src/BigInt.test.ts +28 -0
  180. package/src/Binary.test.ts +1128 -0
  181. package/src/Binary.ts +1377 -0
  182. package/src/Brand.test.ts +90 -0
  183. package/src/Cache.test.ts +183 -0
  184. package/src/Callbacks.test.ts +66 -0
  185. package/src/Console.test.ts +809 -0
  186. package/src/Console.ts +9 -17
  187. package/src/Crypto.test.ts +138 -0
  188. package/src/Crypto.ts +5 -5
  189. package/src/Eq.test.ts +333 -0
  190. package/src/Eq.ts +110 -176
  191. package/src/Error.test.ts +118 -0
  192. package/src/Function.test.ts +204 -0
  193. package/src/Function.ts +10 -15
  194. package/src/Http.test.ts +816 -0
  195. package/src/Http.ts +6 -7
  196. package/src/LeakDetector.test.ts +210 -0
  197. package/src/LeakDetector.ts +1 -0
  198. package/src/LockManager.ts +2 -2
  199. package/src/Lookup.test.ts +418 -0
  200. package/src/Lookup.ts +4 -3
  201. package/src/Microtask.test.ts +140 -0
  202. package/src/Number.test.ts +218 -0
  203. package/src/Number.ts +2 -2
  204. package/src/Object.test.ts +293 -0
  205. package/src/Object.ts +5 -4
  206. package/src/Option.test.ts +104 -0
  207. package/src/Option.ts +1 -2
  208. package/src/Order.test.ts +56 -0
  209. package/src/Platform.ts +2 -0
  210. package/src/Polyfills.ts +3 -4
  211. package/src/Random.test.ts +89 -0
  212. package/src/Random.ts +1 -1
  213. package/src/Ref.test.ts +139 -0
  214. package/src/RefCount.test.ts +184 -0
  215. package/src/Relation.test.ts +505 -0
  216. package/src/Resource.test.ts +4623 -0
  217. package/src/Result.test.ts +1829 -0
  218. package/src/Result.ts +49 -54
  219. package/src/Schedule.test.ts +1554 -0
  220. package/src/Set.test.ts +279 -0
  221. package/src/Set.ts +6 -6
  222. package/src/Sqlite.ts +1 -1
  223. package/src/Store.test.ts +288 -0
  224. package/src/String.test.ts +54 -0
  225. package/src/String.ts +3 -3
  226. package/src/Task.test.ts +10820 -0
  227. package/src/Task.ts +38 -43
  228. package/src/Test.test.ts +88 -0
  229. package/src/Test.ts +49 -3
  230. package/src/Time.test.ts +926 -0
  231. package/src/Time.ts +13 -21
  232. package/src/Type.base64.test.ts +88 -0
  233. package/src/Type.test.ts +20465 -0
  234. package/src/Type.ts +114 -111
  235. package/src/Types.test.ts +324 -0
  236. package/src/Types.ts +13 -13
  237. package/src/WebSocket.ts +4 -7
  238. package/src/Worker.test.ts +755 -0
  239. package/src/Worker.ts +13 -18
  240. package/src/index.ts +1 -1
  241. package/src/intl/_en.ts +1 -1
  242. package/src/intl/ar.ts +1 -1
  243. package/src/intl/bn.ts +1 -1
  244. package/src/intl/ca.ts +1 -1
  245. package/src/intl/cs.ts +1 -1
  246. package/src/intl/da.ts +1 -1
  247. package/src/intl/de.ts +1 -1
  248. package/src/intl/el.ts +1 -1
  249. package/src/intl/es.ts +1 -1
  250. package/src/intl/fa.ts +1 -1
  251. package/src/intl/fi.ts +1 -1
  252. package/src/intl/fil.ts +1 -1
  253. package/src/intl/fr.ts +1 -1
  254. package/src/intl/he.ts +1 -1
  255. package/src/intl/hi.ts +1 -1
  256. package/src/intl/hr.ts +1 -1
  257. package/src/intl/hu.ts +1 -1
  258. package/src/intl/id.ts +1 -1
  259. package/src/intl/intl.test.ts +3106 -0
  260. package/src/intl/it.ts +1 -1
  261. package/src/intl/ja.ts +1 -1
  262. package/src/intl/ko.ts +1 -1
  263. package/src/intl/ml.ts +1 -1
  264. package/src/intl/mr.ts +1 -1
  265. package/src/intl/ms.ts +1 -1
  266. package/src/intl/nb.ts +1 -1
  267. package/src/intl/nl.ts +1 -1
  268. package/src/intl/pa.ts +1 -1
  269. package/src/intl/pl.ts +1 -1
  270. package/src/intl/pt-BR.ts +1 -1
  271. package/src/intl/pt.ts +1 -1
  272. package/src/intl/ro.ts +1 -1
  273. package/src/intl/sk.ts +1 -1
  274. package/src/intl/sl.ts +1 -1
  275. package/src/intl/sv.ts +1 -1
  276. package/src/intl/sw.ts +1 -1
  277. package/src/intl/ta.ts +1 -1
  278. package/src/intl/te.ts +1 -1
  279. package/src/intl/th.ts +1 -1
  280. package/src/intl/tr.ts +1 -1
  281. package/src/intl/uk.ts +1 -1
  282. package/src/intl/ur.ts +1 -1
  283. package/src/intl/vi.ts +1 -1
  284. package/src/intl/zh-CN.ts +1 -1
  285. package/src/intl/zh-TW.ts +1 -1
  286. package/src/local-first/Evolu.test.ts +1921 -0
  287. package/src/local-first/Evolu.ts +18 -14
  288. package/src/local-first/Owner.test.ts +83 -0
  289. package/src/local-first/Protocol.test.ts +1037 -0
  290. package/src/local-first/Protocol.ts +75 -290
  291. package/src/local-first/Query.test.ts +349 -0
  292. package/src/local-first/Query.ts +11 -11
  293. package/src/local-first/Relay.ts +2 -2
  294. package/src/local-first/Schema.ts +3 -5
  295. package/src/local-first/Shared.test.ts +1828 -0
  296. package/src/local-first/Shared.ts +9 -8
  297. package/src/local-first/Storage.ts +4 -4
  298. package/src/local-first/Timestamp.test.ts +374 -0
  299. package/src/local-first/Timestamp.ts +22 -10
  300. package/dist/src/Buffer.d.ts +0 -122
  301. package/dist/src/Buffer.d.ts.map +0 -1
  302. package/dist/src/Buffer.js +0 -69
  303. package/src/Buffer.ts +0 -206
@@ -159,18 +159,32 @@
159
159
  *
160
160
  * @module
161
161
  */
162
+ /**
163
+ * TODO:
164
+ *
165
+ * - The client-relay naming convention in functions like
166
+ * `applyProtocolMessageAsClient` and `applyProtocolMessageAsRelay` is not
167
+ * ideal. In the future, clients will be able to sync directly with each other
168
+ * (P2P), making the current naming misleading. Consider using
169
+ * initiator/non-initiator terminology instead, and consolidate into a single
170
+ * `applyProtocolMessage` function with conditional arguments to reduce code
171
+ * duplication.
172
+ * - Allow clients to broadcast messages that are not persisted by relays. This
173
+ * would enable real-time ephemeral data (like cursor positions, typing
174
+ * indicators) to be forwarded by relays without storage overhead.
175
+ */
162
176
  import { type NonEmptyReadonlyArray } from "../Array.ts";
163
177
  import type { Brand } from "../Brand.ts";
164
- import { type Buffer } from "../Buffer.ts";
178
+ import { type Buffer } from "../Binary.ts";
165
179
  import type { ConsoleDep } from "../Console.ts";
166
180
  import { type DecryptWithXChaCha20Poly1305Error, EncryptionKey, type RandomBytesDep } from "../Crypto.ts";
167
181
  import { type Result } from "../Result.ts";
168
- import { SqliteValue } from "../Sqlite.ts";
182
+ import type { SqliteValue } from "../Sqlite.ts";
169
183
  import { type Task } from "../Task.ts";
170
- import { FiniteNumber, NonNegativeInt, PositiveInt, type Typed } from "../Type.ts";
184
+ import { NonNegativeInt, PositiveInt, type Typed } from "../Type.ts";
171
185
  import { type Owner, type OwnerError, OwnerId, OwnerWriteKey } from "./Owner.ts";
172
186
  import { type BaseRange, type CrdtMessage, DbChange, type EncryptedCrdtMessage, type EncryptedDbChange, type FingerprintRange, RangeType, type SkipRange, type StorageDep } from "./Storage.ts";
173
- import { NodeId, Timestamp } from "./Timestamp.ts";
187
+ import { Timestamp } from "./Timestamp.ts";
174
188
  /**
175
189
  * Protocol message maximum size.
176
190
  *
@@ -275,7 +289,7 @@ export interface ProtocolVersionError extends OwnerError, Typed<"ProtocolVersion
275
289
  }
276
290
  /** Error for invalid or corrupted protocol message data. */
277
291
  export interface ProtocolInvalidDataError extends Typed<"ProtocolInvalidDataError"> {
278
- readonly data: globalThis.Uint8Array;
292
+ readonly data: Uint8Array;
279
293
  readonly error: unknown;
280
294
  }
281
295
  /** Error when a {@link OwnerWriteKey} is invalid, missing, or fails validation. */
@@ -411,49 +425,6 @@ export interface ApplyProtocolMessageAsRelayResult extends Typed<"Response"> {
411
425
  export declare const applyProtocolMessageAsRelay: (inputMessage: Uint8Array, options?: ApplyProtocolMessageAsRelayOptions,
412
426
  /** For tests only. */
413
427
  version?: NonNegativeInt) => Task<ApplyProtocolMessageAsRelayResult, ProtocolInvalidDataError, StorageDep>;
414
- export declare const decodeRle: <T>(buffer: Buffer, length: NonNegativeInt, decodeValue: () => T) => ReadonlyArray<T>;
415
- /**
416
- * Evolu uses MessagePack to handle finite numbers except for NonNegativeInt.
417
- * For NonNegativeInt, Evolu provides more efficient encoding.
418
- */
419
- export declare const encodeNumber: (buffer: Buffer, number: FiniteNumber) => void;
420
- export declare const decodeNumber: (buffer: Buffer) => FiniteNumber;
421
- /**
422
- * Encodes an array of boolean flags into a single byte.
423
- *
424
- * Each element in the array corresponds to a bit (0-7). Array can have 0-8
425
- * elements.
426
- *
427
- * ### Example
428
- *
429
- * ```ts
430
- * import { assertEqual, createBuffer } from "@evolu/common";
431
- * import { encodeFlags } from "@evolu/common/local-first";
432
- *
433
- * const buffer = createBuffer();
434
- * encodeFlags(buffer, [true, false, true]);
435
- *
436
- * assertEqual(buffer.unwrap(), new Uint8Array([0b101]));
437
- * ```
438
- */
439
- export declare const encodeFlags: (buffer: Buffer, flags: ReadonlyArray<boolean>) => void;
440
- /**
441
- * Decodes a byte into an array of boolean flags.
442
- *
443
- * ### Example
444
- *
445
- * ```ts
446
- * import { assertEqual, createBuffer, PositiveInt } from "@evolu/common";
447
- * import { decodeFlags } from "@evolu/common/local-first";
448
- *
449
- * const buffer = createBuffer([0b101]);
450
- * const flags = decodeFlags(buffer, PositiveInt.orThrow(3));
451
- *
452
- * assertEqual(flags, [true, false, true]);
453
- * assertEqual(buffer.getLength(), 0);
454
- * ```
455
- */
456
- export declare const decodeFlags: (buffer: Buffer, count: PositiveInt) => ReadonlyArray<boolean>;
457
428
  /**
458
429
  * Encodes and encrypts a {@link DbChange} using the provided owner's encryption
459
430
  * key. Returns an encrypted binary representation as {@link EncryptedDbChange}.
@@ -470,24 +441,18 @@ export declare const encodeAndEncryptDbChange: (deps: RandomBytesDep) => (messag
470
441
  */
471
442
  export declare const decryptAndDecodeDbChange: (message: EncryptedCrdtMessage, key: EncryptionKey) => Result<DbChange, DecryptWithXChaCha20Poly1305Error | ProtocolInvalidDataError | ProtocolTimestampMismatchError>;
472
443
  /**
473
- * Encodes a non-negative integer into a variable-length integer format. It's
474
- * more efficient than encoding via {@link encodeNumber}.
444
+ * Decodes a ProtocolMessage into a readable JSON object for debugging.
475
445
  *
476
- * https://en.wikipedia.org/wiki/Variable-length_quantity
477
- */
478
- export declare const encodeNonNegativeInt: (buffer: Buffer, int: NonNegativeInt) => void;
479
- /**
480
- * Decodes a non-negative integer from a variable-length integer format.
446
+ * Note: This is a stub for future implementation. It should use:
481
447
  *
482
- * https://en.wikipedia.org/wiki/Variable-length_quantity
448
+ * - DecodeVersionAndOwner
449
+ * - DecodeError or decodeWriteKeys (depending on context)
450
+ * - DecodeMessages
451
+ * - DecodeRanges
452
+ *
453
+ * If you want to help, please contribute to this function.
483
454
  */
484
- export declare const decodeNonNegativeInt: (buffer: Buffer) => NonNegativeInt;
485
- export declare const encodeLength: (buffer: Buffer, value: ArrayLike<any>) => void;
486
- export declare const decodeLength: typeof decodeNonNegativeInt;
487
- export declare const encodeString: (buffer: Buffer, value: string) => void;
488
- export declare const decodeString: (buffer: Buffer) => string;
489
- export declare const encodeNodeId: (buffer: Buffer, nodeId: NodeId) => void;
490
- export declare const decodeNodeId: (buffer: Buffer) => NodeId;
455
+ export declare const decodeProtocolMessageToJson: (_protocolMessage: ProtocolMessage, _isInitiator: boolean) => unknown;
491
456
  export declare const ProtocolValueType: {
492
457
  readonly String: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;
493
458
  readonly Number: number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int"> & Brand<"NonNegative">;
@@ -503,18 +468,5 @@ export declare const ProtocolValueType: {
503
468
  };
504
469
  export declare const encodeSqliteValue: (buffer: Buffer, value: SqliteValue) => void;
505
470
  export declare const decodeSqliteValue: (buffer: Buffer) => SqliteValue;
506
- /**
507
- * Decodes a ProtocolMessage into a readable JSON object for debugging.
508
- *
509
- * Note: This is a stub for future implementation. It should use:
510
- *
511
- * - DecodeVersionAndOwner
512
- * - DecodeError or decodeWriteKeys (depending on context)
513
- * - DecodeMessages
514
- * - DecodeRanges
515
- *
516
- * If you want to help, please contribute to this function.
517
- */
518
- export declare const decodeProtocolMessageToJson: (_protocolMessage: ProtocolMessage, _isInitiator: boolean) => unknown;
519
471
  export {};
520
472
  //# sourceMappingURL=Protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Protocol.d.ts","sourceRoot":"","sources":["../../../src/local-first/Protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgKG;AAoBH,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,KAAK,MAAM,EAMZ,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAGL,KAAK,iCAAiC,EACtC,aAAa,EAGb,KAAK,cAAc,EAGpB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3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EX,eAAO,MAAM,iBAAiB,WAAY,MAAM,SAAS,WAAW,KAAG,IA6FtE,CAAC;AAEF,eAAO,MAAM,iBAAiB,WAAY,MAAM,KAAG,WA6DlD,CAAC"}
@@ -169,35 +169,24 @@
169
169
  * initiator/non-initiator terminology instead, and consolidate into a single
170
170
  * `applyProtocolMessage` function with conditional arguments to reduce code
171
171
  * duplication.
172
- * - Replace try-catch with Result + new Error (to preserve stacktraces). Measure
173
- * Result overhead, it should be super small.
174
172
  * - Allow clients to broadcast messages that are not persisted by relays. This
175
173
  * would enable real-time ephemeral data (like cursor positions, typing
176
174
  * indicators) to be forwarded by relays without storage overhead.
177
175
  */
178
- import { Packr } from "msgpackr";
179
176
  import { createMutableArray, isNonEmptyArray, } from "../Array.js";
180
- import { assert, assertNonNullable, assertNotUndefined } from "../Assert.js";
181
- import { bytesToHex, bytesToUtf8, createBuffer, hexToBytes, utf8ToBytes, } from "../Buffer.js";
177
+ import { assert, assertNonNullable, assertNotUndefined, assertSame, } from "../Assert.js";
178
+ import { createBuffer, createRunLengthEncoder, decodeFlags, decodeJsonValue, decodeLength, decodeNonNegativeInt, decodeNumber, decodeRle, decodeString, encodeFlags, encodeJsonValue, encodeLength, encodeNonNegativeInt, encodeNumber, encodeString, } from "../Binary.js";
182
179
  import { createPadmePadding, decryptWithXChaCha20Poly1305, EncryptionKey, encryptWithXChaCha20Poly1305, Entropy24, XChaCha20Poly1305Ciphertext, xChaCha20Poly1305NonceLength, } from "../Crypto.js";
183
180
  import { eqArrayNumber } from "../Eq.js";
184
181
  import { computeBalancedBuckets } from "../Number.js";
185
182
  import { createMutableRecord, objectToEntries } from "../Object.js";
186
183
  import { err, ok } from "../Result.js";
187
- import { SqliteValue } from "../Sqlite.js";
188
184
  import { AbortError } from "../Task.js";
189
185
  import { Millis } from "../Time.js";
190
- import { Base64Url, base64UrlToUint8Array, between, DateIso, FiniteNumber, Id, IdBytes, idBytesToId, idBytesTypeValueLength, idToIdBytes, Int, Json, jsonToJsonValue, NonNegativeInt, onePositiveInt, PositiveInt, uint8ArrayToBase64Url, zeroNonNegativeInt, } from "../Type.js";
186
+ import { assertType, Base64Url, base64UrlToUint8Array, between, DateIso, FiniteNumber, Id, IdBytes, idBytesToId, idBytesTypeValueLength, idToIdBytes, Int, Json, jsonToJsonValue, NonNegativeInt, onePositiveInt, PositiveInt, uint8ArrayToBase64Url, zeroNonNegativeInt, } from "../Type.js";
191
187
  import { OwnerId, OwnerIdBytes, ownerIdToOwnerIdBytes, OwnerWriteKey, ownerWriteKeyLength, } from "./Owner.js";
192
188
  import { DbChange, fingerprintSize, InfiniteUpperBound, RangeType, } from "./Storage.js";
193
- import { Counter, eqTimestamp, NodeId, Timestamp, TimestampBytes, timestampBytesLength, timestampBytesToTimestamp, timestampToTimestampBytes, } from "./Timestamp.js";
194
- /**
195
- * Evolu uses MessagePack for numbers and JSONs.
196
- *
197
- * - `variableMapSize: true` - More compact maps, ~5-10% slower encoding
198
- * - `useRecords: false` - Standard MessagePack without extensions
199
- */
200
- const packr = new Packr({ variableMapSize: true, useRecords: false });
189
+ import { Counter, eqTimestamp, NodeId, nodeIdBytesLength, nodeIdBytesToNodeId, nodeIdToNodeIdBytes, Timestamp, TimestampBytes, timestampBytesLength, timestampBytesToTimestamp, timestampToTimestampBytes, } from "./Timestamp.js";
201
190
  const minProtocolMessageMaxSize = 1_000_000;
202
191
  const maxProtocolMessageMaxSize = 100_000_000;
203
192
  /**
@@ -506,12 +495,12 @@ export const createTimestampsBuffer = () => {
506
495
  encodeNonNegativeInt(buffer, value);
507
496
  });
508
497
  const nodeIdEncoder = createRunLengthEncoder((buffer, value) => {
509
- encodeNodeId(buffer, value);
498
+ buffer.extend(nodeIdToNodeIdBytes(value));
510
499
  });
511
500
  return {
512
501
  add: (timestamp) => {
513
502
  const delta = timestamp.millis - previousMillis;
514
- assert(NonNegativeInt.is(delta), "The delta must be NonNegativeInt");
503
+ assertType(NonNegativeInt, delta);
515
504
  count++;
516
505
  syncCount();
517
506
  previousMillis = timestamp.millis;
@@ -536,29 +525,6 @@ export const createTimestampsBuffer = () => {
536
525
  },
537
526
  };
538
527
  };
539
- const createRunLengthEncoder = (encodeValue) => {
540
- const buffer = createBuffer();
541
- let previousLength = zeroNonNegativeInt;
542
- let previousValue = null;
543
- let runLength = zeroNonNegativeInt;
544
- return {
545
- add: (value) => {
546
- if (value === previousValue) {
547
- runLength++;
548
- buffer.truncate(previousLength);
549
- }
550
- else {
551
- previousValue = value;
552
- runLength = NonNegativeInt.orThrow(1);
553
- }
554
- previousLength = buffer.getLength();
555
- encodeValue(buffer, value);
556
- encodeNonNegativeInt(buffer, runLength);
557
- },
558
- getLength: () => buffer.getLength(),
559
- unwrap: () => buffer.unwrap(),
560
- };
561
- };
562
528
  export const applyProtocolMessageAsClient = (inputMessage, options = {}) => async (run) => {
563
529
  const { storage } = run.deps;
564
530
  try {
@@ -678,7 +644,7 @@ version = protocolVersion) => async (run) => {
678
644
  });
679
645
  }
680
646
  const messageType = input.shift();
681
- assert(messageType === MessageType.Request, "Invalid MessageType");
647
+ assertSame(messageType, MessageType.Request);
682
648
  const hasWriteKey = input.shift();
683
649
  let writeKey;
684
650
  if (hasWriteKey === 1) {
@@ -1139,7 +1105,7 @@ const decodeTimestamps = (buffer, length) => {
1139
1105
  throw new ProtocolDecodeError(counter.error.type);
1140
1106
  return counter.value;
1141
1107
  });
1142
- const nodeIds = decodeRle(buffer, length, () => decodeNodeId(buffer));
1108
+ const nodeIds = decodeRle(buffer, length, () => nodeIdBytesToNodeId(buffer.shiftN(nodeIdBytesLength)));
1143
1109
  const timestamps = createMutableArray(length);
1144
1110
  for (let i = 0; i < length; i++) {
1145
1111
  timestamps[i] = {
@@ -1150,108 +1116,10 @@ const decodeTimestamps = (buffer, length) => {
1150
1116
  }
1151
1117
  return timestamps;
1152
1118
  };
1153
- export const decodeRle = (buffer, length, decodeValue) => {
1154
- const values = createMutableArray(length);
1155
- let index = 0;
1156
- while (index < length) {
1157
- const value = decodeValue();
1158
- const runLength = decodeNonNegativeInt(buffer);
1159
- // Prevent infinite loop on malformed input.
1160
- if (runLength === 0) {
1161
- throw new ProtocolDecodeError("Invalid RLE encoding: runLength must be positive");
1162
- }
1163
- const remaining = length - index;
1164
- // Prevent CPU/memory amplification via oversized runLength.
1165
- if (runLength > remaining) {
1166
- throw new ProtocolDecodeError(`Invalid RLE encoding: runLength ${runLength} exceeds remaining ${remaining}`);
1167
- }
1168
- for (let i = 0; i < runLength; i++) {
1169
- values[index] = value;
1170
- index++;
1171
- }
1172
- }
1173
- return values;
1174
- };
1175
1119
  const decodeId = (buffer) => {
1176
1120
  const bytes = buffer.shiftN(idBytesTypeValueLength);
1177
1121
  return idBytesToId(bytes);
1178
1122
  };
1179
- /**
1180
- * Evolu uses MessagePack to handle finite numbers except for NonNegativeInt.
1181
- * For NonNegativeInt, Evolu provides more efficient encoding.
1182
- */
1183
- export const encodeNumber = (buffer, number) => {
1184
- buffer.extend(packr.pack(number));
1185
- };
1186
- export const decodeNumber = (buffer) => {
1187
- let number;
1188
- let end;
1189
- packr.unpackMultiple(buffer.unwrap(), (n, _, e) => {
1190
- number = n;
1191
- end = e;
1192
- return false;
1193
- });
1194
- const endResult = NonNegativeInt.fromUnknown(end);
1195
- if (!endResult.ok)
1196
- throw new ProtocolDecodeError(endResult.error.type);
1197
- const numberResult = FiniteNumber.fromUnknown(number);
1198
- if (!numberResult.ok)
1199
- throw new ProtocolDecodeError(numberResult.error.type);
1200
- buffer.shiftN(endResult.value);
1201
- return numberResult.value;
1202
- };
1203
- /**
1204
- * Encodes an array of boolean flags into a single byte.
1205
- *
1206
- * Each element in the array corresponds to a bit (0-7). Array can have 0-8
1207
- * elements.
1208
- *
1209
- * ### Example
1210
- *
1211
- * ```ts
1212
- * import { assertEqual, createBuffer } from "@evolu/common";
1213
- * import { encodeFlags } from "@evolu/common/local-first";
1214
- *
1215
- * const buffer = createBuffer();
1216
- * encodeFlags(buffer, [true, false, true]);
1217
- *
1218
- * assertEqual(buffer.unwrap(), new Uint8Array([0b101]));
1219
- * ```
1220
- */
1221
- export const encodeFlags = (buffer, flags) => {
1222
- let byte = 0;
1223
- for (let i = 0; i < flags.length && i < 8; i++) {
1224
- if (flags[i]) {
1225
- byte |= 1 << i;
1226
- }
1227
- }
1228
- buffer.extend([byte]);
1229
- };
1230
- /**
1231
- * Decodes a byte into an array of boolean flags.
1232
- *
1233
- * ### Example
1234
- *
1235
- * ```ts
1236
- * import { assertEqual, createBuffer, PositiveInt } from "@evolu/common";
1237
- * import { decodeFlags } from "@evolu/common/local-first";
1238
- *
1239
- * const buffer = createBuffer([0b101]);
1240
- * const flags = decodeFlags(buffer, PositiveInt.orThrow(3));
1241
- *
1242
- * assertEqual(flags, [true, false, true]);
1243
- * assertEqual(buffer.getLength(), 0);
1244
- * ```
1245
- */
1246
- export const decodeFlags = (buffer, count) => {
1247
- const byte = buffer.shift();
1248
- const length = globalThis.Math.min(count, 8);
1249
- const flags = createMutableArray(length);
1250
- for (let i = 0; i < length; i++) {
1251
- flags[i] = (byte & (1 << i)) !== 0;
1252
- }
1253
- return flags;
1254
- };
1255
1123
  /**
1256
1124
  * Encodes and encrypts a {@link DbChange} using the provided owner's encryption
1257
1125
  * key. Returns an encrypted binary representation as {@link EncryptedDbChange}.
@@ -1343,73 +1211,26 @@ export const decryptAndDecodeDbChange = (message, key) => {
1343
1211
  }
1344
1212
  };
1345
1213
  /**
1346
- * Encodes a non-negative integer into a variable-length integer format. It's
1347
- * more efficient than encoding via {@link encodeNumber}.
1214
+ * Decodes a ProtocolMessage into a readable JSON object for debugging.
1348
1215
  *
1349
- * https://en.wikipedia.org/wiki/Variable-length_quantity
1350
- */
1351
- export const encodeNonNegativeInt = (buffer, int) => {
1352
- if (int === 0) {
1353
- buffer.extend([0]);
1354
- return;
1355
- }
1356
- let remaining = BigInt(int);
1357
- const bytes = [];
1358
- while (remaining !== 0n) {
1359
- const byte = globalThis.Number(remaining & 127n);
1360
- bytes.push(byte);
1361
- remaining >>= 7n;
1362
- }
1363
- for (let i = 0; i < bytes.length - 1; i++) {
1364
- bytes[i] |= 128;
1365
- }
1366
- buffer.extend(bytes);
1367
- };
1368
- /**
1369
- * Decodes a non-negative integer from a variable-length integer format.
1216
+ * Note: This is a stub for future implementation. It should use:
1217
+ *
1218
+ * - DecodeVersionAndOwner
1219
+ * - DecodeError or decodeWriteKeys (depending on context)
1220
+ * - DecodeMessages
1221
+ * - DecodeRanges
1370
1222
  *
1371
- * https://en.wikipedia.org/wiki/Variable-length_quantity
1223
+ * If you want to help, please contribute to this function.
1372
1224
  */
1373
- export const decodeNonNegativeInt = (buffer) => {
1374
- let result = 0n;
1375
- let shift = 0n;
1376
- let byte;
1377
- // 8 is the smallest required count
1378
- for (let byteCount = 0; byteCount < 8; byteCount++) {
1379
- byte = buffer.shift();
1380
- result |= BigInt(byte & 127) << shift;
1381
- if ((byte & 128) === 0)
1382
- break;
1383
- shift += 7n;
1384
- }
1385
- const int = NonNegativeInt.fromUnknown(globalThis.Number(result));
1386
- if (!int.ok)
1387
- throw new ProtocolDecodeError(int.error.type);
1388
- return int.value;
1389
- };
1390
- export const encodeLength = (buffer, value) => {
1391
- encodeNonNegativeInt(buffer, NonNegativeInt.orThrow(value.length));
1392
- };
1393
- export const decodeLength = decodeNonNegativeInt;
1394
- export const encodeString = (buffer, value) => {
1395
- const bytes = utf8ToBytes(value);
1396
- encodeLength(buffer, bytes);
1397
- buffer.extend(bytes);
1398
- };
1399
- export const decodeString = (buffer) => {
1400
- const length = decodeLength(buffer);
1401
- const bytes = buffer.shiftN(length);
1402
- return bytesToUtf8(bytes);
1403
- };
1404
- export const encodeNodeId = (buffer, nodeId) => {
1405
- buffer.extend(hexToBytes(nodeId));
1406
- };
1407
- export const decodeNodeId = (buffer) => {
1408
- const bytes = buffer.shiftN(NonNegativeInt.orThrow(8));
1409
- return bytesToHex(bytes);
1225
+ export const decodeProtocolMessageToJson = (_protocolMessage, _isInitiator) => {
1226
+ // TODO: Implement using
1227
+ // - decodeVersionAndOwner
1228
+ // -- decodeError or decodeWriteKeys (should be refactored out),
1229
+ // -- decodeMessages, and decodeRanges.
1230
+ // This is a stub for PRs and community contributions.
1231
+ throw new Error("decodeProtocolMessageToJson is not implemented yet.");
1410
1232
  };
1411
1233
  // Small ints are encoded into ProtocolValueType, saving one byte per int.
1412
- const isSmallInt = (value) => value >= 0 && value < 20;
1413
1234
  export const ProtocolValueType = {
1414
1235
  // 0-19 small ints
1415
1236
  // SQLite types
@@ -1471,10 +1292,17 @@ export const encodeSqliteValue = (buffer, value) => {
1471
1292
  // Some valid JSON strings like "-0E0" get normalized to "0" during parsing,
1472
1293
  // which would cause data corruption if we don't verify round-trip safety.
1473
1294
  if (json.ok && JSON.stringify(jsonToJsonValue(json.value)) === value) {
1474
- const jsonBytes = packr.pack(jsonToJsonValue(json.value));
1475
- encodeNonNegativeInt(buffer, ProtocolValueType.Json);
1476
- encodeLength(buffer, jsonBytes);
1477
- buffer.extend(jsonBytes);
1295
+ jsonBuffer.reset();
1296
+ try {
1297
+ encodeJsonValue(jsonBuffer, jsonToJsonValue(json.value));
1298
+ const jsonBytes = jsonBuffer.unwrap();
1299
+ encodeNonNegativeInt(buffer, ProtocolValueType.Json);
1300
+ encodeLength(buffer, jsonBytes);
1301
+ buffer.extend(jsonBytes);
1302
+ }
1303
+ finally {
1304
+ jsonBuffer.reset();
1305
+ }
1478
1306
  return;
1479
1307
  }
1480
1308
  const base64Url = Base64Url.from.parent(value);
@@ -1490,7 +1318,9 @@ export const encodeSqliteValue = (buffer, value) => {
1490
1318
  return;
1491
1319
  }
1492
1320
  case "number": {
1493
- if (NonNegativeInt.is(value)) {
1321
+ // Negative zero is a non-negative integer in JavaScript, but integer
1322
+ // encoding would lose its observable sign.
1323
+ if (!Object.is(value, -0) && NonNegativeInt.is(value)) {
1494
1324
  if (isSmallInt(value)) {
1495
1325
  encodeNonNegativeInt(buffer, value);
1496
1326
  return;
@@ -1530,8 +1360,12 @@ export const decodeSqliteValue = (buffer) => {
1530
1360
  return decodeNonNegativeInt(buffer);
1531
1361
  case ProtocolValueType.Json: {
1532
1362
  const length = decodeLength(buffer);
1533
- const bytes = buffer.shiftN(length);
1534
- return JSON.stringify(packr.unpack(bytes));
1363
+ const jsonValueBuffer = createBuffer(buffer.shiftN(length));
1364
+ const value = decodeJsonValue(jsonValueBuffer);
1365
+ if (jsonValueBuffer.getLength() !== 0) {
1366
+ throw new ProtocolDecodeError("Invalid JSON MessagePack length");
1367
+ }
1368
+ return JSON.stringify(value);
1535
1369
  }
1536
1370
  case ProtocolValueType.DateIsoWithNonNegativeTime:
1537
1371
  case ProtocolValueType.DateIsoWithNegativeTime: {
@@ -1554,23 +1388,5 @@ export const decodeSqliteValue = (buffer) => {
1554
1388
  throw new ProtocolDecodeError("invalid ProtocolValueType");
1555
1389
  }
1556
1390
  };
1557
- /**
1558
- * Decodes a ProtocolMessage into a readable JSON object for debugging.
1559
- *
1560
- * Note: This is a stub for future implementation. It should use:
1561
- *
1562
- * - DecodeVersionAndOwner
1563
- * - DecodeError or decodeWriteKeys (depending on context)
1564
- * - DecodeMessages
1565
- * - DecodeRanges
1566
- *
1567
- * If you want to help, please contribute to this function.
1568
- */
1569
- export const decodeProtocolMessageToJson = (_protocolMessage, _isInitiator) => {
1570
- // TODO: Implement using
1571
- // - decodeVersionAndOwner
1572
- // -- decodeError or decodeWriteKeys (should be refactored out),
1573
- // -- decodeMessages, and decodeRanges.
1574
- // This is a stub for PRs and community contributions.
1575
- throw new Error("decodeProtocolMessageToJson is not implemented yet.");
1576
- };
1391
+ const jsonBuffer = createBuffer();
1392
+ const isSmallInt = (value) => value >= 0 && value < 20;
@@ -33,11 +33,11 @@ export type { NotNull as KyselyNotNull } from "kysely";
33
33
  *
34
34
  * type AllTodosRow = typeof allTodos.Row;
35
35
  * assertType<
36
- * true,
37
- * typeof allTodos extends Query<typeof Schema> ? true : false
36
+ * typeof allTodos extends Query<typeof Schema> ? true : false,
37
+ * true
38
38
  * >();
39
- * assertType<TodoId, AllTodosRow["id"]>();
40
- * assertType<NonEmptyTrimmedString100 | null, AllTodosRow["title"]>();
39
+ * assertType<AllTodosRow["id"], TodoId>();
40
+ * assertType<AllTodosRow["title"], NonEmptyTrimmedString100 | null>();
41
41
  * ```
42
42
  */
43
43
  export type Query<S extends EvoluSchema = EvoluSchema, R extends Row = Row> = SqliteQueryString & Brand<"Query"> & {
@@ -66,7 +66,7 @@ export type Query<S extends EvoluSchema = EvoluSchema, R extends Row = Row> = Sq
66
66
  * );
67
67
  *
68
68
  * type AllTodosRow = typeof allTodos.Row;
69
- * assertType<InferRow<typeof allTodos>, AllTodosRow>();
69
+ * assertType<AllTodosRow, InferRow<typeof allTodos>>();
70
70
  * ```
71
71
  */
72
72
  Row: R;
@@ -121,11 +121,11 @@ export interface Row {
121
121
  * );
122
122
  *
123
123
  * assertType<
124
+ * (typeof people.Row.pets)[number],
124
125
  * {
125
126
  * petId: typeof Schema.pet.id.Output;
126
127
  * name: NonEmptyTrimmedString100 | null;
127
- * },
128
- * (typeof people.Row.pets)[number]
128
+ * }
129
129
  * >();
130
130
  * ```
131
131
  */
@@ -180,11 +180,11 @@ export declare const evoluJsonArrayFrom: <O>(expr: SelectQueryBuilderExpression<
180
180
  * );
181
181
  *
182
182
  * assertType<
183
+ * typeof people.Row.favoritePet,
183
184
  * {
184
185
  * petId: typeof Schema.pet.id.Output;
185
186
  * name: NonEmptyTrimmedString100 | null;
186
- * } | null,
187
- * typeof people.Row.favoritePet
187
+ * } | null
188
188
  * >();
189
189
  * ```
190
190
  */
@@ -234,12 +234,12 @@ export declare const evoluJsonObjectFrom: <O>(expr: SelectQueryBuilderExpression
234
234
  * );
235
235
  *
236
236
  * assertType<
237
+ * typeof people.Row.name,
237
238
  * {
238
239
  * first: NonEmptyTrimmedString100 | null;
239
240
  * last: NonEmptyTrimmedString100 | null;
240
241
  * full: string;
241
- * },
242
- * typeof people.Row.name
242
+ * }
243
243
  * >();
244
244
  * ```
245
245
  */
@@ -56,11 +56,11 @@ export { sql as kyselySql } from "kysely";
56
56
  * );
57
57
  *
58
58
  * assertType<
59
+ * (typeof people.Row.pets)[number],
59
60
  * {
60
61
  * petId: typeof Schema.pet.id.Output;
61
62
  * name: NonEmptyTrimmedString100 | null;
62
- * },
63
- * (typeof people.Row.pets)[number]
63
+ * }
64
64
  * >();
65
65
  * ```
66
66
  */
@@ -115,11 +115,11 @@ export const evoluJsonArrayFrom = (expr) => kyselySqlBuilder `(select ${kyselySq
115
115
  * );
116
116
  *
117
117
  * assertType<
118
+ * typeof people.Row.favoritePet,
118
119
  * {
119
120
  * petId: typeof Schema.pet.id.Output;
120
121
  * name: NonEmptyTrimmedString100 | null;
121
- * } | null,
122
- * typeof people.Row.favoritePet
122
+ * } | null
123
123
  * >();
124
124
  * ```
125
125
  */
@@ -169,12 +169,12 @@ export const evoluJsonObjectFrom = (expr) => kyselySqlBuilder `(select ${kyselyS
169
169
  * );
170
170
  *
171
171
  * assertType<
172
+ * typeof people.Row.name,
172
173
  * {
173
174
  * first: NonEmptyTrimmedString100 | null;
174
175
  * last: NonEmptyTrimmedString100 | null;
175
176
  * full: string;
176
- * },
177
- * typeof people.Row.name
177
+ * }
178
178
  * >();
179
179
  * ```
180
180
  */