@rsdk/nats.object-storage 5.12.0-next.5 → 5.12.0-next.6
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/patch.js +25 -11
- package/dist/patch.js.map +1 -1
- package/package.json +3 -3
- package/src/patch.ts +35 -15
package/dist/patch.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const nats_1 = require("nats");
|
|
4
4
|
const objectstore_1 = require("nats/lib/jetstream/objectstore");
|
|
5
|
+
const sha_digest_parser_1 = require("nats/lib/jetstream/sha_digest.parser");
|
|
5
6
|
const codec_1 = require("nats/lib/nats-base-client/codec");
|
|
7
|
+
const js_sha256_1 = require("nats/lib/nats-base-client/js-sha256");
|
|
6
8
|
const queued_iterator_1 = require("nats/lib/nats-base-client/queued_iterator");
|
|
7
|
-
const sha256_1 = require("nats/lib/nats-base-client/sha256");
|
|
8
9
|
function emptyReadableStream() {
|
|
9
10
|
return new ReadableStream({
|
|
10
11
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
@@ -14,6 +15,7 @@ function emptyReadableStream() {
|
|
|
14
15
|
},
|
|
15
16
|
});
|
|
16
17
|
}
|
|
18
|
+
// @ts-expect-error typecheck
|
|
17
19
|
class ObjectInfoImpl {
|
|
18
20
|
info;
|
|
19
21
|
hdrs;
|
|
@@ -85,8 +87,16 @@ objectstore_1.ObjectStoreImpl.prototype.get = async function get(name) {
|
|
|
85
87
|
: await objectstore_1.ObjectStoreImpl.create(this.js, info.options.link.bucket);
|
|
86
88
|
return os.get(ln);
|
|
87
89
|
}
|
|
90
|
+
if (!info.digest.startsWith(objectstore_1.digestType)) {
|
|
91
|
+
throw new Error(`unknown digest type: ${info.digest}`);
|
|
92
|
+
}
|
|
93
|
+
const digest = (0, sha_digest_parser_1.parseSha256)(info.digest.slice(8));
|
|
94
|
+
if (digest === null) {
|
|
95
|
+
throw new Error(`unable to parse digest: ${info.digest}`);
|
|
96
|
+
}
|
|
88
97
|
const d = (0, nats_1.deferred)();
|
|
89
98
|
const r = {
|
|
99
|
+
// @ts-expect-error typecheck
|
|
90
100
|
info: new ObjectInfoImpl(info),
|
|
91
101
|
error: d,
|
|
92
102
|
};
|
|
@@ -98,7 +108,7 @@ objectstore_1.ObjectStoreImpl.prototype.get = async function get(name) {
|
|
|
98
108
|
let controller;
|
|
99
109
|
const oc = (0, nats_1.consumerOpts)();
|
|
100
110
|
oc.orderedConsumer();
|
|
101
|
-
const sha =
|
|
111
|
+
const sha = js_sha256_1.sha256.create();
|
|
102
112
|
const subj = `$O.${this.name}.C.${info.nuid}`;
|
|
103
113
|
let sub;
|
|
104
114
|
try {
|
|
@@ -106,7 +116,10 @@ objectstore_1.ObjectStoreImpl.prototype.get = async function get(name) {
|
|
|
106
116
|
sub = await this.js.subscribe(subj, oc);
|
|
107
117
|
}
|
|
108
118
|
catch (error) {
|
|
109
|
-
if (error
|
|
119
|
+
if (error &&
|
|
120
|
+
typeof error === 'object' &&
|
|
121
|
+
'message' in error &&
|
|
122
|
+
error.message !== 'no stream matches subject') {
|
|
110
123
|
throw error;
|
|
111
124
|
}
|
|
112
125
|
const oc = (0, nats_1.consumerOpts)({
|
|
@@ -126,12 +139,7 @@ objectstore_1.ObjectStoreImpl.prototype.get = async function get(name) {
|
|
|
126
139
|
controller.enqueue(jm.data);
|
|
127
140
|
}
|
|
128
141
|
if (jm.info.pending === 0) {
|
|
129
|
-
|
|
130
|
-
// go pads the hash - which should be multiple of 3 - otherwise pads with '='
|
|
131
|
-
const pad = hash.length % 3;
|
|
132
|
-
const padding = pad > 0 ? '='.repeat(pad) : '';
|
|
133
|
-
const digest = `${objectstore_1.digestType}${hash}${padding}`;
|
|
134
|
-
if (digest === info.digest) {
|
|
142
|
+
if ((0, sha_digest_parser_1.checkSha256)(digest, sha.digest())) {
|
|
135
143
|
controller.close();
|
|
136
144
|
}
|
|
137
145
|
else {
|
|
@@ -170,7 +178,10 @@ objectstore_1.ObjectStoreImpl.prototype.watch = async function watch(opts = {})
|
|
|
170
178
|
await this.jsm.streams.getMessage(this.stream, { last_by_subj: subj });
|
|
171
179
|
}
|
|
172
180
|
catch (error) {
|
|
173
|
-
if (error
|
|
181
|
+
if (error &&
|
|
182
|
+
typeof error === 'object' &&
|
|
183
|
+
'code' in error &&
|
|
184
|
+
error.code === '404') {
|
|
174
185
|
qi.push(null);
|
|
175
186
|
initialized = true;
|
|
176
187
|
}
|
|
@@ -215,7 +226,10 @@ objectstore_1.ObjectStoreImpl.prototype.watch = async function watch(opts = {})
|
|
|
215
226
|
sub = await this.js.subscribe(subj, copts);
|
|
216
227
|
}
|
|
217
228
|
catch (error) {
|
|
218
|
-
if (error
|
|
229
|
+
if (error &&
|
|
230
|
+
typeof error === 'object' &&
|
|
231
|
+
'message' in error &&
|
|
232
|
+
error.message !== 'no stream matches subject') {
|
|
219
233
|
throw error;
|
|
220
234
|
}
|
|
221
235
|
copts.bindStream('OBJ_' + this.name);
|
package/dist/patch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../src/patch.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../src/patch.ts"],"names":[],"mappings":";;AASA,+BAAsE;AAEtE,gEAA6E;AAC7E,4EAAgF;AAChF,2DAA4D;AAC5D,mEAA6D;AAC7D,+EAA+E;AAE/E,SAAS,mBAAmB;IAC1B,OAAO,IAAI,cAAc,CAAC;QACxB,4EAA4E;QAC5E,IAAI,CAAC,CAAC;YACJ,CAAC,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC,CAAC,KAAK,EAAE,CAAC;QACZ,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,6BAA6B;AAC7B,MAAM,cAAc;IAClB,IAAI,CAAmB;IACvB,IAAI,CAAW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A2B,EAC7C,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QAED,KAAK,CAAC,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAErC,iCAAiC;QACjC,mDAAmD;QACnD,GAAG,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,EAAE,CAAC,KAAK,GAAG,GAAG,CAAC;IACf,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE;QACtB,GAAG,CAAC,WAAW,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,MAAM;SACP,IAAI,CAAC,GAAG,EAAE;QACT,EAAE,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IAEL,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/nats.object-storage",
|
|
3
|
-
"version": "5.12.0-next.
|
|
3
|
+
"version": "5.12.0-next.6",
|
|
4
4
|
"description": "Nats NestJS object storage",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "Apache License 2.0",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@nestjs-plugins/nestjs-nats-jetstream-transport": "^2.2.6",
|
|
15
15
|
"lodash": "^4.17.21",
|
|
16
|
-
"nats": "~2.
|
|
16
|
+
"nats": "~2.29.3"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"@nestjs/common": "^10.4.20",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"rxjs": "^7.1.0"
|
|
36
36
|
},
|
|
37
37
|
"nx": {},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "32103725bddbe5e7e99074ba40b5032dc14cf60c"
|
|
39
39
|
}
|
package/src/patch.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck issue - https://github.com/nats-io/nats.js/issues/155
|
|
3
1
|
import type {
|
|
2
|
+
JsMsg,
|
|
4
3
|
MsgHdrs,
|
|
4
|
+
NatsError,
|
|
5
5
|
ObjectInfo,
|
|
6
6
|
ObjectResult,
|
|
7
7
|
ObjectStoreMetaOptions,
|
|
8
|
+
QueuedIterator,
|
|
8
9
|
} from 'nats';
|
|
9
10
|
import { AckPolicy, consumerOpts, deferred, MsgHdrsImpl } from 'nats';
|
|
10
11
|
import type { ServerObjectInfo } from 'nats/lib/jetstream/objectstore';
|
|
11
12
|
import { digestType, ObjectStoreImpl } from 'nats/lib/jetstream/objectstore';
|
|
13
|
+
import { checkSha256, parseSha256 } from 'nats/lib/jetstream/sha_digest.parser';
|
|
12
14
|
import { JSONCodec } from 'nats/lib/nats-base-client/codec';
|
|
15
|
+
import { sha256 } from 'nats/lib/nats-base-client/js-sha256';
|
|
13
16
|
import { QueuedIteratorImpl } from 'nats/lib/nats-base-client/queued_iterator';
|
|
14
|
-
import { SHA256 } from 'nats/lib/nats-base-client/sha256';
|
|
15
17
|
|
|
16
18
|
function emptyReadableStream(): ReadableStream {
|
|
17
19
|
return new ReadableStream({
|
|
@@ -23,6 +25,7 @@ function emptyReadableStream(): ReadableStream {
|
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
// @ts-expect-error typecheck
|
|
26
29
|
class ObjectInfoImpl implements ObjectInfo {
|
|
27
30
|
info: ServerObjectInfo;
|
|
28
31
|
hdrs!: MsgHdrs;
|
|
@@ -117,10 +120,18 @@ ObjectStoreImpl.prototype.get = async function get(
|
|
|
117
120
|
|
|
118
121
|
return os.get(ln);
|
|
119
122
|
}
|
|
123
|
+
if (!info.digest.startsWith(digestType)) {
|
|
124
|
+
throw new Error(`unknown digest type: ${info.digest}`);
|
|
125
|
+
}
|
|
126
|
+
const digest = parseSha256(info.digest.slice(8));
|
|
127
|
+
if (digest === null) {
|
|
128
|
+
throw new Error(`unable to parse digest: ${info.digest}`);
|
|
129
|
+
}
|
|
120
130
|
|
|
121
131
|
const d = deferred<Error | null>();
|
|
122
132
|
|
|
123
133
|
const r: Partial<ObjectResult> = {
|
|
134
|
+
// @ts-expect-error typecheck
|
|
124
135
|
info: new ObjectInfoImpl(info),
|
|
125
136
|
error: d,
|
|
126
137
|
};
|
|
@@ -135,7 +146,7 @@ ObjectStoreImpl.prototype.get = async function get(
|
|
|
135
146
|
const oc = consumerOpts();
|
|
136
147
|
|
|
137
148
|
oc.orderedConsumer();
|
|
138
|
-
const sha =
|
|
149
|
+
const sha = sha256.create();
|
|
139
150
|
const subj = `$O.${this.name}.C.${info.nuid}`;
|
|
140
151
|
let sub;
|
|
141
152
|
|
|
@@ -143,7 +154,12 @@ ObjectStoreImpl.prototype.get = async function get(
|
|
|
143
154
|
// eslint-disable-next-line deprecation/deprecation
|
|
144
155
|
sub = await this.js.subscribe(subj, oc);
|
|
145
156
|
} catch (error) {
|
|
146
|
-
if (
|
|
157
|
+
if (
|
|
158
|
+
error &&
|
|
159
|
+
typeof error === 'object' &&
|
|
160
|
+
'message' in error &&
|
|
161
|
+
error.message !== 'no stream matches subject'
|
|
162
|
+
) {
|
|
147
163
|
throw error;
|
|
148
164
|
}
|
|
149
165
|
const oc = consumerOpts({
|
|
@@ -165,13 +181,7 @@ ObjectStoreImpl.prototype.get = async function get(
|
|
|
165
181
|
controller!.enqueue(jm.data);
|
|
166
182
|
}
|
|
167
183
|
if (jm.info.pending === 0) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
// go pads the hash - which should be multiple of 3 - otherwise pads with '='
|
|
171
|
-
const pad = hash.length % 3;
|
|
172
|
-
const padding = pad > 0 ? '='.repeat(pad) : '';
|
|
173
|
-
const digest = `${digestType}${hash}${padding}`;
|
|
174
|
-
if (digest === info.digest) {
|
|
184
|
+
if (checkSha256(digest, sha.digest())) {
|
|
175
185
|
controller!.close();
|
|
176
186
|
} else {
|
|
177
187
|
controller!.error(
|
|
@@ -221,11 +231,16 @@ ObjectStoreImpl.prototype.watch = async function watch(
|
|
|
221
231
|
try {
|
|
222
232
|
await this.jsm.streams.getMessage(this.stream, { last_by_subj: subj });
|
|
223
233
|
} catch (error) {
|
|
224
|
-
if (
|
|
234
|
+
if (
|
|
235
|
+
error &&
|
|
236
|
+
typeof error === 'object' &&
|
|
237
|
+
'code' in error &&
|
|
238
|
+
error.code === '404'
|
|
239
|
+
) {
|
|
225
240
|
qi.push(null);
|
|
226
241
|
initialized = true;
|
|
227
242
|
} else {
|
|
228
|
-
qi.stop(error);
|
|
243
|
+
qi.stop(error as Error);
|
|
229
244
|
}
|
|
230
245
|
}
|
|
231
246
|
const jc = JSONCodec<ObjectInfo>();
|
|
@@ -265,7 +280,12 @@ ObjectStoreImpl.prototype.watch = async function watch(
|
|
|
265
280
|
// eslint-disable-next-line deprecation/deprecation
|
|
266
281
|
sub = await this.js.subscribe(subj, copts);
|
|
267
282
|
} catch (error) {
|
|
268
|
-
if (
|
|
283
|
+
if (
|
|
284
|
+
error &&
|
|
285
|
+
typeof error === 'object' &&
|
|
286
|
+
'message' in error &&
|
|
287
|
+
error.message !== 'no stream matches subject'
|
|
288
|
+
) {
|
|
269
289
|
throw error;
|
|
270
290
|
}
|
|
271
291
|
|