@evolu/common 4.1.1 → 5.0.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 +1 -1
- package/dist/src/Config.d.ts +27 -30
- package/dist/src/Config.d.ts.map +1 -1
- package/dist/src/Config.js +32 -5
- package/dist/src/Crdt.d.ts +5 -4
- package/dist/src/Crdt.d.ts.map +1 -1
- package/dist/src/Crdt.js +27 -24
- package/dist/src/Crypto.d.ts +16 -10
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +24 -11
- package/dist/src/Db.d.ts +58 -78
- package/dist/src/Db.d.ts.map +1 -1
- package/dist/src/Db.js +368 -170
- package/dist/src/Diff.d.ts +9 -3
- package/dist/src/Diff.d.ts.map +1 -1
- package/dist/src/Diff.js +12 -11
- package/dist/src/Error.d.ts +15 -0
- package/dist/src/Error.d.ts.map +1 -0
- package/dist/src/Error.js +14 -0
- package/dist/src/Evolu.d.ts +139 -91
- package/dist/src/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu.js +267 -239
- package/dist/src/Model.d.ts +52 -0
- package/dist/src/Model.d.ts.map +1 -1
- package/dist/src/Model.js +47 -5
- package/dist/src/Owner.d.ts.map +1 -1
- package/dist/src/Owner.js +14 -8
- package/dist/src/Platform.d.ts +24 -34
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +9 -31
- package/dist/src/Public.d.ts +3 -5
- package/dist/src/Public.d.ts.map +1 -1
- package/dist/src/Public.js +2 -3
- package/dist/src/Sqlite.d.ts +25 -16
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +28 -20
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Sync.d.ts +70 -0
- package/dist/src/Sync.d.ts.map +1 -0
- package/dist/src/Sync.js +126 -0
- package/dist/src/index.d.ts +2 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -5
- package/package.json +12 -10
- package/src/Config.ts +77 -36
- package/src/Crdt.ts +61 -76
- package/src/Crypto.ts +83 -60
- package/src/Db.ts +782 -352
- package/src/Diff.ts +23 -21
- package/src/Error.ts +29 -0
- package/src/Evolu.ts +599 -499
- package/src/Model.ts +102 -6
- package/src/Owner.ts +24 -24
- package/src/Platform.ts +33 -81
- package/src/Public.ts +3 -5
- package/src/Sqlite.ts +81 -44
- package/src/Sync.ts +306 -0
- package/src/index.ts +2 -5
- package/dist/src/DbWorker.d.ts +0 -82
- package/dist/src/DbWorker.d.ts.map +0 -1
- package/dist/src/DbWorker.js +0 -335
- package/dist/src/ErrorStore.d.ts +0 -29
- package/dist/src/ErrorStore.d.ts.map +0 -1
- package/dist/src/ErrorStore.js +0 -13
- package/dist/src/OnCompletes.d.ts +0 -14
- package/dist/src/OnCompletes.d.ts.map +0 -1
- package/dist/src/OnCompletes.js +0 -25
- package/dist/src/SyncWorker.d.ts +0 -80
- package/dist/src/SyncWorker.d.ts.map +0 -1
- package/dist/src/SyncWorker.js +0 -150
- package/dist/src/Types.d.ts +0 -13
- package/dist/src/Types.d.ts.map +0 -1
- package/dist/src/Types.js +0 -1
- package/src/DbWorker.ts +0 -721
- package/src/ErrorStore.ts +0 -46
- package/src/OnCompletes.ts +0 -51
- package/src/SyncWorker.ts +0 -361
- package/src/Types.ts +0 -11
package/README.md
CHANGED
package/dist/src/Config.d.ts
CHANGED
|
@@ -1,45 +1,42 @@
|
|
|
1
1
|
import * as Context from "effect/Context";
|
|
2
|
-
import * as
|
|
3
|
-
import { CreateIndexBuilder } from "kysely";
|
|
2
|
+
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
4
3
|
export interface Config {
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* URL to reload browser tabs after {@link Owner} reset or restore.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* const indexes = [
|
|
14
|
-
* createIndex("indexTodoCreatedAt").on("todo").column("createdAt"),
|
|
7
|
+
* The default value is `/`.
|
|
8
|
+
*/
|
|
9
|
+
reloadUrl: string;
|
|
10
|
+
/**
|
|
11
|
+
* URL for Evolu sync and backup server.
|
|
15
12
|
*
|
|
16
|
-
*
|
|
17
|
-
* .on("todoCategory")
|
|
18
|
-
* .column("createdAt"),
|
|
19
|
-
* ];
|
|
13
|
+
* The default value is `https://evolu.world`.
|
|
20
14
|
*/
|
|
21
|
-
|
|
22
|
-
/** Log SQL. */
|
|
23
|
-
readonly logSql: boolean;
|
|
15
|
+
syncUrl: string;
|
|
24
16
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
17
|
+
* Evolu is multitenant - it can run more instances concurrently. Every Evolu
|
|
18
|
+
* instance has to have its own unique name. Database files are separated and
|
|
19
|
+
* invisible to each other.
|
|
20
|
+
*
|
|
21
|
+
* The default value is: `Evolu`.
|
|
27
22
|
*/
|
|
28
|
-
|
|
29
|
-
/** Alternate URL for Evolu sync and backup server. */
|
|
30
|
-
readonly syncUrl: string;
|
|
23
|
+
name: string;
|
|
31
24
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* default value is
|
|
25
|
+
* Maximum physical clock drift allowed in ms.
|
|
26
|
+
*
|
|
27
|
+
* The default value is 5 * 60 * 1000 (5 minutes).
|
|
35
28
|
*/
|
|
36
|
-
|
|
29
|
+
maxDrift: number;
|
|
37
30
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
31
|
+
* Setting the minimum log level. The default value is `none`.
|
|
32
|
+
*
|
|
33
|
+
* For development, use `trace` to log all events and `debug` to log only
|
|
34
|
+
* events with values. For production, use `warning`.
|
|
40
35
|
*/
|
|
41
|
-
|
|
36
|
+
minimumLogLevel: "none" | "trace" | "debug" | "warning";
|
|
42
37
|
}
|
|
43
38
|
export declare const Config: Context.Tag<Config, Config>;
|
|
44
|
-
export declare const
|
|
39
|
+
export declare const defaultConfig: Config;
|
|
40
|
+
/** https://effect.website/docs/guides/runtime */
|
|
41
|
+
export declare const createRuntime: (partialConfig?: Partial<Config>) => ManagedRuntime.ManagedRuntime<Config, never>;
|
|
45
42
|
//# sourceMappingURL=Config.d.ts.map
|
package/dist/src/Config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAI1C,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AAGxD,MAAM,WAAW,MAAM;IACrB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;OAKG;IACH,eAAe,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;CACzD;AAED,eAAO,MAAM,MAAM,6BAAuC,CAAC;AAE3D,eAAO,MAAM,aAAa,EAAE,MAM3B,CAAC;AAEF,iDAAiD;AACjD,eAAO,MAAM,aAAa,mBACR,QAAQ,MAAM,CAAC,KAC9B,eAAe,cAAc,CAAC,MAAM,EAAE,KAAK,CAsB7C,CAAC"}
|
package/dist/src/Config.js
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
import * as Context from "effect/Context";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import * as LogLevel from "effect/LogLevel";
|
|
4
|
+
import * as Logger from "effect/Logger";
|
|
5
|
+
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
6
|
+
import * as Match from "effect/Match";
|
|
7
|
+
export const Config = Context.GenericTag("Config");
|
|
8
|
+
export const defaultConfig = {
|
|
7
9
|
reloadUrl: "/",
|
|
8
10
|
syncUrl: "https://evolu.world",
|
|
9
11
|
name: "Evolu",
|
|
10
12
|
maxDrift: 5 * 60 * 1000,
|
|
13
|
+
minimumLogLevel: "none",
|
|
11
14
|
};
|
|
12
|
-
|
|
15
|
+
/** https://effect.website/docs/guides/runtime */
|
|
16
|
+
export const createRuntime = (partialConfig) => {
|
|
17
|
+
const config = { ...defaultConfig, ...partialConfig };
|
|
18
|
+
const ConfigLive = Layer.succeed(Config, config);
|
|
19
|
+
const minimumLogLevel = Match.value(config.minimumLogLevel).pipe(Match.when("debug", () => LogLevel.Debug), Match.when("none", () => LogLevel.None), Match.when("trace", () => LogLevel.Trace), Match.when("warning", () => LogLevel.Warning), Match.exhaustive);
|
|
20
|
+
const evoluLayer = config.minimumLogLevel === "none"
|
|
21
|
+
? ConfigLive
|
|
22
|
+
: Layer.mergeAll(ConfigLive, Logger.minimumLogLevel(minimumLogLevel), Logger.replace(Logger.defaultLogger, makeEvoluLogger(config.name)));
|
|
23
|
+
return ManagedRuntime.make(evoluLayer);
|
|
24
|
+
};
|
|
25
|
+
// TODO: Spans and Effect native variadic log args.
|
|
26
|
+
const makeEvoluLogger = (name) => Logger.make(({ logLevel, message, date }) => {
|
|
27
|
+
const fn = logLevel._tag === "Warning"
|
|
28
|
+
? "warn"
|
|
29
|
+
: logLevel._tag === "Error"
|
|
30
|
+
? "error"
|
|
31
|
+
: "log";
|
|
32
|
+
const hours = date.getHours().toString().padStart(2, "0");
|
|
33
|
+
const minutes = date.getMinutes().toString().padStart(2, "0");
|
|
34
|
+
const seconds = date.getSeconds().toString().padStart(2, "0");
|
|
35
|
+
const milliseconds = date.getMilliseconds().toString().padStart(3, "0");
|
|
36
|
+
const formattedDate = `${hours}:${minutes}:${seconds}:${milliseconds}`;
|
|
37
|
+
const messages = Array.isArray(message) ? message : [message];
|
|
38
|
+
globalThis.console[fn](`${formattedDate} [${name}]`, ...messages);
|
|
39
|
+
});
|
package/dist/src/Crdt.d.ts
CHANGED
|
@@ -34,11 +34,12 @@ export declare const unsafeTimestampFromString: (s: TimestampString) => Timestam
|
|
|
34
34
|
export declare const timestampToHash: (t: Timestamp) => TimestampHash;
|
|
35
35
|
export declare const makeSyncTimestamp: (millis?: Millis) => Timestamp;
|
|
36
36
|
export declare const makeInitialTimestamp: Effect.Effect<Timestamp, never, NanoIdGenerator>;
|
|
37
|
-
|
|
37
|
+
declare const Time_base: Context.TagClass<Time, "Time", {
|
|
38
38
|
readonly now: Effect.Effect<Millis, TimestampTimeOutOfRangeError>;
|
|
39
|
+
}>;
|
|
40
|
+
export declare class Time extends Time_base {
|
|
41
|
+
static Live: Layer.Layer<Time, never, never>;
|
|
39
42
|
}
|
|
40
|
-
export declare const Time: Context.Tag<Time, Time>;
|
|
41
|
-
export declare const TimeLive: Layer.Layer<Time, never, never>;
|
|
42
43
|
/**
|
|
43
44
|
* The TimestampError type represents all Timestamp-related errors. If such an
|
|
44
45
|
* error happens, the device clock is skewed and should be set to the current
|
|
@@ -80,7 +81,7 @@ export declare const initialMerkleTree: MerkleTree;
|
|
|
80
81
|
type MerkleTreeKey = keyof Omit<MerkleTree, "hash">;
|
|
81
82
|
type MerkleTreePath = ReadonlyArray<MerkleTreeKey>;
|
|
82
83
|
export declare const millisToMerkleTreePath: (millis: Millis) => MerkleTreePath;
|
|
83
|
-
export declare const insertIntoMerkleTree: (
|
|
84
|
+
export declare const insertIntoMerkleTree: (tree: MerkleTree, timestamp: Timestamp) => MerkleTree;
|
|
84
85
|
export declare const diffMerkleTrees: (tree1: MerkleTree, tree2: MerkleTree) => Option.Option<Millis>;
|
|
85
86
|
export declare const merkleTreeToString: (m: MerkleTree) => MerkleTreeString;
|
|
86
87
|
export declare const unsafeMerkleTreeFromString: (m: MerkleTreeString) => MerkleTree;
|
package/dist/src/Crdt.d.ts.map
CHAN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Q,CAAC,MAAM,EAAE,SAAS,CAAC;CAC5B,KAAG,OAAO,MAAM,CACf,SAAS,EACP,mBAAmB,GACnB,6BAA6B,GAC7B,2BAA2B,GAC3B,4BAA4B,EAC9B,IAAI,GAAG,MAAM,CAmBX,CAAC;AAEL;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC;CAC3B;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;AAExE,eAAO,MAAM,iBAAiB,YAAoC,CAAC;AAEnE,KAAK,aAAa,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAEpD,KAAK,cAAc,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAEnD,eAAO,MAAM,sBAAsB,WAAY,MAAM,mBAGrB,CAAC;AA8BjC,eAAO,MAAM,oBAAoB,SACzB,UAAU,aACL,SAAS,KACnB,UAQF,CAAC;AAOF,eAAO,MAAM,eAAe,UACnB,UAAU,SACV,UAAU,KAChB,OAAO,MAAM,CAAC,MAAM,CAqDtB,CAAC;AAEF,eAAO,MAAM,kBAAkB,MAAO,UAAU,KAAG,gBACZ,CAAC;AAExC,eAAO,MAAM,0BAA0B,MAAO,gBAAgB,KAAG,UACpC,CAAC"}
|
package/dist/src/Crdt.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as S from "@effect/schema/Schema";
|
|
2
|
+
import * as Arr from "effect/Array";
|
|
2
3
|
import * as Context from "effect/Context";
|
|
3
4
|
import * as Effect from "effect/Effect";
|
|
4
5
|
import * as Either from "effect/Either";
|
|
@@ -6,7 +7,6 @@ import { pipe } from "effect/Function";
|
|
|
6
7
|
import * as Layer from "effect/Layer";
|
|
7
8
|
import * as Number from "effect/Number";
|
|
8
9
|
import * as Option from "effect/Option";
|
|
9
|
-
import * as ReadonlyArray from "effect/ReadonlyArray";
|
|
10
10
|
import * as String from "effect/String";
|
|
11
11
|
import { Config } from "./Config.js";
|
|
12
12
|
import { NanoIdGenerator, NodeId } from "./Crypto.js";
|
|
@@ -22,9 +22,9 @@ export const AllowedTimeRange = {
|
|
|
22
22
|
* the device clock is out of range, Evolu will not store data until it's
|
|
23
23
|
* fixed.
|
|
24
24
|
*/
|
|
25
|
-
export const Millis = S.
|
|
25
|
+
export const Millis = S.Number.pipe(S.greaterThan(AllowedTimeRange.greaterThan), S.lessThan(AllowedTimeRange.lessThan), S.brand("Millis"));
|
|
26
26
|
export const initialMillis = S.decodeSync(Millis)(AllowedTimeRange.greaterThan + 1);
|
|
27
|
-
export const Counter = S.
|
|
27
|
+
export const Counter = S.Number.pipe(S.between(0, 65535), S.brand("Counter"));
|
|
28
28
|
const initialCounter = S.decodeSync(Counter)(0);
|
|
29
29
|
export const timestampToString = (t) => [
|
|
30
30
|
new Date(t.millis).toISOString(),
|
|
@@ -46,53 +46,56 @@ export const makeSyncTimestamp = (millis = initialMillis) => ({
|
|
|
46
46
|
counter: initialCounter,
|
|
47
47
|
node: syncNodeId,
|
|
48
48
|
});
|
|
49
|
-
export const makeInitialTimestamp = NanoIdGenerator.pipe(Effect.flatMap(({
|
|
49
|
+
export const makeInitialTimestamp = NanoIdGenerator.pipe(Effect.flatMap(({ nodeId }) => nodeId), Effect.map((node) => ({
|
|
50
50
|
millis: initialMillis,
|
|
51
51
|
counter: initialCounter,
|
|
52
52
|
node,
|
|
53
53
|
})));
|
|
54
|
-
export
|
|
55
|
-
|
|
54
|
+
export class Time extends Context.Tag("Time")() {
|
|
55
|
+
}
|
|
56
|
+
Time.Live = Layer.succeed(Time, {
|
|
56
57
|
now: Effect.suspend(() => S.decode(Millis)(Date.now())).pipe(Effect.catchTag("ParseError", () => Effect.fail({
|
|
57
58
|
_tag: "TimestampTimeOutOfRangeError",
|
|
58
59
|
}))),
|
|
59
|
-
})
|
|
60
|
-
const getNextMillis = (millis) => Effect.gen(function* (
|
|
61
|
-
const time = yield*
|
|
62
|
-
const config = yield*
|
|
63
|
-
const now = yield*
|
|
60
|
+
});
|
|
61
|
+
const getNextMillis = (millis) => Effect.gen(function* () {
|
|
62
|
+
const time = yield* Time;
|
|
63
|
+
const config = yield* Config;
|
|
64
|
+
const now = yield* time.now;
|
|
64
65
|
const next = Math.max(now, ...millis);
|
|
65
66
|
if (next - now > config.maxDrift)
|
|
66
|
-
yield*
|
|
67
|
+
yield* Effect.fail({
|
|
67
68
|
_tag: "TimestampDriftError",
|
|
68
69
|
now,
|
|
69
70
|
next,
|
|
70
|
-
})
|
|
71
|
+
});
|
|
71
72
|
return next;
|
|
72
73
|
});
|
|
73
|
-
const incrementCounter = (counter) => pipe(Number.increment(counter), S.decodeEither(Counter), Either.mapLeft(() => ({
|
|
74
|
+
const incrementCounter = (counter) => pipe(Number.increment(counter), S.decodeEither(Counter), Either.mapLeft(() => ({
|
|
75
|
+
_tag: "TimestampCounterOverflowError",
|
|
76
|
+
})));
|
|
74
77
|
const counterMin = S.decodeSync(Counter)(0);
|
|
75
|
-
export const sendTimestamp = (timestamp) => Effect.gen(function* (
|
|
76
|
-
const millis = yield*
|
|
78
|
+
export const sendTimestamp = (timestamp) => Effect.gen(function* () {
|
|
79
|
+
const millis = yield* getNextMillis([timestamp.millis]);
|
|
77
80
|
const counter = millis === timestamp.millis
|
|
78
|
-
? yield*
|
|
81
|
+
? yield* incrementCounter(timestamp.counter)
|
|
79
82
|
: counterMin;
|
|
80
83
|
return { ...timestamp, millis, counter };
|
|
81
84
|
});
|
|
82
85
|
export const receiveTimestamp = ({ local, remote, }) => Effect.gen(function* (_) {
|
|
83
86
|
if (local.node === remote.node)
|
|
84
|
-
yield*
|
|
87
|
+
yield* Effect.fail({
|
|
85
88
|
_tag: "TimestampDuplicateNodeError",
|
|
86
89
|
node: local.node,
|
|
87
|
-
})
|
|
88
|
-
const millis = yield*
|
|
89
|
-
const counter = yield*
|
|
90
|
+
});
|
|
91
|
+
const millis = yield* getNextMillis([local.millis, remote.millis]);
|
|
92
|
+
const counter = yield* millis === local.millis && millis === remote.millis
|
|
90
93
|
? incrementCounter(Math.max(local.counter, remote.counter))
|
|
91
94
|
: millis === local.millis
|
|
92
95
|
? incrementCounter(local.counter)
|
|
93
96
|
: millis === remote.millis
|
|
94
97
|
? incrementCounter(remote.counter)
|
|
95
|
-
: Either.right(counterMin)
|
|
98
|
+
: Either.right(counterMin);
|
|
96
99
|
return { ...local, millis, counter };
|
|
97
100
|
});
|
|
98
101
|
export const initialMerkleTree = Object.create(null);
|
|
@@ -119,7 +122,7 @@ const insertKey = (tree, path, hash) => {
|
|
|
119
122
|
},
|
|
120
123
|
};
|
|
121
124
|
};
|
|
122
|
-
export const insertIntoMerkleTree = (timestamp) =>
|
|
125
|
+
export const insertIntoMerkleTree = (tree, timestamp) => {
|
|
123
126
|
const path = millisToMerkleTreePath(timestamp.millis);
|
|
124
127
|
const hash = timestampToHash(timestamp);
|
|
125
128
|
return insertKey({ ...tree, hash: xorTimestampHashes(tree.hash, hash) }, path, hash);
|
|
@@ -138,7 +141,7 @@ export const diffMerkleTrees = (tree1, tree2) => {
|
|
|
138
141
|
// the top of this function should pass)
|
|
139
142
|
// eslint-disable-next-line no-constant-condition
|
|
140
143
|
while (1) {
|
|
141
|
-
const keys =
|
|
144
|
+
const keys = Arr.dedupeWith(getSortedMerkleTreeKeys(node1).concat(getSortedMerkleTreeKeys(node2)), String.Equivalence);
|
|
142
145
|
let diffKey = null;
|
|
143
146
|
// Traverse down the trie through keys that are different. We
|
|
144
147
|
// traverse down the keys in order. Stop in two cases: either one
|
package/dist/src/Crypto.d.ts
CHANGED
|
@@ -3,15 +3,18 @@ import * as Brand from "effect/Brand";
|
|
|
3
3
|
import * as Context from "effect/Context";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as Layer from "effect/Layer";
|
|
6
|
-
|
|
6
|
+
import { Id } from "./Model.js";
|
|
7
|
+
declare const Bip39_base: Context.TagClass<Bip39, "Bip39", {
|
|
7
8
|
readonly make: Effect.Effect<Mnemonic>;
|
|
8
9
|
readonly toSeed: (mnemonic: Mnemonic) => Effect.Effect<Uint8Array>;
|
|
9
10
|
readonly parse: (mnemonic: string) => Effect.Effect<Mnemonic, InvalidMnemonicError>;
|
|
11
|
+
}>;
|
|
12
|
+
export declare class Bip39 extends Bip39_base {
|
|
10
13
|
}
|
|
11
|
-
export declare const Bip39: Context.Tag<Bip39, Bip39>;
|
|
12
14
|
export interface InvalidMnemonicError {
|
|
13
15
|
readonly _tag: "InvalidMnemonicError";
|
|
14
16
|
}
|
|
17
|
+
export declare const validateMnemonicToEffect: (validateMnemonic: (mnemonic: string, wordlist: string[]) => boolean) => (mnemonic: string, wordlist: string[]) => Effect.Effect<Mnemonic, InvalidMnemonicError, never>;
|
|
15
18
|
/**
|
|
16
19
|
* Mnemonic is a password generated by Evolu in BIP39 format.
|
|
17
20
|
*
|
|
@@ -20,21 +23,24 @@ export interface InvalidMnemonicError {
|
|
|
20
23
|
* provide a human-readable way of storing a private key.
|
|
21
24
|
*/
|
|
22
25
|
export type Mnemonic = string & Brand.Brand<"Mnemonic">;
|
|
23
|
-
|
|
26
|
+
declare const NanoIdGenerator_base: Context.TagClass<NanoIdGenerator, "NanoIdGenerator", {
|
|
24
27
|
readonly nanoid: Effect.Effect<NanoId>;
|
|
25
|
-
readonly
|
|
28
|
+
readonly nodeId: Effect.Effect<NodeId>;
|
|
29
|
+
readonly rowId: Effect.Effect<Id>;
|
|
30
|
+
}>;
|
|
31
|
+
export declare class NanoIdGenerator extends NanoIdGenerator_base {
|
|
26
32
|
}
|
|
27
|
-
export declare const
|
|
33
|
+
export declare const createNanoIdGeneratorLive: (customAlphabet: (alphabet: string, defaultSize?: number | undefined) => (size?: number | undefined) => string, nanoid: (size?: number) => string) => Layer.Layer<NanoIdGenerator, never, never>;
|
|
28
34
|
export type NanoId = string & Brand.Brand<"NanoId">;
|
|
29
35
|
export declare const NodeId: S.brand<S.Schema<string, string, never>, "NodeId">;
|
|
30
36
|
export type NodeId = S.Schema.Type<typeof NodeId>;
|
|
31
|
-
export declare const NanoIdGeneratorLive: Layer.Layer<NanoIdGenerator, never, never>;
|
|
32
37
|
export declare const slip21Derive: (seed: Uint8Array, path: ReadonlyArray<string>) => Effect.Effect<Uint8Array>;
|
|
33
|
-
|
|
34
|
-
export interface SecretBox {
|
|
38
|
+
declare const SecretBox_base: Context.TagClass<SecretBox, "SecretBox", {
|
|
35
39
|
readonly seal: (key: Uint8Array, plaintext: Uint8Array) => Effect.Effect<Uint8Array>;
|
|
36
40
|
readonly open: (key: Uint8Array, ciphertext: Uint8Array) => Effect.Effect<Uint8Array>;
|
|
41
|
+
}>;
|
|
42
|
+
export declare class SecretBox extends SecretBox_base {
|
|
43
|
+
static Live: Layer.Layer<SecretBox, never, never>;
|
|
37
44
|
}
|
|
38
|
-
export
|
|
39
|
-
export declare const SecretBoxLive: Layer.Layer<SecretBox, never, never>;
|
|
45
|
+
export {};
|
|
40
46
|
//# sourceMappingURL=Crypto.d.ts.map
|
package/dist/src/Crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,uBAAuB,CAAC;AAM3C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"AA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AM,KAAK,MAAM,KAChC,MAAM,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,KAAK,CAU3C,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAEpD,eAAO,MAAM,MAAM,oDAGlB,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC,CAAC;AAIlD,eAAO,MAAM,YAAY,SACjB,UAAU,QACV,cAAc,MAAM,CAAC,KAC1B,OAAO,MAAM,CAAC,UAAU,CAWvB,CAAC;;mBAKc,CACb,GAAG,EAAE,UAAU,EACf,SAAS,EAAE,UAAU,KAClB,OAAO,MAAM,CAAC,UAAU,CAAC;mBAEf,CACb,GAAG,EAAE,UAAU,EACf,UAAU,EAAE,UAAU,KACnB,OAAO,MAAM,CAAC,UAAU,CAAC;;AAXlC,qBAAa,SAAU,SAAQ,cAa5B;IACD,MAAM,CAAC,IAAI,uCAgBT;CACH"}
|
package/dist/src/Crypto.js
CHANGED
|
@@ -7,15 +7,27 @@ import { randomBytes } from "@noble/hashes/utils";
|
|
|
7
7
|
import * as Context from "effect/Context";
|
|
8
8
|
import * as Effect from "effect/Effect";
|
|
9
9
|
import * as Layer from "effect/Layer";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
10
|
+
export class Bip39 extends Context.Tag("Bip39")() {
|
|
11
|
+
}
|
|
12
|
+
export const validateMnemonicToEffect = (validateMnemonic) => (mnemonic, wordlist) => {
|
|
13
|
+
const mnemonicTrimmed = mnemonic.trim();
|
|
14
|
+
return validateMnemonic(mnemonicTrimmed, wordlist)
|
|
15
|
+
? Effect.succeed(mnemonicTrimmed)
|
|
16
|
+
: Effect.fail({
|
|
17
|
+
_tag: "InvalidMnemonicError",
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export class NanoIdGenerator extends Context.Tag("NanoIdGenerator")() {
|
|
21
|
+
}
|
|
22
|
+
export const createNanoIdGeneratorLive = (customAlphabet, nanoid) => {
|
|
23
|
+
const nanoidForNodeId = customAlphabet("0123456789abcdef", 16);
|
|
24
|
+
return Layer.succeed(NanoIdGenerator, NanoIdGenerator.of({
|
|
25
|
+
nanoid: Effect.sync(() => nanoid()),
|
|
26
|
+
nodeId: Effect.sync(() => nanoidForNodeId()),
|
|
27
|
+
rowId: Effect.sync(() => nanoid()),
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
export const NodeId = S.String.pipe(S.pattern(/^[\w-]{16}$/), S.brand("NodeId"));
|
|
19
31
|
// SLIP-21 implementation
|
|
20
32
|
// https://github.com/satoshilabs/slips/blob/master/slip-0021.md
|
|
21
33
|
export const slip21Derive = (seed, path) => Effect.sync(() => {
|
|
@@ -29,8 +41,9 @@ export const slip21Derive = (seed, path) => Effect.sync(() => {
|
|
|
29
41
|
}
|
|
30
42
|
return m.slice(32, 64);
|
|
31
43
|
});
|
|
32
|
-
export
|
|
33
|
-
|
|
44
|
+
export class SecretBox extends Context.Tag("SecretBox")() {
|
|
45
|
+
}
|
|
46
|
+
SecretBox.Live = Layer.succeed(SecretBox, SecretBox.of({
|
|
34
47
|
seal: (key, plaintext) => Effect.sync(() => {
|
|
35
48
|
const nonce = randomBytes(24);
|
|
36
49
|
const ciphertext = secretbox(key, nonce).seal(plaintext);
|
package/dist/src/Db.d.ts
CHANGED
|
@@ -2,81 +2,76 @@ import * as S from "@effect/schema/Schema";
|
|
|
2
2
|
import * as Brand from "effect/Brand";
|
|
3
3
|
import * as Context from "effect/Context";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
|
-
import * as
|
|
6
|
-
import * as ReadonlyArray from "effect/ReadonlyArray";
|
|
7
|
-
import * as ReadonlyRecord from "effect/ReadonlyRecord";
|
|
8
|
-
import * as Types from "effect/Types";
|
|
5
|
+
import * as Record from "effect/Record";
|
|
9
6
|
import * as Kysely from "kysely";
|
|
7
|
+
import { Config } from "./Config.js";
|
|
8
|
+
import { Millis, Time, TimestampCounterOverflowError, TimestampDriftError, TimestampTimeOutOfRangeError } from "./Crdt.js";
|
|
10
9
|
import { Bip39, Mnemonic, NanoIdGenerator } from "./Crypto.js";
|
|
11
|
-
import {
|
|
10
|
+
import { QueryPatches } from "./Diff.js";
|
|
11
|
+
import { EvoluError } from "./Error.js";
|
|
12
12
|
import { Id } from "./Model.js";
|
|
13
13
|
import { Owner } from "./Owner.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
readonly
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* });
|
|
38
|
-
* type TodoTable = S.Schema.Type<typeof TodoTable>;
|
|
39
|
-
*/
|
|
40
|
-
export declare const table: <Fields extends TableFields>(fields: Fields) => ValidateFieldsTypes<Fields> extends true ? ValidateFieldsNames<Fields> extends true ? ValidateFieldsHasId<Fields> extends true ? S.Schema<Types.Simplify<S.Struct.Type<Fields> & S.Schema.Type<typeof ReservedColumns>>, Types.Simplify<S.Struct.Encoded<Fields> & S.Schema.Encoded<typeof ReservedColumns>>> : EvoluTypeError<"table() called without id column."> : EvoluTypeError<"table() called with a reserved column. Reserved columns are createdAt, updatedAt, isDeleted. Those columns are added by default."> : EvoluTypeError<"table() called with unsupported type. Supported types are null, string, number, Uint8Array, JSON Object, and JSON Array. Use SqliteDate for dates and SqliteBoolean for booleans.">;
|
|
41
|
-
declare const ReservedColumns: S.struct<{
|
|
42
|
-
createdAt: S.brand<S.Schema<string, string, never>, "SqliteDate">;
|
|
43
|
-
updatedAt: S.brand<S.Schema<string, string, never>, "SqliteDate">;
|
|
44
|
-
isDeleted: S.brand<S.Schema<number, number, never>, "SqliteBoolean">;
|
|
14
|
+
import { SyncLock } from "./Platform.js";
|
|
15
|
+
import { Sqlite, SqliteExecResult, SqliteFactory, SqliteQuery, Value } from "./Sqlite.js";
|
|
16
|
+
import { NewMessage, SyncFactory, SyncState } from "./Sync.js";
|
|
17
|
+
export interface Db {
|
|
18
|
+
readonly init: (schema: DbSchema, initialData: ReadonlyArray<Mutation>, onError: Callbacks["onError"], onSyncStateChange: Callbacks["onSyncStateChange"], onReceive: Callbacks["onReceive"]) => Effect.Effect<Owner, NotSupportedPlatformError | TimestampTimeOutOfRangeError | TimestampDriftError | TimestampCounterOverflowError, Config>;
|
|
19
|
+
readonly loadQueries: (queries: ReadonlyArray<Query>) => Effect.Effect<ReadonlyArray<QueryPatches>>;
|
|
20
|
+
readonly mutate: (mutations: ReadonlyArray<Mutation>, queriesToRefresh: ReadonlyArray<Query>) => Effect.Effect<ReadonlyArray<QueryPatches>, TimestampTimeOutOfRangeError | TimestampDriftError | TimestampCounterOverflowError, Config>;
|
|
21
|
+
readonly resetOwner: () => Effect.Effect<void>;
|
|
22
|
+
readonly restoreOwner: (schema: DbSchema, mnemonic: Mnemonic) => Effect.Effect<void>;
|
|
23
|
+
readonly ensureSchema: (schema: DbSchema) => Effect.Effect<void>;
|
|
24
|
+
readonly sync: (queriesToRefresh: ReadonlyArray<Query>) => Effect.Effect<ReadonlyArray<QueryPatches>, never, Config>;
|
|
25
|
+
}
|
|
26
|
+
export interface DbSchema {
|
|
27
|
+
readonly tables: ReadonlyArray<Table>;
|
|
28
|
+
readonly indexes: ReadonlyArray<Index>;
|
|
29
|
+
}
|
|
30
|
+
export interface Table {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly columns: ReadonlyArray<string>;
|
|
33
|
+
}
|
|
34
|
+
export declare const Index: S.Struct<{
|
|
35
|
+
name: S.$String;
|
|
36
|
+
sql: S.$String;
|
|
45
37
|
}>;
|
|
46
|
-
type
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @example
|
|
57
|
-
* const Database = database({
|
|
58
|
-
* // A local-only table.
|
|
59
|
-
* _todo: TodoTable,
|
|
60
|
-
* todo: TodoTable,
|
|
61
|
-
* todoCategory: TodoCategoryTable,
|
|
62
|
-
* });
|
|
63
|
-
* type Database = S.Schema.Type<typeof Database>;
|
|
64
|
-
*/
|
|
65
|
-
export declare const database: typeof S.struct;
|
|
38
|
+
export type Index = S.Schema.Type<typeof Index>;
|
|
39
|
+
export interface Mutation {
|
|
40
|
+
readonly table: string;
|
|
41
|
+
readonly id: Id;
|
|
42
|
+
readonly values: Record.ReadonlyRecord<string, Value | Date | boolean | undefined>;
|
|
43
|
+
readonly isInsert: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface NotSupportedPlatformError {
|
|
46
|
+
readonly _tag: "NotSupportedPlatformError";
|
|
47
|
+
}
|
|
66
48
|
declare const __queryBrand: unique symbol;
|
|
67
49
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
50
|
+
* Query is SQL query serialized as a string with a branded type representing a
|
|
51
|
+
* row it returns.
|
|
70
52
|
*/
|
|
71
53
|
export type Query<R extends Row = Row> = string & Brand.Brand<"Query"> & {
|
|
72
54
|
readonly [__queryBrand]: R;
|
|
73
55
|
};
|
|
74
|
-
export type Queries<R extends Row = Row> = ReadonlyArray<Query<R>>;
|
|
75
|
-
export declare const serializeQuery: <R extends Row>({ sql, parameters, options, }: SqliteQuery) => Query<R>;
|
|
76
|
-
export declare const deserializeQuery: <R extends Row>(query: Query<R>) => SqliteQuery;
|
|
77
56
|
export type Row = {
|
|
78
57
|
[key: string]: Value | Row | ReadonlyArray<Row>;
|
|
79
58
|
};
|
|
59
|
+
declare const DbFactory_base: Context.TagClass<DbFactory, "DbFactory", {
|
|
60
|
+
readonly createDb: Effect.Effect<Db>;
|
|
61
|
+
}>;
|
|
62
|
+
export declare class DbFactory extends DbFactory_base {
|
|
63
|
+
}
|
|
64
|
+
export declare const createDb: Effect.Effect<Db, never, SqliteFactory | Bip39 | NanoIdGenerator | Time | SyncFactory | SyncLock>;
|
|
65
|
+
export interface Callbacks {
|
|
66
|
+
readonly onError: (error: EvoluError) => void;
|
|
67
|
+
readonly onSyncStateChange: (state: SyncState) => void;
|
|
68
|
+
readonly onReceive: () => void;
|
|
69
|
+
}
|
|
70
|
+
export declare const Callbacks: Context.Tag<Callbacks, Callbacks>;
|
|
71
|
+
export type QueryRowsMap = ReadonlyMap<Query, ReadonlyArray<Row>>;
|
|
72
|
+
export declare const upsertValueIntoTableRowColumn: (message: NewMessage, messages: ReadonlyArray<NewMessage>, millis: Millis) => Effect.Effect<SqliteExecResult, never, Sqlite>;
|
|
73
|
+
export declare const serializeQuery: <R extends Row>({ sql, parameters, options, }: SqliteQuery) => Query<R>;
|
|
74
|
+
export declare const deserializeQuery: <R extends Row>(query: Query<R>) => SqliteQuery;
|
|
80
75
|
/**
|
|
81
76
|
* Extract {@link Row} from {@link Query} instance.
|
|
82
77
|
*
|
|
@@ -98,6 +93,7 @@ export interface QueryResult<R extends Row = Row> {
|
|
|
98
93
|
*/
|
|
99
94
|
readonly row: Readonly<Kysely.Simplify<R>> | null;
|
|
100
95
|
}
|
|
96
|
+
export type Queries<R extends Row = Row> = ReadonlyArray<Query<R>>;
|
|
101
97
|
export type QueryResultsFromQueries<Q extends Queries> = {
|
|
102
98
|
[P in keyof Q]: Q[P] extends Query<infer R> ? QueryResult<R> : never;
|
|
103
99
|
};
|
|
@@ -105,22 +101,6 @@ export type QueryResultsPromisesFromQueries<Q extends Queries> = {
|
|
|
105
101
|
[P in keyof Q]: Q[P] extends Query<infer R> ? Promise<QueryResult<R>> : never;
|
|
106
102
|
};
|
|
107
103
|
export declare const queryResultFromRows: <R extends Row>(rows: ReadonlyArray<R>) => QueryResult<R>;
|
|
108
|
-
export declare const
|
|
109
|
-
export declare const transaction: <R, E, A>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Sqlite | R>;
|
|
110
|
-
export interface NoSuchTableOrColumnError {
|
|
111
|
-
readonly _tag: "NoSuchTableOrColumnError";
|
|
112
|
-
}
|
|
113
|
-
export declare const SqliteNoSuchTableOrColumnError: S.struct<{
|
|
114
|
-
message: S.union<[S.Schema<string, string, never>, S.Schema<string, string, never>, S.Schema<string, string, never>]>;
|
|
115
|
-
}>;
|
|
116
|
-
export type SqliteNoSuchTableOrColumnError = S.Schema.Type<typeof SqliteNoSuchTableOrColumnError>;
|
|
117
|
-
export declare const someDefectToNoSuchTableOrColumnError: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, NoSuchTableOrColumnError | E, R>;
|
|
118
|
-
export declare const lazyInit: (mnemonic?: Mnemonic) => Effect.Effect<Owner, never, Sqlite | Bip39 | NanoIdGenerator>;
|
|
119
|
-
export declare const ensureSchema: (schema: SqliteSchema) => Effect.Effect<void, never, Sqlite>;
|
|
120
|
-
export declare const dropAllTables: Effect.Effect<void, never, Sqlite>;
|
|
121
|
-
export type RowsStore = Store<RowsStoreValue>;
|
|
122
|
-
export declare const RowsStore: Context.Tag<RowsStore, RowsStore>;
|
|
123
|
-
type RowsStoreValue = ReadonlyMap<Query, ReadonlyArray<Row>>;
|
|
124
|
-
export declare const RowsStoreLive: Layer.Layer<RowsStore, never, never>;
|
|
104
|
+
export declare const notSupportedPlatformWorker: Db;
|
|
125
105
|
export {};
|
|
126
106
|
//# sourceMappingURL=Db.d.ts.map
|