@koolbase/core 12.18.0 → 12.20.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.
@@ -5,8 +5,14 @@ import { KoolbaseStorageError, koolbaseStorageErrorFromResponse, } from './stora
5
5
  import { putWithProgress, runUploadTask } from './storage-transfer.js';
6
6
  import { sendParts } from './storage-multipart.js';
7
7
  import { KoolbaseDownloadCancelledError } from './storage-errors.js';
8
+ import { refreshBucketFiles } from './files-refresh.js';
8
9
  import { KoolbaseNetworkError } from './network.js';
9
10
  import { fileInfoFromJson, filePageFromJson, listFilesQuery, } from './storage-files.js';
11
+ /** An upload task whose success reloads the bucket's file lists (storage S4). */
12
+ function listsReload(task, bucket) {
13
+ task.result.then(() => { void refreshBucketFiles(bucket); }, () => { });
14
+ return task;
15
+ }
10
16
  // --- Cloudflare image-transform URL helpers -------------------------------
11
17
  // Module-private — callers use KoolbaseStorage.publicUrl / publicUrlForObject.
12
18
  function clampInt(v, min, max) {
@@ -129,7 +135,7 @@ export class KoolbaseStorage {
129
135
  * const { object } = await task.result;
130
136
  */
131
137
  startUpload(options) {
132
- return runUploadTask((task) => this.runUpload(options, task));
138
+ return listsReload(runUploadTask((task) => this.runUpload(options, task)), options.bucket);
133
139
  }
134
140
  async runUpload(options, task) {
135
141
  task.checkCancelled();
@@ -239,14 +245,14 @@ export class KoolbaseStorage {
239
245
  * await Koolbase.storage.resumeUpload({ bucket: 'video', uploadId, file }).result;
240
246
  */
241
247
  resumeUpload(options) {
242
- return runUploadTask(async (task) => {
248
+ return listsReload(runUploadTask(async (task) => {
243
249
  const isBlob = typeof Blob !== 'undefined' && options.file instanceof Blob;
244
250
  const blob = isBlob
245
251
  ? options.file
246
252
  : await (await sessionFetch(options.file.uri)).blob();
247
253
  task.setTotal(blob.size);
248
254
  return this.runInParts(options.bucket, options, task, blob, '', options.uploadId);
249
- });
255
+ }), options.bucket);
250
256
  }
251
257
  async runInParts(bucket, options, task, file, contentType, resumeId) {
252
258
  const base = `${this.config.baseUrl}/v1/sdk/storage/uploads`;
@@ -463,7 +469,9 @@ export class KoolbaseStorage {
463
469
  if (!res.ok) {
464
470
  throw await this.error(res, op === 'move' ? 'Failed to move the file' : 'Failed to copy the file');
465
471
  }
466
- return mapObjectFromServer(await res.json());
472
+ const moved = mapObjectFromServer(await res.json());
473
+ void refreshBucketFiles(o.bucket, ...(o.toBucket && o.toBucket !== o.bucket ? [o.toBucket] : []));
474
+ return moved;
467
475
  }
468
476
  /**
469
477
  * Apply a partial metadata update to an existing object. Returns the
@@ -511,6 +519,7 @@ export class KoolbaseStorage {
511
519
  throw await this.error(res, 'Failed to update metadata');
512
520
  }
513
521
  const raw = await res.json();
522
+ void refreshBucketFiles(bucket);
514
523
  return mapObjectFromServer(raw);
515
524
  }
516
525
  /**
@@ -642,11 +651,11 @@ export class KoolbaseStorage {
642
651
  },
643
652
  body: JSON.stringify({ bucket, path }),
644
653
  });
645
- if (res.status === 204)
654
+ if (res.ok) {
655
+ void refreshBucketFiles(bucket);
646
656
  return;
647
- if (!res.ok) {
648
- throw await this.error(res, 'Failed to delete file');
649
657
  }
658
+ throw await this.error(res, 'Failed to delete file');
650
659
  }
651
660
  /**
652
661
  * List all versions of a file path, newest-first. Returns a flat list
@@ -703,7 +712,9 @@ export class KoolbaseStorage {
703
712
  if (!res.ok) {
704
713
  throw await this.error(res, 'Failed to restore version');
705
714
  }
706
- return mapObjectFromServer(await res.json());
715
+ const restored = mapObjectFromServer(await res.json());
716
+ void refreshBucketFiles(bucket);
717
+ return restored;
707
718
  }
708
719
  /**
709
720
  * Hard-remove a single history version — both the metadata row and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "12.18.0",
3
+ "version": "12.20.0",
4
4
  "description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/esm/index.d.ts",