@koolbase/core 12.16.0 → 12.17.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.
@@ -226,6 +226,24 @@ export declare class KoolbaseStorageInvalidCursorError extends KoolbaseStorageEr
226
226
  export declare class KoolbaseStorageSignInRequiredError extends KoolbaseStorageError {
227
227
  constructor(message?: string);
228
228
  }
229
+ /**
230
+ * A move refused while records point at the file (S1b): `field` holds its
231
+ * path in `records` records. Change those first, or copy the file. Code:
232
+ * `file_in_use`.
233
+ */
234
+ export declare class KoolbaseStorageFileInUseError extends KoolbaseStorageError {
235
+ field?: string;
236
+ records: number;
237
+ constructor(message?: string, field?: string, records?: number);
238
+ }
239
+ /**
240
+ * A move, within a bucket, to a name a deleted file's kept versions still
241
+ * use (S1b): the two histories would become one. Choose another name.
242
+ * Code: `name_has_history`.
243
+ */
244
+ export declare class KoolbaseStorageNameHasHistoryError extends KoolbaseStorageError {
245
+ constructor(message?: string);
246
+ }
229
247
  /**
230
248
  * Maps a non-2xx storage-layer response to a typed
231
249
  * {@link KoolbaseStorageError}, preferring the server's stable `code` and
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KoolbaseStorageSignInRequiredError = exports.KoolbaseStorageInvalidCursorError = exports.KoolbaseStorageBusyError = exports.KoolbaseUploadNotFoundError = exports.KoolbaseUploadCancelledError = exports.KoolbaseStorageMetadataInvalidError = exports.KoolbaseStorageMimeTypeError = exports.KoolbaseStorageFileTooLargeError = exports.KoolbaseStorageQuotaError = exports.KoolbaseCapBelowUsageError = exports.KoolbaseUploadExpiredError = exports.KoolbaseUploadURLFailedError = exports.KoolbaseStoragePermissionError = exports.KoolbaseStorageValidationError = exports.KoolbaseStorageNotFoundError = exports.KoolbaseStorageConflictError = exports.KoolbaseStorageProjectIdentityError = exports.KoolbaseStorageError = void 0;
3
+ exports.KoolbaseStorageNameHasHistoryError = exports.KoolbaseStorageFileInUseError = exports.KoolbaseStorageSignInRequiredError = exports.KoolbaseStorageInvalidCursorError = exports.KoolbaseStorageBusyError = exports.KoolbaseUploadNotFoundError = exports.KoolbaseUploadCancelledError = exports.KoolbaseStorageMetadataInvalidError = exports.KoolbaseStorageMimeTypeError = exports.KoolbaseStorageFileTooLargeError = exports.KoolbaseStorageQuotaError = exports.KoolbaseCapBelowUsageError = exports.KoolbaseUploadExpiredError = exports.KoolbaseUploadURLFailedError = exports.KoolbaseStoragePermissionError = exports.KoolbaseStorageValidationError = exports.KoolbaseStorageNotFoundError = exports.KoolbaseStorageConflictError = exports.KoolbaseStorageProjectIdentityError = exports.KoolbaseStorageError = void 0;
4
4
  exports.koolbaseStorageError = koolbaseStorageError;
5
5
  exports.koolbaseStorageErrorFromResponse = koolbaseStorageErrorFromResponse;
6
6
  const errors_js_1 = require("./errors.js");
@@ -316,6 +316,34 @@ class KoolbaseStorageSignInRequiredError extends KoolbaseStorageError {
316
316
  }
317
317
  }
318
318
  exports.KoolbaseStorageSignInRequiredError = KoolbaseStorageSignInRequiredError;
319
+ /**
320
+ * A move refused while records point at the file (S1b): `field` holds its
321
+ * path in `records` records. Change those first, or copy the file. Code:
322
+ * `file_in_use`.
323
+ */
324
+ class KoolbaseStorageFileInUseError extends KoolbaseStorageError {
325
+ constructor(message, field, records = 0) {
326
+ super(message ?? 'Records still point at this file', 'file_in_use');
327
+ this.field = field;
328
+ this.records = records;
329
+ this.name = 'KoolbaseStorageFileInUseError';
330
+ Object.setPrototypeOf(this, KoolbaseStorageFileInUseError.prototype);
331
+ }
332
+ }
333
+ exports.KoolbaseStorageFileInUseError = KoolbaseStorageFileInUseError;
334
+ /**
335
+ * A move, within a bucket, to a name a deleted file's kept versions still
336
+ * use (S1b): the two histories would become one. Choose another name.
337
+ * Code: `name_has_history`.
338
+ */
339
+ class KoolbaseStorageNameHasHistoryError extends KoolbaseStorageError {
340
+ constructor(message) {
341
+ super(message ?? 'A deleted file by that name still has kept versions; choose another name', 'name_has_history');
342
+ this.name = 'KoolbaseStorageNameHasHistoryError';
343
+ Object.setPrototypeOf(this, KoolbaseStorageNameHasHistoryError.prototype);
344
+ }
345
+ }
346
+ exports.KoolbaseStorageNameHasHistoryError = KoolbaseStorageNameHasHistoryError;
319
347
  /**
320
348
  * Maps a non-2xx storage-layer response to a typed
321
349
  * {@link KoolbaseStorageError}, preferring the server's stable `code` and
@@ -363,6 +391,12 @@ function koolbaseStorageError(status, body, fallbackMessage = 'Storage request f
363
391
  return new KoolbaseStorageSignInRequiredError(message);
364
392
  case 'not_allowed':
365
393
  return new KoolbaseStoragePermissionError(message);
394
+ case 'file_in_use': {
395
+ const d = (body?.details ?? {});
396
+ return new KoolbaseStorageFileInUseError(message, d.field, Number(d.records ?? 0));
397
+ }
398
+ case 'name_has_history':
399
+ return new KoolbaseStorageNameHasHistoryError(message);
366
400
  }
367
401
  // ─── status fallback (pre-code servers or uncoded paths) ───
368
402
  switch (status) {
@@ -94,6 +94,37 @@ export declare class KoolbaseStorage {
94
94
  * the bucket's view rule hides from the caller.
95
95
  */
