@dimah-s3/react 1.7.1 → 2.0.0-beta.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 (148) hide show
  1. package/README.md +53 -13
  2. package/dist/api.d.ts +24 -15
  3. package/dist/api.d.ts.map +1 -1
  4. package/dist/chunk-SPUUNLXI.js +824 -0
  5. package/dist/chunk-SPUUNLXI.js.map +1 -0
  6. package/dist/create-s3-client.d.ts +1 -1
  7. package/dist/create-s3-client.d.ts.map +1 -1
  8. package/dist/engine.d.ts +15 -1
  9. package/dist/engine.d.ts.map +1 -1
  10. package/dist/engine.js +204 -512
  11. package/dist/engine.js.map +1 -1
  12. package/dist/helpers/format-accept-labels.d.ts +15 -2
  13. package/dist/helpers/format-accept-labels.d.ts.map +1 -1
  14. package/dist/helpers/format-date.d.ts +7 -0
  15. package/dist/helpers/format-date.d.ts.map +1 -0
  16. package/dist/helpers/format-dimah-error.d.ts +12 -2
  17. package/dist/helpers/format-dimah-error.d.ts.map +1 -1
  18. package/dist/helpers/format-file-size.d.ts +20 -0
  19. package/dist/helpers/format-file-size.d.ts.map +1 -0
  20. package/dist/helpers/format-speed.d.ts +1 -1
  21. package/dist/helpers/format-speed.d.ts.map +1 -1
  22. package/dist/helpers/format-upload-progress.d.ts +1 -1
  23. package/dist/helpers/format-upload-progress.d.ts.map +1 -1
  24. package/dist/helpers/index.d.ts +5 -8
  25. package/dist/helpers/index.d.ts.map +1 -1
  26. package/dist/helpers/load-route-catalog.d.ts +32 -8
  27. package/dist/helpers/load-route-catalog.d.ts.map +1 -1
  28. package/dist/helpers/throttled-speed.d.ts +2 -2
  29. package/dist/helpers/throttled-speed.d.ts.map +1 -1
  30. package/dist/helpers/to-timestamp.d.ts +5 -0
  31. package/dist/helpers/to-timestamp.d.ts.map +1 -0
  32. package/dist/helpers/truncate-file-name.d.ts +8 -0
  33. package/dist/helpers/truncate-file-name.d.ts.map +1 -0
  34. package/dist/helpers/use-format-accept-labels.d.ts +12 -0
  35. package/dist/helpers/use-format-accept-labels.d.ts.map +1 -0
  36. package/dist/helpers/use-format-eta.d.ts +14 -0
  37. package/dist/helpers/use-format-eta.d.ts.map +1 -0
  38. package/dist/helpers/use-format-speed.d.ts +12 -0
  39. package/dist/helpers/use-format-speed.d.ts.map +1 -0
  40. package/dist/hooks/use-delete.d.ts +6 -44
  41. package/dist/hooks/use-delete.d.ts.map +1 -1
  42. package/dist/hooks/use-download.d.ts +7 -117
  43. package/dist/hooks/use-download.d.ts.map +1 -1
  44. package/dist/hooks/use-fetch-download.d.ts +8 -0
  45. package/dist/hooks/use-fetch-download.d.ts.map +1 -0
  46. package/dist/hooks/use-file-intake.d.ts +43 -29
  47. package/dist/hooks/use-file-intake.d.ts.map +1 -1
  48. package/dist/hooks/use-file-upload.d.ts +38 -34
  49. package/dist/hooks/use-file-upload.d.ts.map +1 -1
  50. package/dist/hooks/use-object-list-selection.d.ts +78 -0
  51. package/dist/hooks/use-object-list-selection.d.ts.map +1 -0
  52. package/dist/hooks/use-object-list.d.ts +66 -16
  53. package/dist/hooks/use-object-list.d.ts.map +1 -1
  54. package/dist/hooks/use-object-url.d.ts +27 -10
  55. package/dist/hooks/use-object-url.d.ts.map +1 -1
  56. package/dist/hooks/use-route-upload-policy.d.ts +22 -14
  57. package/dist/hooks/use-route-upload-policy.d.ts.map +1 -1
  58. package/dist/hooks/use-upload.d.ts +72 -65
  59. package/dist/hooks/use-upload.d.ts.map +1 -1
  60. package/dist/index.d.ts +15 -19
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +2420 -2164
  63. package/dist/index.js.map +1 -1
  64. package/dist/internal/abortable.d.ts +9 -0
  65. package/dist/internal/abortable.d.ts.map +1 -0
  66. package/dist/internal/browser-download.d.ts +15 -0
  67. package/dist/internal/browser-download.d.ts.map +1 -0
  68. package/dist/internal/callbacks.d.ts +54 -0
  69. package/dist/internal/callbacks.d.ts.map +1 -0
  70. package/dist/internal/client-error.d.ts +15 -0
  71. package/dist/internal/client-error.d.ts.map +1 -0
  72. package/dist/internal/hooks.d.ts +27 -0
  73. package/dist/internal/hooks.d.ts.map +1 -0
  74. package/dist/internal/lru.d.ts +13 -0
  75. package/dist/internal/lru.d.ts.map +1 -0
  76. package/dist/internal/operations.d.ts +74 -0
  77. package/dist/internal/operations.d.ts.map +1 -0
  78. package/dist/internal/pool.d.ts +8 -0
  79. package/dist/internal/pool.d.ts.map +1 -0
  80. package/dist/list/entries.d.ts +14 -0
  81. package/dist/list/entries.d.ts.map +1 -0
  82. package/dist/list/memory-object-source.d.ts +60 -0
  83. package/dist/list/memory-object-source.d.ts.map +1 -0
  84. package/dist/list/types.d.ts +123 -11
  85. package/dist/list/types.d.ts.map +1 -1
  86. package/dist/s3-provider.d.ts +3 -2
  87. package/dist/s3-provider.d.ts.map +1 -1
  88. package/dist/store/local-storage-store.d.ts +5 -4
  89. package/dist/store/local-storage-store.d.ts.map +1 -1
  90. package/dist/store/memory-store.d.ts +3 -4
  91. package/dist/store/memory-store.d.ts.map +1 -1
  92. package/dist/translations/types.d.ts +105 -23
  93. package/dist/translations/types.d.ts.map +1 -1
  94. package/dist/types/delete.d.ts +98 -9
  95. package/dist/types/delete.d.ts.map +1 -1
  96. package/dist/types/download.d.ts +152 -23
  97. package/dist/types/download.d.ts.map +1 -1
  98. package/dist/types/index.d.ts +1 -1
  99. package/dist/types/index.d.ts.map +1 -1
  100. package/dist/types/operation.d.ts +38 -0
  101. package/dist/types/operation.d.ts.map +1 -0
  102. package/dist/types/upload-store.d.ts +30 -40
  103. package/dist/types/upload-store.d.ts.map +1 -1
  104. package/dist/types/upload.d.ts +177 -130
  105. package/dist/types/upload.d.ts.map +1 -1
  106. package/dist/upload/abort.d.ts +10 -0
  107. package/dist/upload/abort.d.ts.map +1 -0
  108. package/dist/upload/constants.d.ts +8 -3
  109. package/dist/upload/constants.d.ts.map +1 -1
  110. package/dist/upload/index.d.ts +3 -2
  111. package/dist/upload/index.d.ts.map +1 -1
  112. package/dist/upload/multipart.d.ts +14 -4
  113. package/dist/upload/multipart.d.ts.map +1 -1
  114. package/dist/upload/part-pool.d.ts +16 -0
  115. package/dist/upload/part-pool.d.ts.map +1 -0
  116. package/dist/upload/presigned-http.d.ts +5 -14
  117. package/dist/upload/presigned-http.d.ts.map +1 -1
  118. package/dist/upload/progress.d.ts +7 -0
  119. package/dist/upload/progress.d.ts.map +1 -0
  120. package/dist/upload/request.d.ts +9 -0
  121. package/dist/upload/request.d.ts.map +1 -0
  122. package/dist/upload/resume-key.d.ts +7 -3
  123. package/dist/upload/resume-key.d.ts.map +1 -1
  124. package/dist/upload/retry.d.ts +27 -2
  125. package/dist/upload/retry.d.ts.map +1 -1
  126. package/dist/upload/stored-upload.d.ts +7 -0
  127. package/dist/upload/stored-upload.d.ts.map +1 -0
  128. package/dist/upload/upload-file.d.ts +10 -11
  129. package/dist/upload/upload-file.d.ts.map +1 -1
  130. package/dist/upload/upload-part.d.ts +6 -3
  131. package/dist/upload/upload-part.d.ts.map +1 -1
  132. package/dist/upload/xhr-upload.d.ts +10 -2
  133. package/dist/upload/xhr-upload.d.ts.map +1 -1
  134. package/package.json +7 -8
  135. package/dist/helpers/format-eta.d.ts +0 -13
  136. package/dist/helpers/format-eta.d.ts.map +0 -1
  137. package/dist/helpers/format-validate-file-error.d.ts +0 -9
  138. package/dist/helpers/format-validate-file-error.d.ts.map +0 -1
  139. package/dist/hooks/index.d.ts +0 -7
  140. package/dist/hooks/index.d.ts.map +0 -1
  141. package/dist/internal-helpers.d.ts +0 -10
  142. package/dist/internal-helpers.d.ts.map +0 -1
  143. package/dist/store/use-immer-state.d.ts +0 -8
  144. package/dist/store/use-immer-state.d.ts.map +0 -1
  145. package/dist/types/error.d.ts +0 -27
  146. package/dist/types/error.d.ts.map +0 -1
  147. package/dist/upload/upload-files.d.ts +0 -26
  148. package/dist/upload/upload-files.d.ts.map +0 -1
