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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +13 -0
- package/dist/{chunk-XRX3CCYY.js → chunk-DXCQRDRG.js} +9 -3
- package/dist/chunk-DXCQRDRG.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/testing.js +1 -1
- package/package.json +2 -2
- package/src/implementation/createContext.ts +8 -3
- package/src/tests/ContextManager.test.ts +40 -0
- package/dist/chunk-XRX3CCYY.js.map +0 -1
package/dist/index.js
CHANGED
package/dist/testing.js
CHANGED
package/package.json
CHANGED
@@ -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;
|