@syncular/tauri 0.32.0 → 0.33.0

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/dist/index.d.ts CHANGED
@@ -186,6 +186,26 @@ export declare class TauriSyncClient implements PromiseMethods<ClientSnapshotMet
186
186
  crdtDeleteText(table: string, rowId: string, column: string, index: number, len: number, name?: string): Promise<string>;
187
187
  /** Escape hatch: apply an arbitrary Yjs update onto a `crdt` column. */
188
188
  crdtApplyUpdate(table: string, rowId: string, column: string, update: Uint8Array): Promise<string>;
189
+ /**
190
+ * Stage a blob for attachment (§5.9.7) and return the canonical `BlobRef`
191
+ * string to store in a `blob_ref` column. The native core owns the upload
192
+ * queue; write the referencing row after this resolves (§5.9.3).
193
+ */
194
+ uploadBlob(bytes: Uint8Array, options?: {
195
+ readonly mediaType?: string;
196
+ readonly name?: string;
197
+ }): Promise<string>;
198
+ /**
199
+ * Resolve blob bytes for a `blob_ref` column value or a bare `blobId`
200
+ * (§5.9.7): the native core serves a local cache hit and otherwise
201
+ * downloads and verifies the content address.
202
+ */
203
+ fetchBlob(ref: string): Promise<{
204
+ readonly blobId: string;
205
+ readonly byteLength: number;
206
+ readonly bytes: Uint8Array;
207
+ readonly mediaType?: string;
208
+ }>;
189
209
  subscribe(input: {
190
210
  readonly id: string;
191
211
  readonly table: string;
package/dist/index.js CHANGED
@@ -616,6 +616,40 @@ export class TauriSyncClient {
616
616
  }));
617
617
  return result.clientCommitId;
618
618
  }
619
+ /**
620
+ * Stage a blob for attachment (§5.9.7) and return the canonical `BlobRef`
621
+ * string to store in a `blob_ref` column. The native core owns the upload
622
+ * queue; write the referencing row after this resolves (§5.9.3).
623
+ */
624
+ async uploadBlob(bytes, options) {
625
+ const result = (await this.#command('uploadBlob', {
626
+ bytes: { $bytes: bytesToHex(bytes) },
627
+ ...(options?.mediaType !== undefined
628
+ ? { mediaType: options.mediaType }
629
+ : {}),
630
+ ...(options?.name !== undefined ? { name: options.name } : {}),
631
+ }));
632
+ return result.ref;
633
+ }
634
+ /**
635
+ * Resolve blob bytes for a `blob_ref` column value or a bare `blobId`
636
+ * (§5.9.7): the native core serves a local cache hit and otherwise
637
+ * downloads and verifies the content address.
638
+ */
639
+ async fetchBlob(ref) {
640
+ const result = (await this.#command('fetchBlob', { blob: ref }));
641
+ const bytes = result.blob.bytes;
642
+ if (!isBytesEnvelope(bytes))
643
+ throw new TauriSyncError('sync.invalid_request', 'fetchBlob reply carried no $bytes envelope');
644
+ return {
645
+ blobId: result.blob.blobId,
646
+ byteLength: result.blob.byteLength,
647
+ bytes: hexToBytes(bytes.$bytes),
648
+ ...(result.blob.mediaType !== undefined
649
+ ? { mediaType: result.blob.mediaType }
650
+ : {}),
651
+ };
652
+ }
619
653
  async subscribe(input) {
620
654
  await this.#command('subscribe', {
621
655
  id: input.id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/tauri",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "description": "Tauri integration for the Syncular client",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Benjamin Kniffler",
@@ -56,13 +56,13 @@
56
56
  "test": "bun test"
57
57
  },
58
58
  "dependencies": {
59
- "@syncular/client": "0.32.0"
59
+ "@syncular/client": "0.33.0"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@tauri-apps/api": ">=2.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@syncular/react": "0.32.0",
66
- "@syncular/server": "0.32.0"
65
+ "@syncular/react": "0.33.0",
66
+ "@syncular/server": "0.33.0"
67
67
  }
68
68
  }
package/src/index.ts CHANGED
@@ -992,6 +992,60 @@ export class TauriSyncClient implements PromiseMethods<ClientSnapshotMethods> {
992
992
  return result.clientCommitId;
993
993
  }
994
994
 
995
+ /**
996
+ * Stage a blob for attachment (§5.9.7) and return the canonical `BlobRef`
997
+ * string to store in a `blob_ref` column. The native core owns the upload
998
+ * queue; write the referencing row after this resolves (§5.9.3).
999
+ */
1000
+ async uploadBlob(
1001
+ bytes: Uint8Array,
1002
+ options?: { readonly mediaType?: string; readonly name?: string },
1003
+ ): Promise<string> {
1004
+ const result = (await this.#command('uploadBlob', {
1005
+ bytes: { $bytes: bytesToHex(bytes) },
1006
+ ...(options?.mediaType !== undefined
1007
+ ? { mediaType: options.mediaType }
1008
+ : {}),
1009
+ ...(options?.name !== undefined ? { name: options.name } : {}),
1010
+ })) as { ref: string };
1011
+ return result.ref;
1012
+ }
1013
+
1014
+ /**
1015
+ * Resolve blob bytes for a `blob_ref` column value or a bare `blobId`
1016
+ * (§5.9.7): the native core serves a local cache hit and otherwise
1017
+ * downloads and verifies the content address.
1018
+ */
1019
+ async fetchBlob(ref: string): Promise<{
1020
+ readonly blobId: string;
1021
+ readonly byteLength: number;
1022
+ readonly bytes: Uint8Array;
1023
+ readonly mediaType?: string;
1024
+ }> {
1025
+ const result = (await this.#command('fetchBlob', { blob: ref })) as {
1026
+ blob: {
1027
+ blobId: string;
1028
+ byteLength: number;
1029
+ bytes: unknown;
1030
+ mediaType?: string;
1031
+ };
1032
+ };
1033
+ const bytes = result.blob.bytes;
1034
+ if (!isBytesEnvelope(bytes))
1035
+ throw new TauriSyncError(
1036
+ 'sync.invalid_request',
1037
+ 'fetchBlob reply carried no $bytes envelope',
1038
+ );
1039
+ return {
1040
+ blobId: result.blob.blobId,
1041
+ byteLength: result.blob.byteLength,
1042
+ bytes: hexToBytes(bytes.$bytes),
1043
+ ...(result.blob.mediaType !== undefined
1044
+ ? { mediaType: result.blob.mediaType }
1045
+ : {}),
1046
+ };
1047
+ }
1048
+
995
1049
  async subscribe(input: {
996
1050
  readonly id: string;
997
1051
  readonly table: string;