diskio-api 1.1.0 → 1.2.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/README.md CHANGED
@@ -43,6 +43,37 @@ import { DiskioAPIClient } from 'diskio-api';
43
43
  import { DiskioAPIClient } from 'diskio-api';
44
44
  ```
45
45
 
46
+ ## Instance
47
+ ```js
48
+ const client = new DiskioAPIClient('http://localhost:8080');
49
+ ```
50
+
51
+ ## Health Check
52
+ Get information about the server
53
+ ```js
54
+ const response = await client.healthCheck();
55
+ console.log(response.data.response.diskio.size); // 10737418240
56
+ ```
57
+
58
+ ## Upload
59
+ ```ts
60
+ const file: File = new File(['Hello world!'], 'hello.txt');
61
+ const response = await client.upload([ file ]);
62
+ const path = response.data.response[0];
63
+ ```
64
+
65
+ ## Download
66
+ ```js
67
+ const file = await client.download(path, type: 'arrayBuffer' | 'stream') // default download is 'arrayBuffer'
68
+ // Work with the file
69
+ console.log(typeof file) // 'arraybuffer' | 'stream'
70
+ ```
71
+
72
+ ## Delete
73
+ ```js
74
+ await client.delete('/path/to/file');
75
+ ```
76
+
46
77
  ## 📝 License
47
78
 
48
79
  This project is licensed under the `GNU AFFERO GENERAL PUBLIC LICENSE` - see the [LICENSE](LICENSE) file for details
package/cjs/index.d.ts CHANGED
@@ -49,130 +49,81 @@ export declare class DiskioAPIClient {
49
49
  };
50
50
  };
51
51
  }> | undefined, `${string}/${string}`>>;
52
- diskio: {
53
- upload: (files: File[]) => Promise<import("openapi-fetch").FetchResponse<{
54
- parameters: {
55
- query?: never;
56
- header?: never;
57
- path?: never;
58
- cookie?: never;
59
- };
60
- requestBody: {
61
- content: {
62
- "multipart/form-data": {
63
- files: string[];
64
- };
52
+ upload(files: File[]): Promise<import("openapi-fetch").FetchResponse<{
53
+ parameters: {
54
+ query?: never;
55
+ header?: never;
56
+ path?: never;
57
+ cookie?: never;
58
+ };
59
+ requestBody: {
60
+ content: {
61
+ "multipart/form-data": {
62
+ files: string[];
65
63
  };
66
64
  };
67
- responses: {
68
- 200: {
69
- headers: {
70
- [name: string]: unknown;
71
- };
72
- content: {
73
- "application/json": components["schemas"]["response.model"] & {
74
- response: string[];
75
- };
65
+ };
66
+ responses: {
67
+ 200: {
68
+ headers: {
69
+ [name: string]: unknown;
70
+ };
71
+ content: {
72
+ "application/json": components["schemas"]["response.model"] & {
73
+ response: string[];
76
74
  };
77
75
  };
78
76
  };
79
- }, {
80
- body: {
81
- files: any;
77
+ };
78
+ }, {
79
+ body: {
80
+ files: any;
81
+ };
82
+ }, `${string}/${string}`>>;
83
+ download(name: string, type?: 'arrayBuffer' | 'stream'): Promise<ArrayBuffer | ReadableStream<Uint8Array> | null | undefined>;
84
+ delete(name: string): Promise<import("openapi-fetch").FetchResponse<{
85
+ parameters: {
86
+ query?: never;
87
+ header?: never;
88
+ path: {
89
+ name: string;
82
90
  };
83
- }, `${string}/${string}`>>;
84
- download: (name: string) => Promise<import("openapi-fetch").FetchResponse<{
85
- parameters: {
86
- query?: never;
87
- header?: never;
88
- path: {
89
- name: string;
91
+ cookie?: never;
92
+ };
93
+ requestBody?: never;
94
+ responses: {
95
+ 200: {
96
+ headers: {
97
+ [name: string]: unknown;
90
98
  };
91
- cookie?: never;
99
+ content?: never;
92
100
  };
93
- requestBody?: never;
94
- responses: {
95
- 200: {
96
- headers: {
97
- [name: string]: unknown;
98
- };
99
- content: {
100
- "application/octet-stream": string;
101
- };
102
- };
103
- 404: {
104
- headers: {
105
- [name: string]: unknown;
106
- };
107
- content: {
108
- "application/json": components["schemas"]["not-found-response.model"] & {
109
- response: string;
110
- };
111
- };
101
+ 404: {
102
+ headers: {
103
+ [name: string]: unknown;
112
104
  };
113
- 500: {
114
- headers: {
115
- [name: string]: unknown;
116
- };
117
- content: {
118
- "application/json": components["schemas"]["internal-server-error-response.model"] & {
119
- response: string;
120
- };
105
+ content: {
106
+ "application/json": components["schemas"]["not-found-response.model"] & {
107
+ response: string;
121
108
  };
122
109
  };
123
110
  };
124
- }, {
125
- params: {
126
- path: {
127
- name: string;
128
- };
129
- };
130
- responseType: string;
131
- }, `${string}/${string}`>>;
132
- delete: (name: string) => Promise<import("openapi-fetch").FetchResponse<{
133
- parameters: {
134
- query?: never;
135
- header?: never;
136
- path: {
137
- name: string;
138
- };
139
- cookie?: never;
140
- };
141
- requestBody?: never;
142
- responses: {
143
- 200: {
144
- headers: {
145
- [name: string]: unknown;
146
- };
147
- content?: never;
148
- };
149
- 404: {
150
- headers: {
151
- [name: string]: unknown;
152
- };
153
- content: {
154
- "application/json": components["schemas"]["not-found-response.model"] & {
155
- response: string;
156
- };
157
- };
111
+ 500: {
112
+ headers: {
113
+ [name: string]: unknown;
158
114
  };
159
- 500: {
160
- headers: {
161
- [name: string]: unknown;
162
- };
163
- content: {
164
- "application/json": components["schemas"]["internal-server-error-response.model"] & {
165
- response: string;
166
- };
115
+ content: {
116
+ "application/json": components["schemas"]["internal-server-error-response.model"] & {
117
+ response: string;
167
118
  };
168
119
  };
169
120
  };
170
- }, {
171
- params: {
172
- path: {
173
- name: string;
174
- };
121
+ };
122
+ }, {
123
+ params: {
124
+ path: {
125
+ name: string;
175
126
  };
176
- }, `${string}/${string}`>>;
177
- };
127
+ };
128
+ }, `${string}/${string}`>>;
178
129
  }
package/cjs/index.js CHANGED
@@ -23,22 +23,21 @@ class DiskioAPIClient {
23
23
  return this.authentication;
24
24
  }
25
25
  };
26
- this.diskio = {
27
- upload: (files) => {
28
- return this.client.POST('/diskio', { body: { files: files } });
29
- },
30
- download: (name) => {
31
- return this.client.GET('/diskio/{name}', { params: { path: { name } }, responseType: 'arraybuffer' });
32
- },
33
- delete: (name) => {
34
- return this.client.DELETE('/diskio/{name}', { params: { path: { name } } });
35
- }
36
- };
37
26
  this.client = (0, openapi_fetch_1.default)({ baseUrl, headers: { Bearer: 'access_token' } });
38
27
  this.client.use(this.authenticate);
39
28
  }
40
29
  healthCheck() {
41
30
  return this.client.GET('/health-check');
42
31
  }
32
+ upload(files) {
33
+ return this.client.POST('/diskio', { body: { files: files } });
34
+ }
35
+ async download(name, type = 'arrayBuffer') {
36
+ const response = this.client.GET('/diskio/{name}', { params: { path: { name } }, parseAs: type });
37
+ return response.data;
38
+ }
39
+ delete(name) {
40
+ return this.client.DELETE('/diskio/{name}', { params: { path: { name } } });
41
+ }
43
42
  }
44
43
  exports.DiskioAPIClient = DiskioAPIClient;
package/mjs/index.d.ts CHANGED
@@ -49,130 +49,81 @@ export declare class DiskioAPIClient {
49
49
  };
50
50
  };
51
51
  }> | undefined, `${string}/${string}`>>;
52
- diskio: {
53
- upload: (files: File[]) => Promise<import("openapi-fetch").FetchResponse<{
54
- parameters: {
55
- query?: never;
56
- header?: never;
57
- path?: never;
58
- cookie?: never;
59
- };
60
- requestBody: {
61
- content: {
62
- "multipart/form-data": {
63
- files: string[];
64
- };
52
+ upload(files: File[]): Promise<import("openapi-fetch").FetchResponse<{
53
+ parameters: {
54
+ query?: never;
55
+ header?: never;
56
+ path?: never;
57
+ cookie?: never;
58
+ };
59
+ requestBody: {
60
+ content: {
61
+ "multipart/form-data": {
62
+ files: string[];
65
63
  };
66
64
  };
67
- responses: {
68
- 200: {
69
- headers: {
70
- [name: string]: unknown;
71
- };
72
- content: {
73
- "application/json": components["schemas"]["response.model"] & {
74
- response: string[];
75
- };
65
+ };
66
+ responses: {
67
+ 200: {
68
+ headers: {
69
+ [name: string]: unknown;
70
+ };
71
+ content: {
72
+ "application/json": components["schemas"]["response.model"] & {
73
+ response: string[];
76
74
  };
77
75
  };
78
76
  };
79
- }, {
80
- body: {
81
- files: any;
77
+ };
78
+ }, {
79
+ body: {
80
+ files: any;
81
+ };
82
+ }, `${string}/${string}`>>;
83
+ download(name: string, type?: 'arrayBuffer' | 'stream'): Promise<ArrayBuffer | ReadableStream<Uint8Array> | null | undefined>;
84
+ delete(name: string): Promise<import("openapi-fetch").FetchResponse<{
85
+ parameters: {
86
+ query?: never;
87
+ header?: never;
88
+ path: {
89
+ name: string;
82
90
  };
83
- }, `${string}/${string}`>>;
84
- download: (name: string) => Promise<import("openapi-fetch").FetchResponse<{
85
- parameters: {
86
- query?: never;
87
- header?: never;
88
- path: {
89
- name: string;
91
+ cookie?: never;
92
+ };
93
+ requestBody?: never;
94
+ responses: {
95
+ 200: {
96
+ headers: {
97
+ [name: string]: unknown;
90
98
  };
91
- cookie?: never;
99
+ content?: never;
92
100
  };
93
- requestBody?: never;
94
- responses: {
95
- 200: {
96
- headers: {
97
- [name: string]: unknown;
98
- };
99
- content: {
100
- "application/octet-stream": string;
101
- };
102
- };
103
- 404: {
104
- headers: {
105
- [name: string]: unknown;
106
- };
107
- content: {
108
- "application/json": components["schemas"]["not-found-response.model"] & {
109
- response: string;
110
- };
111
- };
101
+ 404: {
102
+ headers: {
103
+ [name: string]: unknown;
112
104
  };
113
- 500: {
114
- headers: {
115
- [name: string]: unknown;
116
- };
117
- content: {
118
- "application/json": components["schemas"]["internal-server-error-response.model"] & {
119
- response: string;
120
- };
105
+ content: {
106
+ "application/json": components["schemas"]["not-found-response.model"] & {
107
+ response: string;
121
108
  };
122
109
  };
123
110
  };
124
- }, {
125
- params: {
126
- path: {
127
- name: string;
128
- };
129
- };
130
- responseType: string;
131
- }, `${string}/${string}`>>;
132
- delete: (name: string) => Promise<import("openapi-fetch").FetchResponse<{
133
- parameters: {
134
- query?: never;
135
- header?: never;
136
- path: {
137
- name: string;
138
- };
139
- cookie?: never;
140
- };
141
- requestBody?: never;
142
- responses: {
143
- 200: {
144
- headers: {
145
- [name: string]: unknown;
146
- };
147
- content?: never;
148
- };
149
- 404: {
150
- headers: {
151
- [name: string]: unknown;
152
- };
153
- content: {
154
- "application/json": components["schemas"]["not-found-response.model"] & {
155
- response: string;
156
- };
157
- };
111
+ 500: {
112
+ headers: {
113
+ [name: string]: unknown;
158
114
  };
159
- 500: {
160
- headers: {
161
- [name: string]: unknown;
162
- };
163
- content: {
164
- "application/json": components["schemas"]["internal-server-error-response.model"] & {
165
- response: string;
166
- };
115
+ content: {
116
+ "application/json": components["schemas"]["internal-server-error-response.model"] & {
117
+ response: string;
167
118
  };
168
119
  };
169
120
  };
170
- }, {
171
- params: {
172
- path: {
173
- name: string;
174
- };
121
+ };
122
+ }, {
123
+ params: {
124
+ path: {
125
+ name: string;
175
126
  };
176
- }, `${string}/${string}`>>;
177
- };
127
+ };
128
+ }, `${string}/${string}`>>;
178
129
  }
package/mjs/index.js CHANGED
@@ -17,21 +17,20 @@ export class DiskioAPIClient {
17
17
  return this.authentication;
18
18
  }
19
19
  };
20
- this.diskio = {
21
- upload: (files) => {
22
- return this.client.POST('/diskio', { body: { files: files } });
23
- },
24
- download: (name) => {
25
- return this.client.GET('/diskio/{name}', { params: { path: { name } }, responseType: 'arraybuffer' });
26
- },
27
- delete: (name) => {
28
- return this.client.DELETE('/diskio/{name}', { params: { path: { name } } });
29
- }
30
- };
31
20
  this.client = createClient({ baseUrl, headers: { Bearer: 'access_token' } });
32
21
  this.client.use(this.authenticate);
33
22
  }
34
23
  healthCheck() {
35
24
  return this.client.GET('/health-check');
36
25
  }
26
+ upload(files) {
27
+ return this.client.POST('/diskio', { body: { files: files } });
28
+ }
29
+ async download(name, type = 'arrayBuffer') {
30
+ const response = await this.client.GET('/diskio/{name}', { params: { path: { name } }, parseAs: type });
31
+ return response.data;
32
+ }
33
+ delete(name) {
34
+ return this.client.DELETE('/diskio/{name}', { params: { path: { name } } });
35
+ }
37
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diskio-api",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "An API Client for diskio-server",
5
5
  "type": "module",
6
6
  "main": "cjs/index.js",