jazz-tools 0.18.25 → 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 (40) hide show
  1. package/.turbo/turbo-build.log +44 -44
  2. package/CHANGELOG.md +10 -0
  3. package/dist/{chunk-DOCEAUVD.js → chunk-ZIAN4UY5.js} +338 -9
  4. package/dist/chunk-ZIAN4UY5.js.map +1 -0
  5. package/dist/index.js +1 -1
  6. package/dist/testing.js +1 -1
  7. package/dist/tools/coValues/coVector.d.ts +127 -0
  8. package/dist/tools/coValues/coVector.d.ts.map +1 -0
  9. package/dist/tools/implementation/zodSchema/coExport.d.ts +2 -1
  10. package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
  11. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
  12. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +47 -0
  13. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -0
  14. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +2 -2
  15. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  16. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +2 -2
  17. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  18. package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -1
  19. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  20. package/dist/tools/implementation/zodSchema/zodSchema.d.ts +3 -2
  21. package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  22. package/dist/tools/internal.d.ts +2 -0
  23. package/dist/tools/internal.d.ts.map +1 -1
  24. package/dist/tools/tests/coVector.test-d.d.ts +2 -0
  25. package/dist/tools/tests/coVector.test-d.d.ts.map +1 -0
  26. package/dist/tools/tests/coVector.test.d.ts +2 -0
  27. package/dist/tools/tests/coVector.test.d.ts.map +1 -0
  28. package/package.json +4 -4
  29. package/src/tools/coValues/coVector.ts +432 -0
  30. package/src/tools/implementation/zodSchema/coExport.ts +2 -0
  31. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +13 -0
  32. package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +105 -0
  33. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +9 -5
  34. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +15 -9
  35. package/src/tools/implementation/zodSchema/zodCo.ts +15 -0
  36. package/src/tools/implementation/zodSchema/zodSchema.ts +15 -6
  37. package/src/tools/internal.ts +2 -0
  38. package/src/tools/tests/coVector.test-d.ts +40 -0
  39. package/src/tools/tests/coVector.test.ts +891 -0
  40. package/dist/chunk-DOCEAUVD.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.18.25 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.18.26 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup && pnpm types && pnpm build:svelte
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts","tools/ssr":"src/tools/ssr/index.ts"}
@@ -109,24 +109,24 @@
109
109
  ESM Build start
110
110
  ESM dist/tiptap/index.js 564.00 B
111
111
  ESM dist/tiptap/index.js.map 1.21 KB
112
- ESM ⚡️ Build success in 36ms
113
- ESM dist/worker/index.js 3.16 KB
112
+ ESM ⚡️ Build success in 44ms
114
113
  ESM dist/worker/edge-wasm.js 215.00 B
114
+ ESM dist/worker/index.js 3.16 KB
115
115
  ESM dist/worker/napi-crypto.js 110.00 B
116
- ESM dist/worker/index.js.map 6.14 KB
117
116
  ESM dist/worker/edge-wasm.js.map 434.00 B
118
117
  ESM dist/worker/napi-crypto.js.map 162.00 B
119
- ESM ⚡️ Build success in 37ms
120
- ESM dist/better-auth/auth/client.js 4.50 KB
118
+ ESM dist/worker/index.js.map 6.14 KB
119
+ ESM ⚡️ Build success in 42ms
121
120
  ESM dist/better-auth/auth/server.js 8.36 KB
121
+ ESM dist/better-auth/auth/client.js 4.50 KB
122
122
  ESM dist/better-auth/auth/react.js 799.00 B
123
123
  ESM dist/better-auth/auth/server.js.map 15.29 KB
124
124
  ESM dist/better-auth/auth/client.js.map 8.32 KB
125
125
  ESM dist/better-auth/auth/react.js.map 2.04 KB
126
- ESM ⚡️ Build success in 33ms
126
+ ESM ⚡️ Build success in 34ms
127
127
  ESM dist/media/index.js 236.00 B
128
- ESM dist/media/index.browser.js 2.79 KB
129
128
  ESM dist/media/index.native.js 2.90 KB
129
+ ESM dist/media/index.browser.js 2.79 KB
130
130
  ESM dist/media/index.server.js 2.95 KB
131
131
  ESM dist/media/chunk-W3S526L3.js 6.47 KB
132
132
  ESM dist/media/index.js.map 71.00 B
@@ -134,78 +134,78 @@
134
134
  ESM dist/media/index.browser.js.map 6.15 KB
135
135
  ESM dist/media/index.server.js.map 6.37 KB
136
136
  ESM dist/media/chunk-W3S526L3.js.map 16.57 KB
