@evolu/common 7.4.0 → 8.0.0-next.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 (251) hide show
  1. package/README.md +4 -61
  2. package/dist/src/Array.d.ts +343 -102
  3. package/dist/src/Array.d.ts.map +1 -1
  4. package/dist/src/Array.js +181 -85
  5. package/dist/src/Assert.d.ts +57 -11
  6. package/dist/src/Assert.d.ts.map +1 -1
  7. package/dist/src/Assert.js +47 -11
  8. package/dist/src/BigInt.d.ts +6 -1
  9. package/dist/src/BigInt.d.ts.map +1 -1
  10. package/dist/src/BigInt.js +5 -0
  11. package/dist/src/Brand.d.ts +40 -12
  12. package/dist/src/Brand.d.ts.map +1 -1
  13. package/dist/src/Brand.js +5 -0
  14. package/dist/src/Buffer.d.ts +6 -1
  15. package/dist/src/Buffer.d.ts.map +1 -1
  16. package/dist/src/Buffer.js +7 -2
  17. package/dist/src/Cache.d.ts +10 -2
  18. package/dist/src/Cache.d.ts.map +1 -1
  19. package/dist/src/Cache.js +6 -0
  20. package/dist/src/Callbacks.d.ts +10 -7
  21. package/dist/src/Callbacks.d.ts.map +1 -1
  22. package/dist/src/Callbacks.js +23 -13
  23. package/dist/src/Console.d.ts +361 -69
  24. package/dist/src/Console.d.ts.map +1 -1
  25. package/dist/src/Console.js +217 -117
  26. package/dist/src/Crypto.d.ts +70 -21
  27. package/dist/src/Crypto.d.ts.map +1 -1
  28. package/dist/src/Crypto.js +72 -27
  29. package/dist/src/Eq.d.ts +22 -2
  30. package/dist/src/Eq.d.ts.map +1 -1
  31. package/dist/src/Eq.js +21 -1
  32. package/dist/src/Error.d.ts +23 -12
  33. package/dist/src/Error.d.ts.map +1 -1
  34. package/dist/src/Error.js +27 -11
  35. package/dist/src/Function.d.ts +128 -56
  36. package/dist/src/Function.d.ts.map +1 -1
  37. package/dist/src/Function.js +118 -14
  38. package/dist/src/Identicon.d.ts +5 -0
  39. package/dist/src/Identicon.d.ts.map +1 -1
  40. package/dist/src/Identicon.js +6 -1
  41. package/dist/src/Lookup.d.ts +160 -0
  42. package/dist/src/Lookup.d.ts.map +1 -0
  43. package/dist/src/Lookup.js +192 -0
  44. package/dist/src/Microtask.d.ts +21 -0
  45. package/dist/src/Microtask.d.ts.map +1 -0
  46. package/dist/src/Microtask.js +37 -0
  47. package/dist/src/Number.d.ts +18 -4
  48. package/dist/src/Number.d.ts.map +1 -1
  49. package/dist/src/Number.js +23 -1
  50. package/dist/src/Object.d.ts +110 -5
  51. package/dist/src/Object.d.ts.map +1 -1
  52. package/dist/src/Object.js +108 -5
  53. package/dist/src/Option.d.ts +58 -0
  54. package/dist/src/Option.d.ts.map +1 -0
  55. package/dist/src/Option.js +43 -0
  56. package/dist/src/Order.d.ts +5 -0
  57. package/dist/src/Order.d.ts.map +1 -1
  58. package/dist/src/Order.js +8 -3
  59. package/dist/src/Platform.d.ts +36 -2
  60. package/dist/src/Platform.d.ts.map +1 -1
  61. package/dist/src/Platform.js +10 -6
  62. package/dist/src/Polyfills.d.ts +27 -0
  63. package/dist/src/Polyfills.d.ts.map +1 -0
  64. package/dist/src/Polyfills.js +299 -0
  65. package/dist/src/Random.d.ts +18 -7
  66. package/dist/src/Random.d.ts.map +1 -1
  67. package/dist/src/Random.js +9 -7
  68. package/dist/src/Redacted.d.ts +7 -4
  69. package/dist/src/Redacted.d.ts.map +1 -1
  70. package/dist/src/Redacted.js +5 -0
  71. package/dist/src/Ref.d.ts +31 -16
  72. package/dist/src/Ref.d.ts.map +1 -1
  73. package/dist/src/Ref.js +35 -7
  74. package/dist/src/RefCount.d.ts +62 -0
  75. package/dist/src/RefCount.d.ts.map +1 -0
  76. package/dist/src/RefCount.js +83 -0
  77. package/dist/src/Relation.d.ts +84 -29
  78. package/dist/src/Relation.d.ts.map +1 -1
  79. package/dist/src/Relation.js +83 -105
  80. package/dist/src/Resource.d.ts +263 -0
  81. package/dist/src/Resource.d.ts.map +1 -0
  82. package/dist/src/Resource.js +389 -0
  83. package/dist/src/Result.d.ts +390 -374
  84. package/dist/src/Result.d.ts.map +1 -1
  85. package/dist/src/Result.js +142 -70
  86. package/dist/src/Schedule.d.ts +953 -0
  87. package/dist/src/Schedule.d.ts.map +1 -0
  88. package/dist/src/Schedule.js +1199 -0
  89. package/dist/src/Set.d.ts +181 -0
  90. package/dist/src/Set.d.ts.map +1 -0
  91. package/dist/src/Set.js +137 -0
  92. package/dist/src/Skiplist.d.ts +6 -1
  93. package/dist/src/Skiplist.d.ts.map +1 -1
  94. package/dist/src/Skiplist.js +5 -0
  95. package/dist/src/Sqlite.d.ts +160 -60
  96. package/dist/src/Sqlite.d.ts.map +1 -1
  97. package/dist/src/Sqlite.js +290 -190
  98. package/dist/src/Store.d.ts +36 -28
  99. package/dist/src/Store.d.ts.map +1 -1
  100. package/dist/src/Store.js +55 -15
  101. package/dist/src/String.d.ts +5 -0
  102. package/dist/src/String.d.ts.map +1 -1
  103. package/dist/src/String.js +5 -0
  104. package/dist/src/Task.d.ts +2263 -423
  105. package/dist/src/Task.d.ts.map +1 -1
  106. package/dist/src/Task.js +1488 -348
  107. package/dist/src/Test.d.ts +122 -0
  108. package/dist/src/Test.d.ts.map +1 -0
  109. package/dist/src/Test.js +66 -0
  110. package/dist/src/Time.d.ts +201 -48
  111. package/dist/src/Time.d.ts.map +1 -1
  112. package/dist/src/Time.js +190 -86
  113. package/dist/src/Tracer.d.ts +48 -0
  114. package/dist/src/Tracer.d.ts.map +1 -0
  115. package/dist/src/Tracer.js +6 -0
  116. package/dist/src/Type.d.ts +582 -209
  117. package/dist/src/Type.d.ts.map +1 -1
  118. package/dist/src/Type.js +362 -240
  119. package/dist/src/Types.d.ts +160 -6
  120. package/dist/src/Types.d.ts.map +1 -1
  121. package/dist/src/Types.js +22 -2
  122. package/dist/src/WebSocket.d.ts +113 -58
  123. package/dist/src/WebSocket.d.ts.map +1 -1
  124. package/dist/src/WebSocket.js +210 -118
  125. package/dist/src/Worker.d.ts +245 -60
  126. package/dist/src/Worker.d.ts.map +1 -1
  127. package/dist/src/Worker.js +220 -64
  128. package/dist/src/index.d.ts +25 -3
  129. package/dist/src/index.d.ts.map +1 -1
  130. package/dist/src/index.js +19 -3
  131. package/dist/src/local-first/Db.d.ts +24 -213
  132. package/dist/src/local-first/Db.d.ts.map +1 -1
  133. package/dist/src/local-first/Db.js +622 -293
  134. package/dist/src/local-first/Error.d.ts +12 -0
  135. package/dist/src/local-first/Error.d.ts.map +1 -0
  136. package/dist/src/local-first/Error.js +6 -0
  137. package/dist/src/local-first/Evolu.d.ts +330 -285
  138. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  139. package/dist/src/local-first/Evolu.js +472 -402
  140. package/dist/src/local-first/LocalAuth.d.ts +10 -10
  141. package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
  142. package/dist/src/local-first/LocalAuth.js +6 -1
  143. package/dist/src/local-first/Owner.d.ts +70 -27
  144. package/dist/src/local-first/Owner.d.ts.map +1 -1
  145. package/dist/src/local-first/Owner.js +27 -14
  146. package/dist/src/local-first/Protocol.d.ts +58 -50
  147. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  148. package/dist/src/local-first/Protocol.js +253 -155
  149. package/dist/src/local-first/Query.d.ts +133 -43
  150. package/dist/src/local-first/Query.d.ts.map +1 -1
  151. package/dist/src/local-first/Query.js +139 -90
  152. package/dist/src/local-first/Relay.d.ts +18 -38
  153. package/dist/src/local-first/Relay.d.ts.map +1 -1
  154. package/dist/src/local-first/Relay.js +59 -171
  155. package/dist/src/local-first/Schema.d.ts +139 -144
  156. package/dist/src/local-first/Schema.d.ts.map +1 -1
  157. package/dist/src/local-first/Schema.js +78 -163
  158. package/dist/src/local-first/Shared.d.ts +125 -0
  159. package/dist/src/local-first/Shared.d.ts.map +1 -0
  160. package/dist/src/local-first/Shared.js +569 -0
  161. package/dist/src/local-first/Storage.d.ts +50 -53
  162. package/dist/src/local-first/Storage.d.ts.map +1 -1
  163. package/dist/src/local-first/Storage.js +121 -173
  164. package/dist/src/local-first/Timestamp.d.ts +28 -35
  165. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  166. package/dist/src/local-first/Timestamp.js +24 -25
  167. package/dist/src/local-first/index.d.ts +2 -15
  168. package/dist/src/local-first/index.d.ts.map +1 -1
  169. package/dist/src/local-first/index.js +2 -15
  170. package/package.json +36 -26
  171. package/src/Array.ts +467 -106
  172. package/src/Assert.ts +87 -12
  173. package/src/BigInt.ts +7 -1
  174. package/src/Brand.ts +41 -12
  175. package/src/Buffer.ts +10 -4
  176. package/src/Cache.ts +11 -2
  177. package/src/Callbacks.ts +33 -23
  178. package/src/Console.ts +567 -178
  179. package/src/Crypto.ts +111 -62
  180. package/src/Eq.ts +30 -3
  181. package/src/Error.ts +50 -34
  182. package/src/Function.ts +140 -68
  183. package/src/Identicon.ts +7 -1
  184. package/src/Lookup.ts +415 -0
  185. package/src/Microtask.ts +58 -0
  186. package/src/Number.ts +40 -7
  187. package/src/Object.ts +155 -16
  188. package/src/Option.ts +74 -0
  189. package/src/Order.ts +11 -3
  190. package/src/Platform.ts +43 -7
  191. package/src/Polyfills.ts +465 -0
  192. package/src/Random.ts +25 -11
  193. package/src/Redacted.ts +8 -4
  194. package/src/Ref.ts +72 -21
  195. package/src/RefCount.ts +170 -0
  196. package/src/Relation.ts +188 -136
  197. package/src/Resource.ts +864 -0
  198. package/src/Result.ts +548 -381
  199. package/src/Schedule.ts +1471 -0
  200. package/src/Set.ts +247 -0
  201. package/src/Skiplist.ts +7 -1
  202. package/src/Sqlite.ts +409 -304
  203. package/src/Store.ts +94 -48
  204. package/src/String.ts +6 -0
  205. package/src/Task.ts +3685 -740
  206. package/src/Test.ts +162 -0
  207. package/src/Time.ts +348 -145
  208. package/src/Tracer.ts +54 -0
  209. package/src/Type.ts +1064 -630
  210. package/src/Types.ts +202 -7
  211. package/src/WebSocket.ts +311 -178
  212. package/src/Worker.ts +527 -147
  213. package/src/index.ts +74 -3
  214. package/src/local-first/Db.ts +871 -597
  215. package/src/local-first/Error.ts +17 -0
  216. package/src/local-first/Evolu.ts +884 -823
  217. package/src/local-first/LocalAuth.ts +10 -10
  218. package/src/local-first/Owner.ts +94 -42
  219. package/src/local-first/Protocol.ts +440 -303
  220. package/src/local-first/Query.ts +243 -194
  221. package/src/local-first/Relay.ts +91 -252
  222. package/src/local-first/Schema.ts +284 -394
  223. package/src/local-first/Shared.ts +932 -0
  224. package/src/local-first/Storage.ts +209 -282
  225. package/src/local-first/Timestamp.ts +38 -45
  226. package/src/local-first/index.ts +2 -16
  227. package/LICENSE +0 -21
  228. package/dist/src/Instances.d.ts +0 -34
  229. package/dist/src/Instances.d.ts.map +0 -1
  230. package/dist/src/Instances.js +0 -44
  231. package/dist/src/Resources.d.ts +0 -118
  232. package/dist/src/Resources.d.ts.map +0 -1
  233. package/dist/src/Resources.js +0 -197
  234. package/dist/src/local-first/Platform.d.ts +0 -25
  235. package/dist/src/local-first/Platform.d.ts.map +0 -1
  236. package/dist/src/local-first/Platform.js +0 -1
  237. package/dist/src/local-first/Public.d.ts +0 -22
  238. package/dist/src/local-first/Public.d.ts.map +0 -1
  239. package/dist/src/local-first/Public.js +0 -15
  240. package/dist/src/local-first/PublicKysely.d.ts +0 -148
  241. package/dist/src/local-first/PublicKysely.d.ts.map +0 -1
  242. package/dist/src/local-first/PublicKysely.js +0 -184
  243. package/dist/src/local-first/Sync.d.ts +0 -112
  244. package/dist/src/local-first/Sync.d.ts.map +0 -1
  245. package/dist/src/local-first/Sync.js +0 -529
  246. package/src/Instances.ts +0 -90
  247. package/src/Resources.ts +0 -367
  248. package/src/local-first/Platform.ts +0 -27
  249. package/src/local-first/Public.ts +0 -42
  250. package/src/local-first/PublicKysely.ts +0 -239
  251. package/src/local-first/Sync.ts +0 -960
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Set helpers.
3
+ *
4
+ * All helpers return readonly sets for safety. Native Set methods like `add()`
5
+ * and `delete()` mutate the original — use {@link addToSet} and
6
+ * {@link deleteFromSet} instead for immutable operations that return new sets.
7
+ *
8
+ * Use {@link isNonEmptySet} to narrow to {@link NonEmptyReadonlySet} before
9
+ * calling functions like {@link firstInSet} that require a non-empty set.
10
+ *
11
+ * ### Example
12
+ *
13
+ * ```ts
14
+ * // Type guards
15
+ * const set: ReadonlySet<number> = new Set([1, 2, 3]);
16
+ * if (isNonEmptySet(set)) {
17
+ * firstInSet(set);
18
+ * }
19
+ *
20
+ * // Immutable transformations
21
+ * const added = addToSet(new Set([1, 2]), 3); // Set {1, 2, 3}
22
+ * const removed = deleteFromSet(new Set([1, 2, 3]), 2); // Set {1, 3}
23
+ * const mapped = mapSet(new Set([1, 2, 3]), (x) => x * 2); // Set {2, 4, 6}
24
+ * const filtered = filterSet(new Set([1, 2, 3, 4]), (x) => x % 2 === 0); // Set {2, 4}
25
+ *
26
+ * // Set operations
27
+ * const union = unionSets(new Set([1, 2]), new Set([2, 3])); // Set {1, 2, 3}
28
+ * const intersection = intersectSets(new Set([1, 2]), new Set([2, 3])); // Set {2}
29
+ * const difference = differenceSets(new Set([1, 2, 3]), new Set([2])); // Set {1, 3}
30
+ * ```
31
+ *
32
+ * @module
33
+ */
34
+ import type { NonEmptyReadonlyArray } from "./Array.js";
35
+ import type { Brand } from "./Brand.js";
36
+ import type { PredicateWithIndex, RefinementWithIndex } from "./Types.js";
37
+ /**
38
+ * An empty readonly set.
39
+ *
40
+ * Use as a default or initial value to avoid allocating new empty sets.
41
+ *
42
+ * @group Constants
43
+ */
44
+ export declare const emptySet: ReadonlySet<never>;
45
+ /**
46
+ * Creates a readonly set from an array.
47
+ *
48
+ * Preserves non-empty type when the input array is non-empty.
49
+ *
50
+ * ### Example
51
+ *
52
+ * ```ts
53
+ * createSet([1, 2, 3]); // NonEmptyReadonlySet<number>
54
+ * createSet([] as ReadonlyArray<number>); // ReadonlySet<number>
55
+ * ```
56
+ *
57
+ * @group Constructors
58
+ */
59
+ export declare function createSet<T>(items: NonEmptyReadonlyArray<T>): NonEmptyReadonlySet<T>;
60
+ /** Possibly empty set. */
61
+ export declare function createSet<T>(items: ReadonlyArray<T>): ReadonlySet<T>;
62
+ /**
63
+ * A readonly set with at least one element (branded for type safety).
64
+ *
65
+ * Use {@link isNonEmptySet} to narrow from `ReadonlySet`, or use functions like
66
+ * {@link addToSet} that return branded non-empty sets.
67
+ *
68
+ * There is no mutable `NonEmptySet` type because mutable sets can be emptied
69
+ * after narrowing (via `clear()` or `delete()`), making compile-time guarantees
70
+ * impossible.
71
+ *
72
+ * @group Types
73
+ */
74
+ export type NonEmptyReadonlySet<T> = ReadonlySet<T> & Brand<"NonEmpty">;
75
+ /**
76
+ * Checks if a set is non-empty and narrows its type to
77
+ * {@link NonEmptyReadonlySet}.
78
+ *
79
+ * Both mutable and readonly sets narrow to the branded
80
+ * {@link NonEmptyReadonlySet} type, which can be used with functions like
81
+ * {@link firstInSet}.
82
+ *
83
+ * To check if a set is empty, use `if (!isNonEmptySet(set))` — using the
84
+ * negated guard is better than `.size === 0` for early returns because
85
+ * TypeScript narrows the type after the check.
86
+ *
87
+ * ### Example
88
+ *
89
+ * ```ts
90
+ * const set: ReadonlySet<number> = new Set([1, 2, 3]);
91
+ * if (isNonEmptySet(set)) {
92
+ * firstInSet(set); // set is NonEmptyReadonlySet<number>
93
+ * }
94
+ * ```
95
+ *
96
+ * @group Type guards
97
+ */
98
+ export declare const isNonEmptySet: <T>(set: ReadonlySet<T>) => set is NonEmptyReadonlySet<T>;
99
+ /**
100
+ * Returns a new readonly set with an item added.
101
+ *
102
+ * If the item already exists, returns a new set with the same elements (still a
103
+ * new reference for change detection).
104
+ *
105
+ * ### Example
106
+ *
107
+ * ```ts
108
+ * addToSet(new Set([1, 2]), 3); // Set {1, 2, 3}
109
+ * addToSet(new Set([1, 2]), 2); // Set {1, 2} (new reference)
110
+ * ```
111
+ *
112
+ * @group Transformations
113
+ */
114
+ export declare const addToSet: <T>(set: ReadonlySet<T>, item: T) => NonEmptyReadonlySet<T>;
115
+ /**
116
+ * Returns a new readonly set with an item removed.
117
+ *
118
+ * If the item doesn't exist, returns a new set with the same elements (still a
119
+ * new reference for change detection).
120
+ *
121
+ * ### Example
122
+ *
123
+ * ```ts
124
+ * deleteFromSet(new Set([1, 2, 3]), 2); // Set {1, 3}
125
+ * deleteFromSet(new Set([1, 2]), 5); // Set {1, 2} (new reference)
126
+ * ```
127
+ *
128
+ * @group Transformations
129
+ */
130
+ export declare const deleteFromSet: <T>(set: ReadonlySet<T>, item: T) => ReadonlySet<T>;
131
+ /**
132
+ * Maps a set using a mapper function, returning a new readonly set.
133
+ *
134
+ * Preserves non-empty type.
135
+ *
136
+ * Note: If the mapper produces duplicate values, the resulting set will have
137
+ * fewer elements.
138
+ *
139
+ * ### Example
140
+ *
141
+ * ```ts
142
+ * mapSet(new Set([1, 2, 3]), (x) => x * 2); // Set {2, 4, 6}
143
+ * mapSet(new Set([1, 2, 3]), (x) => x % 2); // Set {1, 0} (duplicates merged)
144
+ * ```
145
+ *
146
+ * @group Transformations
147
+ */
148
+ export declare function mapSet<T, U>(set: NonEmptyReadonlySet<T>, mapper: (item: T) => U): NonEmptyReadonlySet<U>;
149
+ /** Possibly empty set. */
150
+ export declare function mapSet<T, U>(set: ReadonlySet<T>, mapper: (item: T) => U): ReadonlySet<U>;
151
+ /**
152
+ * Filters a set using a predicate or refinement function, returning a new
153
+ * readonly set.
154
+ *
155
+ * When used with a refinement function (with `value is Type` syntax),
156
+ * TypeScript will narrow the result type.
157
+ *
158
+ * ### Example
159
+ *
160
+ * ```ts
161
+ * filterSet(new Set([1, 2, 3, 4, 5]), (x) => x % 2 === 0); // Set {2, 4}
162
+ * ```
163
+ *
164
+ * @group Transformations
165
+ */
166
+ export declare function filterSet<T, S extends T>(set: ReadonlySet<T>, refinement: RefinementWithIndex<T, S>): ReadonlySet<S>;
167
+ /** With predicate. */
168
+ export declare function filterSet<T>(set: ReadonlySet<T>, predicate: PredicateWithIndex<T>): ReadonlySet<T>;
169
+ /**
170
+ * Returns the first element of a non-empty set (by insertion order).
171
+ *
172
+ * ### Example
173
+ *
174
+ * ```ts
175
+ * firstInSet(new Set(["a", "b", "c"])); // "a"
176
+ * ```
177
+ *
178
+ * @group Accessors
179
+ */
180
+ export declare const firstInSet: <T>(set: NonEmptyReadonlySet<T>) => T;
181
+ //# sourceMappingURL=Set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Set.d.ts","sourceRoot":"","sources":["../../src/Set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE1E;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,EAAE,WAAW,CAAC,KAAK,CAA2B,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC9B,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAC1B,0BAA0B;AAC1B,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAKtE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAC7B,KAAK,WAAW,CAAC,CAAC,CAAC,KAClB,GAAG,IAAI,mBAAmB,CAAC,CAAC,CAAiB,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EACxB,KAAK,WAAW,CAAC,CAAC,CAAC,EACnB,MAAM,CAAC,KACN,mBAAmB,CAAC,CAAC,CAIvB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAC7B,KAAK,WAAW,CAAC,CAAC,CAAC,EACnB,MAAM,CAAC,KACN,WAAW,CAAC,CAAC,CAIf,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EACzB,GAAG,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAC3B,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GACrB,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAC1B,0BAA0B;AAC1B,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EACzB,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GACrB,WAAW,CAAC,CAAC,CAAC,CAAC;AAYlB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,EACtC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EACnB,UAAU,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,GACpC,WAAW,CAAC,CAAC,CAAC,CAAC;AAClB,sBAAsB;AACtB,wBAAgB,SAAS,CAAC,CAAC,EACzB,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,EACnB,SAAS,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC/B,WAAW,CAAC,CAAC,CAAC,CAAC;AAelB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,KAAK,mBAAmB,CAAC,CAAC,CAAC,KAAG,CAC5B,CAAC"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Set helpers.
3
+ *
4
+ * All helpers return readonly sets for safety. Native Set methods like `add()`
5
+ * and `delete()` mutate the original — use {@link addToSet} and
6
+ * {@link deleteFromSet} instead for immutable operations that return new sets.
7
+ *
8
+ * Use {@link isNonEmptySet} to narrow to {@link NonEmptyReadonlySet} before
9
+ * calling functions like {@link firstInSet} that require a non-empty set.
10
+ *
11
+ * ### Example
12
+ *
13
+ * ```ts
14
+ * // Type guards
15
+ * const set: ReadonlySet<number> = new Set([1, 2, 3]);
16
+ * if (isNonEmptySet(set)) {
17
+ * firstInSet(set);
18
+ * }
19
+ *
20
+ * // Immutable transformations
21
+ * const added = addToSet(new Set([1, 2]), 3); // Set {1, 2, 3}
22
+ * const removed = deleteFromSet(new Set([1, 2, 3]), 2); // Set {1, 3}
23
+ * const mapped = mapSet(new Set([1, 2, 3]), (x) => x * 2); // Set {2, 4, 6}
24
+ * const filtered = filterSet(new Set([1, 2, 3, 4]), (x) => x % 2 === 0); // Set {2, 4}
25
+ *
26
+ * // Set operations
27
+ * const union = unionSets(new Set([1, 2]), new Set([2, 3])); // Set {1, 2, 3}
28
+ * const intersection = intersectSets(new Set([1, 2]), new Set([2, 3])); // Set {2}
29
+ * const difference = differenceSets(new Set([1, 2, 3]), new Set([2])); // Set {1, 3}
30
+ * ```
31
+ *
32
+ * @module
33
+ */
34
+ /**
35
+ * An empty readonly set.
36
+ *
37
+ * Use as a default or initial value to avoid allocating new empty sets.
38
+ *
39
+ * @group Constants
40
+ */
41
+ export const emptySet = /*#__PURE__*/ new Set();
42
+ export function createSet(items) {
43
+ return new Set(items);
44
+ }
45
+ /**
46
+ * Checks if a set is non-empty and narrows its type to
47
+ * {@link NonEmptyReadonlySet}.
48
+ *
49
+ * Both mutable and readonly sets narrow to the branded
50
+ * {@link NonEmptyReadonlySet} type, which can be used with functions like
51
+ * {@link firstInSet}.
52
+ *
53
+ * To check if a set is empty, use `if (!isNonEmptySet(set))` — using the
54
+ * negated guard is better than `.size === 0` for early returns because
55
+ * TypeScript narrows the type after the check.
56
+ *
57
+ * ### Example
58
+ *
59
+ * ```ts
60
+ * const set: ReadonlySet<number> = new Set([1, 2, 3]);
61
+ * if (isNonEmptySet(set)) {
62
+ * firstInSet(set); // set is NonEmptyReadonlySet<number>
63
+ * }
64
+ * ```
65
+ *
66
+ * @group Type guards
67
+ */
68
+ export const isNonEmptySet = (set) => set.size > 0;
69
+ /**
70
+ * Returns a new readonly set with an item added.
71
+ *
72
+ * If the item already exists, returns a new set with the same elements (still a
73
+ * new reference for change detection).
74
+ *
75
+ * ### Example
76
+ *
77
+ * ```ts
78
+ * addToSet(new Set([1, 2]), 3); // Set {1, 2, 3}
79
+ * addToSet(new Set([1, 2]), 2); // Set {1, 2} (new reference)
80
+ * ```
81
+ *
82
+ * @group Transformations
83
+ */
84
+ export const addToSet = (set, item) => {
85
+ const next = new Set(set);
86
+ next.add(item);
87
+ return next;
88
+ };
89
+ /**
90
+ * Returns a new readonly set with an item removed.
91
+ *
92
+ * If the item doesn't exist, returns a new set with the same elements (still a
93
+ * new reference for change detection).
94
+ *
95
+ * ### Example
96
+ *
97
+ * ```ts
98
+ * deleteFromSet(new Set([1, 2, 3]), 2); // Set {1, 3}
99
+ * deleteFromSet(new Set([1, 2]), 5); // Set {1, 2} (new reference)
100
+ * ```
101
+ *
102
+ * @group Transformations
103
+ */
104
+ export const deleteFromSet = (set, item) => {
105
+ const next = new Set(set);
106
+ next.delete(item);
107
+ return next;
108
+ };
109
+ export function mapSet(set, mapper) {
110
+ const next = new Set();
111
+ for (const item of set) {
112
+ next.add(mapper(item));
113
+ }
114
+ return next;
115
+ }
116
+ export function filterSet(set, predicate) {
117
+ const next = new Set();
118
+ let index = 0;
119
+ for (const item of set) {
120
+ if (predicate(item, index++)) {
121
+ next.add(item);
122
+ }
123
+ }
124
+ return next;
125
+ }
126
+ /**
127
+ * Returns the first element of a non-empty set (by insertion order).
128
+ *
129
+ * ### Example
130
+ *
131
+ * ```ts
132
+ * firstInSet(new Set(["a", "b", "c"])); // "a"
133
+ * ```
134
+ *
135
+ * @group Accessors
136
+ */
137
+ export const firstInSet = (set) => set.values().next().value;
@@ -1,4 +1,9 @@
1
- import { RandomDep } from "./Random.js";
1
+ /**
2
+ * Skiplist data structure with probabilistic level generation.
3
+ *
4
+ * @module
5
+ */
6
+ import type { RandomDep } from "./Random.js";
2
7
  import { PositiveInt } from "./Type.js";
