bedrock-ts-sdk 0.0.7 → 0.0.8

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.mts CHANGED
@@ -674,6 +674,7 @@ declare class FileService {
674
674
  * @param files - Array of files to upload
675
675
  * @param directoryPath - Optional directory path prefix
676
676
  * @returns Array of uploaded file info
677
+ * @throws FileConflictError if any file path conflicts with non-trashed file
677
678
  */
678
679
  uploadFiles(files: FileInput[], directoryPath?: string): Promise<FileFullInfo[]>;
679
680
  editFileContent(fileInfo: FileFullInfo, newContent: Buffer): Promise<FileFullInfo>;
@@ -713,6 +714,7 @@ declare class FileService {
713
714
  /**
714
715
  * Restore soft-deleted files
715
716
  * @param filePaths - Paths of files to restore
717
+ * @throws FileConflictError if any file path conflicts with non-trashed file
716
718
  */
717
719
  restoreFiles(filePaths: string[]): Promise<void>;
718
720
  /**
@@ -723,6 +725,7 @@ declare class FileService {
723
725
  /**
724
726
  * Move/rename files
725
727
  * @param moves - Array of {oldPath, newPath} objects
728
+ * @throws FileConflictError if any newPath conflicts with non-trashed file
726
729
  */
727
730
  moveFiles(moves: Array<{
728
731
  oldPath: string;
@@ -765,6 +768,12 @@ declare class FileService {
765
768
  * @returns File content as ArrayBuffer
766
769
  */
767
770
  static downloadPublicFile(storeHash: string): Promise<ArrayBuffer>;
771
+ /**
772
+ * Check for path conflicts with non-trashed files
773
+ * @param paths - Paths to check
774
+ * @throws FileConflictError on first conflict
775
+ */
776
+ private checkPathConflicts;
768
777
  private saveFileEntries;
769
778
  private encryptFileMeta;
770
779
  private decryptFileMeta;
package/dist/index.d.ts CHANGED
@@ -674,6 +674,7 @@ declare class FileService {
674
674
  * @param files - Array of files to upload
675
675
  * @param directoryPath - Optional directory path prefix
676
676
  * @returns Array of uploaded file info
677
+ * @throws FileConflictError if any file path conflicts with non-trashed file
677
678
  */
678
679
  uploadFiles(files: FileInput[], directoryPath?: string): Promise<FileFullInfo[]>;
679
680
  editFileContent(fileInfo: FileFullInfo, newContent: Buffer): Promise<FileFullInfo>;
@@ -713,6 +714,7 @@ declare class FileService {
713
714
  /**
714
715
  * Restore soft-deleted files
715
716
  * @param filePaths - Paths of files to restore
717
+ * @throws FileConflictError if any file path conflicts with non-trashed file
716
718
  */
717
719
  restoreFiles(filePaths: string[]): Promise<void>;
718
720
  /**
@@ -723,6 +725,7 @@ declare class FileService {
723
725
  /**
724
726
  * Move/rename files
725
727
  * @param moves - Array of {oldPath, newPath} objects
728
+ * @throws FileConflictError if any newPath conflicts with non-trashed file
726
729
  */
727
730
  moveFiles(moves: Array<{
728
731
  oldPath: string;
@@ -765,6 +768,12 @@ declare class FileService {
765
768
  * @returns File content as ArrayBuffer
766
769
  */
767
770
  static downloadPublicFile(storeHash: string): Promise<ArrayBuffer>;
771
+ /**
772
+ * Check for path conflicts with non-trashed files
773
+ * @param paths - Paths to check
774
+ * @throws FileConflictError on first conflict
775
+ */
776
+ private checkPathConflicts;
768
777
  private saveFileEntries;
769
778
  private encryptFileMeta;
770
779
  private decryptFileMeta;
package/dist/index.js CHANGED
@@ -121,6 +121,14 @@ var FileNotFoundError = class _FileNotFoundError extends FileError {
121
121
  Object.setPrototypeOf(this, _FileNotFoundError.prototype);
122
122
  }
123
123
  };
124
+ var FileConflictError = class _FileConflictError extends FileError {
125
+ constructor(path) {
126
+ super(`File path conflict: ${path} already exists`);
127
+ this.name = "FileConflictError";
128
+ this.code = "FILE_CONFLICT";
129
+ Object.setPrototypeOf(this, _FileConflictError.prototype);
130
+ }
131
+ };
124
132
  var ContactError = class _ContactError extends BedrockError {
125
133
  constructor(message) {
126
134
  super(message, "CONTACT_ERROR");
@@ -944,21 +952,16 @@ var FileService = class {
944
952
  * @param files - Array of files to upload
945
953
  * @param directoryPath - Optional directory path prefix
946
954
  * @returns Array of uploaded file info
955
+ * @throws FileConflictError if any file path conflicts with non-trashed file
947
956
  */
948
957
  async uploadFiles(files, directoryPath = "") {
949
958
  const aleph = this.core.getAlephService();
950
959
  const publicKey = this.core.getPublicKey();
951
960
  const uploadedFiles = [];
952
- const existingFiles = await this.listFiles();
953
- const filesToUpload = files.filter((file) => {
954
- const filterIn = !existingFiles.some(
955
- (existingFile) => !existingFile.deleted_at && existingFile.path === (directoryPath ? `${directoryPath}${file.path}` : file.path)
956
- );
957
- console.log(`Keeping ${file} in ? ${filterIn ? "yes" : "no"}`);
958
- return filterIn;
959
- });
961
+ const fullPaths = files.map((f) => directoryPath ? `${directoryPath}${f.path}` : f.path);
962
+ await this.checkPathConflicts(fullPaths);
960
963
  try {
961
- for (const file of filesToUpload) {
964
+ for (const file of files) {
962
965
  const key = EncryptionService.generateKey();
963
966
  const iv = EncryptionService.generateIv();
964
967
  let fileBuffer;
@@ -1158,9 +1161,11 @@ var FileService = class {
1158
1161
  /**
1159
1162
  * Restore soft-deleted files
1160
1163
  * @param filePaths - Paths of files to restore
1164
+ * @throws FileConflictError if any file path conflicts with non-trashed file
1161
1165
  */
1162
1166
  async restoreFiles(filePaths) {
1163
1167
  const aleph = this.core.getAlephService();
1168
+ await this.checkPathConflicts(filePaths);
1164
1169
  try {
1165
1170
  for (const path of filePaths) {
1166
1171
  const file = await this.getFile(path);
@@ -1205,10 +1210,18 @@ var FileService = class {
1205
1210
  /**
1206
1211
  * Move/rename files
1207
1212
  * @param moves - Array of {oldPath, newPath} objects
1213
+ * @throws FileConflictError if any newPath conflicts with non-trashed file
1208
1214
  */
1209
1215
  async moveFiles(moves) {
1210
1216
  const aleph = this.core.getAlephService();
1211
1217
  const publicKey = this.core.getPublicKey();
1218
+ const existingFiles = await this.listFiles(false);
1219
+ const existingPaths = new Set(existingFiles.map((f) => f.path));
1220
+ for (const { oldPath, newPath } of moves) {
1221
+ if (existingPaths.has(newPath) && newPath !== oldPath) {
1222
+ throw new FileConflictError(newPath);
1223
+ }
1224
+ }
1212
1225
  try {
1213
1226
  for (const { oldPath, newPath } of moves) {
1214
1227
  const file = await this.getFile(oldPath);
@@ -1385,6 +1398,20 @@ var FileService = class {
1385
1398
  // ============================================================================
1386
1399
  // Private helper methods
1387
1400
  // ============================================================================
1401
+ /**
1402
+ * Check for path conflicts with non-trashed files
1403
+ * @param paths - Paths to check
1404
+ * @throws FileConflictError on first conflict
1405
+ */
1406
+ async checkPathConflicts(paths) {
1407
+ const existingFiles = await this.listFiles(false);
1408
+ const existingPaths = new Set(existingFiles.map((f) => f.path));
1409
+ for (const path of paths) {
1410
+ if (existingPaths.has(path)) {
1411
+ throw new FileConflictError(path);
1412
+ }
1413
+ }
1414
+ }
1388
1415
  async saveFileEntries(files) {
1389
1416
  const aleph = this.core.getAlephService();
1390
1417
  const publicKey = this.core.getPublicKey();