@relaybus/core 0.3.0 → 0.3.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/{chunk-3OHMEMZA.cjs → chunk-J76M7XTS.cjs} +127 -9
- package/dist/chunk-J76M7XTS.cjs.map +1 -0
- package/dist/{chunk-WS274DL3.js → chunk-NOR5JHVN.js} +121 -9
- package/dist/chunk-NOR5JHVN.js.map +1 -0
- package/dist/index.cjs +2232 -1898
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +82 -475
- package/dist/index.d.ts +82 -475
- package/dist/index.js +2259 -1931
- package/dist/index.js.map +1 -1
- package/dist/internal/index.cjs +335 -117
- package/dist/internal/index.cjs.map +1 -1
- package/dist/internal/index.d.cts +269 -2
- package/dist/internal/index.d.ts +269 -2
- package/dist/internal/index.js +293 -101
- package/dist/internal/index.js.map +1 -1
- package/dist/transport-BlfzIBZD.d.cts +535 -0
- package/dist/transport-BlfzIBZD.d.ts +535 -0
- package/package.json +1 -1
- package/dist/chunk-3OHMEMZA.cjs.map +0 -1
- package/dist/chunk-WS274DL3.js.map +0 -1
- package/dist/event-DCRTuYKI.d.cts +0 -142
- package/dist/event-DCRTuYKI.d.ts +0 -142
package/dist/internal/index.cjs
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkJ76M7XTS_cjs = require('../chunk-J76M7XTS.cjs');
|
|
4
|
+
|
|
5
|
+
// src/internal/validation.ts
|
|
6
|
+
function assertPositiveInteger(value, name) {
|
|
7
|
+
return chunkJ76M7XTS_cjs.PositiveInteger.of(value, name);
|
|
8
|
+
}
|
|
4
9
|
|
|
5
10
|
// src/internal/field-extractors.ts
|
|
6
11
|
function fromHeader(name) {
|
|
7
12
|
if (name.length === 0) {
|
|
8
|
-
throw new
|
|
13
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError("fromHeader needs a header name");
|
|
9
14
|
}
|
|
10
15
|
return (message) => Object.hasOwn(message.headers, name) ? message.headers[name] : void 0;
|
|
11
16
|
}
|
|
12
17
|
function fromPayloadField(path) {
|
|
13
18
|
const segments = path.split(".");
|
|
14
19
|
if (segments.some((segment) => segment.length === 0)) {
|
|
15
|
-
throw new
|
|
20
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(
|
|
16
21
|
`fromPayloadField needs a dotted path of non-empty names, received '${path}'`
|
|
17
22
|
);
|
|
18
23
|
}
|
|
@@ -57,7 +62,7 @@ function createCloudEventReaders(invalid) {
|
|
|
57
62
|
},
|
|
58
63
|
assertValidType: (type, label) => {
|
|
59
64
|
try {
|
|
60
|
-
|
|
65
|
+
chunkJ76M7XTS_cjs.assertEventType(type);
|
|
61
66
|
} catch (error) {
|
|
62
67
|
throw invalid(`${label} is not a valid event type: ${error.message}`);
|
|
63
68
|
}
|
|
@@ -85,7 +90,7 @@ function writeStructuredCloudEvent(envelope, { time, data }) {
|
|
|
85
90
|
return `${JSON.stringify(attributes).slice(0, -1)},"data":${data}}`;
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
// src/internal/json-envelope.ts
|
|
93
|
+
// src/internal/json-envelope-plan.ts
|
|
89
94
|
var OPTIONAL_NAMES = [
|
|
90
95
|
"key",
|
|
91
96
|
"source",
|
|
@@ -93,22 +98,10 @@ var OPTIONAL_NAMES = [
|
|
|
93
98
|
"correlationId",
|
|
94
99
|
"causationId"
|
|
95
100
|
];
|
|
96
|
-
var MAXIMUM_RFC3339_YEAR = 9999;
|
|
97
|
-
var RFC3339_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/i;
|
|
98
101
|
var ARRAY_INDEX = /^(?:0|[1-9]\d*)$/;
|
|
99
|
-
function createJsonEnvelopeFormat(mapping, {
|
|
100
|
-
transportIds,
|
|
101
|
-
failures
|
|
102
|
-
}) {
|
|
103
|
-
const plan = compile(mapping, transportIds);
|
|
104
|
-
return {
|
|
105
|
-
write: (envelope) => writeMessage(envelope, { plan, failures }),
|
|
106
|
-
read: (message) => readMessage(message, { plan, failures })
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
102
|
function compile(mapping, transportIds) {
|
|
110
103
|
if (!isJsonObject(mapping)) {
|
|
111
|
-
throw new
|
|
104
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError("jsonEnvelope needs a mapping object");
|
|
112
105
|
}
|
|
113
106
|
const optional = {};
|
|
114
107
|
for (const name of OPTIONAL_NAMES) {
|
|
@@ -129,11 +122,11 @@ function compile(mapping, transportIds) {
|
|
|
129
122
|
}
|
|
130
123
|
function compileType(type) {
|
|
131
124
|
if (isJsonObject(type) && typeof type["fixed"] === "string") {
|
|
132
|
-
|
|
125
|
+
chunkJ76M7XTS_cjs.assertEventType(type["fixed"]);
|
|
133
126
|
return { fixed: type["fixed"] };
|
|
134
127
|
}
|
|
135
128
|
if (type === void 0) {
|
|
136
|
-
throw new
|
|
129
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError("jsonEnvelope needs a type: { body }, { header } or { fixed }");
|
|
137
130
|
}
|
|
138
131
|
return toLocation(type, "type");
|
|
139
132
|
}
|
|
@@ -142,7 +135,7 @@ function compileId(id, transportIds) {
|
|
|
142
135
|
return void 0;
|
|
143
136
|
}
|
|
144
137
|
if (!isJsonObject(id)) {
|
|
145
|
-
throw new
|
|
138
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(
|
|
146
139
|
`jsonEnvelope needs an id: { body }, { header } or one of ${transportIds.map((name) => `'${name}'`).join(", ")}`
|
|
147
140
|
);
|
|
148
141
|
}
|
|
@@ -153,7 +146,7 @@ function compilePayload(payload) {
|
|
|
153
146
|
return void 0;
|
|
154
147
|
}
|
|
155
148
|
if (!isJsonObject(payload) || typeof payload["body"] !== "string") {
|
|
156
|
-
throw new
|
|
149
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(
|
|
157
150
|
"jsonEnvelope needs a payload: { body: '<path>' } or 'whole-body'"
|
|
158
151
|
);
|
|
159
152
|
}
|
|
@@ -164,7 +157,7 @@ function compileHeaders(headers) {
|
|
|
164
157
|
return void 0;
|
|
165
158
|
}
|
|
166
159
|
if (!isJsonObject(headers) || typeof headers["body"] !== "string") {
|
|
167
|
-
throw new
|
|
160
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(
|
|
168
161
|
"jsonEnvelope headers must be { body: '<path>' } or 'message-headers'"
|
|
169
162
|
);
|
|
170
163
|
}
|
|
@@ -177,14 +170,14 @@ function toLocation(field, label) {
|
|
|
177
170
|
if (isJsonObject(field) && typeof field["body"] === "string") {
|
|
178
171
|
return { label, path: toPath(field["body"], label) };
|
|
179
172
|
}
|
|
180
|
-
throw new
|
|
173
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(
|
|
181
174
|
`jsonEnvelope ${label} must be { body: '<path>' } or { header: '<name>' }`
|
|
182
175
|
);
|
|
183
176
|
}
|
|
184
177
|
function toPath(path, label) {
|
|
185
178
|
const segments = path.split(".");
|
|
186
179
|
if (segments.some((segment) => segment.length === 0)) {
|
|
187
|
-
throw new
|
|
180
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(
|
|
188
181
|
`jsonEnvelope ${label} needs a dotted path of non-empty names, received '${path}'`
|
|
189
182
|
);
|
|
190
183
|
}
|
|
@@ -197,7 +190,7 @@ function assertDisjoint(plan) {
|
|
|
197
190
|
const headers = locations.flatMap((location) => "header" in location ? [location.header] : []);
|
|
198
191
|
const duplicate = headers.find((name, index) => headers.indexOf(name) !== index);
|
|
199
192
|
if (duplicate !== void 0) {
|
|
200
|
-
throw new
|
|
193
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(`jsonEnvelope maps header '${duplicate}' twice`);
|
|
201
194
|
}
|
|
202
195
|
const paths = [
|
|
203
196
|
...locations.flatMap((location) => "path" in location ? [location.path] : []),
|
|
@@ -217,12 +210,117 @@ function assertCompatiblePaths(path, other) {
|
|
|
217
210
|
const parting = path.findIndex((segment, position) => segment !== other[position]);
|
|
218
211
|
const both = `'${path.join(".")}' and '${other.join(".")}'`;
|
|
219
212
|
if (parting === -1 || parting === other.length) {
|
|
220
|
-
throw new
|
|
213
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(`jsonEnvelope body paths ${both} overlap`);
|
|
221
214
|
}
|
|
222
215
|
if (ARRAY_INDEX.test(path[parting]) !== ARRAY_INDEX.test(other[parting])) {
|
|
223
|
-
throw new
|
|
216
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(`jsonEnvelope body paths ${both} mix an array index and a name`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/internal/json-envelope-read.ts
|
|
221
|
+
var RFC3339_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/i;
|
|
222
|
+
function readMessage(message, context) {
|
|
223
|
+
const { plan, failures } = context;
|
|
224
|
+
if (plan.payload !== void 0 && !isJsonObject(message.body)) {
|
|
225
|
+
throw failures.invalid("The message body must be a JSON object");
|
|
226
|
+
}
|
|
227
|
+
const read = (location) => location === void 0 ? void 0 : readText(message, { location, failures });
|
|
228
|
+
const fields = {
|
|
229
|
+
id: plan.id === void 0 ? void 0 : requireText(read(plan.id), { location: plan.id, failures }),
|
|
230
|
+
type: readType(message, context),
|
|
231
|
+
payload: readPayload(message.body, context),
|
|
232
|
+
key: read(plan.optional.key),
|
|
233
|
+
source: read(plan.optional.source),
|
|
234
|
+
headers: readEventHeaders(message, plan),
|
|
235
|
+
correlationId: read(plan.optional.correlationId) ?? null,
|
|
236
|
+
causationId: read(plan.optional.causationId) ?? null,
|
|
237
|
+
occurredAt: readTime(read(plan.optional.occurredAt), failures)
|
|
238
|
+
};
|
|
239
|
+
return Object.fromEntries(
|
|
240
|
+
Object.entries(fields).filter((entry) => entry[1] !== void 0)
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
function readType(message, { plan, failures }) {
|
|
244
|
+
if ("fixed" in plan.type) {
|
|
245
|
+
return plan.type.fixed;
|
|
246
|
+
}
|
|
247
|
+
const location = plan.type;
|
|
248
|
+
const type = requireText(readText(message, { location, failures }), { location, failures });
|
|
249
|
+
try {
|
|
250
|
+
chunkJ76M7XTS_cjs.assertEventType(type);
|
|
251
|
+
} catch (error) {
|
|
252
|
+
throw failures.invalid(`The event type is not a valid event type: ${error.message}`);
|
|
253
|
+
}
|
|
254
|
+
return type;
|
|
255
|
+
}
|
|
256
|
+
function readPayload(body, { plan, failures }) {
|
|
257
|
+
if (plan.payload === void 0) {
|
|
258
|
+
return body;
|
|
259
|
+
}
|
|
260
|
+
const payload = valueAt(body, plan.payload);
|
|
261
|
+
if (payload === void 0) {
|
|
262
|
+
throw failures.invalid(`The message has no payload at '${plan.payload.join(".")}'`);
|
|
263
|
+
}
|
|
264
|
+
return payload;
|
|
265
|
+
}
|
|
266
|
+
function readEventHeaders(message, plan) {
|
|
267
|
+
if (plan.headers === void 0) {
|
|
268
|
+
return Object.fromEntries(
|
|
269
|
+
Object.entries(message.headers).filter(([name]) => !plan.mappedHeaders.has(name))
|
|
270
|
+
);
|
|
224
271
|
}
|
|
272
|
+
const headers = valueAt(message.body, plan.headers);
|
|
273
|
+
return isJsonObject(headers) ? Object.fromEntries(
|
|
274
|
+
Object.entries(headers).filter(
|
|
275
|
+
(entry) => typeof entry[1] === "string"
|
|
276
|
+
)
|
|
277
|
+
) : {};
|
|
225
278
|
}
|
|
279
|
+
function readTime(text, failures) {
|
|
280
|
+
if (text === void 0) {
|
|
281
|
+
return void 0;
|
|
282
|
+
}
|
|
283
|
+
const time = new Date(text);
|
|
284
|
+
if (!RFC3339_PATTERN.test(text) || Number.isNaN(time.getTime())) {
|
|
285
|
+
throw failures.invalid(`The event time is not an RFC 3339 timestamp: '${text}'`);
|
|
286
|
+
}
|
|
287
|
+
return time;
|
|
288
|
+
}
|
|
289
|
+
function readText(message, { location, failures }) {
|
|
290
|
+
const value = "header" in location ? Object.hasOwn(message.headers, location.header) ? message.headers[location.header] : void 0 : valueAt(message.body, location.path);
|
|
291
|
+
if (value === void 0 || value === null || value === "") {
|
|
292
|
+
return void 0;
|
|
293
|
+
}
|
|
294
|
+
if (typeof value === "string") {
|
|
295
|
+
return value;
|
|
296
|
+
}
|
|
297
|
+
if (typeof value === "number" && Number.isSafeInteger(value)) {
|
|
298
|
+
return String(value);
|
|
299
|
+
}
|
|
300
|
+
throw failures.invalid(`The ${location.label} at ${describe(location)} must be a string`);
|
|
301
|
+
}
|
|
302
|
+
function requireText(value, { location, failures }) {
|
|
303
|
+
if (value === void 0) {
|
|
304
|
+
throw failures.invalid(`The message has no ${location.label} at ${describe(location)}`);
|
|
305
|
+
}
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
function describe(location) {
|
|
309
|
+
return "header" in location ? `header '${location.header}'` : `'${location.path.join(".")}'`;
|
|
310
|
+
}
|
|
311
|
+
function valueAt(body, path) {
|
|
312
|
+
let value = body;
|
|
313
|
+
for (const segment of path) {
|
|
314
|
+
if (typeof value !== "object" || value === null || !Object.hasOwn(value, segment)) {
|
|
315
|
+
return void 0;
|
|
316
|
+
}
|
|
317
|
+
value = value[segment];
|
|
318
|
+
}
|
|
319
|
+
return value;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/internal/json-envelope-write.ts
|
|
323
|
+
var MAXIMUM_RFC3339_YEAR = 9999;
|
|
226
324
|
function writeMessage(envelope, { plan, failures }) {
|
|
227
325
|
const root = {};
|
|
228
326
|
const headers = [];
|
|
@@ -321,124 +419,244 @@ function defineValue(target, { name, value }) {
|
|
|
321
419
|
configurable: true
|
|
322
420
|
});
|
|
323
421
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
key: read(plan.optional.key),
|
|
335
|
-
source: read(plan.optional.source),
|
|
336
|
-
headers: readEventHeaders(message, plan),
|
|
337
|
-
correlationId: read(plan.optional.correlationId) ?? null,
|
|
338
|
-
causationId: read(plan.optional.causationId) ?? null,
|
|
339
|
-
occurredAt: readTime(read(plan.optional.occurredAt), failures)
|
|
422
|
+
|
|
423
|
+
// src/internal/json-envelope.ts
|
|
424
|
+
function createJsonEnvelopeFormat(mapping, {
|
|
425
|
+
transportIds,
|
|
426
|
+
failures
|
|
427
|
+
}) {
|
|
428
|
+
const plan = compile(mapping, transportIds);
|
|
429
|
+
return {
|
|
430
|
+
write: (envelope) => writeMessage(envelope, { plan, failures }),
|
|
431
|
+
read: (message) => readMessage(message, { plan, failures })
|
|
340
432
|
};
|
|
341
|
-
return Object.fromEntries(
|
|
342
|
-
Object.entries(fields).filter((entry) => entry[1] !== void 0)
|
|
343
|
-
);
|
|
344
433
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
434
|
+
|
|
435
|
+
// src/store-kit/handed-out-ledger.ts
|
|
436
|
+
var HandedOutLedger = class {
|
|
437
|
+
#entries = /* @__PURE__ */ new Map();
|
|
438
|
+
register(lease, entry) {
|
|
439
|
+
this.#entries.set(chunkJ76M7XTS_cjs.DeliveryLeaseIdentity.of(lease.deliveryId, lease.leaseToken), entry);
|
|
440
|
+
}
|
|
441
|
+
/** Whether the claim with this identity ({@link DeliveryLeaseIdentity.of}) is handed out. */
|
|
442
|
+
has(identity) {
|
|
443
|
+
return this.#entries.has(identity);
|
|
444
|
+
}
|
|
445
|
+
forget(lease) {
|
|
446
|
+
this.#entries.delete(chunkJ76M7XTS_cjs.DeliveryLeaseIdentity.of(lease.deliveryId, lease.leaseToken));
|
|
447
|
+
}
|
|
448
|
+
/** Forgets every entry `settled` says is settled. */
|
|
449
|
+
forgetWhere(settled) {
|
|
450
|
+
for (const [identity, entry] of this.#entries) {
|
|
451
|
+
if (settled(entry, identity)) {
|
|
452
|
+
this.#entries.delete(identity);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
361
455
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
456
|
+
/** The entries handed out to `owner`. */
|
|
457
|
+
entriesOf(owner) {
|
|
458
|
+
return [...this.#entries.values()].filter((entry) => entry.owner === owner);
|
|
365
459
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// src/store-kit/owner-serialized-claims.ts
|
|
463
|
+
var OwnerSerializedClaims = class {
|
|
464
|
+
/** The last claim of each owner still running; the next one waits for it. */
|
|
465
|
+
#queues = /* @__PURE__ */ new Map();
|
|
466
|
+
claim(request) {
|
|
467
|
+
if (this.claimsNothing(request)) {
|
|
468
|
+
return Promise.resolve([]);
|
|
469
|
+
}
|
|
470
|
+
return this.#serialized(request.leaseOwner, () => this.claimInTurn(request));
|
|
471
|
+
}
|
|
472
|
+
/** Whether the request cannot claim anything: no handlers, or a limit that is not above 0. */
|
|
473
|
+
claimsNothing(request) {
|
|
474
|
+
return request.handlers.length === 0 || !(request.limit > 0);
|
|
475
|
+
}
|
|
476
|
+
#serialized(owner, work) {
|
|
477
|
+
const previous = this.#queues.get(owner) ?? Promise.resolve();
|
|
478
|
+
const run = previous.then(work, work);
|
|
479
|
+
const tail = run.then(
|
|
480
|
+
() => void 0,
|
|
481
|
+
() => void 0
|
|
372
482
|
);
|
|
483
|
+
this.#queues.set(owner, tail);
|
|
484
|
+
void tail.then(() => {
|
|
485
|
+
if (this.#queues.get(owner) === tail) {
|
|
486
|
+
this.#queues.delete(owner);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
return run;
|
|
373
490
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
// src/transport-kit/decoded-event-reader.ts
|
|
494
|
+
function observeRejection(value) {
|
|
495
|
+
if (typeof value === "object" && value !== null && "then" in value) {
|
|
496
|
+
Promise.resolve(value).catch(() => void 0);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
var DecodedEventReader = class {
|
|
500
|
+
/**
|
|
501
|
+
* Fills the fields a decoder left out and guards against a decoder that returned no object,
|
|
502
|
+
* which would otherwise surface as a retried `TypeError` instead of a malformed message.
|
|
503
|
+
*/
|
|
504
|
+
complete(decoded, message) {
|
|
505
|
+
if (typeof decoded !== "object" || decoded === null) {
|
|
506
|
+
throw this.invalid("The decoder must return an event object synchronously");
|
|
507
|
+
}
|
|
508
|
+
if ("then" in decoded) {
|
|
509
|
+
observeRejection(decoded);
|
|
510
|
+
throw this.invalid("The decoder must return an event object synchronously");
|
|
511
|
+
}
|
|
512
|
+
const event = decoded;
|
|
513
|
+
return {
|
|
514
|
+
id: event.id,
|
|
515
|
+
type: event.type,
|
|
516
|
+
source: event.source ?? this.defaultSource(message),
|
|
517
|
+
key: event.key === void 0 ? this.defaultKey(message) : event.key,
|
|
518
|
+
payload: event.payload,
|
|
519
|
+
headers: event.headers ?? {},
|
|
520
|
+
correlationId: event.correlationId ?? null,
|
|
521
|
+
causationId: event.causationId ?? null,
|
|
522
|
+
occurredAt: event.occurredAt ?? this.defaultTime(message)
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
/** The text an option gives for `plain`; undefined when it gives none or `''`. */
|
|
526
|
+
text(option, { plain, name }) {
|
|
527
|
+
const value = typeof option === "function" ? option(plain) : option;
|
|
528
|
+
if (value === void 0 || value === null) {
|
|
529
|
+
return void 0;
|
|
530
|
+
}
|
|
531
|
+
if (typeof value !== "string") {
|
|
532
|
+
observeRejection(value);
|
|
533
|
+
throw this.invalid(`The ${name} option returned ${typeof value}, expected a string`);
|
|
534
|
+
}
|
|
535
|
+
return value.length === 0 ? void 0 : value;
|
|
395
536
|
}
|
|
396
|
-
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
// src/transport-kit/subscribing-transport.ts
|
|
540
|
+
var SubscribingTransport = class {
|
|
541
|
+
/**
|
|
542
|
+
* Subscribes to `destinations`. Not async itself: the subscription's own promise is returned
|
|
543
|
+
* as it is, so its checks reject rather than throw.
|
|
544
|
+
*/
|
|
545
|
+
// eslint-disable-next-line relaybus/max-two-params -- the Transport.subscribe signature
|
|
546
|
+
subscribe(destinations, onMessage, hooks) {
|
|
547
|
+
return this.openSubscription({ destinations, onMessage, hooks });
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
// src/values/bounded-integer.ts
|
|
552
|
+
var BoundedInteger = class {
|
|
553
|
+
/** Returns `value` when it is an integer within the bounds, else throws a {@link ConfigurationError}. */
|
|
554
|
+
static of(value, { name, minimum, maximum }) {
|
|
555
|
+
if (!Number.isInteger(value) || value < minimum || value > maximum) {
|
|
556
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(
|
|
557
|
+
`${name} must be an integer from ${minimum} to ${maximum}, received ${value}`
|
|
558
|
+
);
|
|
559
|
+
}
|
|
397
560
|
return value;
|
|
398
561
|
}
|
|
399
|
-
|
|
400
|
-
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
// src/values/exponential-backoff.ts
|
|
565
|
+
var ExponentialBackoff = class {
|
|
566
|
+
initialMs;
|
|
567
|
+
maxMs;
|
|
568
|
+
constructor({ initialMs, maxMs }) {
|
|
569
|
+
this.initialMs = initialMs;
|
|
570
|
+
this.maxMs = maxMs;
|
|
571
|
+
}
|
|
572
|
+
/** The delay after failed attempt `attempt` (1-based). */
|
|
573
|
+
delayFor(attempt) {
|
|
574
|
+
return Math.min(this.initialMs * 2 ** (attempt - 1), this.maxMs);
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
// src/values/lane-lease-token.ts
|
|
579
|
+
var LANE_DIGITS = 3;
|
|
580
|
+
var LaneLeaseTokenFormat = class {
|
|
581
|
+
#pattern;
|
|
582
|
+
#laneCount;
|
|
583
|
+
constructor(limits) {
|
|
584
|
+
this.#laneCount = limits.laneCount;
|
|
585
|
+
this.#pattern = new RegExp(
|
|
586
|
+
`^(\\d{1,${LANE_DIGITS}}):(\\d{1,${limits.epochDigits}}):(\\d{1,${limits.claimsDigits}})$`
|
|
587
|
+
);
|
|
401
588
|
}
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
function requireText(value, { location, failures }) {
|
|
405
|
-
if (value === void 0) {
|
|
406
|
-
throw failures.invalid(`The message has no ${location.label} at ${describe(location)}`);
|
|
589
|
+
format(lane, { epoch, claims }) {
|
|
590
|
+
return `${lane}:${epoch}:${claims}`;
|
|
407
591
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
function valueAt(body, path) {
|
|
414
|
-
let value = body;
|
|
415
|
-
for (const segment of path) {
|
|
416
|
-
if (typeof value !== "object" || value === null || !Object.hasOwn(value, segment)) {
|
|
592
|
+
/** The parts of `token`; undefined when the store cannot have issued it. */
|
|
593
|
+
parse(token) {
|
|
594
|
+
const match = this.#pattern.exec(token);
|
|
595
|
+
if (match === null || Number(match[1]) >= this.#laneCount) {
|
|
417
596
|
return void 0;
|
|
418
597
|
}
|
|
419
|
-
|
|
598
|
+
return { lane: Number(match[1]), epoch: match[2], claims: Number(match[3]) };
|
|
420
599
|
}
|
|
421
|
-
|
|
422
|
-
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
// src/values/non-empty-text.ts
|
|
603
|
+
var NonEmptyText = class _NonEmptyText {
|
|
604
|
+
static of(value, name) {
|
|
605
|
+
if (value.length === 0) {
|
|
606
|
+
throw new chunkJ76M7XTS_cjs.ConfigurationError(`${name} must not be empty`);
|
|
607
|
+
}
|
|
608
|
+
return value;
|
|
609
|
+
}
|
|
610
|
+
/** Like {@link NonEmptyText.of}, for an option that may be left out. */
|
|
611
|
+
static optional(value, name) {
|
|
612
|
+
return value === void 0 ? void 0 : _NonEmptyText.of(value, name);
|
|
613
|
+
}
|
|
614
|
+
};
|
|
423
615
|
|
|
424
|
-
Object.defineProperty(exports, "
|
|
616
|
+
Object.defineProperty(exports, "CompositeKey", {
|
|
617
|
+
enumerable: true,
|
|
618
|
+
get: function () { return chunkJ76M7XTS_cjs.CompositeKey; }
|
|
619
|
+
});
|
|
620
|
+
Object.defineProperty(exports, "DeliveryLeaseIdentity", {
|
|
621
|
+
enumerable: true,
|
|
622
|
+
get: function () { return chunkJ76M7XTS_cjs.DeliveryLeaseIdentity; }
|
|
623
|
+
});
|
|
624
|
+
Object.defineProperty(exports, "LeaseSettlement", {
|
|
625
|
+
enumerable: true,
|
|
626
|
+
get: function () { return chunkJ76M7XTS_cjs.LeaseSettlement; }
|
|
627
|
+
});
|
|
628
|
+
Object.defineProperty(exports, "Milliseconds", {
|
|
629
|
+
enumerable: true,
|
|
630
|
+
get: function () { return chunkJ76M7XTS_cjs.Milliseconds; }
|
|
631
|
+
});
|
|
632
|
+
Object.defineProperty(exports, "PositiveInteger", {
|
|
425
633
|
enumerable: true,
|
|
426
|
-
get: function () { return
|
|
634
|
+
get: function () { return chunkJ76M7XTS_cjs.PositiveInteger; }
|
|
427
635
|
});
|
|
428
636
|
Object.defineProperty(exports, "schedule", {
|
|
429
637
|
enumerable: true,
|
|
430
|
-
get: function () { return
|
|
638
|
+
get: function () { return chunkJ76M7XTS_cjs.schedule; }
|
|
431
639
|
});
|
|
432
640
|
Object.defineProperty(exports, "sleep", {
|
|
433
641
|
enumerable: true,
|
|
434
|
-
get: function () { return
|
|
642
|
+
get: function () { return chunkJ76M7XTS_cjs.sleep; }
|
|
435
643
|
});
|
|
644
|
+
exports.BoundedInteger = BoundedInteger;
|
|
645
|
+
exports.DecodedEventReader = DecodedEventReader;
|
|
646
|
+
exports.ExponentialBackoff = ExponentialBackoff;
|
|
647
|
+
exports.HandedOutLedger = HandedOutLedger;
|
|
648
|
+
exports.LaneLeaseTokenFormat = LaneLeaseTokenFormat;
|
|
649
|
+
exports.NonEmptyText = NonEmptyText;
|
|
650
|
+
exports.OwnerSerializedClaims = OwnerSerializedClaims;
|
|
651
|
+
exports.SubscribingTransport = SubscribingTransport;
|
|
652
|
+
exports.assertPositiveInteger = assertPositiveInteger;
|
|
436
653
|
exports.createCloudEventReaders = createCloudEventReaders;
|
|
437
654
|
exports.createJsonEnvelopeFormat = createJsonEnvelopeFormat;
|
|
438
655
|
exports.fromHeader = fromHeader;
|
|
439
656
|
exports.fromPayloadField = fromPayloadField;
|
|
440
657
|
exports.isJsonObject = isJsonObject;
|
|
441
658
|
exports.mediaTypeOf = mediaTypeOf;
|
|
659
|
+
exports.observeRejection = observeRejection;
|
|
442
660
|
exports.writeStructuredCloudEvent = writeStructuredCloudEvent;
|
|
443
661
|
//# sourceMappingURL=index.cjs.map
|
|
444
662
|
//# sourceMappingURL=index.cjs.map
|