137
- ESM ⚡️ Build success in 39ms
137
+ ESM ⚡️ Build success in 43ms
138
+ ESM dist/react-native/index.js 2.53 KB
138
139
  ESM dist/react-native/testing.js 120.00 B
139
140
  ESM dist/react-native/crypto.js 161.00 B
140
- ESM dist/react-native/index.js 2.53 KB
141
+ ESM dist/react-native/index.js.map 5.68 KB
141
142
  ESM dist/react-native/testing.js.map 176.00 B
142
143
  ESM dist/react-native/crypto.js.map 197.00 B
143
- ESM dist/react-native/index.js.map 5.68 KB
144
- ESM ⚡️ Build success in 36ms
144
+ ESM ⚡️ Build success in 40ms
145
145
  ESM dist/react-core/index.js 13.94 KB
146
146
  ESM dist/react-core/testing.js 1.22 KB
147
147
  ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
148
- ESM dist/react-core/testing.js.map 1.86 KB
149
148
  ESM dist/react-core/index.js.map 42.53 KB
150
149
  ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
151
- ESM ⚡️ Build success in 38ms
150
+ ESM dist/react-core/testing.js.map 1.86 KB
151
+ ESM ⚡️ Build success in 42ms
152
+ ESM dist/browser/index.js 14.06 KB
153
+ ESM dist/browser/index.js.map 29.94 KB
154
+ ESM ⚡️ Build success in 46ms
152
155
  ESM dist/expo/index.js 4.68 KB
153
156
  ESM dist/expo/testing.js 112.00 B
154
157
  ESM dist/expo/crypto.js 153.00 B
155
158
  ESM dist/expo/index.js.map 10.23 KB
156
159
  ESM dist/expo/crypto.js.map 189.00 B
157
160
  ESM dist/expo/testing.js.map 168.00 B
158
- ESM ⚡️ Build success in 34ms
159
- ESM dist/browser/index.js 14.06 KB
160
- ESM dist/browser/index.js.map 29.94 KB
161
- ESM ⚡️ Build success in 45ms
161
+ ESM ⚡️ Build success in 39ms
162
162
  ESM dist/better-auth/database-adapter/index.js 26.34 KB
163
163
  ESM dist/better-auth/database-adapter/index.js.map 57.62 KB
164
- ESM ⚡️ Build success in 40ms
165
- ESM dist/react-native-core/index.js 18.93 KB
166
- ESM dist/react-native-core/testing.js 119.00 B
167
- ESM dist/react-native-core/crypto.js 2.10 KB
168
- ESM dist/react-native-core/index.js.map 38.12 KB
169
- ESM dist/react-native-core/crypto.js.map 4.25 KB
170
- ESM dist/react-native-core/testing.js.map 175.00 B
171
- ESM ⚡️ Build success in 49ms
164
+ ESM ⚡️ Build success in 46ms
165
+ ESM dist/prosemirror/index.js 77.76 KB
166
+ ESM dist/prosemirror/index.js.map 307.20 KB
167
+ ESM ⚡️ Build success in 58ms
168
+ ESM dist/react/index.js 25.32 KB
172
169
  ESM dist/react/testing.js 122.00 B
173
170
  ESM dist/react/ssr.js 697.00 B
174
- ESM dist/react/index.js 25.32 KB
175
171
  ESM dist/react/testing.js.map 165.00 B
176
172
  ESM dist/react/ssr.js.map 1.11 KB
177
173
  ESM dist/react/index.js.map 54.26 KB
178
- ESM ⚡️ Build success in 43ms
179
- ESM dist/prosemirror/index.js 77.76 KB
180
- ESM dist/prosemirror/index.js.map 307.20 KB
181
- ESM ⚡️ Build success in 59ms
174
+ ESM ⚡️ Build success in 50ms
175
+ ESM dist/react-native-core/index.js 18.93 KB
176
+ ESM dist/react-native-core/testing.js 119.00 B
177
+ ESM dist/react-native-core/crypto.js 2.10 KB
178
+ ESM dist/react-native-core/testing.js.map 175.00 B
179
+ ESM dist/react-native-core/crypto.js.map 4.25 KB
180
+ ESM dist/react-native-core/index.js.map 38.12 KB
181
+ ESM ⚡️ Build success in 58ms
182
182
  ESM dist/inspector/index.js 71.88 KB
183
183
  ESM dist/inspector/index.js.map 124.87 KB
