jazz-run 0.8.16 → 0.8.18

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # jazz-run
2
2
 
3
+ ## 0.8.18
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d4319d8]
8
+ - cojson@0.8.18
9
+ - cojson-storage-sqlite@0.8.18
10
+ - cojson-transport-ws@0.8.18
11
+ - jazz-tools@0.8.18
12
+
13
+ ## 0.8.17
14
+
15
+ ### Patch Changes
16
+
17
+ - d433cf4: Improve the sync wait using the new API from the sync manager
18
+ - Updated dependencies [d433cf4]
19
+ - Updated dependencies [b6162f0]
20
+ - cojson@0.8.17
21
+ - cojson-transport-ws@0.8.17
22
+ - cojson-storage-sqlite@0.8.17
23
+ - jazz-tools@0.8.17
24
+
3
25
  ## 0.8.16
4
26
 
5
27
  ### Patch Changes
@@ -26,8 +26,8 @@ export const createWorkerAccount = async ({ name, peer: peerAddr, }) => {
26
26
  ]);
27
27
  await Promise.race([
28
28
  Promise.all([
29
- waitForSync(account, peer, accountCoValue),
30
- waitForSync(account, peer, accountProfileCoValue),
29
+ syncManager.waitForUploadIntoPeer(peer.id, accountCoValue.id),
30
+ syncManager.waitForUploadIntoPeer(peer.id, accountProfileCoValue.id),
31
31
  ]),
32
32
  failAfter(4000, "Timeout: Didn't manage to upload the account and profile"),
33
33
  ]);
@@ -47,53 +47,13 @@ export const createWorkerAccount = async ({ name, peer: peerAddr, }) => {
47
47
  peersToLoadFrom: [peer2],
48
48
  crypto,
49
49
  }),
50
- failAfter(4000, "Timeout: Account loading check failed"),
50
+ failAfter(10000, "Timeout: Account loading check failed"),
51
51
  ]);
52
52
  return {
53
53
  accountId: account.id,
54
54
  agentSecret: account._raw.agentSecret,
55
55
  };
56
56
  };
