@evolu/common 6.0.1-preview.20 → 6.0.1-preview.22
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/Evolu/Db.d.ts +23 -1
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.d.ts +21 -25
- package/dist/src/Evolu/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.js +15 -135
- package/dist/src/Evolu/Owner.d.ts +60 -0
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +33 -0
- package/dist/src/Evolu/Protocol.d.ts +91 -30
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +80 -25
- package/dist/src/Evolu/Relay.d.ts +70 -3
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +74 -1
- package/dist/src/Evolu/Sync.d.ts +2 -11
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +7 -46
- package/dist/src/Result.d.ts +45 -16
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +23 -0
- package/dist/src/Task.js +1 -1
- package/dist/src/Type.d.ts +12 -0
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +12 -0
- package/package.json +1 -1
- package/src/Evolu/Db.ts +24 -1
- package/src/Evolu/Evolu.ts +21 -259
- package/src/Evolu/Owner.ts +70 -1
- package/src/Evolu/Protocol.ts +117 -36
- package/src/Evolu/Relay.ts +180 -6
- package/src/Evolu/Sync.ts +7 -57
- package/src/Result.ts +47 -16
- package/src/Task.ts +3 -3
- package/src/Type.ts +12 -0
package/dist/src/Evolu/Db.d.ts
CHANGED
|
@@ -38,6 +38,13 @@ export interface DbConfig extends ConsoleConfig, TimestampConfig {
|
|
|
38
38
|
* Transport configuration for data sync and backup. Supports single transport
|
|
39
39
|
* or multiple transports simultaneously for redundancy.
|
|
40
40
|
*
|
|
41
|
+
* **Redundancy:** The ideal setup uses at least two completely independent
|
|
42
|
+
* relays - for example, a home relay and a geographically separate relay.
|
|
43
|
+
* Data is sent to both relays simultaneously, providing true redundancy
|
|
44
|
+
* similar to using two independent clouds. This eliminates vendor lock-in and
|
|
45
|
+
* ensures your app continues working regardless of circumstances - whether
|
|
46
|
+
* home relay hardware is stolen or a remote relay provider shuts down.
|
|
47
|
+
*
|
|
41
48
|
* Currently supports:
|
|
42
49
|
*
|
|
43
50
|
* - WebSocket: Real-time bidirectional communication with relay servers
|
|
@@ -46,6 +53,11 @@ export interface DbConfig extends ConsoleConfig, TimestampConfig {
|
|
|
46
53
|
* added and removed for any owner (including {@link AppOwner}) via
|
|
47
54
|
* {@link Evolu#useOwner}.
|
|
48
55
|
*
|
|
56
|
+
* Use {@link createWebSocketTransportConfig} to create WebSocket transport
|
|
57
|
+
* configurations with proper URL formatting and {@link OwnerId} inclusion. The
|
|
58
|
+
* {@link OwnerId} in the URL enables relay authentication, allowing relay
|
|
59
|
+
* servers to control access (e.g., for paid tiers or private instances).
|
|
60
|
+
*
|
|
49
61
|
* The default value is:
|
|
50
62
|
*
|
|
51
63
|
* `{ type: "WebSocket", url: "wss://free.evoluhq.com" }`.
|
|
@@ -63,8 +75,18 @@ export interface DbConfig extends ConsoleConfig, TimestampConfig {
|
|
|
63
75
|
* { type: "WebSocket", url: "wss://relay3.example.com" },
|
|
64
76
|
* ];
|
|
65
77
|
*
|
|
66
|
-
* // Local-only instance (no sync) - useful for device settings
|
|
78
|
+
* // Local-only instance (no sync) - useful for device settings or when relay
|
|
79
|
+
* // URL will be provided later (e.g., after authentication), allowing users
|
|
80
|
+
* // to work offline before the app connects
|
|
67
81
|
* transports: [];
|
|
82
|
+
*
|
|
83
|
+
* // Using createWebSocketTransportConfig helper for relay authentication
|
|
84
|
+
* transports: [
|
|
85
|
+
* createWebSocketTransportConfig({
|
|
86
|
+
* relayUrl: "ws://localhost:4000",
|
|
87
|
+
* ownerId,
|
|
88
|
+
* }),
|
|
89
|
+
* ];
|
|
68
90
|
* ```
|
|
69
91
|
*/
|
|
70
92
|
readonly transports: ReadonlyArray<TransportConfig>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Db.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAEL,aAAa,EACb,cAAc,EACd,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAEL,qBAAqB,EAIrB,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAGL,MAAM,EACP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAe,YAAY,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"Db.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAEL,aAAa,EACb,cAAc,EACd,2BAA2B,EAC5B,MAAM,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AI,EAAE,UAAU,CAAC;CAC3B,CAAC;AAEN,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAC3C,qBAAqB,GACrB,kBAAkB,GAClB,cAAc,GACd,SAAS,GACT,OAAO,CAAC;AAgBV,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CACzD;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED,eAAO,MAAM,yBAAyB,GACpC,cAAc,oBAAoB,KACjC,QAKsD,CAAC"}
|
|
@@ -92,13 +92,9 @@ export interface Evolu<S extends EvoluSchema = EvoluSchema> {
|
|
|
92
92
|
* reason why loading should fail. All data are local, and the query is typed.
|
|
93
93
|
* Unexpected errors are handled with {@link Evolu#subscribeError}.
|
|
94
94
|
*
|
|
95
|
-
* Loading is batched, and returned promises are cached
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* return a new pending promise. Subscribed queries remain in the cache to
|
|
99
|
-
* prevent unnecessary Suspense boundaries from activating. Their promises are
|
|
100
|
-
* replaced with `Promise.resolve(rows)`, allowing React to synchronously
|
|
101
|
-
* unwrap the updated data without suspending.
|
|
95
|
+
* Loading is batched, and returned promises are cached until resolved to
|
|
96
|
+
* prevent redundant database queries and to support React Suspense (which
|
|
97
|
+
* requires stable promise references while pending).
|
|
102
98
|
*
|
|
103
99
|
* To subscribe a query for automatic updates, use
|
|
104
100
|
* {@link Evolu#subscribeQuery}.
|
|
@@ -154,6 +150,9 @@ export interface Evolu<S extends EvoluSchema = EvoluSchema> {
|
|
|
154
150
|
/**
|
|
155
151
|
* Promise that resolves to {@link AppOwner} when available.
|
|
156
152
|
*
|
|
153
|
+
* Note: With web-only deps, this promise will not resolve during SSR because
|
|
154
|
+
* there is no AppOwner on the server.
|
|
155
|
+
*
|
|
157
156
|
* ### Example
|
|
158
157
|
*
|
|
159
158
|
* ```ts
|
|
@@ -367,24 +366,9 @@ export interface Evolu<S extends EvoluSchema = EvoluSchema> {
|
|
|
367
366
|
export type EvoluError = ProtocolError | ProtocolUnsupportedVersionError | SqliteError | SymmetricCryptoDecryptError | TimestampError | TransferableError;
|
|
368
367
|
export type EvoluDeps = ConsoleDep & CreateDbWorkerDep & LocalAuthDep & Partial<FlushSyncDep> & RandomBytesDep & ReloadAppDep & TimeDep;
|
|
369
368
|
/**
|
|
370
|
-
* Creates an {@link Evolu} instance configured with the specified
|
|
371
|
-
* {@link EvoluSchema} and optional
|
|
372
|
-
*
|
|
373
|
-
* This function returns a configured Evolu instance, providing a typed
|
|
374
|
-
* interface for querying, mutating, and syncing your application's data. The
|
|
375
|
-
* returned instance includes:
|
|
376
|
-
*
|
|
377
|
-
* - Subscription methods for receiving updates on queries, the owner, errors, and
|
|
378
|
-
* sync state.
|
|
379
|
-
* - Methods for creating, updating, or deleting rows in a type-safe manner.
|
|
380
|
-
* - Methods for querying data using Evolu's typed SQL queries, leveraging Kysely
|
|
381
|
-
* under the hood.
|
|
382
|
-
* - Built-in support for local-first and offline-first data with automatic sync
|
|
383
|
-
* and merging.
|
|
384
|
-
* - Automatic schema evolution that updates the underlying database with new
|
|
385
|
-
* columns or tables.
|
|
386
|
-
* - Managing owner data with {@link Evolu#resetAppOwner} and
|
|
387
|
-
* {@link Evolu#restoreAppOwner}.
|
|
369
|
+
* Creates an {@link Evolu} instance for a platform configured with the specified
|
|
370
|
+
* {@link EvoluSchema} and optional {@link EvoluConfig} providing a typed
|
|
371
|
+
* interface for querying, mutating, and syncing your application's data.
|
|
388
372
|
*
|
|
389
373
|
* ### Example
|
|
390
374
|
*
|
|
@@ -413,6 +397,18 @@ export type EvoluDeps = ConsoleDep & CreateDbWorkerDep & LocalAuthDep & Partial<
|
|
|
413
397
|
*
|
|
414
398
|
* const evolu = createEvolu(evoluReactDeps)(Schema);
|
|
415
399
|
* ```
|
|
400
|
+
*
|
|
401
|
+
* ### Instance Caching
|
|
402
|
+
*
|
|
403
|
+
* Evolu caches instances by {@link EvoluConfig} name to enable hot reloading and
|
|
404
|
+
* multitenancy. Multiple calls to `createEvolu` with the same name return the
|
|
405
|
+
* same instance, preserving database connections and state across module
|
|
406
|
+
* reloads during development. This ensures a seamless developer experience
|
|
407
|
+
* where edits don't interrupt ongoing sync or lose in-memory state.
|
|
408
|
+
*
|
|
409
|
+
* For testing, either dispose of instances after each test (TODO: implement
|
|
410
|
+
* dispose method) or use unique instance names to ensure proper isolation
|
|
411
|
+
* between test cases.
|
|
416
412
|
*/
|
|
417
413
|
export declare const createEvolu: (deps: EvoluDeps) => <S extends EvoluSchema>(schema: ValidateSchema<S> extends never ? S : ValidateSchema<S>, config?: EvoluConfig) => Evolu<S>;
|
|
418
414
|
export declare const createQuery: <R extends Row>(queryCallback: Parameters<CreateQuery<EvoluSchema>>[0], options?: Parameters<CreateQuery<EvoluSchema>>[1]) => Query<R>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Evolu.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Evolu.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,EAA0B,WAAW,EAAe,MAAM,cAAc,CAAC;AAChF,OAAO,EAAe,cAAc,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAML,QAAQ,EAIT,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAmB,MAAM,SAAS,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YA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SAAS,EAAE,MAAM,IAAI,CAAC;IAE/B,iDAAiD;IACjD,QAAQ,CAAC,cAAc,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;IAEhE;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,MAAM,IAAI,CAAC;CACrD;AAED,iDAAiD;AACjD,MAAM,MAAM,UAAU,GAClB,aAAa,GACb,+BAA+B,GAC/B,WAAW,GACX,2BAA2B,GAC3B,cAAc,GACd,iBAAiB,CAAC;AAWtB,MAAM,MAAM,SAAS,GAAG,UAAU,GAChC,iBAAiB,GACjB,YAAY,GACZ,OAAO,CAAC,YAAY,CAAC,GACrB,cAAc,GACd,YAAY,GACZ,OAAO,CAAC;AAMV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,WAAW,GACrB,MAAM,SAAS,MACf,CAAC,SAAS,WAAW,EACpB,QAAQ,cAAc,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,EAC/D,SAAS,WAAW,KACnB,KAAK,CAAC,CAAC,CAaT,CAAC;AAwaJ,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,GAAG,EACvC,eAAe,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACtD,UAAU,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,KAChD,KAAK,CAAC,CAAC,CAeT,CAAC"}
|
package/dist/src/Evolu/Evolu.js
CHANGED
|
@@ -14,28 +14,12 @@ import { createSubscribedQueries, emptyRows, serializeQuery, } from "./Query.js"
|
|
|
14
14
|
import { evoluSchemaToDbSchema, insertable, kysely, updateable, upsertable, } from "./Schema.js";
|
|
15
15
|
import { DbChange } from "./Storage.js";
|
|
16
16
|
import { initialSyncState } from "./Sync.js";
|
|
17
|
-
// For hot reloading and Evolu multitenancy.
|
|
18
17
|
const evoluInstances = new Map();
|
|
19
18
|
let tabId = null;
|
|
20
19
|
/**
|
|
21
|
-
* Creates an {@link Evolu} instance configured with the specified
|
|
22
|
-
* {@link EvoluSchema} and optional
|
|
23
|
-
*
|
|
24
|
-
* This function returns a configured Evolu instance, providing a typed
|
|
25
|
-
* interface for querying, mutating, and syncing your application's data. The
|
|
26
|
-
* returned instance includes:
|
|
27
|
-
*
|
|
28
|
-
* - Subscription methods for receiving updates on queries, the owner, errors, and
|
|
29
|
-
* sync state.
|
|
30
|
-
* - Methods for creating, updating, or deleting rows in a type-safe manner.
|
|
31
|
-
* - Methods for querying data using Evolu's typed SQL queries, leveraging Kysely
|
|
32
|
-
* under the hood.
|
|
33
|
-
* - Built-in support for local-first and offline-first data with automatic sync
|
|
34
|
-
* and merging.
|
|
35
|
-
* - Automatic schema evolution that updates the underlying database with new
|
|
36
|
-
* columns or tables.
|
|
37
|
-
* - Managing owner data with {@link Evolu#resetAppOwner} and
|
|
38
|
-
* {@link Evolu#restoreAppOwner}.
|
|
20
|
+
* Creates an {@link Evolu} instance for a platform configured with the specified
|
|
21
|
+
* {@link EvoluSchema} and optional {@link EvoluConfig} providing a typed
|
|
22
|
+
* interface for querying, mutating, and syncing your application's data.
|
|
39
23
|
*
|
|
40
24
|
* ### Example
|
|
41
25
|
*
|
|
@@ -64,6 +48,18 @@ let tabId = null;
|
|
|
64
48
|
*
|
|
65
49
|
* const evolu = createEvolu(evoluReactDeps)(Schema);
|
|
66
50
|
* ```
|
|
51
|
+
*
|
|
52
|
+
* ### Instance Caching
|
|
53
|
+
*
|
|
54
|
+
* Evolu caches instances by {@link EvoluConfig} name to enable hot reloading and
|
|
55
|
+
* multitenancy. Multiple calls to `createEvolu` with the same name return the
|
|
56
|
+
* same instance, preserving database connections and state across module
|
|
57
|
+
* reloads during development. This ensures a seamless developer experience
|
|
58
|
+
* where edits don't interrupt ongoing sync or lose in-memory state.
|
|
59
|
+
*
|
|
60
|
+
* For testing, either dispose of instances after each test (TODO: implement
|
|
61
|
+
* dispose method) or use unique instance names to ensure proper isolation
|
|
62
|
+
* between test cases.
|
|
67
63
|
*/
|
|
68
64
|
export const createEvolu = (deps) => (schema, config) => {
|
|
69
65
|
const name = config?.name ?? defaultDbConfig.name;
|
|
@@ -102,39 +98,6 @@ const createEvoluInstance = (deps) => (schema, config) => {
|
|
|
102
98
|
tabId ??= createId(deps);
|
|
103
99
|
return tabId;
|
|
104
100
|
};
|
|
105
|
-
// const createLocalOnly = (
|
|
106
|
-
// localMutations: Array<MutationChange>,
|
|
107
|
-
// defaultOwnerId: OwnerId | undefined,
|
|
108
|
-
// ): LocalOnly<EvoluSchema> => ({
|
|
109
|
-
// insert: (table, values) => {
|
|
110
|
-
// const id = createId(deps);
|
|
111
|
-
// localMutations.push({
|
|
112
|
-
// table,
|
|
113
|
-
// id,
|
|
114
|
-
// values,
|
|
115
|
-
// ownerId: defaultOwnerId,
|
|
116
|
-
// });
|
|
117
|
-
// return id;
|
|
118
|
-
// },
|
|
119
|
-
// update: (table, values) => {
|
|
120
|
-
// const { id, ...rest } = values;
|
|
121
|
-
// localMutations.push({
|
|
122
|
-
// table,
|
|
123
|
-
// id: id as Id,
|
|
124
|
-
// values: rest,
|
|
125
|
-
// ownerId: defaultOwnerId,
|
|
126
|
-
// });
|
|
127
|
-
// },
|
|
128
|
-
// upsert: (table, values) => {
|
|
129
|
-
// const { id, ...rest } = values as Record<string, unknown> & { id: Id };
|
|
130
|
-
// localMutations.push({
|
|
131
|
-
// table,
|
|
132
|
-
// id: id,
|
|
133
|
-
// values: rest as MutationChange["values"],
|
|
134
|
-
// ownerId: defaultOwnerId,
|
|
135
|
-
// });
|
|
136
|
-
// },
|
|
137
|
-
// });
|
|
138
101
|
// Worker responses are delivered to all tabs. Each case must handle this
|
|
139
102
|
// properly (e.g., AppOwner promise resolves only once, tabId filtering).
|
|
140
103
|
dbWorker.onMessage((message) => {
|
|
@@ -197,66 +160,6 @@ const createEvoluInstance = (deps) => (schema, config) => {
|
|
|
197
160
|
}
|
|
198
161
|
break;
|
|
199
162
|
}
|
|
200
|
-
// case "processNewMessages": {
|
|
201
|
-
// void requestIdleTask(
|
|
202
|
-
// toTask(async () => {
|
|
203
|
-
// const approved: Array<Timestamp> = [];
|
|
204
|
-
// const invalidChanges: Array<DbChange> = [];
|
|
205
|
-
// const rejectedChanges: Array<DbChange> = [];
|
|
206
|
-
// const localMutations: Array<MutationChange> = [];
|
|
207
|
-
// for (const crdtMessage of message.messages) {
|
|
208
|
-
// let isApproved = true;
|
|
209
|
-
// let isValid = true;
|
|
210
|
-
// const table = crdtMessage.change.table;
|
|
211
|
-
// if (table in schema) {
|
|
212
|
-
// const { createdAt, ...values } = crdtMessage.change.values;
|
|
213
|
-
// isValid =
|
|
214
|
-
// (createdAt ? DateIso.is(createdAt) : true) &&
|
|
215
|
-
// getMutationType(table, "update").is({
|
|
216
|
-
// id: crdtMessage.change.id,
|
|
217
|
-
// ...values,
|
|
218
|
-
// });
|
|
219
|
-
// } else {
|
|
220
|
-
// isValid = false;
|
|
221
|
-
// }
|
|
222
|
-
// if (!isValid) {
|
|
223
|
-
// isApproved = false;
|
|
224
|
-
// invalidChanges.push(crdtMessage.change);
|
|
225
|
-
// } else if (onMessage) {
|
|
226
|
-
// // At this point, we've validated that the message conforms to the
|
|
227
|
-
// // schema, so the typed callback can safely process it.
|
|
228
|
-
// isApproved = await onMessage(crdtMessage.change, {
|
|
229
|
-
// ownerId: message.ownerId,
|
|
230
|
-
// localOnly: createLocalOnly(localMutations, message.ownerId),
|
|
231
|
-
// });
|
|
232
|
-
// if (!isApproved) {
|
|
233
|
-
// rejectedChanges.push(crdtMessage.change);
|
|
234
|
-
// }
|
|
235
|
-
// }
|
|
236
|
-
// if (isApproved) {
|
|
237
|
-
// approved.push(crdtMessage.timestamp);
|
|
238
|
-
// }
|
|
239
|
-
// }
|
|
240
|
-
// // Report OnMessageError if there were any invalid or rejected changes
|
|
241
|
-
// if (invalidChanges.length > 0 || rejectedChanges.length > 0) {
|
|
242
|
-
// const onMessageError: OnMessageError = {
|
|
243
|
-
// type: "OnMessageError",
|
|
244
|
-
// invalidChanges,
|
|
245
|
-
// rejectedChanges,
|
|
246
|
-
// };
|
|
247
|
-
// errorStore.set(onMessageError);
|
|
248
|
-
// }
|
|
249
|
-
// dbWorker.postMessage({
|
|
250
|
-
// type: "onProcessNewMessages",
|
|
251
|
-
// onCompleteId: message.onCompleteId,
|
|
252
|
-
// approved,
|
|
253
|
-
// localMutations,
|
|
254
|
-
// });
|
|
255
|
-
// return ok();
|
|
256
|
-
// }),
|
|
257
|
-
// )();
|
|
258
|
-
// break;
|
|
259
|
-
// }
|
|
260
163
|
case "onExport": {
|
|
261
164
|
exportRegistry.execute(message.onCompleteId, message.file);
|
|
262
165
|
break;
|
|
@@ -339,29 +242,6 @@ const createEvoluInstance = (deps) => (schema, config) => {
|
|
|
339
242
|
loadingPromises.releaseUnsubscribedOnMutation();
|
|
340
243
|
if (!isNonEmptyArray(changes))
|
|
341
244
|
return;
|
|
342
|
-
// if (onMessage) {
|
|
343
|
-
// const rejectedChanges: Array<DbChange> = [];
|
|
344
|
-
// const localMutations: Array<MutationChange> = [];
|
|
345
|
-
// for (const change of changes) {
|
|
346
|
-
// const localOnly = createLocalOnly(localMutations, change.ownerId);
|
|
347
|
-
// const isApproved = await onMessage(change, {
|
|
348
|
-
// ownerId: change.ownerId,
|
|
349
|
-
// localOnly,
|
|
350
|
-
// });
|
|
351
|
-
// if (!isApproved) {
|
|
352
|
-
// rejectedChanges.push(change);
|
|
353
|
-
// }
|
|
354
|
-
// }
|
|
355
|
-
// if (rejectedChanges.length > 0) {
|
|
356
|
-
// errorStore.set({
|
|
357
|
-
// type: "OnMessageError",
|
|
358
|
-
// invalidChanges: [],
|
|
359
|
-
// rejectedChanges,
|
|
360
|
-
// });
|
|
361
|
-
// return;
|
|
362
|
-
// }
|
|
363
|
-
// changes.push(...localMutations);
|
|
364
|
-
// }
|
|
365
245
|
dbWorker.postMessage({
|
|
366
246
|
type: "mutate",
|
|
367
247
|
tabId: getTabId(),
|
|
@@ -115,11 +115,71 @@ export interface AppOwner extends Owner {
|
|
|
115
115
|
}
|
|
116
116
|
/** Creates an {@link AppOwner} from an {@link OwnerSecret}. */
|
|
117
117
|
export declare const createAppOwner: (secret: OwnerSecret) => AppOwner;
|
|
118
|
+
/**
|
|
119
|
+
* Transport configuration for connecting to relays.
|
|
120
|
+
*
|
|
121
|
+
* Each {@link Owner} can specify one or more transports to connect to different
|
|
122
|
+
* relays for data synchronization. Currently supports WebSocket transport, with
|
|
123
|
+
* future support planned for Bluetooth, LocalNetwork, and other protocols.
|
|
124
|
+
*/
|
|
118
125
|
export type TransportConfig = WebSocketTransportConfig;
|
|
126
|
+
/**
|
|
127
|
+
* WebSocket transport configuration for relay connections.
|
|
128
|
+
*
|
|
129
|
+
* Use {@link createWebSocketTransportConfig} to create a properly formatted URL
|
|
130
|
+
* with {@link OwnerId}. The relay uses {@link parseOwnerIdFromUrl} to extract the
|
|
131
|
+
* OwnerId from the query string.
|
|
132
|
+
*
|
|
133
|
+
* ### Authentication and Error Handling
|
|
134
|
+
*
|
|
135
|
+
* When a relay rejects a connection (invalid OwnerId, unauthorized owner, or
|
|
136
|
+
* server error), the browser WebSocket API does not expose the specific HTTP
|
|
137
|
+
* status code or reason - it only reports a generic connection failure. The
|
|
138
|
+
* client automatically retries with exponential backoff and jitter, eventually
|
|
139
|
+
* succeeding once the configuration or server issue is resolved.
|
|
140
|
+
*
|
|
141
|
+
* Legitimate clients will be properly configured with valid credentials, so
|
|
142
|
+
* automatic retry is appropriate.
|
|
143
|
+
*
|
|
144
|
+
* @see {@link createWebSocketTransportConfig}
|
|
145
|
+
* @see {@link parseOwnerIdFromUrl}
|
|
146
|
+
*/
|
|
119
147
|
export interface WebSocketTransportConfig {
|
|
120
148
|
readonly type: "WebSocket";
|
|
121
149
|
readonly url: string;
|
|
122
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Creates a {@link WebSocketTransportConfig} for the given relay URL and
|
|
153
|
+
* {@link OwnerId}.
|
|
154
|
+
*
|
|
155
|
+
* ### Example
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* const transport = createWebSocketTransportConfig({
|
|
159
|
+
* relayUrl: "wss://relay.evolu.dev",
|
|
160
|
+
* ownerId: owner.id,
|
|
161
|
+
* });
|
|
162
|
+
* // Result: { type: "WebSocket", url: "wss://relay.evolu.dev?ownerId=..." }
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare const createWebSocketTransportConfig: ({ relayUrl, ownerId, }: {
|
|
166
|
+
readonly relayUrl: string;
|
|
167
|
+
readonly ownerId: OwnerId;
|
|
168
|
+
}) => WebSocketTransportConfig;
|
|
169
|
+
/**
|
|
170
|
+
* Extracts {@link OwnerId} from a URL query string.
|
|
171
|
+
*
|
|
172
|
+
* Parses the query string `?ownerId=...` and validates that the extracted value
|
|
173
|
+
* is a valid {@link OwnerId}.
|
|
174
|
+
*
|
|
175
|
+
* ### Example
|
|
176
|
+
*
|
|
177
|
+
* ```ts
|
|
178
|
+
* parseOwnerIdFromUrl("/sync?ownerId=_12345678abcdefgh");
|
|
179
|
+
* // Returns: OwnerId or null
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare const parseOwnerIdFromUrl: (url: string | undefined) => OwnerId | null;
|
|
123
183
|
/**
|
|
124
184
|
* An {@link Owner} for sharding data.
|
|
125
185
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Owner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAEL,aAAa,EAGb,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAML,QAAQ,EACR,cAAc,EACf,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IACvC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CACtD;AAED,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,WAAW,EACnB,aAAa,aAAa,CAAC,eAAe,CAAC,KAC1C,UAMF,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,GAC3B,OAAO,QAAQ,EACf,MAAM,qBAAqB,CAAC,MAAM,GAAG,MAAM,CAAC,EAC5C,aAAa,aAAa,CAAC,eAAe,CAAC,KAC1C,UAQF,CAAC;AAEF,iEAAiE;AACjE,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CACtD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,WAAW,EACnB,aAAa,aAAa,CAAC,eAAe,CAAC,KAC1C,WAMF,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CACtD;AAED,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,GACpC,aAAa,WAAW,KACvB,mBAKD,CAAC"}
|
package/dist/src/Evolu/Owner.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as bip39 from "@scure/bip39";
|
|
|
2
2
|
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
3
3
|
import { createSlip21, EncryptionKey, Entropy16, Entropy32, } from "../Crypto.js";
|
|
4
4
|
import { brand, Id, IdBytes, idBytesToId, idToIdBytes, } from "../Type.js";
|
|
5
|
+
import { getOrNull } from "../Result.js";
|
|
5
6
|
/**
|
|
6
7
|
* 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
|
|
7
8
|
*
|
|
@@ -55,6 +56,38 @@ export const createAppOwner = (secret) => ({
|
|
|
55
56
|
mnemonic: ownerSecretToMnemonic(secret),
|
|
56
57
|
...createOwner(secret),
|
|
57
58
|
});
|
|
59
|
+
/**
|
|
60
|
+
* Creates a {@link WebSocketTransportConfig} for the given relay URL and
|
|
61
|
+
* {@link OwnerId}.
|
|
62
|
+
*
|
|
63
|
+
* ### Example
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* const transport = createWebSocketTransportConfig({
|
|
67
|
+
* relayUrl: "wss://relay.evolu.dev",
|
|
68
|
+
* ownerId: owner.id,
|
|
69
|
+
* });
|
|
70
|
+
* // Result: { type: "WebSocket", url: "wss://relay.evolu.dev?ownerId=..." }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const createWebSocketTransportConfig = ({ relayUrl, ownerId, }) => ({
|
|
74
|
+
type: "WebSocket",
|
|
75
|
+
url: `${relayUrl}?ownerId=${ownerId}`,
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Extracts {@link OwnerId} from a URL query string.
|
|
79
|
+
*
|
|
80
|
+
* Parses the query string `?ownerId=...` and validates that the extracted value
|
|
81
|
+
* is a valid {@link OwnerId}.
|
|
82
|
+
*
|
|
83
|
+
* ### Example
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* parseOwnerIdFromUrl("/sync?ownerId=_12345678abcdefgh");
|
|
87
|
+
* // Returns: OwnerId or null
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export const parseOwnerIdFromUrl = (url) => getOrNull(OwnerId.fromUnknown(url?.split("=")[1]));
|
|
58
91
|
/** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
|
|
59
92
|
export const createShardOwner = (secret, transports) => {
|
|
60
93
|
return {
|