184
- ESM ⚡️ Build success in 61ms
185
- ESM dist/tools/ssr.js 156.00 B
186
- ESM dist/index.js 26.24 KB
187
- ESM dist/chunk-M2HGBOXS.js 694.00 B
184
+ ESM ⚡️ Build success in 67ms
188
185
  ESM dist/chunk-PZ5AY32C.js 233.00 B
186
+ ESM dist/chunk-M2HGBOXS.js 694.00 B
189
187
  ESM dist/testing.js 8.32 KB
190
- ESM dist/chunk-DOCEAUVD.js 178.74 KB
191
- ESM dist/tools/ssr.js.map 71.00 B
192
- ESM dist/chunk-M2HGBOXS.js.map 1.10 KB
193
- ESM dist/index.js.map 52.92 KB
188
+ ESM dist/tools/ssr.js 156.00 B
189
+ ESM dist/index.js 26.24 KB
190
+ ESM dist/chunk-ZIAN4UY5.js 189.00 KB
194
191
  ESM dist/chunk-PZ5AY32C.js.map 71.00 B
192
+ ESM dist/chunk-M2HGBOXS.js.map 1.10 KB
193
+ ESM dist/tools/ssr.js.map 71.00 B
195
194
  ESM dist/testing.js.map 15.83 KB
196
- ESM dist/chunk-DOCEAUVD.js.map 425.24 KB
197
- ESM ⚡️ Build success in 66ms
195
+ ESM dist/index.js.map 52.92 KB
196
+ ESM dist/chunk-ZIAN4UY5.js.map 447.28 KB
197
+ ESM ⚡️ Build success in 75ms
198
198
  ESM dist/inspector/register-custom-element.js 218.00 B
199
199
  ESM dist/inspector/register-custom-element.js.map 314.00 B
200
200
  ESM dist/inspector/custom-element-A7UAELEG.js 1.54 MB
201
201
  ESM dist/inspector/custom-element-A7UAELEG.js.map 2.36 MB
202
- ESM ⚡️ Build success in 115ms
202
+ ESM ⚡️ Build success in 121ms
203
203
 
204
- > jazz-tools@0.18.25 types /home/runner/_work/jazz/jazz/packages/jazz-tools
204
+ > jazz-tools@0.18.26 types /home/runner/_work/jazz/jazz/packages/jazz-tools
205
205
  > tsc --outDir dist
206
206
 
207
207
 
208
- > jazz-tools@0.18.25 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
208
+ > jazz-tools@0.18.26 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
209
209
  > rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
210
210
 
211
211
  src/svelte -> dist/svelte
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.18.26
4
+
5
+ ### Patch Changes
6
+
7
+ - 4e0ea26: Added new CoVector type of CoValue
8
+ - Updated dependencies [f956cd3]
9
+ - cojson@0.18.26
10
+ - cojson-storage-indexeddb@0.18.26
11
+ - cojson-transport-ws@0.18.26
12
+
3
13
  ## 0.18.25
4
14
 
5
15
  ### Patch Changes
@@ -3299,6 +3299,279 @@ var SchemaUnion = class _SchemaUnion extends CoValueBase {
3299
3299
  }
3300
3300
  };
3301
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
+
3302
3575
  // src/tools/implementation/anonymousJazzAgent.ts
3303
3576
  var _a;
3304
3577
  _a = TypeSym;
