@alepha/bucket-azure 0.10.0 → 0.10.2
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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/package.json +9 -10
- package/dist/index.cjs +0 -148
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -50
- package/dist/index.d.cts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ declare class AzureFileStorageProvider implements FileStorageProvider {
|
|
|
44
44
|
* @see {@link AzureFileStorageProvider}
|
|
45
45
|
* @module alepha.bucket.azure
|
|
46
46
|
*/
|
|
47
|
-
declare const AlephaBucketAzure: _alepha_core1.Service<_alepha_core1.Module
|
|
47
|
+
declare const AlephaBucketAzure: _alepha_core1.Service<_alepha_core1.Module<{}>>;
|
|
48
48
|
//#endregion
|
|
49
49
|
export { AlephaBucketAzure, AzureFileStorageProvider };
|
|
50
50
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/providers/AzureFileStorageProvider.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;cA0BM,yBAAS;gCAIb,aAAA,CAAA;;;EAJI,UAAA,GAIJ,SAGqB,OAHrB,CAG6B,MAH7B,CAAA,OAG2C,SAH3C,CAAA,CAAA,CAAA,CAAA;;;;AAJa;AAAA,cAaF,wBAAA,YAAoC,mBAblC,CAAA;qBAO8B,GAAA,EAMP,eAAA,CACf,MAPsB;qBAAd,GAAA,EAAA;IAAR,4BAAA,EAAA,MAAA;EAAO,CAAA;EAAA,mBAAA,MAAA,EASJ,MATI;EAMjB,mBAAA,IAAA,EAIW,gBAJc;EAAA,mBAAA,UAAA,EAKN,MALM,CAAA,MAAA,EAKS,eALT,CAAA;qBACf,iBAAA,EAKgB,iBALhB;WAEG,OAAA,EAKA,s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IW,gBAJc;EAAA,mBAAA,UAAA,EAKN,MALM,CAAA,MAAA,EAKS,eALT,CAAA;qBACf,iBAAA,EAKgB,iBALhB;WAEG,OAAA,EAKA,sBALA;aACF,CAAA;qBACuB,OAAA,EAGC,aAAA,CASrB,cAZoB,CAAA,OAAA,CAAA;aAAf,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,MAAA;QACO,CAAA,UAAA,EAAA,MAAA,EAAA,IAAA,EAwC/B,QAxC+B,EAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EA0CnC,OA1CmC,CAAA,MAAA,CAAA;UAEb,CAAA,UAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAqFkC,OArFlC,CAqF0C,QArF1C,CAAA;QAAsB,CAAA,UASrB,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAoG+B,OApG/B,CAAA,OAAA,CAAA;QA6BnB,CAAA,UAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EA8EkD,OA9ElD,CAAA,IAAA,CAAA;UAEJ,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAwFiD,eAxFjD;YA6CgE,qBAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAyDhE,OAzDgE,CAyDxD,eAzDwD,CAAA;YAAR,QAAA,CAAA,CAAA,EAAA,MAAA;;;;;;;;;;cCtH/C,mBAAiB,aAAA,CAAA,QAW5B,aAAA,CAX4B"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"storage-blob"
|
|
11
11
|
],
|
|
12
12
|
"author": "Feunard",
|
|
13
|
-
"version": "0.10.
|
|
13
|
+
"version": "0.10.2",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=22.0.0"
|
|
@@ -23,17 +23,17 @@
|
|
|
23
23
|
"src"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@alepha/bucket": "0.10.
|
|
27
|
-
"@alepha/core": "0.10.
|
|
28
|
-
"@alepha/datetime": "0.10.
|
|
29
|
-
"@alepha/file": "0.10.
|
|
30
|
-
"@alepha/logger": "0.10.
|
|
26
|
+
"@alepha/bucket": "0.10.2",
|
|
27
|
+
"@alepha/core": "0.10.2",
|
|
28
|
+
"@alepha/datetime": "0.10.2",
|
|
29
|
+
"@alepha/file": "0.10.2",
|
|
30
|
+
"@alepha/logger": "0.10.2",
|
|
31
31
|
"@azure/storage-blob": "^12.29.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@biomejs/biome": "^2.2.4",
|
|
35
|
-
"tsdown": "^0.15.
|
|
36
|
-
"typescript": "^5.9.
|
|
35
|
+
"tsdown": "^0.15.6",
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
37
|
"vitest": "^3.2.4"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
@@ -51,8 +51,7 @@
|
|
|
51
51
|
"exports": {
|
|
52
52
|
".": {
|
|
53
53
|
"types": "./dist/index.d.ts",
|
|
54
|
-
"import": "./dist/index.js"
|
|
55
|
-
"require": "./dist/index.cjs"
|
|
54
|
+
"import": "./dist/index.js"
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const __alepha_bucket = __toESM(require("@alepha/bucket"));
|
|
25
|
-
const __alepha_core = __toESM(require("@alepha/core"));
|
|
26
|
-
const node_crypto = __toESM(require("node:crypto"));
|
|
27
|
-
const node_stream = __toESM(require("node:stream"));
|
|
28
|
-
const __alepha_datetime = __toESM(require("@alepha/datetime"));
|
|
29
|
-
const __alepha_file = __toESM(require("@alepha/file"));
|
|
30
|
-
const __alepha_logger = __toESM(require("@alepha/logger"));
|
|
31
|
-
const __azure_storage_blob = __toESM(require("@azure/storage-blob"));
|
|
32
|
-
|
|
33
|
-
//#region src/providers/AzureFileStorageProvider.ts
|
|
34
|
-
const envSchema = __alepha_core.t.object({ AZ_STORAGE_CONNECTION_STRING: __alepha_core.t.string({ size: "long" }) });
|
|
35
|
-
/**
|
|
36
|
-
* Azure Blog Storage implementation of File Storage Provider.
|
|
37
|
-
*/
|
|
38
|
-
var AzureFileStorageProvider = class {
|
|
39
|
-
log = (0, __alepha_logger.$logger)();
|
|
40
|
-
env = (0, __alepha_core.$env)(envSchema);
|
|
41
|
-
alepha = (0, __alepha_core.$inject)(__alepha_core.Alepha);
|
|
42
|
-
time = (0, __alepha_core.$inject)(__alepha_datetime.DateTimeProvider);
|
|
43
|
-
containers = {};
|
|
44
|
-
blobServiceClient;
|
|
45
|
-
options = {};
|
|
46
|
-
constructor() {
|
|
47
|
-
this.blobServiceClient = __azure_storage_blob.BlobServiceClient.fromConnectionString(this.env.AZ_STORAGE_CONNECTION_STRING, this.options);
|
|
48
|
-
}
|
|
49
|
-
onStart = (0, __alepha_core.$hook)({
|
|
50
|
-
on: "start",
|
|
51
|
-
handler: async () => {
|
|
52
|
-
for (const bucket of this.alepha.descriptors(__alepha_bucket.$bucket)) {
|
|
53
|
-
if (bucket.provider !== this) continue;
|
|
54
|
-
const containerName = this.convertName(bucket.name);
|
|
55
|
-
this.log.debug(`Prepare container '${containerName}' ...`);
|
|
56
|
-
if (!this.containers[containerName]) this.containers[containerName] = await this.createContainerClient(containerName);
|
|
57
|
-
this.log.info(`Container '${bucket.name}' OK`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
convertName(name) {
|
|
62
|
-
return name.replaceAll("/", "-").toLowerCase();
|
|
63
|
-
}
|
|
64
|
-
async upload(bucketName, file, fileId) {
|
|
65
|
-
fileId ??= this.createId();
|
|
66
|
-
this.log.trace(`Uploading file '${file.name}' to bucket '${bucketName}' with id '${fileId}'...`);
|
|
67
|
-
const block = this.getBlock(bucketName, fileId);
|
|
68
|
-
const metadata = {
|
|
69
|
-
name: file.name,
|
|
70
|
-
type: file.type
|
|
71
|
-
};
|
|
72
|
-
if (file.filepath) await block.uploadFile(file.filepath, {
|
|
73
|
-
metadata,
|
|
74
|
-
blobHTTPHeaders: { blobContentType: file.type }
|
|
75
|
-
});
|
|
76
|
-
else if (file.size > 0) await block.uploadData(await file.arrayBuffer(), {
|
|
77
|
-
metadata,
|
|
78
|
-
blobHTTPHeaders: { blobContentType: file.type }
|
|
79
|
-
});
|
|
80
|
-
else await block.uploadStream(node_stream.Readable.from(file.stream()), file.size || void 0, 5, {
|
|
81
|
-
metadata,
|
|
82
|
-
blobHTTPHeaders: { blobContentType: file.type }
|
|
83
|
-
});
|
|
84
|
-
return fileId;
|
|
85
|
-
}
|
|
86
|
-
async download(bucketName, fileId) {
|
|
87
|
-
this.log.trace(`Downloading file '${fileId}' from bucket '${bucketName}'...`);
|
|
88
|
-
const block = this.getBlock(bucketName, fileId);
|
|
89
|
-
const blob = await block.download().catch((error) => {
|
|
90
|
-
if (error instanceof Error) throw new __alepha_bucket.FileNotFoundError("Error downloading file", { cause: error });
|
|
91
|
-
throw error;
|
|
92
|
-
});
|
|
93
|
-
if (!blob.readableStreamBody) throw new __alepha_bucket.FileNotFoundError("File not found - empty stream body");
|
|
94
|
-
return (0, __alepha_file.createFile)(blob.readableStreamBody, {
|
|
95
|
-
...blob.metadata,
|
|
96
|
-
size: blob.contentLength
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
async exists(bucketName, fileId) {
|
|
100
|
-
this.log.trace(`Checking existence of file '${fileId}' in bucket '${bucketName}'...`);
|
|
101
|
-
return await this.getBlock(bucketName, fileId).exists();
|
|
102
|
-
}
|
|
103
|
-
async delete(bucketName, fileId) {
|
|
104
|
-
this.log.trace(`Deleting file '${fileId}' from bucket '${bucketName}'...`);
|
|
105
|
-
try {
|
|
106
|
-
await this.getBlock(bucketName, fileId).delete();
|
|
107
|
-
} catch (error) {
|
|
108
|
-
if (error instanceof Error) throw new __alepha_bucket.FileNotFoundError("Error deleting file", { cause: error });
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
getBlock(container, fileId) {
|
|
113
|
-
const containerName = this.convertName(container);
|
|
114
|
-
if (!this.containers[containerName]) throw new __alepha_bucket.FileNotFoundError(`File '${fileId}' not found - container '${container}' does not exists`);
|
|
115
|
-
return this.containers[containerName].getBlockBlobClient(fileId);
|
|
116
|
-
}
|
|
117
|
-
async createContainerClient(name) {
|
|
118
|
-
const container = this.blobServiceClient.getContainerClient(name);
|
|
119
|
-
await this.time.deadline((abortSignal) => container.createIfNotExists({ abortSignal }), [5, "seconds"]);
|
|
120
|
-
return container;
|
|
121
|
-
}
|
|
122
|
-
createId() {
|
|
123
|
-
return (0, node_crypto.randomUUID)();
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region src/index.ts
|
|
129
|
-
/**
|
|
130
|
-
* Plugin for Alepha Bucket that provides Azure Blob Storage capabilities.
|
|
131
|
-
*
|
|
132
|
-
* @see {@link AzureFileStorageProvider}
|
|
133
|
-
* @module alepha.bucket.azure
|
|
134
|
-
*/
|
|
135
|
-
const AlephaBucketAzure = (0, __alepha_core.$module)({
|
|
136
|
-
name: "alepha.bucket.azure",
|
|
137
|
-
services: [AzureFileStorageProvider],
|
|
138
|
-
register: (alepha) => alepha.with({
|
|
139
|
-
optional: true,
|
|
140
|
-
provide: __alepha_bucket.FileStorageProvider,
|
|
141
|
-
use: AzureFileStorageProvider
|
|
142
|
-
}).with(__alepha_bucket.AlephaBucket)
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
//#endregion
|
|
146
|
-
exports.AlephaBucketAzure = AlephaBucketAzure;
|
|
147
|
-
exports.AzureFileStorageProvider = AzureFileStorageProvider;
|
|
148
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["t","Alepha","DateTimeProvider","BlobServiceClient","$bucket","Readable","FileNotFoundError","FileStorageProvider","AlephaBucket"],"sources":["../src/providers/AzureFileStorageProvider.ts","../src/index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { Readable } from \"node:stream\";\nimport {\n\t$bucket,\n\tFileNotFoundError,\n\ttype FileStorageProvider,\n} from \"@alepha/bucket\";\nimport {\n\t$env,\n\t$hook,\n\t$inject,\n\tAlepha,\n\ttype FileLike,\n\ttype Static,\n\tt,\n} from \"@alepha/core\";\nimport { DateTimeProvider } from \"@alepha/datetime\";\nimport { createFile } from \"@alepha/file\";\nimport { $logger } from \"@alepha/logger\";\nimport {\n\tBlobServiceClient,\n\ttype BlockBlobClient,\n\ttype ContainerClient,\n\ttype StoragePipelineOptions,\n} from \"@azure/storage-blob\";\n\nconst envSchema = t.object({\n\tAZ_STORAGE_CONNECTION_STRING: t.string({\n\t\tsize: \"long\",\n\t}),\n});\n\ndeclare module \"@alepha/core\" {\n\tinterface Env extends Partial<Static<typeof envSchema>> {}\n}\n\n/**\n * Azure Blog Storage implementation of File Storage Provider.\n */\nexport class AzureFileStorageProvider implements FileStorageProvider {\n\tprotected readonly log = $logger();\n\tprotected readonly env = $env(envSchema);\n\tprotected readonly alepha = $inject(Alepha);\n\tprotected readonly time = $inject(DateTimeProvider);\n\tprotected readonly containers: Record<string, ContainerClient> = {};\n\tprotected readonly blobServiceClient: BlobServiceClient;\n\n\tpublic readonly options: StoragePipelineOptions = {};\n\n\tconstructor() {\n\t\tthis.blobServiceClient = BlobServiceClient.fromConnectionString(\n\t\t\tthis.env.AZ_STORAGE_CONNECTION_STRING,\n\t\t\tthis.options,\n\t\t);\n\t}\n\n\tprotected readonly onStart = $hook({\n\t\ton: \"start\",\n\t\thandler: async () => {\n\t\t\tfor (const bucket of this.alepha.descriptors($bucket)) {\n\t\t\t\tif (bucket.provider !== this) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst containerName = this.convertName(bucket.name);\n\n\t\t\t\tthis.log.debug(`Prepare container '${containerName}' ...`);\n\n\t\t\t\tif (!this.containers[containerName]) {\n\t\t\t\t\tthis.containers[containerName] =\n\t\t\t\t\t\tawait this.createContainerClient(containerName);\n\t\t\t\t}\n\n\t\t\t\tthis.log.info(`Container '${bucket.name}' OK`);\n\t\t\t}\n\t\t},\n\t});\n\n\tpublic convertName(name: string): string {\n\t\t// Azure Blob Storage does not allow uppercase letters in container names\n\t\treturn name.replaceAll(\"/\", \"-\").toLowerCase();\n\t}\n\n\tpublic async upload(\n\t\tbucketName: string,\n\t\tfile: FileLike,\n\t\tfileId?: string,\n\t): Promise<string> {\n\t\tfileId ??= this.createId();\n\n\t\tthis.log.trace(\n\t\t\t`Uploading file '${file.name}' to bucket '${bucketName}' with id '${fileId}'...`,\n\t\t);\n\n\t\tconst block = this.getBlock(bucketName, fileId);\n\n\t\tconst metadata = {\n\t\t\tname: file.name,\n\t\t\ttype: file.type,\n\t\t};\n\n\t\tif (file.filepath) {\n\t\t\tawait block.uploadFile(file.filepath, {\n\t\t\t\tmetadata,\n\t\t\t\tblobHTTPHeaders: {\n\t\t\t\t\tblobContentType: file.type,\n\t\t\t\t},\n\t\t\t});\n\t\t} else if (file.size > 0) {\n\t\t\tawait block.uploadData(await file.arrayBuffer(), {\n\t\t\t\tmetadata,\n\t\t\t\tblobHTTPHeaders: {\n\t\t\t\t\tblobContentType: file.type,\n\t\t\t\t},\n\t\t\t});\n\t\t} else {\n\t\t\tawait block.uploadStream(\n\t\t\t\tReadable.from(file.stream()),\n\t\t\t\tfile.size || undefined,\n\t\t\t\t5,\n\t\t\t\t{\n\t\t\t\t\tmetadata,\n\t\t\t\t\tblobHTTPHeaders: {\n\t\t\t\t\t\tblobContentType: file.type,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\treturn fileId;\n\t}\n\n\tpublic async download(bucketName: string, fileId: string): Promise<FileLike> {\n\t\tthis.log.trace(\n\t\t\t`Downloading file '${fileId}' from bucket '${bucketName}'...`,\n\t\t);\n\t\tconst block = this.getBlock(bucketName, fileId);\n\n\t\tconst blob = await block.download().catch((error) => {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tthrow new FileNotFoundError(\"Error downloading file\", { cause: error });\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t});\n\n\t\tif (!blob.readableStreamBody) {\n\t\t\tthrow new FileNotFoundError(\"File not found - empty stream body\");\n\t\t}\n\n\t\treturn createFile(blob.readableStreamBody, {\n\t\t\t...blob.metadata,\n\t\t\tsize: blob.contentLength,\n\t\t});\n\t}\n\n\tpublic async exists(bucketName: string, fileId: string): Promise<boolean> {\n\t\tthis.log.trace(\n\t\t\t`Checking existence of file '${fileId}' in bucket '${bucketName}'...`,\n\t\t);\n\t\treturn await this.getBlock(bucketName, fileId).exists();\n\t}\n\n\tpublic async delete(bucketName: string, fileId: string): Promise<void> {\n\t\tthis.log.trace(`Deleting file '${fileId}' from bucket '${bucketName}'...`);\n\t\ttry {\n\t\t\tawait this.getBlock(bucketName, fileId).delete();\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tthrow new FileNotFoundError(\"Error deleting file\", { cause: error });\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tpublic getBlock(container: string, fileId: string): BlockBlobClient {\n\t\tconst containerName = this.convertName(container);\n\n\t\tif (!this.containers[containerName]) {\n\t\t\tthrow new FileNotFoundError(\n\t\t\t\t`File '${fileId}' not found - container '${container}' does not exists`,\n\t\t\t);\n\t\t}\n\n\t\treturn this.containers[containerName].getBlockBlobClient(fileId);\n\t}\n\n\tprotected async createContainerClient(\n\t\tname: string,\n\t): Promise<ContainerClient> {\n\t\tconst container = this.blobServiceClient.getContainerClient(name);\n\n\t\tawait this.time.deadline(\n\t\t\t(abortSignal) => container.createIfNotExists({ abortSignal }),\n\t\t\t[5, \"seconds\"],\n\t\t);\n\n\t\treturn container;\n\t}\n\n\tprotected createId(): string {\n\t\treturn randomUUID();\n\t}\n}\n","import { AlephaBucket, FileStorageProvider } from \"@alepha/bucket\";\nimport { $module } from \"@alepha/core\";\nimport { AzureFileStorageProvider } from \"./providers/AzureFileStorageProvider.ts\";\n\nexport * from \"./providers/AzureFileStorageProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Plugin for Alepha Bucket that provides Azure Blob Storage capabilities.\n *\n * @see {@link AzureFileStorageProvider}\n * @module alepha.bucket.azure\n */\nexport const AlephaBucketAzure = $module({\n\tname: \"alepha.bucket.azure\",\n\tservices: [AzureFileStorageProvider],\n\tregister: (alepha) =>\n\t\talepha\n\t\t\t.with({\n\t\t\t\toptional: true,\n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Y,KAAK,kBAAkB,mBAAmB;AAE5D,QAAM,KAAK,KAAK,UACd,gBAAgB,UAAU,kBAAkB,EAAE,aAAa,GAC5D,CAAC,GAAG,UAAU;AAGf,SAAO;CACP;CAED,AAAU,WAAmB;AAC5B;CACA;AACD;;;;;;;;;;AC7LD,MAAa,+CAA4B;CACxC,MAAM;CACN,UAAU,CAAC,yBAAyB;CACpC,WAAW,WACV,OACE,KAAK;EACL,UAAU;EACV,SAASC;EACT,KAAK;EACL,EACA,KAAKC;CACR"}
|
package/dist/index.d.cts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import * as _alepha_core1 from "@alepha/core";
|
|
2
|
-
import { Alepha, FileLike, Static } from "@alepha/core";
|
|
3
|
-
import * as _alepha_logger0 from "@alepha/logger";
|
|
4
|
-
import { FileStorageProvider } from "@alepha/bucket";
|
|
5
|
-
import { DateTimeProvider } from "@alepha/datetime";
|
|
6
|
-
import { BlobServiceClient, BlockBlobClient, ContainerClient, StoragePipelineOptions } from "@azure/storage-blob";
|
|
7
|
-
|
|
8
|
-
//#region src/providers/AzureFileStorageProvider.d.ts
|
|
9
|
-
declare const envSchema: _alepha_core1.TObject<{
|
|
10
|
-
AZ_STORAGE_CONNECTION_STRING: _alepha_core1.TString;
|
|
11
|
-
}>;
|
|
12
|
-
declare module "@alepha/core" {
|
|
13
|
-
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Azure Blog Storage implementation of File Storage Provider.
|
|
17
|
-
*/
|
|
18
|
-
declare class AzureFileStorageProvider implements FileStorageProvider {
|
|
19
|
-
protected readonly log: _alepha_logger0.Logger;
|
|
20
|
-
protected readonly env: {
|
|
21
|
-
AZ_STORAGE_CONNECTION_STRING: string;
|
|
22
|
-
};
|
|
23
|
-
protected readonly alepha: Alepha;
|
|
24
|
-
protected readonly time: DateTimeProvider;
|
|
25
|
-
protected readonly containers: Record<string, ContainerClient>;
|
|
26
|
-
protected readonly blobServiceClient: BlobServiceClient;
|
|
27
|
-
readonly options: StoragePipelineOptions;
|
|
28
|
-
constructor();
|
|
29
|
-
protected readonly onStart: _alepha_core1.HookDescriptor<"start">;
|
|
30
|
-
convertName(name: string): string;
|
|
31
|
-
upload(bucketName: string, file: FileLike, fileId?: string): Promise<string>;
|
|
32
|
-
download(bucketName: string, fileId: string): Promise<FileLike>;
|
|
33
|
-
exists(bucketName: string, fileId: string): Promise<boolean>;
|
|
34
|
-
delete(bucketName: string, fileId: string): Promise<void>;
|
|
35
|
-
getBlock(container: string, fileId: string): BlockBlobClient;
|
|
36
|
-
protected createContainerClient(name: string): Promise<ContainerClient>;
|
|
37
|
-
protected createId(): string;
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region src/index.d.ts
|
|
41
|
-
/**
|
|
42
|
-
* Plugin for Alepha Bucket that provides Azure Blob Storage capabilities.
|
|
43
|
-
*
|
|
44
|
-
* @see {@link AzureFileStorageProvider}
|
|
45
|
-
* @module alepha.bucket.azure
|
|
46
|
-
*/
|
|
47
|
-
declare const AlephaBucketAzure: _alepha_core1.Service<_alepha_core1.Module>;
|
|
48
|
-
//#endregion
|
|
49
|
-
export { AlephaBucketAzure, AzureFileStorageProvider };
|
|
50
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/providers/AzureFileStorageProvider.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;cA0BM,yBAAS;gCAIb,aAAA,CAAA;;;EAJI,UAAA,GAIJ,SAGqB,OAHrB,CAG6B,MAH7B,CAAA,OAG2C,SAH3C,CAAA,CAAA,CAAA,CAAA;;;;AAJa;AAAA,cAaF,wBAAA,YAAoC,mBAblC,CAAA;qBAO8B,GAAA,EAMP,eAAA,CACf,MAPsB;qBAAd,GAAA,EAAA;IAAR,4BAAA,EAAA,MAAA;EAAO,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