@@ -1,47 +1,46 @@
1
1
  /**
2
- * Minimal state that must be persisted to resume a multipart upload.
2
+ * What must be persisted to resume a multipart upload. The engine writes one
3
+ * record after `multipart.init` and deletes it once the upload completes or
4
+ * is cancelled.
3
5
  */
4
6
  export type StoredUpload = {
5
7
  /**
6
- * Client-side resume identity
7
- * (`${route}:${file.name}:${file.size}:${file.lastModified}`).
8
+ * Client-side resume identity from `multipartResumeKey`: the route, the
9
+ * file, and the request's name, type and metadata.
8
10
  */
9
11
  resumeKey: string;
10
- /** S3 multipart `UploadId` returned by `CreateMultipartUpload`. */
11
- uploadId: string;
12
+ /** Upload ticket from `multipart.init`. Every later multipart call sends it. */
13
+ ticket: string;
12
14
  /** Server-generated S3 object key. */
13
15
  key: string;
14
- /** Total file size in bytes — used to verify the same file is being resumed. */
16
+ /** S3 multipart `UploadId`. */
17
+ uploadId: string;
18
+ /** Total file size in bytes, so a different file is never resumed. */
15
19
  fileSize: number;
20
+ /** Part size the server chose, in bytes. */
21
+ partSize: number;
22
+ /** Number of parts the server chose. */
23
+ partCount: number;
24
+ /** Whether every part must send a SHA-256 checksum. */
25
+ checksum: boolean;
16
26
  };
