jazz-tools 0.9.10-jazz-bridge-preview.0 → 0.9.11

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.
@@ -1,20 +1,20 @@
1
1
 
2
- > jazz-tools@0.9.9 build /vercel/path0/packages/jazz-tools
2
+ > jazz-tools@0.9.11 build /home/runner/work/jazz/jazz/packages/jazz-tools
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: {"index.web":"src/index.web.ts","index.native":"src/index.native.ts","testing":"src/testing.ts"}
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.3.5
8
- CLI Using tsup config: /vercel/path0/packages/jazz-tools/tsup.config.ts
8
+ CLI Using tsup config: /home/runner/work/jazz/jazz/packages/jazz-tools/tsup.config.ts
9
9
  CLI Target: es2021
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  ESM dist/index.web.js 1.15 KB
13
13
  ESM dist/index.native.js 1.14 KB
14
14
  ESM dist/testing.js 2.30 KB
15
- ESM dist/chunk-VQZOWIPU.js 96.39 KB
15
+ ESM dist/chunk-ICWP2U63.js 94.94 KB
16
16
  ESM dist/index.web.js.map 273.00 B
17
17
  ESM dist/index.native.js.map 283.00 B
18
18
  ESM dist/testing.js.map 4.89 KB
19
- ESM dist/chunk-VQZOWIPU.js.map 238.27 KB
20
- ESM ⚡️ Build success in 90ms
19
+ ESM dist/chunk-ICWP2U63.js.map 235.54 KB
20
+ ESM ⚡️ Build success in 88ms
package/CHANGELOG.md CHANGED
@@ -1,10 +1,20 @@
1
1
  # jazz-tools
2
2
 
3
- ## 0.9.10-jazz-bridge-preview.0
3
+ ## 0.9.11
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - 5f43fbf: Implement applyDiff for CoLists
7
+ - Updated dependencies [efbf3d8]
8
+ - Updated dependencies [5863bad]
9
+ - cojson@0.9.11
10
+
11
+ ## 0.9.10
12
+
13
+ ### Patch Changes
14
+
15
+ - 5e83864: Improve error management on initial auth, fixed an infinite loop when migration fails
16
+ - Updated dependencies [4aa377d]
17
+ - cojson@0.9.10
8
18
 
9
19
  ## 0.9.9
10
20
 
@@ -454,110 +454,88 @@ async function randomSessionProvider(accountID, crypto) {
454
454
  };
455
455
  }
456
456
  async function createJazzContext(options) {
457
- while (true) {
458
- if (!("auth" in options)) {
459
- return createAnonymousJazzContext({
460
- peersToLoadFrom: options.peersToLoadFrom,
461
- crypto: options.crypto
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
- const { auth, sessionProvider, peersToLoadFrom, crypto } = options;
465
- const AccountSchema = options.AccountSchema ?? RegisteredSchemas["Account"];
466
- let authResult;
467
- try {
468
- authResult = await auth.start(crypto);
469
- } catch (e) {
470
- console.error("error", e);
471
- throw e;
472
- }
473
- if (authResult.type === "existing") {
474
- try {
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
- } else if (authResult.type === "new") {
525
- try {
526
- const { node } = await LocalNode.withNewlyCreatedAccount({
527
- creationProps: authResult.creationProps,
528
- peersToLoadFrom,
529
- crypto,
530
- initialAgentSecret: authResult.initialSecret,
531
- migration: async (rawAccount, _node, creationProps) => {
532
- const account2 = new AccountSchema({
533
- fromRaw: rawAccount
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
- authResult.onSuccess();
546
- return {
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-YWGGIF2U.js.map
3383
+ //# sourceMappingURL=chunk-ICWP2U63.js.map