eventsourcingdb 2.0.0 → 2.0.1
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/v1/V1Transport.js
CHANGED
|
@@ -16,6 +16,7 @@ import { isBoolean } from '../types/isBoolean.js';
|
|
|
16
16
|
import { isString } from '../types/isString.js';
|
|
17
17
|
import { getV1ErrorCode } from './getV1ErrorCode.js';
|
|
18
18
|
import { isV1Refusal } from './isV1Refusal.js';
|
|
19
|
+
import { normalizeSubject } from './normalizeSubject.js';
|
|
19
20
|
import { isStreamCloudEvent } from './stream/isStreamCloudEvent.js';
|
|
20
21
|
import { isStreamError } from './stream/isStreamError.js';
|
|
21
22
|
import { isStreamEventType } from './stream/isStreamEventType.js';
|
|
@@ -247,11 +248,17 @@ class V1Transport {
|
|
|
247
248
|
}
|
|
248
249
|
// The v1 API always reads the subjects below the subject as well. Reading
|
|
249
250
|
// only the subject itself keeps the subject alone, which the server lists
|
|
250
|
-
// at most once, so the request ends once it arrives.
|
|
251
|
+
// at most once, so the request ends once it arrives. The server lists it
|
|
252
|
+
// as it keeps it, so it is compared as the server keeps it, which makes
|
|
253
|
+
// '/test/' keep '/test', as the v2 API does.
|
|
251
254
|
readSubjects(subject, { recursive }, signal) {
|
|
252
255
|
const url = this.#getUrl('/api/v1/read-subjects');
|
|
253
256
|
const apiToken = this.#apiToken;
|
|
254
257
|
const stallTimeout = this.#stallTimeout;
|
|
258
|
+
// A caller without types may pass a subject that is not a string, which
|
|
259
|
+
// the server refuses with an error of its own, so the client normalizes
|
|
260
|
+
// only a string, and only to read the subject alone.
|
|
261
|
+
const normalizedSubject = !recursive && isString(subject) ? normalizeSubject(subject) : subject;
|
|
255
262
|
return streamWithStallGuard({ stallTimeout, signal }, async function* (stallGuard) {
|
|
256
263
|
const response = await stallGuard.send(url, {
|
|
257
264
|
method: 'POST',
|
|
@@ -273,7 +280,7 @@ class V1Transport {
|
|
|
273
280
|
yield line.payload.subject;
|
|
274
281
|
continue;
|
|
275
282
|
}
|
|
276
|
-
if (line.payload.subject ===
|
|
283
|
+
if (line.payload.subject === normalizedSubject) {
|
|
277
284
|
yield line.payload.subject;
|
|
278
285
|
return;
|
|
279
286
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const leadingAndTrailingSlashes = /^\/+|\/+$/gu;
|
|
2
|
+
// Returns the subject as the server keeps it, which is a slash followed by
|
|
3
|
+
// the subject without its leading and trailing slashes, so '/test/' becomes
|
|
4
|
+
// '/test', and '/' stays '/'.
|
|
5
|
+
const normalizeSubject = (subject) => `/${subject.replaceAll(leadingAndTrailingSlashes, '')}`;
|
|
6
|
+
export { normalizeSubject };
|