@twin.org/blob-storage-connector-azure 0.0.1-next.16 → 0.0.1-next.18
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/cjs/index.cjs +3 -25
- package/dist/esm/index.mjs +3 -25
- package/dist/types/azureBlobStorageConnector.d.ts +2 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/IAzureBlobStorageConnectorConstructorOptions.d.ts +10 -0
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/AzureBlobStorageConnector.md +15 -9
- package/docs/reference/index.md +1 -0
- package/docs/reference/interfaces/IAzureBlobStorageConnectorConstructorOptions.md +11 -0
- package/package.json +3 -3
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var node_stream = require('node:stream');
|
|
4
3
|
var storageBlob = require('@azure/storage-blob');
|
|
5
4
|
var core = require('@twin.org/core');
|
|
6
5
|
var crypto = require('@twin.org/crypto');
|
|
@@ -39,7 +38,6 @@ class AzureBlobStorageConnector {
|
|
|
39
38
|
/**
|
|
40
39
|
* Create a new instance of AzureBlobStorageConnector.
|
|
41
40
|
* @param options The options for the connector.
|
|
42
|
-
* @param options.config The configuration for the connector.
|
|
43
41
|
*/
|
|
44
42
|
constructor(options) {
|
|
45
43
|
core.Guards.object(this.CLASS_NAME, "options", options);
|
|
@@ -114,18 +112,7 @@ class AzureBlobStorageConnector {
|
|
|
114
112
|
try {
|
|
115
113
|
const id = core.Converter.bytesToHex(crypto.Sha256.sum256(blob));
|
|
116
114
|
const blockBlobClient = this._azureContainerClient.getBlockBlobClient(id);
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Reads data from the blob and pushes it into the stream.
|
|
120
|
-
* This method is automatically called when the stream is read from.
|
|
121
|
-
* It pushes the blob data and signals the end of the stream.
|
|
122
|
-
*/
|
|
123
|
-
read() {
|
|
124
|
-
this.push(blob);
|
|
125
|
-
this.push(null);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
await blockBlobClient.uploadStream(readableStream);
|
|
115
|
+
await blockBlobClient.uploadData(blob);
|
|
129
116
|
return `blob:${new core.Urn(AzureBlobStorageConnector.NAMESPACE, id).toString()}`;
|
|
130
117
|
}
|
|
131
118
|
catch (err) {
|
|
@@ -149,17 +136,8 @@ class AzureBlobStorageConnector {
|
|
|
149
136
|
try {
|
|
150
137
|
const key = urnParsed.namespaceSpecific(1);
|
|
151
138
|
const blobClient = this._azureContainerClient.getBlobClient(key);
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
const readableStream = downloadResponse.readableStreamBody;
|
|
155
|
-
const chunks = [];
|
|
156
|
-
for await (const chunk of readableStream) {
|
|
157
|
-
chunks.push(chunk);
|
|
158
|
-
}
|
|
159
|
-
const buffer = Buffer.concat(chunks);
|
|
160
|
-
return new Uint8Array(buffer);
|
|
161
|
-
}
|
|
162
|
-
return undefined;
|
|
139
|
+
const buffer = await blobClient.downloadToBuffer();
|
|
140
|
+
return new Uint8Array(buffer);
|
|
163
141
|
}
|
|
164
142
|
catch (err) {
|
|
165
143
|
throw new core.GeneralError(this.CLASS_NAME, "getBlobFailed", {
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Readable } from 'node:stream';
|
|
2
1
|
import { BlobServiceClient, StorageSharedKeyCredential } from '@azure/storage-blob';
|
|
3
2
|
import { Guards, BaseError, Converter, Urn, GeneralError } from '@twin.org/core';
|
|
4
3
|
import { Sha256 } from '@twin.org/crypto';
|
|
@@ -37,7 +36,6 @@ class AzureBlobStorageConnector {
|
|
|
37
36
|
/**
|
|
38
37
|
* Create a new instance of AzureBlobStorageConnector.
|
|
39
38
|
* @param options The options for the connector.
|
|
40
|
-
* @param options.config The configuration for the connector.
|
|
41
39
|
*/
|
|
42
40
|
constructor(options) {
|
|
43
41
|
Guards.object(this.CLASS_NAME, "options", options);
|
|
@@ -112,18 +110,7 @@ class AzureBlobStorageConnector {
|
|
|
112
110
|
try {
|
|
113
111
|
const id = Converter.bytesToHex(Sha256.sum256(blob));
|
|
114
112
|
const blockBlobClient = this._azureContainerClient.getBlockBlobClient(id);
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Reads data from the blob and pushes it into the stream.
|
|
118
|
-
* This method is automatically called when the stream is read from.
|
|
119
|
-
* It pushes the blob data and signals the end of the stream.
|
|
120
|
-
*/
|
|
121
|
-
read() {
|
|
122
|
-
this.push(blob);
|
|
123
|
-
this.push(null);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
await blockBlobClient.uploadStream(readableStream);
|
|
113
|
+
await blockBlobClient.uploadData(blob);
|
|
127
114
|
return `blob:${new Urn(AzureBlobStorageConnector.NAMESPACE, id).toString()}`;
|
|
128
115
|
}
|
|
129
116
|
catch (err) {
|
|
@@ -147,17 +134,8 @@ class AzureBlobStorageConnector {
|
|
|
147
134
|
try {
|
|
148
135
|
const key = urnParsed.namespaceSpecific(1);
|
|
149
136
|
const blobClient = this._azureContainerClient.getBlobClient(key);
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
const readableStream = downloadResponse.readableStreamBody;
|
|
153
|
-
const chunks = [];
|
|
154
|
-
for await (const chunk of readableStream) {
|
|
155
|
-
chunks.push(chunk);
|
|
156
|
-
}
|
|
157
|
-
const buffer = Buffer.concat(chunks);
|
|
158
|
-
return new Uint8Array(buffer);
|
|
159
|
-
}
|
|
160
|
-
return undefined;
|
|
137
|
+
const buffer = await blobClient.downloadToBuffer();
|
|
138
|
+
return new Uint8Array(buffer);
|
|
161
139
|
}
|
|
162
140
|
catch (err) {
|
|
163
141
|
throw new GeneralError(this.CLASS_NAME, "getBlobFailed", {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IBlobStorageConnector } from "@twin.org/blob-storage-models";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IAzureBlobStorageConnectorConstructorOptions } from "./models/IAzureBlobStorageConnectorConstructorOptions";
|
|
3
3
|
/**
|
|
4
4
|
* Class for performing blob storage operations on Azure.
|
|
5
5
|
* See https://learn.microsoft.com/en-us/azure/storage/common/storage-samples-javascript?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json for more information.
|
|
@@ -16,11 +16,8 @@ export declare class AzureBlobStorageConnector implements IBlobStorageConnector
|
|
|
16
16
|
/**
|
|
17
17
|
* Create a new instance of AzureBlobStorageConnector.
|
|
18
18
|
* @param options The options for the connector.
|
|
19
|
-
* @param options.config The configuration for the connector.
|
|
20
19
|
*/
|
|
21
|
-
constructor(options:
|
|
22
|
-
config: IAzureBlobStorageConnectorConfig;
|
|
23
|
-
});
|
|
20
|
+
constructor(options: IAzureBlobStorageConnectorConstructorOptions);
|
|
24
21
|
/**
|
|
25
22
|
* Bootstrap the component by creating and initializing any resources it needs.
|
|
26
23
|
* @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IAzureBlobStorageConnectorConfig } from "./IAzureBlobStorageConnectorConfig";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the Azure Blob Storage Connector constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IAzureBlobStorageConnectorConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The configuration for the connector.
|
|
8
|
+
*/
|
|
9
|
+
config: IAzureBlobStorageConnectorConfig;
|
|
10
|
+
}
|
package/docs/changelog.md
CHANGED
|
@@ -17,13 +17,11 @@ Create a new instance of AzureBlobStorageConnector.
|
|
|
17
17
|
|
|
18
18
|
#### Parameters
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
##### options
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
• **options.config**: [`IAzureBlobStorageConnectorConfig`](../interfaces/IAzureBlobStorageConnectorConfig.md)
|
|
22
|
+
[`IAzureBlobStorageConnectorConstructorOptions`](../interfaces/IAzureBlobStorageConnectorConstructorOptions.md)
|
|
25
23
|
|
|
26
|
-
The
|
|
24
|
+
The options for the connector.
|
|
27
25
|
|
|
28
26
|
#### Returns
|
|
29
27
|
|
|
@@ -59,7 +57,9 @@ Bootstrap the component by creating and initializing any resources it needs.
|
|
|
59
57
|
|
|
60
58
|
#### Parameters
|
|
61
59
|
|
|
62
|
-
|
|
60
|
+
##### nodeLoggingConnectorType?
|
|
61
|
+
|
|
62
|
+
`string`
|
|
63
63
|
|
|
64
64
|
The node logging connector type, defaults to "node-logging".
|
|
65
65
|
|
|
@@ -83,7 +83,9 @@ Set the blob.
|
|
|
83
83
|
|
|
84
84
|
#### Parameters
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
##### blob
|
|
87
|
+
|
|
88
|
+
`Uint8Array`
|
|
87
89
|
|
|
88
90
|
The data for the blob.
|
|
89
91
|
|
|
@@ -107,7 +109,9 @@ Get the blob.
|
|
|
107
109
|
|
|
108
110
|
#### Parameters
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
##### id
|
|
113
|
+
|
|
114
|
+
`string`
|
|
111
115
|
|
|
112
116
|
The id of the blob to get in urn format.
|
|
113
117
|
|
|
@@ -131,7 +135,9 @@ Remove the blob.
|
|
|
131
135
|
|
|
132
136
|
#### Parameters
|
|
133
137
|
|
|
134
|
-
|
|
138
|
+
##### id
|
|
139
|
+
|
|
140
|
+
`string`
|
|
135
141
|
|
|
136
142
|
The id of the blob to remove in urn format.
|
|
137
143
|
|
package/docs/reference/index.md
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Interface: IAzureBlobStorageConnectorConstructorOptions
|
|
2
|
+
|
|
3
|
+
Options for the Azure Blob Storage Connector constructor.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### config
|
|
8
|
+
|
|
9
|
+
> **config**: [`IAzureBlobStorageConnectorConfig`](IAzureBlobStorageConnectorConfig.md)
|
|
10
|
+
|
|
11
|
+
The configuration for the connector.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/blob-storage-connector-azure",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.18",
|
|
4
4
|
"description": "Blob Storage connector implementation using Azure",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@azure/storage-blob": "^12.
|
|
18
|
-
"@twin.org/blob-storage-models": "0.0.1-next.
|
|
17
|
+
"@azure/storage-blob": "^12.26.0",
|
|
18
|
+
"@twin.org/blob-storage-models": "0.0.1-next.18",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
20
|
"@twin.org/crypto": "next",
|
|
21
21
|
"@twin.org/logging-models": "next",
|