@evolu/common 6.0.1-preview.2 → 6.0.1-preview.20
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/dist/src/Assert.d.ts +6 -3
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +7 -4
- package/dist/src/Brand.d.ts +75 -0
- package/dist/src/Brand.d.ts.map +1 -0
- package/dist/src/Brand.js +1 -0
- package/dist/src/Buffer.d.ts +1 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +1 -1
- package/dist/src/CallbackRegistry.d.ts +53 -0
- package/dist/src/CallbackRegistry.d.ts.map +1 -0
- package/dist/src/CallbackRegistry.js +25 -0
- package/dist/src/Console.d.ts +31 -6
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +72 -9
- package/dist/src/Crypto.d.ts +61 -34
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +29 -42
- package/dist/src/Evolu/Db.d.ts +137 -66
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Db.js +300 -705
- package/dist/src/Evolu/Diff.d.ts +3 -3
- package/dist/src/Evolu/Diff.d.ts.map +1 -1
- package/dist/src/Evolu/Diff.js +7 -5
- package/dist/src/Evolu/Evolu.d.ts +200 -115
- package/dist/src/Evolu/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.js +287 -157
- package/dist/src/Evolu/Internal.d.ts +0 -2
- package/dist/src/Evolu/Internal.d.ts.map +1 -1
- package/dist/src/Evolu/Internal.js +0 -2
- package/dist/src/Evolu/LocalAuth.d.ts +144 -0
- package/dist/src/Evolu/LocalAuth.d.ts.map +1 -0
- package/dist/src/Evolu/LocalAuth.js +171 -0
- package/dist/src/Evolu/Owner.d.ts +152 -127
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +88 -107
- package/dist/src/Evolu/Platform.d.ts +9 -7
- package/dist/src/Evolu/Platform.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.d.ts +170 -186
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +487 -343
- package/dist/src/Evolu/Public.d.ts +6 -8
- package/dist/src/Evolu/Public.d.ts.map +1 -1
- package/dist/src/Evolu/Public.js +2 -3
- package/dist/src/Evolu/PublicKysely.js +3 -3
- package/dist/src/Evolu/Query.d.ts +2 -1
- package/dist/src/Evolu/Query.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.d.ts +4 -3
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +50 -12
- package/dist/src/Evolu/Schema.d.ts +129 -73
- package/dist/src/Evolu/Schema.d.ts.map +1 -1
- package/dist/src/Evolu/Schema.js +169 -89
- package/dist/src/Evolu/Storage.d.ts +159 -14
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +42 -32
- package/dist/src/Evolu/Sync.d.ts +77 -13
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +453 -20
- package/dist/src/Evolu/Timestamp.d.ts +35 -27
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +27 -18
- package/dist/src/ManyToManyMap.d.ts +74 -10
- package/dist/src/ManyToManyMap.d.ts.map +1 -1
- package/dist/src/ManyToManyMap.js +41 -6
- package/dist/src/Number.d.ts +2 -1
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Random.d.ts +3 -2
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/RefCountedResourceManager.d.ts +119 -0
- package/dist/src/RefCountedResourceManager.d.ts.map +1 -0
- package/dist/src/RefCountedResourceManager.js +197 -0
- package/dist/src/Result.d.ts +147 -51
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +7 -241
- package/dist/src/Sqlite.d.ts +21 -4
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +50 -8
- package/dist/src/Task.d.ts +511 -0
- package/dist/src/Task.d.ts.map +1 -0
- package/dist/src/Task.js +410 -0
- package/dist/src/Time.d.ts +59 -0
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +87 -4
- package/dist/src/Type.d.ts +462 -327
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +490 -436
- package/dist/src/Types.d.ts +0 -74
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/WebSocket.d.ts +5 -2
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +12 -13
- package/dist/src/Worker.d.ts +39 -11
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +22 -4
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/package.json +14 -13
- package/src/Assert.ts +8 -7
- package/src/Brand.ts +75 -0
- package/src/Buffer.ts +1 -1
- package/src/CallbackRegistry.ts +84 -0
- package/src/Console.ts +91 -11
- package/src/Crypto.ts +94 -79
- package/src/Evolu/Db.ts +505 -1027
- package/src/Evolu/Diff.ts +7 -5
- package/src/Evolu/Evolu.ts +682 -329
- package/src/Evolu/Internal.ts +0 -2
- package/src/Evolu/LocalAuth.ts +422 -0
- package/src/Evolu/Owner.ts +221 -235
- package/src/Evolu/Platform.ts +9 -9
- package/src/Evolu/Protocol.ts +681 -614
- package/src/Evolu/Public.ts +7 -14
- package/src/Evolu/PublicKysely.ts +3 -3
- package/src/Evolu/Query.ts +2 -1
- package/src/Evolu/Relay.ts +62 -16
- package/src/Evolu/Schema.ts +391 -191
- package/src/Evolu/Storage.ts +275 -55
- package/src/Evolu/Sync.ts +758 -37
- package/src/Evolu/Timestamp.ts +38 -35
- package/src/ManyToManyMap.ts +127 -24
- package/src/Number.ts +2 -6
- package/src/Random.ts +3 -2
- package/src/RefCountedResourceManager.ts +368 -0
- package/src/Result.ts +152 -53
- package/src/Sqlite.ts +59 -23
- package/src/Task.ts +779 -0
- package/src/Time.ts +168 -4
- package/src/Type.ts +696 -660
- package/src/Types.ts +0 -76
- package/src/WebSocket.ts +23 -17
- package/src/Worker.ts +72 -23
- package/src/index.ts +3 -3
- package/dist/src/Callbacks.d.ts +0 -20
- package/dist/src/Callbacks.d.ts.map +0 -1
- package/dist/src/Callbacks.js +0 -18
- package/dist/src/Evolu/Config.d.ts +0 -69
- package/dist/src/Evolu/Config.d.ts.map +0 -1
- package/dist/src/Evolu/Config.js +0 -9
- package/dist/src/Evolu/Kysely.d.ts +0 -6
- package/dist/src/Evolu/Kysely.d.ts.map +0 -1
- package/dist/src/Evolu/Kysely.js +0 -21
- package/dist/src/NanoId.d.ts +0 -27
- package/dist/src/NanoId.d.ts.map +0 -1
- package/dist/src/NanoId.js +0 -6
- package/dist/src/Promise.d.ts +0 -180
- package/dist/src/Promise.d.ts.map +0 -1
- package/dist/src/Promise.js +0 -176
- package/src/Callbacks.ts +0 -43
- package/src/Evolu/Config.ts +0 -83
- package/src/Evolu/Kysely.ts +0 -38
- package/src/NanoId.ts +0 -39
- package/src/Promise.ts +0 -295
|
@@ -4,15 +4,13 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
export { createEvolu } from "./Evolu.js";
|
|
7
|
-
export type { Evolu,
|
|
7
|
+
export type { Evolu, EvoluConfig, EvoluDeps, EvoluError } from "./Evolu.js";
|
|
8
8
|
export * from "./Owner.js";
|
|
9
|
-
export
|
|
10
|
-
export type { BinaryId } from "./Protocol.js";
|
|
9
|
+
export * from "./LocalAuth.js";
|
|
11
10
|
export * as kysely from "./PublicKysely.js";
|
|
12
11
|
export type { InferRow, Query, QueryRows, Row } from "./Query.js";
|
|
13
|
-
export {
|
|
14
|
-
export type {
|
|
15
|
-
export
|
|
16
|
-
export {
|
|
17
|
-
export type { BinaryTimestamp, TimestampCounterOverflowError, TimestampDriftError, TimestampDuplicateNodeError, TimestampError, TimestampTimeOutOfRangeError, } from "./Timestamp.js";
|
|
12
|
+
export type { EvoluSchema } from "./Schema.js";
|
|
13
|
+
export type { NetworkError, PaymentRequiredError, ServerError, SyncOwner, SyncState, SyncStateInitial, SyncStateIsNotSynced, SyncStateIsSynced, SyncStateIsSyncing, } from "./Sync.js";
|
|
14
|
+
export { Timestamp, timestampBytesToTimestamp, timestampToTimestampBytes, } from "./Timestamp.js";
|
|
15
|
+
export type { TimestampBytes, TimestampCounterOverflowError, TimestampDriftError, TimestampError, TimestampTimeOutOfRangeError, } from "./Timestamp.js";
|
|
18
16
|
//# sourceMappingURL=Public.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Public.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Public.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,YAAY,
|
|
1
|
+
{"version":3,"file":"Public.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Public.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC5E,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,SAAS,EACT,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,cAAc,EACd,6BAA6B,EAC7B,mBAAmB,EACnB,cAAc,EACd,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC"}
|
package/dist/src/Evolu/Public.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { createEvolu } from "./Evolu.js";
|
|
7
7
|
export * from "./Owner.js";
|
|
8
|
-
export
|
|
8
|
+
export * from "./LocalAuth.js";
|
|
9
9
|
export * as kysely from "./PublicKysely.js";
|
|
10
|
-
export {
|
|
11
|
-
export { binaryTimestampToTimestamp, Timestamp, timestampToBinaryTimestamp, } from "./Timestamp.js";
|
|
10
|
+
export { Timestamp, timestampBytesToTimestamp, timestampToTimestampBytes, } from "./Timestamp.js";
|
|
@@ -48,7 +48,7 @@ export { sql } from "kysely";
|
|
|
48
48
|
* from "person"
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
|
-
//
|
|
51
|
+
// Kysely expects strict AST.
|
|
52
52
|
// prettier-ignore
|
|
53
53
|
export function jsonArrayFrom(expr) {
|
|
54
54
|
return sql `(select ${sql.lit(kyselyJsonIdentifier)} || coalesce(json_group_array(json_object(${sql.join(getSqliteJsonObjectArgs(expr.toOperationNode(), 'agg'))})), '[]') from ${expr} as agg)`;
|
|
@@ -100,7 +100,7 @@ export function jsonArrayFrom(expr) {
|
|
|
100
100
|
* from "person";
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
|
-
//
|
|
103
|
+
// Kysely expects strict AST.
|
|
104
104
|
// prettier-ignore
|
|
105
105
|
export function jsonObjectFrom(expr) {
|
|
106
106
|
return sql `(select ${sql.lit(kyselyJsonIdentifier)} || json_object(${sql.join(getSqliteJsonObjectArgs(expr.toOperationNode(), 'obj'))}) from ${expr} as obj)`;
|
|
@@ -145,7 +145,7 @@ export function jsonObjectFrom(expr) {
|
|
|
145
145
|
* from "person"
|
|
146
146
|
* ```
|
|
147
147
|
*/
|
|
148
|
-
//
|
|
148
|
+
// Kysely expects strict AST.
|
|
149
149
|
// prettier-ignore
|
|
150
150
|
export function jsonBuildObject(obj) {
|
|
151
151
|
return sql `${sql.lit(kyselyJsonIdentifier)} || json_object(${sql.join(Object.keys(obj).flatMap((k) => [sql.lit(k), obj[k]]))})`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SqliteQuery, SqliteRow, SqliteValue } from "../Sqlite.js";
|
|
2
2
|
import { Store, StoreSubscribe } from "../Store.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Simplify } from "../Types.js";
|
|
4
|
+
import { Brand } from "../Brand.js";
|
|
4
5
|
/**
|
|
5
6
|
* A type-safe SQL query.
|
|
6
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Query.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Query.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EAEX,SAAS,EACT,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Query.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Query.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EAEX,SAAS,EACT,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,GAAG,GAAG,GAAG,IAAI,MAAM,GAC7C,KAAK,CAAC,OAAO,CAAC,GAAG;IACf;;;;;;;;;;;OAWG;IACH,GAAG,EAAE,CAAC,CAAC;CACR,CAA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,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;AAElE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,CACZ,WAAW,EAAE,aAAa,CAAC,SAAS,CAAC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,KACnE,IAAI,CAAC;IACV,QAAQ,CAAC,GAAG,EAAE,MAAM,YAAY,CAAC;CAClC;AAED,eAAO,MAAM,oBAAoB,QAAO,cAWvC,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,cAAc,CAAC;IAE5C,GAAG,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC;IAE/B,GAAG,EAAE,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;CACjC;AAED,eAAO,MAAM,uBAAuB,GAClC,WAAW,KAAK,CAAC,YAAY,CAAC,KAC7B,iBAwBF,CAAC"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ConsoleConfig } from "../Console.js";
|
|
2
|
+
import { TimingSafeEqualDep } from "../Crypto.js";
|
|
2
3
|
import { Result } from "../Result.js";
|
|
3
4
|
import { SqliteError } from "../Sqlite.js";
|
|
4
5
|
import { SimpleName } from "../Type.js";
|
|
5
|
-
import { Storage } from "./
|
|
6
|
-
import { CreateSqliteStorageBaseOptions, SqliteStorageDeps } from "./Storage.js";
|
|
6
|
+
import { CreateSqliteStorageBaseOptions, SqliteStorageDeps, Storage } from "./Storage.js";
|
|
7
7
|
export interface Relay extends Disposable {
|
|
8
8
|
}
|
|
9
9
|
export interface RelayConfig extends ConsoleConfig {
|
|
10
10
|
readonly name?: SimpleName;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type RelaySqliteStorageDeps = SqliteStorageDeps & TimingSafeEqualDep;
|
|
13
|
+
export declare const createRelayStorage: (deps: RelaySqliteStorageDeps) => (options: CreateSqliteStorageBaseOptions) => Result<Storage, SqliteError>;
|
|
13
14
|
//# sourceMappingURL=Relay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Relay.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Relay.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Relay.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Relay.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAW,MAAM,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAO,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAEL,8BAA8B,EAE9B,iBAAiB,EACjB,OAAO,EACR,MAAM,cAAc,CAAC;AAGtB,MAAM,WAAW,KAAM,SAAQ,UAAU;CAAG;AAE5C,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;CAC5B;AAED,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AAE5E,eAAO,MAAM,kBAAkB,GAC5B,MAAM,sBAAsB,MAC5B,SAAS,8BAA8B,KAAG,MAAM,CAAC,OAAO,EAAE,WAAW,CAiKrE,CAAC"}
|
package/dist/src/Evolu/Relay.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { isNonEmptyReadonlyArray } from "../Array.js";
|
|
2
|
-
import {
|
|
3
|
-
import { ok } from "../Result.js";
|
|
2
|
+
import { err, ok } from "../Result.js";
|
|
4
3
|
import { sql } from "../Sqlite.js";
|
|
5
4
|
import { createSqliteStorageBase, } from "./Storage.js";
|
|
6
|
-
import {
|
|
5
|
+
import { timestampToTimestampBytes } from "./Timestamp.js";
|
|
7
6
|
export const createRelayStorage = (deps) => (options) => {
|
|
8
7
|
const sqliteStorageBase = createSqliteStorageBase(deps)(options);
|
|
9
8
|
if (!sqliteStorageBase.ok)
|
|
@@ -34,7 +33,7 @@ export const createRelayStorage = (deps) => (options) => {
|
|
|
34
33
|
return ok({
|
|
35
34
|
...sqliteStorageBase.value,
|
|
36
35
|
/**
|
|
37
|
-
* Lazily authorizes the initiator's {@link
|
|
36
|
+
* Lazily authorizes the initiator's {@link OwnerWriteKey} for the given
|
|
38
37
|
* {@link OwnerId}.
|
|
39
38
|
*
|
|
40
39
|
* - If the {@link OwnerId} does not exist, it is created and associated with
|
|
@@ -44,10 +43,10 @@ export const createRelayStorage = (deps) => (options) => {
|
|
|
44
43
|
*/
|
|
45
44
|
validateWriteKey: (ownerId, writeKey) => {
|
|
46
45
|
const selectWriteKey = deps.sqlite.exec(sql `
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
select writeKey
|
|
47
|
+
from evolu_writeKey
|
|
48
|
+
where ownerId = ${ownerId};
|
|
49
|
+
`);
|
|
51
50
|
if (!selectWriteKey.ok) {
|
|
52
51
|
options.onStorageError(selectWriteKey.error);
|
|
53
52
|
return false;
|
|
@@ -64,12 +63,27 @@ export const createRelayStorage = (deps) => (options) => {
|
|
|
64
63
|
}
|
|
65
64
|
return true;
|
|
66
65
|
}
|
|
67
|
-
return
|
|
66
|
+
return deps.timingSafeEqual(rows[0].writeKey, writeKey);
|
|
68
67
|
},
|
|
69
|
-
|
|
68
|
+
setWriteKey: (ownerId, writeKey) => {
|
|
69
|
+
const upsertWriteKey = deps.sqlite.exec(sql `
|
|
70
|
+
insert into evolu_writeKey (ownerId, writeKey)
|
|
71
|
+
values (${ownerId}, ${writeKey})
|
|
72
|
+
on conflict (ownerId) do update
|
|
73
|
+
set writeKey = excluded.writeKey;
|
|
74
|
+
`);
|
|
75
|
+
if (!upsertWriteKey.ok) {
|
|
76
|
+
options.onStorageError(upsertWriteKey.error);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
},
|
|
81
|
+
// https://eslint.org/docs/latest/rules/require-await#when-not-to-use-it
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
83
|
+
writeMessages: async (ownerId, messages) => {
|
|
70
84
|
const result = deps.sqlite.transaction(() => {
|
|
71
85
|
for (const message of messages) {
|
|
72
|
-
const insertTimestampResult = sqliteStorageBase.value.insertTimestamp(ownerId,
|
|
86
|
+
const insertTimestampResult = sqliteStorageBase.value.insertTimestamp(ownerId, timestampToTimestampBytes(message.timestamp));
|
|
73
87
|
if (!insertTimestampResult.ok)
|
|
74
88
|
return insertTimestampResult;
|
|
75
89
|
const insertMessage = deps.sqlite.exec(sql `
|
|
@@ -77,7 +91,7 @@ export const createRelayStorage = (deps) => (options) => {
|
|
|
77
91
|
values
|
|
78
92
|
(
|
|
79
93
|
${ownerId},
|
|
80
|
-
${
|
|
94
|
+
${timestampToTimestampBytes(message.timestamp)},
|
|
81
95
|
${message.change}
|
|
82
96
|
)
|
|
83
97
|
on conflict do nothing;
|
|
@@ -105,5 +119,29 @@ export const createRelayStorage = (deps) => (options) => {
|
|
|
105
119
|
}
|
|
106
120
|
return result.value.rows[0]?.change;
|
|
107
121
|
},
|
|
122
|
+
deleteOwner: (ownerId) => {
|
|
123
|
+
const result = deps.sqlite.transaction(() => {
|
|
124
|
+
const del1 = deps.sqlite.exec(sql `
|
|
125
|
+
delete from evolu_writeKey where ownerId = ${ownerId};
|
|
126
|
+
`);
|
|
127
|
+
if (!del1.ok)
|
|
128
|
+
return del1;
|
|
129
|
+
const del2 = deps.sqlite.exec(sql `
|
|
130
|
+
delete from evolu_message where ownerId = ${ownerId};
|
|
131
|
+
`);
|
|
132
|
+
if (!del2.ok)
|
|
133
|
+
return del2;
|
|
134
|
+
const del3 = sqliteStorageBase.value.deleteOwner(ownerId);
|
|
135
|
+
if (!del3)
|
|
136
|
+
return err(null);
|
|
137
|
+
return ok();
|
|
138
|
+
});
|
|
139
|
+
if (!result.ok) {
|
|
140
|
+
if (result.error)
|
|
141
|
+
options.onStorageError(result.error);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
},
|
|
108
146
|
});
|
|
109
147
|
};
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Kysely from "kysely";
|
|
2
2
|
import { ReadonlyRecord } from "../Object.js";
|
|
3
3
|
import { Result } from "../Result.js";
|
|
4
|
-
import { SqliteBoolean, SqliteQueryOptions, SqliteValue } from "../Sqlite.js";
|
|
5
|
-
import { AnyType,
|
|
4
|
+
import { SqliteBoolean, SqliteDep, SqliteError, SqliteQueryOptions, SqliteValue } from "../Sqlite.js";
|
|
5
|
+
import { AnyType, DateIso, IdBytes, InferErrors, InferInput, InferType, MergeObjectTypeErrors, NullableToOptionalProps, ObjectType, OptionalType, TableId, Type, ValidMutationSize, ValidMutationSizeError } from "../Type.js";
|
|
6
6
|
import { Simplify } from "../Types.js";
|
|
7
|
-
import {
|
|
8
|
-
import { DbIndexesBuilder } from "./Kysely.js";
|
|
9
|
-
import { ShardOwner, SharedOwner } from "./Owner.js";
|
|
10
|
-
import { BinaryId } from "./Protocol.js";
|
|
7
|
+
import { OwnerId } from "./Owner.js";
|
|
11
8
|
import { Query, Row } from "./Query.js";
|
|
12
|
-
import {
|
|
9
|
+
import { DbChange } from "./Storage.js";
|
|
10
|
+
import { TimestampBytes } from "./Timestamp.js";
|
|
13
11
|
/**
|
|
14
12
|
* Defines the schema of an Evolu database.
|
|
15
13
|
*
|
|
16
|
-
* - Each top-level key represents a table name.
|
|
17
|
-
* - The value for each table name is a record of column names mapped to their
|
|
18
|
-
* respective data types, defined by {@link Type}.
|
|
19
|
-
* - Each table must include a mandatory `id` column of type {@link Id}.
|
|
20
|
-
* - No table may contain {@link DefaultColumns}.
|
|
21
|
-
*
|
|
22
14
|
* Table schema defines columns that are required for table rows. For not
|
|
23
15
|
* required columns, use {@link nullOr}.
|
|
24
16
|
*
|
|
@@ -50,64 +42,104 @@ import { BinaryTimestamp } from "./Timestamp.js";
|
|
|
50
42
|
* };
|
|
51
43
|
* ```
|
|
52
44
|
*/
|
|
53
|
-
export type EvoluSchema = ReadonlyRecord<string, ReadonlyRecord<string, Type<any, any, any, any, any
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
45
|
+
export type EvoluSchema = ReadonlyRecord<string, ReadonlyRecord<string, Type<any, any, any, any, any, any>>>;
|
|
46
|
+
/**
|
|
47
|
+
* Validates an {@link EvoluSchema} at compile time, returning the first error
|
|
48
|
+
* found as a readable string literal type. This approach provides much clearer
|
|
49
|
+
* and more actionable TypeScript errors than the default, which are often hard
|
|
50
|
+
* to read.
|
|
51
|
+
*
|
|
52
|
+
* Validates the following schema requirements:
|
|
53
|
+
*
|
|
54
|
+
* 1. All tables must have an 'id' column
|
|
55
|
+
* 2. The 'id' column must be a branded ID type (created with id() function)
|
|
56
|
+
* 3. Tables cannot use default column names (createdAt, updatedAt, isDeleted)
|
|
57
|
+
* 4. All column types must be compatible with SQLite (extend SqliteValue)
|
|
58
|
+
*/
|
|
59
|
+
export type ValidateSchema<S extends EvoluSchema> = ValidateSchemaHasId<S> extends never ? ValidateIdColumnType<S> extends never ? ValidateNoDefaultColumns<S> extends never ? ValidateColumnTypes<S> extends never ? S : ValidateColumnTypes<S> : ValidateNoDefaultColumns<S> : ValidateIdColumnType<S> : ValidateSchemaHasId<S>;
|
|
60
|
+
export type ValidateSchemaHasId<S extends EvoluSchema> = keyof S extends infer TableName ? TableName extends keyof S ? "id" extends keyof S[TableName] ? never : SchemaValidationError<`Table "${TableName & string}" is missing required id column.`> : never : never;
|
|
61
|
+
export type ValidateIdColumnType<S extends EvoluSchema> = keyof S extends infer TableName ? TableName extends keyof S ? "id" extends keyof S[TableName] ? S[TableName]["id"] extends TableId<any> ? never : SchemaValidationError<`Table "${TableName & string}" id column must be a branded ID type (created with id("${TableName & string}")).`> : never : never : never;
|
|
62
|
+
export type ValidateNoDefaultColumns<S extends EvoluSchema> = keyof S extends infer TableName ? TableName extends keyof S ? keyof S[TableName] extends infer ColumnName ? ColumnName extends keyof S[TableName] ? ColumnName extends "createdAt" | "updatedAt" | "isDeleted" ? SchemaValidationError<`Table "${TableName & string}" uses default column name "${ColumnName & string}". Default columns (createdAt, updatedAt, isDeleted) are added automatically.`> : never : never : never : never : never;
|
|
63
|
+
export type ValidateColumnTypes<S extends EvoluSchema> = keyof S extends infer TableName ? TableName extends keyof S ? keyof S[TableName] extends infer ColumnName ? ColumnName extends keyof S[TableName] ? InferType<S[TableName][ColumnName]> extends SqliteValue ? never : SchemaValidationError<`Table "${TableName & string}" column "${ColumnName & string}" type is not compatible with SQLite. Column types must extend SqliteValue (string, number, Uint8Array, or null).`> : never : never : never : never;
|
|
64
|
+
/** Schema validation error that shows clear, readable messages */
|
|
65
|
+
export type SchemaValidationError<Message extends string> = `❌ Schema Error: ${Message}`;
|
|
66
|
+
export type IndexesConfig = (create: (indexName: string) => Kysely.CreateIndexBuilder) => ReadonlyArray<Kysely.CreateIndexBuilder<any>>;
|
|
67
|
+
export declare const evoluSchemaToDbSchema: (schema: EvoluSchema, indexesConfig?: IndexesConfig) => DbSchema;
|
|
68
|
+
export type CreateQuery<S extends EvoluSchema> = <R extends Row>(queryCallback: (db: Pick<Kysely.Kysely<{
|
|
57
69
|
[Table in keyof S]: {
|
|
58
70
|
readonly [Column in keyof S[Table]]: Column extends "id" | "createdAt" | "updatedAt" ? InferType<S[Table][Column]> : InferType<S[Table][Column]> | null;
|
|
59
71
|
} & DefaultColumns;
|
|
60
72
|
} & {
|
|
61
73
|
readonly evolu_history: {
|
|
62
|
-
readonly timestamp:
|
|
74
|
+
readonly timestamp: TimestampBytes;
|
|
63
75
|
readonly table: keyof S;
|
|
64
|
-
readonly
|
|
76
|
+
readonly id: IdBytes;
|
|
65
77
|
readonly column: string;
|
|
66
78
|
readonly value: SqliteValue;
|
|
67
79
|
};
|
|
68
|
-
}>, "selectFrom" | "fn" | "with" | "withRecursive">) => SelectQueryBuilder<any, any, R>, options?: SqliteQueryOptions) => Query<Simplify<R>>;
|
|
69
|
-
export declare const DefaultColumns: ObjectType<{
|
|
70
|
-
createdAt: BrandType<Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>, "DateIso", import("../Type.js").DateIsoStringError, import("../Type.js").StringError>;
|
|
71
|
-
updatedAt: BrandType<Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>, "DateIso", import("../Type.js").DateIsoStringError, import("../Type.js").StringError>;
|
|
72
|
-
isDeleted: import("../Type.js").UnionType<[Type<"Null", null, null, import("../Type.js").NullError, null, import("../Type.js").NullError>, import("../Type.js").TransformType<Type<"Boolean", boolean, boolean, import("../Type.js").BooleanError, boolean, import("../Type.js").BooleanError>, import("../Type.js").UnionType<[import("../Type.js").LiteralType<0>, import("../Type.js").LiteralType<1>]>, never>]>;
|
|
73
|
-
}>;
|
|
74
|
-
export type DefaultColumns = typeof DefaultColumns.Type;
|
|
80
|
+
}>, "selectFrom" | "fn" | "with" | "withRecursive">) => Kysely.SelectQueryBuilder<any, any, R>, options?: SqliteQueryOptions) => Query<Simplify<R>>;
|
|
75
81
|
/**
|
|
76
|
-
*
|
|
82
|
+
* Default columns automatically added to all tables.
|
|
77
83
|
*
|
|
78
|
-
* -
|
|
79
|
-
*
|
|
80
|
-
* -
|
|
84
|
+
* - `createdAt`: Set by Evolu when `insert` is called, or can be custom with
|
|
85
|
+
* `upsert`.
|
|
86
|
+
* - `updatedAt`: Always set by Evolu, derived from {@link CrdtMessage} timestamp.
|
|
87
|
+
* If you defer sync to avoid leaking time activity, use a custom column to
|
|
88
|
+
* preserve real update time.
|
|
89
|
+
* - `isDeleted`: Soft delete flag.
|
|
81
90
|
*/
|
|
82
|
-
export declare const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}, import("../Type.js").StringError | import("../Type.js").RegexError<"Base64Url">, never>>>;
|
|
89
|
-
export type ValidEvoluSchema = typeof ValidEvoluSchema.Type;
|
|
90
|
-
export interface ValidEvoluSchemaError extends TypeError<"ValidEvoluSchema"> {
|
|
91
|
-
readonly reason: {
|
|
92
|
-
kind: "DefaultColumnError";
|
|
93
|
-
tableName: string;
|
|
94
|
-
columnName: string;
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Asserts that the given value is {@link ValidEvoluSchema}.
|
|
99
|
-
*
|
|
100
|
-
* Throws an error if the value is not a valid Evolu schema.
|
|
101
|
-
*/
|
|
102
|
-
export declare const assertValidEvoluSchema: (value: unknown) => ValidEvoluSchema;
|
|
103
|
-
export declare const validEvoluSchemaToDbSchema: (validEvoluSchema: ValidEvoluSchema, indexes?: DbIndexesBuilder) => DbSchema;
|
|
91
|
+
export declare const DefaultColumns: ObjectType<{
|
|
92
|
+
createdAt: import("../Type.js").BrandType<Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>, "DateIso", import("../Type.js").DateIsoError, import("../Type.js").StringError>;
|
|
93
|
+
updatedAt: import("../Type.js").BrandType<Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>, "DateIso", import("../Type.js").DateIsoError, import("../Type.js").StringError>;
|
|
94
|
+
isDeleted: import("../Type.js").UnionType<[Type<"Null", null, null, import("../Type.js").NullError, null, import("../Type.js").NullError>, import("../Type.js").UnionType<[import("../Type.js").LiteralType<0>, import("../Type.js").LiteralType<1>]>]>;
|
|
95
|
+
}>;
|
|
96
|
+
export type DefaultColumns = typeof DefaultColumns.Type;
|
|
104
97
|
export type MutationKind = "insert" | "update" | "upsert";
|
|
105
98
|
export type Mutation<S extends EvoluSchema, Kind extends MutationKind> = <TableName extends keyof S>(table: TableName, props: InferInput<ObjectType<MutationMapping<S[TableName], Kind>>>, options?: MutationOptions) => Result<{
|
|
106
99
|
readonly id: S[TableName]["id"]["Type"];
|
|
107
100
|
}, ValidMutationSizeError | MergeObjectTypeErrors<ObjectType<MutationMapping<S[TableName], Kind>>>>;
|
|
108
101
|
export type MutationMapping<P extends Record<string, AnyType>, M extends MutationKind> = M extends "insert" ? InsertableProps<P> : M extends "update" ? UpdateableProps<P> : UpsertableProps<P>;
|
|
109
102
|
export interface MutationOptions {
|
|
103
|
+
/**
|
|
104
|
+
* Called after the mutation is completed and the local state is updated.
|
|
105
|
+
* Useful for triggering side effects (e.g., notifications, UI updates) after
|
|
106
|
+
* insert, update, or upsert.
|
|
107
|
+
*/
|
|
110
108
|
readonly onComplete?: () => void;
|
|
109
|
+
/**
|
|
110
|
+
* Specifies the owner ID for this mutation. If omitted, the default
|
|
111
|
+
* {@link AppOwner} is used.
|
|
112
|
+
*
|
|
113
|
+
* The owner must be used with `evolu.useOwner()` to enable sync. Mutations
|
|
114
|
+
* with unused owners are stored locally but not synced until the owner is
|
|
115
|
+
* used.
|
|
116
|
+
*
|
|
117
|
+
* ### Example
|
|
118
|
+
*
|
|
119
|
+
* ```ts
|
|
120
|
+
* // Partition your own data by project (derived from your AppOwner)
|
|
121
|
+
* const projectOwner = deriveShardOwner(appOwner, [
|
|
122
|
+
* "project",
|
|
123
|
+
* projectId,
|
|
124
|
+
* ]);
|
|
125
|
+
* evolu.insert(
|
|
126
|
+
* "task",
|
|
127
|
+
* { title: "Task 1" },
|
|
128
|
+
* { ownerId: projectOwner.id },
|
|
129
|
+
* );
|
|
130
|
+
*
|
|
131
|
+
* // Collaborative data (independent owner shared with others)
|
|
132
|
+
* const sharedOwner = createSharedOwner(sharedSecret);
|
|
133
|
+
* evolu.insert(
|
|
134
|
+
* "comment",
|
|
135
|
+
* { text: "Hello" },
|
|
136
|
+
* { ownerId: sharedOwner.id },
|
|
137
|
+
* );
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @experimental
|
|
141
|
+
*/
|
|
142
|
+
readonly ownerId?: OwnerId;
|
|
111
143
|
/**
|
|
112
144
|
* Only validate, don't mutate.
|
|
113
145
|
*
|
|
@@ -115,24 +147,11 @@ export interface MutationOptions {
|
|
|
115
147
|
* `onlyValidate: true`.
|
|
116
148
|
*/
|
|
117
149
|
readonly onlyValidate?: boolean;
|
|
118
|
-
/**
|
|
119
|
-
* The owner to use for this mutation. Can be a {@link ShardOwner} for sharding
|
|
120
|
-
* app data or a {@link SharedOwner} for collaborative write access. If
|
|
121
|
-
* omitted, defaults to the app's {@link AppOwner}.
|
|
122
|
-
*/
|
|
123
|
-
readonly owner?: ShardOwner | SharedOwner;
|
|
124
150
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* measured via MessagePack. Evolu Protocol DbChange will be smaller thanks to
|
|
129
|
-
* various optimizations.
|
|
130
|
-
*/
|
|
131
|
-
export declare const maxMutationSize = 655360;
|
|
132
|
-
export interface ValidMutationSizeError extends TypeError<"ValidMutationSize"> {
|
|
151
|
+
export interface MutationChange extends DbChange {
|
|
152
|
+
/** Owner of the change. If undefined, the change belongs to the AppOwner. */
|
|
153
|
+
readonly ownerId?: OwnerId | undefined;
|
|
133
154
|
}
|
|
134
|
-
export declare const formatValidMutationSizeError: import("../Type.js").TypeErrorFormatter<ValidMutationSizeError>;
|
|
135
|
-
export type ValidMutationSize<Props extends Record<string, AnyType>> = BrandType<ObjectType<Props>, "ValidMutationSize", ValidMutationSizeError, InferErrors<ObjectType<Props>>>;
|
|
136
155
|
/**
|
|
137
156
|
* Type Factory to create insertable {@link Type}. It makes nullable Types
|
|
138
157
|
* optional, omits Id, and ensures the {@link maxMutationSize}.
|
|
@@ -176,20 +195,28 @@ export type UpdateableProps<Props extends Record<string, AnyType>> = {
|
|
|
176
195
|
};
|
|
177
196
|
export type Updateable<Props extends Record<string, AnyType>> = InferInput<ObjectType<UpdateableProps<Props>>>;
|
|
178
197
|
/**
|
|
179
|
-
* Type Factory to create upsertable Type. It makes nullable Types optional
|
|
180
|
-
* ensures the
|
|
198
|
+
* Type Factory to create upsertable Type. It makes nullable Types optional,
|
|
199
|
+
* includes optional default columns (createdAt, isDeleted), and ensures the
|
|
200
|
+
* {@link maxMutationSize}.
|
|
181
201
|
*
|
|
182
202
|
* ### Example
|
|
183
203
|
*
|
|
184
204
|
* ```ts
|
|
185
205
|
* const UpsertableTodo = upsertable(Schema.todo);
|
|
186
206
|
* type UpsertableTodo = typeof UpsertableTodo.Type;
|
|
187
|
-
* const todo = UpsertableTodo.from({
|
|
207
|
+
* const todo = UpsertableTodo.from({
|
|
208
|
+
* id,
|
|
209
|
+
* title,
|
|
210
|
+
* createdAt: "2023-01-01T00:00:00.000Z",
|
|
211
|
+
* });
|
|
188
212
|
* if (!todo.ok) return; // handle errors
|
|
189
213
|
* ```
|
|
190
214
|
*/
|
|
191
215
|
export declare const upsertable: <Props extends Record<string, AnyType>>(props: Props) => ValidMutationSize<UpsertableProps<Props>>;
|
|
192
|
-
export type UpsertableProps<Props extends Record<string, AnyType>> = NullableToOptionalProps<Props
|
|
216
|
+
export type UpsertableProps<Props extends Record<string, AnyType>> = NullableToOptionalProps<Props & {
|
|
217
|
+
createdAt: OptionalType<typeof DateIso>;
|
|
218
|
+
isDeleted: OptionalType<typeof SqliteBoolean>;
|
|
219
|
+
}>;
|
|
193
220
|
export type Upsertable<Props extends Record<string, AnyType>> = InferInput<ObjectType<UpsertableProps<Props>>>;
|
|
194
221
|
export type InferEvoluSchemaError<S extends EvoluSchema> = {
|
|
195
222
|
[Table in keyof S]: InferMutationTypeErrors<S[Table]>;
|
|
@@ -198,4 +225,33 @@ export type InferMutationTypeErrors<T extends Record<string, AnyType>> = InferCo
|
|
|
198
225
|
export type InferColumnErrors<T extends Record<string, AnyType>, M extends MutationKind> = {
|
|
199
226
|
[Column in keyof MutationMapping<T, M>]: InferErrors<MutationMapping<T, M>[Column]>;
|
|
200
227
|
}[keyof MutationMapping<T, M>];
|
|
228
|
+
export declare const DbTable: ObjectType<{
|
|
229
|
+
name: Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>;
|
|
230
|
+
columns: import("../Type.js").ArrayType<Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>>;
|
|
231
|
+
}>;
|
|
232
|
+
export type DbTable = typeof DbTable.Type;
|
|
233
|
+
export declare const DbIndex: ObjectType<{
|
|
234
|
+
name: Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>;
|
|
235
|
+
sql: Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>;
|
|
236
|
+
}>;
|
|
237
|
+
export type DbIndex = typeof DbIndex.Type;
|
|
238
|
+
export declare const DbSchema: ObjectType<{
|
|
239
|
+
tables: import("../Type.js").ArrayType<ObjectType<{
|
|
240
|
+
name: Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>;
|
|
241
|
+
columns: import("../Type.js").ArrayType<Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>>;
|
|
242
|
+
}>>;
|
|
243
|
+
indexes: import("../Type.js").ArrayType<ObjectType<{
|
|
244
|
+
name: Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>;
|
|
245
|
+
sql: Type<"String", string, string, import("../Type.js").StringError, string, import("../Type.js").StringError>;
|
|
246
|
+
}>>;
|
|
247
|
+
}>;
|
|
248
|
+
export type DbSchema = typeof DbSchema.Type;
|
|
249
|
+
/** Get the current database schema by reading SQLite metadata. */
|
|
250
|
+
export declare const getDbSchema: (deps: SqliteDep) => ({ allIndexes }?: {
|
|
251
|
+
allIndexes?: boolean;
|
|
252
|
+
}) => Result<DbSchema, SqliteError>;
|
|
253
|
+
export declare const ensureDbSchema: (deps: SqliteDep) => (newSchema: DbSchema, currentSchema: DbSchema, options?: {
|
|
254
|
+
ignoreIndexes: boolean;
|
|
255
|
+
}) => Result<void, SqliteError>;
|
|
256
|
+
export declare const kysely: Kysely.Kysely<unknown>;
|
|
201
257
|
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAA8B,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAM,MAAM,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAGL,aAAa,EACb,SAAS,EACT,WAAW,EAEX,kBAAkB,EAClB,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,OAAO,EAEP,OAAO,EACP,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EAET,qBAAqB,EAErB,uBAAuB,EAGvB,UAAU,EAGV,YAAY,EAEZ,OAAO,EACP,IAAI,EACJ,iBAAiB,EAEjB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAY,OAAO,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAe,QAAQ,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,MAAM,WAAW,GAAG,cAAc,CACtC,MAAM,EAEN,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAC3D,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM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