@sab-js/adapter-local 0.0.0-stage → 3.0.4

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.
@@ -0,0 +1,252 @@
1
+ import { ResultObject, ResultObjectBoolean, ResultObjectBuckets, ResultObjectFiles, ResultObjectNumber, ResultObjectObject, ResultObjectStream } from "./result";
2
+ import { FileBufferParams, FilePathParams, FileStreamParams } from "./add_file_params";
3
+ export declare enum Provider {
4
+ NONE = "none",// initial value for the abstract adapter, don't use this one
5
+ LOCAL = "local",// local testing adapter
6
+ GCS = "gcs",// Google Cloud Storage
7
+ GS = "gs",// Google Cloud Storage
8
+ S3 = "s3",// Amazon S3
9
+ AWS = "aws",// Amazon S3
10
+ AZURE = "azure",// Azure Storage Blob
11
+ B2 = "b2",// BackBlaze B2 using native API with AdapterBackblazeB2
12
+ BACKBLAZE = "b2",// BackBlaze B2 using native API with AdapterBackblazeB2
13
+ B2_S3 = "b2-s3",// Backblaze B2 using S3 API with AdapterAmazonS3
14
+ BACKBLAZE_S3 = "b2-s3",// Backblaze B2 using S3 API with AdapterAmazonS3
15
+ MINIO = "minio",// Minio using native API with AdapterMinio
16
+ MINIO_S3 = "minio-s3",// Minio using S3 API with AdapterAmazonS3
17
+ CUBBIT = "cubbit",// Cubbit uses S3 API with AdapterAmazonS3
18
+ R2 = "r2",// Cloudflare R2 uses S3 API with AdapterAmazonS3
19
+ CLOUDFLARE = "r2"
20
+ }
21
+ export interface AdapterConfig {
22
+ bucketName?: string;
23
+ [id: string]: any;
24
+ }
25
+ export interface StorageAdapterConfig extends AdapterConfig {
26
+ provider: string;
27
+ }
28
+ export interface Options {
29
+ [id: string]: any;
30
+ }
31
+ /**
32
+ * @param start the byte of the file where the stream starts(default: 0)
33
+ * @param end the byte in the file where the stream ends(default: last byte of file)
34
+ */
35
+ export interface StreamOptions extends Options {
36
+ start?: number;
37
+ end?: number;
38
+ }
39
+ export interface IAdapter {
40
+ /**
41
+ * @returns The instance of the service client that connects to the cloud service under the hood. For instance the adapter for Amazon returns the S3Client of the AWS SDK v3.
42
+ */
43
+ getServiceClient(): any;
44
+ /**
45
+ * `getServiceClient` implemented as getter
46
+ * The instance of the service client that connects to the cloud service under the hood. For instance the adapter for Amazon returns the S3Client of the AWS SDK v3.
47
+ */
48
+ get serviceClient(): any;
49
+ /**
50
+ * @returns the storage provide, e.g. 'gcs', 'b2', 'local' etc.
51
+ */
52
+ getProvider(): Provider;
53
+ /**
54
+ * `getType` implemented as getter
55
+ * The adapter type, e.g. 'gcs', 'b2', 'local' etc.
56
+ */
57
+ get provider(): Provider;
58
+ /**
59
+ * Returns configuration settings that you've provided when instantiating as an object.
60
+ * Use this only for debugging and with great care as it may expose sensitive information.
61
+ *
62
+ * The object contains the key `bucketName` which is the initial value that you've set during
63
+ * initialization.
64
+ *
65
+ * The object also contains the key `options` which are only the options passed in during
66
+ * initialization; if you want all options, including the default options use `getOptions()`
67
+ *
68
+ * @returns adapter configuration as object
69
+ */
70
+ getConfig(): AdapterConfig;
71
+ /**
72
+ * `getConfiguration` implemented as getter
73
+ * The adapter configuration as object
74
+ */
75
+ get config(): AdapterConfig;
76
+ /**
77
+ * @returns the error message from the configuration parser or `null`.
78
+ */
79
+ getConfigError(): null | string;
80
+ /**
81
+ * `getConfigError` implemented as getter
82
+ * The error message from the configuration parser or `null`.
83
+ */
84
+ get configError(): null | string;
85
+ /**
86
+ * @returns The name of the selected bucket or `null` if no bucket is selected.
87
+ */
88
+ getSelectedBucket(): null | string;
89
+ /**
90
+ * `getSelectedBucket` implemented as getter
91
+ * The name of the selected bucket or `null` if no bucket is selected.
92
+ */
93
+ get selectedBucket(): null | string;
94
+ /**
95
+ * Stores the name of a bucket. The name of the bucket will be accessible using `getSelectedBucket` or the getter `selectedBucket`. By setting a selected bucket you can omit the `bucketName` parameter in all methods that otherwise require this parameter
96
+ * @param bucketName the name of the bucket, if you pass `null` the currently selected bucket will be deselected
97
+ */
98
+ setSelectedBucket(bucketName: null | string): void;
99
+ /**
100
+ * Stores the name of a bucket. The name of the bucket will be accessible using `getSelectedBucket` or the getter `selectedBucket`. By setting a selected bucket you can omit the `bucketName` parameter in all methods that otherwise require this parameter
101
+ * @param bucketName the name of the bucket, if you pass `null` the currently selected bucket will be deselected
102
+ */
103
+ set selectedBucket(bucketName: null | string);
104
+ /**
105
+ * short version of `getSelectedBucket`
106
+ * The name of the selected bucket or `null` if no bucket is selected.
107
+ */
108
+ get bucketName(): null | string;
109
+ /**
110
+ * @description short version of `setSelectedBucket`
111
+ * @description Stores the name of a bucket. The name of the bucket will be accessible using `getSelectedBucket` or the getter `selectedBucket`. By setting a selected bucket you can omit the `bucketName` parameter in all methods that otherwise require this parameter
112
+ * @param name the name of the bucket, if you pass `null` the currently selected bucket will be deselected
113
+ */
114
+ set bucketName(name: null | string);
115
+ /**
116
+ * @promise CreateBucketPromise
117
+ * @fulfill {ResultObject} `{value: "ok"}` or `{error: "the generated error message"}`
118
+ */
119
+ /**
120
+ * @description creates new bucket
121
+ * @param bucketName name of the bucket to create, returns "ok" once the bucket has been created but yields an error if bucket already exists.
122
+ * @param options additional options for creating a bucket such as access rights
123
+ * @resolves `{value: "ok"}` or `{error: "the generated error message"}`
124
+ */
125
+ createBucket(...args: [bucketName?: string, options?: Options] | [options?: Options]): Promise<ResultObject>;
126
+ /**
127
+ * @param bucketName: deletes all files in the bucket.
128
+ */
129
+ clearBucket(bucketName?: string): Promise<ResultObject>;
130
+ /**
131
+ * Deletes the bucket with the provided name. If no bucket name is provided, the selected bucket will be deleted.
132
+ * @param {string} bucketName name of the bucket
133
+ * @returns {Promise<ResultObject>} a promise that always resolves in a ResultObject:
134
+ * ```typescript
135
+ * { error: null | string, value: null | string }
136
+ * ```
137
+ */
138
+ deleteBucket(bucketName?: string): Promise<ResultObject>;
139
+ /**
140
+ * @returns an array of the names of the buckets in this storage
141
+ */
142
+ listBuckets(): Promise<ResultObjectBuckets>;
143
+ /**
144
+ * @param {filePathParams | FileBufferParams | FileStreamParams} params related to the file to be added
145
+ * @returns the public url to the file
146
+ * Called internally by addFileFromPath, addFileFromBuffer and addFileFromReadable
147
+ */
148
+ addFile(params: FilePathParams | FileBufferParams | FileStreamParams): Promise<ResultObject>;
149
+ /**
150
+ * @param {FilePathParams} params object that has the following keys:
151
+ * ```typescript
152
+ * {
153
+ * bucketName: string
154
+ * origPath: string //path to the file that you want to add, e.g. /home/user/Pictures/image1.jpg
155
+ * targetPath: string //path on the storage, you can add a path or only provide name of the file
156
+ * options?: object
157
+ * }
158
+ * ```
159
+ * @returns {ResultObject} a promise that always resolves in a ResultObject:
160
+ * ```typescript
161
+ * {
162
+ * value: null | string
163
+ * error: null | string
164
+ * }
165
+ * ```
166
+ */
167
+ addFileFromPath(params: FilePathParams): Promise<ResultObject>;
168
+ /**
169
+ * @param {FileBufferParams} params
170
+ * @property {string} FilePath.bucketName
171
+ * @property {Buffer} FilePath.buffer - buffer
172
+ * @property {string} FilePath.targetPath - path on the storage, you can add a path or only provide name of the file
173
+ * @property {object} FilePath.options
174
+ */
175
+ addFileFromBuffer(params: FileBufferParams): Promise<ResultObject>;
176
+ /**
177
+ * @param {FileStreamParams} params object that contains the following keys:
178
+ * ```typescript
179
+ * {
180
+ * bucketName: string
181
+ * readable: Readable // stream from the local file, e.g. fs.createReadStream(path)
182
+ * targetPath: string // path on the storage, you can add a path or only provide name of the file
183
+ * options?: object
184
+ * }
185
+ * ```
186
+ * @returns {ResultObject} a promise that always resolves in a ResultObject
187
+ * ```typescript
188
+ * {
189
+ * value: null | string // if success value is the public url to the file
190
+ * error: null | string // if fails error is the error message
191
+ * }
192
+ * ```
193
+ */
194
+ addFileFromStream(params: FileStreamParams): Promise<ResultObject>;
195
+ /**
196
+ * @param bucketName name of the bucket where the file is stored
197
+ * @param fileName name of the file to be returned as a readable stream
198
+ */
199
+ getFileAsStream(...args: [bucketName: string, fileName: string, options?: StreamOptions] | [fileName: string, options?: StreamOptions]): Promise<ResultObjectStream>;
200
+ /**
201
+ * @param bucketName name of the bucket where the file is stored
202
+ * @param fileName name of the file
203
+ * @param options
204
+ */
205
+ getPublicURL(...args: [bucketName: string, fileName: string, options?: Options] | [fileName: string, options?: Options]): Promise<ResultObject>;
206
+ /**
207
+ * @param bucketName name of the bucket where the file is stored
208
+ * @param fileName name of the file
209
+ * @param options e.g. { expiresIn: 3600 }
210
+ */
211
+ getSignedURL(...args: [bucketName: string, fileName: string, options?: Options] | [fileName: string, options?: Options]): Promise<ResultObject>;
212
+ /**
213
+ * @param bucketName name of the bucket where the file is stored
214
+ * @param fileName name of the file to be removed
215
+ */
216
+ removeFile(...args: [bucketName: string, fileName: string] | [fileName: string]): Promise<ResultObject>;
217
+ /**
218
+ * @param bucketName
219
+ * @param numFiles
220
+ * @returns an array of tuples containing the file path and the file size of all files in the bucket.
221
+ */
222
+ listFiles(...args: [bucketName: string, numFiles?: number] | [bucketName?: string] | [numFiles?: number]): Promise<ResultObjectFiles>;
223
+ /**
224
+ * @param bucketName name of the bucket where the file is stored
225
+ * @param fileName name of the file
226
+ * @returns the size of the file in bytes
227
+ */
228
+ sizeOf(...args: [bucketName: string, fileName: string] | [fileName: string]): Promise<ResultObjectNumber>;
229
+ /**
230
+ * @param bucketName name of the bucket
231
+ * @returns boolean
232
+ */
233
+ bucketExists(bucketName?: string): Promise<ResultObjectBoolean>;
234
+ /**
235
+ * @param bucketName name of the bucket
236
+ * @returns boolean
237
+ */
238
+ bucketIsPublic(bucketName?: string): Promise<ResultObjectBoolean>;
239
+ /**
240
+ * @param bucketName name of the bucket where the file is stored
241
+ * @param fileName name of the file
242
+ * @returns boolean
243
+ */
244
+ fileExists(...args: [bucketName: string, fileName: string] | [fileName: string]): Promise<ResultObjectBoolean>;
245
+ /**
246
+ * @param bucketName name of the bucket where the file is stored
247
+ * @param fileName name of the file
248
+ * @param options constraint validity of URL
249
+ * @returns string presigned upload URL
250
+ */
251
+ getPresignedUploadURL(...args: [bucketName: string, fileName: string, options?: Options] | [fileName: string, options?: Options]): Promise<ResultObjectObject>;
252
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Provider = void 0;
4
+ // add your custom type here
5
+ var Provider;
6
+ (function (Provider) {
7
+ Provider["NONE"] = "none";
8
+ Provider["LOCAL"] = "local";
9
+ Provider["GCS"] = "gcs";
10
+ Provider["GS"] = "gs";
11
+ Provider["S3"] = "s3";
12
+ Provider["AWS"] = "aws";
13
+ Provider["AZURE"] = "azure";
14
+ Provider["B2"] = "b2";
15
+ Provider["BACKBLAZE"] = "b2";
16
+ Provider["B2_S3"] = "b2-s3";
17
+ Provider["BACKBLAZE_S3"] = "b2-s3";
18
+ Provider["MINIO"] = "minio";
19
+ Provider["MINIO_S3"] = "minio-s3";
20
+ Provider["CUBBIT"] = "cubbit";
21
+ Provider["R2"] = "r2";
22
+ Provider["CLOUDFLARE"] = "r2";
23
+ })(Provider || (exports.Provider = Provider = {}));
24
+ //# sourceMappingURL=general.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"general.js","sourceRoot":"","sources":["../../../src/types/general.ts"],"names":[],"mappings":";;;AAWA,4BAA4B;AAC5B,IAAY,QAiBX;AAjBD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,2BAAe,CAAA;IACf,uBAAW,CAAA;IACX,qBAAS,CAAA;IACT,qBAAS,CAAA;IACT,uBAAW,CAAA;IACX,2BAAe,CAAA;IACf,qBAAS,CAAA;IACT,4BAAgB,CAAA;IAChB,2BAAe,CAAA;IACf,kCAAsB,CAAA;IACtB,2BAAe,CAAA;IACf,iCAAqB,CAAA;IACrB,6BAAiB,CAAA;IACjB,qBAAS,CAAA;IACT,6BAAiB,CAAA;AACnB,CAAC,EAjBW,QAAQ,wBAAR,QAAQ,QAiBnB"}
@@ -0,0 +1,58 @@
1
+ import { Readable } from "stream";
2
+ export type ParseUrlResult = {
3
+ error: null | string;
4
+ value: null | {
5
+ protocol: null | string;
6
+ username: null | string;
7
+ password: null | string;
8
+ host: null | string;
9
+ port: null | string;
10
+ path: null | string;
11
+ searchParams: null | {
12
+ [key: string]: string;
13
+ };
14
+ };
15
+ };
16
+ /**
17
+ * Generic return type
18
+ */
19
+ export interface ResultObject {
20
+ value: string | null;
21
+ error: string | null;
22
+ }
23
+ export type ResultObjectNumber = {
24
+ error: string | null;
25
+ value: number | null;
26
+ };
27
+ export type ResultObjectBoolean = {
28
+ error: string | null;
29
+ value: boolean | null;
30
+ };
31
+ export type ResultObjectFiles = {
32
+ error: string | null;
33
+ value: Array<[string, number]> | null;
34
+ };
35
+ export type ResultObjectBuckets = {
36
+ error: string | null;
37
+ value: Array<string> | null;
38
+ };
39
+ export type ResultObjectStringArray = {
40
+ error: string | null;
41
+ value: Array<string> | null;
42
+ };
43
+ export type ResultObjectKeyValue = {
44
+ error: string | null;
45
+ value: {
46
+ [key: string]: any;
47
+ } | null;
48
+ };
49
+ export type ResultObjectObject = {
50
+ error: string | null;
51
+ value: {
52
+ [key: string]: any;
53
+ } | null;
54
+ };
55
+ export type ResultObjectStream = {
56
+ error: string | null;
57
+ value: Readable | null;
58
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/types/result.ts"],"names":[],"mappings":""}
package/dist/util.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { ParseUrlResult, ResultObjectNumber } from "./types/result";
2
+ export declare const getErrorMessage: (error: unknown) => string;
3
+ /**
4
+ * @param {string} url
5
+ * strips off the querystring of an url and returns it as an object
6
+ */
7
+ export declare const parseQueryString: (url: string) => {
8
+ [id: string]: string;
9
+ };
10
+ /**
11
+ * @param {string} url
12
+ * Parses a config url string into fragments and parses the query string into a
13
+ * key-value object.
14
+ */
15
+ export declare const parseUrlStandard: (url: string, checkType?: boolean) => ParseUrlResult;
16
+ /**
17
+ * @param {string} url
18
+ * Parses a config url string into fragments and parses the query string into a
19
+ * key-value object.
20
+ */
21
+ export declare const parseUrl: (url: string, checkType?: boolean) => ParseUrlResult;
22
+ /**
23
+ * @param {string} s
24
+ *
25
+ * Parses a string that contains a radix prefix to a number
26
+ *
27
+ */
28
+ export declare const parseIntFromString: (s: string) => number;
29
+ export declare const parseMode: (mode: number | string) => ResultObjectNumber;
30
+ /**
31
+ * @param {string} str
32
+ *
33
+ * Checks if the value of the name is not null or undefined
34
+ */
35
+ export declare const isBlankString: (str: string) => boolean;
36
+ /**
37
+ * @param {string} name
38
+ *
39
+ * Checks if the value of the name is not null, undefined or an empty string
40
+ */
41
+ export declare const validateName: (name: string, type: string) => null | string;
package/dist/util.js ADDED
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateName = exports.isBlankString = exports.parseMode = exports.parseIntFromString = exports.parseUrl = exports.parseUrlStandard = exports.parseQueryString = exports.getErrorMessage = void 0;
4
+ const url_1 = require("url");
5
+ const general_1 = require("./types/general");
6
+ const getErrorMessage = (error) => {
7
+ if (error instanceof Error)
8
+ return error.message;
9
+ return String(error);
10
+ };
11
+ exports.getErrorMessage = getErrorMessage;
12
+ /**
13
+ * @param {string} url
14
+ * strips off the querystring of an url and returns it as an object
15
+ */
16
+ const parseQueryString = (url) => {
17
+ let options = {};
18
+ const questionMark = url.indexOf("?");
19
+ if (questionMark !== -1) {
20
+ options = url
21
+ .substring(questionMark + 1)
22
+ .split("&")
23
+ .map((pair) => pair.split("="))
24
+ .reduce((acc, val) => {
25
+ // acc[val[0]] = `${val[1]}`.valueOf();
26
+ acc[val[0]] = val[1];
27
+ return acc;
28
+ }, {});
29
+ }
30
+ return options;
31
+ };
32
+ exports.parseQueryString = parseQueryString;
33
+ /**
34
+ * @param {string} url
35
+ * Parses a config url string into fragments and parses the query string into a
36
+ * key-value object.
37
+ */
38
+ const parseUrlStandard = (url, checkType = false) => {
39
+ let parsed = null;
40
+ let searchParams = null;
41
+ if ((0, exports.isBlankString)(url)) {
42
+ return {
43
+ value: null,
44
+ error: "please provide a configuration url",
45
+ };
46
+ }
47
+ try {
48
+ parsed = new url_1.URL(url);
49
+ }
50
+ catch (e) {
51
+ return { value: null, error: (0, exports.getErrorMessage)(e) };
52
+ }
53
+ if (Object.keys(parsed.searchParams)) {
54
+ searchParams = {};
55
+ for (const [key, val] of parsed.searchParams) {
56
+ searchParams[key] = val;
57
+ }
58
+ }
59
+ return {
60
+ value: {
61
+ protocol: parsed.protocol,
62
+ username: parsed.username,
63
+ password: parsed.password,
64
+ host: parsed.host,
65
+ port: parsed.port,
66
+ path: parsed.pathname || null,
67
+ searchParams,
68
+ },
69
+ error: null,
70
+ };
71
+ };
72
+ exports.parseUrlStandard = parseUrlStandard;
73
+ /**
74
+ * @param {string} url
75
+ * Parses a config url string into fragments and parses the query string into a
76
+ * key-value object.
77
+ */
78
+ const parseUrl = (url, checkType = false) => {
79
+ let protocol = null;
80
+ let username = null;
81
+ let password = null;
82
+ let port = null;
83
+ let path = null;
84
+ let host = null;
85
+ let searchParams = null;
86
+ if ((0, exports.isBlankString)(url)) {
87
+ return {
88
+ value: null,
89
+ error: "please provide a configuration url",
90
+ };
91
+ }
92
+ const p = url.indexOf("://");
93
+ if (p === -1) {
94
+ return {
95
+ value: { protocol: url, username, password, host, port, path, searchParams },
96
+ error: null,
97
+ };
98
+ }
99
+ protocol = url.substring(0, p);
100
+ if (checkType === true && Object.values(general_1.Provider).includes(protocol) === false) {
101
+ return { value: null, error: `"${protocol}" is not a supported provider` };
102
+ }
103
+ let config = url.substring(p + 3);
104
+ const at = config.indexOf("@");
105
+ const questionMark = config.indexOf("?");
106
+ // parse options
107
+ if (questionMark !== -1) {
108
+ searchParams = (0, exports.parseQueryString)(url);
109
+ config = config.substring(0, questionMark);
110
+ }
111
+ // get host (bucket name)
112
+ if (at !== -1) {
113
+ host = config.substring(at + 1);
114
+ // remove port
115
+ const colon = host.indexOf(":");
116
+ if (colon !== -1) {
117
+ port = host.substring(colon + 1);
118
+ host = host.substring(0, colon);
119
+ }
120
+ // console.log(colon, port);
121
+ if (questionMark !== -1) {
122
+ host = host.substring(0, questionMark);
123
+ }
124
+ if ((0, exports.isBlankString)(host)) {
125
+ host = null;
126
+ }
127
+ config = config.substring(0, at);
128
+ }
129
+ // get credentials
130
+ const colon = config.indexOf(":");
131
+ if (colon !== -1) {
132
+ if (port === null) {
133
+ [username, password, port] = config.split(":");
134
+ if (typeof port === "undefined") {
135
+ port = null;
136
+ }
137
+ }
138
+ else {
139
+ [username, password] = config.split(":");
140
+ }
141
+ }
142
+ else if (config !== "") {
143
+ username = config;
144
+ }
145
+ // remove path from port in case it hasn't been removed
146
+ if (port !== null) {
147
+ const slash = port.indexOf("/");
148
+ if (slash !== -1) {
149
+ path = port.substring(slash + 1);
150
+ port = port.substring(0, slash);
151
+ }
152
+ }
153
+ // remove path from bucketName in case it hasn't been removed
154
+ if (host !== null) {
155
+ const slash = host.indexOf("/");
156
+ if (slash !== -1) {
157
+ path = host.substring(slash + 1);
158
+ host = host.substring(0, slash);
159
+ }
160
+ }
161
+ return {
162
+ value: { protocol, username, password, host, port, path, searchParams },
163
+ error: null,
164
+ };
165
+ };
166
+ exports.parseUrl = parseUrl;
167
+ /**
168
+ * @param {string} s
169
+ *
170
+ * Parses a string that contains a radix prefix to a number
171
+ *
172
+ */
173
+ const parseIntFromString = (s) => {
174
+ if (s.startsWith("0o")) {
175
+ return parseInt(s, 8);
176
+ }
177
+ if (s.startsWith("0x") || s.startsWith("0X")) {
178
+ return parseInt(s, 16);
179
+ }
180
+ if (s.startsWith("0b") || s.startsWith("0B")) {
181
+ return parseInt(s, 2);
182
+ }
183
+ return parseInt(s);
184
+ };
185
+ exports.parseIntFromString = parseIntFromString;
186
+ const parseMode = (mode) => {
187
+ // if mode is a number, parseMode assumes it is a decimal number
188
+ if (typeof mode === "number") {
189
+ if (mode < 0) {
190
+ return {
191
+ value: null,
192
+ error: `The argument 'mode' must be a 32-bit unsigned integer or an octal string. Received ${mode}`,
193
+ };
194
+ }
195
+ return { value: mode, error: null };
196
+ }
197
+ // mode is a string
198
+ // e.g "0o755" (octal string)
199
+ if (mode.startsWith("0o")) {
200
+ return { value: parseInt(mode.substring(2), 8), error: null };
201
+ }
202
+ // e.g '511' (decimal)
203
+ const i = parseInt(mode, 10);
204
+ // quick fix for erroneously passed octal number as string (without 0o prefix)
205
+ return { value: i > 511 ? 511 : i, error: null };
206
+ };
207
+ exports.parseMode = parseMode;
208
+ /**
209
+ * @param {string} str
210
+ *
211
+ * Checks if the value of the name is not null or undefined
212
+ */
213
+ const isBlankString = (str) => {
214
+ return !str || /^\s*$/.test(str);
215
+ };
216
+ exports.isBlankString = isBlankString;
217
+ /**
218
+ * @param {string} name
219
+ *
220
+ * Checks if the value of the name is not null, undefined or an empty string
221
+ */
222
+ const validateName = (name, type) => {
223
+ let error = null;
224
+ if (name === null) {
225
+ error = "Bucket name can not be `null`";
226
+ }
227
+ else if (name === "null") {
228
+ error = 'Bucket name can not be the string "null"';
229
+ }
230
+ else if (typeof name === "undefined") {
231
+ error = "Bucket name can not be `undefined`";
232
+ }
233
+ else if (name === "undefined") {
234
+ error = 'Bucket name can not be the string "undefined"';
235
+ }
236
+ else if ((0, exports.isBlankString)(name)) {
237
+ error = "Bucket name can not be an empty string";
238
+ }
239
+ else if (type === general_1.Provider.AZURE && name.indexOf("_") !== -1) {
240
+ error = "Bucket name can not contain underscores";
241
+ }
242
+ return error;
243
+ };
244
+ exports.validateName = validateName;
245
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAC1B,6CAA2C;AAQpC,MAAM,eAAe,GAAG,CAAC,KAAc,EAAU,EAAE;IACxD,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,OAAO,MAAM,C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,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,KAAK,GAAG,+BAA+B,CAAC;IAC1C,CAAC;SAAM,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QAC3B,KAAK,GAAG,0CAA0C,CAAC;IACrD,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QACvC,KAAK,GAAG,oCAAoC,CAAC;IAC/C,CAAC;SAAM,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,KAAK,GAAG,+CAA+C,CAAC;IAC1D,CAAC;SAAM,IAAI,IAAA,qBAAa,EAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,KAAK,GAAG,wCAAwC,CAAC;IACnD,CAAC;SAAM,IAAI,IAAI,KAAK,kBAAQ,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC/D,KAAK,GAAG,yCAAyC,CAAC;IACpD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAhBW,QAAA,YAAY,gBAgBvB"}
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@sab-js/adapter-local",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "3.0.4",
4
+ "description": "Provides an abstraction layer for interacting with local storage on your local machine or on your server.",
5
+ "main": "dist/index/AdapterLocal.js",
6
+ "types": "dist/index/AdapterLocal.d.ts",
7
+ "homepage": "https://github.com/sab-js/storage-abstraction/",
8
+ "repository": "https://github.com/sab-js/storage-abstraction/",
9
+ "dependencies": {
10
+ "glob": "^13.0.6",
11
+ "rimraf": "^6.1.3"
12
+ },
13
+ "scripts": {},
14
+ "keywords": [
15
+ "local file system",
16
+ "google cloud",
17
+ "backblaze b2",
18
+ "amazon s3",
19
+ "storage",
20
+ "storage abstraction",
21
+ "cloud filesystem",
22
+ "cloudflare r2",
23
+ "cubbit",
24
+ "minio",
25
+ "azure"
26
+ ],
27
+ "author": "abudaan@pm.me",
28
+ "license": "MIT",
29
+ "publishConfig": {
30
+ "access": "public"
31
+ }
6
32
  }