@evolu/common 3.1.2 → 3.1.3
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/Config.d.ts +1 -1
- package/dist/src/Config.d.ts.map +1 -1
- package/dist/src/Config.js +1 -1
- package/dist/src/Crdt.d.ts +7 -7
- package/dist/src/Crdt.d.ts.map +1 -1
- package/dist/src/Crdt.js +1 -1
- package/dist/src/Crypto.d.ts +11 -11
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +3 -3
- package/dist/src/Db.d.ts +20 -20
- package/dist/src/Db.d.ts.map +1 -1
- package/dist/src/Db.js +1 -1
- package/dist/src/DbWorker.d.ts +2 -2
- package/dist/src/DbWorker.d.ts.map +1 -1
- package/dist/src/DbWorker.js +3 -3
- package/dist/src/ErrorStore.d.ts +2 -2
- package/dist/src/ErrorStore.d.ts.map +1 -1
- package/dist/src/Evolu.d.ts +5 -5
- package/dist/src/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu.js +6 -6
- package/dist/src/Model.d.ts +8 -8
- package/dist/src/OnCompletes.d.ts +3 -3
- package/dist/src/OnCompletes.d.ts.map +1 -1
- package/dist/src/OnCompletes.js +1 -1
- package/dist/src/Owner.d.ts +1 -1
- package/dist/src/Owner.d.ts.map +1 -1
- package/dist/src/Owner.js +1 -1
- package/dist/src/Platform.d.ts +5 -5
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +5 -5
- package/dist/src/Sqlite.d.ts +1 -1
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +1 -1
- package/dist/src/Store.d.ts +2 -2
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/SyncWorker.d.ts +1 -1
- package/dist/src/SyncWorker.d.ts.map +1 -1
- package/dist/src/SyncWorker.js +3 -3
- package/package.json +6 -6
- package/src/Config.ts +2 -4
- package/src/Crdt.ts +8 -8
- package/src/Crypto.ts +11 -13
- package/src/Db.ts +17 -18
- package/src/DbWorker.ts +24 -22
- package/src/ErrorStore.ts +1 -1
- package/src/Evolu.ts +14 -10
- package/src/Model.ts +1 -1
- package/src/OnCompletes.ts +5 -5
- package/src/Owner.ts +2 -2
- package/src/Platform.ts +11 -9
- package/src/Sqlite.ts +2 -4
- package/src/Store.ts +2 -4
- package/src/SyncWorker.ts +12 -8
package/src/Evolu.ts
CHANGED
|
@@ -297,7 +297,7 @@ export interface Evolu<S extends DatabaseSchema = DatabaseSchema> {
|
|
|
297
297
|
* database.
|
|
298
298
|
*/
|
|
299
299
|
readonly ensureSchema: <From, To extends S>(
|
|
300
|
-
schema: S.Schema<
|
|
300
|
+
schema: S.Schema<To, From>,
|
|
301
301
|
) => void;
|
|
302
302
|
|
|
303
303
|
/**
|
|
@@ -310,7 +310,7 @@ export interface Evolu<S extends DatabaseSchema = DatabaseSchema> {
|
|
|
310
310
|
readonly sync: () => void;
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
export const Evolu = Context.
|
|
313
|
+
export const Evolu = Context.GenericTag<Evolu>("@services/Evolu");
|
|
314
314
|
|
|
315
315
|
type CreateQuery<S extends DatabaseSchema> = <R extends Row>(
|
|
316
316
|
queryCallback: QueryCallback<S, R>,
|
|
@@ -374,7 +374,9 @@ export interface LoadingPromises {
|
|
|
374
374
|
readonly release: () => void;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
-
export const LoadingPromises = Context.
|
|
377
|
+
export const LoadingPromises = Context.GenericTag<LoadingPromises>(
|
|
378
|
+
"@services/LoadingPromises",
|
|
379
|
+
);
|
|
378
380
|
|
|
379
381
|
export type LoadingPromise<R extends Row> = Promise<QueryResult<R>> & {
|
|
380
382
|
status?: "pending" | "fulfilled" | "rejected";
|
|
@@ -452,7 +454,7 @@ const setPromiseAsResolved =
|
|
|
452
454
|
|
|
453
455
|
type LoadQuery = <R extends Row>(query: Query<R>) => Promise<QueryResult<R>>;
|
|
454
456
|
|
|
455
|
-
const LoadQuery = Context.
|
|
457
|
+
const LoadQuery = Context.GenericTag<LoadQuery>("@services/LoadQuery");
|
|
456
458
|
|
|
457
459
|
const LoadQueryLive = Layer.effect(
|
|
458
460
|
LoadQuery,
|
|
@@ -478,9 +480,9 @@ const LoadQueryLive = Layer.effect(
|
|
|
478
480
|
|
|
479
481
|
type OnQuery = (
|
|
480
482
|
dbWorkerOutputOnQuery: DbWorkerOutputOnQuery,
|
|
481
|
-
) => Effect.Effect<
|
|
483
|
+
) => Effect.Effect<void>;
|
|
482
484
|
|
|
483
|
-
const OnQuery = Context.
|
|
485
|
+
const OnQuery = Context.GenericTag<OnQuery>("@services/OnQuery");
|
|
484
486
|
|
|
485
487
|
const OnQueryLive = Layer.effect(
|
|
486
488
|
OnQuery,
|
|
@@ -528,7 +530,9 @@ export interface SubscribedQueries {
|
|
|
528
530
|
readonly getSubscribedQueries: () => Queries;
|
|
529
531
|
}
|
|
530
532
|
|
|
531
|
-
export const SubscribedQueries = Context.
|
|
533
|
+
export const SubscribedQueries = Context.GenericTag<SubscribedQueries>(
|
|
534
|
+
"@services/SubscribedQueries",
|
|
535
|
+
);
|
|
532
536
|
|
|
533
537
|
export const SubscribedQueriesLive = Layer.effect(
|
|
534
538
|
SubscribedQueries,
|
|
@@ -604,7 +608,7 @@ export type Mutate<
|
|
|
604
608
|
readonly id: S[K]["id"];
|
|
605
609
|
};
|
|
606
610
|
|
|
607
|
-
export const Mutate = Context.
|
|
611
|
+
export const Mutate = Context.GenericTag<Mutate>("@services/Mutate");
|
|
608
612
|
|
|
609
613
|
// https://stackoverflow.com/a/54713648/233902
|
|
610
614
|
type PartialForNullable<
|
|
@@ -782,9 +786,9 @@ export const EvoluCommonLive = EvoluCommon.pipe(
|
|
|
782
786
|
);
|
|
783
787
|
|
|
784
788
|
export const makeCreateEvolu =
|
|
785
|
-
(EvoluLive: Layer.Layer<
|
|
789
|
+
(EvoluLive: Layer.Layer<Evolu, never, Config>) =>
|
|
786
790
|
<From, To extends DatabaseSchema>(
|
|
787
|
-
schema: S.Schema<
|
|
791
|
+
schema: S.Schema<To, From>,
|
|
788
792
|
config?: Partial<Config>,
|
|
789
793
|
): Evolu<To> => {
|
|
790
794
|
// For https://nextjs.org/docs/architecture/fast-refresh etc.
|
package/src/Model.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type Id = S.Schema.To<typeof Id>;
|
|
|
21
21
|
*/
|
|
22
22
|
export const id = <T extends string>(
|
|
23
23
|
table: T,
|
|
24
|
-
): S.BrandSchema<
|
|
24
|
+
): S.BrandSchema<string & Brand.Brand<"Id"> & Brand.Brand<T>, string, never> =>
|
|
25
25
|
Id.pipe(S.brand(table));
|
|
26
26
|
|
|
27
27
|
/**
|
package/src/OnCompletes.ts
CHANGED
|
@@ -7,20 +7,20 @@ import * as ReadonlyArray from "effect/ReadonlyArray";
|
|
|
7
7
|
import { NanoId } from "./Crypto.js";
|
|
8
8
|
|
|
9
9
|
export interface OnCompletes {
|
|
10
|
-
readonly add: (
|
|
11
|
-
onComplete: OnComplete,
|
|
12
|
-
) => Effect.Effect<never, never, OnCompleteId>;
|
|
10
|
+
readonly add: (onComplete: OnComplete) => Effect.Effect<OnCompleteId>;
|
|
13
11
|
|
|
14
12
|
readonly complete: (
|
|
15
13
|
onCompleteIds: readonly OnCompleteId[],
|
|
16
|
-
) => Effect.Effect<
|
|
14
|
+
) => Effect.Effect<void>;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export type OnComplete = () => void;
|
|
20
18
|
|
|
21
19
|
export type OnCompleteId = string & Brand.Brand<"OnCompleteId">;
|
|
22
20
|
|
|
23
|
-
export const OnCompletes = Context.
|
|
21
|
+
export const OnCompletes = Context.GenericTag<OnCompletes>(
|
|
22
|
+
"@services/OnCompletes",
|
|
23
|
+
);
|
|
24
24
|
|
|
25
25
|
export const OnCompletesLive = Layer.effect(
|
|
26
26
|
OnCompletes,
|
package/src/Owner.ts
CHANGED
|
@@ -28,7 +28,7 @@ export interface Owner {
|
|
|
28
28
|
readonly encryptionKey: Uint8Array;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export const Owner = Context.
|
|
31
|
+
export const Owner = Context.GenericTag<Owner>("@services/Owner");
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* The unique identifier of {@link Owner} safely derived from its
|
|
@@ -38,7 +38,7 @@ export type OwnerId = Id & Brand.Brand<"Owner">;
|
|
|
38
38
|
|
|
39
39
|
export const makeOwner = (
|
|
40
40
|
mnemonic?: Mnemonic,
|
|
41
|
-
): Effect.Effect<
|
|
41
|
+
): Effect.Effect<Owner, never, Bip39> =>
|
|
42
42
|
Effect.gen(function* (_) {
|
|
43
43
|
const bip39 = yield* _(Bip39);
|
|
44
44
|
|
package/src/Platform.ts
CHANGED
|
@@ -8,31 +8,33 @@ export type PlatformName =
|
|
|
8
8
|
| "web-without-opfs"
|
|
9
9
|
| "react-native";
|
|
10
10
|
|
|
11
|
-
export const PlatformName = Context.
|
|
11
|
+
export const PlatformName = Context.GenericTag<PlatformName>(
|
|
12
|
+
"@services/PlatformName",
|
|
13
|
+
);
|
|
12
14
|
|
|
13
15
|
export type FlushSync = (callback: () => void) => void;
|
|
14
16
|
|
|
15
|
-
export const FlushSync = Context.
|
|
17
|
+
export const FlushSync = Context.GenericTag<FlushSync>("@services/FlushSync");
|
|
16
18
|
|
|
17
19
|
export interface SyncLock {
|
|
18
20
|
/**
|
|
19
21
|
* Try to acquire a sync lock. The caller must not call sync if a sync lock
|
|
20
22
|
* can't be acquired.
|
|
21
23
|
*/
|
|
22
|
-
readonly acquire: Effect.Effect<
|
|
24
|
+
readonly acquire: Effect.Effect<boolean>;
|
|
23
25
|
|
|
24
26
|
/** Release a sync lock. */
|
|
25
|
-
readonly release: Effect.Effect<
|
|
27
|
+
readonly release: Effect.Effect<void>;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
export const SyncLock = Context.
|
|
30
|
+
export const SyncLock = Context.GenericTag<SyncLock>("@services/SyncLock");
|
|
29
31
|
|
|
30
32
|
export type Fetch = (
|
|
31
33
|
url: string,
|
|
32
34
|
body: Uint8Array,
|
|
33
|
-
) => Effect.Effect<
|
|
35
|
+
) => Effect.Effect<Response, FetchError>;
|
|
34
36
|
|
|
35
|
-
export const Fetch = Context.
|
|
37
|
+
export const Fetch = Context.GenericTag<Fetch>("@services/Fetch");
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* This error occurs when there is a problem with the network connection, or the
|
|
@@ -66,10 +68,10 @@ interface AppStateConfig {
|
|
|
66
68
|
|
|
67
69
|
export interface AppState {
|
|
68
70
|
readonly init: (config: AppStateConfig) => void;
|
|
69
|
-
readonly reset: Effect.Effect<
|
|
71
|
+
readonly reset: Effect.Effect<void>;
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
export const AppState = Context.
|
|
74
|
+
export const AppState = Context.GenericTag<AppState>("@services/AppState");
|
|
73
75
|
|
|
74
76
|
/** To detect whether DOM can be used. */
|
|
75
77
|
export const canUseDom = ((): boolean => {
|
package/src/Sqlite.ts
CHANGED
|
@@ -4,12 +4,10 @@ import * as Predicate from "effect/Predicate";
|
|
|
4
4
|
import * as ReadonlyRecord from "effect/ReadonlyRecord";
|
|
5
5
|
|
|
6
6
|
export interface Sqlite {
|
|
7
|
-
readonly exec: (
|
|
8
|
-
arg: string | SqliteQuery,
|
|
9
|
-
) => Effect.Effect<never, never, ExecResult>;
|
|
7
|
+
readonly exec: (arg: string | SqliteQuery) => Effect.Effect<ExecResult>;
|
|
10
8
|
}
|
|
11
9
|
|
|
12
|
-
export const Sqlite = Context.
|
|
10
|
+
export const Sqlite = Context.GenericTag<Sqlite>("@services/Sqlite");
|
|
13
11
|
|
|
14
12
|
export interface SqliteQuery {
|
|
15
13
|
readonly sql: string;
|
package/src/Store.ts
CHANGED
|
@@ -10,12 +10,10 @@ export interface Store<T> {
|
|
|
10
10
|
readonly getState: () => T;
|
|
11
11
|
|
|
12
12
|
// Effect API because it's a side-effect.
|
|
13
|
-
readonly setState: (state: T) => Effect.Effect<
|
|
13
|
+
readonly setState: (state: T) => Effect.Effect<void>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const makeStore = <T>(
|
|
17
|
-
initialState: T,
|
|
18
|
-
): Effect.Effect<never, never, Store<T>> =>
|
|
16
|
+
export const makeStore = <T>(initialState: T): Effect.Effect<Store<T>> =>
|
|
19
17
|
Effect.sync(() => {
|
|
20
18
|
const listeners = new Set<Listener>();
|
|
21
19
|
let currentState = initialState;
|
package/src/SyncWorker.ts
CHANGED
|
@@ -37,11 +37,15 @@ export interface SyncWorker {
|
|
|
37
37
|
onMessage: (output: SyncWorkerOutput) => void;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export const SyncWorker = Context.
|
|
40
|
+
export const SyncWorker = Context.GenericTag<SyncWorker>(
|
|
41
|
+
"@services/SyncWorker",
|
|
42
|
+
);
|
|
41
43
|
|
|
42
44
|
export type SyncWorkerPostMessage = SyncWorker["postMessage"];
|
|
43
45
|
|
|
44
|
-
export const SyncWorkerPostMessage = Context.
|
|
46
|
+
export const SyncWorkerPostMessage = Context.GenericTag<SyncWorkerPostMessage>(
|
|
47
|
+
"@services/SyncWorkerPostMessage",
|
|
48
|
+
);
|
|
45
49
|
|
|
46
50
|
export type SyncWorkerInput =
|
|
47
51
|
| SyncWorkerInputSync
|
|
@@ -83,7 +87,9 @@ interface SyncWorkerInputSyncCompleted {
|
|
|
83
87
|
|
|
84
88
|
type SyncWorkerOnMessage = SyncWorker["onMessage"];
|
|
85
89
|
|
|
86
|
-
const SyncWorkerOnMessage = Context.
|
|
90
|
+
const SyncWorkerOnMessage = Context.GenericTag<SyncWorkerOnMessage>(
|
|
91
|
+
"@services/SyncWorkerOnMessage",
|
|
92
|
+
);
|
|
87
93
|
|
|
88
94
|
export type SyncWorkerOutput =
|
|
89
95
|
| UnexpectedError
|
|
@@ -226,9 +232,9 @@ const binaryReadOptions = {
|
|
|
226
232
|
const sync = (
|
|
227
233
|
input: SyncWorkerInputSync,
|
|
228
234
|
): Effect.Effect<
|
|
229
|
-
|
|
235
|
+
void,
|
|
230
236
|
never,
|
|
231
|
-
|
|
237
|
+
SyncLock | SyncWorkerOnMessage | Fetch | SecretBox
|
|
232
238
|
> =>
|
|
233
239
|
Effect.gen(function* (_) {
|
|
234
240
|
const syncLock = yield* _(SyncLock);
|
|
@@ -324,9 +330,7 @@ export const SyncWorkerLive = Layer.effect(
|
|
|
324
330
|
Effect.gen(function* (_) {
|
|
325
331
|
const syncLock = yield* _(SyncLock);
|
|
326
332
|
|
|
327
|
-
const onError = (
|
|
328
|
-
error: UnexpectedError,
|
|
329
|
-
): Effect.Effect<never, never, void> =>
|
|
333
|
+
const onError = (error: UnexpectedError): Effect.Effect<void> =>
|
|
330
334
|
Effect.sync(() => {
|
|
331
335
|
syncWorker.onMessage(error);
|
|
332
336
|
});
|