@@ -3560,7 +3833,7 @@ function applyCoValueMigrations(instance) {
3560
3833
 
3561
3834
  // src/tools/subscribe/CoValueCoreSubscription.ts
3562
3835
  import {
3563
- cojsonInternals as cojsonInternals5
3836
+ cojsonInternals as cojsonInternals6
3564
3837
  } from "cojson";
3565
3838
  var CoValueCoreSubscription = class {
3566
3839
  constructor(localNode, id, listener, skipRetry, branch) {
@@ -3607,7 +3880,7 @@ var CoValueCoreSubscription = class {
3607
3880
  * Either subscribes directly or attempts to get the requested branch.
3608
3881
  */
3609
3882
  handleAvailableSource() {
3610
- if (!this.branchName || !cojsonInternals5.canBeBranched(this.source)) {
3883
+ if (!this.branchName || !cojsonInternals6.canBeBranched(this.source)) {
3611
3884
  this.subscribe(this.source.getCurrentContent());
3612
3885
  return;
3613
3886
  }
@@ -4740,6 +5013,16 @@ var coFileStreamDefiner = () => {
4740
5013
  const coreSchema = createCoreFileStreamSchema();
4741
5014
  return hydrateCoreCoValueSchema(coreSchema);
4742
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
+ };
4743
5026
  var coPlainTextDefiner = () => {
4744
5027
  const coreSchema = createCoreCoPlainTextSchema();
4745
5028
  return hydrateCoreCoValueSchema(coreSchema);
@@ -4773,6 +5056,7 @@ __export(coExport_exports, {
4773
5056
  Optional: () => CoOptionalSchema,
4774
5057
  PlainText: () => PlainTextSchema,
4775
5058
  RichText: () => RichTextSchema,
5059
+ Vector: () => CoVectorSchema,
4776
5060
  account: () => coAccountDefiner,
4777
5061
  discriminatedUnion: () => coDiscriminatedUnionDefiner,
4778
5062
  feed: () => coFeedDefiner,
@@ -4785,7 +5069,8 @@ __export(coExport_exports, {
4785
5069
  plainText: () => coPlainTextDefiner,
4786
5070
  profile: () => coProfileDefiner,
4787
5071
  record: () => coRecordDefiner,
4788
- richText: () => coRichTextDefiner
5072
+ richText: () => coRichTextDefiner,
5073
+ vector: () => coVectorDefiner
4789
5074
  });
4790
5075
 
4791
5076
  // src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts
@@ -5052,6 +5337,41 @@ var FileStreamSchema = class {
5052
5337
  }
5053
5338
  };
5054
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
+
5055
5375
  // src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts
5056
5376
  function createCoreAccountSchema(shape) {
5057
5377
  return {
@@ -5318,6 +5638,7 @@ function isCoValueSchema(schema) {
5318
5638
  return isAnyCoValueSchema2(schema) && "getCoValueClass" in schema;
5319
5639
  }
5320
5640
  function hydrateCoreCoValueSchema(schema) {
5641
+ var _a2;
5321
5642
  if (isCoValueSchema(schema)) {
5322
5643
  return schema;
5323
5644
  }
@@ -5366,6 +5687,14 @@ function hydrateCoreCoValueSchema(schema) {
5366
5687
  } else if (schema.builtin === "FileStream") {
5367
5688
  const coValueClass = FileStream;
5368
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
+ );
5369
5698
  } else if (schema.builtin === "CoPlainText") {
5370
5699
  const coValueClass = CoPlainText;
5371
5700
  return new PlainTextSchema(coValueClass);
@@ -5404,7 +5733,7 @@ var ImageDefinitionBase = coMapDefiner({
5404
5733
  var ImageDefinition = ImageDefinitionBase;
5405
5734
 
5406
5735
  // src/tools/implementation/ContextManager.ts
5407
- import { cojsonInternals as cojsonInternals6 } from "cojson";
5736
+ import { cojsonInternals as cojsonInternals7 } from "cojson";
5408
5737
  import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
5409
5738
 
5410
5739
  // src/tools/auth/KvStoreContext.ts
@@ -5775,7 +6104,7 @@ var JazzContextManager = class {
5775
6104
  }
5776
6105
  const currentContext = this.context;
5777
6106
  if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
5778
- const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals6.connectedPeers(
6107
+ const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals7.connectedPeers(
5779
6108
  prevContext.me.$jazz.id,
5780
6109
  currentContext.me.$jazz.id,
5781
6110
  {
@@ -6043,9 +6372,9 @@ function isAccountInstance(instance) {
6043
6372
  return TypeSym in instance && instance[TypeSym] === "Account";
6044
6373
  }
6045
6374
  function parseCoValueCreateOptions(options) {
6046
- const Group16 = RegisteredSchemas["Group"];
6375
+ const Group18 = RegisteredSchemas["Group"];
6047
6376
  if (!options) {
6048
- return { owner: Group16.create(), uniqueness: void 0 };
6377
+ return { owner: Group18.create(), uniqueness: void 0 };
6049
6378
  }
6050
6379
  if (TypeSym in options) {
6051
6380
  if (options[TypeSym] === "Account") {
@@ -6056,7 +6385,7 @@ function parseCoValueCreateOptions(options) {
6056
6385
  }
6057
6386
  const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
6058
6387
  const opts = {
6059
- owner: options.owner ? accountOrGroupToGroup(options.owner) : Group16.create(),
6388
+ owner: options.owner ? accountOrGroupToGroup(options.owner) : Group18.create(),
6060
6389
  uniqueness
6061
6390
  };
6062
6391
  return opts;
@@ -6234,4 +6563,4 @@ export {
6234
6563
  JazzContextManager
6235
6564
  };
6236
6565
  /* istanbul ignore file -- @preserve */
6237
- //# sourceMappingURL=chunk-DOCEAUVD.js.map
6566
+ //# sourceMappingURL=chunk-ZIAN4UY5.js.map