@cloudbase/js-sdk 3.4.7 → 3.4.9-alpha.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/ai/dist/index.esm.js +1 -1
  3. package/ai/dist/index.esm.js.map +1 -1
  4. package/ai/dist/index.js +1 -1
  5. package/ai/dist/index.js.map +1 -1
  6. package/app/dist/index.esm.js +1 -1
  7. package/app/dist/index.esm.js.map +1 -1
  8. package/app/dist/index.js +1 -1
  9. package/app/dist/index.js.map +1 -1
  10. package/auth/dist/index.esm.js +1 -1
  11. package/auth/dist/index.esm.js.map +1 -1
  12. package/auth/dist/index.js +1 -1
  13. package/auth/dist/index.js.map +1 -1
  14. package/cloudrun/dist/index.esm.js +1 -1
  15. package/cloudrun/dist/index.esm.js.map +1 -1
  16. package/cloudrun/dist/index.js +1 -1
  17. package/cloudrun/dist/index.js.map +1 -1
  18. package/container/dist/index.esm.js +1 -1
  19. package/container/dist/index.esm.js.map +1 -1
  20. package/container/dist/index.js +1 -1
  21. package/container/dist/index.js.map +1 -1
  22. package/dist/index.cjs.js +1 -1
  23. package/dist/index.cjs.js.map +1 -1
  24. package/dist/index.esm.js +1 -1
  25. package/dist/index.esm.js.map +1 -1
  26. package/functions/dist/index.esm.js +1 -1
  27. package/functions/dist/index.esm.js.map +1 -1
  28. package/functions/dist/index.js +1 -1
  29. package/functions/dist/index.js.map +1 -1
  30. package/index.d.ts +654 -45
  31. package/miniprogram_dist/ai.js +1 -1
  32. package/miniprogram_dist/app.js +1 -1
  33. package/miniprogram_dist/auth.js +1 -1
  34. package/miniprogram_dist/cloudrun.js +1 -1
  35. package/miniprogram_dist/container.js +1 -1
  36. package/miniprogram_dist/functions.js +1 -1
  37. package/miniprogram_dist/index.js +1 -1
  38. package/miniprogram_dist/model.js +1 -1
  39. package/miniprogram_dist/oauth.js +1 -1
  40. package/miniprogram_dist/storage.js +1 -1
  41. package/model/dist/index.esm.js +1 -1
  42. package/model/dist/index.esm.js.map +1 -1
  43. package/model/dist/index.js +1 -1
  44. package/model/dist/index.js.map +1 -1
  45. package/oauth/dist/index.esm.js +1 -1
  46. package/oauth/dist/index.esm.js.map +1 -1
  47. package/oauth/dist/index.js +1 -1
  48. package/oauth/dist/index.js.map +1 -1
  49. package/package.json +1 -1
  50. package/storage/dist/index.esm.js +1 -1
  51. package/storage/dist/index.esm.js.map +1 -1
  52. package/storage/dist/index.js +1 -1
  53. package/storage/dist/index.js.map +1 -1
  54. package/types/index.d.ts +2 -2
  55. package/types/package.json +1 -1
  56. package/utilities/dist/cjs/adapters/platforms/web.js +12 -4
  57. package/utilities/dist/esm/adapters/platforms/web.js +12 -4
  58. package/utilities/dist/miniprogram/index.js +1 -1
  59. package/utilities/package.json +2 -2
