@evolu/common 6.0.1-preview.2 → 6.0.1-preview.21
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 +159 -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 +209 -124
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +118 -104
- 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 +256 -211
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +558 -359
- 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 +72 -4
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +124 -13
- 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 +68 -13
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +414 -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 +176 -51
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +30 -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 +474 -327
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +502 -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 +528 -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 +282 -227
- package/src/Evolu/Platform.ts +9 -9
- package/src/Evolu/Protocol.ts +788 -640
- 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 +238 -18
- package/src/Evolu/Schema.ts +391 -191
- package/src/Evolu/Storage.ts +275 -55
- package/src/Evolu/Sync.ts +708 -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 +183 -53
- package/src/Sqlite.ts +59 -23
- package/src/Task.ts +779 -0
- package/src/Time.ts +168 -4
- package/src/Type.ts +708 -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,81 @@
|
|
|
1
|
-
import { ConsoleConfig } from "../Console.js";
|
|
1
|
+
import { ConsoleConfig, ConsoleDep } from "../Console.js";
|
|
2
|
+
import { TimingSafeEqualDep } from "../Crypto.js";
|
|
3
|
+
import { LazyValue } from "../Function.js";
|
|
2
4
|
import { Result } from "../Result.js";
|
|
3
5
|
import { SqliteError } from "../Sqlite.js";
|
|
4
6
|
import { SimpleName } from "../Type.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
+
import { OwnerId } from "./Owner.js";
|
|
8
|
+
import { ProtocolInvalidDataError } from "./Protocol.js";
|
|
9
|
+
import { CreateSqliteStorageBaseOptions, SqliteStorageDeps, Storage } from "./Storage.js";
|
|
7
10
|
export interface Relay extends Disposable {
|
|
8
11
|
}
|
|
9
12
|
export interface RelayConfig extends ConsoleConfig {
|
|
13
|
+
/**
|
|
14
|
+
* The relay name.
|
|
15
|
+
*
|
|
16
|
+
* Implementations can use this for identification purposes (e.g., database
|
|
17
|
+
* file name, logging).
|
|
18
|
+
*/
|
|
10
19
|
readonly name?: SimpleName;
|
|
20
|
+
/**
|
|
21
|
+
* Optional callback to authenticate an {@link OwnerId} with the relay.
|
|
22
|
+
*
|
|
23
|
+
* If this callback is not provided, all owners are allowed.
|
|
24
|
+
*
|
|
25
|
+
* If provided, the callback receives the OwnerId and should return a promise
|
|
26
|
+
* that resolves to `true` to allow access, or `false` to deny.
|
|
27
|
+
*
|
|
28
|
+
* The callback returns a boolean rather than an error type because error
|
|
29
|
+
* handling and logging are the responsibility of the callback implementation,
|
|
30
|
+
* not the relay. This prevents leaking authentication implementation details
|
|
31
|
+
* into the generic relay interface.
|
|
32
|
+
*
|
|
33
|
+
* OwnerId is used for authentication rather than short-lived tokens because
|
|
34
|
+
* this only controls relay access, not write permissions. Since all data is
|
|
35
|
+
* encrypted on the relay, OwnerId exposure is safe.
|
|
36
|
+
*
|
|
37
|
+
* Owners specify which relays to connect to via {@link TransportConfig}. In
|
|
38
|
+
* WebSocket-based implementations, this check occurs before accepting the
|
|
39
|
+
* connection, with the OwnerId typically extracted from the URL path (e.g.,
|
|
40
|
+
* `ws://localhost:4000/<ownerId>`).
|
|
41
|
+
*
|
|
42
|
+
* ### Example
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* const relay = await createNodeJsRelay(deps)({
|
|
46
|
+
* authenticateOwner: async (ownerId) => {
|
|
47
|
+
* const isRegistered = await db.checkOwner(ownerId);
|
|
48
|
+
* if (!isRegistered) {
|
|
49
|
+
* logger.warn("Unauthorized access attempt", { ownerId });
|
|
50
|
+
* }
|
|
51
|
+
* return isRegistered;
|
|
52
|
+
* },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
readonly authenticateOwner?: (ownerId: OwnerId) => Promise<boolean>;
|
|
11
57
|
}
|
|
12
|
-
export declare const
|
|
58
|
+
export declare const createRelaySqliteStorage: (deps: SqliteStorageDeps & TimingSafeEqualDep) => (options: CreateSqliteStorageBaseOptions) => Result<Storage, SqliteError>;
|
|
59
|
+
export interface RelayLogger {
|
|
60
|
+
readonly started: (enableLogging: boolean, port: number) => void;
|
|
61
|
+
readonly storageError: (error: unknown) => void;
|
|
62
|
+
readonly upgradeSocketError: (error: Error) => void;
|
|
63
|
+
readonly invalidOrMissingOwnerIdInUrl: (url: string | undefined) => void;
|
|
64
|
+
readonly unauthorizedOwner: (ownerId: OwnerId) => void;
|
|
65
|
+
readonly authenticateOwnerError: (error: unknown) => void;
|
|
66
|
+
readonly connectionEstablished: (totalConnectionCount: number) => void;
|
|
67
|
+
readonly connectionWebSocketError: (error: Error) => void;
|
|
68
|
+
readonly relayOptionSubscribe: (ownerId: OwnerId, getSubscriberCount: LazyValue<number>) => void;
|
|
69
|
+
readonly relayOptionUnsubscribe: (ownerId: OwnerId, getSubscriberCount: LazyValue<number>) => void;
|
|
70
|
+
readonly relayOptionBroadcast: (ownerId: OwnerId, broadcastCount: number, subscriberCount: number) => void;
|
|
71
|
+
readonly messageLength: (messageLength: number) => void;
|
|
72
|
+
readonly applyProtocolMessageAsRelayError: (error: ProtocolInvalidDataError) => void;
|
|
73
|
+
readonly responseLength: (responseLength: number) => void;
|
|
74
|
+
readonly applyProtocolMessageAsRelayUnknownError: (error: unknown) => void;
|
|
75
|
+
readonly connectionClosed: (totalConnectionCount: number) => void;
|
|
76
|
+
readonly shuttingDown: () => void;
|
|
77
|
+
readonly webSocketServerDisposed: () => void;
|
|
78
|
+
readonly httpServerDisposed: () => void;
|
|
79
|
+
}
|
|
80
|
+
export declare const createRelayLogger: (deps: ConsoleDep) => RelayLogger;
|
|
13
81
|
//# 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,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YAAY,EAAE,MAAM,IAAI,CAAC;IAClC,QAAQ,CAAC,uBAAuB,EAAE,MAAM,IAAI,CAAC;IAC7C,QAAQ,CAAC,kBAAkB,EAAE,MAAM,IAAI,CAAC;CACzC;AAED,eAAO,MAAM,iBAAiB,GAAI,MAAM,UAAU,KAAG,WA8FnD,CAAC"}
|
package/dist/src/Evolu/Relay.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
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 {
|
|
7
|
-
export const
|
|
5
|
+
import { timestampToTimestampBytes } from "./Timestamp.js";
|
|
6
|
+
export const createRelaySqliteStorage = (deps) => (options) => {
|
|
8
7
|
const sqliteStorageBase = createSqliteStorageBase(deps)(options);
|
|
9
8
|
if (!sqliteStorageBase.ok)
|
|
10
9
|
return sqliteStorageBase;
|
|
@@ -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);
|
|
67
|
+
},
|
|
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;
|
|
68
80
|
},
|
|
69
|
-
|
|
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,102 @@ 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
|
};
|
|
148
|
+
export const createRelayLogger = (deps) => ({
|
|
149
|
+
started: (enableLogging, port) => {
|
|
150
|
+
deps.console.enabled = true;
|
|
151
|
+
deps.console.log(`Evolu Relay started on port ${port}`);
|
|
152
|
+
deps.console.enabled = enableLogging;
|
|
153
|
+
},
|
|
154
|
+
storageError: (error) => {
|
|
155
|
+
deps.console.error("[relay]", "storage", error);
|
|
156
|
+
},
|
|
157
|
+
upgradeSocketError: (error) => {
|
|
158
|
+
deps.console.warn("[relay]", "socket error", { error });
|
|
159
|
+
},
|
|
160
|
+
invalidOrMissingOwnerIdInUrl: (url) => {
|
|
161
|
+
deps.console.warn("[relay]", "invalid or missing ownerId in URL", { url });
|
|
162
|
+
},
|
|
163
|
+
unauthorizedOwner: (ownerId) => {
|
|
164
|
+
deps.console.warn("[relay]", "unauthorized owner", { ownerId });
|
|
165
|
+
},
|
|
166
|
+
authenticateOwnerError: (error) => {
|
|
167
|
+
deps.console.error("[relay]", "authenticateOwner error", error);
|
|
168
|
+
},
|
|
169
|
+
connectionEstablished: (totalConnectionCount) => {
|
|
170
|
+
deps.console.log("[relay]", "connection", { totalConnectionCount });
|
|
171
|
+
},
|
|
172
|
+
connectionWebSocketError: (error) => {
|
|
173
|
+
deps.console.error("[relay]", "error", { error });
|
|
174
|
+
},
|
|
175
|
+
relayOptionSubscribe: (ownerId, getSubscriberCount) => {
|
|
176
|
+
if (deps.console.enabled)
|
|
177
|
+
deps.console.log("[relay]", "subscribe", {
|
|
178
|
+
ownerId,
|
|
179
|
+
subscriberCount: getSubscriberCount(),
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
relayOptionUnsubscribe: (ownerId, getSubscriberCount) => {
|
|
183
|
+
if (deps.console.enabled)
|
|
184
|
+
deps.console.log("[relay]", "unsubscribe", {
|
|
185
|
+
ownerId,
|
|
186
|
+
subscriberCount: getSubscriberCount(),
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
relayOptionBroadcast: (ownerId, broadcastCount, totalSubscribers) => {
|
|
190
|
+
deps.console.log("[relay]", "broadcast", {
|
|
191
|
+
ownerId,
|
|
192
|
+
broadcastCount,
|
|
193
|
+
totalSubscribers,
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
messageLength: (messageLength) => {
|
|
197
|
+
deps.console.log("[relay]", "on message", { messageLength });
|
|
198
|
+
},
|
|
199
|
+
applyProtocolMessageAsRelayError: (error) => {
|
|
200
|
+
deps.console.error("[relay]", "applyProtocolMessageAsRelay", error);
|
|
201
|
+
},
|
|
202
|
+
responseLength: (responseLength) => {
|
|
203
|
+
deps.console.log("[relay]", "responseLength", { responseLength });
|
|
204
|
+
},
|
|
205
|
+
applyProtocolMessageAsRelayUnknownError: (error) => {
|
|
206
|
+
deps.console.error("[relay]", "applyProtocolMessageAsRelayUnknownError", error);
|
|
207
|
+
},
|
|
208
|
+
connectionClosed: (totalConnectionCount) => {
|
|
209
|
+
deps.console.log("[relay]", "close", { totalConnectionCount });
|
|
210
|
+
},
|
|
211
|
+
shuttingDown: () => {
|
|
212
|
+
deps.console.log("Shutting down Evolu Relay...");
|
|
213
|
+
},
|
|
214
|
+
webSocketServerDisposed: () => {
|
|
215
|
+
deps.console.log("Evolu Relay WebSocketServer disposed");
|
|
216
|
+
},
|
|
217
|
+
httpServerDisposed: () => {
|
|
218
|
+
deps.console.log("Evolu Relay HTTP server disposed");
|
|
219
|
+
},
|
|
220
|
+
});
|