57
- function waitForSync(account, peer, coValue) {
58
- const syncManager = account._raw.core.node.syncManager;
59
- const peerState = syncManager.peers[peer.id];
60
- if (!peerState) {
61
- throw new Error(`Peer state for ${peer.id} not found`);
62
- }
63
- const isSynced = () => {
64
- const knownState = coValue.knownState();
65
- if (!peerState.optimisticKnownStates.get(coValue.id)) {
66
- return false;
67
- }
68
- return isEqualSession(knownState.sessions, peerState.optimisticKnownStates.get(coValue.id)?.sessions ?? {});
69
- };
70
- if (isSynced()) {
71
- return Promise.resolve(true);
72
- }
73
- return new Promise((resolve) => {
74
- const unsubscribe = peerState?.optimisticKnownStates.subscribe((id, knownState) => {
75
- if (id !== coValue.id)
76
- return;
77
- if (isSynced()) {
78
- resolve(true);
79
- unsubscribe?.();
80
- }
81
- });
82
- });
83
- }
84
- function isEqualSession(a, b) {
85
- const keysA = Object.keys(a);
86
- const keysB = Object.keys(b);
87
- if (keysA.length !== keysB.length) {
88
- return false;
89
- }
90
- for (const sessionId of keysA) {
91
- if (a[sessionId] !== b[sessionId]) {
92
- return false;
93
- }
94
- }
95
- return true;
96
- }
97
57
  function failAfter(ms, errorMessage) {
98
58
  return new Promise((_, reject) => {
99
59
  setTimeout(() => reject(new Error(errorMessage)), ms);
@@ -1 +1 @@
1
- {"version":3,"file":"createWorkerAccount.js","sourceRoot":"","sources":["../src/createWorkerAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,OAAO,EAGP,UAAU,EACV,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,EACxC,IAAI,EACJ,IAAI,EAAE,QAAQ,GAIf,EAAE,EAAE;IACH,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC;IAEzC,MAAM,IAAI,GAAG,mBAAmB,CAAC;QAC/B,EAAE,EAAE,UAAU;QACd,SAAS,EAAE,IAAI,SAA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AAE,EAAE,cAAc,CAAC,EAAE,CAAC;YAC7D,WAAW,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,EAAE,qBAAqB,CAAC,EAAE,CAAC;SACrE,CAAC;QACF,SAAS,CACP,IAAK,EACL,0DAA0D,CAC3D;KACF,CAAC,CAAC;IAEH,uEAAuE;IACvE,MAAM,KAAK,GAAG,mBAAmB,CAAC;QAChC,EAAE,EAAE,eAAe;QACnB,SAAS,EAAE,IAAI,SAAS,CAAC,QAAQ,CAAC;QAClC,IAAI,EAAE,QAAQ;KACf,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,IAAI,CAAC;QACjB,iBAAiB,CAAC;YAChB,IAAI,EAAE,oBAAoB,CAAC;gBACzB,SAAS,EAAE,OAAO,CAAC,EAAE;gBACrB,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW;aACjC,CAAC;YACF,eAAe,EAAE,qBAAqB;YACtC,eAAe,EAAE,CAAC,KAAK,CAAC;YACxB,MAAM;SACP,CAAC;QACF,SAAS,CAAC,KAAM,EAAE,uCAAuC,CAAC;KAC3D,CAAC,CAAC;IAEH,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW;KACtC,CAAC;AACJ,CAAC,CAAC;AAEF,SAAS,SAAS,CAAC,EAAU,EAAE,YAAoB;IACjD,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC/B,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bin": "./dist/index.js",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
- "version": "0.8.16",
6
+ "version": "0.8.18",
7
7
  "dependencies": {
8
8
  "@effect/cli": "^0.41.2",
9
9
  "@effect/platform-node": "^0.57.2",
@@ -11,11 +11,11 @@
11
11
  "@effect/printer-ansi": "^0.34.5",
12
12
  "@effect/schema": "^0.71.1",
13
13
  "@effect/typeclass": "^0.25.5",
14
- "cojson": "0.8.16",
15
- "cojson-storage-sqlite": "0.8.16",
16
- "cojson-transport-ws": "0.8.16",
14
+ "cojson": "0.8.18",
15
+ "cojson-storage-sqlite": "0.8.18",
16
+ "cojson-transport-ws": "0.8.18",
17
17
  "effect": "^3.6.5",
18
- "jazz-tools": "0.8.16",
18
+ "jazz-tools": "0.8.18",
19
19
  "ws": "^8.14.2"
20
20
  },
21
21
  "devDependencies": {
@@ -47,8 +47,8 @@ export const createWorkerAccount = async ({
47
47
 
48
48
  await Promise.race([
49
49
  Promise.all([
50
- waitForSync(account, peer, accountCoValue),
51
- waitForSync(account, peer, accountProfileCoValue),
50
+ syncManager.waitForUploadIntoPeer(peer.id, accountCoValue.id),
51
+ syncManager.waitForUploadIntoPeer(peer.id, accountProfileCoValue.id),
52
52
  ]),
53
53
  failAfter(
54
54
  4_000,
@@ -73,7 +73,7 @@ export const createWorkerAccount = async ({
73
73
  peersToLoadFrom: [peer2],
74
74
  crypto,
75
75
  }),
76
- failAfter(4_000, "Timeout: Account loading check failed"),
76
+ failAfter(10_000, "Timeout: Account loading check failed"),
77
77
  ]);
78
78
 
79
79
  return {
@@ -82,62 +82,6 @@ export const createWorkerAccount = async ({
82
82
  };
83
83
  };
84
84
 
85
- function waitForSync(account: Account, peer: Peer, coValue: CoValueCore) {
86
- const syncManager = account._raw.core.node.syncManager;
87
- const peerState = syncManager.peers[peer.id];
88
-
89
- if (!peerState) {
90
- throw new Error(`Peer state for ${peer.id} not found`);
91
- }
92
-
93
- const isSynced = () => {
94
- const knownState = coValue.knownState();
95
-
96
- if (!peerState.optimisticKnownStates.get(coValue.id)) {
97
- return false;
98
- }
99
-
100
- return isEqualSession(
101
- knownState.sessions,
102
- peerState.optimisticKnownStates.get(coValue.id)?.sessions ?? {},
103
- );
104
- };
105
-
106
- if (isSynced()) {
107
- return Promise.resolve(true);
108
- }
109
-
110
- return new Promise((resolve) => {
111
- const unsubscribe = peerState?.optimisticKnownStates.subscribe(
112
- (id, knownState) => {
113
- if (id !== coValue.id) return;
114
-
115
- if (isSynced()) {
116
- resolve(true);
117
- unsubscribe?.();
118
- }
119
- },
120
- );
121
- });
122
- }
123
-
124
- function isEqualSession(a: Record<string, number>, b: Record<string, number>) {
125
- const keysA = Object.keys(a);
126
- const keysB = Object.keys(b);
127
-
128
- if (keysA.length !== keysB.length) {
129
- return false;
130
- }
131
-
132
- for (const sessionId of keysA) {
133
- if (a[sessionId] !== b[sessionId]) {
134
- return false;
135
- }
136
- }
137
-
138
- return true;
139
- }
140
-
141
85
  function failAfter(ms: number, errorMessage: string) {
142
86
  return new Promise((_, reject) => {
143
87
  setTimeout(() => reject(new Error(errorMessage)), ms);