96
96
  getFileInfo(bucket: string, path: string): Promise<KoolbaseFileInfo>;
97
+ /**
98
+ * Move a file to `to`, in its bucket or into `toBucket` (S1b). Nothing is
99
+ * uploaded again. The bucket's rules decide: delete on the file, and
100
+ * upload at the destination, whose limits apply as to an upload. The
101
+ * destination must be free.
102
+ *
103
+ * Within one bucket the file keeps its kept versions. Refused with
104
+ * `KoolbaseStorageFileInUseError` while records point at the file: change
105
+ * them first, or {@link copy} it.
106
+ *
107
+ * @example
108
+ * await Koolbase.storage.move({ bucket: 'inbox', from: 'scan.png', toBucket: 'vault', to: '2026/scan.png' });
109
+ */
110
+ move(options: {
111
+ bucket: string;
112
+ from: string;
113
+ to: string;
114
+ toBucket?: string;
115
+ }): Promise<KoolbaseObject>;
116
+ /**
117
+ * Copy a file to `to`, in its bucket or into `toBucket` (S1b): a new file,
118
+ * the caller's, with the same bytes. The bucket's rules decide: view on
119
+ * the file, and upload at the destination.
120
+ */
121
+ copy(options: {
122
+ bucket: string;
123
+ from: string;
124
+ to: string;
125
+ toBucket?: string;
126
+ }): Promise<KoolbaseObject>;
127
+ private transfer;
97
128
  /**
98
129
  * Apply a partial metadata update to an existing object. Returns the
99
130
  * post-update {@link KoolbaseObject} with the merged metadata.
@@ -256,6 +256,44 @@ class KoolbaseStorage {
256
256
  }
257
257
  return (0, storage_files_js_1.fileInfoFromJson)((await res.json()));
258
258
  }
259
+ /**
260
+ * Move a file to `to`, in its bucket or into `toBucket` (S1b). Nothing is
261
+ * uploaded again. The bucket's rules decide: delete on the file, and
262
+ * upload at the destination, whose limits apply as to an upload. The
263
+ * destination must be free.
264
+ *
265
+ * Within one bucket the file keeps its kept versions. Refused with
266
+ * `KoolbaseStorageFileInUseError` while records point at the file: change
267
+ * them first, or {@link copy} it.
268
+ *
269
+ * @example
270
+ * await Koolbase.storage.move({ bucket: 'inbox', from: 'scan.png', toBucket: 'vault', to: '2026/scan.png' });
271
+ */
272
+ async move(options) {
273
+ return this.transfer('move', options);
274
+ }
275
+ /**
276
+ * Copy a file to `to`, in its bucket or into `toBucket` (S1b): a new file,
277
+ * the caller's, with the same bytes. The bucket's rules decide: view on
278
+ * the file, and upload at the destination.
279
+ */
280
+ async copy(options) {
281
+ return this.transfer('copy', options);
282
+ }
283
+ async transfer(op, o) {
284
+ const body = { bucket: o.bucket, from: o.from, to: o.to };
285
+ if (o.toBucket && o.toBucket !== o.bucket)
286
+ body.to_bucket = o.toBucket;
287
+ const res = await (0, network_js_1.sessionFetch)(`${this.config.baseUrl}/v1/sdk/storage/${op}`, {
288
+ method: 'POST',
289
+ headers: { ...(await this.buildHeaders()), 'Content-Type': 'application/json' },
290
+ body: JSON.stringify(body),
291
+ });
292
+ if (!res.ok) {
293
+ throw await this.error(res, op === 'move' ? 'Failed to move the file' : 'Failed to copy the file');
294
+ }
295
+ return mapObjectFromServer(await res.json());
296
+ }
259
297
  /**
260
298
  * Apply a partial metadata update to an existing object. Returns the
261
299
  * post-update {@link KoolbaseObject} with the merged metadata.
@@ -226,6 +226,24 @@ export declare class KoolbaseStorageInvalidCursorError extends KoolbaseStorageEr
226
226
  export declare class KoolbaseStorageSignInRequiredError extends KoolbaseStorageError {
227
227
  constructor(message?: string);
228
228
  }
229
+ /**
230
+ * A move refused while records point at the file (S1b): `field` holds its
231
+ * path in `records` records. Change those first, or copy the file. Code:
232
+ * `file_in_use`.
233
+ */
234
+ export declare class KoolbaseStorageFileInUseError extends KoolbaseStorageError {
235
+ field?: string;
236
+ records: number;
237
+ constructor(message?: string, field?: string, records?: number);
238
+ }
239
+ /**
240
+ * A move, within a bucket, to a name a deleted file's kept versions still
241
+ * use (S1b): the two histories would become one. Choose another name.
242
+ * Code: `name_has_history`.
243
+ */
244
+ export declare class KoolbaseStorageNameHasHistoryError extends KoolbaseStorageError {
245
+ constructor(message?: string);
246
+ }
229
247
  /**
230
248
  * Maps a non-2xx storage-layer response to a typed
231
249
  * {@link KoolbaseStorageError}, preferring the server's stable `code` and
@@ -293,6 +293,32 @@ export class KoolbaseStorageSignInRequiredError extends KoolbaseStorageError {
293
293
  Object.setPrototypeOf(this, KoolbaseStorageSignInRequiredError.prototype);
294
294
  }
295
295
  }
296
+ /**
297
+ * A move refused while records point at the file (S1b): `field` holds its
298
+ * path in `records` records. Change those first, or copy the file. Code:
299
+ * `file_in_use`.
300
+ */
301
+ export class KoolbaseStorageFileInUseError extends KoolbaseStorageError {
302
+ constructor(message, field, records = 0) {
303
+ super(message ?? 'Records still point at this file', 'file_in_use');
304
+ this.field = field;
305
+ this.records = records;
306
+ this.name = 'KoolbaseStorageFileInUseError';
307
+ Object.setPrototypeOf(this, KoolbaseStorageFileInUseError.prototype);
308
+ }
309
+ }
310
+ /**
311
+ * A move, within a bucket, to a name a deleted file's kept versions still
312
+ * use (S1b): the two histories would become one. Choose another name.
313
+ * Code: `name_has_history`.
314
+ */
315
+ export class KoolbaseStorageNameHasHistoryError extends KoolbaseStorageError {
316
+ constructor(message) {
317
+ super(message ?? 'A deleted file by that name still has kept versions; choose another name', 'name_has_history');
318
+ this.name = 'KoolbaseStorageNameHasHistoryError';
319
+ Object.setPrototypeOf(this, KoolbaseStorageNameHasHistoryError.prototype);
320
+ }
321
+ }
296
322
  /**
297
323
  * Maps a non-2xx storage-layer response to a typed
298
324
  * {@link KoolbaseStorageError}, preferring the server's stable `code` and
@@ -340,6 +366,12 @@ export function koolbaseStorageError(status, body, fallbackMessage = 'Storage re
340
366
  return new KoolbaseStorageSignInRequiredError(message);
341
367
  case 'not_allowed':
342
368
  return new KoolbaseStoragePermissionError(message);
369
+ case 'file_in_use': {
370
+ const d = (body?.details ?? {});
371
+ return new KoolbaseStorageFileInUseError(message, d.field, Number(d.records ?? 0));
372
+ }
373
+ case 'name_has_history':
374
+ return new KoolbaseStorageNameHasHistoryError(message);
343
375
  }
344
376
  // ─── status fallback (pre-code servers or uncoded paths) ───
345
377
  switch (status) {
@@ -94,6 +94,37 @@ export declare class KoolbaseStorage {
94
94
  * the bucket's view rule hides from the caller.
95
95
  */
