jazz-tools 0.18.24 → 0.18.26

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.
Files changed (112) hide show
  1. package/.svelte-kit/__package__/Provider.svelte +2 -0
  2. package/.svelte-kit/__package__/Provider.svelte.d.ts.map +1 -1
  3. package/.turbo/turbo-build.log +49 -49
  4. package/CHANGELOG.md +24 -0
  5. package/dist/browser/index.js +9 -9
  6. package/dist/browser/index.js.map +1 -1
  7. package/dist/{chunk-BOMSRY5H.js → chunk-M2HGBOXS.js} +2 -2
  8. package/dist/chunk-M2HGBOXS.js.map +1 -0
  9. package/dist/{chunk-W7JT3QUN.js → chunk-ZIAN4UY5.js} +406 -40
  10. package/dist/chunk-ZIAN4UY5.js.map +1 -0
  11. package/dist/index.js +2 -2
  12. package/dist/inspector/{custom-element-XDJT5T57.js → custom-element-A7UAELEG.js} +3 -1
  13. package/dist/inspector/{custom-element-XDJT5T57.js.map → custom-element-A7UAELEG.js.map} +1 -1
  14. package/dist/inspector/index.js +2 -0
  15. package/dist/inspector/index.js.map +1 -1
  16. package/dist/inspector/register-custom-element.js +1 -1
  17. package/dist/inspector/viewer/use-open-inspector.d.ts.map +1 -1
  18. package/dist/inspector/viewer/use-page-path.d.ts.map +1 -1
  19. package/dist/react/index.js +4 -2
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/react/provider.d.ts +2 -1
  22. package/dist/react/provider.d.ts.map +1 -1
  23. package/dist/react/ssr.js +1 -1
  24. package/dist/react/ssr.js.map +1 -1
  25. package/dist/react-native-core/index.js +12 -11
  26. package/dist/react-native-core/index.js.map +1 -1
  27. package/dist/react-native-core/provider.d.ts +2 -1
  28. package/dist/react-native-core/provider.d.ts.map +1 -1
  29. package/dist/svelte/Provider.svelte +2 -0
  30. package/dist/svelte/Provider.svelte.d.ts.map +1 -1
  31. package/dist/testing.js +4 -4
  32. package/dist/testing.js.map +1 -1
  33. package/dist/tools/auth/AuthSecretStorage.d.ts +3 -1
  34. package/dist/tools/auth/AuthSecretStorage.d.ts.map +1 -1
  35. package/dist/tools/coValues/account.d.ts +3 -3
  36. package/dist/tools/coValues/account.d.ts.map +1 -1
  37. package/dist/tools/coValues/coVector.d.ts +127 -0
  38. package/dist/tools/coValues/coVector.d.ts.map +1 -0
  39. package/dist/tools/coValues/group.d.ts +20 -1
  40. package/dist/tools/coValues/group.d.ts.map +1 -1
  41. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  42. package/dist/tools/implementation/ContextManager.d.ts +1 -0
  43. package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
  44. package/dist/tools/implementation/createContext.d.ts +7 -7
  45. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  46. package/dist/tools/implementation/zodSchema/coExport.d.ts +2 -1
  47. package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
  48. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
  49. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +47 -0
  50. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -0
  51. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +5 -0
  52. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
  53. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +2 -2
  54. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  55. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +2 -2
  56. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  57. package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -1
  58. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  59. package/dist/tools/implementation/zodSchema/zodSchema.d.ts +3 -2
  60. package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  61. package/dist/tools/internal.d.ts +2 -0
  62. package/dist/tools/internal.d.ts.map +1 -1
  63. package/dist/tools/ssr.js +1 -1
  64. package/dist/tools/testing.d.ts.map +1 -1
  65. package/dist/tools/tests/coVector.test-d.d.ts +2 -0
  66. package/dist/tools/tests/coVector.test-d.d.ts.map +1 -0
  67. package/dist/tools/tests/coVector.test.d.ts +2 -0
  68. package/dist/tools/tests/coVector.test.d.ts.map +1 -0
  69. package/dist/worker/index.js +3 -3
  70. package/dist/worker/index.js.map +1 -1
  71. package/package.json +4 -4
  72. package/src/better-auth/database-adapter/tests/sync-utils.ts +1 -1
  73. package/src/browser/createBrowserContext.ts +9 -9
  74. package/src/browser/tests/utils.ts +2 -2
  75. package/src/inspector/viewer/use-open-inspector.ts +1 -0
  76. package/src/inspector/viewer/use-page-path.ts +1 -0
  77. package/src/react/provider.tsx +3 -0
  78. package/src/react-native-core/platform.ts +9 -9
  79. package/src/react-native-core/provider.tsx +3 -1
  80. package/src/svelte/Provider.svelte +2 -0
  81. package/src/tools/auth/AuthSecretStorage.ts +16 -9
  82. package/src/tools/coValues/account.ts +5 -5
  83. package/src/tools/coValues/coVector.ts +432 -0
  84. package/src/tools/coValues/group.ts +33 -0
  85. package/src/tools/coValues/interfaces.ts +4 -1
  86. package/src/tools/implementation/ContextManager.ts +7 -3
  87. package/src/tools/implementation/createContext.ts +12 -12
  88. package/src/tools/implementation/zodSchema/coExport.ts +2 -0
  89. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +13 -0
  90. package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +105 -0
  91. package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +7 -1
  92. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +9 -5
  93. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +15 -9
  94. package/src/tools/implementation/zodSchema/zodCo.ts +15 -0
  95. package/src/tools/implementation/zodSchema/zodSchema.ts +15 -6
  96. package/src/tools/internal.ts +2 -0
  97. package/src/tools/ssr/ssr.ts +1 -1
  98. package/src/tools/testing.ts +3 -3
  99. package/src/tools/tests/AuthSecretStorage.test.ts +59 -1
  100. package/src/tools/tests/ContextManager.test.ts +11 -1
  101. package/src/tools/tests/account.test.ts +16 -0
  102. package/src/tools/tests/coPlainText.test.ts +2 -2
  103. package/src/tools/tests/coVector.test-d.ts +40 -0
  104. package/src/tools/tests/coVector.test.ts +891 -0
  105. package/src/tools/tests/createContext.test.ts +19 -19
  106. package/src/tools/tests/deepLoading.test.ts +2 -2
  107. package/src/tools/tests/group.test.ts +59 -0
  108. package/src/tools/tests/inbox.test.ts +2 -2
  109. package/src/tools/tests/utils.ts +3 -3
  110. package/src/worker/index.ts +3 -3
  111. package/dist/chunk-BOMSRY5H.js.map +0 -1
  112. package/dist/chunk-W7JT3QUN.js.map +0 -1
