jazz-tools 0.9.10-jazz-bridge-preview.0 → 0.9.10
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 +5 -5
- package/CHANGELOG.md +4 -2
- package/dist/{chunk-YWGGIF2U.js → chunk-ICWP2U63.js} +79 -147
- package/dist/chunk-ICWP2U63.js.map +1 -0
- package/dist/index.native.js +1 -1
- package/dist/index.web.js +1 -1
- package/dist/testing.js +1 -1
- package/package.json +2 -3
- package/src/coValues/coList.ts +1 -14
- package/src/coValues/coMap.ts +0 -54
- package/src/coValues/coRichText.ts +1 -0
- package/src/coValues/interfaces.ts +0 -10
- package/src/exports.ts +1 -6
- package/src/implementation/createContext.ts +86 -109
- package/src/tests/coList.test.ts +0 -20
- package/.turbo/turbo-lint.log +0 -4
- package/.turbo/turbo-test.log +0 -144
- package/dist/chunk-YWGGIF2U.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.9.
|
2
|
+
> jazz-tools@0.9.10 build /home/runner/work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: {"index.web":"src/index.web.ts","index.native":"src/index.native.ts","testing":"src/testing.ts"}
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
7
7
|
[34mCLI[39m tsup v8.3.5
|
8
|
-
[34mCLI[39m Using tsup config: /
|
8
|
+
[34mCLI[39m Using tsup config: /home/runner/work/jazz/jazz/packages/jazz-tools/tsup.config.ts
|
9
9
|
[34mCLI[39m Target: es2021
|
10
10
|
[34mCLI[39m Cleaning output folder
|
11
11
|
[34mESM[39m Build start
|
12
12
|
[32mESM[39m [1mdist/index.web.js [22m[32m1.15 KB[39m
|
13
13
|
[32mESM[39m [1mdist/index.native.js [22m[32m1.14 KB[39m
|
14
14
|
[32mESM[39m [1mdist/testing.js [22m[32m2.30 KB[39m
|
15
|
-
[32mESM[39m [1mdist/chunk-
|
15
|
+
[32mESM[39m [1mdist/chunk-ICWP2U63.js [22m[32m94.94 KB[39m
|
16
16
|
[32mESM[39m [1mdist/index.web.js.map [22m[32m273.00 B[39m
|
17
17
|
[32mESM[39m [1mdist/index.native.js.map [22m[32m283.00 B[39m
|
18
18
|
[32mESM[39m [1mdist/testing.js.map [22m[32m4.89 KB[39m
|
19
|
-
[32mESM[39m [1mdist/chunk-
|
20
|
-
[32mESM[39m ⚡️ Build success in
|
19
|
+
[32mESM[39m [1mdist/chunk-ICWP2U63.js.map [22m[32m235.54 KB[39m
|
20
|
+
[32mESM[39m ⚡️ Build success in 88ms
|
package/CHANGELOG.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# jazz-tools
|
2
2
|
|
3
|
-
## 0.9.10
|
3
|
+
## 0.9.10
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
7
|
-
-
|
7
|
+
- 5e83864: Improve error management on initial auth, fixed an infinite loop when migration fails
|
8
|
+
- Updated dependencies [4aa377d]
|
9
|
+
- cojson@0.9.10
|
8
10
|
|
9
11
|
## 0.9.9
|
10
12
|
|
@@ -454,110 +454,88 @@ async function randomSessionProvider(accountID, crypto) {
|
|
454
454
|
};
|
455
455
|
}
|
456
456
|
async function createJazzContext(options) {
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
457
|
+
if (!("auth" in options)) {
|
458
|
+
return createAnonymousJazzContext({
|
459
|
+
peersToLoadFrom: options.peersToLoadFrom,
|
460
|
+
crypto: options.crypto
|
461
|
+
});
|
462
|
+
}
|
463
|
+
const { auth, sessionProvider, peersToLoadFrom, crypto } = options;
|
464
|
+
const AccountSchema = options.AccountSchema ?? RegisteredSchemas["Account"];
|
465
|
+
const authResult = await auth.start(crypto);
|
466
|
+
if (authResult.type === "existing") {
|
467
|
+
const { sessionID, sessionDone } = await sessionProvider(
|
468
|
+
authResult.credentials.accountID,
|
469
|
+
crypto
|
470
|
+
);
|
471
|
+
const node = await LocalNode.withLoadedAccount({
|
472
|
+
accountID: authResult.credentials.accountID,
|
473
|
+
accountSecret: authResult.credentials.secret,
|
474
|
+
sessionID,
|
475
|
+
peersToLoadFrom,
|
476
|
+
crypto,
|
477
|
+
migration: async (rawAccount, _node, creationProps) => {
|
478
|
+
const account2 = new AccountSchema({
|
479
|
+
fromRaw: rawAccount
|
480
|
+
});
|
481
|
+
activeAccountContext.set(account2);
|
482
|
+
await account2.applyMigration(creationProps);
|
483
|
+
}
|
484
|
+
});
|
485
|
+
const account = AccountSchema.fromNode(node);
|
486
|
+
activeAccountContext.set(account);
|
487
|
+
if (authResult.saveCredentials) {
|
488
|
+
await authResult.saveCredentials({
|
489
|
+
accountID: node.account.id,
|
490
|
+
secret: node.account.agentSecret
|
462
491
|
});
|
463
492
|
}
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
const { sessionID, sessionDone } = await sessionProvider(
|
476
|
-
authResult.credentials.accountID,
|
477
|
-
crypto
|
478
|
-
);
|
479
|
-
try {
|
480
|
-
const node = await LocalNode.withLoadedAccount({
|
481
|
-
accountID: authResult.credentials.accountID,
|
482
|
-
accountSecret: authResult.credentials.secret,
|
483
|
-
sessionID,
|
484
|
-
peersToLoadFrom,
|
485
|
-
crypto,
|
486
|
-
migration: async (rawAccount, _node, creationProps) => {
|
487
|
-
const account2 = new AccountSchema({
|
488
|
-
fromRaw: rawAccount
|
489
|
-
});
|
490
|
-
activeAccountContext.set(account2);
|
491
|
-
await account2.applyMigration(creationProps);
|
492
|
-
}
|
493
|
-
});
|
494
|
-
const account = AccountSchema.fromNode(node);
|
495
|
-
activeAccountContext.set(account);
|
496
|
-
if (authResult.saveCredentials) {
|
497
|
-
await authResult.saveCredentials({
|
498
|
-
accountID: node.account.id,
|
499
|
-
secret: node.account.agentSecret
|
500
|
-
});
|
501
|
-
}
|
502
|
-
authResult.onSuccess();
|
503
|
-
return {
|
504
|
-
account,
|
505
|
-
done: () => {
|
506
|
-
node.gracefulShutdown();
|
507
|
-
sessionDone();
|
508
|
-
},
|
509
|
-
logOut: () => {
|
510
|
-
node.gracefulShutdown();
|
511
|
-
sessionDone();
|
512
|
-
authResult.logOut();
|
513
|
-
}
|
514
|
-
};
|
515
|
-
} catch (e) {
|
516
|
-
authResult.onError(new Error("Error loading account", { cause: e }));
|
517
|
-
sessionDone();
|
518
|
-
}
|
519
|
-
} catch (e) {
|
520
|
-
authResult.onError(
|
521
|
-
new Error("Error acquiring sessionID", { cause: e })
|
522
|
-
);
|
493
|
+
authResult.onSuccess();
|
494
|
+
return {
|
495
|
+
account,
|
496
|
+
done: () => {
|
497
|
+
node.gracefulShutdown();
|
498
|
+
sessionDone();
|
499
|
+
},
|
500
|
+
logOut: () => {
|
501
|
+
node.gracefulShutdown();
|
502
|
+
sessionDone();
|
503
|
+
authResult.logOut();
|
523
504
|
}
|
524
|
-
}
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
});
|
535
|
-
activeAccountContext.set(account2);
|
536
|
-
await account2.applyMigration(creationProps);
|
537
|
-
}
|
538
|
-
});
|
539
|
-
const account = AccountSchema.fromNode(node);
|
540
|
-
activeAccountContext.set(account);
|
541
|
-
await authResult.saveCredentials({
|
542
|
-
accountID: node.account.id,
|
543
|
-
secret: node.account.agentSecret
|
505
|
+
};
|
506
|
+
} else if (authResult.type === "new") {
|
507
|
+
const { node } = await LocalNode.withNewlyCreatedAccount({
|
508
|
+
creationProps: authResult.creationProps,
|
509
|
+
peersToLoadFrom,
|
510
|
+
crypto,
|
511
|
+
initialAgentSecret: authResult.initialSecret,
|
512
|
+
migration: async (rawAccount, _node, creationProps) => {
|
513
|
+
const account2 = new AccountSchema({
|
514
|
+
fromRaw: rawAccount
|
544
515
|
});
|
545
|
-
|
546
|
-
|
547
|
-
account,
|
548
|
-
done: () => {
|
549
|
-
node.gracefulShutdown();
|
550
|
-
},
|
551
|
-
logOut: () => {
|
552
|
-
node.gracefulShutdown();
|
553
|
-
authResult.logOut();
|
554
|
-
}
|
555
|
-
};
|
556
|
-
} catch (e) {
|
557
|
-
authResult.onError(new Error("Error creating account", { cause: e }));
|
516
|
+
activeAccountContext.set(account2);
|
517
|
+
await account2.applyMigration(creationProps);
|
558
518
|
}
|
559
|
-
}
|
519
|
+
});
|
520
|
+
const account = AccountSchema.fromNode(node);
|
521
|
+
activeAccountContext.set(account);
|
522
|
+
await authResult.saveCredentials({
|
523
|
+
accountID: node.account.id,
|
524
|
+
secret: node.account.agentSecret
|
525
|
+
});
|
526
|
+
authResult.onSuccess();
|
527
|
+
return {
|
528
|
+
account,
|
529
|
+
done: () => {
|
530
|
+
node.gracefulShutdown();
|
531
|
+
},
|
532
|
+
logOut: () => {
|
533
|
+
node.gracefulShutdown();
|
534
|
+
authResult.logOut();
|
535
|
+
}
|
536
|
+
};
|
560
537
|
}
|
538
|
+
throw new Error("Invalid auth result");
|
561
539
|
}
|
562
540
|
async function createAnonymousJazzContext({
|
563
541
|
peersToLoadFrom,
|
@@ -1121,7 +1099,6 @@ function getAccountIDfromSessionID(sessionID) {
|
|
1121
1099
|
|
1122
1100
|
// src/coValues/coMap.ts
|
1123
1101
|
import {
|
1124
|
-
CoValueCore,
|
1125
1102
|
cojsonInternals
|
1126
1103
|
} from "cojson";
|
1127
1104
|
var _CoMap = class _CoMap extends CoValueBase {
|
@@ -1376,43 +1353,6 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
1376
1353
|
const crypto = as._type === "Anonymous" ? as.node.crypto : as._raw.core.crypto;
|
1377
1354
|
return cojsonInternals.idforHeader(header, crypto);
|
1378
1355
|
}
|
1379
|
-
static async getUnique(unique, ownerID, as) {
|
1380
|
-
as ||= activeAccountContext.get();
|
1381
|
-
const header = {
|
1382
|
-
type: "comap",
|
1383
|
-
ruleset: {
|
1384
|
-
type: "ownedByGroup",
|
1385
|
-
group: ownerID
|
1386
|
-
},
|
1387
|
-
meta: null,
|
1388
|
-
uniqueness: unique
|
1389
|
-
};
|
1390
|
-
const crypto = as._raw.core.crypto;
|
1391
|
-
const id = cojsonInternals.idforHeader(header, crypto);
|
1392
|
-
const existingEntry = as._raw.core.node.coValuesStore.get(id);
|
1393
|
-
if (existingEntry) {
|
1394
|
-
if (existingEntry.state.type === "available") {
|
1395
|
-
return this.fromRaw(
|
1396
|
-
existingEntry.state.coValue.getCurrentContent()
|
1397
|
-
);
|
1398
|
-
} else if (existingEntry.state.type !== "unknown") {
|
1399
|
-
throw new Error(
|
1400
|
-
`Can't handle intermediate state for unique CoMap: ${existingEntry.state.type}`
|
1401
|
-
);
|
1402
|
-
}
|
1403
|
-
}
|
1404
|
-
as._raw.core.node.coValuesStore.setAsAvailable(
|
1405
|
-
id,
|
1406
|
-
new CoValueCore(header, as._raw.core.node)
|
1407
|
-
);
|
1408
|
-
const entry = as._raw.core.node.coValuesStore.get(id);
|
1409
|
-
if (entry.state.type !== "available") {
|
1410
|
-
throw new Error("CoValue not found");
|
1411
|
-
}
|
1412
|
-
return this.fromRaw(
|
1413
|
-
entry.state.coValue.getCurrentContent()
|
1414
|
-
);
|
1415
|
-
}
|
1416
1356
|
/**
|
1417
1357
|
* Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
|
1418
1358
|
*
|
@@ -2352,7 +2292,6 @@ var FileStream = class extends CoValueBase {
|
|
2352
2292
|
|
2353
2293
|
// src/coValues/coList.ts
|
2354
2294
|
import { RawAccount as RawAccount5 } from "cojson";
|
2355
|
-
import { calcPatch } from "fast-myers-diff";
|
2356
2295
|
var _CoList = class _CoList extends Array {
|
2357
2296
|
/**
|
2358
2297
|
* Declare a `CoList` by subclassing `CoList.Of(...)` and passing the item schema using `co`.
|
@@ -2517,20 +2456,12 @@ var _CoList = class _CoList extends Array {
|
|
2517
2456
|
}
|
2518
2457
|
let appendAfter = Math.max(start - 1, 0);
|
2519
2458
|
for (const item of toRawItems(items, this._schema[ItemsSym])) {
|
2459
|
+
console.log(this._raw.asArray(), appendAfter);
|
2520
2460
|
this._raw.append(item, appendAfter);
|
2521
2461
|
appendAfter++;
|
2522
2462
|
}
|
2523
2463
|
return deleted;
|
2524
2464
|
}
|
2525
|
-
applyDiff(other) {
|
2526
|
-
const current = this._raw.asArray();
|
2527
|
-
const cmp = isRefEncoded(this._schema[ItemsSym]) ? (aIdx, bIdx) => current[aIdx].id === other[bIdx].id : void 0;
|
2528
|
-
for (const [from, to, insert] of [
|
2529
|
-
...calcPatch(current, other, cmp)
|
2530
|
-
].reverse()) {
|
2531
|
-
this.splice(from, to - from, ...insert);
|
2532
|
-
}
|
2533
|
-
}
|
2534
2465
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2535
2466
|
toJSON(_key, seenAbove) {
|
2536
2467
|
const itemDescriptor = this._schema[ItemsSym];
|
@@ -3123,6 +3054,7 @@ var CoRichText = class extends CoMap {
|
|
3123
3054
|
end + 1,
|
3124
3055
|
mark.endBefore,
|
3125
3056
|
RangeClass,
|
3057
|
+
// @ts-ignore Some Typescript versions flag this as an error
|
3126
3058
|
{},
|
3127
3059
|
{
|
3128
3060
|
markOwner: mark.sourceMark._owner || this._owner
|
@@ -3448,4 +3380,4 @@ export {
|
|
3448
3380
|
SchemaUnion
|
3449
3381
|
};
|
3450
3382
|
/* istanbul ignore file -- @preserve */
|
3451
|
-
//# sourceMappingURL=chunk-
|
3383
|
+
//# sourceMappingURL=chunk-ICWP2U63.js.map
|