package/index.d.ts CHANGED
@@ -453,6 +453,8 @@ declare namespace cloudbase.app {
453
453
  * @param params.onUploadProgress 【可选】上传进度回调函数
454
454
  *
455
455
  * @return Promise-上传结果
456
+ *
457
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().upload()`。
456
458
  */
457
459
  uploadFile(
458
460
  params: cloudbase.storage.ICloudbaseUploadFileParams,
@@ -477,6 +479,8 @@ declare namespace cloudbase.app {
477
479
  * @param params.fileID 要下载的文件的 `id`,在控制台云存储中查看
478
480
  *
479
481
  * @return Promise-下载结果
482
+ *
483
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().download()`。
480
484
  */
481
485
  downloadFile(
482
486
  params: cloudbase.storage.ICloudbaseDownloadFileParams,
@@ -507,6 +511,8 @@ declare namespace cloudbase.app {
507
511
  * @param params.fileList 要复制的文件信息组成的数组
508
512
  *
509
513
  * @return Promise-复制结果
514
+ *
515
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().copy()`。
510
516
  */
511
517
  copyFile(
512
518
  params: cloudbase.storage.ICloudbaseCopyFileParams,
@@ -539,6 +545,8 @@ declare namespace cloudbase.app {
539
545
  * @param params.fileList[].maxAge 下载链接的有效期,单位`ms`
540
546
  *
541
547
  * @return Promise-文件下载链接
548
+ *
549
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().createSignedUrl()`。
542
550
  */
543
551
  getTempFileURL(
544
552
  params: cloudbase.storage.ICloudbaseGetTempFileURLParams,
@@ -566,12 +574,19 @@ declare namespace cloudbase.app {
566
574
  * @param params.fileList 要删除的文件ID数组
567
575
  *
568
576
  * @return Promise-删除结果
577
+ *
578
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().remove()`。
569
579
  */
570
580
  deleteFile(
571
581
  params: cloudbase.storage.ICloudbaseDeleteFileParams,
572
582
  callback?: Function,
573
583
  ): Promise<cloudbase.storage.ICloudbaseDeleteFileResult>
574
584
 
585
+ /**
586
+ * 云存储-获取文件信息
587
+ *
588
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().info()`。
589
+ */
575
590
  getFileInfo(
576
591
  params: cloudbase.storage.ICloudbaseGetTempFileURLParams,
577
592
  ): Promise<cloudbase.storage.ICloudbaseGetFileInfoResult>
@@ -581,6 +596,8 @@ declare namespace cloudbase.app {
581
596
  *
582
597
  * @param params
583
598
  * @param callback
599
+ *
600
+ * @deprecated 传统云存储 API 已不推荐使用,请改用 `app.storage.from().createSignedUploadUrl()`。
584
601
  */
585
602
  getUploadMetadata(params: cloudbase.storage.ICloudbaseGetUploadMetadataParams, callback?: Function): Promise<any>
586
603
 
@@ -593,7 +610,7 @@ declare namespace cloudbase.app {
593
610
  * const { data, error } = await bucket.upload('path/to/file.jpg', file)
594
611
  * ```
595
612
  */
596
- storage: cloudbase.storage.SupabaseFileAPILikeStorage
613
+ storage: cloudbase.storage.StorageClient
597
614
  /**
598
615
  * 获取数据库实例
599
616
  *
@@ -1917,32 +1934,68 @@ declare namespace cloudbase.storage {
1917
1934
 
1918
1935
  // ---- Supabase-like Storage Types ----
1919
1936
 
1937
+ /** Node.js 风格可读流的最小兼容类型,避免依赖 `@types/node`。 */
1938
+ interface NodeReadableStreamLike {
1939
+ /** 将当前流管道输出到目标流。 */
1940
+ pipe(destination: any, options?: any): any
1941
+ }
1942
+
1943
+ /**
1944
+ * Node.js `Buffer` 的兼容类型。
1945
+ *
1946
+ * 在安装了 `@types/node` 的项目中解析为 `Buffer`,未安装时退化为 `never`,
1947
+ * 从而既能让 Node 端继续显式传入 `Buffer`,又不会让纯浏览器项目因缺少
1948
+ * `@types/node` 而报“找不到名称 Buffer”,避免对 `@types/node` 的硬依赖。
1949
+ */
1950
+ type MaybeNodeBuffer = typeof globalThis extends { Buffer: new (...args: any[]) => infer B } ? B : never
1951
+
1952
+ /**
1953
+ * 可上传的文件内容类型。
1954
+ *
1955
+ * @remarks
1956
+ * - Node.js `Buffer`:通过 `MaybeNodeBuffer` 兼容(装有 `@types/node` 时可直接传入);
1957
+ * 即便未装 `@types/node`,`Buffer` 仍可作为 `ArrayBufferView` / `Uint8Array` 传入。
1958
+ * - Node.js 可读流(如 `NodeJS.ReadableStream` / `fs.ReadStream`):可作为 `NodeReadableStreamLike` 传入。
1959
+ */
1920
1960
  type FileBody =
1921
1961
  | ArrayBuffer
1922
1962
  | ArrayBufferView
1923
1963
  | Blob
1924
- | Buffer
1925
1964
  | File
1926
1965
  | FormData
1927
- | NodeJS.ReadableStream
1966
+ | MaybeNodeBuffer
1967
+ | NodeReadableStreamLike
1928
1968
  | ReadableStream<Uint8Array>
1929
1969
  | URLSearchParams
1930
1970
  | string
1931
1971
 
1972
+ /** 上传 / 覆盖对象选项。 */
1932
1973
  interface FileOptions {
1974
+ /** 缓存时间,单位为秒;会转换为 `Cache-Control: max-age=<seconds>`。 */
1933
1975
  cacheControl?: string
1976
+ /** 文件 MIME 类型;当 `fileBody` 不是 `Blob` / `File` / `FormData` 时建议显式指定。 */
1934
1977
  contentType?: string
1978
+ /** 是否允许覆盖同名对象。 */
1935
1979
  upsert?: boolean
1980
+ /** 透传给底层 `fetch` 的 duplex 配置,用于流式请求场景。 */
1936
1981
  duplex?: string
1982
+ /** 用户自定义元数据。 */
1937
1983
  metadata?: Record<string, any>
1984
+ /** 额外请求头。 */
1938
1985
  headers?: Record<string, string>
1939
1986
  }
1940
1987
 
1988
+ /** 图片转换选项。 */
1941
1989
  interface TransformOptions {
1990
+ /** 图片宽度,单位为像素。 */
1942
1991
  width?: number
1992
+ /** 图片高度,单位为像素。 */
1943
1993
  height?: number
1994
+ /** 缩放模式:`cover` 保持比例裁剪填满;`contain` 保持比例完整适配;`fill` 拉伸填满。 */
1944
1995
  resize?: 'cover' | 'contain' | 'fill'
1996
+ /** 图片质量,通常取值 20 到 100,数值越大质量越高。 */
1945
1997
  quality?: number
1998
+ /** 输出格式;`origin` 表示保持原图格式。 */
1946
1999
  format?: 'origin'
1947
2000
  }
1948
2001
 
@@ -2008,25 +2061,12 @@ declare namespace cloudbase.storage {
2008
2061
  * const { data } = await bucket.download('path/to/file.jpg')
2009
2062
  * ```
2010
2063
  */
2011
- interface SupabaseFileAPILikeStorage {
2064
+ interface ClassicStorageFileApi {
2012
2065
  /**
2013
2066
  * 启用错误抛出模式,而非返回 `{ data: null, error }` 格式
2014
2067
  */
2015
2068
  throwOnError(): this
2016
2069
 
2017
- /**
2018
- * 选择存储桶
2019
- *
2020
- * @param bucket 存储桶名称
2021
- * @returns 当前实例(链式调用)
2022
- *
2023
- * @example
2024
- * ```typescript
2025
- * const bucket = app.storage.from('my-bucket')
2026
- * ```
2027
- */
2028
- from(bucket?: string): this
2029
-
2030
2070
  /**
2031
2071
  * 上传文件
2032
2072
  *
@@ -2216,42 +2256,611 @@ declare namespace cloudbase.storage {
2216
2256
  | { data: FileObject[]; error: null }
2217
2257
  | { data: null; error: StorageError }
2218
2258
  >
2259
+ }
2219
2260
 
2220
- // ---- 继承自 CloudbaseStorage 的方法 ----
2261
+ /**
2262
+ * Bucket 管理 API,挂载在 `app.storage` 上。
2263
+ *
2264
+ * @remarks 权限由 `storage.buckets` 的 RLS Policy 决定。暂不提供
2265
+ * `emptyBucket()`、`headBucket()`、Bucket CORS、Bucket ACL 等 COS/S3 风格 Bucket 管理 API。
2266
+ */
2267
+ interface StorageBucketApi {
2268
+ /**
2269
+ * 启用错误抛出模式。开启后请求失败会抛异常;请求成功仍返回 `{ data, error: null }`。
2270
+ * 该设置会传递给 `from()` 返回的客户端。
2271
+ */
2272
+ throwOnError(): this
2221
2273
 
2222
- uploadFile(
2223
- params: ICloudbaseUploadFileParams,
2224
- callback?: Function,
2225
- ): Promise<ICloudbaseUploadFileResult>
2274
+ /**
2275
+ * 获取 Bucket 列表,支持偏移分页、排序和搜索。
2276
+ *
2277
+ * @param options 查询参数:`limit`、`offset`、`sortColumn`、`sortOrder`、`search`。
2278
+ */
2279
+ listBuckets(options?: ListBucketOptions): Promise<
2280
+ | { data: Bucket[]; error: null }
2281
+ | { data: null; error: StorageError }
2282
+ >
2226
2283
 
2227
- deleteFile(
2228
- params: ICloudbaseDeleteFileParams,
2229
- callback?: Function,
2230
- ): Promise<ICloudbaseDeleteFileResult>
2284
+ /**
2285
+ * 获取指定 Bucket 详情。
2286
+ *
2287
+ * @param bucketId Bucket ID。
2288
+ */
2289
+ getBucket(bucketId: string): Promise<
2290
+ | { data: Bucket; error: null }
2291
+ | { data: null; error: StorageError }
2292
+ >
2231
2293
 
2232
- getTempFileURL(
2233
- params: ICloudbaseGetTempFileURLParams,
2234
- callback?: Function,
2235
- ): Promise<ICloudbaseGetTempFileURLResult>
2294
+ /**
2295
+ * 创建 Bucket。
2296
+ *
2297
+ * @param bucketId Bucket ID,同时作为后端 `id` 与 `name` 传入。
2298
+ * @param options 创建参数:`public`、`fileSizeLimit`、`allowedMimeTypes`、`type`。
2299
+ * @remarks `public` 默认 `false`。
2300
+ */
2301
+ createBucket(bucketId: string, options?: CreateBucketOptions): Promise<
2302
+ | { data: { name: string }; error: null }
2303
+ | { data: null; error: StorageError }
2304
+ >
2236
2305
 
2237
- downloadFile(
2238
- params: ICloudbaseDownloadFileParams,
2239
- callback?: Function,
2240
- ): Promise<ICloudbaseDownloadFileResult>
2306
+ /**
2307
+ * 更新 Bucket 配置。
2308
+ *
2309
+ * @param bucketId Bucket ID。
2310
+ * @param options 更新参数:`public`、`fileSizeLimit`、`allowedMimeTypes`。不支持更新 `type`。
2311
+ */
2312
+ updateBucket(bucketId: string, options: UpdateBucketOptions): Promise<
2313
+ | { data: { message: string }; error: null }
2314
+ | { data: null; error: StorageError }
2315
+ >
2241
2316
 
2242
- getUploadMetadata(
2243
- params: ICloudbaseGetUploadMetadataParams,
2244
- callback?: Function,
2245
- ): Promise<ICloudbaseFileMetaDataRes>
2317
+ /**
2318
+ * 删除空 Bucket。
2319
+ *
2320
+ * @param bucketId Bucket ID。
2321
+ * @remarks Bucket 非空时后端会返回错误。
2322
+ */
2323
+ deleteBucket(bucketId: string): Promise<
2324
+ | { data: { message: string }; error: null }
2325
+ | { data: null; error: StorageError }
2326
+ >
2327
+ }
2246
2328
 
2247
- copyFile(
2248
- params: ICloudbaseCopyFileParams,
2249
- callback?: Function,
2250
- ): Promise<ICloudbaseCopyFileResult>
2329
+ /**
2330
+ * `app.storage` 命名空间(分流器)。继承 `StorageBucketApi` 的 Bucket 管理能力,并提供 `from()` 分流。
2331
+ *
2332
+ * `from()` 分流到两个**对等且独立**的客户端——`ClassicStorageFileApi`(传统环境)
2333
+ * 与 `StorageFileApi`(针对全新的 Neo 环境)。
2334
+ *
2335
+ * - `from()`:返回 `ClassicStorageFileApi`;
2336
+ * - `from(bucketId)`:返回 `StorageFileApi`。
2337
+ */
2338
+ interface StorageClient extends StorageBucketApi {
2339
+ /**
2340
+ * 进入对象操作客户端。
2341
+ *
2342
+ * - `from()`(不传 bucketId):返回传统环境对象操作客户端;
2343
+ * - `from(bucketId)`:返回 Neo 环境对象操作(`bucketId + objectName` 语义)客户端。
2344
+ *
2345
+ * @remarks 传入 `bucketId` 时返回的客户端仅 Neo 环境可用。
2346
+ *
2347
+ * @example
2348
+ * ```typescript
2349
+ * // 传统环境
2350
+ * const file = app.storage.from()
2351
+ * // Neo 环境
2352
+ * const avatars = app.storage.from('avatars')
2353
+ * ```
2354
+ */
2355
+ from(): ClassicStorageFileApi
2356
+ from<B extends string>(bucketId: B): StorageFileApi
2357
+ }
2251
2358
 
2252
- getFileInfo(
2253
- params: ICloudbaseGetTempFileURLParams,
2254
- ): Promise<ICloudbaseGetFileInfoResult>
2359
+ // ==================== Storage 类型 ====================
2360
+ // 以下类型通过 app.storage.from(bucketId) 与 Bucket 管理 API 暴露。
2361
+
2362
+ type BucketType = 'STANDARD'
2363
+
2364
+ /** Bucket 资源(对应 storage.buckets 表记录)。 */
2365
+ interface Bucket {
2366
+ /** Bucket ID。 */
2367
+ id: string
2368
+ /** Bucket 名称。 */
2369
+ name: string
2370
+ /** 创建者用户 ID;可能为空。 */
2371
+ owner_id?: string | null
2372
+ /** 是否为公开 Bucket。 */
2373
+ public: boolean
2374
+ /** Bucket 类型。 */
2375
+ type?: BucketType
2376
+ /** 文件大小限制,单位为字节;`null` 表示不限制。 */
2377
+ file_size_limit?: number | null
2378
+ /** 允许上传的 MIME 类型列表;`null` 表示不限制。 */
2379
+ allowed_mime_types?: string[] | null
2380
+ /** 创建时间,ISO 8601 日期时间字符串。 */
2381
+ created_at: string
2382
+ /** 更新时间,ISO 8601 日期时间字符串。 */
2383
+ updated_at: string
2384
+ }
2385
+
2386
+ interface ListBucketOptions {
2387
+ /** 返回数量限制。 */
2388
+ limit?: number
2389
+ /** 分页偏移量。 */
2390
+ offset?: number
2391
+ /** 排序字段。 */
2392
+ sortColumn?: 'id' | 'name' | 'created_at' | 'updated_at'
2393
+ /** 排序方向。 */
2394
+ sortOrder?: 'asc' | 'desc'
2395
+ /** 搜索关键词。 */
2396
+ search?: string
2397
+ }
2398
+
2399
+ interface CreateBucketOptions {
2400
+ /** 是否公开,默认 `false`。 */
2401
+ public?: boolean
2402
+ /** 文件大小限制;数字按字节处理,字符串支持如 `100MB`,`null` 表示不限制。 */
2403
+ fileSizeLimit?: number | string | null
2404
+ /** 允许上传的 MIME 类型列表,`null` 表示不限制。 */
2405
+ allowedMimeTypes?: string[] | null
2406
+ /** Bucket 类型,仅创建时可传。 */
2407
+ type?: BucketType
2408
+ }
2409
+
2410
+ interface UpdateBucketOptions {
2411
+ /** 是否公开。 */
2412
+ public?: boolean
2413
+ /** 文件大小限制;数字按字节处理,字符串支持如 `100MB`,`null` 表示不限制。 */
2414
+ fileSizeLimit?: number | string | null
2415
+ /** 允许上传的 MIME 类型列表,`null` 表示不限制。 */
2416
+ allowedMimeTypes?: string[] | null
2417
+ }
2418
+
2419
+ /** 上传选项。 */
2420
+ type UploadOptions = FileOptions
2421
+
2422
+ interface UploadResult {
2423
+ /** 对象 UUID(后端 `Id`)。 */
2424
+ id: string
2425
+ /** Bucket 内相对路径。 */
2426
+ path: string
2427
+ /** 对象完整路径 `bucketId/objectName`(后端 `Key`)。 */
2428
+ fullPath: string
2429
+ }
2430
+
2431
+ interface DownloadOptions {
2432
+ /** 触发浏览器下载,传字符串作为下载文件名。 */
2433
+ download?: string | boolean
2434
+ /** 缓存失效 nonce,追加到请求 URL 以绕过 CDN 缓存。 */
2435
+ cacheNonce?: string
2436
+ }
2437
+
2438
+ interface ListOptions {
2439
+ /** 返回数量限制。 */
2440
+ limit?: number
2441
+ /** 翻页游标,由上一页响应的 `nextCursor` 提供。 */
2442
+ cursor?: string
2443
+ /** 是否使用 `/` 作为分隔符区分文件夹。 */
2444
+ withDelimiter?: boolean
2445
+ /** 排序配置。 */
2446
+ sortBy?: {
2447
+ /** 排序字段。 */
2448
+ column?: 'name' | 'created_at' | 'updated_at'
2449
+ /** 排序方向。 */
2450
+ order?: 'asc' | 'desc'
2451
+ }
2452
+ }
2453
+
2454
+ interface ListObjectsEntry {
2455
+ /** 对象完整 key;文件夹条目可能为空。 */
2456
+ key?: string | null
2457
+ /** 对象名或文件夹名。 */
2458
+ name: string
2459
+ /** 对象 UUID;文件夹条目可能为空。 */
2460
+ id?: string | null
2461
+ /** 更新时间,ISO 8601 日期时间字符串。 */
2462
+ updated_at?: string | null
2463
+ /** 创建时间,ISO 8601 日期时间字符串。 */
2464
+ created_at?: string | null
2465
+ /** 最后访问时间,ISO 8601 日期时间字符串。 */
2466
+ last_accessed_at?: string | null
2467
+ /** 对象元数据。 */
2468
+ metadata?: Record<string, any> | null
2469
+ }
2470
+
2471
+ interface ListObjectsResponse {
2472
+ /** 当前前缀下的文件夹条目。 */
2473
+ folders: ListObjectsEntry[]
2474
+ /** 当前前缀下的对象条目。 */
2475
+ objects: ListObjectsEntry[]
2476
+ /** 是否还有下一页。 */
2477
+ hasNext: boolean
2478
+ /** 下一页游标。 */
2479
+ nextCursor?: string
2480
+ /** 下一页起始 key。 */
2481
+ nextCursorKey?: string
2482
+ }
2483
+
2484
+ interface ObjectInfo {
2485
+ /** 对象 UUID。 */
2486
+ id: string
2487
+ /** Bucket 内相对路径。 */
2488
+ name: string
2489
+ /** 对象版本标识;可能为空。 */
2490
+ version?: string | null
2491
+ /** 所属 Bucket ID。 */
2492
+ bucketId: string
2493
+ /** 文件大小,单位为字节;可能为空。 */
2494
+ size?: number | null
2495
+ /** 文件 MIME 类型;可能为空。 */
2496
+ contentType?: string | null
2497
+ /** 缓存控制信息;可能为空。 */
2498
+ cacheControl?: string | null
2499
+ /** 对象 ETag;可能为空。 */
2500
+ etag?: string | null
2501
+ /** 用户自定义元数据。 */
2502
+ metadata?: Record<string, any>
2503
+ /** 最后修改时间,ISO 8601 日期时间字符串。 */
2504
+ lastModified?: string | null
2505
+ /** 创建时间,ISO 8601 日期时间字符串。 */
2506
+ createdAt?: string | null
2507
+ }
2508
+
2509
+ interface FullObject {
2510
+ /** Bucket 内相对路径。 */
2511
+ name: string
2512
+ /** 所属 Bucket ID。 */
2513
+ bucket_id: string
2514
+ /** 创建者用户 ID;可能为空。 */
2515
+ owner_id?: string | null
2516
+ /** 对象版本标识;可能为空。 */
2517
+ version?: string | null
2518
+ /** 对象 UUID;可能为空。 */
2519
+ id?: string | null
2520
+ /** 更新时间,ISO 8601 日期时间字符串。 */
2521
+ updated_at?: string | null
2522
+ /** 创建时间,ISO 8601 日期时间字符串。 */
2523
+ created_at?: string | null
2524
+ /** 最后访问时间,ISO 8601 日期时间字符串。 */
2525
+ last_accessed_at?: string | null
2526
+ /** 系统或对象元数据。 */
2527
+ metadata?: Record<string, any>
2528
+ /** 用户自定义元数据。 */
2529
+ user_metadata?: Record<string, any>
2530
+ }
2531
+
2532
+ interface DestinationOptions {
2533
+ /** 目标 Bucket ID,默认与源相同。 */
2534
+ destinationBucket?: string
2535
+ /** 允许覆盖目标位置已有对象。 */
2536
+ upsert?: boolean
2537
+ /** 是否复制源对象元数据,默认 true。 */
2538
+ copyMetadata?: boolean
2539
+ /** `copyMetadata=false` 时合并到目标对象的用户元数据。 */
2540
+ metadata?: Record<string, any>
2541
+ }
2542
+
2543
+ interface SignedUrlOptions {
2544
+ /** 触发浏览器下载,传字符串作为下载文件名。 */
2545
+ download?: string | boolean
2546
+ /** 缓存失效 nonce,追加到请求 URL 以绕过 CDN 缓存。 */
2547
+ cacheNonce?: string
2548
+ }
2549
+
2550
+ /** 公开 URL 选项。 */
2551
+ interface PublicUrlOptions {
2552
+ /** 触发浏览器下载,传字符串作为下载文件名。 */
2553
+ download?: string | boolean
2554
+ /** 缓存失效 nonce,追加到请求 URL 以绕过 CDN 缓存。 */
2555
+ cacheNonce?: string
2556
+ }
2557
+
2558
+ /**
2559
+ * 请求级 fetch 控制参数(对齐 Supabase `FetchParameters`)。
2560
+ *
2561
+ * 纯客户端能力:`signal` 用于取消请求;`cache` 透传给底层 fetch 的缓存策略
2562
+ * (主要在浏览器 fetch 路径生效,XHR / 部分运行时会忽略)。
2563
+ */
2564
+ interface FetchParameters {
2565
+ /** 请求取消信号。 */
2566
+ signal?: AbortSignal
2567
+ /** 透传给底层 `fetch` 的缓存策略。 */
2568
+ cache?: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached'
2569
+ }
2570
+
2571
+ /**
2572
+ * 流式下载构建器(thenable)。`await` 后 resolve 为 `Result<ReadableStream>`。
2573
+ * 由 `DownloadBuilder.asStream()` 创建。
2574
+ */
2575
+ interface StreamDownloadBuilder extends PromiseLike<
2576
+ | { data: ReadableStream<Uint8Array>; error: null }
2577
+ | { data: null; error: StorageError }
2578
+ > {}
2579
+
2580
+ /**
2581
+ * 下载构建器(thenable)。默认 `await` 得 `Result<Blob>`;`.asStream()` 切换为流式终态。
2582
+ * 惰性执行:请求在 `await` / `.then()` 时才真正发出。
2583
+ */
2584
+ interface DownloadBuilder extends PromiseLike<
2585
+ | { data: Blob; error: null }
2586
+ | { data: null; error: StorageError }
2587
+ > {
2588
+ /** 切换为流式下载终态,返回 `StreamDownloadBuilder`。 */
2589
+ asStream(): StreamDownloadBuilder
2590
+ }
2591
+
2592
+ /**
2593
+ * 单 Bucket 对象操作客户端。通过 `app.storage.from(bucketId)` 获取。
2594
+ *
2595
+ * @remarks 所有 `objectName` 均为 Bucket 内相对路径。
2596
+ */
2597
+ interface StorageFileApi {
2598
+ /** 当前客户端绑定的 Bucket ID。 */
2599
+ readonly bucketId: string
2600
+
2601
+ /**
2602
+ * 启用错误抛出模式。开启后请求失败会抛异常;请求成功仍返回 `{ data, error: null }`。
2603
+ */
2604
+ throwOnError(): this
2605
+
2606
+ /**
2607
+ * 设置自定义请求头(链式)。
2608
+ *
2609
+ * @remarks 设置后对当前实例后续所有请求生效;每个 `from(bucketId)` 返回独立实例,互不影响。
2610
+ * 单次请求内部的功能性头(如上传的 `Content-Type` / `x-upsert`)优先级更高,会覆盖此处同名头。
2611
+ * name 为空或 name/value 含 CR/LF 时抛 `StorageError`。
2612
+ */
2613
+ setHeader(name: string, value: string): this
2614
+
2615
+ /**
2616
+ * 直接上传对象,默认不覆盖同名对象。
2617
+ *
2618
+ * 需要当前用户已登录,权限由 `storage.objects` 的 RLS `INSERT` / `UPDATE` 策略判定。
2619
+ *
2620
+ * 上传行为:
2621
+ * - `options.upsert` 默认 `false`:目标路径已有对象时,上传失败。
2622
+ * - `options.upsert` 设为 `true`:目标路径已有对象时,覆盖写入。
2623
+ * - 成功时返回 `{ id, path, fullPath }`。
2624
+ *
2625
+ * @param path Bucket 内相对路径。
2626
+ * @param fileBody 文件内容。
2627
+ * @param fileOptions 上传选项,如 `contentType`、`cacheControl`、`upsert`、`metadata`。
2628
+ * @see createSignedUploadUrl uploadToSignedUrl
2629
+ */
2630
+ upload(path: string, fileBody: FileBody, fileOptions?: UploadOptions): Promise<
2631
+ | { data: UploadResult; error: null }
2632
+ | { data: null; error: StorageError }
2633
+ >
2634
+
2635
+ /**
2636
+ * 覆盖更新对象。
2637
+ *
2638
+ * 与 `upload` 共享同一底层,区别:
2639
+ * - 使用 `PUT` 方法(语义为覆盖)。
2640
+ * - 目标路径不存在时也会创建(upsert 行为)。
2641
+ *
2642
+ * @param path Bucket 内相对路径。
2643
+ * @param fileBody 文件内容。
2644
+ * @param fileOptions 上传选项,如 `contentType`、`cacheControl`、`metadata`。
2645
+ */
2646
+ update(path: string, fileBody: FileBody, fileOptions?: UploadOptions): Promise<
2647
+ | { data: UploadResult; error: null }
2648
+ | { data: null; error: StorageError }
2649
+ >
2650
+
2651
+ /**
2652
+ * 下载对象。返回**下载构建器**(thenable),默认 `await` 得到 `Blob`。
2653
+ *
2654
+ * 需要登录态,权限由 `storage.objects` 的 RLS `SELECT` 策略判定。
2655
+ *
2656
+ * 两种终态:
2657
+ * - 默认:`await bucket.download(path)` → `{ data: Blob, error }`。
2658
+ * - 流式:`await bucket.download(path).asStream()` → `{ data: ReadableStream, error }`,
2659
+ * 适合 Node 大文件等不希望整体读入内存的场景。
2660
+ *
2661
+ * 两者统一走原生 `fetch` 的 `Response`:流式终态返回 `Response.body`,Blob 终态调 `Response.blob()`。
2662
+ *
2663
+ * 下载行为:
2664
+ * - 惰性执行:请求在 `await` / `.then()` 时才真正发出。
2665
+ * - 返回的 `Blob` 不会自动触发浏览器下载或渲染,需配合 `URL.createObjectURL` 手动处理。
2666
+ * - 支持 `parameters.signal`(AbortSignal)取消进行中的下载。
2667
+ *
2668
+ * @param path Bucket 内相对路径。
2669
+ * @param options 下载选项,支持 `download`(触发浏览器下载)、`cacheNonce`(绕过 CDN 缓存)。
2670
+ * @param parameters 请求控制参数,支持 `signal` / `cache`。
2671
+ * @returns `DownloadBuilder`:可 `await` 得 `Blob`,或 `.asStream()` 后得 `ReadableStream`。
2672
+ */
2673
+ download(path: string, options?: DownloadOptions, parameters?: FetchParameters): DownloadBuilder
2674
+
2675
+ /**
2676
+ * 获取对象列表(游标分页)。
2677
+ *
2678
+ * 采用**游标分页**,与 Supabase 的 `listV2` 对应。
2679
+ *
2680
+ * - 首次查询不传 `cursor`,后续用上一页的 `nextCursor` 继续翻页。
2681
+ * - 返回 `{ folders, objects, hasNext, nextCursor }`(区别于 Supabase `list` 的 offset 分页 `FileObject[]`)。
2682
+ * - `path` 不传时列出 Bucket 根目录。
2683
+ * - `options.withDelimiter` 为 `true` 时以 `/` 分隔文件夹和文件。
2684
+ *
2685
+ * @param path 路径前缀,不传表示 Bucket 根目录。
2686
+ * @param options 列表选项,支持 `limit`、`cursor`、`withDelimiter`、`sortBy`。
2687
+ * @param parameters 请求控制参数,支持 `signal` / `cache`。
2688
+ * @remarks 本方法对应 Supabase 的 `listV2`(游标分页),而非 `list`(offset 分页)。
2689
+ */
2690
+ list(path?: string, options?: ListOptions, parameters?: FetchParameters): Promise<
2691
+ | { data: ListObjectsResponse; error: null }
2692
+ | { data: null; error: StorageError }
2693
+ >
2694
+
2695
+ /**
2696
+ * 删除一个或多个对象。
2697
+ *
2698
+ * 权限由 `storage.objects` 的 RLS `DELETE` 策略判定。
2699
+ *
2700
+ * - 后端单次最多删除 100 个对象,超出时 SDK 自动分批发送。
2701
+ * - 返回所有被成功删除的对象信息(`FullObject[]`)。
2702
+ *
2703
+ * @param paths Bucket 内相对路径数组。
2704
+ */
2705
+ remove(paths: string[]): Promise<
2706
+ | { data: FullObject[]; error: null }
2707
+ | { data: null; error: StorageError }
2708
+ >
2709
+
2710
+ /**
2711
+ * 复制对象,支持跨 Bucket。
2712
+ *
2713
+ * 权限由 `storage.objects` 的 RLS 策略判定:读取源需要 `SELECT`,写入目标需要 `INSERT`。
2714
+ *
2715
+ * - `options.destinationBucket` 不传时在同一 Bucket 内复制。
2716
+ * - `options.upsert` 为 `true` 时,目标路径已有对象则覆盖。
2717
+ * - `options.copyMetadata` 设为 `false` 并传 `options.metadata` 时替换原 metadata。
2718
+ * - 返回目标对象的完整路径。
2719
+ *
2720
+ * @param fromPath 源对象 Bucket 内相对路径。
2721
+ * @param toPath 目标对象相对路径。
2722
+ * @param options 目标 Bucket、覆盖、元数据复制等选项。
2723
+ */
2724
+ copy(fromPath: string, toPath: string, options?: DestinationOptions): Promise<
2725
+ | { data: { path: string }; error: null }
2726
+ | { data: null; error: StorageError }
2727
+ >
2728
+
2729
+ /**
2730
+ * 移动对象,支持跨 Bucket;源对象会被删除。
2731
+ *
2732
+ * 语义为"复制到目标 → 删除源",非原地重命名。
2733
+ * 权限由 `storage.objects` 的 RLS 策略判定:读取源需要 `SELECT`,写入目标需要 `INSERT`,删除源需要 `DELETE`。
2734
+ *
2735
+ * - `options.destinationBucket` 不传时在同一 Bucket 内移动。
2736
+ *
2737
+ * @param fromPath 源对象 Bucket 内相对路径。
2738
+ * @param toPath 目标对象相对路径。
2739
+ * @param options 目标 Bucket 等选项。
2740
+ */
2741
+ move(fromPath: string, toPath: string, options?: DestinationOptions): Promise<
2742
+ | { data: { message: string }; error: null }
2743
+ | { data: null; error: StorageError }
2744
+ >
2745
+
2746
+ /**
2747
+ * 获取对象元信息。
2748
+ *
2749
+ * 返回对象在 `storage.objects` 表中的记录信息,包括 `bucketId`、`version`、`etag`、
2750
+ * `contentType`、`cacheControl`、`metadata`、`lastModified`、`createdAt` 等。
2751
+ *
2752
+ * @param path Bucket 内相对路径。
2753
+ */
2754
+ info(path: string): Promise<
2755
+ | { data: ObjectInfo; error: null }
2756
+ | { data: null; error: StorageError }
2757
+ >
2758
+
2759
+ /**
2760
+ * 判断对象是否存在。
2761
+ *
2762
+ * 底层调用 `info` 端点:
2763
+ * - HTTP 200 → 存在(返回 `true`)。
2764
+ * - HTTP 400 或 404 → 不存在(返回 `false`)。
2765
+ * - 其他异常 → 返回 `{ data: null, error }`。
2766
+ *
2767
+ * @param path Bucket 内相对路径。
2768
+ */
2769
+ exists(path: string): Promise<
2770
+ | { data: boolean; error: null }
2771
+ | { data: null; error: StorageError }
2772
+ >
2773
+
2774
+ /**
2775
+ * 生成单个对象的签名下载 URL。
2776
+ *
2777
+ * 需要登录态,权限由 `storage.objects` 的 RLS `SELECT` 策略判定。
2778
+ *
2779
+ * - `expiresIn` 以秒为单位,过期后 URL 不可用。
2780
+ * - 返回的 `fullSignedURL` 是服务端已拼接好的完整 URL,客户端可直接使用(无需再拼 HOST)。
2781
+ * - `options.download` 为 `true` 时追加 `?download`,浏览器访问时自动触发下载。
2782
+ *
2783
+ * @param path Bucket 内相对路径。
2784
+ * @param expiresIn 过期时间,单位为秒。
2785
+ * @param options 签名下载 URL 选项;当前仅支持 `download`,不支持图片 `transform`。
2786
+ */
2787
+ createSignedUrl(path: string, expiresIn: number, options?: SignedUrlOptions): Promise<
2788
+ | { data: { fullSignedURL: string }; error: null }
2789
+ | { data: null; error: StorageError }
2790
+ >
2791
+
2792
+ /**
2793
+ * 批量生成对象的签名下载 URL。
2794
+ *
2795
+ * 需要登录态,权限由 `storage.objects` 的 RLS `SELECT` 策略判定。
2796
+ *
2797
+ * - 后端单次最多 500 个,超出时 SDK 自动分批发送。
2798
+ * - 返回数组中每个元素包含 `path`、`fullSignedURL`(完整 URL,生成失败时为 `null`)、`error`。
2799
+ * - 部分路径生成失败不会影响其他路径。
2800
+ *
2801
+ * @param paths Bucket 内相对路径数组。
2802
+ * @param expiresIn 过期时间,单位为秒。
2803
+ * @param options 签名下载 URL 选项;当前仅支持 `download`,不支持图片 `transform`。
2804
+ */
2805
+ createSignedUrls(paths: string[], expiresIn: number, options?: SignedUrlOptions): Promise<
2806
+ | { data: Array<{ path: string; fullSignedURL: string | null; error: string | null }>; error: null }
2807
+ | { data: null; error: StorageError }
2808
+ >
2809
+
2810
+ /**
2811
+ * 两阶段上传(第一阶段):生成签名上传 URL,需登录态。
2812
+ *
2813
+ * 服务端基于调用者身份 + RLS 策略判断上传权限,生成临时签名 URL 和 token。
2814
+ * 适合的场景:服务端鉴定用户权限后,将 `token` 下发给不受信客户端(如浏览器前端),
2815
+ * 让客户端用 `uploadToSignedUrl` 直接上传文件,无需暴露登录凭证。
2816
+ *
2817
+ * - 返回的 `fullSignedURL` 是服务端已拼接好的完整上传 URL。
2818
+ * - 返回的 `token` 是临时凭证,与 `uploadToSignedUrl` 配合使用。
2819
+ * - `options.upsert` 为 `true` 时允许覆盖同名对象。
2820
+ *
2821
+ * @param path Bucket 内相对路径。
2822
+ * @param options 签名上传选项,`upsert=true` 时允许覆盖。
2823
+ * @see uploadToSignedUrl
2824
+ */
2825
+ createSignedUploadUrl(path: string, options?: { upsert?: boolean }): Promise<
2826
+ | { data: { fullSignedURL: string; token: string; path: string }; error: null }
2827
+ | { data: null; error: StorageError }
2828
+ >
2829
+
2830
+ /**
2831
+ * 两阶段上传(第二阶段):使用签名上传 token 上传对象,无需登录态。
2832
+ *
2833
+ * 配合 `createSignedUploadUrl` 完成两阶段上传:
2834
+ * 1. 服务端调用 `createSignedUploadUrl` 生成 token(需登录态)
2835
+ * 2. 客户端调用本方法,凭 token 上传文件(无需登录态)
2836
+ *
2837
+ * - 请求**不携带**登录态,仅凭 `token` 鉴权。
2838
+ * - `path` 和 `token` 必须与 `createSignedUploadUrl` 的返回值对应。
2839
+ *
2840
+ * @param path Bucket 内相对路径,需与 `createSignedUploadUrl` 的 `path` 一致。
2841
+ * @param token `createSignedUploadUrl()` 返回的 `token`。
2842
+ * @param fileBody 文件内容。
2843
+ * @param fileOptions 上传选项。
2844
+ * @see createSignedUploadUrl
2845
+ */
2846
+ uploadToSignedUrl(path: string, token: string, fileBody: FileBody, fileOptions?: UploadOptions): Promise<
2847
+ | { data: { path: string; fullPath: string }; error: null }
2848
+ | { data: null; error: StorageError }
2849
+ >
2850
+
2851
+ /**
2852
+ * 同步获取 public bucket 对象的公开访问 URL;不发请求、不返回 `error`。
2853
+ *
2854
+ * **同步方法**,不发起网络请求,不会抛异常。
2855
+ *
2856
+ * - URL 由客户端直接拼接 `{gateway}/v1/storages/object/public/{bucketId}/{path}` 得到。
2857
+ * - URL 是否可访问取决于 Bucket 的 `public` 属性。
2858
+ * - `options.download` 为 `true` 时追加 `?download`。
2859
+ *
2860
+ * @param path Bucket 内相对路径。
2861
+ * @param options 公开 URL 选项;当前仅支持 `download`,不支持图片 `transform`。
2862
+ */
2863
+ getPublicUrl(path: string, options?: PublicUrlOptions): { data: { publicUrl: string } }
2255
2864
  }
2256
2865
  }
2257
2866