17
27
  /**
18
- * Storage backend for resumable multipart uploads.
19
- *
20
- * Implement this interface to persist `uploadId` state in any storage system
21
- * (database, Redis, IndexedDB, etc.). The default implementation uses
22
- * `localStorage` via `createLocalStorageStore()`.
28
+ * Storage backend for resumable multipart uploads, looked up by
29
+ * {@link StoredUpload.resumeKey}. `createLocalStorageStore()` and
30
+ * `createMemoryStore()` are built in. Implement it to keep uploads in any
31
+ * other storage, such as IndexedDB or a database.
23
32
  *
24
- * Lookup is by {@link StoredUpload.resumeKey}, not the S3 object key.
33
+ * The engine ignores and deletes a record that is not a valid
34
+ * {@link StoredUpload}, such as one written by 1.x.
25
35
  *
26
36
  * @example
27
37
  * ```ts
28
38
  * const dbStore: UploadStore = {
29
39
  * async get(resumeKey, fileSize) {
30
- * const row = await db.uploads.findFirst({ where: { resumeKey, fileSize } });
31
- * return row
32
- * ? {
33
- * resumeKey,
34
- * uploadId: row.uploadId,
35
- * key: row.key,
36
- * fileSize,
37
- * }
38
- * : null;
40
+ * return (await db.uploads.findFirst({ where: { resumeKey, fileSize } })) ?? null;
39
41
  * },
40
42
  * async set(upload) {
41
- * await db.uploads.upsert({
42
- * where: { resumeKey: upload.resumeKey },
43
- * data: upload,
44
- * });
43
+ * await db.uploads.upsert({ where: { resumeKey: upload.resumeKey }, data: upload });
45
44
  * },
46
45
  * async delete(resumeKey) {
47
46
  * await db.uploads.deleteMany({ where: { resumeKey } });
@@ -50,20 +49,11 @@ export type StoredUpload = {
50
49
  * ```
51
50
  */
52
51
  export type UploadStore = {
53
- /**
54
- * Look up a pending upload by resume identity and file size.
55
- * Returns `null` if no matching upload is found.
56
- */
57
- get: (resumeKey: string, fileSize: number) => StoredUpload | null | Promise<StoredUpload | null>;
58
- /**
59
- * Persist a new upload state after `CreateMultipartUpload` succeeds.
60
- * Called once per upload, before any parts are sent.
61
- */
62
- set: (upload: StoredUpload) => void | Promise<void>;
63
- /**
64
- * Remove the upload state after the upload completes or is explicitly
65
- * abandoned. Should be a no-op if the key is not found.
66
- */
67
- delete: (resumeKey: string) => void | Promise<void>;
52
+ /** The pending upload for this resume identity and file size, or `null`. */
53
+ get(resumeKey: string, fileSize: number): StoredUpload | null | Promise<StoredUpload | null>;
54
+ /** Saves an upload after `multipart.init`, before any part is sent. */
55
+ set(upload: StoredUpload): void | Promise<void>;
56
+ /** Removes an upload. Does nothing when the key is unknown. */
57
+ delete(resumeKey: string): void | Promise<void>;
68
58
  };
69
59
  //# sourceMappingURL=upload-store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upload-store.d.ts","sourceRoot":"","sources":["../../src/types/upload-store.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,g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E,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,+DAA+D;IAC/D,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD,CAAC"}
@@ -1,173 +1,220 @@
1
- import type { APIError, S3RouteName, UploadPresignResponse } from "@dimah-s3/core";
1
+ import type { APIError, ConfirmedObjectResponse, S3Api, S3RouteName, UploadPresignResponse } from "@dimah-s3/core";
2
+ import type { TransferProgress } from "./operation";
2
3
  import type { UploadStore } from "./upload-store";
