@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.
- package/README.md +4 -61
- package/dist/src/Array.d.ts +343 -102
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +181 -85
- package/dist/src/Assert.d.ts +57 -11
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +47 -11
- package/dist/src/BigInt.d.ts +6 -1
- package/dist/src/BigInt.d.ts.map +1 -1
- package/dist/src/BigInt.js +5 -0
- package/dist/src/Brand.d.ts +40 -12
- package/dist/src/Brand.d.ts.map +1 -1
- package/dist/src/Brand.js +5 -0
- package/dist/src/Buffer.d.ts +6 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +7 -2
- package/dist/src/Cache.d.ts +10 -2
- package/dist/src/Cache.d.ts.map +1 -1
- package/dist/src/Cache.js +6 -0
- package/dist/src/Callbacks.d.ts +10 -7
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Callbacks.js +23 -13
- package/dist/src/Console.d.ts +361 -69
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +217 -117
- package/dist/src/Crypto.d.ts +70 -21
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +72 -27
- package/dist/src/Eq.d.ts +22 -2
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +21 -1
- package/dist/src/Error.d.ts +23 -12
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +27 -11
- package/dist/src/Function.d.ts +128 -56
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +118 -14
- package/dist/src/Identicon.d.ts +5 -0
- package/dist/src/Identicon.d.ts.map +1 -1
- package/dist/src/Identicon.js +6 -1
- package/dist/src/Lookup.d.ts +160 -0
- package/dist/src/Lookup.d.ts.map +1 -0
- package/dist/src/Lookup.js +192 -0
- package/dist/src/Microtask.d.ts +21 -0
- package/dist/src/Microtask.d.ts.map +1 -0
- package/dist/src/Microtask.js +37 -0
- package/dist/src/Number.d.ts +18 -4
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +23 -1
- package/dist/src/Object.d.ts +110 -5
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +108 -5
- package/dist/src/Option.d.ts +58 -0
- package/dist/src/Option.d.ts.map +1 -0
- package/dist/src/Option.js +43 -0
- package/dist/src/Order.d.ts +5 -0
- package/dist/src/Order.d.ts.map +1 -1
- package/dist/src/Order.js +8 -3
- package/dist/src/Platform.d.ts +36 -2
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +10 -6
- package/dist/src/Polyfills.d.ts +27 -0
- package/dist/src/Polyfills.d.ts.map +1 -0
- package/dist/src/Polyfills.js +299 -0
- package/dist/src/Random.d.ts +18 -7
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +9 -7
- package/dist/src/Redacted.d.ts +7 -4
- package/dist/src/Redacted.d.ts.map +1 -1
- package/dist/src/Redacted.js +5 -0
- package/dist/src/Ref.d.ts +31 -16
- package/dist/src/Ref.d.ts.map +1 -1
- package/dist/src/Ref.js +35 -7
- package/dist/src/RefCount.d.ts +62 -0
- package/dist/src/RefCount.d.ts.map +1 -0
- package/dist/src/RefCount.js +83 -0
- package/dist/src/Relation.d.ts +84 -29
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Relation.js +83 -105
- package/dist/src/Resource.d.ts +263 -0
- package/dist/src/Resource.d.ts.map +1 -0
- package/dist/src/Resource.js +389 -0
- package/dist/src/Result.d.ts +390 -374
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +142 -70
- package/dist/src/Schedule.d.ts +953 -0
- package/dist/src/Schedule.d.ts.map +1 -0
- package/dist/src/Schedule.js +1199 -0
- package/dist/src/Set.d.ts +181 -0
- package/dist/src/Set.d.ts.map +1 -0
- package/dist/src/Set.js +137 -0
- package/dist/src/Skiplist.d.ts +6 -1
- package/dist/src/Skiplist.d.ts.map +1 -1
- package/dist/src/Skiplist.js +5 -0
- package/dist/src/Sqlite.d.ts +160 -60
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +290 -190
- package/dist/src/Store.d.ts +36 -28
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Store.js +55 -15
- package/dist/src/String.d.ts +5 -0
- package/dist/src/String.d.ts.map +1 -1
- package/dist/src/String.js +5 -0
- package/dist/src/Task.d.ts +2263 -423
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1488 -348
- package/dist/src/Test.d.ts +122 -0
- package/dist/src/Test.d.ts.map +1 -0
- package/dist/src/Test.js +66 -0
- package/dist/src/Time.d.ts +201 -48
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +190 -86
- package/dist/src/Tracer.d.ts +48 -0
- package/dist/src/Tracer.d.ts.map +1 -0
- package/dist/src/Tracer.js +6 -0
- package/dist/src/Type.d.ts +582 -209
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +362 -240
- package/dist/src/Types.d.ts +160 -6
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/Types.js +22 -2
- package/dist/src/WebSocket.d.ts +113 -58
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +210 -118
- package/dist/src/Worker.d.ts +245 -60
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +220 -64
- package/dist/src/index.d.ts +25 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +19 -3
- package/dist/src/local-first/Db.d.ts +24 -213
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +622 -293
- package/dist/src/local-first/Error.d.ts +12 -0
- package/dist/src/local-first/Error.d.ts.map +1 -0
- package/dist/src/local-first/Error.js +6 -0
- package/dist/src/local-first/Evolu.d.ts +330 -285
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +472 -402
- package/dist/src/local-first/LocalAuth.d.ts +10 -10
- package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
- package/dist/src/local-first/LocalAuth.js +6 -1
- package/dist/src/local-first/Owner.d.ts +70 -27
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +27 -14
- package/dist/src/local-first/Protocol.d.ts +58 -50
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +253 -155
- package/dist/src/local-first/Query.d.ts +133 -43
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +139 -90
- package/dist/src/local-first/Relay.d.ts +18 -38
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Relay.js +59 -171
- package/dist/src/local-first/Schema.d.ts +139 -144
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +78 -163
- package/dist/src/local-first/Shared.d.ts +125 -0
- package/dist/src/local-first/Shared.d.ts.map +1 -0
- package/dist/src/local-first/Shared.js +569 -0
- package/dist/src/local-first/Storage.d.ts +50 -53
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +121 -173
- package/dist/src/local-first/Timestamp.d.ts +28 -35
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +24 -25
- package/dist/src/local-first/index.d.ts +2 -15
- package/dist/src/local-first/index.d.ts.map +1 -1
- package/dist/src/local-first/index.js +2 -15
- package/package.json +36 -26
- package/src/Array.ts +467 -106
- package/src/Assert.ts +87 -12
- package/src/BigInt.ts +7 -1
- package/src/Brand.ts +41 -12
- package/src/Buffer.ts +10 -4
- package/src/Cache.ts +11 -2
- package/src/Callbacks.ts +33 -23
- package/src/Console.ts +567 -178
- package/src/Crypto.ts +111 -62
- package/src/Eq.ts +30 -3
- package/src/Error.ts +50 -34
- package/src/Function.ts +140 -68
- package/src/Identicon.ts +7 -1
- package/src/Lookup.ts +415 -0
- package/src/Microtask.ts +58 -0
- package/src/Number.ts +40 -7
- package/src/Object.ts +155 -16
- package/src/Option.ts +74 -0
- package/src/Order.ts +11 -3
- package/src/Platform.ts +43 -7
- package/src/Polyfills.ts +465 -0
- package/src/Random.ts +25 -11
- package/src/Redacted.ts +8 -4
- package/src/Ref.ts +72 -21
- package/src/RefCount.ts +170 -0
- package/src/Relation.ts +188 -136
- package/src/Resource.ts +864 -0
- package/src/Result.ts +548 -381
- package/src/Schedule.ts +1471 -0
- package/src/Set.ts +247 -0
- package/src/Skiplist.ts +7 -1
- package/src/Sqlite.ts +409 -304
- package/src/Store.ts +94 -48
- package/src/String.ts +6 -0
- package/src/Task.ts +3685 -740
- package/src/Test.ts +162 -0
- package/src/Time.ts +348 -145
- package/src/Tracer.ts +54 -0
- package/src/Type.ts +1064 -630
- package/src/Types.ts +202 -7
- package/src/WebSocket.ts +311 -178
- package/src/Worker.ts +527 -147
- package/src/index.ts +74 -3
- package/src/local-first/Db.ts +871 -597
- package/src/local-first/Error.ts +17 -0
- package/src/local-first/Evolu.ts +884 -823
- package/src/local-first/LocalAuth.ts +10 -10
- package/src/local-first/Owner.ts +94 -42
- package/src/local-first/Protocol.ts +440 -303
- package/src/local-first/Query.ts +243 -194
- package/src/local-first/Relay.ts +91 -252
- package/src/local-first/Schema.ts +284 -394
- package/src/local-first/Shared.ts +932 -0
- package/src/local-first/Storage.ts +209 -282
- package/src/local-first/Timestamp.ts +38 -45
- package/src/local-first/index.ts +2 -16
- package/LICENSE +0 -21
- package/dist/src/Instances.d.ts +0 -34
- package/dist/src/Instances.d.ts.map +0 -1
- package/dist/src/Instances.js +0 -44
- package/dist/src/Resources.d.ts +0 -118
- package/dist/src/Resources.d.ts.map +0 -1
- package/dist/src/Resources.js +0 -197
- package/dist/src/local-first/Platform.d.ts +0 -25
- package/dist/src/local-first/Platform.d.ts.map +0 -1
- package/dist/src/local-first/Platform.js +0 -1
- package/dist/src/local-first/Public.d.ts +0 -22
- package/dist/src/local-first/Public.d.ts.map +0 -1
- package/dist/src/local-first/Public.js +0 -15
- package/dist/src/local-first/PublicKysely.d.ts +0 -148
- package/dist/src/local-first/PublicKysely.d.ts.map +0 -1
- package/dist/src/local-first/PublicKysely.js +0 -184
- package/dist/src/local-first/Sync.d.ts +0 -112
- package/dist/src/local-first/Sync.d.ts.map +0 -1
- package/dist/src/local-first/Sync.js +0 -529
- package/src/Instances.ts +0 -90
- package/src/Resources.ts +0 -367
- package/src/local-first/Platform.ts +0 -27
- package/src/local-first/Public.ts +0 -42
- package/src/local-first/PublicKysely.ts +0 -239
- 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"}
|
package/dist/src/Set.js
ADDED
|
@@ -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;
|
package/dist/src/Skiplist.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
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;
|
|
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"}
|
package/dist/src/Skiplist.js
CHANGED
package/dist/src/Sqlite.d.ts
CHANGED
|
@@ -1,65 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
*
|
|
14
|
+
* Platform-agnostic SQLite wrapping a {@link SqliteDriver}.
|
|
27
15
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
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
|
|
34
|
-
readonly exec: <R extends SqliteRow = SqliteRow>(query: SqliteQuery) =>
|
|
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.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
*
|
|
100
|
-
*
|
|
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
|
-
|
|
108
|
-
|
|
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
|
-
|
|
112
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
162
|
-
*
|
|
254
|
+
* Returns {@link SqliteSchema} and full {@link SqliteRow} table contents for
|
|
255
|
+
* inspection and testing.
|
|
163
256
|
*/
|
|
164
|
-
export
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
277
|
+
* ## Tips
|
|
178
278
|
*
|
|
179
279
|
* - Use {@link sqliteTrue} and {@link sqliteFalse} constants for better
|
|
180
280
|
* readability.
|