@alepha/bucket-azure 0.11.11 → 0.12.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 +1 -13
- package/dist/index.cjs +21 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -12
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +46 -56
- package/src/index.ts +2 -2
- package/src/providers/AzureFileStorageProvider.ts +14 -14
package/README.md
CHANGED
|
@@ -14,25 +14,13 @@ npm install alepha
|
|
|
14
14
|
|
|
15
15
|
Plugin for Alepha Bucket that provides Azure Blob Storage capabilities.
|
|
16
16
|
|
|
17
|
-
This module can be imported and used as follows:
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
import { Alepha, run } from "alepha";
|
|
21
|
-
import { AlephaBucketAzure } from "alepha/bucket/azure";
|
|
22
|
-
|
|
23
|
-
const alepha = Alepha.create()
|
|
24
|
-
.with(AlephaBucketAzure);
|
|
25
|
-
|
|
26
|
-
run(alepha);
|
|
27
|
-
```
|
|
28
|
-
|
|
29
17
|
## API Reference
|
|
30
18
|
|
|
31
19
|
### Providers
|
|
32
20
|
|
|
33
21
|
Providers are classes that encapsulate specific functionality and can be injected into your application. They handle initialization, configuration, and lifecycle management.
|
|
34
22
|
|
|
35
|
-
For more details, see the [Providers documentation](/
|
|
23
|
+
For more details, see the [Providers documentation](https://feunard.github.io/alepha/).
|
|
36
24
|
|
|
37
25
|
#### AzureFileStorageProvider
|
|
38
26
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
let
|
|
2
|
-
let
|
|
1
|
+
let alepha = require("alepha");
|
|
2
|
+
let alepha_bucket = require("alepha/bucket");
|
|
3
3
|
let node_crypto = require("node:crypto");
|
|
4
4
|
let node_stream = require("node:stream");
|
|
5
|
-
let __alepha_datetime = require("@alepha/datetime");
|
|
6
|
-
let __alepha_file = require("@alepha/file");
|
|
7
|
-
let __alepha_logger = require("@alepha/logger");
|
|
8
5
|
let __azure_storage_blob = require("@azure/storage-blob");
|
|
6
|
+
let alepha_datetime = require("alepha/datetime");
|
|
7
|
+
let alepha_file = require("alepha/file");
|
|
8
|
+
let alepha_logger = require("alepha/logger");
|
|
9
9
|
|
|
10
10
|
//#region src/providers/AzureFileStorageProvider.ts
|
|
11
|
-
const envSchema =
|
|
11
|
+
const envSchema = alepha.t.object({ AZ_STORAGE_CONNECTION_STRING: alepha.t.string() });
|
|
12
12
|
/**
|
|
13
13
|
* Azure Blog Storage implementation of File Storage Provider.
|
|
14
14
|
*/
|
|
15
15
|
var AzureFileStorageProvider = class {
|
|
16
|
-
log = (0,
|
|
17
|
-
env = (0,
|
|
18
|
-
alepha = (0,
|
|
19
|
-
time = (0,
|
|
20
|
-
fileSystem = (0,
|
|
16
|
+
log = (0, alepha_logger.$logger)();
|
|
17
|
+
env = (0, alepha.$env)(envSchema);
|
|
18
|
+
alepha = (0, alepha.$inject)(alepha.Alepha);
|
|
19
|
+
time = (0, alepha.$inject)(alepha_datetime.DateTimeProvider);
|
|
20
|
+
fileSystem = (0, alepha.$inject)(alepha_file.FileSystemProvider);
|
|
21
21
|
containers = {};
|
|
22
22
|
blobServiceClient;
|
|
23
23
|
options = {};
|
|
24
24
|
constructor() {
|
|
25
25
|
this.blobServiceClient = __azure_storage_blob.BlobServiceClient.fromConnectionString(this.env.AZ_STORAGE_CONNECTION_STRING, this.options);
|
|
26
26
|
}
|
|
27
|
-
onStart = (0,
|
|
27
|
+
onStart = (0, alepha.$hook)({
|
|
28
28
|
on: "start",
|
|
29
29
|
handler: async () => {
|
|
30
|
-
for (const bucket of this.alepha.descriptors(
|
|
30
|
+
for (const bucket of this.alepha.descriptors(alepha_bucket.$bucket)) {
|
|
31
31
|
if (bucket.provider !== this) continue;
|
|
32
32
|
const containerName = this.convertName(bucket.name);
|
|
33
33
|
this.log.debug(`Prepare container '${containerName}' ...`);
|
|
@@ -64,10 +64,10 @@ var AzureFileStorageProvider = class {
|
|
|
64
64
|
async download(bucketName, fileId) {
|
|
65
65
|
this.log.trace(`Downloading file '${fileId}' from bucket '${bucketName}'...`);
|
|
66
66
|
const blob = await this.getBlock(bucketName, fileId).download().catch((error) => {
|
|
67
|
-
if (error instanceof Error) throw new
|
|
67
|
+
if (error instanceof Error) throw new alepha_bucket.FileNotFoundError("Error downloading file", { cause: error });
|
|
68
68
|
throw error;
|
|
69
69
|
});
|
|
70
|
-
if (!blob.readableStreamBody) throw new
|
|
70
|
+
if (!blob.readableStreamBody) throw new alepha_bucket.FileNotFoundError("File not found - empty stream body");
|
|
71
71
|
return this.fileSystem.createFile({
|
|
72
72
|
stream: blob.readableStreamBody,
|
|
73
73
|
...blob.metadata,
|
|
@@ -83,13 +83,13 @@ var AzureFileStorageProvider = class {
|
|
|
83
83
|
try {
|
|
84
84
|
await this.getBlock(bucketName, fileId).delete();
|
|
85
85
|
} catch (error) {
|
|
86
|
-
if (error instanceof Error) throw new
|
|
86
|
+
if (error instanceof Error) throw new alepha_bucket.FileNotFoundError("Error deleting file", { cause: error });
|
|
87
87
|
throw error;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
getBlock(container, fileId) {
|
|
91
91
|
const containerName = this.convertName(container);
|
|
92
|
-
if (!this.containers[containerName]) throw new
|
|
92
|
+
if (!this.containers[containerName]) throw new alepha_bucket.FileNotFoundError(`File '${fileId}' not found - container '${container}' does not exists`);
|
|
93
93
|
return this.containers[containerName].getBlockBlobClient(fileId);
|
|
94
94
|
}
|
|
95
95
|
async createContainerClient(name) {
|
|
@@ -110,14 +110,14 @@ var AzureFileStorageProvider = class {
|
|
|
110
110
|
* @see {@link AzureFileStorageProvider}
|
|
111
111
|
* @module alepha.bucket.azure
|
|
112
112
|
*/
|
|
113
|
-
const AlephaBucketAzure = (0,
|
|
113
|
+
const AlephaBucketAzure = (0, alepha.$module)({
|
|
114
114
|
name: "alepha.bucket.azure",
|
|
115
115
|
services: [AzureFileStorageProvider],
|
|
116
|
-
register: (alepha) => alepha.with({
|
|
116
|
+
register: (alepha$1) => alepha$1.with({
|
|
117
117
|
optional: true,
|
|
118
|
-
provide:
|
|
118
|
+
provide: alepha_bucket.FileStorageProvider,
|
|
119
119
|
use: AzureFileStorageProvider
|
|
120
|
-
}).with(
|
|
120
|
+
}).with(alepha_bucket.AlephaBucket)
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
//#endregion
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["t","Alepha","DateTimeProvider","FileSystemProvider","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
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["t","Alepha","DateTimeProvider","FileSystemProvider","BlobServiceClient","$bucket","Readable","FileNotFoundError","alepha","FileStorageProvider","AlephaBucket"],"sources":["../src/providers/AzureFileStorageProvider.ts","../src/index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { Readable } from \"node:stream\";\nimport {\n BlobServiceClient,\n type BlockBlobClient,\n type ContainerClient,\n type StoragePipelineOptions,\n} from \"@azure/storage-blob\";\nimport {\n $env,\n $hook,\n $inject,\n Alepha,\n type FileLike,\n type Static,\n t,\n} from \"alepha\";\nimport {\n $bucket,\n FileNotFoundError,\n type FileStorageProvider,\n} from \"alepha/bucket\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { FileSystemProvider } from \"alepha/file\";\nimport { $logger } from \"alepha/logger\";\n\nconst envSchema = t.object({\n AZ_STORAGE_CONNECTION_STRING: t.string(),\n});\n\ndeclare module \"alepha\" {\n interface 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 protected readonly log = $logger();\n protected readonly env = $env(envSchema);\n protected readonly alepha = $inject(Alepha);\n protected readonly time = $inject(DateTimeProvider);\n protected readonly fileSystem = $inject(FileSystemProvider);\n protected readonly containers: Record<string, ContainerClient> = {};\n protected readonly blobServiceClient: BlobServiceClient;\n\n public readonly options: StoragePipelineOptions = {};\n\n constructor() {\n this.blobServiceClient = BlobServiceClient.fromConnectionString(\n this.env.AZ_STORAGE_CONNECTION_STRING,\n this.options,\n );\n }\n\n protected readonly onStart = $hook({\n on: \"start\",\n handler: async () => {\n for (const bucket of this.alepha.descriptors($bucket)) {\n if (bucket.provider !== this) {\n continue;\n }\n\n const containerName = this.convertName(bucket.name);\n\n this.log.debug(`Prepare container '${containerName}' ...`);\n\n if (!this.containers[containerName]) {\n this.containers[containerName] =\n await this.createContainerClient(containerName);\n }\n\n this.log.info(`Container '${bucket.name}' OK`);\n }\n },\n });\n\n public convertName(name: string): string {\n // Azure Blob Storage does not allow uppercase letters in container names\n return name.replaceAll(\"/\", \"-\").toLowerCase();\n }\n\n public async upload(\n bucketName: string,\n file: FileLike,\n fileId?: string,\n ): Promise<string> {\n fileId ??= this.createId();\n\n this.log.trace(\n `Uploading file '${file.name}' to bucket '${bucketName}' with id '${fileId}'...`,\n );\n\n const block = this.getBlock(bucketName, fileId);\n\n const metadata = {\n name: file.name,\n type: file.type,\n };\n\n if (file.filepath) {\n await block.uploadFile(file.filepath, {\n metadata,\n blobHTTPHeaders: {\n blobContentType: file.type,\n },\n });\n } else if (file.size > 0) {\n await block.uploadData(await file.arrayBuffer(), {\n metadata,\n blobHTTPHeaders: {\n blobContentType: file.type,\n },\n });\n } else {\n await block.uploadStream(\n Readable.from(file.stream()),\n file.size || undefined,\n 5,\n {\n metadata,\n blobHTTPHeaders: {\n blobContentType: file.type,\n },\n },\n );\n }\n\n return fileId;\n }\n\n public async download(bucketName: string, fileId: string): Promise<FileLike> {\n this.log.trace(\n `Downloading file '${fileId}' from bucket '${bucketName}'...`,\n );\n const block = this.getBlock(bucketName, fileId);\n\n const blob = await block.download().catch((error) => {\n if (error instanceof Error) {\n throw new FileNotFoundError(\"Error downloading file\", { cause: error });\n }\n\n throw error;\n });\n\n if (!blob.readableStreamBody) {\n throw new FileNotFoundError(\"File not found - empty stream body\");\n }\n\n return this.fileSystem.createFile({\n stream: blob.readableStreamBody,\n ...blob.metadata,\n size: blob.contentLength,\n });\n }\n\n public async exists(bucketName: string, fileId: string): Promise<boolean> {\n this.log.trace(\n `Checking existence of file '${fileId}' in bucket '${bucketName}'...`,\n );\n return await this.getBlock(bucketName, fileId).exists();\n }\n\n public async delete(bucketName: string, fileId: string): Promise<void> {\n this.log.trace(`Deleting file '${fileId}' from bucket '${bucketName}'...`);\n try {\n await this.getBlock(bucketName, fileId).delete();\n } catch (error) {\n if (error instanceof Error) {\n throw new FileNotFoundError(\"Error deleting file\", { cause: error });\n }\n throw error;\n }\n }\n\n public getBlock(container: string, fileId: string): BlockBlobClient {\n const containerName = this.convertName(container);\n\n if (!this.containers[containerName]) {\n throw new FileNotFoundError(\n `File '${fileId}' not found - container '${container}' does not exists`,\n );\n }\n\n return this.containers[containerName].getBlockBlobClient(fileId);\n }\n\n protected async createContainerClient(\n name: string,\n ): Promise<ContainerClient> {\n const container = this.blobServiceClient.getContainerClient(name);\n\n await this.time.deadline(\n (abortSignal) => container.createIfNotExists({ abortSignal }),\n [5, \"seconds\"],\n );\n\n return container;\n }\n\n protected createId(): string {\n return randomUUID();\n }\n}\n","import { $module } from \"alepha\";\nimport { AlephaBucket, FileStorageProvider } from \"alepha/bucket\";\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 name: \"alepha.bucket.azure\",\n services: [AzureFileStorageProvider],\n register: (alepha) =>\n alepha\n .with({\n optional: true,\n provide: FileStorageProvider,\n use: AzureFileStorageProvider,\n })\n .with(AlephaBucket),\n});\n"],"mappings":";;;;;;;;;;AA0BA,MAAM,YAAYA,SAAE,OAAO,EACzB,8BAA8BA,SAAE,QAAQ,EACzC,CAAC;;;;AASF,IAAa,2BAAb,MAAqE;CACnE,AAAmB,kCAAe;CAClC,AAAmB,uBAAW,UAAU;CACxC,AAAmB,6BAAiBC,cAAO;CAC3C,AAAmB,2BAAeC,iCAAiB;CACnD,AAAmB,iCAAqBC,+BAAmB;CAC3D,AAAmB,aAA8C,EAAE;CACnE,AAAmB;CAEnB,AAAgB,UAAkC,EAAE;CAEpD,cAAc;AACZ,OAAK,oBAAoBC,uCAAkB,qBACzC,KAAK,IAAI,8BACT,KAAK,QACN;;CAGH,AAAmB,4BAAgB;EACjC,IAAI;EACJ,SAAS,YAAY;AACnB,QAAK,MAAM,UAAU,KAAK,OAAO,YAAYC,sBAAQ,EAAE;AACrD,QAAI,OAAO,aAAa,KACtB;IAGF,MAAM,gBAAgB,KAAK,YAAY,OAAO,KAAK;AAEnD,SAAK,IAAI,MAAM,sBAAsB,cAAc,OAAO;AAE1D,QAAI,CAAC,KAAK,WAAW,eACnB,MAAK,WAAW,iBACd,MAAM,KAAK,sBAAsB,cAAc;AAGnD,SAAK,IAAI,KAAK,cAAc,OAAO,KAAK,MAAM;;;EAGnD,CAAC;CAEF,AAAO,YAAY,MAAsB;AAEvC,SAAO,KAAK,WAAW,KAAK,IAAI,CAAC,aAAa;;CAGhD,MAAa,OACX,YACA,MACA,QACiB;AACjB,aAAW,KAAK,UAAU;AAE1B,OAAK,IAAI,MACP,mBAAmB,KAAK,KAAK,eAAe,WAAW,aAAa,OAAO,MAC5E;EAED,MAAM,QAAQ,KAAK,SAAS,YAAY,OAAO;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,EAAE,OAAO,OAAO,CAAC;AAEtE,SAAM;;;CAIV,AAAO,SAAS,WAAmB,QAAiC;EAClE,MAAM,gBAAgB,KAAK,YAAY,UAAU;AAEjD,MAAI,CAAC,KAAK,WAAW,eACnB,OAAM,IAAIA,gCACR,SAAS,OAAO,2BAA2B,UAAU,mBACtD;AAGH,SAAO,KAAK,WAAW,eAAe,mBAAmB,OAAO;;CAGlE,MAAgB,sBACd,MAC0B;EAC1B,MAAM,YAAY,KAAK,kBAAkB,mBAAmB,KAAK;AAEjE,QAAM,KAAK,KAAK,UACb,gBAAgB,UAAU,kBAAkB,EAAE,aAAa,CAAC,EAC7D,CAAC,GAAG,UAAU,CACf;AAED,SAAO;;CAGT,AAAU,WAAmB;AAC3B,sCAAmB;;;;;;;;;;;;AC3LvB,MAAa,wCAA4B;CACvC,MAAM;CACN,UAAU,CAAC,yBAAyB;CACpC,WAAW,aACTC,SACG,KAAK;EACJ,UAAU;EACV,SAASC;EACT,KAAK;EACN,CAAC,CACD,KAAKC,2BAAa;CACxB,CAAC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { Alepha, FileLike, Static } from "
|
|
3
|
-
import * as
|
|
4
|
-
import { FileStorageProvider } from "@alepha/bucket";
|
|
5
|
-
import { DateTimeProvider } from "@alepha/datetime";
|
|
6
|
-
import { FileSystemProvider } from "@alepha/file";
|
|
1
|
+
import * as alepha1 from "alepha";
|
|
2
|
+
import { Alepha, FileLike, Static } from "alepha";
|
|
3
|
+
import * as alepha_logger0 from "alepha/logger";
|
|
7
4
|
import { BlobServiceClient, BlockBlobClient, ContainerClient, StoragePipelineOptions } from "@azure/storage-blob";
|
|
5
|
+
import { FileStorageProvider } from "alepha/bucket";
|
|
6
|
+
import { DateTimeProvider } from "alepha/datetime";
|
|
7
|
+
import { FileSystemProvider } from "alepha/file";
|
|
8
8
|
|
|
9
9
|
//#region src/providers/AzureFileStorageProvider.d.ts
|
|
10
|
-
declare const envSchema:
|
|
11
|
-
AZ_STORAGE_CONNECTION_STRING:
|
|
10
|
+
declare const envSchema: alepha1.TObject<{
|
|
11
|
+
AZ_STORAGE_CONNECTION_STRING: alepha1.TString;
|
|
12
12
|
}>;
|
|
13
|
-
declare module "
|
|
13
|
+
declare module "alepha" {
|
|
14
14
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Azure Blog Storage implementation of File Storage Provider.
|
|
18
18
|
*/
|
|
19
19
|
declare class AzureFileStorageProvider implements FileStorageProvider {
|
|
20
|
-
protected readonly log:
|
|
20
|
+
protected readonly log: alepha_logger0.Logger;
|
|
21
21
|
protected readonly env: {
|
|
22
22
|
AZ_STORAGE_CONNECTION_STRING: string;
|
|
23
23
|
};
|
|
@@ -28,7 +28,7 @@ declare class AzureFileStorageProvider implements FileStorageProvider {
|
|
|
28
28
|
protected readonly blobServiceClient: BlobServiceClient;
|
|
29
29
|
readonly options: StoragePipelineOptions;
|
|
30
30
|
constructor();
|
|
31
|
-
protected readonly onStart:
|
|
31
|
+
protected readonly onStart: alepha1.HookDescriptor<"start">;
|
|
32
32
|
convertName(name: string): string;
|
|
33
33
|
upload(bucketName: string, file: FileLike, fileId?: string): Promise<string>;
|
|
34
34
|
download(bucketName: string, fileId: string): Promise<FileLike>;
|
|
@@ -46,7 +46,7 @@ declare class AzureFileStorageProvider implements FileStorageProvider {
|
|
|
46
46
|
* @see {@link AzureFileStorageProvider}
|
|
47
47
|
* @module alepha.bucket.azure
|
|
48
48
|
*/
|
|
49
|
-
declare const AlephaBucketAzure:
|
|
49
|
+
declare const AlephaBucketAzure: alepha1.Service<alepha1.Module>;
|
|
50
50
|
//#endregion
|
|
51
51
|
export { AlephaBucketAzure, AzureFileStorageProvider };
|
|
52
52
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/providers/AzureFileStorageProvider.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cA0BM,WAEJ,
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/providers/AzureFileStorageProvider.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cA0BM,WAEJ,OAAA,CAFa;gCAEb,OAAA,CAAA;;;EAFI,UAAA,GAEJ,SAGsB,OAHtB,CAG8B,MAH9B,CAAA,OAG4C,SAL/B,CAAA,CAAA,CAAA,CAAA;;;;;AAKS,cAMX,wBAAA,YAAoC,mBANzB,CAAA;EAAO,mBAAA,GAAA,EAMO,cAAA,CACd,MAPO;EAAA,mBAAA,GAAA,EAAA;IAAA,4BAAA,EAAA,MAAA;EAMlB,CAAA;EAAyB,mBACd,MAAA,EAEG,MAFH;EAEG,mBAAA,IAAA,EACF,gBADE;EACF,mBAAA,UAAA,EACM,kBADN;EACM,mBAAA,UAAA,EACE,MADF,CAAA,MAAA,EACiB,eADjB,CAAA;EACiB,mBAAA,iBAAA,EACR,iBADQ;EAAf,SAAA,OAAA,EAGN,sBAHM;EACO,WAAA,CAAA;EAEb,mBAAA,OAAA,EAAsB,OAAA,CASrB,cATD,CAAA,OAAA,CAAA;EAAsB,WASrB,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EA6BlB,MAAA,CAAA,UAAA,EAAA,MAAA,EAAA,IAAA,EAAA,QAAA,EAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAEL,OAFK,CAAA,MAAA,CAAA;EAEL,QAAA,CAAA,UAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EA6CwD,OA7CxD,CA6CgE,QA7ChE,CAAA;EA6CgE,MAAA,CAAA,UAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAyBV,OAzBU,CAAA,OAAA,CAAA;EAAR,MAAA,CAAA,UAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAgCF,OAhCE,CAAA,IAAA,CAAA;EAyBF,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAmBL,eAnBK;EAOA,UAAA,qBAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EA0BtD,OA1BsD,CA0B9C,eA1B8C,CAAA;EAYL,UAAA,QAAA,CAAA,CAAA,EAAA,MAAA;;;;;;;;;;cCjKzC,mBAAiB,OAAA,CAAA,QAW5B,OAAA,CAX4B,MAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { DateTimeProvider } from "@alepha/datetime";
|
|
5
|
-
import { FileSystemProvider } from "@alepha/file";
|
|
6
|
-
import * as _alepha_logger0 from "@alepha/logger";
|
|
1
|
+
import * as alepha1 from "alepha";
|
|
2
|
+
import { Alepha, FileLike, Static } from "alepha";
|
|
3
|
+
import { FileStorageProvider } from "alepha/bucket";
|
|
7
4
|
import { BlobServiceClient, BlockBlobClient, ContainerClient, StoragePipelineOptions } from "@azure/storage-blob";
|
|
5
|
+
import { DateTimeProvider } from "alepha/datetime";
|
|
6
|
+
import { FileSystemProvider } from "alepha/file";
|
|
7
|
+
import * as alepha_logger0 from "alepha/logger";
|
|
8
8
|
|
|
9
9
|
//#region src/providers/AzureFileStorageProvider.d.ts
|
|
10
|
-
declare const envSchema:
|
|
11
|
-
AZ_STORAGE_CONNECTION_STRING:
|
|
10
|
+
declare const envSchema: alepha1.TObject<{
|
|
11
|
+
AZ_STORAGE_CONNECTION_STRING: alepha1.TString;
|
|
12
12
|
}>;
|
|
13
|
-
declare module "
|
|
13
|
+
declare module "alepha" {
|
|
14
14
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Azure Blog Storage implementation of File Storage Provider.
|
|
18
18
|
*/
|
|
19
19
|
declare class AzureFileStorageProvider implements FileStorageProvider {
|
|
20
|
-
protected readonly log:
|
|
20
|
+
protected readonly log: alepha_logger0.Logger;
|
|
21
21
|
protected readonly env: {
|
|
22
22
|
AZ_STORAGE_CONNECTION_STRING: string;
|
|
23
23
|
};
|
|
@@ -28,7 +28,7 @@ declare class AzureFileStorageProvider implements FileStorageProvider {
|
|
|
28
28
|
protected readonly blobServiceClient: BlobServiceClient;
|
|
29
29
|
readonly options: StoragePipelineOptions;
|
|
30
30
|
constructor();
|
|
31
|
-
protected readonly onStart:
|
|
31
|
+
protected readonly onStart: alepha1.HookDescriptor<"start">;
|
|
32
32
|
convertName(name: string): string;
|
|
33
33
|
upload(bucketName: string, file: FileLike, fileId?: string): Promise<string>;
|
|
34
34
|
download(bucketName: string, fileId: string): Promise<FileLike>;
|
|
@@ -46,7 +46,7 @@ declare class AzureFileStorageProvider implements FileStorageProvider {
|
|
|
46
46
|
* @see {@link AzureFileStorageProvider}
|
|
47
47
|
* @module alepha.bucket.azure
|
|
48
48
|
*/
|
|
49
|
-
declare const AlephaBucketAzure:
|
|
49
|
+
declare const AlephaBucketAzure: alepha1.Service<alepha1.Module>;
|
|
50
50
|
//#endregion
|
|
51
51
|
export { AlephaBucketAzure, AzureFileStorageProvider };
|
|
52
52
|
//# 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,WAEJ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/providers/AzureFileStorageProvider.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cA0BM,WAEJ,OAAA,CAFa;gCAEb,OAAA,CAAA;;;EAFI,UAAA,GAEJ,SAGsB,OAHtB,CAG8B,MAH9B,CAAA,OAG4C,SAL/B,CAAA,CAAA,CAAA,CAAA;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|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { $
|
|
2
|
-
import { $
|
|
1
|
+
import { $env, $hook, $inject, $module, Alepha, t } from "alepha";
|
|
2
|
+
import { $bucket, AlephaBucket, FileNotFoundError, FileStorageProvider } from "alepha/bucket";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { Readable } from "node:stream";
|
|
5
|
-
import { DateTimeProvider } from "@alepha/datetime";
|
|
6
|
-
import { FileSystemProvider } from "@alepha/file";
|
|
7
|
-
import { $logger } from "@alepha/logger";
|
|
8
5
|
import { BlobServiceClient } from "@azure/storage-blob";
|
|
6
|
+
import { DateTimeProvider } from "alepha/datetime";
|
|
7
|
+
import { FileSystemProvider } from "alepha/file";
|
|
8
|
+
import { $logger } from "alepha/logger";
|
|
9
9
|
|
|
10
10
|
//#region src/providers/AzureFileStorageProvider.ts
|
|
11
11
|
const envSchema = t.object({ AZ_STORAGE_CONNECTION_STRING: t.string() });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/providers/AzureFileStorageProvider.ts","../src/index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { Readable } from \"node:stream\";\nimport {\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/providers/AzureFileStorageProvider.ts","../src/index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { Readable } from \"node:stream\";\nimport {\n BlobServiceClient,\n type BlockBlobClient,\n type ContainerClient,\n type StoragePipelineOptions,\n} from \"@azure/storage-blob\";\nimport {\n $env,\n $hook,\n $inject,\n Alepha,\n type FileLike,\n type Static,\n t,\n} from \"alepha\";\nimport {\n $bucket,\n FileNotFoundError,\n type FileStorageProvider,\n} from \"alepha/bucket\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { FileSystemProvider } from \"alepha/file\";\nimport { $logger } from \"alepha/logger\";\n\nconst envSchema = t.object({\n AZ_STORAGE_CONNECTION_STRING: t.string(),\n});\n\ndeclare module \"alepha\" {\n interface 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 protected readonly log = $logger();\n protected readonly env = $env(envSchema);\n protected readonly alepha = $inject(Alepha);\n protected readonly time = $inject(DateTimeProvider);\n protected readonly fileSystem = $inject(FileSystemProvider);\n protected readonly containers: Record<string, ContainerClient> = {};\n protected readonly blobServiceClient: BlobServiceClient;\n\n public readonly options: StoragePipelineOptions = {};\n\n constructor() {\n this.blobServiceClient = BlobServiceClient.fromConnectionString(\n this.env.AZ_STORAGE_CONNECTION_STRING,\n this.options,\n );\n }\n\n protected readonly onStart = $hook({\n on: \"start\",\n handler: async () => {\n for (const bucket of this.alepha.descriptors($bucket)) {\n if (bucket.provider !== this) {\n continue;\n }\n\n const containerName = this.convertName(bucket.name);\n\n this.log.debug(`Prepare container '${containerName}' ...`);\n\n if (!this.containers[containerName]) {\n this.containers[containerName] =\n await this.createContainerClient(containerName);\n }\n\n this.log.info(`Container '${bucket.name}' OK`);\n }\n },\n });\n\n public convertName(name: string): string {\n // Azure Blob Storage does not allow uppercase letters in container names\n return name.replaceAll(\"/\", \"-\").toLowerCase();\n }\n\n public async upload(\n bucketName: string,\n file: FileLike,\n fileId?: string,\n ): Promise<string> {\n fileId ??= this.createId();\n\n this.log.trace(\n `Uploading file '${file.name}' to bucket '${bucketName}' with id '${fileId}'...`,\n );\n\n const block = this.getBlock(bucketName, fileId);\n\n const metadata = {\n name: file.name,\n type: file.type,\n };\n\n if (file.filepath) {\n await block.uploadFile(file.filepath, {\n metadata,\n blobHTTPHeaders: {\n blobContentType: file.type,\n },\n });\n } else if (file.size > 0) {\n await block.uploadData(await file.arrayBuffer(), {\n metadata,\n blobHTTPHeaders: {\n blobContentType: file.type,\n },\n });\n } else {\n await block.uploadStream(\n Readable.from(file.stream()),\n file.size || undefined,\n 5,\n {\n metadata,\n blobHTTPHeaders: {\n blobContentType: file.type,\n },\n },\n );\n }\n\n return fileId;\n }\n\n public async download(bucketName: string, fileId: string): Promise<FileLike> {\n this.log.trace(\n `Downloading file '${fileId}' from bucket '${bucketName}'...`,\n );\n const block = this.getBlock(bucketName, fileId);\n\n const blob = await block.download().catch((error) => {\n if (error instanceof Error) {\n throw new FileNotFoundError(\"Error downloading file\", { cause: error });\n }\n\n throw error;\n });\n\n if (!blob.readableStreamBody) {\n throw new FileNotFoundError(\"File not found - empty stream body\");\n }\n\n return this.fileSystem.createFile({\n stream: blob.readableStreamBody,\n ...blob.metadata,\n size: blob.contentLength,\n });\n }\n\n public async exists(bucketName: string, fileId: string): Promise<boolean> {\n this.log.trace(\n `Checking existence of file '${fileId}' in bucket '${bucketName}'...`,\n );\n return await this.getBlock(bucketName, fileId).exists();\n }\n\n public async delete(bucketName: string, fileId: string): Promise<void> {\n this.log.trace(`Deleting file '${fileId}' from bucket '${bucketName}'...`);\n try {\n await this.getBlock(bucketName, fileId).delete();\n } catch (error) {\n if (error instanceof Error) {\n throw new FileNotFoundError(\"Error deleting file\", { cause: error });\n }\n throw error;\n }\n }\n\n public getBlock(container: string, fileId: string): BlockBlobClient {\n const containerName = this.convertName(container);\n\n if (!this.containers[containerName]) {\n throw new FileNotFoundError(\n `File '${fileId}' not found - container '${container}' does not exists`,\n );\n }\n\n return this.containers[containerName].getBlockBlobClient(fileId);\n }\n\n protected async createContainerClient(\n name: string,\n ): Promise<ContainerClient> {\n const container = this.blobServiceClient.getContainerClient(name);\n\n await this.time.deadline(\n (abortSignal) => container.createIfNotExists({ abortSignal }),\n [5, \"seconds\"],\n );\n\n return container;\n }\n\n protected createId(): string {\n return randomUUID();\n }\n}\n","import { $module } from \"alepha\";\nimport { AlephaBucket, FileStorageProvider } from \"alepha/bucket\";\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 name: \"alepha.bucket.azure\",\n services: [AzureFileStorageProvider],\n register: (alepha) =>\n alepha\n .with({\n optional: true,\n provide: FileStorageProvider,\n use: AzureFileStorageProvider,\n })\n .with(AlephaBucket),\n});\n"],"mappings":";;;;;;;;;;AA0BA,MAAM,YAAY,EAAE,OAAO,EACzB,8BAA8B,EAAE,QAAQ,EACzC,CAAC;;;;AASF,IAAa,2BAAb,MAAqE;CACnE,AAAmB,MAAM,SAAS;CAClC,AAAmB,MAAM,KAAK,UAAU;CACxC,AAAmB,SAAS,QAAQ,OAAO;CAC3C,AAAmB,OAAO,QAAQ,iBAAiB;CACnD,AAAmB,aAAa,QAAQ,mBAAmB;CAC3D,AAAmB,aAA8C,EAAE;CACnE,AAAmB;CAEnB,AAAgB,UAAkC,EAAE;CAEpD,cAAc;AACZ,OAAK,oBAAoB,kBAAkB,qBACzC,KAAK,IAAI,8BACT,KAAK,QACN;;CAGH,AAAmB,UAAU,MAAM;EACjC,IAAI;EACJ,SAAS,YAAY;AACnB,QAAK,MAAM,UAAU,KAAK,OAAO,YAAY,QAAQ,EAAE;AACrD,QAAI,OAAO,aAAa,KACtB;IAGF,MAAM,gBAAgB,KAAK,YAAY,OAAO,KAAK;AAEnD,SAAK,IAAI,MAAM,sBAAsB,cAAc,OAAO;AAE1D,QAAI,CAAC,KAAK,WAAW,eACnB,MAAK,WAAW,iBACd,MAAM,KAAK,sBAAsB,cAAc;AAGnD,SAAK,IAAI,KAAK,cAAc,OAAO,KAAK,MAAM;;;EAGnD,CAAC;CAEF,AAAO,YAAY,MAAsB;AAEvC,SAAO,KAAK,WAAW,KAAK,IAAI,CAAC,aAAa;;CAGhD,MAAa,OACX,YACA,MACA,QACiB;AACjB,aAAW,KAAK,UAAU;AAE1B,OAAK,IAAI,MAC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|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
"homepage": "https://github.com/feunard/alepha",
|
|
50
|
-
"module": "./dist/index.js",
|
|
51
|
-
"exports": {
|
|
52
|
-
".": {
|
|
53
|
-
"types": "./dist/index.d.ts",
|
|
54
|
-
"import": "./dist/index.js",
|
|
55
|
-
"require": "./dist/index.cjs"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
2
|
+
"name": "@alepha/bucket-azure",
|
|
3
|
+
"description": "Azure Blob Storage implementation for the bucket file storage.",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"alepha",
|
|
6
|
+
"bucket",
|
|
7
|
+
"file-storage",
|
|
8
|
+
"file",
|
|
9
|
+
"azure",
|
|
10
|
+
"storage-blob"
|
|
11
|
+
],
|
|
12
|
+
"author": "Feunard",
|
|
13
|
+
"version": "0.12.0",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.0.0"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@azure/storage-blob": "^12.29.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"alepha": "0.12.0",
|
|
30
|
+
"tsdown": "^0.16.4",
|
|
31
|
+
"vitest": "^4.0.9"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"alepha": "0.12.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"lint": "alepha lint",
|
|
38
|
+
"typecheck": "alepha typecheck",
|
|
39
|
+
"test": "alepha test",
|
|
40
|
+
"build": "tsdown -c=../../tsdown.config.ts"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/feunard/alepha.git"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/feunard/alepha",
|
|
47
|
+
"module": "./dist/index.js"
|
|
58
48
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { $module } from "alepha";
|
|
2
|
+
import { AlephaBucket, FileStorageProvider } from "alepha/bucket";
|
|
3
3
|
import { AzureFileStorageProvider } from "./providers/AzureFileStorageProvider.ts";
|
|
4
4
|
|
|
5
5
|
export * from "./providers/AzureFileStorageProvider.ts";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { Readable } from "node:stream";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type
|
|
7
|
-
|
|
4
|
+
BlobServiceClient,
|
|
5
|
+
type BlockBlobClient,
|
|
6
|
+
type ContainerClient,
|
|
7
|
+
type StoragePipelineOptions,
|
|
8
|
+
} from "@azure/storage-blob";
|
|
8
9
|
import {
|
|
9
10
|
$env,
|
|
10
11
|
$hook,
|
|
@@ -13,22 +14,21 @@ import {
|
|
|
13
14
|
type FileLike,
|
|
14
15
|
type Static,
|
|
15
16
|
t,
|
|
16
|
-
} from "
|
|
17
|
-
import { DateTimeProvider } from "@alepha/datetime";
|
|
18
|
-
import { FileSystemProvider } from "@alepha/file";
|
|
19
|
-
import { $logger } from "@alepha/logger";
|
|
17
|
+
} from "alepha";
|
|
20
18
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
} from "
|
|
19
|
+
$bucket,
|
|
20
|
+
FileNotFoundError,
|
|
21
|
+
type FileStorageProvider,
|
|
22
|
+
} from "alepha/bucket";
|
|
23
|
+
import { DateTimeProvider } from "alepha/datetime";
|
|
24
|
+
import { FileSystemProvider } from "alepha/file";
|
|
25
|
+
import { $logger } from "alepha/logger";
|
|
26
26
|
|
|
27
27
|
const envSchema = t.object({
|
|
28
28
|
AZ_STORAGE_CONNECTION_STRING: t.string(),
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
declare module "
|
|
31
|
+
declare module "alepha" {
|
|
32
32
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
33
33
|
}
|
|
34
34
|
|