@@ -2164,7 +2164,7 @@ var Account = class extends CoValueBase {
2164
2164
  *
2165
2165
  * @param valueID The ID of the `CoValue` or `Group` to accept the invite to.
2166
2166
  * @param inviteSecret The secret of the invite to accept.
2167
- * @param coValueClass The class of the `CoValue` or `Group` to accept the invite to.
2167
+ * @param coValueClass [Group] The class of the `CoValue` or `Group` to accept the invite to.
2168
2168
  * @returns The loaded `CoValue` or `Group`.
2169
2169
  */
2170
2170
  async acceptInvite(valueID, inviteSecret, coValueClass) {
@@ -2176,7 +2176,7 @@ var Account = class extends CoValueBase {
2176
2176
  inviteSecret
2177
2177
  );
2178
2178
  return loadCoValue(
2179
- coValueClassFromCoValueClassOrSchema(coValueClass),
2179
+ coValueClassFromCoValueClassOrSchema(coValueClass ?? Group5),
2180
2180
  valueID,
2181
2181
  {
2182
2182
  loadAs: this
@@ -2258,7 +2258,7 @@ var Account = class extends CoValueBase {
2258
2258
  const account = await this.create({
2259
2259
  creationProps: options.creationProps,
2260
2260
  crypto: as.$jazz.localNode.crypto,
2261
- peersToLoadFrom: [connectedPeers[0]]
2261
+ peers: [connectedPeers[0]]
2262
2262
  });
2263
2263
  await account.$jazz.waitForAllCoValuesSync();
2264
2264
  return account;
@@ -2646,9 +2646,27 @@ var _Group = class _Group extends CoValueBase {
2646
2646
  const { options, listener } = parseSubscribeRestArgs(args);
2647
2647
  return subscribeToCoValueWithoutMe(this, id, options, listener);
2648
2648
  }
2649
+ /** @category Invites
2650
+ * Creates a group invite
2651
+ * @param id The ID of the group to create an invite for
2652
+ * @param options Optional configuration
2653
+ * @param options.role The role to grant to the accepter of the invite. Defaults to 'reader'
2654
+ * @param options.loadAs The account to use when loading the group. Defaults to the current account
2655
+ * @returns An invite secret, (a string starting with "inviteSecret_"). Can be
2656
+ * accepted using `Account.acceptInvite()`
2657
+ */
2658
+ static async createInvite(id, options) {
2659
+ const group = await loadCoValueWithoutMe(this, id, {
2660
+ loadAs: options?.loadAs
2661
+ });
2662
+ if (!group) {
2663
+ throw new Error(`Group with id ${id} not found`);
2664
+ }
2665
+ return group.$jazz.createInvite(options?.role ?? "reader");
2666
+ }
2649
2667
  };
2650
2668
  _Group.prototype[TypeSym] = "Group";
2651
- var Group6 = _Group;
2669
+ var Group5 = _Group;
2652
2670
  var GroupJazzApi = class extends CoValueJazzApi {
2653
2671
  constructor(group, raw) {
2654
2672
  super(group);
@@ -2676,6 +2694,14 @@ var GroupJazzApi = class extends CoValueJazzApi {
2676
2694
  const { options, listener } = parseSubscribeRestArgs(args);
2677
2695
  return subscribeToExistingCoValue(this.group, options, listener);
2678
2696
  }
2697
+ /**
2698
+ * Create an invite to this group
2699
+ *
2700
+ * @category Invites
2701
+ */
2702
+ createInvite(role = "reader") {
2703
+ return this.raw.createInvite(role);
2704
+ }
2679
2705
  /**
2680
2706
  * Wait for the `Group` to be uploaded to the other peers.
2681
2707
  *
@@ -2685,7 +2711,7 @@ var GroupJazzApi = class extends CoValueJazzApi {
2685
2711
  return this.raw.core.waitForSync(options);
2686
2712
  }
2687
2713
  };
2688
- RegisteredSchemas["Group"] = Group6;
2714
+ RegisteredSchemas["Group"] = Group5;
2689
2715
  function isAccountID(id) {
2690
2716
  return id.startsWith("co_");
2691
2717
  }
@@ -3273,6 +3299,279 @@ var SchemaUnion = class _SchemaUnion extends CoValueBase {
3273
3299
  }
3274
3300
  };
3275
3301
 
3302
+ // src/tools/coValues/coVector.ts
3303
+ import { cojsonInternals as cojsonInternals5 } from "cojson";
3304
+ var _CoVector = class _CoVector extends Float32Array {
3305
+ static get [Symbol.species]() {
3306
+ return Float32Array;
3307
+ }
3308
+ constructor(options) {
3309
+ const dimensionsCount = new.target.requiredDimensionsCount;
3310
+ if (dimensionsCount === void 0) {
3311
+ throw new Error(
3312
+ "Instantiating CoVector without a dimensions count is not allowed. Use co.vector(...).create() instead."
3313
+ );
3314
+ }
3315
+ super(dimensionsCount);
3316
+ const isFromRaw = "fromRaw" in options;
3317
+ const raw = isFromRaw ? options.fromRaw : options.owner.$jazz.raw.createBinaryStream();
3318
+ Object.defineProperties(this, {
3319
+ [TypeSym]: { value: "BinaryCoStream", enumerable: false },
3320
+ $jazz: {
3321
+ value: new CoVectorJazzApi(this, raw),
3322
+ enumerable: false
3323
+ },
3324
+ _isVectorLoaded: { value: false, enumerable: false, writable: true },
3325
+ _requiredDimensionsCount: {
3326
+ value: dimensionsCount,
3327
+ enumerable: false,
3328
+ writable: false
3329
+ }
3330
+ });
3331
+ if (isFromRaw) {
3332
+ this.loadVectorData();
3333
+ }
3334
+ }
3335
+ /** @category Internals */
3336
+ static fromRaw(raw) {
3337
+ return new this({ fromRaw: raw });
3338
+ }
3339
+ /**
3340
+ * Create a new `CoVector` instance with the given vector.
3341
+ *
3342
+ * @category Creation
3343
+ * @deprecated Use `co.vector(...).create` instead.
3344
+ */
3345
+ static create(vector, options) {
3346
+ const vectorAsFloat32Array = vector instanceof Float32Array ? vector : new Float32Array(vector);
3347
+ const givenVectorDimensions = vectorAsFloat32Array.byteLength / vectorAsFloat32Array.BYTES_PER_ELEMENT;
3348
+ if (this.requiredDimensionsCount !== void 0 && givenVectorDimensions !== this.requiredDimensionsCount) {
3349
+ throw new Error(
3350
+ `Vector dimension mismatch! Expected ${this.requiredDimensionsCount} dimensions, got ${givenVectorDimensions}`
3351
+ );
3352
+ }
3353
+ const coVector = new this(parseCoValueCreateOptions(options));
3354
+ coVector.setVectorData(vectorAsFloat32Array);
3355
+ const byteArray = _CoVector.toByteArray(vectorAsFloat32Array);
3356
+ coVector.$jazz.raw.startBinaryStream({
3357
+ mimeType: "application/vector+octet-stream",
3358
+ totalSizeBytes: byteArray.byteLength
3359
+ });
3360
+ const chunkSize = cojsonInternals5.TRANSACTION_CONFIG.MAX_RECOMMENDED_TX_SIZE;
3361
+ for (let idx = 0; idx < byteArray.length; idx += chunkSize) {
3362
+ coVector.$jazz.raw.pushBinaryStreamChunk(
3363
+ byteArray.slice(idx, idx + chunkSize)
3364
+ );
3365
+ }
3366
+ coVector.$jazz.raw.endBinaryStream();
3367
+ return coVector;
3368
+ }
3369
+ static toByteArray(vector) {
3370
+ return new Uint8Array(vector.buffer, vector.byteOffset, vector.byteLength);
3371
+ }
3372
+ static fromByteArray(bytesChunks) {
3373
+ const total = bytesChunks.reduce((acc, c) => acc + c.byteLength, 0);
3374
+ if (total % 4 !== 0)
3375
+ throw new Error("[INTERNAL] Total byte length must be multiple of 4");
3376
+ const u8 = new Uint8Array(total);
3377
+ let off = 0;
3378
+ for (const c of bytesChunks) {
3379
+ u8.set(c, off);
3380
+ off += c.byteLength;
3381
+ }
3382
+ return new Float32Array(u8.buffer, u8.byteOffset, total / 4);
3383
+ }
3384
+ loadVectorData() {
3385
+ if (this._isVectorLoaded === true) {
3386
+ return;
3387
+ }
3388
+ const chunks = this.$jazz.raw.getBinaryChunks();
3389
+ if (!chunks) {
3390
+ throw new Error(`CoVector '${this.$jazz.raw.id}' is not loaded`);
3391
+ }
3392
+ const vector = _CoVector.fromByteArray(chunks.chunks);
3393
+ if (vector.length !== this._requiredDimensionsCount) {
3394
+ throw new Error(
3395
+ `Vector dimension mismatch! CoVector '${this.$jazz.raw.id}' loaded with ${vector.length} dimensions, but the schema requires ${this._requiredDimensionsCount} dimensions`
3396
+ );
3397
+ }
3398
+ this.setVectorData(vector);
3399
+ return;
3400
+ }
3401
+ setVectorData(vector) {
3402
+ super.set(vector, 0);
3403
+ this._isVectorLoaded = true;
3404
+ }
3405
+ /**
3406
+ * Get a JSON representation of the `CoVector`
3407
+ * @category Content
3408
+ */
3409
+ toJSON() {
3410
+ return Array.from(this);
3411
+ }
3412
+ /** @internal */
3413
+ [inspect]() {
3414
+ return this.toJSON();
3415
+ }
3416
+ /**
3417
+ * Load a `CoVector`
3418
+ *
3419
+ * @category Subscription & Loading
3420
+ * @deprecated Use `co.vector(...).load` instead.
3421
+ */
3422
+ static async load(id, options) {
3423
+ const coVector = await loadCoValueWithoutMe(this, id, options);
3424
+ if (!coVector?.$jazz.raw.isBinaryStreamEnded()) {
3425
+ return new Promise((resolve) => {
3426
+ subscribeToCoValueWithoutMe(
3427
+ this,
3428
+ id,
3429
+ options || {},
3430
+ (value, unsubscribe) => {
3431
+ if (value.$jazz.raw.isBinaryStreamEnded()) {
3432
+ unsubscribe();
3433
+ resolve(value);
3434
+ }
3435
+ }
3436
+ );
3437
+ });
3438
+ }
3439
+ coVector.loadVectorData();
3440
+ return coVector;
3441
+ }
3442
+ static subscribe(id, ...args) {
3443
+ const { options, listener } = parseSubscribeRestArgs(args);
3444
+ return subscribeToCoValueWithoutMe(this, id, options, listener);
3445
+ }
3446
+ // CoVector mutation method overrides, as CoVectors aren't meant to be mutated
3447
+ /**
3448
+ * Calling `copyWithin` on a CoVector is forbidden. CoVectors are immutable.
3449
+ * @deprecated If you want to change the vector, replace the former instance of CoVector with a new one.
3450
+ */
3451
+ copyWithin(target, start, end) {
3452
+ throw new Error("Cannot mutate a CoVector using `copyWithin`");
3453
+ }
3454
+ /**
3455
+ * Calling `fill` on a CoVector is forbidden. CoVectors are immutable.
3456
+ * @deprecated If you want to change the vector, replace the former instance of CoVector with a new one.
3457
+ */
3458
+ fill(value, start, end) {
3459
+ throw new Error("Cannot mutate a CoVector using `fill`");
3460
+ }
3461
+ /**
3462
+ * Calling `reverse` on a CoVector is forbidden. CoVectors are immutable.
3463
+ * @deprecated If you want to change the vector, replace the former instance of CoVector with a new one.
3464
+ */
3465
+ reverse() {
3466
+ throw new Error("Cannot mutate a CoVector using `reverse`");
3467
+ }
3468
+ /**
3469
+ * Calling `set` on a CoVector is forbidden. CoVectors are immutable.
3470
+ * @deprecated If you want to change the vector, replace the former instance of CoVector with a new one.
3471
+ // */
3472
+ set(array2, offset) {
3473
+ throw new Error("Cannot mutate a CoVector using `set`");
3474
+ }
3475
+ /**
3476
+ * Calling `sort` on a CoVector is forbidden. CoVectors are immutable.
3477
+ * @deprecated If you want to change the vector, replace the former instance of CoVector with a new one.
3478
+ */
3479
+ sort(compareFn) {
3480
+ throw new Error("Cannot mutate a CoVector using `sort`");
3481
+ }
3482
+ };
3483
+ _CoVector.requiredDimensionsCount = void 0;
3484
+ var CoVector = _CoVector;
3485
+ var CoVectorJazzApi = class extends CoValueJazzApi {
3486
+ constructor(coVector, raw) {
3487
+ super(coVector);
3488
+ this.coVector = coVector;
3489
+ this.raw = raw;
3490
+ }
3491
+ get owner() {
3492
+ return getCoValueOwner(this.coVector);
3493
+ }
3494
+ /**
3495
+ * An instance method to subscribe to an existing `CoVector`
3496
+ * @category Subscription & Loading
3497
+ */
3498
+ subscribe(listener) {
3499
+ return subscribeToExistingCoValue(this.coVector, {}, listener);
3500
+ }
3501
+ /**
3502
+ * Wait for the `CoVector` to be uploaded to the other peers.
3503
+ *
3504
+ * @category Subscription & Loading
3505
+ */
3506
+ waitForSync(options) {
3507
+ return this.raw.core.waitForSync(options);
3508
+ }
3509
+ // Vector operations
3510
+ /**
3511
+ * Calculate the magnitude of this vector.
3512
+ */
3513
+ magnitude() {
3514
+ return VectorCalculation.magnitude(this.coVector);
3515
+ }
3516
+ /**
3517
+ * Normalize this vector.
3518
+ * @returns A new instance of a normalized vector.
3519
+ */
3520
+ normalize() {
3521
+ return VectorCalculation.normalize(this.coVector);
3522
+ }
3523
+ /**
3524
+ * Calculate the dot product of this vector and another vector.
3525
+ */
3526
+ dotProduct(otherVector) {
3527
+ return VectorCalculation.dotProduct(this.coVector, otherVector);
3528
+ }
3529
+ /**
3530
+ * Calculate the cosine similarity between this vector and another vector.
3531
+ *
3532
+ * @returns A value between `-1` and `1`:
3533
+ * - `1` means the vectors are identical
3534
+ * - `0` means the vectors are orthogonal (i.e. no similarity)
3535
+ * - `-1` means the vectors are opposite direction (perfectly dissimilar)
3536
+ */
3537
+ cosineSimilarity(otherVector) {
3538
+ return VectorCalculation.cosineSimilarity(this.coVector, otherVector);
3539
+ }
3540
+ };
3541
+ var VectorCalculation = {
3542
+ magnitude: (vector) => {
3543
+ let sum = 0;
3544
+ for (const v of vector) {
3545
+ sum += v * v;
3546
+ }
3547
+ return Math.sqrt(sum);
3548
+ },
3549
+ normalize: (vector) => {
3550
+ const mag = VectorCalculation.magnitude(vector);
3551
+ if (mag === 0) {
3552
+ return new Float32Array(vector.length).fill(0);
3553
+ }
3554
+ return vector.map((v) => v / mag);
3555
+ },
3556
+ dotProduct: (vectorA, vectorB) => {
3557
+ if (vectorA.length !== vectorB.length) {
3558
+ throw new Error(
3559
+ `Vector dimensions don't match: ${vectorA.length} vs ${vectorB.length}`
3560
+ );
3561
+ }
3562
+ return vectorA.reduce((sum, a, i) => sum + a * vectorB[i], 0);
3563
+ },
3564
+ cosineSimilarity: (vectorA, vectorB) => {
3565
+ const magnitudeA = VectorCalculation.magnitude(vectorA);
3566
+ const magnitudeB = VectorCalculation.magnitude(vectorB);
3567
+ if (magnitudeA === 0 || magnitudeB === 0) {
3568
+ return 0;
3569
+ }
3570
+ const dotProductAB = VectorCalculation.dotProduct(vectorA, vectorB);
3571
+ return dotProductAB / (magnitudeA * magnitudeB);
3572
+ }
3573
+ };
3574
+
3276
3575
  // src/tools/implementation/anonymousJazzAgent.ts
3277
3576
  var _a;
3278
3577
  _a = TypeSym;
@@ -3514,7 +3813,7 @@ function instantiateRefEncodedWithInit(schema, init, parentOwner) {
3514
3813
  }
3515
3814
  const node = parentOwner.$jazz.localNode;
3516
3815
  const rawGroup = node.createGroup();
3517
- const owner = new Group6({ fromRaw: rawGroup });
3816
+ const owner = new Group5({ fromRaw: rawGroup });
3518
3817
  owner.addMember(parentOwner);
3519
3818
  return schema.ref.create(init, owner);
3520
3819
  }
@@ -3534,7 +3833,7 @@ function applyCoValueMigrations(instance) {
3534
3833
 
3535
3834
  // src/tools/subscribe/CoValueCoreSubscription.ts
3536
3835
  import {
3537
- cojsonInternals as cojsonInternals5
3836
+ cojsonInternals as cojsonInternals6
3538
3837
  } from "cojson";
3539
3838
  var CoValueCoreSubscription = class {
3540
3839
  constructor(localNode, id, listener, skipRetry, branch) {
@@ -3581,7 +3880,7 @@ var CoValueCoreSubscription = class {
3581
3880
  * Either subscribes directly or attempts to get the requested branch.
3582
3881
  */
3583
3882
  handleAvailableSource() {
3584
- if (!this.branchName || !cojsonInternals5.canBeBranched(this.source)) {
3883
+ if (!this.branchName || !cojsonInternals6.canBeBranched(this.source)) {
3585
3884
  this.subscribe(this.source.getCurrentContent());
3586
3885
  return;
3587
3886
  }
@@ -4344,7 +4643,7 @@ async function randomSessionProvider(accountID, crypto) {
4344
4643
  }
4345
4644
  async function createJazzContextFromExistingCredentials({
4346
4645
  credentials,
4347
- peersToLoadFrom,
4646
+ peers,
4348
4647
  crypto,
4349
4648
  storage,
4350
4649
  AccountSchema: PropsAccountSchema,
@@ -4362,7 +4661,7 @@ async function createJazzContextFromExistingCredentials({
4362
4661
  accountID: credentials.accountID,
4363
4662
  accountSecret: credentials.secret,
4364
4663
  sessionID,
4365
- peersToLoadFrom,
4664
+ peers,
4366
4665
  crypto,
4367
4666
  storage,
4368
4667
  migration: async (rawAccount, _node, creationProps) => {
@@ -4394,7 +4693,7 @@ async function createJazzContextFromExistingCredentials({
4394
4693
  async function createJazzContextForNewAccount({
4395
4694
  creationProps,
4396
4695
  initialAgentSecret,
4397
- peersToLoadFrom,
4696
+ peers,
4398
4697
  crypto,
4399
4698
  AccountSchema: PropsAccountSchema,
4400
4699
  onLogOut,
@@ -4404,7 +4703,7 @@ async function createJazzContextForNewAccount({
4404
4703
  const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
4405
4704
  const { node } = await LocalNode4.withNewlyCreatedAccount({
4406
4705
  creationProps,
4407
- peersToLoadFrom,
4706
+ peers,
4408
4707
  crypto,
4409
4708
  initialAgentSecret,
4410
4709
  storage,
@@ -4440,7 +4739,7 @@ async function createJazzContext(options) {
4440
4739
  accountID: credentials.accountID,
4441
4740
  secret: credentials.accountSecret
4442
4741
  },
4443
- peersToLoadFrom: options.peersToLoadFrom,
4742
+ peers: options.peers,
4444
4743
  crypto,
4445
4744
  AccountSchema: options.AccountSchema,
4446
4745
  sessionProvider: options.sessionProvider,
@@ -4459,7 +4758,7 @@ async function createJazzContext(options) {
4459
4758
  context = await createJazzContextForNewAccount({
4460
4759
  creationProps,
4461
4760
  initialAgentSecret,
4462
- peersToLoadFrom: options.peersToLoadFrom,
4761
+ peers: options.peers,
4463
4762
  crypto,
4464
4763
  AccountSchema: options.AccountSchema,
4465
4764
  onLogOut: async () => {
@@ -4482,7 +4781,7 @@ async function createJazzContext(options) {
4482
4781
  };
4483
4782
  }
4484
4783
  function createAnonymousJazzContext({
4485
- peersToLoadFrom,
4784
+ peers,
4486
4785
  crypto,
4487
4786
  storage
4488
4787
  }) {
@@ -4492,7 +4791,7 @@ function createAnonymousJazzContext({
4492
4791
  crypto.newRandomSessionID(crypto.getAgentID(agentSecret)),
4493
4792
  crypto
4494
4793
  );
4495
- for (const peer of peersToLoadFrom) {
4794
+ for (const peer of peers) {
4496
4795
  node.syncManager.addPeer(peer);
4497
4796
  }
4498
4797
  if (storage) {
@@ -4620,19 +4919,22 @@ var GroupSchema = class {
4620
4919
  this.builtin = "Group";
4621
4920
  }
4622
4921
  getCoValueClass() {
4623
- return Group6;
4922
+ return Group5;
4624
4923
  }
4625
4924
  optional() {
4626
4925
  return coOptionalDefiner(this);
4627
4926
  }
4628
4927
  create(options) {
4629
- return Group6.create(options);
4928
+ return Group5.create(options);
4630
4929
  }
4631
4930
  load(id, options) {
4632
- return Group6.load(id, options);
4931
+ return Group5.load(id, options);
4932
+ }
4933
+ createInvite(id, options) {
4934
+ return Group5.createInvite(id, options);
4633
4935
  }
4634
4936
  subscribe(id, ...args) {
4635
- return Group6.subscribe(id, ...args);
4937
+ return Group5.subscribe(id, ...args);
4636
4938
  }
4637
4939
  };
4638
4940
 
@@ -4711,6 +5013,16 @@ var coFileStreamDefiner = () => {
4711
5013
  const coreSchema = createCoreFileStreamSchema();
4712
5014
  return hydrateCoreCoValueSchema(coreSchema);
4713
5015
  };
5016
+ var coVectorDefiner = (dimensions) => {
5017
+ const isPositiveInteger = Number.isInteger(dimensions) && dimensions > 0;
5018
+ if (!isPositiveInteger) {
5019
+ throw new Error(
5020
+ "co.vector() expects the vector dimensions count to be a positive integer"
5021
+ );
5022
+ }
5023
+ const coreSchema = createCoreCoVectorSchema(dimensions);
5024
+ return hydrateCoreCoValueSchema(coreSchema);
5025
+ };
4714
5026
  var coPlainTextDefiner = () => {
4715
5027
  const coreSchema = createCoreCoPlainTextSchema();
4716
5028
  return hydrateCoreCoValueSchema(coreSchema);
@@ -4744,6 +5056,7 @@ __export(coExport_exports, {
4744
5056
  Optional: () => CoOptionalSchema,
4745
5057
  PlainText: () => PlainTextSchema,
4746
5058
  RichText: () => RichTextSchema,
5059
+ Vector: () => CoVectorSchema,
4747
5060
  account: () => coAccountDefiner,
4748
5061
  discriminatedUnion: () => coDiscriminatedUnionDefiner,
4749
5062
  feed: () => coFeedDefiner,
@@ -4756,7 +5069,8 @@ __export(coExport_exports, {
4756
5069
  plainText: () => coPlainTextDefiner,
4757
5070
  profile: () => coProfileDefiner,
4758
5071
  record: () => coRecordDefiner,
4759
- richText: () => coRichTextDefiner
5072
+ richText: () => coRichTextDefiner,
5073
+ vector: () => coVectorDefiner
4760
5074
  });
4761
5075
 
4762
5076
  // src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts
@@ -5023,6 +5337,41 @@ var FileStreamSchema = class {
5023
5337
  }
5024
5338
  };
5025
5339
 
5340
+ // src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts
5341
+ function createCoreCoVectorSchema(dimensions) {
5342
+ return {
5343
+ collaborative: true,
5344
+ builtin: "CoVector",
5345
+ dimensions
5346
+ };
5347
+ }
5348
+ var CoVectorSchema = class {
5349
+ constructor(dimensions, coValueClass) {
5350
+ this.dimensions = dimensions;
5351
+ this.coValueClass = coValueClass;
5352
+ this.collaborative = true;
5353
+ this.builtin = "CoVector";
5354
+ }
5355
+ create(vector, options) {
5356
+ return this.coValueClass.create(vector, options);
5357
+ }
5358
+ /**
5359
+ * Load a `CoVector` with a given ID.
5360
+ */
5361
+ load(id, options) {
5362
+ return this.coValueClass.load(id, options);
5363
+ }
5364
+ subscribe(...args) {
5365
+ return this.coValueClass.subscribe(...args);
5366
+ }
5367
+ getCoValueClass() {
5368
+ return this.coValueClass;
5369
+ }
5370
+ optional() {
5371
+ return coOptionalDefiner(this);
5372
+ }
5373
+ };
5374
+
5026
5375
  // src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts
5027
5376
  function createCoreAccountSchema(shape) {
5028
5377
  return {
@@ -5289,6 +5638,7 @@ function isCoValueSchema(schema) {
5289
5638
  return isAnyCoValueSchema2(schema) && "getCoValueClass" in schema;
5290
5639
  }
5291
5640
  function hydrateCoreCoValueSchema(schema) {
5641
+ var _a2;
5292
5642
  if (isCoValueSchema(schema)) {
5293
5643
  return schema;
5294
5644
  }
@@ -5337,6 +5687,14 @@ function hydrateCoreCoValueSchema(schema) {
5337
5687
  } else if (schema.builtin === "FileStream") {
5338
5688
  const coValueClass = FileStream;
5339
5689
  return new FileStreamSchema(coValueClass);
5690
+ } else if (schema.builtin === "CoVector") {
5691
+ const dimensions = schema.dimensions;
5692
+ const coValueClass = (_a2 = class extends CoVector {
5693
+ }, _a2.requiredDimensionsCount = dimensions, _a2);
5694
+ return new CoVectorSchema(
5695
+ dimensions,
5696
+ coValueClass
5697
+ );
5340
5698
  } else if (schema.builtin === "CoPlainText") {
5341
5699
  const coValueClass = CoPlainText;
5342
5700
  return new PlainTextSchema(coValueClass);
@@ -5375,7 +5733,7 @@ var ImageDefinitionBase = coMapDefiner({
5375
5733
  var ImageDefinition = ImageDefinitionBase;
5376
5734
 
5377
5735
  // src/tools/implementation/ContextManager.ts
5378
- import { cojsonInternals as cojsonInternals6 } from "cojson";
5736
+ import { cojsonInternals as cojsonInternals7 } from "cojson";
5379
5737
  import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
5380
5738
 
5381
5739
  // src/tools/auth/KvStoreContext.ts
@@ -5407,20 +5765,26 @@ var KvStoreContext = class _KvStoreContext {
5407
5765
  var KvStoreContext_default = KvStoreContext;
5408
5766
 
5409
5767
  // src/tools/auth/AuthSecretStorage.ts
5768
+ import { z as z2 } from "zod/v4";
5410
5769
  var STORAGE_KEY = "jazz-logged-in-secret";
5411
5770
  var AuthSecretStorage = class {
5412
- constructor() {
5771
+ constructor(storageKey = STORAGE_KEY) {
5772
+ this.storageKey = storageKey;
5773
+ z2.string().nonempty().parse(storageKey);
5413
5774
  this.listeners = /* @__PURE__ */ new Set();
5414
5775
  this.isAuthenticated = false;
5415
5776
  }
5777
+ getStorageKey() {
5778
+ return this.storageKey;
5779
+ }
5416
5780
  async migrate() {
5417
5781
  const kvStore = KvStoreContext_default.getInstance().getStorage();
5418
- if (!await kvStore.get(STORAGE_KEY)) {
5782
+ if (!await kvStore.get(this.storageKey)) {
5419
5783
  const demoAuthSecret = await kvStore.get("demo-auth-logged-in-secret");
5420
5784
  if (demoAuthSecret) {
5421
5785
  const parsed = JSON.parse(demoAuthSecret);
5422
5786
  await kvStore.set(
5423
- STORAGE_KEY,
5787
+ this.storageKey,
5424
5788
  JSON.stringify({
5425
5789
  accountID: parsed.accountID,
5426
5790
  accountSecret: parsed.accountSecret,
@@ -5433,7 +5797,7 @@ var AuthSecretStorage = class {
5433
5797
  if (clerkAuthSecret) {
5434
5798
  const parsed = JSON.parse(clerkAuthSecret);
5435
5799
  await kvStore.set(
5436
- STORAGE_KEY,
5800
+ this.storageKey,
5437
5801
  JSON.stringify({
5438
5802
  accountID: parsed.accountID,
5439
5803
  accountSecret: parsed.secret,
@@ -5443,12 +5807,12 @@ var AuthSecretStorage = class {
5443
5807
  await kvStore.delete("jazz-clerk-auth");
5444
5808
  }
5445
5809
  }
5446
- const value = await kvStore.get(STORAGE_KEY);
5810
+ const value = await kvStore.get(this.storageKey);
5447
5811
  if (value) {
5448
5812
  const parsed = JSON.parse(value);
5449
5813
  if ("secret" in parsed) {
5450
5814
  await kvStore.set(
5451
- STORAGE_KEY,
5815
+ this.storageKey,
5452
5816
  JSON.stringify({
5453
5817
  accountID: parsed.accountID,
5454
5818
  secretSeed: parsed.secretSeed,
@@ -5461,7 +5825,7 @@ var AuthSecretStorage = class {
5461
5825
  }
5462
5826
  async get() {
5463
5827
  const kvStore = KvStoreContext_default.getInstance().getStorage();
5464
- const data = await kvStore.get(STORAGE_KEY);
5828
+ const data = await kvStore.get(this.storageKey);
5465
5829
  if (!data) return null;
5466
5830
  const parsed = JSON.parse(data);
5467
5831
  if (!parsed.accountID || !parsed.accountSecret) {
@@ -5477,7 +5841,7 @@ var AuthSecretStorage = class {
5477
5841
  async setWithoutNotify(payload) {
5478
5842
  const kvStore = KvStoreContext_default.getInstance().getStorage();
5479
5843
  await kvStore.set(
5480
- STORAGE_KEY,
5844
+ this.storageKey,
5481
5845
  JSON.stringify({
5482
5846
  accountID: payload.accountID,
5483
5847
  secretSeed: payload.secretSeed ? Array.from(payload.secretSeed) : void 0,
@@ -5510,7 +5874,7 @@ var AuthSecretStorage = class {
5510
5874
  }
5511
5875
  async clearWithoutNotify() {
5512
5876
  const kvStore = KvStoreContext_default.getInstance().getStorage();
5513
- await kvStore.delete(STORAGE_KEY);
5877
+ await kvStore.delete(this.storageKey);
5514
5878
  }
5515
5879
  async clear() {
5516
5880
  await this.clearWithoutNotify();
@@ -5542,7 +5906,7 @@ var InMemoryKVStore = class {
5542
5906
  // src/tools/implementation/ContextManager.ts
5543
5907
  function getAnonymousFallback() {
5544
5908
  const context = createAnonymousJazzContext({
5545
- peersToLoadFrom: [],
5909
+ peers: [],
5546
5910
  crypto: new PureJSCrypto()
5547
5911
  });
5548
5912
  return {
@@ -5565,7 +5929,6 @@ function getAnonymousFallback() {
5565
5929
  }
5566
5930
  var JazzContextManager = class {
5567
5931
  constructor(opts) {
5568
- this.authSecretStorage = new AuthSecretStorage();
5569
5932
  this.keepContextOpen = false;
5570
5933
  this.authenticatingAccountID = null;
5571
5934
  this.logOut = async () => {
@@ -5669,6 +6032,7 @@ var JazzContextManager = class {
5669
6032
  };
5670
6033
  };
5671
6034
  KvStoreContext.getInstance().initialize(this.getKvStore());
6035
+ this.authSecretStorage = new AuthSecretStorage(opts?.authSecretStorageKey);
5672
6036
  if (opts?.useAnonymousFallback) {
5673
6037
  this.value = getAnonymousFallback();
5674
6038
  }
@@ -5740,7 +6104,7 @@ var JazzContextManager = class {
5740
6104
  }
5741
6105
  const currentContext = this.context;
5742
6106
  if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
5743
- const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals6.connectedPeers(
6107
+ const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals7.connectedPeers(
5744
6108
  prevContext.me.$jazz.id,
5745
6109
  currentContext.me.$jazz.id,
5746
6110
  {
@@ -5960,7 +6324,9 @@ function subscribeToCoValue(cls, id, options, listener) {
5960
6324
  if (unsubscribed) return;
5961
6325
  if (value.type === "unavailable") {
5962
6326
  options.onUnavailable?.();
5963
- console.error(value.toString());
6327
+ if (!options.skipRetry) {
6328
+ console.error(value.toString());
6329
+ }
5964
6330
  } else if (value.type === "unauthorized") {
5965
6331
  options.onUnauthorized?.();
5966
6332
  console.error(value.toString());
@@ -6006,9 +6372,9 @@ function isAccountInstance(instance) {
6006
6372
  return TypeSym in instance && instance[TypeSym] === "Account";
6007
6373
  }
6008
6374
  function parseCoValueCreateOptions(options) {
6009
- const Group17 = RegisteredSchemas["Group"];
6375
+ const Group18 = RegisteredSchemas["Group"];
6010
6376
  if (!options) {
6011
- return { owner: Group17.create(), uniqueness: void 0 };
6377
+ return { owner: Group18.create(), uniqueness: void 0 };
6012
6378
  }
6013
6379
  if (TypeSym in options) {
6014
6380
  if (options[TypeSym] === "Account") {
@@ -6019,7 +6385,7 @@ function parseCoValueCreateOptions(options) {
6019
6385
  }
6020
6386
  const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
6021
6387
  const opts = {
6022
- owner: options.owner ? accountOrGroupToGroup(options.owner) : Group17.create(),
6388
+ owner: options.owner ? accountOrGroupToGroup(options.owner) : Group18.create(),
6023
6389
  uniqueness
6024
6390
  };
6025
6391
  return opts;
@@ -6168,7 +6534,7 @@ export {
6168
6534
  FileStream,
6169
6535
  Account,
6170
6536
  isControlledAccount,
6171
- Group6 as Group,
6537
+ Group5 as Group,
6172
6538
  Profile,
6173
6539
  isCoValueId,
6174
6540
  Inbox,
@@ -6197,4 +6563,4 @@ export {
6197
6563
  JazzContextManager
6198
6564
  };
6199
6565
  /* istanbul ignore file -- @preserve */
6200
- //# sourceMappingURL=chunk-W7JT3QUN.js.map
6566
+ //# sourceMappingURL=chunk-ZIAN4UY5.js.map