jazz-tools 0.10.3 → 0.10.5

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/index.js CHANGED
@@ -35,7 +35,7 @@ import {
35
35
  parseInviteLink,
36
36
  randomSessionProvider,
37
37
  subscribeToCoValue
38
- } from "./chunk-XRX3CCYY.js";
38
+ } from "./chunk-DXCQRDRG.js";
39
39
 
40
40
  // src/index.ts
41
41
  import { MAX_RECOMMENDED_TX_SIZE, cojsonInternals } from "cojson";
package/dist/testing.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  createAnonymousJazzContext,
6
6
  createJazzContext,
7
7
  randomSessionProvider
8
- } from "./chunk-XRX3CCYY.js";
8
+ } from "./chunk-DXCQRDRG.js";
9
9
 
10
10
  // src/testing.ts
11
11
  import { LocalNode } from "cojson";
package/package.json CHANGED
@@ -17,10 +17,10 @@
17
17
  },
18
18
  "type": "module",
19
19
  "license": "MIT",
20
- "version": "0.10.3",
20
+ "version": "0.10.5",
21
21
  "dependencies": {
22
22
  "@scure/bip39": "^1.3.0",
23
- "cojson": "0.10.2"
23
+ "cojson": "0.10.4"
24
24
  },
25
25
  "devDependencies": {
26
26
  "tsup": "8.3.5",
@@ -110,14 +110,19 @@ export async function createJazzContextFromExistingCredentials<
110
110
  sessionID: sessionID,
111
111
  peersToLoadFrom: peersToLoadFrom,
112
112
  crypto: crypto,
113
+ migration: async (rawAccount, _node, creationProps) => {
114
+ const account = new CurrentAccountSchema({
115
+ fromRaw: rawAccount,
116
+ }) as Acc;
117
+ activeAccountContext.set(account);
118
+
119
+ await account.applyMigration(creationProps);
120
+ },
113
121
  });
114
122
 
115
123
  const account = CurrentAccountSchema.fromNode(node);
116
124
  activeAccountContext.set(account);
117
125
 
118
- // Running the migration outside of withLoadedAccount for better error management
119
- await account.applyMigration();
120
-
121
126
  return {
122
127
  node,
123
128
  account,
@@ -196,6 +196,46 @@ describe("ContextManager", () => {
196
196
  expect(onAnonymousAccountDiscarded).not.toHaveBeenCalled();
197
197
  });
198
198
 
199
+ test("the migration should be applied correctly on existing accounts ", async () => {
200
+ class AccountRoot extends CoMap {
201
+ value = co.string;
202
+ transferredRoot = co.optional.ref(AccountRoot);
203
+ }
204
+
205
+ let lastRootId: string | undefined;
206
+
207
+ class CustomAccount extends Account {
208
+ root = co.ref(AccountRoot);
209
+
210
+ migrate() {
211
+ this.root = AccountRoot.create({
212
+ value: "Hello",
213
+ });
214
+ lastRootId = this.root.id;
215
+ }
216
+ }
217
+ const customManager = new TestJazzContextManager<CustomAccount>();
218
+
219
+ // Create initial anonymous context
220
+ await customManager.createContext({
221
+ AccountSchema: CustomAccount,
222
+ });
223
+
224
+ const account = (
225
+ customManager.getCurrentValue() as JazzAuthContext<CustomAccount>
226
+ ).me;
227
+
228
+ await customManager.authenticate({
229
+ accountID: account.id,
230
+ accountSecret: account._raw.core.node.account.agentSecret,
231
+ provider: "test",
232
+ });
233
+
234
+ const me = await CustomAccount.getMe().ensureLoaded({ root: {} });
235
+
236
+ expect(me.root.id).toBe(lastRootId);
237
+ });
238
+
199
239
  test("onAnonymousAccountDiscarded should work on transfering data between accounts", async () => {
200
240
  class AccountRoot extends CoMap {
201
241
  value = co.string;