@relaybus/core 0.4.0 → 0.5.0
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/README.md +5 -0
- package/dist/{chunk-J76M7XTS.cjs → chunk-2E6NSHGE.cjs} +27 -2
- package/dist/chunk-2E6NSHGE.cjs.map +1 -0
- package/dist/{chunk-NOR5JHVN.js → chunk-6PQ673MW.js} +23 -3
- package/dist/chunk-6PQ673MW.js.map +1 -0
- package/dist/index.cjs +567 -215
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +111 -11
- package/dist/index.d.ts +111 -11
- package/dist/index.js +418 -89
- package/dist/index.js.map +1 -1
- package/dist/internal/index.cjs +218 -49
- package/dist/internal/index.cjs.map +1 -1
- package/dist/internal/index.d.cts +45 -2
- package/dist/internal/index.d.ts +45 -2
- package/dist/internal/index.js +188 -21
- package/dist/internal/index.js.map +1 -1
- package/dist/{transport-DIFdeXQY.d.cts → transport-CXoZgh5u.d.cts} +77 -2
- package/dist/{transport-DIFdeXQY.d.ts → transport-CXoZgh5u.d.ts} +77 -2
- package/package.json +1 -1
- package/dist/chunk-J76M7XTS.cjs.map +0 -1
- package/dist/chunk-NOR5JHVN.js.map +0 -1
package/dist/internal/index.cjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk2E6NSHGE_cjs = require('../chunk-2E6NSHGE.cjs');
|
|
4
4
|
|
|
5
5
|
// src/internal/validation.ts
|
|
6
6
|
function assertPositiveInteger(value, name) {
|
|
7
|
-
return
|
|
7
|
+
return chunk2E6NSHGE_cjs.PositiveInteger.of(value, name);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
// src/internal/field-extractors.ts
|
|
11
11
|
function fromHeader(name) {
|
|
12
12
|
if (name.length === 0) {
|
|
13
|
-
throw new
|
|
13
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("fromHeader needs a header name");
|
|
14
14
|
}
|
|
15
15
|
return (message) => Object.hasOwn(message.headers, name) ? message.headers[name] : void 0;
|
|
16
16
|
}
|
|
17
17
|
function fromPayloadField(path) {
|
|
18
18
|
const segments = path.split(".");
|
|
19
19
|
if (segments.some((segment) => segment.length === 0)) {
|
|
20
|
-
throw new
|
|
20
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
21
21
|
`fromPayloadField needs a dotted path of non-empty names, received '${path}'`
|
|
22
22
|
);
|
|
23
23
|
}
|
|
@@ -62,7 +62,7 @@ function createCloudEventReaders(invalid) {
|
|
|
62
62
|
},
|
|
63
63
|
assertValidType: (type, label) => {
|
|
64
64
|
try {
|
|
65
|
-
|
|
65
|
+
chunk2E6NSHGE_cjs.assertEventType(type);
|
|
66
66
|
} catch (error) {
|
|
67
67
|
throw invalid(`${label} is not a valid event type: ${error.message}`);
|
|
68
68
|
}
|
|
@@ -90,6 +90,93 @@ function writeStructuredCloudEvent(envelope, { time, data }) {
|
|
|
90
90
|
return `${JSON.stringify(attributes).slice(0, -1)},"data":${data}}`;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
// src/internal/json-envelope-wire-types.ts
|
|
94
|
+
function compileWireTypes(wireTypes, { fixed }) {
|
|
95
|
+
if (wireTypes === void 0) {
|
|
96
|
+
return { wireTypes: /* @__PURE__ */ new Map(), eventTypes: /* @__PURE__ */ new Map() };
|
|
97
|
+
}
|
|
98
|
+
if (!isJsonObject(wireTypes) || fixed) {
|
|
99
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
100
|
+
"jsonEnvelope wireTypes must be an object of event type to wire name, with a type at { body } or { header }"
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
const entries = Object.entries(wireTypes);
|
|
104
|
+
const eventTypes = /* @__PURE__ */ new Map();
|
|
105
|
+
for (const [type, wire] of entries) {
|
|
106
|
+
chunk2E6NSHGE_cjs.assertEventType(type);
|
|
107
|
+
if (typeof wire !== "string" || wire.length === 0 || eventTypes.has(wire)) {
|
|
108
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
109
|
+
`jsonEnvelope wireTypes needs a non-empty wire name for '${type}' that no other type uses`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
eventTypes.set(wire, type);
|
|
113
|
+
}
|
|
114
|
+
return { wireTypes: new Map(entries), eventTypes };
|
|
115
|
+
}
|
|
116
|
+
function wireTypeOf(envelope, { plan, failures }) {
|
|
117
|
+
const wire = plan.wireTypes.get(envelope.type);
|
|
118
|
+
if (wire !== void 0) {
|
|
119
|
+
return wire;
|
|
120
|
+
}
|
|
121
|
+
const other = plan.eventTypes.get(envelope.type);
|
|
122
|
+
if (other !== void 0) {
|
|
123
|
+
throw failures.unencodable(
|
|
124
|
+
`Event ${envelope.id} has type '${envelope.type}', which wireTypes uses as the wire name of '${other}'`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return envelope.type;
|
|
128
|
+
}
|
|
129
|
+
function eventTypeOf(wire, { plan, failures }) {
|
|
130
|
+
const type = plan.eventTypes.get(wire);
|
|
131
|
+
if (type !== void 0) {
|
|
132
|
+
return type;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
chunk2E6NSHGE_cjs.assertEventType(wire);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw failures.invalid(`The event type is not a valid event type: ${error.message}`);
|
|
138
|
+
}
|
|
139
|
+
return wire;
|
|
140
|
+
}
|
|
141
|
+
function withDeclaredWireTypes(codec, {
|
|
142
|
+
wireTypes,
|
|
143
|
+
transport
|
|
144
|
+
}) {
|
|
145
|
+
if (codec.withWireTypes === void 0) {
|
|
146
|
+
throw new chunk2E6NSHGE_cjs.WireTypesUnsupportedError(
|
|
147
|
+
`The codec of transport '${transport}' cannot map event types to wire names; use jsonEnvelope with a type at { body } or { header }`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return codec.withWireTypes(wireTypes);
|
|
151
|
+
}
|
|
152
|
+
function mergeWireTypes(mapping, declared) {
|
|
153
|
+
if (isJsonObject(mapping.type) && "fixed" in mapping.type) {
|
|
154
|
+
throw new chunk2E6NSHGE_cjs.WireTypesUnsupportedError(
|
|
155
|
+
"A jsonEnvelope with a fixed type writes no type, so it has no wire names to declare"
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
const merged = new Map(Object.entries(mapping.wireTypes ?? {}));
|
|
159
|
+
for (const [type, wire] of Object.entries(declared)) {
|
|
160
|
+
assertDeclarable(merged, { type, wire });
|
|
161
|
+
merged.set(type, wire);
|
|
162
|
+
}
|
|
163
|
+
return Object.fromEntries(merged);
|
|
164
|
+
}
|
|
165
|
+
function assertDeclarable(wireTypes, { type, wire }) {
|
|
166
|
+
const current = wireTypes.get(type);
|
|
167
|
+
if (current !== void 0 && current !== wire) {
|
|
168
|
+
throw new chunk2E6NSHGE_cjs.WireTypeCollisionError(
|
|
169
|
+
`Event type '${type}' has the wire name '${current}' in the wireTypes of the codec and '${wire}' from a route or catalog`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
const owner = [...wireTypes].find(([other, name]) => name === wire && other !== type);
|
|
173
|
+
if (owner !== void 0) {
|
|
174
|
+
throw new chunk2E6NSHGE_cjs.WireTypeCollisionError(
|
|
175
|
+
`Event types '${owner[0]}' and '${type}' share the wire name '${wire}' in the codec and a route or catalog`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
93
180
|
// src/internal/json-envelope-plan.ts
|
|
94
181
|
var OPTIONAL_NAMES = [
|
|
95
182
|
"key",
|
|
@@ -102,7 +189,7 @@ var TIME_FORMATS = ["rfc3339", "epoch-millis", "epoch-seconds"];
|
|
|
102
189
|
var ARRAY_INDEX = /^(?:0|[1-9]\d*)$/;
|
|
103
190
|
function compile(mapping, transportIds) {
|
|
104
191
|
if (!isJsonObject(mapping)) {
|
|
105
|
-
throw new
|
|
192
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope needs a mapping object");
|
|
106
193
|
}
|
|
107
194
|
const optional = {};
|
|
108
195
|
for (const name of OPTIONAL_NAMES) {
|
|
@@ -114,10 +201,11 @@ function compile(mapping, transportIds) {
|
|
|
114
201
|
const payload = compilePayload(mapping.payload);
|
|
115
202
|
const topLevelHeaders = mapping.headers === "top-level-fields";
|
|
116
203
|
if (topLevelHeaders && payload === void 0) {
|
|
117
|
-
throw new
|
|
204
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope headers 'top-level-fields' needs a body payload");
|
|
118
205
|
}
|
|
206
|
+
const type = compileType(mapping.type);
|
|
119
207
|
const plan = {
|
|
120
|
-
type
|
|
208
|
+
type,
|
|
121
209
|
id: compileId(mapping.id, transportIds),
|
|
122
210
|
idWhenMissing: isJsonObject(mapping.id) && "whenMissing" in mapping.id,
|
|
123
211
|
optional,
|
|
@@ -127,6 +215,8 @@ function compile(mapping, transportIds) {
|
|
|
127
215
|
topLevelNames: /* @__PURE__ */ new Set(),
|
|
128
216
|
mappedHeaders: /* @__PURE__ */ new Set(),
|
|
129
217
|
timeFormat: compileTimeFormat(mapping.occurredAt),
|
|
218
|
+
otherFields: compileOtherFields(mapping, payload !== void 0),
|
|
219
|
+
...compileWireTypes(mapping.wireTypes, { fixed: "fixed" in type }),
|
|
130
220
|
...compileExtras(mapping, payload !== void 0)
|
|
131
221
|
};
|
|
132
222
|
return assertDisjoint(plan);
|
|
@@ -137,7 +227,7 @@ function compileTimeFormat(field) {
|
|
|
137
227
|
return "rfc3339";
|
|
138
228
|
}
|
|
139
229
|
if (!TIME_FORMATS.includes(format)) {
|
|
140
|
-
throw new
|
|
230
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
141
231
|
`jsonEnvelope occurredAt format must be one of ${TIME_FORMATS.map((name) => `'${name}'`).join(", ")}`
|
|
142
232
|
);
|
|
143
233
|
}
|
|
@@ -147,7 +237,7 @@ function compileExtras(mapping, hasBody) {
|
|
|
147
237
|
const extra = mapping.extra ?? {};
|
|
148
238
|
const bodyOrder = mapping.bodyOrder ?? [];
|
|
149
239
|
if (!hasBody && (extra.body !== void 0 || bodyOrder.length > 0)) {
|
|
150
|
-
throw new
|
|
240
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
151
241
|
"jsonEnvelope with a whole-body payload has no body for extra values or a body order"
|
|
152
242
|
);
|
|
153
243
|
}
|
|
@@ -160,13 +250,27 @@ function compileExtras(mapping, hasBody) {
|
|
|
160
250
|
bodyOrder
|
|
161
251
|
};
|
|
162
252
|
}
|
|
253
|
+
function compileOtherFields(mapping, hasBody) {
|
|
254
|
+
const otherFields = mapping.otherFields;
|
|
255
|
+
if (otherFields === void 0) {
|
|
256
|
+
return void 0;
|
|
257
|
+
}
|
|
258
|
+
if (!hasBody) {
|
|
259
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope otherFields needs a body payload");
|
|
260
|
+
}
|
|
261
|
+
const field = isJsonObject(otherFields) ? otherFields["payloadField"] : void 0;
|
|
262
|
+
if (typeof field !== "string" || field.length === 0) {
|
|
263
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope otherFields must be { payloadField: '<name>' }");
|
|
264
|
+
}
|
|
265
|
+
return field;
|
|
266
|
+
}
|
|
163
267
|
function compileType(type) {
|
|
164
268
|
if (isJsonObject(type) && typeof type["fixed"] === "string") {
|
|
165
|
-
|
|
269
|
+
chunk2E6NSHGE_cjs.assertEventType(type["fixed"]);
|
|
166
270
|
return { fixed: type["fixed"] };
|
|
167
271
|
}
|
|
168
272
|
if (type === void 0) {
|
|
169
|
-
throw new
|
|
273
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope needs a type: { body }, { header } or { fixed }");
|
|
170
274
|
}
|
|
171
275
|
return toLocation(type, "type");
|
|
172
276
|
}
|
|
@@ -176,12 +280,12 @@ function compileId(id, transportIds) {
|
|
|
176
280
|
}
|
|
177
281
|
const names = transportIds.map((name) => `'${name}'`).join(", ");
|
|
178
282
|
if (!isJsonObject(id)) {
|
|
179
|
-
throw new
|
|
283
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
180
284
|
`jsonEnvelope needs an id: { body }, { header } or one of ${names}`
|
|
181
285
|
);
|
|
182
286
|
}
|
|
183
287
|
if ("whenMissing" in id && !transportIds.includes(id["whenMissing"])) {
|
|
184
|
-
throw new
|
|
288
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`jsonEnvelope id whenMissing must be one of ${names}`);
|
|
185
289
|
}
|
|
186
290
|
return toLocation(id, "id");
|
|
187
291
|
}
|
|
@@ -190,7 +294,7 @@ function compilePayload(payload) {
|
|
|
190
294
|
return void 0;
|
|
191
295
|
}
|
|
192
296
|
if (!isJsonObject(payload) || typeof payload["body"] !== "string") {
|
|
193
|
-
throw new
|
|
297
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
194
298
|
"jsonEnvelope needs a payload: { body: '<path>' } or 'whole-body'"
|
|
195
299
|
);
|
|
196
300
|
}
|
|
@@ -201,7 +305,7 @@ function compileHeaders(headers) {
|
|
|
201
305
|
return void 0;
|
|
202
306
|
}
|
|
203
307
|
if (!isJsonObject(headers) || typeof headers["body"] !== "string") {
|
|
204
|
-
throw new
|
|
308
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
205
309
|
"jsonEnvelope headers must be { body: '<path>' } or 'message-headers'"
|
|
206
310
|
);
|
|
207
311
|
}
|
|
@@ -214,14 +318,14 @@ function toLocation(field, label) {
|
|
|
214
318
|
if (isJsonObject(field) && typeof field["body"] === "string") {
|
|
215
319
|
return { label, path: toPath(field["body"], label) };
|
|
216
320
|
}
|
|
217
|
-
throw new
|
|
321
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
218
322
|
`jsonEnvelope ${label} must be { body: '<path>' } or { header: '<name>' }`
|
|
219
323
|
);
|
|
220
324
|
}
|
|
221
325
|
function toPath(path, label) {
|
|
222
326
|
const segments = path.split(".");
|
|
223
327
|
if (segments.some((segment) => segment.length === 0)) {
|
|
224
|
-
throw new
|
|
328
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
225
329
|
`jsonEnvelope ${label} needs a dotted path of non-empty names, received '${path}'`
|
|
226
330
|
);
|
|
227
331
|
}
|
|
@@ -237,7 +341,7 @@ function assertDisjoint(plan) {
|
|
|
237
341
|
];
|
|
238
342
|
const duplicate = headers.find((name, index) => headers.indexOf(name) !== index);
|
|
239
343
|
if (duplicate !== void 0) {
|
|
240
|
-
throw new
|
|
344
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`jsonEnvelope maps header '${duplicate}' twice`);
|
|
241
345
|
}
|
|
242
346
|
const paths = [
|
|
243
347
|
...locations.flatMap((location) => "path" in location ? [location.path] : []),
|
|
@@ -262,13 +366,63 @@ function assertCompatiblePaths(path, other) {
|
|
|
262
366
|
const parting = path.findIndex((segment, position) => segment !== other[position]);
|
|
263
367
|
const both = `'${path.join(".")}' and '${other.join(".")}'`;
|
|
264
368
|
if (parting === -1 || parting === other.length) {
|
|
265
|
-
throw new
|
|
369
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`jsonEnvelope body paths ${both} overlap`);
|
|
266
370
|
}
|
|
267
371
|
if (ARRAY_INDEX.test(path[parting]) !== ARRAY_INDEX.test(other[parting])) {
|
|
268
|
-
throw new
|
|
372
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`jsonEnvelope body paths ${both} mix an array index and a name`);
|
|
269
373
|
}
|
|
270
374
|
}
|
|
271
375
|
|
|
376
|
+
// src/internal/json-envelope-other-fields.ts
|
|
377
|
+
function unusedFields(body, { plan }) {
|
|
378
|
+
return Object.entries(body).filter(
|
|
379
|
+
([name, value]) => !plan.topLevelNames.has(name) && !(plan.topLevelHeaders && typeof value === "string")
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
function withOtherFields(payload, { body, context }) {
|
|
383
|
+
const field = context.plan.otherFields;
|
|
384
|
+
if (field === void 0) {
|
|
385
|
+
return payload;
|
|
386
|
+
}
|
|
387
|
+
const fields = unusedFields(body, context);
|
|
388
|
+
if (!isJsonObject(payload) && fields.length === 0) {
|
|
389
|
+
return payload;
|
|
390
|
+
}
|
|
391
|
+
if (!isJsonObject(payload) || Object.hasOwn(payload, field)) {
|
|
392
|
+
throw context.failures.invalid(
|
|
393
|
+
`otherFields keeps the unused top-level fields under the payload field '${field}', but the payload is not an object without that field`
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
return Object.fromEntries([...Object.entries(payload), [field, Object.fromEntries(fields)]]);
|
|
397
|
+
}
|
|
398
|
+
function splitOtherFields(envelope, context) {
|
|
399
|
+
const field = context.plan.otherFields;
|
|
400
|
+
const { payload } = envelope;
|
|
401
|
+
if (field === void 0 || !isJsonObject(payload) || !Object.hasOwn(payload, field)) {
|
|
402
|
+
return { payload, fields: [] };
|
|
403
|
+
}
|
|
404
|
+
const others = payload[field];
|
|
405
|
+
if (!isJsonObject(others)) {
|
|
406
|
+
throw context.failures.unencodable(
|
|
407
|
+
`Event ${envelope.id} has a payload field '${field}' that is not an object of top-level fields`
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
const fields = Object.entries(others);
|
|
411
|
+
const refused = fields.find((entry) => isRefused(entry, context));
|
|
412
|
+
if (refused !== void 0) {
|
|
413
|
+
throw context.failures.unencodable(
|
|
414
|
+
`Event ${envelope.id} keeps a top-level field '${refused[0]}' under '${field}' that the mapping reads as another value`
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
payload: Object.fromEntries(Object.entries(payload).filter(([name]) => name !== field)),
|
|
419
|
+
fields
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function isRefused([name, value], { plan }) {
|
|
423
|
+
return plan.topLevelNames.has(name) || plan.topLevelHeaders && typeof value === "string";
|
|
424
|
+
}
|
|
425
|
+
|
|
272
426
|
// src/internal/json-envelope-read.ts
|
|
273
427
|
var RFC3339_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/i;
|
|
274
428
|
var EPOCH_PATTERN = /^\d+$/;
|
|
@@ -305,13 +459,8 @@ function readType(message, { plan, failures }) {
|
|
|
305
459
|
return plan.type.fixed;
|
|
306
460
|
}
|
|
307
461
|
const location = plan.type;
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
chunkJ76M7XTS_cjs.assertEventType(type);
|
|
311
|
-
} catch (error) {
|
|
312
|
-
throw failures.invalid(`The event type is not a valid event type: ${error.message}`);
|
|
313
|
-
}
|
|
314
|
-
return type;
|
|
462
|
+
const wire = requireText(readText(message, { location, failures }), { location, failures });
|
|
463
|
+
return eventTypeOf(wire, { plan, failures });
|
|
315
464
|
}
|
|
316
465
|
function readPayload(body, { plan, failures }) {
|
|
317
466
|
if (plan.payload === void 0) {
|
|
@@ -321,7 +470,10 @@ function readPayload(body, { plan, failures }) {
|
|
|
321
470
|
if (payload === void 0) {
|
|
322
471
|
throw failures.invalid(`The message has no payload at '${plan.payload.join(".")}'`);
|
|
323
472
|
}
|
|
324
|
-
return payload
|
|
473
|
+
return withOtherFields(payload, {
|
|
474
|
+
body,
|
|
475
|
+
context: { plan, failures }
|
|
476
|
+
});
|
|
325
477
|
}
|
|
326
478
|
function readEventHeaders(message, plan) {
|
|
327
479
|
if (plan.topLevelHeaders) {
|
|
@@ -411,7 +563,7 @@ function writeMessage(envelope, { plan, failures }) {
|
|
|
411
563
|
};
|
|
412
564
|
const typeAt = typeLocation(envelope, { plan, failures });
|
|
413
565
|
if (typeAt !== void 0) {
|
|
414
|
-
put(typeAt, envelope
|
|
566
|
+
put(typeAt, wireTypeOf(envelope, { plan, failures }));
|
|
415
567
|
}
|
|
416
568
|
if (plan.id !== void 0) {
|
|
417
569
|
put(plan.id, envelope.id);
|
|
@@ -422,12 +574,8 @@ function writeMessage(envelope, { plan, failures }) {
|
|
|
422
574
|
put(location, value);
|
|
423
575
|
}
|
|
424
576
|
}
|
|
425
|
-
const body = writeBody(envelope, { plan, root });
|
|
426
|
-
if (plan.topLevelHeaders) {
|
|
427
|
-
spreadHeaders(envelope, { plan, failures, root: body });
|
|
428
|
-
}
|
|
429
577
|
return {
|
|
430
|
-
body,
|
|
578
|
+
body: writeBody(envelope, { plan, failures, root }),
|
|
431
579
|
headers: Object.fromEntries([
|
|
432
580
|
...eventHeaderEntries(envelope, { plan, failures }),
|
|
433
581
|
...headers,
|
|
@@ -464,11 +612,12 @@ function optionalValues(envelope, { plan, failures }) {
|
|
|
464
612
|
["causationId", envelope.causationId]
|
|
465
613
|
];
|
|
466
614
|
}
|
|
467
|
-
function writeBody(envelope, { plan, root }) {
|
|
615
|
+
function writeBody(envelope, { plan, failures, root }) {
|
|
616
|
+
const { payload, fields } = splitOtherFields(envelope, { plan, failures });
|
|
468
617
|
if (plan.payload === void 0) {
|
|
469
|
-
return
|
|
618
|
+
return payload;
|
|
470
619
|
}
|
|
471
|
-
setAt(root, { path: plan.payload, value:
|
|
620
|
+
setAt(root, { path: plan.payload, value: payload });
|
|
472
621
|
if (plan.headers !== void 0) {
|
|
473
622
|
setAt(root, {
|
|
474
623
|
path: plan.headers,
|
|
@@ -478,6 +627,10 @@ function writeBody(envelope, { plan, root }) {
|
|
|
478
627
|
for (const { path, value } of plan.extraBody) {
|
|
479
628
|
setAt(root, { path, value: typeof value === "function" ? value(envelope) : value });
|
|
480
629
|
}
|
|
630
|
+
if (plan.topLevelHeaders) {
|
|
631
|
+
spreadHeaders(envelope, { plan, failures, root });
|
|
632
|
+
}
|
|
633
|
+
spreadOtherFields(envelope, { failures, fields, root });
|
|
481
634
|
return ordered(root, plan.bodyOrder);
|
|
482
635
|
}
|
|
483
636
|
function spreadHeaders(envelope, { plan, failures, root }) {
|
|
@@ -490,6 +643,20 @@ function spreadHeaders(envelope, { plan, failures, root }) {
|
|
|
490
643
|
setAt(root, { path: [name], value });
|
|
491
644
|
}
|
|
492
645
|
}
|
|
646
|
+
function spreadOtherFields(envelope, {
|
|
647
|
+
failures,
|
|
648
|
+
fields,
|
|
649
|
+
root
|
|
650
|
+
}) {
|
|
651
|
+
for (const [name, value] of fields) {
|
|
652
|
+
if (Object.hasOwn(root, name)) {
|
|
653
|
+
throw failures.unencodable(
|
|
654
|
+
`Event ${envelope.id} keeps a top-level field '${name}' that an event header also writes`
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
setAt(root, { path: [name], value });
|
|
658
|
+
}
|
|
659
|
+
}
|
|
493
660
|
function timeValue(text, { envelope, format }) {
|
|
494
661
|
const milliseconds = envelope.occurredAt.getTime();
|
|
495
662
|
if (format === "epoch-millis") {
|
|
@@ -570,14 +737,14 @@ function createJsonEnvelopeFormat(mapping, {
|
|
|
570
737
|
var HandedOutLedger = class {
|
|
571
738
|
#entries = /* @__PURE__ */ new Map();
|
|
572
739
|
register(lease, entry) {
|
|
573
|
-
this.#entries.set(
|
|
740
|
+
this.#entries.set(chunk2E6NSHGE_cjs.DeliveryLeaseIdentity.of(lease.deliveryId, lease.leaseToken), entry);
|
|
574
741
|
}
|
|
575
742
|
/** Whether the claim with this identity ({@link DeliveryLeaseIdentity.of}) is handed out. */
|
|
576
743
|
has(identity) {
|
|
577
744
|
return this.#entries.has(identity);
|
|
578
745
|
}
|
|
579
746
|
forget(lease) {
|
|
580
|
-
this.#entries.delete(
|
|
747
|
+
this.#entries.delete(chunk2E6NSHGE_cjs.DeliveryLeaseIdentity.of(lease.deliveryId, lease.leaseToken));
|
|
581
748
|
}
|
|
582
749
|
/** Forgets every entry `settled` says is settled. */
|
|
583
750
|
forgetWhere(settled) {
|
|
@@ -687,7 +854,7 @@ var BoundedInteger = class {
|
|
|
687
854
|
/** Returns `value` when it is an integer within the bounds, else throws a {@link ConfigurationError}. */
|
|
688
855
|
static of(value, { name, minimum, maximum }) {
|
|
689
856
|
if (!Number.isInteger(value) || value < minimum || value > maximum) {
|
|
690
|
-
throw new
|
|
857
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
691
858
|
`${name} must be an integer from ${minimum} to ${maximum}, received ${value}`
|
|
692
859
|
);
|
|
693
860
|
}
|
|
@@ -737,7 +904,7 @@ var LaneLeaseTokenFormat = class {
|
|
|
737
904
|
var NonEmptyText = class _NonEmptyText {
|
|
738
905
|
static of(value, name) {
|
|
739
906
|
if (value.length === 0) {
|
|
740
|
-
throw new
|
|
907
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`${name} must not be empty`);
|
|
741
908
|
}
|
|
742
909
|
return value;
|
|
743
910
|
}
|
|
@@ -749,31 +916,31 @@ var NonEmptyText = class _NonEmptyText {
|
|
|
749
916
|
|
|
750
917
|
Object.defineProperty(exports, "CompositeKey", {
|
|
751
918
|
enumerable: true,
|
|
752
|
-
get: function () { return
|
|
919
|
+
get: function () { return chunk2E6NSHGE_cjs.CompositeKey; }
|
|
753
920
|
});
|
|
754
921
|
Object.defineProperty(exports, "DeliveryLeaseIdentity", {
|
|
755
922
|
enumerable: true,
|
|
756
|
-
get: function () { return
|
|
923
|
+
get: function () { return chunk2E6NSHGE_cjs.DeliveryLeaseIdentity; }
|
|
757
924
|
});
|
|
758
925
|
Object.defineProperty(exports, "LeaseSettlement", {
|
|
759
926
|
enumerable: true,
|
|
760
|
-
get: function () { return
|
|
927
|
+
get: function () { return chunk2E6NSHGE_cjs.LeaseSettlement; }
|
|
761
928
|
});
|
|
762
929
|
Object.defineProperty(exports, "Milliseconds", {
|
|
763
930
|
enumerable: true,
|
|
764
|
-
get: function () { return
|
|
931
|
+
get: function () { return chunk2E6NSHGE_cjs.Milliseconds; }
|
|
765
932
|
});
|
|
766
933
|
Object.defineProperty(exports, "PositiveInteger", {
|
|
767
934
|
enumerable: true,
|
|
768
|
-
get: function () { return
|
|
935
|
+
get: function () { return chunk2E6NSHGE_cjs.PositiveInteger; }
|
|
769
936
|
});
|
|
770
937
|
Object.defineProperty(exports, "schedule", {
|
|
771
938
|
enumerable: true,
|
|
772
|
-
get: function () { return
|
|
939
|
+
get: function () { return chunk2E6NSHGE_cjs.schedule; }
|
|
773
940
|
});
|
|
774
941
|
Object.defineProperty(exports, "sleep", {
|
|
775
942
|
enumerable: true,
|
|
776
|
-
get: function () { return
|
|
943
|
+
get: function () { return chunk2E6NSHGE_cjs.sleep; }
|
|
777
944
|
});
|
|
778
945
|
exports.BoundedInteger = BoundedInteger;
|
|
779
946
|
exports.DecodedEventReader = DecodedEventReader;
|
|
@@ -790,7 +957,9 @@ exports.fromHeader = fromHeader;
|
|
|
790
957
|
exports.fromPayloadField = fromPayloadField;
|
|
791
958
|
exports.isJsonObject = isJsonObject;
|
|
792
959
|
exports.mediaTypeOf = mediaTypeOf;
|
|
960
|
+
exports.mergeWireTypes = mergeWireTypes;
|
|
793
961
|
exports.observeRejection = observeRejection;
|
|
962
|
+
exports.withDeclaredWireTypes = withDeclaredWireTypes;
|
|
794
963
|
exports.writeStructuredCloudEvent = writeStructuredCloudEvent;
|
|
795
964
|
//# sourceMappingURL=index.cjs.map
|
|
796
965
|
//# sourceMappingURL=index.cjs.map
|