@data-loom/storage-js 0.2.1-alpha.1
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/LICENSE +201 -0
- package/README.md +163 -0
- package/dist/main/StorageClient.d.ts +18 -0
- package/dist/main/StorageClient.d.ts.map +1 -0
- package/dist/main/StorageClient.js +23 -0
- package/dist/main/StorageClient.js.map +1 -0
- package/dist/main/index.d.ts +4 -0
- package/dist/main/index.d.ts.map +1 -0
- package/dist/main/index.js +22 -0
- package/dist/main/index.js.map +1 -0
- package/dist/main/lib/constants.d.ts +4 -0
- package/dist/main/lib/constants.d.ts.map +1 -0
- package/dist/main/lib/constants.js +6 -0
- package/dist/main/lib/constants.js.map +1 -0
- package/dist/main/lib/errors.d.ts +22 -0
- package/dist/main/lib/errors.d.ts.map +1 -0
- package/dist/main/lib/errors.js +45 -0
- package/dist/main/lib/errors.js.map +1 -0
- package/dist/main/lib/fetch.d.ts +16 -0
- package/dist/main/lib/fetch.d.ts.map +1 -0
- package/dist/main/lib/fetch.js +78 -0
- package/dist/main/lib/fetch.js.map +1 -0
- package/dist/main/lib/helpers.d.ts +14 -0
- package/dist/main/lib/helpers.d.ts.map +1 -0
- package/dist/main/lib/helpers.js +104 -0
- package/dist/main/lib/helpers.js.map +1 -0
- package/dist/main/lib/index.d.ts +5 -0
- package/dist/main/lib/index.d.ts.map +1 -0
- package/dist/main/lib/index.js +21 -0
- package/dist/main/lib/index.js.map +1 -0
- package/dist/main/lib/types.d.ts +139 -0
- package/dist/main/lib/types.d.ts.map +1 -0
- package/dist/main/lib/types.js +3 -0
- package/dist/main/lib/types.js.map +1 -0
- package/dist/main/lib/version.d.ts +2 -0
- package/dist/main/lib/version.d.ts.map +1 -0
- package/dist/main/lib/version.js +6 -0
- package/dist/main/lib/version.js.map +1 -0
- package/dist/main/packages/StorageBucketApi.d.ts +118 -0
- package/dist/main/packages/StorageBucketApi.d.ts.map +1 -0
- package/dist/main/packages/StorageBucketApi.js +149 -0
- package/dist/main/packages/StorageBucketApi.js.map +1 -0
- package/dist/main/packages/StorageFileApi.d.ts +243 -0
- package/dist/main/packages/StorageFileApi.d.ts.map +1 -0
- package/dist/main/packages/StorageFileApi.js +456 -0
- package/dist/main/packages/StorageFileApi.js.map +1 -0
- package/dist/module/StorageClient.d.ts +18 -0
- package/dist/module/StorageClient.d.ts.map +1 -0
- package/dist/module/StorageClient.js +16 -0
- package/dist/module/StorageClient.js.map +1 -0
- package/dist/module/index.d.ts +4 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +4 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/lib/constants.d.ts +4 -0
- package/dist/module/lib/constants.d.ts.map +1 -0
- package/dist/module/lib/constants.js +3 -0
- package/dist/module/lib/constants.js.map +1 -0
- package/dist/module/lib/errors.d.ts +22 -0
- package/dist/module/lib/errors.d.ts.map +1 -0
- package/dist/module/lib/errors.js +37 -0
- package/dist/module/lib/errors.js.map +1 -0
- package/dist/module/lib/fetch.d.ts +16 -0
- package/dist/module/lib/fetch.d.ts.map +1 -0
- package/dist/module/lib/fetch.js +70 -0
- package/dist/module/lib/fetch.js.map +1 -0
- package/dist/module/lib/helpers.d.ts +14 -0
- package/dist/module/lib/helpers.d.ts.map +1 -0
- package/dist/module/lib/helpers.js +72 -0
- package/dist/module/lib/helpers.js.map +1 -0
- package/dist/module/lib/index.d.ts +5 -0
- package/dist/module/lib/index.d.ts.map +1 -0
- package/dist/module/lib/index.js +5 -0
- package/dist/module/lib/index.js.map +1 -0
- package/dist/module/lib/types.d.ts +139 -0
- package/dist/module/lib/types.d.ts.map +1 -0
- package/dist/module/lib/types.js +2 -0
- package/dist/module/lib/types.js.map +1 -0
- package/dist/module/lib/version.d.ts +2 -0
- package/dist/module/lib/version.d.ts.map +1 -0
- package/dist/module/lib/version.js +3 -0
- package/dist/module/lib/version.js.map +1 -0
- package/dist/module/packages/StorageBucketApi.d.ts +118 -0
- package/dist/module/packages/StorageBucketApi.d.ts.map +1 -0
- package/dist/module/packages/StorageBucketApi.js +146 -0
- package/dist/module/packages/StorageBucketApi.js.map +1 -0
- package/dist/module/packages/StorageFileApi.d.ts +243 -0
- package/dist/module/packages/StorageFileApi.d.ts.map +1 -0
- package/dist/module/packages/StorageFileApi.js +453 -0
- package/dist/module/packages/StorageFileApi.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FileBody } from './types';
|
|
2
|
+
type Fetch = typeof fetch;
|
|
3
|
+
export declare const resolveFetch: (customFetch?: Fetch) => Fetch;
|
|
4
|
+
export declare const resolveResponse: () => Promise<typeof Response>;
|
|
5
|
+
export declare const recursiveToCamel: (item: Record<string, any>) => unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Determine if input is a plain object
|
|
8
|
+
* An object is plain if it's created by either {}, new Object(), or Object.create(null)
|
|
9
|
+
* source: https://github.com/sindresorhus/is-plain-obj
|
|
10
|
+
*/
|
|
11
|
+
export declare const isPlainObject: (value: object) => boolean;
|
|
12
|
+
export declare const getUpdateFileSize: (file: FileBody) => string;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,KAAK,KAAK,GAAG,OAAO,KAAK,CAAC;AAE1B,eAAO,MAAM,YAAY,iBAAkB,KAAK,KAAG,KAWlD,CAAC;AAEF,eAAO,MAAM,eAAe,QAAa,QAAQ,eAAe,CAO/D,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAU,OAAO,MAAM,EAAE,GAAG,CAAC,KAAG,OAc5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,OAa7C,CAAC;AAEF,eAAO,MAAM,iBAAiB,SAAU,QAAQ,KAAG,MAqBlD,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getUpdateFileSize = exports.isPlainObject = exports.recursiveToCamel = exports.resolveResponse = exports.resolveFetch = void 0;
|
|
27
|
+
const resolveFetch = (customFetch) => {
|
|
28
|
+
let _fetch;
|
|
29
|
+
if (customFetch) {
|
|
30
|
+
_fetch = customFetch;
|
|
31
|
+
}
|
|
32
|
+
else if (typeof fetch === 'undefined') {
|
|
33
|
+
_fetch = (...args) => { var _a; return (_a = '@data-loom/node-fetch', Promise.resolve().then(() => __importStar(require(_a)))).then(({ default: fetch }) => fetch(...args)); };
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
_fetch = fetch;
|
|
37
|
+
}
|
|
38
|
+
return (...args) => _fetch(...args);
|
|
39
|
+
};
|
|
40
|
+
exports.resolveFetch = resolveFetch;
|
|
41
|
+
const resolveResponse = async () => {
|
|
42
|
+
var _a;
|
|
43
|
+
if (typeof Response === 'undefined') {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
return (await (_a = '@data-loom/node-fetch', Promise.resolve().then(() => __importStar(require(_a))))).Response;
|
|
46
|
+
}
|
|
47
|
+
return Response;
|
|
48
|
+
};
|
|
49
|
+
exports.resolveResponse = resolveResponse;
|
|
50
|
+
const recursiveToCamel = (item) => {
|
|
51
|
+
if (Array.isArray(item)) {
|
|
52
|
+
return item.map((el) => (0, exports.recursiveToCamel)(el));
|
|
53
|
+
}
|
|
54
|
+
else if (typeof item === 'function' || item !== Object(item)) {
|
|
55
|
+
return item;
|
|
56
|
+
}
|
|
57
|
+
const result = {};
|
|
58
|
+
Object.entries(item).forEach(([key, value]) => {
|
|
59
|
+
const newKey = key.replace(/([-_][a-z])/gi, (c) => c.toUpperCase().replace(/[-_]/g, ''));
|
|
60
|
+
result[newKey] = (0, exports.recursiveToCamel)(value);
|
|
61
|
+
});
|
|
62
|
+
return result;
|
|
63
|
+
};
|
|
64
|
+
exports.recursiveToCamel = recursiveToCamel;
|
|
65
|
+
/**
|
|
66
|
+
* Determine if input is a plain object
|
|
67
|
+
* An object is plain if it's created by either {}, new Object(), or Object.create(null)
|
|
68
|
+
* source: https://github.com/sindresorhus/is-plain-obj
|
|
69
|
+
*/
|
|
70
|
+
const isPlainObject = (value) => {
|
|
71
|
+
if (typeof value !== 'object' || value === null) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const prototype = Object.getPrototypeOf(value);
|
|
75
|
+
return ((prototype === null ||
|
|
76
|
+
prototype === Object.prototype ||
|
|
77
|
+
Object.getPrototypeOf(prototype) === null) &&
|
|
78
|
+
!(Symbol.toStringTag in value) &&
|
|
79
|
+
!(Symbol.iterator in value));
|
|
80
|
+
};
|
|
81
|
+
exports.isPlainObject = isPlainObject;
|
|
82
|
+
const getUpdateFileSize = (file) => {
|
|
83
|
+
if (file instanceof File) {
|
|
84
|
+
return file.size.toString();
|
|
85
|
+
}
|
|
86
|
+
if (file instanceof Blob) {
|
|
87
|
+
return file.size.toString();
|
|
88
|
+
}
|
|
89
|
+
if (file instanceof URLSearchParams) {
|
|
90
|
+
return file.size.toString();
|
|
91
|
+
}
|
|
92
|
+
if (typeof file === 'string') {
|
|
93
|
+
return file.length.toString();
|
|
94
|
+
}
|
|
95
|
+
if (ArrayBuffer.isView(file)) {
|
|
96
|
+
return file.byteLength.toString();
|
|
97
|
+
}
|
|
98
|
+
if (file instanceof ArrayBuffer) {
|
|
99
|
+
return file.byteLength.toString();
|
|
100
|
+
}
|
|
101
|
+
return '0';
|
|
102
|
+
};
|
|
103
|
+
exports.getUpdateFileSize = getUpdateFileSize;
|
|
104
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/lib/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAS,EAAE;IACzD,IAAI,MAAa,CAAC;IAClB,IAAI,WAAW,EAAE;QACf,MAAM,GAAG,WAAW,CAAC;KACtB;SAAM,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QACvC,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,WACnB,OAAA,MAAO,uBAA8B,2DAAE,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA,EAAA,CAAC;KACvF;SAAM;QACL,MAAM,GAAG,KAAK,CA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B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("../packages/StorageBucketApi"), exports);
|
|
18
|
+
__exportStar(require("../packages/StorageFileApi"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./constants"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,6DAA2C;AAC3C,0CAAwB;AACxB,8CAA4B"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
export type BucketType = 'STANDARD' | 'ANALYTICS';
|
|
5
|
+
export interface Bucket {
|
|
6
|
+
id: string;
|
|
7
|
+
type?: BucketType;
|
|
8
|
+
name: string;
|
|
9
|
+
owner: string;
|
|
10
|
+
file_size_limit?: number;
|
|
11
|
+
allowed_mime_types?: string[];
|
|
12
|
+
created_at: string;
|
|
13
|
+
updated_at: string;
|
|
14
|
+
public: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface FileObject {
|
|
17
|
+
name: string;
|
|
18
|
+
bucket_id: string;
|
|
19
|
+
id: string;
|
|
20
|
+
updated_at: string;
|
|
21
|
+
created_at: string;
|
|
22
|
+
created_by: string;
|
|
23
|
+
updated_by: string;
|
|
24
|
+
metadata: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
export interface FileObjectV2 {
|
|
27
|
+
id: string;
|
|
28
|
+
version: string;
|
|
29
|
+
name: string;
|
|
30
|
+
bucket_id: string;
|
|
31
|
+
updated_at: string;
|
|
32
|
+
created_at: string;
|
|
33
|
+
last_accessed_at: string;
|
|
34
|
+
size?: number;
|
|
35
|
+
cache_control?: string;
|
|
36
|
+
content_type?: string;
|
|
37
|
+
etag?: string;
|
|
38
|
+
last_modified?: string;
|
|
39
|
+
metadata?: Record<string, any>;
|
|
40
|
+
}
|
|
41
|
+
export interface SortBy {
|
|
42
|
+
column?: string;
|
|
43
|
+
order?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface FileOptions {
|
|
46
|
+
/**
|
|
47
|
+
* The number of seconds the asset is cached in the browser and in the Supabase CDN. This is set in the `Cache-Control: max-age=<seconds>` header. Defaults to 3600 seconds.
|
|
48
|
+
*/
|
|
49
|
+
cacheControl?: string;
|
|
50
|
+
/**
|
|
51
|
+
* the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
|
|
52
|
+
*/
|
|
53
|
+
contentType?: string;
|
|
54
|
+
/**
|
|
55
|
+
* When upsert is set to true, the file is overwritten if it exists. When set to false, an error is thrown if the object already exists. Defaults to false.
|
|
56
|
+
*/
|
|
57
|
+
upsert?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface PreUploadBody {
|
|
60
|
+
file_size: string;
|
|
61
|
+
upsert: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface DestinationOptions {
|
|
64
|
+
destinationBucket?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface SearchOptions {
|
|
67
|
+
/**
|
|
68
|
+
* The number of files you want to be returned.
|
|
69
|
+
* @default 100
|
|
70
|
+
*/
|
|
71
|
+
limit?: number;
|
|
72
|
+
/**
|
|
73
|
+
* The starting position.
|
|
74
|
+
*/
|
|
75
|
+
offset?: number;
|
|
76
|
+
/**
|
|
77
|
+
* The column to sort by. Can be any column inside a FileObject.
|
|
78
|
+
*/
|
|
79
|
+
sortBy?: SortBy;
|
|
80
|
+
}
|
|
81
|
+
export interface SearchV2Options {
|
|
82
|
+
limit?: number;
|
|
83
|
+
prefix?: string;
|
|
84
|
+
cursor?: string;
|
|
85
|
+
with_delimiter?: boolean;
|
|
86
|
+
}
|
|
87
|
+
export interface SearchV2Result {
|
|
88
|
+
hasNext: boolean;
|
|
89
|
+
folders: {
|
|
90
|
+
name: string;
|
|
91
|
+
}[];
|
|
92
|
+
objects: FileObject[];
|
|
93
|
+
}
|
|
94
|
+
export interface FetchParameters {
|
|
95
|
+
/**
|
|
96
|
+
* Pass in an AbortController's signal to cancel the request.
|
|
97
|
+
*/
|
|
98
|
+
signal?: AbortSignal;
|
|
99
|
+
}
|
|
100
|
+
export interface Metadata {
|
|
101
|
+
name: string;
|
|
102
|
+
}
|
|
103
|
+
export interface TransformOptions {
|
|
104
|
+
/**
|
|
105
|
+
* The width of the image in pixels.
|
|
106
|
+
*/
|
|
107
|
+
width?: number;
|
|
108
|
+
/**
|
|
109
|
+
* The height of the image in pixels.
|
|
110
|
+
*/
|
|
111
|
+
height?: number;
|
|
112
|
+
/**
|
|
113
|
+
* The resize mode can be cover, contain or fill. Defaults to cover.
|
|
114
|
+
* Cover resizes the image to maintain it's aspect ratio while filling the entire width and height.
|
|
115
|
+
* Contain resizes the image to maintain it's aspect ratio while fitting the entire image within the width and height.
|
|
116
|
+
* Fill resizes the image to fill the entire width and height. If the object's aspect ratio does not match the width and height, the image will be stretched to fit.
|
|
117
|
+
*/
|
|
118
|
+
resize?: 'cover' | 'contain' | 'fill';
|
|
119
|
+
/**
|
|
120
|
+
* Set the quality of the returned image.
|
|
121
|
+
* A number from 20 to 100, with 100 being the highest quality.
|
|
122
|
+
* Defaults to 80
|
|
123
|
+
*/
|
|
124
|
+
quality?: number;
|
|
125
|
+
/**
|
|
126
|
+
* Specify the format of the image requested.
|
|
127
|
+
*
|
|
128
|
+
* When using 'origin' we force the format to be the same as the original image.
|
|
129
|
+
* When this option is not passed in, images are optimized to modern image formats like Webp.
|
|
130
|
+
*/
|
|
131
|
+
format?: 'origin';
|
|
132
|
+
}
|
|
133
|
+
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : S;
|
|
134
|
+
export type Camelize<T> = {
|
|
135
|
+
[K in keyof T as CamelCase<Extract<K, string>>]: T[K];
|
|
136
|
+
};
|
|
137
|
+
export type FileBody = ArrayBuffer | ArrayBufferView | Blob | Buffer | File | NodeJS.ReadableStream | ReadableStream<Uint8Array> | URLSearchParams | string;
|
|
138
|
+
export {};
|
|
139
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":";;;AAAA,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;AAElD,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;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SAAS,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,EAAE,IAAI,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,GAC7E,GAAG,SAAS,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,EAAE,GAClD,CAAC,CAAC;AAEN,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF,MAAM,MAAM,QAAQ,GAChB,WAAW,GACX,eAAe,GACf,IAAI,GACJ,MAAM,GACN,IAAI,GACJ,MAAM,CAAC,cAAc,GACrB,cAAc,CAAC,UAAU,CAAC,GAC1B,eAAe,GACf,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AACb,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { StorageError } from '../lib/errors';
|
|
2
|
+
import { Fetch } from '../lib/fetch';
|
|
3
|
+
import { Bucket, BucketType } from '../lib/types';
|
|
4
|
+
import { StorageClientOptions } from '../StorageClient';
|
|
5
|
+
export default class StorageBucketApi {
|
|
6
|
+
protected url: string;
|
|
7
|
+
protected headers: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
10
|
+
protected fetch: Fetch;
|
|
11
|
+
constructor(url: string, headers?: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
}, fetch?: Fetch, opts?: StorageClientOptions);
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the details of all Storage buckets within an existing project.
|
|
16
|
+
*/
|
|
17
|
+
listBuckets(): Promise<{
|
|
18
|
+
data: Bucket[];
|
|
19
|
+
error: null;
|
|
20
|
+
} | {
|
|
21
|
+
data: null;
|
|
22
|
+
error: StorageError;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the details of an existing Storage bucket.
|
|
26
|
+
*
|
|
27
|
+
* @param id The unique identifier of the bucket you would like to retrieve.
|
|
28
|
+
*/
|
|
29
|
+
getBucket(id: string): Promise<{
|
|
30
|
+
data: Bucket;
|
|
31
|
+
error: null;
|
|
32
|
+
} | {
|
|
33
|
+
data: null;
|
|
34
|
+
error: StorageError;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new Storage bucket
|
|
38
|
+
*
|
|
39
|
+
* @param id A unique identifier for the bucket you are creating.
|
|
40
|
+
* @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. By default, buckets are private.
|
|
41
|
+
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
42
|
+
* The global file size limit takes precedence over this value.
|
|
43
|
+
* The default value is null, which doesn't set a per bucket file size limit.
|
|
44
|
+
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
45
|
+
* The default value is null, which allows files with all mime types to be uploaded.
|
|
46
|
+
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
47
|
+
* @returns newly created bucket id
|
|
48
|
+
* @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
|
|
49
|
+
* - default bucket type is `STANDARD`
|
|
50
|
+
*/
|
|
51
|
+
createBucket(id: string, options?: {
|
|
52
|
+
public: boolean;
|
|
53
|
+
fileSizeLimit?: number | string | null;
|
|
54
|
+
allowedMimeTypes?: string[] | null;
|
|
55
|
+
type?: BucketType;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
data: Pick<Bucket, 'name'>;
|
|
58
|
+
error: null;
|
|
59
|
+
} | {
|
|
60
|
+
data: null;
|
|
61
|
+
error: StorageError;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Updates a Storage bucket
|
|
65
|
+
*
|
|
66
|
+
* @param id A unique identifier for the bucket you are updating.
|
|
67
|
+
* @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations.
|
|
68
|
+
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
69
|
+
* The global file size limit takes precedence over this value.
|
|
70
|
+
* The default value is null, which doesn't set a per bucket file size limit.
|
|
71
|
+
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
72
|
+
* The default value is null, which allows files with all mime types to be uploaded.
|
|
73
|
+
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
74
|
+
*/
|
|
75
|
+
updateBucket(id: string, options: {
|
|
76
|
+
public: boolean;
|
|
77
|
+
fileSizeLimit?: number | string | null;
|
|
78
|
+
allowedMimeTypes?: string[] | null;
|
|
79
|
+
}): Promise<{
|
|
80
|
+
data: {
|
|
81
|
+
message: string;
|
|
82
|
+
};
|
|
83
|
+
error: null;
|
|
84
|
+
} | {
|
|
85
|
+
data: null;
|
|
86
|
+
error: StorageError;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Removes all objects inside a single bucket.
|
|
90
|
+
*
|
|
91
|
+
* @param id The unique identifier of the bucket you would like to empty.
|
|
92
|
+
*/
|
|
93
|
+
emptyBucket(id: string): Promise<{
|
|
94
|
+
data: {
|
|
95
|
+
message: string;
|
|
96
|
+
};
|
|
97
|
+
error: null;
|
|
98
|
+
} | {
|
|
99
|
+
data: null;
|
|
100
|
+
error: StorageError;
|
|
101
|
+
}>;
|
|
102
|
+
/**
|
|
103
|
+
* Deletes an existing bucket. A bucket can't be deleted with existing objects inside it.
|
|
104
|
+
* You must first `empty()` the bucket.
|
|
105
|
+
*
|
|
106
|
+
* @param id The unique identifier of the bucket you would like to delete.
|
|
107
|
+
*/
|
|
108
|
+
deleteBucket(id: string): Promise<{
|
|
109
|
+
data: {
|
|
110
|
+
message: string;
|
|
111
|
+
};
|
|
112
|
+
error: null;
|
|
113
|
+
} | {
|
|
114
|
+
data: null;
|
|
115
|
+
error: StorageError;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=StorageBucketApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageBucketApi.d.ts","sourceRoot":"","sources":["../../../src/packages/StorageBucketApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,KAAK,EAA0B,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7C,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;gBAGrB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAO,EACvC,KAAK,CAAC,EAAE,KAAK,EACb,IAAI,CAAC,EAAE,oBAAoB;IAS7B;;OAEG;IACG,WAAW,IAAI,OAAO,CACxB;QACE,IAAI,EAAE,MAAM,EAA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AE,MAAM,GAAG,OAAO,CAClC;QACE,IAAI,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1B,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;IAkBD;;;;;OAKG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CACnC;QACE,IAAI,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1B,KAAK,EAAE,IAAI,CAAC;KACb,GACD;QACE,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,EAAE,YAAY,CAAC;KACrB,CACJ;CAiBF"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../lib/constants");
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const fetch_1 = require("../lib/fetch");
|
|
6
|
+
const helpers_1 = require("../lib/helpers");
|
|
7
|
+
class StorageBucketApi {
|
|
8
|
+
constructor(url, headers = {}, fetch, opts) {
|
|
9
|
+
const baseUrl = new URL(url);
|
|
10
|
+
this.url = baseUrl.href;
|
|
11
|
+
this.headers = Object.assign(Object.assign({}, constants_1.DEFAULT_HEADERS), headers);
|
|
12
|
+
this.fetch = (0, helpers_1.resolveFetch)(fetch);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the details of all Storage buckets within an existing project.
|
|
16
|
+
*/
|
|
17
|
+
async listBuckets() {
|
|
18
|
+
try {
|
|
19
|
+
const data = await (0, fetch_1.get)(this.fetch, `${this.url}/bucket`, { headers: this.headers });
|
|
20
|
+
return { data, error: null };
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if ((0, errors_1.isStorageError)(error)) {
|
|
24
|
+
return { data: null, error };
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the details of an existing Storage bucket.
|
|
31
|
+
*
|
|
32
|
+
* @param id The unique identifier of the bucket you would like to retrieve.
|
|
33
|
+
*/
|
|
34
|
+
async getBucket(id) {
|
|
35
|
+
try {
|
|
36
|
+
const data = await (0, fetch_1.get)(this.fetch, `${this.url}/bucket/${id}`, { headers: this.headers });
|
|
37
|
+
return { data, error: null };
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if ((0, errors_1.isStorageError)(error)) {
|
|
41
|
+
return { data: null, error };
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new Storage bucket
|
|
48
|
+
*
|
|
49
|
+
* @param id A unique identifier for the bucket you are creating.
|
|
50
|
+
* @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations. By default, buckets are private.
|
|
51
|
+
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
52
|
+
* The global file size limit takes precedence over this value.
|
|
53
|
+
* The default value is null, which doesn't set a per bucket file size limit.
|
|
54
|
+
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
55
|
+
* The default value is null, which allows files with all mime types to be uploaded.
|
|
56
|
+
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
57
|
+
* @returns newly created bucket id
|
|
58
|
+
* @param options.type (private-beta) specifies the bucket type. see `BucketType` for more details.
|
|
59
|
+
* - default bucket type is `STANDARD`
|
|
60
|
+
*/
|
|
61
|
+
async createBucket(id, options = {
|
|
62
|
+
public: false,
|
|
63
|
+
}) {
|
|
64
|
+
try {
|
|
65
|
+
const data = await (0, fetch_1.post)(this.fetch, `${this.url}/bucket`, {
|
|
66
|
+
id,
|
|
67
|
+
name: id,
|
|
68
|
+
type: options.type,
|
|
69
|
+
public: options.public,
|
|
70
|
+
file_size_limit: options.fileSizeLimit,
|
|
71
|
+
allowed_mime_types: options.allowedMimeTypes,
|
|
72
|
+
}, { headers: this.headers });
|
|
73
|
+
return { data, error: null };
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if ((0, errors_1.isStorageError)(error)) {
|
|
77
|
+
return { data: null, error };
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Updates a Storage bucket
|
|
84
|
+
*
|
|
85
|
+
* @param id A unique identifier for the bucket you are updating.
|
|
86
|
+
* @param options.public The visibility of the bucket. Public buckets don't require an authorization token to download objects, but still require a valid token for all other operations.
|
|
87
|
+
* @param options.fileSizeLimit specifies the max file size in bytes that can be uploaded to this bucket.
|
|
88
|
+
* The global file size limit takes precedence over this value.
|
|
89
|
+
* The default value is null, which doesn't set a per bucket file size limit.
|
|
90
|
+
* @param options.allowedMimeTypes specifies the allowed mime types that this bucket can accept during upload.
|
|
91
|
+
* The default value is null, which allows files with all mime types to be uploaded.
|
|
92
|
+
* Each mime type specified can be a wildcard, e.g. image/*, or a specific mime type, e.g. image/png.
|
|
93
|
+
*/
|
|
94
|
+
async updateBucket(id, options) {
|
|
95
|
+
try {
|
|
96
|
+
const data = await (0, fetch_1.put)(this.fetch, `${this.url}/bucket/${id}`, {
|
|
97
|
+
id,
|
|
98
|
+
name: id,
|
|
99
|
+
public: options.public,
|
|
100
|
+
file_size_limit: options.fileSizeLimit,
|
|
101
|
+
allowed_mime_types: options.allowedMimeTypes,
|
|
102
|
+
}, { headers: this.headers });
|
|
103
|
+
return { data, error: null };
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if ((0, errors_1.isStorageError)(error)) {
|
|
107
|
+
return { data: null, error };
|
|
108
|
+
}
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Removes all objects inside a single bucket.
|
|
114
|
+
*
|
|
115
|
+
* @param id The unique identifier of the bucket you would like to empty.
|
|
116
|
+
*/
|
|
117
|
+
async emptyBucket(id) {
|
|
118
|
+
try {
|
|
119
|
+
const data = await (0, fetch_1.post)(this.fetch, `${this.url}/bucket/${id}/empty`, {}, { headers: this.headers });
|
|
120
|
+
return { data, error: null };
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if ((0, errors_1.isStorageError)(error)) {
|
|
124
|
+
return { data: null, error };
|
|
125
|
+
}
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Deletes an existing bucket. A bucket can't be deleted with existing objects inside it.
|
|
131
|
+
* You must first `empty()` the bucket.
|
|
132
|
+
*
|
|
133
|
+
* @param id The unique identifier of the bucket you would like to delete.
|
|
134
|
+
*/
|
|
135
|
+
async deleteBucket(id) {
|
|
136
|
+
try {
|
|
137
|
+
const data = await (0, fetch_1.remove)(this.fetch, `${this.url}/bucket/${id}`, {}, { headers: this.headers });
|
|
138
|
+
return { data, error: null };
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
if ((0, errors_1.isStorageError)(error)) {
|
|
142
|
+
return { data: null, error };
|
|
143
|
+
}
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.default = StorageBucketApi;
|
|
149
|
+
//# sourceMappingURL=StorageBucketApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageBucketApi.js","sourceRoot":"","sources":["../../../src/packages/StorageBucketApi.ts"],"names":[],"mappings":";;AAAA,gDAAmD;AACnD,0CAA6D;AAC7D,wCAA6D;AAC7D,4CAA8C;AAI9C,MAAqB,gBAAgB;IAKnC,YACE,GAAW,EACX,UAAqC,EAAE,EACvC,KAAa,EACb,IAA2B;QAE3B,MAAM,OAAO,GAAG,IAAI,GAAG,CA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