3
8
  export interface SkiplistLevel {
4
9
  readonly create: () => PositiveInt;
@@ -1 +1 @@
1
- {"version":3,"file":"Skiplist.d.ts","sourceRoot":"","sources":["../../src/Skiplist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,WAAW,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;CACvC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAGD,eAAO,MAAM,mBAAmB,GAC7B,MAAM,SAAS,MACf,SAAQ,mBAAwB,KAAG,aAWnC,CAAC;AAEJ,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CACxC;AAED,eAAO,MAAM,cAAc,GAAI,MAAM,gBAAgB,KAAG,QA2DvD,CAAC"}
1
+ {"version":3,"file":"Skiplist.d.ts","sourceRoot":"","sources":["../../src/Skiplist.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,WAAW,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;CACvC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAGD,eAAO,MAAM,mBAAmB,GAC7B,MAAM,SAAS,MACf,SAAQ,mBAAwB,KAAG,aAWnC,CAAC;AAEJ,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CACxC;AAED,eAAO,MAAM,cAAc,GAAI,MAAM,gBAAgB,KAAG,QA2DvD,CAAC"}
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Skiplist data structure with probabilistic level generation.
3
+ *
4
+ * @module
5
+ */
1
6
  import { PositiveInt } from "./Type.js";
2
7
  // TODO: Use in Storage.
3
8
  export const createSkiplistLevel = (deps) => (config = {}) => {
@@ -1,65 +1,71 @@
1
- import { Brand } from "./Brand.js";
2
- import { ConsoleDep } from "./Console.js";
3
- import { EncryptionKey } from "./Crypto.js";
4
- import { Eq } from "./Eq.js";
5
- import { TransferableError } from "./Error.js";
6
- import { Result } from "./Result.js";
7
- import { SimpleName } from "./Type.js";
8
- import { Predicate } from "./Types.js";
9
- /**
10
- * SQLite driver interface. This is the minimal interface that platform-specific
11
- * drivers must implement.
1
+ /**
2
+ * SQLite database abstraction and query execution.
3
+ *
4
+ * @module
12
5
  */
13
- export interface SqliteDriver extends Disposable {
14
- readonly exec: (query: SqliteQuery, isMutation: boolean) => SqliteExecResult;
15
- readonly export: () => Uint8Array;
16
- }
17
- export type CreateSqliteDriver = (name: SimpleName, options?: SqliteDriverOptions) => Promise<SqliteDriver>;
18
- export interface CreateSqliteDriverDep {
19
- readonly createSqliteDriver: CreateSqliteDriver;
20
- }
21
- export interface SqliteDriverOptions {
22
- readonly memory?: boolean;
23
- readonly encryptionKey?: EncryptionKey | undefined;
24
- }
6
+ import type { Brand } from "./Brand.js";
7
+ import type { EncryptionKey } from "./Crypto.js";
8
+ import type { Eq } from "./Eq.js";
9
+ import type { Result } from "./Result.js";
10
+ import type { Run, Task } from "./Task.js";
11
+ import { type TestDeps } from "./Test.js";
12
+ import type { InferType, Name, Typed } from "./Type.js";
25
13
  /**
26
- * Cross-platform SQLite abstraction.
14
+ * Platform-agnostic SQLite wrapping a {@link SqliteDriver}.
27
15
  *
28
- * This API is sync only because SQLite is an embedded, single-threaded engine.
29
- * All operations are blocking and in-process, so async APIs add needless
30
- * complexity without any real benefit and are also slower. Check better-sqlite3
31
- * GitHub issues and docs for details.
16
+ * API is synchronous because it provides
17
+ * {@link https://github.com/WiseLibs/better-sqlite3/issues/262 | better concurrency}
18
+ * for SQLite.
32
19
  */
33
- export interface Sqlite extends Disposable {
34
- readonly exec: <R extends SqliteRow = SqliteRow>(query: SqliteQuery) => Result<SqliteExecResult<R>, SqliteError>;
20
+ export interface Sqlite extends AsyncDisposable {
21
+ readonly exec: <R extends SqliteRow = SqliteRow>(query: SqliteQuery) => SqliteExecResult<R>;
35
22
  /**
36
23
  * Executes a transaction, running the provided callback within a begin/commit
37
- * block. If the callback returns an error (E or {@link SqliteError}), the
38
- * transaction is rolled back. If the rollback fails, a SqliteError is
39
- * returned with both the original error and rollbackError.
24
+ * block.
25
+ *
26
+ * If the callback returns a {@link Result} error, the transaction is rolled
27
+ * back and the error result is returned.
28
+ *
29
+ * If the callback returns `void`, the transaction is committed unless the
30
+ * callback throws.
31
+ */
32
+ readonly transaction: SqliteTransaction;
33
+ /**
34
+ * Returns bytes backed by {@link ArrayBuffer}.
35
+ *
36
+ * Exported databases are forwarded through worker `postMessage` transfer
37
+ * lists, which require transferable `ArrayBuffer` backing.
40
38
  */
41
- readonly transaction: <T, E>(callback: () => Result<T, E | SqliteError>) => Result<T, E | SqliteError>;
42
- readonly export: () => Result<Uint8Array, SqliteError>;
39
+ readonly export: () => Uint8Array<ArrayBuffer>;
43
40
  }
44
41
  export interface SqliteDep {
45
42
  readonly sqlite: Sqlite;
46
43
  }
44
+ export interface SqliteTransaction {
45
+ <T, E>(callback: () => Result<T, E>): Result<T, E>;
46
+ (callback: () => void): void;
47
+ }
48
+ /** Represents a SQL query to be executed on a {@link Sqlite} database. */
47
49
  export interface SqliteQuery {
48
50
  readonly sql: SafeSql;
49
51
  readonly parameters: Array<SqliteValue>;
50
52
  readonly options?: SqliteQueryOptions;
51
53
  }
52
- /** A type representing a sanitized SQL string. */
54
+ /** Serialized {@link SqliteQuery} used as a stable string key. */
55
+ export type SqliteQueryString = string & Brand<"SqliteQueryString">;
56
+ /** A sanitized SQL string for {@link SqliteQuery}. */
53
57
  export type SafeSql = string & Brand<"SafeSql">;
54
58
  /**
55
- * A value that can be stored in Sqlite.
59
+ * A value that can be stored in {@link Sqlite}.
56
60
  *
57
61
  * Note that Evolu can't support Int64 because expo-sqlite (and some others) do
58
62
  * not support it.
59
63
  */
60
64
  export declare const SqliteValue: import("./Type.js").UnionType<[import("./Type.js").Type<"Null", null, null, import("./Type.js").NullError, null, import("./Type.js").NullError>, import("./Type.js").Type<"String", string, string, import("./Type.js").StringError, string, import("./Type.js").StringError>, import("./Type.js").Type<"Number", number, number, import("./Type.js").NumberError, number, import("./Type.js").NumberError>, import("./Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError>]>;
61
65
  export type SqliteValue = typeof SqliteValue.Type;
66
+ /** Equality comparison for {@link SqliteValue}. */
62
67
  export declare const eqSqliteValue: Eq<SqliteValue>;
68
+ /** Options for configuring {@link SqliteQuery} execution behavior. */
63
69
  export interface SqliteQueryOptions {
64
70
  /**
65
71
  * If set to `true`, logs the time taken to execute the SQL query. Useful for
@@ -83,35 +89,91 @@ export interface SqliteQueryOptions {
83
89
  */
84
90
  readonly prepare?: boolean;
85
91
  }
92
+ /** Converts a {@link SqliteQuery} into a stable {@link SqliteQueryString}. */
93
+ export declare const sqliteQueryToSqliteQueryString: (query: SqliteQuery) => SqliteQueryString;
94
+ /** Converts a {@link SqliteQueryString} back into a {@link SqliteQuery}. */
95
+ export declare const sqliteQueryStringToSqliteQuery: (query: SqliteQueryString) => SqliteQuery;
86
96
  /** Result of executing a SQLite query. */
87
97
  export interface SqliteExecResult<R extends SqliteRow = SqliteRow> {
88
98
  readonly rows: ReadonlyArray<R>;
89
99
  readonly changes: number;
90
100
  }
91
- /** Represents an error that occurred during a SQLite operation. */
92
- export interface SqliteError {
93
- readonly type: "SqliteError";
94
- readonly error: TransferableError;
95
- readonly rollbackError?: TransferableError;
96
- }
101
+ /**
102
+ * A row returned from a {@link Sqlite} query, mapping column names to
103
+ * {@link SqliteValue}.
104
+ */
97
105
  export type SqliteRow = Record<string, SqliteValue>;
98
106
  /**
99
- * Creates a fully featured {@link Sqlite} instance from a {@link SqliteDriver}
100
- * implementation.
107
+ * SQLite driver interface.
108
+ *
109
+ * Platform-specific drivers must implement this interface.
110
+ */
111
+ export interface SqliteDriver extends Disposable {
112
+ readonly exec: (query: SqliteQuery) => SqliteExecResult;
113
+ /**
114
+ * Returns bytes backed by {@link ArrayBuffer}.
115
+ *
116
+ * Exported databases are forwarded through worker `postMessage` transfer
117
+ * lists, which require transferable `ArrayBuffer` backing.
118
+ */
119
+ readonly export: () => Uint8Array<ArrayBuffer>;
120
+ }
121
+ /** Creates a {@link SqliteDriver}. */
122
+ export type CreateSqliteDriver = (name: Name, options?: SqliteDriverOptions) => Task<SqliteDriver>;
123
+ export interface CreateSqliteDriverDep {
124
+ createSqliteDriver: CreateSqliteDriver;
125
+ }
126
+ /**
127
+ * Options for creating a {@link CreateSqliteDriver}.
128
+ *
129
+ * Three mutually exclusive modes: in-memory (for testing), encrypted persistent
130
+ * (OPFS/file with encryption key), or persistent (default when omitted).
131
+ */
132
+ export type SqliteDriverOptions = {
133
+ readonly mode: "memory";
134
+ } | {
135
+ readonly mode: "encrypted";
136
+ readonly encryptionKey: EncryptionKey;
137
+ };
138
+ /**
139
+ * Creates a {@link Sqlite} instance backed by a platform-specific driver.
140
+ *
141
+ * The driver is created via {@link CreateSqliteDriver} and wrapped with logging,
142
+ * error handling, and transaction helpers.
143
+ */
144
+ export declare const createSqlite: (name: Name, options?: SqliteDriverOptions) => Task<Sqlite, never, CreateSqliteDriverDep>;
145
+ /** Creates a test setup with a in-memory {@link Sqlite}. */
146
+ export declare const testSetupSqlite: (deps: CreateSqliteDriverDep) => Promise<AsyncDisposable & SqliteDep & {
147
+ readonly run: Run<TestDeps & CreateSqliteDriverDep & SqliteDep>;
148
+ readonly sqlite: Sqlite;
149
+ }>;
150
+ /**
151
+ * Cache for compiled prepared statements.
152
+ *
153
+ * Statements are created on first access and reused for subsequent calls with
154
+ * the same SQL. Disposing the cache finalizes all cached statements.
101
155
  */
102
- export declare const createSqlite: (deps: CreateSqliteDriverDep & Partial<ConsoleDep>) => (name: SimpleName, options?: SqliteDriverOptions) => Promise<Result<Sqlite, SqliteError>>;
103
156
  export interface PreparedStatements<P> extends Disposable {
104
157
  readonly get: <T extends boolean>(query: SqliteQuery, alwaysPrepare?: T) => T extends true ? P : P | null;
105
158
  }
159
+ /**
160
+ * Creates a {@link PreparedStatements} cache backed by the given factory and
161
+ * dispose function.
162
+ */
106
163
  export declare const createPreparedStatementsCache: <P>(factory: (sql: SafeSql) => P, disposeFn: (statement: P) => void) => PreparedStatements<P>;
107
- export interface SqlIdentifier {
108
- readonly type: "SqlIdentifier";
164
+ /** A double-quoted SQL identifier for safe column or table name interpolation. */
165
+ export interface SqlIdentifier extends Typed<"SqlIdentifier"> {
109
166
  readonly sql: SafeSql;
110
167
  }
111
- export interface RawSql {
112
- readonly type: "RawSql";
168
+ /**
169
+ * An unescaped SQL fragment inserted verbatim into a query.
170
+ *
171
+ * **Warning**: Use only with trusted, constant strings to avoid SQL injection.
172
+ */
173
+ export interface RawSql extends Typed<"RawSql"> {
113
174
  readonly sql: string;
114
175
  }
176
+ /** A parameter accepted by the {@link sql} tagged template. */
115
177
  export type SqlTemplateParam = SqliteValue | SqlIdentifier | RawSql;
116
178
  /**
117
179
  * Creates a safe SQL query using a tagged template literal.
@@ -145,7 +207,7 @@ export type SqlTemplateParam = SqliteValue | SqlIdentifier | RawSql;
145
207
  * sqlite.exec(sql`select * from users order by ${sql.raw(orderBy)};`);
146
208
  * ```
147
209
  *
148
- * ### TIP
210
+ * ## TIP
149
211
  *
150
212
  * Use `prettier-plugin-sql-cst` for SQL formatting. Like Prettier for
151
213
  * JavaScript, this plugin formats SQL expressions differently depending on
@@ -157,24 +219,62 @@ export declare const sql: {
157
219
  raw(raw: string): RawSql;
158
220
  prepared(strings: TemplateStringsArray, ...parameters: Array<SqlTemplateParam>): SqliteQuery;
159
221
  };
222
+ /** Index metadata stored in `sqlite_master` for a {@link Sqlite} database. */
223
+ export declare const SqliteIndex: import("./Type.js").ObjectType<{
224
+ name: import("./Type.js").Type<"String", string, string, import("./Type.js").StringError, string, import("./Type.js").StringError>;
225
+ sql: import("./Type.js").Type<"String", string, string, import("./Type.js").StringError, string, import("./Type.js").StringError>;
226
+ }>;
227
+ export interface SqliteIndex extends InferType<typeof SqliteIndex> {
228
+ }
229
+ /** {@link Eq} instance for {@link SqliteIndex}. */
230
+ export declare const eqSqliteIndex: Eq<SqliteIndex>;
231
+ /**
232
+ * Full schema metadata for a {@link Sqlite} database.
233
+ *
234
+ * Includes table-column mappings and user-visible indexes.
235
+ */
236
+ export declare const SqliteSchema: import("./Type.js").ObjectType<{
237
+ tables: import("./Type.js").RecordType<"String", string, string, import("./Type.js").StringError, string, import("./Type.js").StringError, import("./Type.js").SetType<import("./Type.js").Type<"String", string, string, import("./Type.js").StringError, string, import("./Type.js").StringError>>>;
238
+ indexes: import("./Type.js").ArrayType<import("./Type.js").ObjectType<{
239
+ name: import("./Type.js").Type<"String", string, string, import("./Type.js").StringError, string, import("./Type.js").StringError>;
240
+ sql: import("./Type.js").Type<"String", string, string, import("./Type.js").StringError, string, import("./Type.js").StringError>;
241
+ }>>;
242
+ }>;
243
+ export interface SqliteSchema extends InferType<typeof SqliteSchema> {
244
+ }
245
+ /** Get the current SQLite schema by reading SQLite metadata. */
246
+ export declare const getSqliteSchema: (deps: SqliteDep) => ({ excludeIndexNamePrefix, }?: {
247
+ /**
248
+ * If provided, indexes with names starting with this prefix are excluded in
249
+ * SQLite query.
250
+ */
251
+ excludeIndexNamePrefix?: string;
252
+ }) => SqliteSchema;
160
253
  /**
161
- * Checks if a SQL string contains mutation keywords (insert, update, delete,
162
- * etc.). Results are cached for performance.
254
+ * Returns {@link SqliteSchema} and full {@link SqliteRow} table contents for
255
+ * inspection and testing.
163
256
  */
164
- export declare const isSqlMutation: Predicate<string>;
165
- export interface SqliteQueryPlanRow {
166
- id: number;
167
- parent: number;
168
- detail: string;
257
+ export interface SqliteSnapshot {
258
+ readonly schema: SqliteSchema;
259
+ readonly tables: Array<{
260
+ readonly name: string;
261
+ readonly rows: ReadonlyArray<SqliteRow>;
262
+ }>;
169
263
  }
170
- export declare const explainSqliteQueryPlan: (deps: SqliteDep) => (query: SqliteQuery) => Result<void, SqliteError>;
264
+ /**
265
+ * Captures a full {@link SqliteSnapshot} for testing and diagnostics.
266
+ *
267
+ * The snapshot includes current {@link SqliteSchema} and all rows from every
268
+ * discovered table. Table order follows `schema.tables` iteration order.
269
+ */
270
+ export declare const getSqliteSnapshot: (deps: SqliteDep) => SqliteSnapshot;
171
271
  /**
172
272
  * SQLite represents boolean values using `0` (false) and `1` (true) instead of
173
273
  * a dedicated boolean type.
174
274
  *
175
275
  * See: https://www.sqlite.org/quirks.html#no_separate_boolean_datatype
176
276
  *
177
- * ### Tips
277
+ * ## Tips
178
278
  *
179
279
  * - Use {@link sqliteTrue} and {@link sqliteFalse} constants for better
180
280
  * readability.