@evolu/common 7.2.0 → 7.2.2

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.
Files changed (88) hide show
  1. package/dist/src/WebSocket.d.ts.map +1 -1
  2. package/dist/src/WebSocket.js +4 -1
  3. package/dist/src/index.d.ts +1 -1
  4. package/dist/src/index.d.ts.map +1 -1
  5. package/dist/src/index.js +1 -1
  6. package/dist/src/local-first/Db.d.ts.map +1 -0
  7. package/dist/src/local-first/Diff.d.ts.map +1 -0
  8. package/dist/src/{Evolu → local-first}/Evolu.d.ts +14 -11
  9. package/dist/src/local-first/Evolu.d.ts.map +1 -0
  10. package/dist/src/local-first/LocalAuth.d.ts.map +1 -0
  11. package/dist/src/{Evolu → local-first}/Owner.d.ts +39 -42
  12. package/dist/src/local-first/Owner.d.ts.map +1 -0
  13. package/dist/src/{Evolu → local-first}/Owner.js +22 -29
  14. package/dist/src/local-first/Platform.d.ts.map +1 -0
  15. package/dist/src/{Evolu → local-first}/Protocol.d.ts +6 -6
  16. package/dist/src/local-first/Protocol.d.ts.map +1 -0
  17. package/dist/src/{Evolu → local-first}/Public.d.ts +3 -2
  18. package/dist/src/local-first/Public.d.ts.map +1 -0
  19. package/dist/src/{Evolu → local-first}/Public.js +2 -2
  20. package/dist/src/local-first/PublicKysely.d.ts.map +1 -0
  21. package/dist/src/local-first/Query.d.ts.map +1 -0
  22. package/dist/src/local-first/Relay.d.ts.map +1 -0
  23. package/dist/src/local-first/Schema.d.ts.map +1 -0
  24. package/dist/src/{Evolu → local-first}/Storage.d.ts +3 -3
  25. package/dist/src/local-first/Storage.d.ts.map +1 -0
  26. package/dist/src/{Evolu → local-first}/Sync.d.ts +9 -14
  27. package/dist/src/local-first/Sync.d.ts.map +1 -0
  28. package/dist/src/{Evolu → local-first}/Sync.js +21 -21
  29. package/dist/src/local-first/Timestamp.d.ts.map +1 -0
  30. package/dist/src/{Evolu/Internal.js → local-first/index.d.ts} +2 -7
  31. package/dist/src/local-first/index.d.ts.map +1 -0
  32. package/dist/src/{Evolu/Internal.d.ts → local-first/index.js} +1 -8
  33. package/package.json +6 -5
  34. package/src/WebSocket.ts +6 -1
  35. package/src/index.ts +1 -1
  36. package/src/{Evolu → local-first}/Evolu.ts +15 -11
  37. package/src/{Evolu → local-first}/Owner.ts +47 -57
  38. package/src/{Evolu → local-first}/Protocol.ts +6 -6
  39. package/src/{Evolu → local-first}/Public.ts +3 -2
  40. package/src/{Evolu → local-first}/Storage.ts +3 -3
  41. package/src/{Evolu → local-first}/Sync.ts +31 -39
  42. package/src/{Evolu/Internal.ts → local-first/index.ts} +1 -7
  43. package/dist/src/Evolu/Db.d.ts.map +0 -1
  44. package/dist/src/Evolu/Diff.d.ts.map +0 -1
  45. package/dist/src/Evolu/Evolu.d.ts.map +0 -1
  46. package/dist/src/Evolu/Internal.d.ts.map +0 -1
  47. package/dist/src/Evolu/LocalAuth.d.ts.map +0 -1
  48. package/dist/src/Evolu/Owner.d.ts.map +0 -1
  49. package/dist/src/Evolu/Platform.d.ts.map +0 -1
  50. package/dist/src/Evolu/Protocol.d.ts.map +0 -1
  51. package/dist/src/Evolu/Public.d.ts.map +0 -1
  52. package/dist/src/Evolu/PublicKysely.d.ts.map +0 -1
  53. package/dist/src/Evolu/Query.d.ts.map +0 -1
  54. package/dist/src/Evolu/Relay.d.ts.map +0 -1
  55. package/dist/src/Evolu/Schema.d.ts.map +0 -1
  56. package/dist/src/Evolu/Storage.d.ts.map +0 -1
  57. package/dist/src/Evolu/Sync.d.ts.map +0 -1
  58. package/dist/src/Evolu/Timestamp.d.ts.map +0 -1
  59. /package/dist/src/{Evolu → local-first}/Db.d.ts +0 -0
  60. /package/dist/src/{Evolu → local-first}/Db.js +0 -0
  61. /package/dist/src/{Evolu → local-first}/Diff.d.ts +0 -0
  62. /package/dist/src/{Evolu → local-first}/Diff.js +0 -0
  63. /package/dist/src/{Evolu → local-first}/Evolu.js +0 -0
  64. /package/dist/src/{Evolu → local-first}/LocalAuth.d.ts +0 -0
  65. /package/dist/src/{Evolu → local-first}/LocalAuth.js +0 -0
  66. /package/dist/src/{Evolu → local-first}/Platform.d.ts +0 -0
  67. /package/dist/src/{Evolu → local-first}/Platform.js +0 -0
  68. /package/dist/src/{Evolu → local-first}/Protocol.js +0 -0
  69. /package/dist/src/{Evolu → local-first}/PublicKysely.d.ts +0 -0
  70. /package/dist/src/{Evolu → local-first}/PublicKysely.js +0 -0
  71. /package/dist/src/{Evolu → local-first}/Query.d.ts +0 -0
  72. /package/dist/src/{Evolu → local-first}/Query.js +0 -0
  73. /package/dist/src/{Evolu → local-first}/Relay.d.ts +0 -0
  74. /package/dist/src/{Evolu → local-first}/Relay.js +0 -0
  75. /package/dist/src/{Evolu → local-first}/Schema.d.ts +0 -0
  76. /package/dist/src/{Evolu → local-first}/Schema.js +0 -0
  77. /package/dist/src/{Evolu → local-first}/Storage.js +0 -0
  78. /package/dist/src/{Evolu → local-first}/Timestamp.d.ts +0 -0
  79. /package/dist/src/{Evolu → local-first}/Timestamp.js +0 -0
  80. /package/src/{Evolu → local-first}/Db.ts +0 -0
  81. /package/src/{Evolu → local-first}/Diff.ts +0 -0
  82. /package/src/{Evolu → local-first}/LocalAuth.ts +0 -0
  83. /package/src/{Evolu → local-first}/Platform.ts +0 -0
  84. /package/src/{Evolu → local-first}/PublicKysely.ts +0 -0
  85. /package/src/{Evolu → local-first}/Query.ts +0 -0
  86. /package/src/{Evolu → local-first}/Relay.ts +0 -0
  87. /package/src/{Evolu → local-first}/Schema.ts +0 -0
  88. /package/src/{Evolu → local-first}/Timestamp.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../../../src/local-first/Storage.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,C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Iso } from "../Type.js";
