tiny-oss 0.5.0 → 1.0.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.
package/UPGRADING.md ADDED
@@ -0,0 +1,151 @@
1
+ # Upgrading to 1.0
2
+
3
+ This guide walks through migrating a tiny-oss 0.x application (latest release: 0.5.1) to 1.0.0.
4
+
5
+ tiny-oss 1.0 replaces the class-based API with a functional API. The `TinyOSS` class, the `new TinyOSS(...)` constructor and the `TinyOSS.*` namespace types are gone: every operation is a standalone function that takes the client options as its first argument, and all public types are top-level named exports. The SDK also grows from browser-only Aliyun OSS to multi-provider, multi-environment support — Tencent Cloud COS, Huawei Cloud OBS, AWS S3, Azure Blob Storage, plus Node.js, Service Workers and WeChat mini programs.
6
+
7
+ ## Quick migration
8
+
9
+ Before (0.x):
10
+
11
+ ```js
12
+ import TinyOSS from 'tiny-oss';
13
+
14
+ const oss = new TinyOSS({
15
+ accessKeyId: 'your accessKeyId',
16
+ accessKeySecret: 'your accessKeySecret',
17
+ stsToken: 'security token',
18
+ region: 'oss-cn-beijing',
19
+ bucket: 'your bucket',
20
+ });
21
+
22
+ await oss.put('hello-world', blob);
23
+ ```
24
+
25
+ After (1.0):
26
+
27
+ ```js
28
+ import { put } from 'tiny-oss';
29
+
30
+ const options = {
31
+ accessKeyId: 'your accessKeyId',
32
+ accessKeySecret: 'your accessKeySecret',
33
+ stsToken: 'security token',
34
+ region: 'oss-cn-beijing',
35
+ bucket: 'your bucket',
36
+ };
37
+
38
+ await put(options, 'hello-world', blob);
39
+ ```
40
+
41
+ If you call operations from many places, `bindOptions` keeps the credentials in one place:
42
+
43
+ ```js
44
+ import { put, bindOptions } from 'tiny-oss';
45
+
46
+ const upload = bindOptions(put, {
47
+ accessKeyId: 'your accessKeyId',
48
+ accessKeySecret: 'your accessKeySecret',
49
+ region: 'oss-cn-beijing',
50
+ bucket: 'your bucket',
51
+ });
52
+
53
+ await upload('hello-world', blob);
54
+ ```
55
+
56
+ ## Breaking changes
57
+
58
+ ### 1. The `TinyOSS` class is removed
59
+
60
+ | 0.x | 1.0 |
61
+ | --- | --- |
62
+ | `oss.put(name, blob)` | `put(options, name, blob)` |
63
+ | `oss.putSymlink(name, target)` | `putSymlink(options, name, target)` |
64
+ | `oss.signatureUrl(name, opts)` | `signatureUrl(options, name, opts)` |
65
+
66
+ The options object is now required on every call, unless you bind it once with `bindOptions`. Other operations that were never on the 0.x class — the multipart and listing functions — use the same `options`-first convention.
67
+
68
+ ### 2. Types are top-level named exports
69
+
70
+ Before:
71
+
72
+ ```ts
73
+ import TinyOSS from 'tiny-oss';
74
+
75
+ const options: TinyOSS.TinyOSSOptions = { /* ... */ };
76
+ ```
77
+
78
+ After:
79
+
80
+ ```ts
81
+ import { put, type Options, type PutOptions, type Progress, type SignatureUrlOptions } from 'tiny-oss';
82
+ ```
83
+
84
+ `TinyOSSOptions` is renamed to `Options`. The `Progress` type is new.
85
+
86
+ ### 3. Progress callback shape changed
87
+
88
+ 0.x passed the native `ProgressEvent`; 1.0 passes a plain object:
89
+
90
+ ```ts
91
+ interface Progress {
92
+ loaded: number;
93
+ total: number;
94
+ lengthComputable: boolean;
95
+ }
96
+ ```
97
+
98
+ `lengthComputable` can be `false` for transports without native progress reporting (fetch, wx.request); those adapters fire a 0% event before sending and a 100% event after.
99
+
100
+ ### 4. Input data widened
101
+
102
+ 0.x accepted `Blob` only; 1.0 accepts `Blob | ArrayBuffer | Uint8Array | string`. WeChat mini programs pass `ArrayBuffer`.
103
+
104
+ ### 5. Node.js and WeChat users must pick a transport
105
+
106
+ The default transport is `XMLHttpRequest` (browsers). In Node.js / Service Workers:
107
+
108
+ ```js
109
+ import { put, setTransport, fetchTransport } from 'tiny-oss';
110
+
111
+ setTransport(fetchTransport);
112
+ ```
113
+
114
+ In WeChat mini programs:
115
+
116
+ ```js
117
+ import { put, setTransport, wxRequestTransport } from 'tiny-oss';
118
+
119
+ setTransport(wxRequestTransport);
120
+ ```
121
+
122
+ ### 6. Provider entry points
123
+
124
+ 0.x was Aliyun OSS only, imported from the package root. 1.0 keeps OSS at the root and adds per-provider entries:
125
+
126
+ - `tiny-oss` — Aliyun OSS
127
+ - `tiny-oss/cos` — Tencent Cloud COS
128
+ - `tiny-oss/obs` — Huawei Cloud OBS
129
+ - `tiny-oss/aws` — AWS S3 and S3-compatible stores (MinIO, Cloudflare R2, Google Cloud Storage)
130
+ - `tiny-oss/azure` — Azure Blob Storage
131
+ - `tiny-oss/protocol` — the protocol layer for building custom providers
132
+
133
+ Each entry exports its own `setTransport`, `getTransport`, `bindOptions` and its operation types by name.
134
+
135
+ ### 7. `Options` gained a field
136
+
137
+ `pathStyle?: boolean` — S3-style path addressing (bucket in the URL path), required for S3-compatible endpoints such as MinIO and Cloudflare R2. Ignored by OSS.
138
+
139
+ ## New capabilities (no migration needed)
140
+
141
+ 1.0 adds operations 0.x never had:
142
+
143
+ - `multipartUpload`, `initMultipartUpload`, `uploadPart`, `completeMultipartUpload`, `abortMultipartUpload`
144
+ - `listParts`, `listUploads`, `uploadPartCopy`
145
+
146
+ and two helpers: `bindOptions` (bind credentials to an operation once) and `setTransport`/`getTransport` (swap the network layer).
147
+
148
+ ## Notes
149
+
150
+ - `put` still resolves to the parsed response body.
151
+ - All 0.x option fields (`accessKeyId`, `accessKeySecret`, `stsToken`, `bucket`, `endpoint`, `region`, `internal`, `secure`, `timeout`, `cname`) are unchanged and keep their meaning.
package/dist/aws.d.ts ADDED
@@ -0,0 +1,208 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export declare const abortMultipartUpload: (options: Options, objectName: string, uploadId: string, multipartOptions?: MultipartOptions) => Promise<void>;
4
+ export declare const completeMultipartUpload: (options: Options, objectName: string, uploadId: string, parts: PartInfo[], multipartOptions?: MultipartOptions) => Promise<CompleteMultipartUploadResult>;
5
+ export declare const initMultipartUpload: (options: Options, objectName: string, multipartOptions?: MultipartOptions) => Promise<InitMultipartUploadResult>;
6
+ export declare const listParts: (options: Options, objectName: string, uploadId: string, query?: ListQuery, multipartOptions?: MultipartOptions) => Promise<ListPartsResult>;
7
+ export declare const listUploads: (options: Options, query?: ListUploadsQuery, multipartOptions?: MultipartOptions) => Promise<ListUploadsResult>;
8
+ export declare const multipartUpload: (options: Options, objectName: string, file: BlobLike | string, multipartOptions?: MultipartUploadOptions) => Promise<CompleteMultipartUploadResult>;
9
+ export declare const put: (options: Options, objectName: string, data: BlobLike | string, putOptions?: PutOptions) => Promise<any>;
10
+ export declare const signatureUrl: (options: Options, objectName: string, urlOptions?: SignatureUrlOptions) => string;
11
+ export declare const uploadPart: (options: Options, objectName: string, uploadId: string, partNo: number, data: BlobLike | string, start: number, end: number, multipartOptions?: MultipartOptions) => Promise<UploadPartResult>;
12
+ export declare const uploadPartCopy: (options: Options, objectName: string, uploadId: string, partNo: number, range: string, sourceData: SourceData, copyOptions?: UploadPartCopyOptions) => Promise<UploadPartCopyResult>;
13
+ /**
14
+ * Bind client options to an operation function, so callers don't have to
15
+ * repeat the credentials on every call. The returned function keeps the
16
+ * operation's original signature minus the leading options argument.
17
+ *
18
+ * Unlike a client object factory, this never references operations it
19
+ * isn't given, so tree shaking keeps working: importing `put` plus
20
+ * `bindOptions` still excludes the multipart code from the bundle.
21
+ *
22
+ * @example
23
+ * import { put, bindOptions } from 'tiny-oss';
24
+ * const upload = bindOptions(put, { accessKeyId, accessKeySecret, region, bucket });
25
+ * upload('hello.txt', blob);
26
+ */
27
+ export declare function bindOptions<O, A extends unknown[], R>(operation: (options: O, ...args: A) => R, options: O): (...args: A) => R;
28
+ /**
29
+ * fetch-based transport for Service Workers and Node.js, where
30
+ * XMLHttpRequest is unavailable. fetch cannot report intermediate
31
+ * upload progress, so a synthetic 0% event fires before sending and a
32
+ * 100% event after, with lengthComputable false.
33
+ */
34
+ export declare function fetchTransport(url: string, options: TransportOptions): Promise<TransportResponse>;
35
+ export declare function getTransport(): Transport;
36
+ /**
37
+ * Replace the network layer. Defaults to XMLHttpRequest; pass a
38
+ * fetch-based adapter in Service Workers or a wx.request-based adapter
39
+ * in WeChat mini programs.
40
+ */
41
+ export declare function setTransport(transport: Transport): void;
42
+ /**
43
+ * wx.request-based transport for WeChat mini programs. Mini programs
44
+ * have no XMLHttpRequest and no Blob, so uploads must pass ArrayBuffer
45
+ * (see README). wx.request cannot report intermediate upload progress,
46
+ * so a synthetic 0% event fires before sending and a 100% event after,
47
+ * with lengthComputable false.
48
+ */
49
+ export declare function wxRequestTransport(url: string, options: TransportOptions): Promise<TransportResponse>;
50
+ export interface Checkpoint {
51
+ file: BlobLike | string;
52
+ name: string;
53
+ uploadId: string;
54
+ partSize: number;
55
+ parts: PartInfo[];
56
+ doneParts: PartInfo[];
57
+ }
58
+ export interface CompleteMultipartUploadResult {
59
+ name: string;
60
+ etag: string;
61
+ bucket?: string;
62
+ res?: any;
63
+ }
64
+ export interface InitMultipartUploadResult {
65
+ name: string;
66
+ uploadId: string;
67
+ res?: any;
68
+ }
69
+ export interface ListPartsResult {
70
+ isTruncated: boolean;
71
+ nextPartNumberMarker: number;
72
+ parts: Part[];
73
+ res?: any;
74
+ }
75
+ export interface ListQuery {
76
+ "max-parts"?: number;
77
+ "part-number-marker"?: number;
78
+ }
79
+ export interface ListUploadsQuery {
80
+ prefix?: string;
81
+ marker?: string;
82
+ "max-uploads"?: number;
83
+ "upload-id-marker"?: string;
84
+ }
85
+ export interface ListUploadsResult {
86
+ uploads: UploadInfo[];
87
+ isTruncated: boolean;
88
+ nextKeyMarker?: string;
89
+ nextUploadIdMarker?: string;
90
+ res?: any;
91
+ }
92
+ export interface MultipartOptions {
93
+ timeout?: number;
94
+ headers?: Record<string, any>;
95
+ }
96
+ export interface MultipartUploadOptions extends MultipartOptions {
97
+ parallel?: number;
98
+ partSize?: number;
99
+ checkpoint?: Checkpoint;
100
+ progress?: (percentage: number, checkpoint: Checkpoint, res?: any) => void;
101
+ meta?: Record<string, any>;
102
+ mime?: string;
103
+ }
104
+ export interface ObjectCallback {
105
+ url: string;
106
+ host?: string;
107
+ body: string;
108
+ contentType?: string;
109
+ customValue?: object;
110
+ headers?: object;
111
+ }
112
+ export interface Options {
113
+ accessKeyId: string;
114
+ accessKeySecret: string;
115
+ stsToken?: string;
116
+ bucket?: string;
117
+ endpoint?: string;
118
+ region?: string;
119
+ internal?: boolean;
120
+ secure?: boolean;
121
+ timeout?: string | number;
122
+ cname?: boolean;
123
+ pathStyle?: boolean;
124
+ }
125
+ export interface Part {
126
+ PartNumber: number;
127
+ LastModified: string;
128
+ ETag: string;
129
+ Size: number;
130
+ }
131
+ export interface PartInfo {
132
+ number: number;
133
+ etag: string;
134
+ }
135
+ export interface Progress {
136
+ loaded: number;
137
+ total: number;
138
+ lengthComputable: boolean;
139
+ }
140
+ export interface PutOptions {
141
+ onprogress?: (e: Progress) => any;
142
+ }
143
+ export interface ResponseHeaderType {
144
+ "content-type"?: string;
145
+ "content-disposition"?: string;
146
+ "cache-control"?: string;
147
+ "content-encoding"?: string;
148
+ "content-language"?: string;
149
+ }
150
+ export interface SignatureUrlOptions {
151
+ expires?: number;
152
+ method?: HTTPMethods;
153
+ "Content-Type"?: string;
154
+ process?: string;
155
+ response?: ResponseHeaderType;
156
+ callback?: ObjectCallback;
157
+ [key: string]: any;
158
+ }
159
+ export interface SourceData {
160
+ sourceKey: string;
161
+ sourceBucket?: string;
162
+ }
163
+ export interface TransportOptions {
164
+ method: string;
165
+ headers: Record<string, string>;
166
+ data?: any;
167
+ timeout?: number;
168
+ /**
169
+ * Total payload size in bytes; transports without native progress
170
+ * events use it to fire 0%/100% synthetic events.
171
+ */
172
+ total?: number;
173
+ /**
174
+ * Upload progress. lengthComputable is false when the environment
175
+ * cannot report intermediate progress (fetch, wx.request); such
176
+ * adapters fire a 0% event before sending and a 100% event after.
177
+ */
178
+ onprogress?: (e: Progress) => void;
179
+ }
180
+ export interface TransportResponse {
181
+ data: string;
182
+ headers: Record<string, string>;
183
+ status: number;
184
+ statusText: string;
185
+ }
186
+ export interface UploadInfo {
187
+ uploadId: string;
188
+ name: string;
189
+ initiated: string;
190
+ }
191
+ export interface UploadPartCopyOptions extends MultipartOptions {
192
+ headers?: Record<string, any>;
193
+ }
194
+ export interface UploadPartCopyResult {
195
+ etag: string;
196
+ lastModified: string;
197
+ res?: any;
198
+ }
199
+ export interface UploadPartResult {
200
+ name: string;
201
+ etag: string;
202
+ res?: any;
203
+ }
204
+ export type BlobLike = Blob | ArrayBuffer | Uint8Array;
205
+ export type HTTPMethods = "GET" | "POST" | "DELETE" | "PUT";
206
+ export type Transport = (url: string, options: TransportOptions) => Promise<TransportResponse>;
207
+
208
+ export {};
@@ -0,0 +1,204 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export declare const multipartUpload: (options: Options, objectName: string, file: BlobLike | string, multipartOptions?: MultipartUploadOptions) => Promise<CompleteMultipartUploadResult>;
4
+ export declare const put: (options: Options, objectName: string, data: BlobLike | string, putOptions?: PutOptions) => Promise<any>;
5
+ export declare const signatureUrl: (options: Options, objectName: string, urlOptions?: SignatureUrlOptions) => string;
6
+ /**
7
+ * Bind client options to an operation function, so callers don't have to
8
+ * repeat the credentials on every call. The returned function keeps the
9
+ * operation's original signature minus the leading options argument.
10
+ *
11
+ * Unlike a client object factory, this never references operations it
12
+ * isn't given, so tree shaking keeps working: importing `put` plus
13
+ * `bindOptions` still excludes the multipart code from the bundle.
14
+ *
15
+ * @example
16
+ * import { put, bindOptions } from 'tiny-oss';
17
+ * const upload = bindOptions(put, { accessKeyId, accessKeySecret, region, bucket });
18
+ * upload('hello.txt', blob);
19
+ */
20
+ export declare function bindOptions<O, A extends unknown[], R>(operation: (options: O, ...args: A) => R, options: O): (...args: A) => R;
21
+ export declare function completeMultipartUpload(options: Options, objectName: string, uploadId: string, parts: PartInfo[], multipartOptions?: MultipartOptions): Promise<CompleteMultipartUploadResult>;
22
+ /**
23
+ * fetch-based transport for Service Workers and Node.js, where
24
+ * XMLHttpRequest is unavailable. fetch cannot report intermediate
25
+ * upload progress, so a synthetic 0% event fires before sending and a
26
+ * 100% event after, with lengthComputable false.
27
+ */
28
+ export declare function fetchTransport(url: string, options: TransportOptions): Promise<TransportResponse>;
29
+ export declare function getTransport(): Transport;
30
+ export declare function initMultipartUpload(options: Options, objectName: string, multipartOptions?: MultipartOptions): Promise<InitMultipartUploadResult>;
31
+ /**
32
+ * Replace the network layer. Defaults to XMLHttpRequest; pass a
33
+ * fetch-based adapter in Service Workers or a wx.request-based adapter
34
+ * in WeChat mini programs.
35
+ */
36
+ export declare function setTransport(transport: Transport): void;
37
+ export declare function uploadPart(options: Options, objectName: string, uploadId: string, partNo: number, data: BlobLike | string, start: number, end: number, multipartOptions?: MultipartOptions): Promise<UploadPartResult>;
38
+ /**
39
+ * wx.request-based transport for WeChat mini programs. Mini programs
40
+ * have no XMLHttpRequest and no Blob, so uploads must pass ArrayBuffer
41
+ * (see README). wx.request cannot report intermediate upload progress,
42
+ * so a synthetic 0% event fires before sending and a 100% event after,
43
+ * with lengthComputable false.
44
+ */
45
+ export declare function wxRequestTransport(url: string, options: TransportOptions): Promise<TransportResponse>;
46
+ export interface Checkpoint {
47
+ file: BlobLike | string;
48
+ name: string;
49
+ uploadId: string;
50
+ partSize: number;
51
+ parts: PartInfo[];
52
+ doneParts: PartInfo[];
53
+ }
54
+ export interface CompleteMultipartUploadResult {
55
+ name: string;
56
+ etag: string;
57
+ bucket?: string;
58
+ res?: any;
59
+ }
60
+ export interface InitMultipartUploadResult {
61
+ name: string;
62
+ uploadId: string;
63
+ res?: any;
64
+ }
65
+ export interface ListPartsResult {
66
+ isTruncated: boolean;
67
+ nextPartNumberMarker: number;
68
+ parts: Part[];
69
+ res?: any;
70
+ }
71
+ export interface ListQuery {
72
+ "max-parts"?: number;
73
+ "part-number-marker"?: number;
74
+ }
75
+ export interface ListUploadsQuery {
76
+ prefix?: string;
77
+ marker?: string;
78
+ "max-uploads"?: number;
79
+ "upload-id-marker"?: string;
80
+ }
81
+ export interface ListUploadsResult {
82
+ uploads: UploadInfo[];
83
+ isTruncated: boolean;
84
+ nextKeyMarker?: string;
85
+ nextUploadIdMarker?: string;
86
+ res?: any;
87
+ }
88
+ export interface MultipartOptions {
89
+ timeout?: number;
90
+ headers?: Record<string, any>;
91
+ }
92
+ export interface MultipartUploadOptions extends MultipartOptions {
93
+ parallel?: number;
94
+ partSize?: number;
95
+ checkpoint?: Checkpoint;
96
+ progress?: (percentage: number, checkpoint: Checkpoint, res?: any) => void;
97
+ meta?: Record<string, any>;
98
+ mime?: string;
99
+ }
100
+ export interface ObjectCallback {
101
+ url: string;
102
+ host?: string;
103
+ body: string;
104
+ contentType?: string;
105
+ customValue?: object;
106
+ headers?: object;
107
+ }
108
+ export interface Options {
109
+ accessKeyId: string;
110
+ accessKeySecret: string;
111
+ stsToken?: string;
112
+ bucket?: string;
113
+ endpoint?: string;
114
+ region?: string;
115
+ internal?: boolean;
116
+ secure?: boolean;
117
+ timeout?: string | number;
118
+ cname?: boolean;
119
+ pathStyle?: boolean;
120
+ }
121
+ export interface Part {
122
+ PartNumber: number;
123
+ LastModified: string;
124
+ ETag: string;
125
+ Size: number;
126
+ }
127
+ export interface PartInfo {
128
+ number: number;
129
+ etag: string;
130
+ }
131
+ export interface Progress {
132
+ loaded: number;
133
+ total: number;
134
+ lengthComputable: boolean;
135
+ }
136
+ export interface PutOptions {
137
+ onprogress?: (e: Progress) => any;
138
+ }
139
+ export interface ResponseHeaderType {
140
+ "content-type"?: string;
141
+ "content-disposition"?: string;
142
+ "cache-control"?: string;
143
+ "content-encoding"?: string;
144
+ "content-language"?: string;
145
+ }
146
+ export interface SignatureUrlOptions {
147
+ expires?: number;
148
+ method?: HTTPMethods;
149
+ "Content-Type"?: string;
150
+ process?: string;
151
+ response?: ResponseHeaderType;
152
+ callback?: ObjectCallback;
153
+ [key: string]: any;
154
+ }
155
+ export interface SourceData {
156
+ sourceKey: string;
157
+ sourceBucket?: string;
158
+ }
159
+ export interface TransportOptions {
160
+ method: string;
161
+ headers: Record<string, string>;
162
+ data?: any;
163
+ timeout?: number;
164
+ /**
165
+ * Total payload size in bytes; transports without native progress
166
+ * events use it to fire 0%/100% synthetic events.
167
+ */
168
+ total?: number;
169
+ /**
170
+ * Upload progress. lengthComputable is false when the environment
171
+ * cannot report intermediate progress (fetch, wx.request); such
172
+ * adapters fire a 0% event before sending and a 100% event after.
173
+ */
174
+ onprogress?: (e: Progress) => void;
175
+ }
176
+ export interface TransportResponse {
177
+ data: string;
178
+ headers: Record<string, string>;
179
+ status: number;
180
+ statusText: string;
181
+ }
182
+ export interface UploadInfo {
183
+ uploadId: string;
184
+ name: string;
185
+ initiated: string;
186
+ }
187
+ export interface UploadPartCopyOptions extends MultipartOptions {
188
+ headers?: Record<string, any>;
189
+ }
190
+ export interface UploadPartCopyResult {
191
+ etag: string;
192
+ lastModified: string;
193
+ res?: any;
194
+ }
195
+ export interface UploadPartResult {
196
+ name: string;
197
+ etag: string;
198
+ res?: any;
199
+ }
200
+ export type BlobLike = Blob | ArrayBuffer | Uint8Array;
201
+ export type HTTPMethods = "GET" | "POST" | "DELETE" | "PUT";
202
+ export type Transport = (url: string, options: TransportOptions) => Promise<TransportResponse>;
203
+
204
+ export {};