3
- /** Result returned after a successful upload. */
4
- export type UploadResult = {
5
- /** S3 object key. */
6
- key: string;
7
- /** Object ETag from S3. */
8
- eTag?: string;
9
- /** Verified size from HeadObject / multipart complete. */
10
- contentLength: number;
11
- /** MIME type from HeadObject. */
4
+ /** The verified object after a successful upload (from HeadObject). */
5
+ export type UploadResult = ConfirmedObjectResponse;
6
+ /** Per-upload options sent to the presign API. */
7
+ export type UploadRequestOptions = {
8
+ /**
9
+ * Client extras sent to the server `object` callback as `clientMetadata`.
10
+ * Not written to S3 unless the route copies them into `object().metadata`.
11
+ */
12
+ metadata?: Record<string, string>;
13
+ /** Overrides the browser's content type. */
12
14
  contentType?: string;
13
- /** Stored filename. */
15
+ /** Overrides the browser's file name. */
14
16
  fileName?: string;
15
17
  };
16
- /** Byte transfer progress for upload and fetch-download. */
17
- export type UploadProgress = {
18
- /** Bytes transferred so far. */
19
- loaded: number;
20
- /** Total bytes to transfer. */
21
- total: number;
22
- /** Progress percentage (0–100). */
23
- percent: number;
24
- /** Instantaneous transfer speed in bytes/second. `undefined` until measurable. */
25
- speed?: number;
18
+ /**
19
+ * Request options for every file, or a function that returns them per file.
20
+ * A throw from the function fails that file with `HOOK_FAILED`.
21
+ */
22
+ export type UploadRequestInput = UploadRequestOptions | ((file: File) => UploadRequestOptions);
23
+ /**
24
+ * Options for one `handleFiles` call. Call `uploadOptions` shallow-merge over
25
+ * the hook's: call fields win, and `metadata` merges key by key.
26
+ */
27
+ export type UploadCallOptions = {
28
+ uploadOptions?: UploadRequestInput;
29
+ /** Lowers `maxFiles` for this call. */
30
+ maxFiles?: number;
26
31
  };
27
- export type UploadPhase = "idle" | "validating" | "presigning" | "uploading" | "finalizing" | "success" | "error";
28
- /** Per-file status inside a batch (`pending` before bytes start). */
29
- export type UploadFileStatus = "pending" | "uploading" | "success" | "error";
30
- /** Display metadata for a file in upload UI (no raw `File`). */
32
+ /** Where one file is in its upload. */
33
+ export type UploadFilePhase = "queued" | "preparing" | "presigning" | "uploading" | "finalizing" | "success" | "error";
34
+ /** The phases `uploadFile` reports while a file is in flight. */
35
+ export type UploadEnginePhase = Extract<UploadFilePhase, "preparing" | "presigning" | "uploading" | "finalizing">;
36
+ /** The phase of the whole upload queue. */
37
+ export type UploadPhase = "idle" | "uploading" | "success" | "error";
38
+ /** Display metadata for a file in upload UI. */
31
39
  export type UploadFileInfo = {
32
- /** Display file name. */
33
- name: string;
40
+ fileName: string;
34
41
  /** File size in bytes. */
35
- size: number;
42
+ fileSize: number;
36
43
  /** MIME type from the browser `File`. */
37
- type: string;
44
+ contentType: string;
38
45
  /**
39
- * Object URL for an image thumbnail, or `null` for non-images.
40
- * Created/revoked by upload hooks — do not revoke manually while hooks own it.
46
+ * Object URL for an image thumbnail, or `null` for other files. The upload
47
+ * hooks create and revoke it, so do not revoke it yourself.
41
48
  */
42
49
  previewUrl: string | null;
43
50
  };
44
- /** Per-file state in `useUpload` (`files[]`; `file` is `files[0]`). */
51
+ /** One file in the `useUpload` queue. */
45
52
  export type UploadFileState = UploadFileInfo & {
46
- /** Unique ID for this file in the batch. */
53
+ /** Unique ID for this file in the queue. Pass it to `cancel(id)`. */
47
54
  id: string;
48
- status: UploadFileStatus;
49
- progress: UploadProgress;
55
+ file: File;
56
+ phase: UploadFilePhase;
57
+ progress: TransferProgress;
50
58
  error: APIError | null;
51
59
  /** Set after this file succeeds. */
52
60
  result: UploadResult | null;
53
61
  };
54
- /** Per-upload options passed to the presign API. */
55
- export type UploadRequestOptions = {
56
- /**
57
- * Client extras sent to the server `object` callback as `clientMetadata`.
58
- * Not written to S3 unless the route copies them into `object().metadata`.
59
- */
60
- metadata?: Record<string, string>;
61
- /** Override auto-detected content type. */
62
- contentType?: string;
63
- /**
64
- * Original file name sent on presign. Defaults to the browser's `file.name`.
65
- * The protocol requires a non-empty name — it cannot be omitted.
66
- */
67
- fileName?: string;
68
- /**
69
- * Unpadded base64 SHA-256. Sent when the route sets `upload.checksum`.
70
- * The engine computes this when {@link FileUploadConfig.checksum} is true.
71
- */
72
- checksum?: string;
73
- };
74
- /**
75
- * Lifecycle hooks for `useUpload`.
76
- * Callbacks that receive `File[]` / `UploadResult[]` always use arrays
77
- * (a single file is `[file]` / `[result]`).
78
- */
79
- export type UploadHooks = {
80
- /** Runs before the upload starts. Return `false` to block it. */
81
- beforeUpload?: (files: File[]) => Promise<boolean> | boolean;
82
- /** Fires after validation passes and the upload begins. */
83
- onUploadStart?: (files: File[]) => void;
84
- /** Fires continuously with aggregate progress across the batch. */
85
- onProgress?: (progress: UploadProgress) => void;
86
- /** Fires continuously for one file while its bytes are transferred. */
87
- onFileProgress?: (file: File, progress: UploadProgress) => void;
88
- /** Fires after each part is successfully uploaded to S3 (multipart only). */
89
- onPartUpload?: (file: File, partNumber: number, totalParts: number) => void;
90
- /** Fires once after `CreateMultipartUpload` succeeds (multipart only). */
91
- onMultipartInit?: (file: File, uploadId: string) => void;
92
- /** Fires when one file in the batch finishes successfully. */
93
- onFileSuccess?: (file: File, result: UploadResult) => void;
94
- /** Fires when one file in the batch fails. */
95
- onFileError?: (file: File, error: APIError) => void;
96
- /** Fires when every file in the batch succeeds. */
97
- onSuccess?: (results: UploadResult[]) => Promise<void> | void;
98
- /** Fires when the batch fails (validation, block, or one or more file errors). */
99
- onError?: (error: unknown, phase: UploadPhase) => void;
100
- /** Fires when the upload is cancelled via `cancel()`. */
101
- onCancel?: () => void;
62
+ /** How every file of one `handleFiles` call ended. */
63
+ export type UploadBatchResult = {
64
+ uploaded: {
65
+ file: File;
66
+ result: UploadResult;
67
+ }[];
68
+ failed: {
69
+ file: File;
70
+ error: APIError;
71
+ }[];
72
+ /** Files a `beforeUpload` callback blocked. */
73
+ blocked: File[];
74
+ /** Files cancelled or detached before they finished. */
75
+ aborted: File[];
102
76
  };
103
- /**
104
- * Replaces PUT/POST to `presign.url`. Use for in-memory backends or when
105
- * file bytes must not pass through a serverless function.
106
- */
107
- export type UploadTransport = (file: File, presign: UploadPresignResponse, options: {
108
- onProgress?: (progress: UploadProgress) => void;
109
- signal?: AbortSignal;
110
- }) => Promise<void>;
111
- /**
112
- * Custom `S3Api` objects may set this to handle the byte transfer instead of
113
- * uploading to the presigned URL.
114
- */
115
- export type S3ApiUploadTransport = {
116
- uploadTransport?: UploadTransport;
77
+ /** A file rejected before upload, such as for its type, size or count. */
78
+ export type FileRejection = {
79
+ file: File;
80
+ errors: readonly APIError[];
117
81
  };
118
- /** Retry configuration for failed network requests. */
82
+ /** Retry settings for failed network requests. */
119
83
  export type RetryConfig = {
120
- /** Maximum number of retry attempts per request. @default 3 */
84
+ /** Retries per request after the first attempt. @default 3 */
121
85
  maxRetries?: number;
122
86
  /** Base delay in ms for exponential backoff. @default 1000 */
123
87
  baseDelay?: number;
124
88
  };
125
- /** Engine configuration for `useUpload`. */
126
- export type FileUploadConfig = {
127
- /**
128
- * Named server route (`dimahS3({ routes })`). Required — the server
129
- * generates the object key from this route's policy.
130
- */
89
+ /** Options for `useUpload`. */
90
+ export type UseUploadOptions = {
91
+ /** Optional when an `<S3Provider>` is in the tree. */
92
+ api?: S3Api;
93
+ /** Named server route. The server builds the object key from its policy. */
131
94
  route: S3RouteName;
132
95
  /**
133
- * Attempt multipart when the file is at least 50 MB. The server must
134
- * enable `multipart` on the route or init returns `FEATURE_DISABLED`.
135
- * The threshold is not configurable.
96
+ * HTML `accept` tokens: MIME types (`image/*`) and extensions (`.pdf`).
97
+ * Narrows the route's `fileTypes`; the server still enforces the route.
136
98
  */
99
+ accept?: readonly string[];
100
+ /** Max file size in bytes. The smaller of this and the route's wins. */
101
+ maxFileSize?: number;
102
+ /** Max files per selection. @default 1 */
103
+ maxFiles?: number;
104
+ /** `false` disables multipart even when the route allows it. */
137
105
  multipart?: boolean;
106
+ /** Files uploaded at once. @default 2 */
107
+ concurrentFiles?: number;
108
+ /** Multipart parts uploaded at once per file. @default 4 */
109
+ concurrentParts?: number;
110
+ retry?: RetryConfig;
111
+ /** Persists multipart uploads so they can resume after a reload. */
112
+ uploadStore?: UploadStore;
113
+ /** Request options for every file. A call's `uploadOptions` merge over them. */
114
+ uploadOptions?: UploadRequestInput;
138
115
  /**
139
- * HTML `accept` tokens: MIME types (`image/*`, `application/pdf`) and/or
140
- * extensions (`.pdf`). Client-side UX only — the server enforces
141
- * route `fileTypes`. Omitted values are filled from `api.catalog()`.
116
+ * `true` appends new files to the queue instead of replacing it. Without it,
117
+ * a new call cancels the calls still preparing, and replaces the queue once
118
+ * its files start uploading. A call that is blocked, rejected or fails
119
+ * before uploading leaves the queue alone.
120
+ * @default false
142
121
  */
143
- accept?: string[];
122
+ queue?: boolean;
144
123
  /**
145
- * Max file size in bytes. Client-side UX only — the server enforces
146
- * route `maxFileSize`. Omitted values are filled from `api.catalog()`.
124
+ * Disables every intake interaction: the root, drop targets and paste, and
125
+ * `open()` does nothing. `handleFiles` still uploads what it is given.
147
126
  */
148
- maxFileSize?: number;
127
+ disabled?: boolean;
128
+ /** Disables drag and drop on the root. */
129
+ noDrag?: boolean;
130
+ /** Disables click-to-open on the root. */
131
+ noClick?: boolean;
132
+ /** Disables keyboard activation on the root. */
133
+ noKeyboard?: boolean;
134
+ /** Runs once per call. Return `false` to block it. */
135
+ beforeUpload?: (files: readonly File[]) => boolean | Promise<boolean>;
136
+ /** Runs once per call, after `beforeUpload` allows it. */
137
+ onUploadStart?: (files: readonly File[]) => void;
138
+ /** Byte progress of one file. */
139
+ onProgress?: (progress: TransferProgress, file: File) => void;
140
+ /** Runs after each multipart part is uploaded. */
141
+ onPartUpload?: (part: {
142
+ partNumber: number;
143
+ totalParts: number;
144
+ }, file: File) => void;
145
+ /** Runs once a multipart upload has started or resumed. */
146
+ onMultipartInit?: (session: {
147
+ uploadId: string;
148
+ key: string;
149
+ }, file: File) => void;
149
150
  /**
150
- * Max number of files per selection. @default 1
151
+ * Runs once per uploaded file, after every file of the call has ended and
152
+ * every `onError` of the call has run.
151
153
  */
152
- maxFiles?: number;
154
+ onSuccess?: (result: UploadResult, file: File) => void | Promise<void>;
155
+ /** Runs once per failed file, after every file of the call has ended. */
156
+ onError?: (error: APIError, file: File) => void;
157
+ /**
158
+ * Runs once per call, after every other callback, including a call with
159
+ * no valid file.
160
+ */
161
+ onSettled?: (result: UploadBatchResult) => void | Promise<void>;
162
+ /** Runs with the files rejected before upload. */
163
+ onFileReject?: (rejections: readonly FileRejection[]) => void;
164
+ };
165
+ /**
166
+ * Replaces the PUT or POST to `presign.url` for single-shot uploads, such as
167
+ * for an in-memory backend. It must send `presign.fields` or
168
+ * `presign.headers` exactly, and reject with an `APIError` so the engine can
169
+ * retry: `UPLOAD_FAILED` with S3's status, `CHECKSUM_MISMATCH` when S3
170
+ * rejects the bytes' checksum (never retried), or `NETWORK_ERROR`.
171
+ */
172
+ export type UploadTransport = (file: File, presign: UploadPresignResponse, options: {
173
+ onProgress?: (progress: TransferProgress) => void;
174
+ signal?: AbortSignal;
175
+ }) => Promise<void>;
176
+ /** An `S3Api` may set this to replace the default byte transfer. */
177
+ export type S3ApiUploadTransport = {
178
+ uploadTransport?: UploadTransport;
179
+ };
180
+ /** Options for `uploadFile`. */
181
+ export type UploadFileOptions = {
182
+ route: S3RouteName;
153
183
  /**
154
- * Compute and send a SHA-256 checksum on presign. Filled from
155
- * `api.catalog()` when the route sets `upload.checksum`.
184
+ * What the route allows. Multipart is used for files of at least
185
+ * `DEFAULT_MULTIPART_THRESHOLD` bytes when `multipart` is true. A single-shot
186
+ * upload sends a SHA-256 checksum when `checksum` is true; multipart
187
+ * follows the init response instead.
156
188
  */
157
- checksum?: boolean;
158
- /** Number of parts uploaded concurrently (multipart). */
189
+ policy: {
190
+ multipart: boolean;
191
+ checksum: boolean;
192
+ };
193
+ /** Parts uploaded at once. @default 4 */
159
194
  concurrentParts?: number;
160
- /** Number of files uploaded concurrently when `maxFiles` is greater than 1. */
161
- concurrentFiles?: number;
162
- /** Retry configuration for failed network requests. */
163
195
  retry?: RetryConfig;
196
+ /** Persists multipart uploads so they can resume. */
197
+ uploadStore?: UploadStore;
198
+ request?: UploadRequestOptions;
164
199
  /**
165
- * Store for resumable multipart uploads.
166
- *
167
- * - Omit / `undefined` — abort immediately on cancel or error.
168
- * - `false` — same as omitting.
169
- * - Custom `UploadStore` — persist `uploadId` across sessions.
200
+ * Aborts the upload. Abort with `uploadAbortReason("detach")` to keep a
201
+ * stored multipart upload for resuming; any other reason cancels it.
170
202
  */
171
- uploadStore?: UploadStore | false;
203
+ signal?: AbortSignal;
204
+ onProgress?: (progress: TransferProgress) => void;
205
+ onPhaseChange?: (phase: UploadEnginePhase) => void;
206
+ onPartUpload?: (part: {
207
+ partNumber: number;
208
+ totalParts: number;
209
+ }) => void;
210
+ onMultipartInit?: (session: {
211
+ uploadId: string;
212
+ key: string;
213
+ }) => void;
172
214
  };
215
+ /**
216
+ * Why an upload was aborted. `cancel` aborts the multipart upload and deletes
217
+ * its stored record. `detach` keeps both so the upload can resume.
218
+ */
219
+ export type UploadAbortKind = "cancel" | "detach";
173
220
  //# sourceMappingURL=upload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/types/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,WAAW,EACX,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,iDAAiD;AAC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WAAW,CAAC;IACnB;;;;;OAKG;IACH,MAAM,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IAClD,yCAAyC;IACzC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,qDAAqD;IACrD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAClD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACnD,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC1E,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACxE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { UploadAbortKind } from "../types/upload.js";
2
+ /**
3
+ * The abort reason for an upload: an `AbortError` `DOMException` whose
4
+ * message is `kind`. Abort an upload's signal with it to pick what happens
5
+ * to a stored multipart upload.
6
+ */
7
+ export declare function uploadAbortReason(kind: UploadAbortKind): DOMException;
8
+ /** The kind of an abort reason made by {@link uploadAbortReason}, else `null`. */
9
+ export declare function getUploadAbortKind(reason: unknown): UploadAbortKind | null;
10
+ //# sourceMappingURL=abort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abort.d.ts","sourceRoot":"","sources":["../../src/upload/abort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,YAAY,CAErE;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAM1E"}
@@ -1,9 +1,14 @@
1
+ /** Files at least this large use multipart when the route allows it. */
1
2
  export declare const DEFAULT_MULTIPART_THRESHOLD: number;
2
- export declare const DEFAULT_PART_SIZE: number;
3
3
  export declare const MAX_RETRIES = 3;
4
4
  export declare const RETRY_BASE_DELAY = 1000;
5
- export declare const DEFAULT_CONCURRENT_PARTS = 2;
5
+ export declare const DEFAULT_CONCURRENT_PARTS = 4;
6
6
  export declare const DEFAULT_CONCURRENT_FILES = 2;
7
- /** Default max files per selection — one file. */
7
+ /** Default max files per selection: one file. */
8
8
  export declare const DEFAULT_MAX_FILES = 1;
9
+ /**
10
+ * A presigned URL counts as expired this long before its `expiresIn` ends,
11
+ * to allow for clock skew between the app server and S3.
12
+ */
13
+ export declare const URL_EXPIRY_MARGIN_MS = 30000;
9
14
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/upload/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,QAAmB,CAAC;AAC5D,eAAO,MAAM,iBAAiB,QAAkB,CAAC;AACjD,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,gBAAgB,OAAQ,CAAC;AACtC,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,kDAAkD;AAClD,eAAO,MAAM,iBAAiB,IAAI,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/upload/constants.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,eAAO,MAAM,2BAA2B,QAAmB,CAAC;AAC5D,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,gBAAgB,OAAQ,CAAC;AACtC,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,iDAAiD;AACjD,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,QAAS,CAAC"}
@@ -1,5 +1,6 @@
1
- export { uploadFile, type UploadEngineCallbacks } from "./upload-file";
2
- export { uploadFiles, type FileItem, type FileItemStatus, type MultiUploadCallbacks, } from "./upload-files";
1
+ export { uploadFile } from "./upload-file";
2
+ export { getUploadAbortKind, uploadAbortReason } from "./abort";
3
3
  export { multipartResumeKey } from "./resume-key";
4
+ export { mergeUploadRequest } from "./request";
4
5
  export { DEFAULT_MULTIPART_THRESHOLD } from "./constants";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upload/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EACL,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upload/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC"}
@@ -1,5 +1,15 @@
1
- import type { UploadProgress, UploadRequestOptions, RetryConfig, UploadResult } from "../types/index.js";
2
- import { type S3Api } from "@dimah-s3/core";
3
- import type { UploadStore } from "../types/upload-store.js";
4
- export declare function uploadMultipart(api: S3Api, file: File, route: string, partSize: number, concurrentParts: number, onProgress?: (progress: UploadProgress) => void, signal?: AbortSignal, requestOptions?: UploadRequestOptions, retryConfig?: RetryConfig, uploadStore?: UploadStore | false, onPartUpload?: (partNumber: number, totalParts: number) => void, onMultipartInit?: (uploadId: string, key: string) => void): Promise<UploadResult>;
1
+ import { type MultipartInitPayload, type S3Api } from "@dimah-s3/core";
2
+ import type { UploadEnginePhase, UploadFileOptions, UploadResult } from "../types/upload.js";
3
+ /**
4
+ * Uploads `file` as a multipart upload in the layout the server picks at
5
+ * init, resuming a stored upload when `options.uploadStore` has one.
6
+ *
7
+ * With a store, a request error that may pass later (see
8
+ * {@link isRetryableError}) or an abort with `uploadAbortReason("detach")`
9
+ * keeps the server upload and its record for resuming. A cancel, any other
10
+ * abort, a failure that retrying cannot fix, or any failure without a store
11
+ * aborts the server upload and deletes the record. While one upload of a resume key runs, another upload of the
12
+ * same key runs without the store, so the two never share a session.
13
+ */
14
+ export declare function uploadMultipart(api: S3Api, file: File, payload: MultipartInitPayload, options: UploadFileOptions, setPhase: (phase: UploadEnginePhase) => void): Promise<UploadResult>;
5
15
  //# sourceMappingURL=multipart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/upload/multipart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAiB,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAiBxD,wBAAsB,eAAe,CACnC,GAAG,EAAE,KAAK,EACV,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,EACvB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,EAC/C,MAAM,CAAC,EAAE,WAAW,EACpB,cAAc,CAAC,EAAE,oBAAoB,EACrC,WAAW,CAAC,EAAE,WAAW,EACzB,WAAW,CAAC,EAAE,WAAW,GAAG,KAAK,EACjC,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,EAC/D,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,GACxD,OAAO,CAAC,YAAY,CAAC,CAmLvB"}
1
+ {"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/upload/multipart.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EAEzB,KAAK,KAAK,EACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACb,MAAM,gBAAgB,CAAC;AAoBxB;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,KAAK,EACV,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GAC3C,OAAO,CAAC,YAAY,CAAC,CAcvB"}
@@ -0,0 +1,16 @@
1
+ import { type S3Api } from "@dimah-s3/core";
2
+ import type { UploadFileOptions } from "../types/upload.js";
3
+ import type { StoredUpload } from "../types/upload-store.js";
4
+ /** The server's part layout for one multipart upload. */
5
+ export type PartLayout = Pick<StoredUpload, "fileSize" | "partSize" | "partCount">;
6
+ /** Byte size of part `partNumber`. Only the last part may be smaller. */
7
+ export declare function layoutPartSize(layout: PartLayout, partNumber: number): number;
8
+ /**
9
+ * Uploads every part of `upload` that is not in `done` through a pool of
10
+ * `concurrentParts` workers, following the server's layout. Each worker
11
+ * hashes its part as a stream when the upload requires checksums, signs it,
12
+ * and sends it with retries. The first failure aborts the parts still
13
+ * running and rejects with that failure.
14
+ */
15
+ export declare function uploadParts(api: S3Api, file: File, upload: StoredUpload, done: ReadonlySet<number>, options: UploadFileOptions): Promise<void>;
16
+ //# sourceMappingURL=part-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"part-pool.d.ts","sourceRoot":"","sources":["../../src/upload/part-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAMzD,yDAAyD;AACzD,MAAM,MAAM,UAAU,GAAG,IAAI,CAC3B,YAAY,EACZ,UAAU,GAAG,UAAU,GAAG,WAAW,CACtC,CAAC;AAEF,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAK7E;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,KAAK,EACV,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EACzB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAqEf"}
@@ -1,17 +1,8 @@
1
- import type { UploadProgress } from "../types/index.js";
1
+ import type { UploadTransport } from "../types/upload.js";
2
2
  /**
3
- * Uploads a file directly to S3 using a presigned POST form.
4
- *
5
- * All policy fields (acl, Content-Type, content-length-range, signature, etc.)
6
- * are embedded in `fields` and must be appended to the FormData **before** the
7
- * file — this is an S3 requirement.
3
+ * The default {@link UploadTransport}. Sends `file` to the presigned URL with
4
+ * exactly the presign's PUT `headers`, or as a form with its POST `fields`
5
+ * first (S3 requires the fields before the file).
8
6
  */
9
- export declare function uploadSimple(file: File, url: string, fields: Record<string, string>, onProgress?: (progress: UploadProgress) => void, signal?: AbortSignal): Promise<void>;
10
- /**
11
- * Uploads a file directly to S3 using a presigned PUT URL.
12
- *
13
- * Use this when the server is configured with `method: "PUT"` — for
14
- * example with Cloudflare R2 which does not support presigned POST.
15
- */
16
- export declare function uploadPut(file: File, url: string, headers: Record<string, string>, onProgress?: (progress: UploadProgress) => void, signal?: AbortSignal): Promise<void>;
7
+ export declare const sendPresignedUpload: UploadTransport;
17
8
  //# sourceMappingURL=presigned-http.d.ts.map