96
96
  getFileInfo(bucket: string, path: string): Promise<KoolbaseFileInfo>;
97
+ /**
98
+ * Move a file to `to`, in its bucket or into `toBucket` (S1b). Nothing is
99
+ * uploaded again. The bucket's rules decide: delete on the file, and
100
+ * upload at the destination, whose limits apply as to an upload. The
101
+ * destination must be free.
102
+ *
103
+ * Within one bucket the file keeps its kept versions. Refused with
104
+ * `KoolbaseStorageFileInUseError` while records point at the file: change
105
+ * them first, or {@link copy} it.
106
+ *
107
+ * @example
108
+ * await Koolbase.storage.move({ bucket: 'inbox', from: 'scan.png', toBucket: 'vault', to: '2026/scan.png' });
109
+ */
110
+ move(options: {
111
+ bucket: string;
112
+ from: string;
113
+ to: string;
114
+ toBucket?: string;
115
+ }): Promise<KoolbaseObject>;
116
+ /**
117
+ * Copy a file to `to`, in its bucket or into `toBucket` (S1b): a new file,
118
+ * the caller's, with the same bytes. The bucket's rules decide: view on
119
+ * the file, and upload at the destination.
120
+ */
121
+ copy(options: {
122
+ bucket: string;
123
+ from: string;
124
+ to: string;
125
+ toBucket?: string;
126
+ }): Promise<KoolbaseObject>;
127
+ private transfer;
97
128
  /**
98
129
  * Apply a partial metadata update to an existing object. Returns the
99
130
  * post-update {@link KoolbaseObject} with the merged metadata.
@@ -253,6 +253,44 @@ export class KoolbaseStorage {
253
253
  }
254
254
  return fileInfoFromJson((await res.json()));
255
255
  }
256
+ /**
257
+ * Move a file to `to`, in its bucket or into `toBucket` (S1b). Nothing is
258
+ * uploaded again. The bucket's rules decide: delete on the file, and
259
+ * upload at the destination, whose limits apply as to an upload. The
260
+ * destination must be free.
261
+ *
262
+ * Within one bucket the file keeps its kept versions. Refused with
263
+ * `KoolbaseStorageFileInUseError` while records point at the file: change
264
+ * them first, or {@link copy} it.
265
+ *
266
+ * @example
267
+ * await Koolbase.storage.move({ bucket: 'inbox', from: 'scan.png', toBucket: 'vault', to: '2026/scan.png' });
268
+ */
269
+ async move(options) {
270
+ return this.transfer('move', options);
271
+ }
272
+ /**
273
+ * Copy a file to `to`, in its bucket or into `toBucket` (S1b): a new file,
274
+ * the caller's, with the same bytes. The bucket's rules decide: view on
275
+ * the file, and upload at the destination.
276
+ */
277
+ async copy(options) {
278
+ return this.transfer('copy', options);
279
+ }
280
+ async transfer(op, o) {
281
+ const body = { bucket: o.bucket, from: o.from, to: o.to };
282
+ if (o.toBucket && o.toBucket !== o.bucket)
283
+ body.to_bucket = o.toBucket;
284
+ const res = await sessionFetch(`${this.config.baseUrl}/v1/sdk/storage/${op}`, {
285
+ method: 'POST',
286
+ headers: { ...(await this.buildHeaders()), 'Content-Type': 'application/json' },
287
+ body: JSON.stringify(body),
288
+ });
289
+ if (!res.ok) {
290
+ throw await this.error(res, op === 'move' ? 'Failed to move the file' : 'Failed to copy the file');
291
+ }
292
+ return mapObjectFromServer(await res.json());
293
+ }
256
294
  /**
257
295
  * Apply a partial metadata update to an existing object. Returns the
258
296
  * post-update {@link KoolbaseObject} with the merged metadata.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "12.16.0",
3
+ "version": "12.17.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",