10
10
  import { CreateWebSocketDep } from "../WebSocket.js";
11
11
  import type { AppOwnerDep, PostMessageDep } from "./Db.js";
12
- import { AppOwner, OwnerEncryptionKey, OwnerId, OwnerIdBytes, OwnerTransport, OwnerWriteKey } from "./Owner.js";
12
+ import { AppOwner, Owner, OwnerIdBytes, OwnerTransport, ReadonlyOwner } from "./Owner.js";
13
13
  import { ProtocolError, ProtocolInvalidDataError, ProtocolTimestampMismatchError } from "./Protocol.js";
14
14
  import { MutationChange } from "./Schema.js";
15
15
  import { BaseSqliteStorage, CrdtMessage, Storage, StorageInsertTimestampStrategy } from "./Storage.js";
@@ -18,9 +18,9 @@ export interface Sync extends Disposable {
18
18
  /**
19
19
  * Assigns or removes an owner to/from transports with reference counting.
20
20
  *
21
- * Owners are only "active" if assigned to at least one transport. Uses
22
- * `owner.transports` or falls back to config transports. Multiple calls
23
- * increment/decrement reference counts (useful for React Hooks).
21
+ * Owners are only synced if assigned to at least one transport. Uses
22
+ * `owner.transports` or falls back to {@link SyncConfig} transports. Multiple
23
+ * calls increment/decrement reference counts (useful for React Hooks).
24
24
  */
25
25
  readonly useOwner: (use: boolean, owner: SyncOwner) => void;
26
26
  readonly applyChanges: (changes: NonEmptyReadonlyArray<MutationChange>) => Result<void, SqliteError | TimestampCounterOverflowError | TimestampDriftError | TimestampTimeOutOfRangeError>;
@@ -29,18 +29,13 @@ export interface SyncDep {
29
29
  readonly sync: Sync;
30
30
  }
31
31
  /**
32
- * Represents an owner for sync operations. This is a unified interface that
33
- * abstracts over the specific owner types ({@link ShardOwner},
34
- * {@link SharedOwner}, {@link SharedReadonlyOwner}) for the sync layer.
32
+ * Represents an owner for sync operations.
35
33
  *
36
- * The sync layer only needs the essential data for synchronization and doesn't
37
- * need to distinguish between different owner types.
34
+ * Includes readonly owner fields plus optional write key (for clients that
35
+ * write) and optional transports to override SyncConfig transports per owner.
38
36
  */
39
- export interface SyncOwner {
40
- readonly id: OwnerId;
41
- readonly encryptionKey: OwnerEncryptionKey;
42
- /** Optional for read-only owners like {@link SharedReadonlyOwner}. */
43
- readonly writeKey?: OwnerWriteKey;
37
+ export interface SyncOwner extends ReadonlyOwner {
38
+ readonly writeKey?: Owner["writeKey"];
44
39
  readonly transports?: ReadonlyArray<OwnerTransport>;
45
40
  }
46
41
  export interface SyncConfig {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sync.d.ts","sourceRoot":"","sources":["../../../src/local-first/Sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,cAAc,EACd,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAA2B,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGzE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAW,MAAM,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAKL,SAAS,EACT,WAAW,EAGZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACL,OAAO,EAKR,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAa,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EACL,QAAQ,EACR,KAAK,EAEL,YAAY,EAGZ,cAAc,EACd,aAAa,EACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAOL,aAAa,EACb,wBAAwB,EACxB,8BAA8B,EAE/B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,WAAW,EAKX,OAAO,EACP,8BAA8B,EAG/B,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,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AW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,GAAG,oBAAoB,CAAC;CACnE;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;CACvC;AAED,eAAO,MAAM,gBAAgB,EAAE,gBAA+C,CAAC"}
@@ -19,7 +19,7 @@ export const createSync = (deps) => (config) => {
19
19
  const getSyncOwner = (ownerId) => {
20
20
  if (isDisposed)
21
21
  return null;
22
- return transports.getConsumer(ownerId);
22
+ return resources.getConsumer(ownerId);
23
23
  };
24
24
  const storageResult = createClientStorage({
25
25
  ...deps,
@@ -28,21 +28,21 @@ export const createSync = (deps) => (config) => {
28
28
  if (!storageResult.ok)
29
29
  return storageResult;
30
30
  const storage = storageResult.value;
31
- const createResource = (transportConfig) => {
32
- const transportKey = createTransportKey(transportConfig);
31
+ const createResource = (transport) => {
32
+ const transportKey = createTransportKey(transport);
33
33
  deps.console.log("[sync]", "createWebSocket", {
34
34
  transportKey,
35
- url: transportConfig.url,
35
+ url: transport.url,
36
36
  });
37
- return deps.createWebSocket(transportConfig.url, {
37
+ return deps.createWebSocket(transport.url, {
38
38
  binaryType: "arraybuffer",
39
39
  onOpen: () => {
40
40
  if (isDisposed)
41
41
  return;
42
- const webSocket = transports.getResource(transportKey);
42
+ const webSocket = resources.getResource(transportKey);
43
43
  if (!webSocket)
44
44
  return;
45
- const ownerIds = transports.getConsumersForResource(transportKey);
45
+ const ownerIds = resources.getConsumersForResource(transportKey);
46
46
  deps.console.log("[sync]", "onOpen", { transportKey, ownerIds });
47
47
  for (const ownerId of ownerIds) {
48
48
  const message = createProtocolMessageForSync({ storage })(ownerId, SubscriptionFlags.Subscribe);
@@ -67,7 +67,7 @@ export const createSync = (deps) => (config) => {
67
67
  // Only handle ArrayBuffer data for sync messages
68
68
  if (isDisposed || !(data instanceof ArrayBuffer))
69
69
  return;
70
- const webSocket = transports.getResource(transportKey);
70
+ const webSocket = resources.getResource(transportKey);
71
71
  if (!webSocket)
72
72
  return;
73
73
  const input = new Uint8Array(data);
@@ -102,7 +102,7 @@ export const createSync = (deps) => (config) => {
102
102
  },
103
103
  });
104
104
  };
105
- const transports = createResources({
105
+ const resources = createResources({
106
106
  createResource,
107
107
  getResourceKey: createTransportKey,
108
108
  getConsumerId: (owner) => owner.id,
@@ -135,15 +135,15 @@ export const createSync = (deps) => (config) => {
135
135
  return;
136
136
  }
137
137
  deps.console.log("[sync]", "useOwner", { use, owner });
138
- const transportsToUse = owner.transports ?? config.transports;
138
+ const transports = owner.transports ?? config.transports;
139
139
  if (use) {
140
- transports.addConsumer(owner, transportsToUse);
140
+ resources.addConsumer(owner, transports);
141
141
  }
142
142
  else {
143
- const result = transports.removeConsumer(owner, transportsToUse);
143
+ const result = resources.removeConsumer(owner, transports);
144
144
  if (!result.ok) {
145
145
  deps.console.warn("[sync]", "Failed to remove consumer", {
146
- transportsToUse,
146
+ transports,
147
147
  ownerId: owner.id,
148
148
  error: result.error,
149
149
  });
@@ -182,11 +182,11 @@ export const createSync = (deps) => (config) => {
182
182
  encryptionKey: owner.encryptionKey,
183
183
  writeKey: owner.writeKey,
184
184
  }, messages);
185
- const transportsToUse = owner.transports ?? config.transports;
185
+ const transports = owner.transports ?? config.transports;
186
186
  // Send message to all transports for this owner
187
- for (const transportConfig of transportsToUse) {
188
- const transportKey = createTransportKey(transportConfig);
189
- const webSocket = transports.getResource(transportKey);
187
+ for (const transport of transports) {
188
+ const transportKey = createTransportKey(transport);
189
+ const webSocket = resources.getResource(transportKey);
190
190
  if (!webSocket)
191
191
  continue;
192
192
  if (webSocket.isOpen()) {
@@ -201,7 +201,7 @@ export const createSync = (deps) => (config) => {
201
201
  if (isDisposed)
202
202
  return;
203
203
  isDisposed = true;
204
- transports[Symbol.dispose]();
204
+ resources[Symbol.dispose]();
205
205
  },
206
206
  };
207
207
  return ok(sync);
@@ -341,9 +341,9 @@ const createClientStorage = (deps) => (config) => {
341
341
  };
342
342
  return ok(storage);
343
343
  };
344
- /** Creates a unique identifier for a transport configuration. */
345
- const createTransportKey = (transportConfig) => {
346
- return `${transportConfig.type}:${transportConfig.url}`;
344
+ /** Creates a unique identifier for a {@link OwnerTransport}. */
345
+ const createTransportKey = (transport) => {
346
+ return `${transport.type}:${transport.url}`;
347
347
  };
348
348
  export const applyLocalOnlyChange = (deps) => (change) => {
349
349
  if (change.isDelete) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Timestamp.d.ts","sourceRoot":"","sources":["../../../src/local-first/Timestamp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,EAAE,KAAK,EAAmB,MAAM,aAAa,CAAC;AACrD,OAAO,EAAW,MAAM,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAEL,OAAO,EACP,SAAS,EAOV,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C;AAED,MAAM,MAAM,cAAc,GACtB,mBAAmB,GACnB,6BAA6B,GAC7B,4BAA4B,CAAC;AAEjC,MAAM,WAAW,mBAAmB;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CAAC;AAExE,eAAO,MAAM,sBAAsB,GAAI,MAAM,cAAc,KAAG,SAG7D,CAAC;AA6BF,eAAO,MAAM,aAAa,GACvB,MAAM,OAAO,GAAG,kBAAkB,MAEjC,WAAW,SAAS,KACnB,MAAM,CACP,SAAS,EACP,mBAAmB,GACnB,6BAA6B,GAC7B,4BAA4B,CAgB/B,CAAC;AAEJ,eAAO,MAAM,gBAAgB,GAC1B,MAAM,OAAO,GAAG,kBAAkB,MAEjC,OAAO,SAAS,EAChB,QAAQ,SAAS,KAChB,MAAM,CACP,SAAS,EACP,mBAAmB,GACnB,6BAA6B,GAC7B,4BAA4B,CAqB/B,CAAC;AAEJ,0DAA0D;AAC1D,eAAO,MAAM,cAAc,2WAAsC,CAAC;AAClE,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAC;AAExD,eAAO,MAAM,oBAAoB,0FAA6B,CAAC;AAE/D,eAAO,MAAM,yBAAyB,GACpC,WAAW,SAAS,KACnB,cA0BF,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,WAAW,cAAc,KACxB,SAoBF,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,cAAc,CAAmB,CAAC;AAE1E,eAAO,MAAM,kBAAkB,GAAI,WAAW,SAAS,KAAG,OAEL,CAAC"}
@@ -1,11 +1,5 @@
1
1
  /**
2
- * Internal Evolu
3
- *
4
- * ### Example
5
- *
6
- * ```ts
7
- * import { createTimestamp } from "@evolu/common/evolu";
8
- * ```
2
+ * Local-first code to be imported from "@evolu/common/local-first"
9
3
  *
10
4
  * @module
11
5
  */
@@ -21,3 +15,4 @@ export * from "./Schema.js";
21
15
  export * from "./Storage.js";
22
16
  export * from "./Sync.js";
23
17
  export * from "./Timestamp.js";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/local-first/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
@@ -1,11 +1,5 @@
1
1
  /**
2
- * Internal Evolu
3
- *
4
- * ### Example
5
- *
6
- * ```ts
7
- * import { createTimestamp } from "@evolu/common/evolu";
8
- * ```
2
+ * Local-first code to be imported from "@evolu/common/local-first"
9
3
  *
10
4
  * @module
11
5
  */
@@ -21,4 +15,3 @@ export * from "./Schema.js";
21
15
  export * from "./Storage.js";
22
16
  export * from "./Sync.js";
23
17
  export * from "./Timestamp.js";
24
- //# sourceMappingURL=Internal.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evolu/common",
3
- "version": "7.2.0",
3
+ "version": "7.2.2",
4
4
  "description": "TypeScript library and local-first platform",
5
5
  "keywords": [
6
6
  "evolu",
@@ -25,14 +25,15 @@
25
25
  "browser": "./dist/src/index.js",
26
26
  "react-native": "./dist/src/index.js"
27
27
  },
28
- "./evolu": {
29
- "import": "./dist/src/Evolu/Internal.js"
28
+ "./local-first": {
29
+ "types": "./dist/src/local-first/index.d.ts",
30
+ "import": "./dist/src/local-first/index.js"
30
31
  }
31
32
  },
32
33
  "typesVersions": {
33
34
  "*": {
34
- "evolu": [
35
- "./dist/src/Evolu/Internal.d.ts"
35
+ "local-first": [
36
+ "./dist/src/local-first/index.d.ts"
36
37
  ]
37
38
  }
38
39
  },
package/src/WebSocket.ts CHANGED
@@ -171,7 +171,12 @@ export const createWebSocket: CreateWebSocket = (
171
171
  socket.onmessage = null;
172
172
  socket.onerror = null;
173
173
 
174
- socket.close();
174
+ if (
175
+ socket.readyState !== socket.CLOSING &&
176
+ socket.readyState !== socket.CLOSED
177
+ ) {
178
+ socket.close();
179
+ }
175
180
  socket = null;
176
181
  };
177
182
 
package/src/index.ts CHANGED
@@ -9,10 +9,10 @@ export * from "./Console.js";
9
9
  export * from "./Crypto.js";
10
10
  export * from "./Eq.js";
11
11
  export * from "./Error.js";
12
- export * from "./Evolu/Public.js";
13
12
  export * from "./Function.js";
14
13
  export * from "./Identicon.js";
15
14
  export * from "./Instances.js";
15
+ export * from "./local-first/Public.js";
16
16
  export * from "./Number.js";
17
17
  export * from "./Object.js";
18
18
  export * from "./Order.js";
@@ -423,32 +423,36 @@ export interface Evolu<S extends EvoluSchema = EvoluSchema> extends Disposable {
423
423
  readonly exportDatabase: () => Promise<Uint8Array<ArrayBuffer>>;
424
424
 
425
425
  /**
426
- * Use an owner. Using an owner means syncing it and subscribing to
427
- * broadcasted changes. Returns a function to stop using the owner.
426
+ * Use a {@link SyncOwner}. Returns a {@link UnuseOwner}.
428
427
  *
429
- * Transport connections are automatically deduplicated and reference-counted,
430
- * so multiple owners using the same transport will share a single
431
- * connection.
428
+ * Using an owner means syncing it with its transports, or the transports
429
+ * defined in Evolu config if the owner has no transports defined.
430
+ *
431
+ * Transport are automatically deduplicated and reference-counted, so multiple
432
+ * owners using the same transport will share a single connection.
432
433
  *
433
434
  * ### Example
434
435
  *
435
436
  * ```ts
436
- * // Use an owner (starts syncing and subscribing to changes).
437
- * const unuse = evolu.useOwner(shardOwner);
437
+ * // Use an owner (starts syncing).
438
+ * const unuseOwner = evolu.useOwner(shardOwner);
438
439
  *
439
440
  * // Later, stop using the owner.
440
- * unuse();
441
+ * unuseOwner();
441
442
  *
442
443
  * // Bulk operations.
443
- * const unuses = owners.map((owner) => evolu.useOwner(owner));
444
- * // Later: unuses.forEach(unuse => unuse());
444
+ * const unuseOwners = owners.map((owner) => evolu.useOwner(owner));
445
+ * // Later: for (const unuse of unuseOwners) unuse();
445
446
  * ```
446
447
  *
447
448
  * @experimental
448
449
  */
449
- readonly useOwner: (owner: SyncOwner) => () => void;
450
+ readonly useOwner: (owner: SyncOwner) => UnuseOwner;
450
451
  }
451
452
 
453
+ /** Function returned by {@link Evolu#useOwner} to stop using an {@link SyncOwner}. */
454
+ export type UnuseOwner = () => void;
455
+
452
456
  /** Represents errors that can occur in Evolu. */
453
457
  export type EvoluError =
454
458
  | ProtocolError
@@ -22,15 +22,23 @@ import type { EncryptedDbChange, Storage } from "./Storage.js";
22
22
  import { TimestampBytes } from "./Timestamp.js";
23
23
 
24
24
  /**
25
- * The Owner represents ownership of data in Evolu. Every database change is
26
- * assigned to an owner, enabling sync functionality and access control.
25
+ * {@link Owner} without a {@link OwnerWriteKey}.
27
26
  *
28
- * Owners enable **partial sync** - applications can choose which owners to
29
- * sync, allowing selective data synchronization based on specific needs.
27
+ * @see {@link createSharedReadonlyOwner}
28
+ */
29
+ export interface ReadonlyOwner {
30
+ readonly id: OwnerId;
31
+ readonly encryptionKey: OwnerEncryptionKey;
32
+ }
33
+
34
+ /**
35
+ * The Owner represents ownership of data in Evolu. Every database change is
36
+ * assigned to an owner and encrypted with its {@link OwnerEncryptionKey}. Owners
37
+ * allow partial sync, only the {@link AppOwner} is synced by default.
30
38
  *
31
- * Owners also provide **real data deletion** - while individual changes in
32
- * local-first/distributed systems can only be marked as deleted, entire owners
33
- * can be completely deleted from both relays and devices (except for
39
+ * Owners can also provide real data deletion, while individual changes in
40
+ * local-first/distributed systems can only be soft deleted, entire owners can
41
+ * be completely deleted from both relays and devices (except for
34
42
  * {@link AppOwner}, which must be preserved for sync coordination).
35
43
  *
36
44
  * Evolu provides different owner types depending on their use case:
@@ -46,21 +54,19 @@ import { TimestampBytes } from "./Timestamp.js";
46
54
  * SLIP-21, ensuring secure and deterministic key generation:
47
55
  *
48
56
  * - {@link OwnerId}: Globally unique public identifier
49
- * - {@link EncryptionKey}: Symmetric encryption key for data protection
57
+ * - {@link OwnerEncryptionKey}: Symmetric encryption key for data protection
50
58
  * - {@link OwnerWriteKey}: Authentication token for write operations (rotatable)
51
59
  *
52
- * @see {@link createOwner}
60
+ * @see {@link createAppOwner}
61
+ * @see {@link createShardOwner}
62
+ * @see {@link createSharedOwner}
63
+ * @see {@link createSharedReadonlyOwner}
53
64
  */
54
- export interface Owner {
55
- readonly id: OwnerId;
56
- readonly encryptionKey: OwnerEncryptionKey;
65
+ export interface Owner extends ReadonlyOwner {
57
66
  readonly writeKey: OwnerWriteKey;
58
67
  }
59
68
 
60
- /**
61
- * OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}.
62
- * Branded from {@link Id} to leverage existing helpers like {@link idToIdBytes}.
63
- */
69
+ /** OwnerId is a branded {@link Id} that uniquely identifies an {@link Owner}. */
64
70
  export const OwnerId = brand("OwnerId", Id);
65
71
  export type OwnerId = typeof OwnerId.Type;
66
72
 
@@ -68,14 +74,17 @@ export type OwnerId = typeof OwnerId.Type;
68
74
  export const OwnerIdBytes = brand("OwnerIdBytes", IdBytes);
69
75
  export type OwnerIdBytes = typeof OwnerIdBytes.Type;
70
76
 
77
+ /** Converts {@link OwnerId} to {@link OwnerIdBytes}. */
71
78
  export const ownerIdToOwnerIdBytes = (ownerId: OwnerId): OwnerIdBytes =>
72
79
  idToIdBytes(ownerId) as OwnerIdBytes;
73
80
 
81
+ /** Converts {@link OwnerIdBytes} to {@link OwnerId}. */
74
82
  export const ownerIdBytesToOwnerId = (ownerIdBytes: OwnerIdBytes): OwnerId =>
75
83
  idBytesToId(ownerIdBytes as IdBytes) as OwnerId;
76
84
 
77
85
  export const ownerWriteKeyLength = NonNegativeInt.orThrow(16);
78
86
 
87
+ /** Symmetric encryption key for {@link Owner} data protection. */
79
88
  export const OwnerEncryptionKey = brand("OwnerEncryptionKey", EncryptionKey);
80
89
  export type OwnerEncryptionKey = typeof OwnerEncryptionKey.Type;
81
90
 
@@ -86,6 +95,16 @@ export type OwnerEncryptionKey = typeof OwnerEncryptionKey.Type;
86
95
  export const OwnerWriteKey = brand("OwnerWriteKey", Entropy16);
87
96
  export type OwnerWriteKey = typeof OwnerWriteKey.Type;
88
97
 
98
+ /**
99
+ * Creates a new random {@link OwnerWriteKey} for rotation.
100
+ *
101
+ * The initial OwnerWriteKey is deterministically derived from
102
+ * {@link OwnerSecret}. Use `createOwnerWriteKey` to rotate (replace) the write
103
+ * key without changing the owner identity.
104
+ */
105
+ export const createOwnerWriteKey = (deps: RandomBytesDep): OwnerWriteKey =>
106
+ deps.randomBytes.create(16) as OwnerWriteKey;
107
+
89
108
  /**
90
109
  * 32 bytes of cryptographic entropy used to derive {@link Owner} keys.
91
110
  *
@@ -107,22 +126,11 @@ export const ownerSecretToMnemonic = (secret: OwnerSecret): Mnemonic =>
107
126
  export const mnemonicToOwnerSecret = (mnemonic: Mnemonic): OwnerSecret =>
108
127
  bip39.mnemonicToEntropy(mnemonic, wordlist) as OwnerSecret;
109
128
 
110
- /** Creates a randomly generated {@link OwnerWriteKey}. */
111
- export const createOwnerWriteKey = (deps: RandomBytesDep): OwnerWriteKey =>
112
- deps.randomBytes.create(16) as OwnerWriteKey;
113
-
114
129
  /**
115
130
  * Creates an {@link Owner} from a {@link OwnerSecret} using SLIP-21 key
116
131
  * derivation.
117
- *
118
- * This is an internal helper function, use:
119
- *
120
- * - {@link createAppOwner}
121
- * - {@link createShardOwner}
122
- * - {@link createSharedOwner}
123
- * - {@link createSharedReadonlyOwner}
124
132
  */
125
- export const createOwner = (secret: OwnerSecret): Owner => ({
133
+ const createOwner = (secret: OwnerSecret): Owner => ({
126
134
  id: ownerIdBytesToOwnerId(
127
135
  OwnerIdBytes.orThrow(
128
136
  createSlip21(secret, ["Evolu", "OwnerIdBytes"]).slice(0, 16),
@@ -182,9 +190,9 @@ export interface AppOwner extends Owner {
182
190
 
183
191
  /** Creates an {@link AppOwner} from an {@link OwnerSecret}. */
184
192
  export const createAppOwner = (secret: OwnerSecret): AppOwner => ({
193
+ ...createOwner(secret),
185
194
  type: "AppOwner",
186
195
  mnemonic: ownerSecretToMnemonic(secret),
187
- ...createOwner(secret),
188
196
  });
189
197
 
190
198
  /**
@@ -200,18 +208,13 @@ export const createAppOwner = (secret: OwnerSecret): AppOwner => ({
200
208
  */
201
209
  export interface ShardOwner extends Owner {
202
210
  readonly type: "ShardOwner";
203
- readonly transports?: ReadonlyArray<OwnerTransport>;
204
211
  }
205
212
 
206
213
  /** Creates a {@link ShardOwner} from an {@link OwnerSecret}. */
207
- export const createShardOwner = (
208
- secret: OwnerSecret,
209
- transports?: ReadonlyArray<OwnerTransport>,
210
- ): ShardOwner => {
214
+ export const createShardOwner = (secret: OwnerSecret): ShardOwner => {
211
215
  return {
212
- type: "ShardOwner",
213
216
  ...createOwner(secret),
214
- ...(transports && { transports }),
217
+ type: "ShardOwner",
215
218
  };
216
219
  };
217
220
 
@@ -236,21 +239,18 @@ export const createShardOwner = (
236
239
  export const deriveShardOwner = (
237
240
  owner: AppOwner,
238
241
  path: NonEmptyReadonlyArray<string | number>,
239
- transports?: ReadonlyArray<OwnerTransport>,
240
242
  ): ShardOwner => {
241
243
  const secret = createSlip21(owner.encryptionKey, path) as OwnerSecret;
242
244
 
243
245
  return {
244
- type: "ShardOwner",
245
246
  ...createOwner(secret),
246
- ...(transports && { transports }),
247
+ type: "ShardOwner",
247
248
  };
248
249
  };
249
250
 
250
251
  /** An {@link Owner} for collaborative data with write access. */
251
252
  export interface SharedOwner extends Owner {
252
253
  readonly type: "SharedOwner";
253
- readonly transports?: ReadonlyArray<OwnerTransport>;
254
254
  }
255
255
 
256
256
  /**
@@ -260,27 +260,18 @@ export interface SharedOwner extends Owner {
260
260
  * Use {@link createSharedReadonlyOwner} to create a read-only version for
261
261
  * sharing.
262
262
  */
263
- export const createSharedOwner = (
264
- secret: OwnerSecret,
265
- transports?: ReadonlyArray<OwnerTransport>,
266
- ): SharedOwner => {
267
- return {
268
- type: "SharedOwner",
269
- ...createOwner(secret),
270
- ...(transports && { transports }),
271
- };
272
- };
263
+ export const createSharedOwner = (secret: OwnerSecret): SharedOwner => ({
264
+ ...createOwner(secret),
265
+ type: "SharedOwner",
266
+ });
273
267
 
274
268
  /**
275
269
  * Read-only version of a {@link SharedOwner} for data sharing. Contains only the
276
270
  * {@link OwnerId} and {@link EncryptionKey} needed for others to read the shared
277
271
  * data without write access.
278
272
  */
279
- export interface SharedReadonlyOwner {
273
+ export interface SharedReadonlyOwner extends ReadonlyOwner {
280
274
  readonly type: "SharedReadonlyOwner";
281
- readonly id: OwnerId;
282
- readonly encryptionKey: EncryptionKey;
283
- readonly transports?: ReadonlyArray<OwnerTransport>;
284
275
  }
285
276
 
286
277
  /** Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner}. */
@@ -290,7 +281,6 @@ export const createSharedReadonlyOwner = (
290
281
  type: "SharedReadonlyOwner",
291
282
  id: sharedOwner.id,
292
283
  encryptionKey: sharedOwner.encryptionKey,
293
- ...(sharedOwner.transports && { transports: sharedOwner.transports }),
294
284
  });
295
285
 
296
286
  /**
@@ -383,8 +373,8 @@ export const parseOwnerIdFromOwnerWebSocketTransportUrl = (
383
373
  url: string,
384
374
  ): OwnerId | null => getOrNull(OwnerId.fromUnknown(url.split("=")[1]));
385
375
 
386
- /** Base interface for all owner errors. */
387
- export interface BaseOwnerError {
376
+ /** Common interface implemented by all owner domain errors. */
377
+ export interface OwnerError {
388
378
  readonly ownerId: OwnerId;
389
379
  }
390
380
 
@@ -221,7 +221,7 @@ import {
221
221
  } from "../Type.js";
222
222
  import { Predicate } from "../Types.js";
223
223
  import {
224
- BaseOwnerError,
224
+ OwnerError,
225
225
  Owner,
226
226
  OwnerId,
227
227
  OwnerIdBytes,
@@ -382,7 +382,7 @@ export type ProtocolError =
382
382
  * Represents a version mismatch in the Evolu Protocol. Occurs when the
383
383
  * initiator and non-initiator are using incompatible protocol versions.
384
384
  */
385
- export interface ProtocolVersionError extends BaseOwnerError {
385
+ export interface ProtocolVersionError extends OwnerError {
386
386
  readonly type: "ProtocolVersionError";
387
387
  readonly version: NonNegativeInt;
388
388
  /** Indicates which side is obsolete and should update. */
@@ -397,7 +397,7 @@ export interface ProtocolInvalidDataError {
397
397
  }
398
398
 
399
399
  /** Error when a {@link OwnerWriteKey} is invalid, missing, or fails validation. */
400
- export interface ProtocolWriteKeyError extends BaseOwnerError {
400
+ export interface ProtocolWriteKeyError extends OwnerError {
401
401
  readonly type: "ProtocolWriteKeyError";
402
402
  }
403
403
 
@@ -405,7 +405,7 @@ export interface ProtocolWriteKeyError extends BaseOwnerError {
405
405
  * Error indicating a serious relay-side write failure. Clients should log this
406
406
  * error and show a generic sync error to the user.
407
407
  */
408
- export interface ProtocolWriteError extends BaseOwnerError {
408
+ export interface ProtocolWriteError extends OwnerError {
409
409
  readonly type: "ProtocolWriteError";
410
410
  }
411
411
 
@@ -422,7 +422,7 @@ export interface ProtocolWriteError extends BaseOwnerError {
422
422
  * plan. Quota monitoring and management is the relay provider's
423
423
  * responsibility.
424
424
  */
425
- export interface ProtocolQuotaError extends BaseOwnerError {
425
+ export interface ProtocolQuotaError extends OwnerError {
426
426
  readonly type: "ProtocolQuotaError";
427
427
  }
428
428
 
@@ -430,7 +430,7 @@ export interface ProtocolQuotaError extends BaseOwnerError {
430
430
  * Error indicating a serious relay-side synchronization failure. Clients should
431
431
  * log this error and show a generic sync error to the user.
432
432
  */
433
- export interface ProtocolSyncError extends BaseOwnerError {
433
+ export interface ProtocolSyncError extends OwnerError {
434
434
  readonly type: "ProtocolSyncError";
435
435
  }
436
436
 
@@ -1,13 +1,14 @@
1
1
  /**
2
- * Public Evolu
2
+ * Local-first code to be imported from "@evolu/common"
3
3
  *
4
4
  * @module
5
5
  */
6
6
 
7
7
  export { createEvolu } from "./Evolu.js";
8
8
  export type { Evolu, EvoluConfig, EvoluDeps, EvoluError } from "./Evolu.js";
9
- export * from "./Owner.js";
9
+ export type { UnuseOwner } from "./Evolu.js";
10
10
  export * from "./LocalAuth.js";
11
+ export * from "./Owner.js";
11
12
  export * as kysely from "./PublicKysely.js";
12
13
  export type { InferRow, Query, QueryRows, Row } from "./Query.js";
13
14
  export type { EvoluSchema } from "./Schema.js";
@@ -26,7 +26,7 @@ import {
26
26
  TypeError,
27
27
  } from "../Type.js";
28
28
  import {
29
- BaseOwnerError,
29
+ OwnerError,
30
30
  Owner,
31
31
  OwnerId,
32
32
  OwnerIdBytes,
@@ -172,12 +172,12 @@ export interface StorageDep {
172
172
  }
173
173
 
174
174
  /** Error indicating a serious write failure. */
175
- export interface StorageWriteError extends BaseOwnerError {
175
+ export interface StorageWriteError extends OwnerError {
176
176
  readonly type: "StorageWriteError";
177
177
  }
178
178
 
179
179
  /** Error when storage or billing quota is exceeded. */
180
- export interface StorageQuotaError extends BaseOwnerError {
180
+ export interface StorageQuotaError extends OwnerError {
181
181
  readonly type: "StorageQuotaError";
182
182
  }
183
183