@rsdk/nats.object-storage 5.11.0-next.0 → 5.11.0-next.10
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.
|
@@ -12,6 +12,18 @@ export declare class NatsObjectStorage {
|
|
|
12
12
|
delete(key: string): Promise<PurgeResponse>;
|
|
13
13
|
/**
|
|
14
14
|
* Загружает объект в хранилище
|
|
15
|
+
* @overload
|
|
16
|
+
* Загрузка из Buffer - конвертация выполняется автоматически
|
|
17
|
+
*/
|
|
18
|
+
put(meta: ObjectStoreMeta, buffer: Buffer, opts?: ObjectStorePutOpts): Promise<ObjectInfo>;
|
|
19
|
+
/**
|
|
20
|
+
* @overload
|
|
21
|
+
* Загрузка из Node.js Readable stream - конвертация выполняется автоматически
|
|
22
|
+
*/
|
|
23
|
+
put(meta: ObjectStoreMeta, stream: NodeJS.ReadableStream, opts?: ObjectStorePutOpts): Promise<ObjectInfo>;
|
|
24
|
+
/**
|
|
25
|
+
* @overload
|
|
26
|
+
* Загрузка из Web ReadableStream
|
|
15
27
|
*/
|
|
16
28
|
put(meta: ObjectStoreMeta, rs: ReadableStream<Uint8Array>, opts?: ObjectStorePutOpts): Promise<ObjectInfo>;
|
|
17
29
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NatsObjectStorage = void 0;
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
4
5
|
class NatsObjectStorage {
|
|
5
6
|
storage;
|
|
6
7
|
constructor(storage) {
|
|
@@ -18,11 +19,21 @@ class NatsObjectStorage {
|
|
|
18
19
|
delete(key) {
|
|
19
20
|
return this.storage.delete(key);
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
put(meta, data, opts) {
|
|
23
|
+
let readableStream;
|
|
24
|
+
if (Buffer.isBuffer(data)) {
|
|
25
|
+
// Конвертация Buffer в Web ReadableStream
|
|
26
|
+
readableStream = node_stream_1.Readable.toWeb(node_stream_1.Readable.from(data));
|
|
27
|
+
}
|
|
28
|
+
else if (data instanceof ReadableStream) {
|
|
29
|
+
// Уже Web ReadableStream
|
|
30
|
+
readableStream = data;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// Node.js ReadableStream - конвертация в Web ReadableStream
|
|
34
|
+
readableStream = node_stream_1.Readable.toWeb(data);
|
|
35
|
+
}
|
|
36
|
+
return this.storage.put(meta, readableStream, opts);
|
|
26
37
|
}
|
|
27
38
|
/**
|
|
28
39
|
* Возвращает массив всех объектов в хранилище
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nats-object-storage.js","sourceRoot":"","sources":["../src/nats-object-storage.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"nats-object-storage.js","sourceRoot":"","sources":["../src/nats-object-storage.ts"],"names":[],"mappings":";;;AAQA,6CAAuC;AAEvC,MAAa,iBAAiB;IACC;IAA7B,YAA6B,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAErD;;OAEG;IACI,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,GAAW;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAgCM,GAAG,CACR,IAAqB,EACrB,IAAiE,EACjE,IAAyB;QAEzB,IAAI,cAA0C,CAAC;QAE/C,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,0CAA0C;YAC1C,cAAc,GAAG,sBAAQ,CAAC,KAAK,CAAC,sBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACvD,CAAC;aAAM,IAAI,IAAI,YAAY,cAAc,EAAE,CAAC;YAC1C,yBAAyB;YACzB,cAAc,GAAG,IAAI,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,4DAA4D;YAC5D,cAAc,GAAG,sBAAQ,CAAC,KAAK,CAAC,IAAgB,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACI,aAAa;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAnFD,8CAmFC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/nats.object-storage",
|
|
3
|
-
"version": "5.11.0-next.
|
|
3
|
+
"version": "5.11.0-next.10",
|
|
4
4
|
"description": "Nats NestJS object storage",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "Apache License 2.0",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"nats": "~2.28.2"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@nestjs/common": "^10.
|
|
20
|
-
"@nestjs/core": "^10.
|
|
21
|
-
"@nestjs/microservices": "^10.
|
|
19
|
+
"@nestjs/common": "^10.4.20",
|
|
20
|
+
"@nestjs/core": "^10.4.20",
|
|
21
|
+
"@nestjs/microservices": "^10.4.20",
|
|
22
22
|
"@opentelemetry/api": "^1.9.0",
|
|
23
23
|
"@rsdk/actx": "*",
|
|
24
24
|
"@rsdk/autodoc.protocol": "*",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"rxjs": "^7.1.0"
|
|
36
36
|
},
|
|
37
37
|
"nx": {},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "de767781fa92c9a3db87d8aa982aa682cb6375b6"
|
|
39
39
|
}
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
ObjectStorePutOpts,
|
|
7
7
|
PurgeResponse,
|
|
8
8
|
} from 'nats';
|
|
9
|
+
import { Readable } from 'node:stream';
|
|
9
10
|
|
|
10
11
|
export class NatsObjectStorage {
|
|
11
12
|
constructor(private readonly storage: ObjectStore) {}
|
|
@@ -26,13 +27,53 @@ export class NatsObjectStorage {
|
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Загружает объект в хранилище
|
|
30
|
+
* @overload
|
|
31
|
+
* Загрузка из Buffer - конвертация выполняется автоматически
|
|
32
|
+
*/
|
|
33
|
+
public put(
|
|
34
|
+
meta: ObjectStoreMeta,
|
|
35
|
+
buffer: Buffer,
|
|
36
|
+
opts?: ObjectStorePutOpts,
|
|
37
|
+
): Promise<ObjectInfo>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @overload
|
|
41
|
+
* Загрузка из Node.js Readable stream - конвертация выполняется автоматически
|
|
42
|
+
*/
|
|
43
|
+
public put(
|
|
44
|
+
meta: ObjectStoreMeta,
|
|
45
|
+
stream: NodeJS.ReadableStream,
|
|
46
|
+
opts?: ObjectStorePutOpts,
|
|
47
|
+
): Promise<ObjectInfo>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @overload
|
|
51
|
+
* Загрузка из Web ReadableStream
|
|
29
52
|
*/
|
|
30
53
|
public put(
|
|
31
54
|
meta: ObjectStoreMeta,
|
|
32
55
|
rs: ReadableStream<Uint8Array>,
|
|
33
56
|
opts?: ObjectStorePutOpts,
|
|
57
|
+
): Promise<ObjectInfo>;
|
|
58
|
+
public put(
|
|
59
|
+
meta: ObjectStoreMeta,
|
|
60
|
+
data: Buffer | NodeJS.ReadableStream | ReadableStream<Uint8Array>,
|
|
61
|
+
opts?: ObjectStorePutOpts,
|
|
34
62
|
): Promise<ObjectInfo> {
|
|
35
|
-
|
|
63
|
+
let readableStream: ReadableStream<Uint8Array>;
|
|
64
|
+
|
|
65
|
+
if (Buffer.isBuffer(data)) {
|
|
66
|
+
// Конвертация Buffer в Web ReadableStream
|
|
67
|
+
readableStream = Readable.toWeb(Readable.from(data));
|
|
68
|
+
} else if (data instanceof ReadableStream) {
|
|
69
|
+
// Уже Web ReadableStream
|
|
70
|
+
readableStream = data;
|
|
71
|
+
} else {
|
|
72
|
+
// Node.js ReadableStream - конвертация в Web ReadableStream
|
|
73
|
+
readableStream = Readable.toWeb(data as Readable);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return this.storage.put(meta, readableStream, opts);
|
|
36
77
|
}
|
|
37
78
|
|
|
38
79
|
/**
|