@relaybus/core 0.4.1 → 1.0.0-next.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/README.md +4 -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 +77 -37
- package/dist/internal/index.cjs.map +1 -1
- package/dist/internal/index.d.cts +24 -2
- package/dist/internal/index.d.ts +24 -2
- package/dist/internal/index.js +41 -3
- 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
|
}
|
|
@@ -96,16 +96,16 @@ function compileWireTypes(wireTypes, { fixed }) {
|
|
|
96
96
|
return { wireTypes: /* @__PURE__ */ new Map(), eventTypes: /* @__PURE__ */ new Map() };
|
|
97
97
|
}
|
|
98
98
|
if (!isJsonObject(wireTypes) || fixed) {
|
|
99
|
-
throw new
|
|
99
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
100
100
|
"jsonEnvelope wireTypes must be an object of event type to wire name, with a type at { body } or { header }"
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
const entries = Object.entries(wireTypes);
|
|
104
104
|
const eventTypes = /* @__PURE__ */ new Map();
|
|
105
105
|
for (const [type, wire] of entries) {
|
|
106
|
-
|
|
106
|
+
chunk2E6NSHGE_cjs.assertEventType(type);
|
|
107
107
|
if (typeof wire !== "string" || wire.length === 0 || eventTypes.has(wire)) {
|
|
108
|
-
throw new
|
|
108
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
109
109
|
`jsonEnvelope wireTypes needs a non-empty wire name for '${type}' that no other type uses`
|
|
110
110
|
);
|
|
111
111
|
}
|
|
@@ -132,12 +132,50 @@ function eventTypeOf(wire, { plan, failures }) {
|
|
|
132
132
|
return type;
|
|
133
133
|
}
|
|
134
134
|
try {
|
|
135
|
-
|
|
135
|
+
chunk2E6NSHGE_cjs.assertEventType(wire);
|
|
136
136
|
} catch (error) {
|
|
137
137
|
throw failures.invalid(`The event type is not a valid event type: ${error.message}`);
|
|
138
138
|
}
|
|
139
139
|
return wire;
|
|
140
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
|
+
}
|
|
141
179
|
|
|
142
180
|
// src/internal/json-envelope-plan.ts
|
|
143
181
|
var OPTIONAL_NAMES = [
|
|
@@ -151,7 +189,7 @@ var TIME_FORMATS = ["rfc3339", "epoch-millis", "epoch-seconds"];
|
|
|
151
189
|
var ARRAY_INDEX = /^(?:0|[1-9]\d*)$/;
|
|
152
190
|
function compile(mapping, transportIds) {
|
|
153
191
|
if (!isJsonObject(mapping)) {
|
|
154
|
-
throw new
|
|
192
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope needs a mapping object");
|
|
155
193
|
}
|
|
156
194
|
const optional = {};
|
|
157
195
|
for (const name of OPTIONAL_NAMES) {
|
|
@@ -163,7 +201,7 @@ function compile(mapping, transportIds) {
|
|
|
163
201
|
const payload = compilePayload(mapping.payload);
|
|
164
202
|
const topLevelHeaders = mapping.headers === "top-level-fields";
|
|
165
203
|
if (topLevelHeaders && payload === void 0) {
|
|
166
|
-
throw new
|
|
204
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope headers 'top-level-fields' needs a body payload");
|
|
167
205
|
}
|
|
168
206
|
const type = compileType(mapping.type);
|
|
169
207
|
const plan = {
|
|
@@ -189,7 +227,7 @@ function compileTimeFormat(field) {
|
|
|
189
227
|
return "rfc3339";
|
|
190
228
|
}
|
|
191
229
|
if (!TIME_FORMATS.includes(format)) {
|
|
192
|
-
throw new
|
|
230
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
193
231
|
`jsonEnvelope occurredAt format must be one of ${TIME_FORMATS.map((name) => `'${name}'`).join(", ")}`
|
|
194
232
|
);
|
|
195
233
|
}
|
|
@@ -199,7 +237,7 @@ function compileExtras(mapping, hasBody) {
|
|
|
199
237
|
const extra = mapping.extra ?? {};
|
|
200
238
|
const bodyOrder = mapping.bodyOrder ?? [];
|
|
201
239
|
if (!hasBody && (extra.body !== void 0 || bodyOrder.length > 0)) {
|
|
202
|
-
throw new
|
|
240
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
203
241
|
"jsonEnvelope with a whole-body payload has no body for extra values or a body order"
|
|
204
242
|
);
|
|
205
243
|
}
|
|
@@ -218,21 +256,21 @@ function compileOtherFields(mapping, hasBody) {
|
|
|
218
256
|
return void 0;
|
|
219
257
|
}
|
|
220
258
|
if (!hasBody) {
|
|
221
|
-
throw new
|
|
259
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope otherFields needs a body payload");
|
|
222
260
|
}
|
|
223
261
|
const field = isJsonObject(otherFields) ? otherFields["payloadField"] : void 0;
|
|
224
262
|
if (typeof field !== "string" || field.length === 0) {
|
|
225
|
-
throw new
|
|
263
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope otherFields must be { payloadField: '<name>' }");
|
|
226
264
|
}
|
|
227
265
|
return field;
|
|
228
266
|
}
|
|
229
267
|
function compileType(type) {
|
|
230
268
|
if (isJsonObject(type) && typeof type["fixed"] === "string") {
|
|
231
|
-
|
|
269
|
+
chunk2E6NSHGE_cjs.assertEventType(type["fixed"]);
|
|
232
270
|
return { fixed: type["fixed"] };
|
|
233
271
|
}
|
|
234
272
|
if (type === void 0) {
|
|
235
|
-
throw new
|
|
273
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError("jsonEnvelope needs a type: { body }, { header } or { fixed }");
|
|
236
274
|
}
|
|
237
275
|
return toLocation(type, "type");
|
|
238
276
|
}
|
|
@@ -242,12 +280,12 @@ function compileId(id, transportIds) {
|
|
|
242
280
|
}
|
|
243
281
|
const names = transportIds.map((name) => `'${name}'`).join(", ");
|
|
244
282
|
if (!isJsonObject(id)) {
|
|
245
|
-
throw new
|
|
283
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
246
284
|
`jsonEnvelope needs an id: { body }, { header } or one of ${names}`
|
|
247
285
|
);
|
|
248
286
|
}
|
|
249
287
|
if ("whenMissing" in id && !transportIds.includes(id["whenMissing"])) {
|
|
250
|
-
throw new
|
|
288
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`jsonEnvelope id whenMissing must be one of ${names}`);
|
|
251
289
|
}
|
|
252
290
|
return toLocation(id, "id");
|
|
253
291
|
}
|
|
@@ -256,7 +294,7 @@ function compilePayload(payload) {
|
|
|
256
294
|
return void 0;
|
|
257
295
|
}
|
|
258
296
|
if (!isJsonObject(payload) || typeof payload["body"] !== "string") {
|
|
259
|
-
throw new
|
|
297
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
260
298
|
"jsonEnvelope needs a payload: { body: '<path>' } or 'whole-body'"
|
|
261
299
|
);
|
|
262
300
|
}
|
|
@@ -267,7 +305,7 @@ function compileHeaders(headers) {
|
|
|
267
305
|
return void 0;
|
|
268
306
|
}
|
|
269
307
|
if (!isJsonObject(headers) || typeof headers["body"] !== "string") {
|
|
270
|
-
throw new
|
|
308
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
271
309
|
"jsonEnvelope headers must be { body: '<path>' } or 'message-headers'"
|
|
272
310
|
);
|
|
273
311
|
}
|
|
@@ -280,14 +318,14 @@ function toLocation(field, label) {
|
|
|
280
318
|
if (isJsonObject(field) && typeof field["body"] === "string") {
|
|
281
319
|
return { label, path: toPath(field["body"], label) };
|
|
282
320
|
}
|
|
283
|
-
throw new
|
|
321
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
284
322
|
`jsonEnvelope ${label} must be { body: '<path>' } or { header: '<name>' }`
|
|
285
323
|
);
|
|
286
324
|
}
|
|
287
325
|
function toPath(path, label) {
|
|
288
326
|
const segments = path.split(".");
|
|
289
327
|
if (segments.some((segment) => segment.length === 0)) {
|
|
290
|
-
throw new
|
|
328
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
291
329
|
`jsonEnvelope ${label} needs a dotted path of non-empty names, received '${path}'`
|
|
292
330
|
);
|
|
293
331
|
}
|
|
@@ -303,7 +341,7 @@ function assertDisjoint(plan) {
|
|
|
303
341
|
];
|
|
304
342
|
const duplicate = headers.find((name, index) => headers.indexOf(name) !== index);
|
|
305
343
|
if (duplicate !== void 0) {
|
|
306
|
-
throw new
|
|
344
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`jsonEnvelope maps header '${duplicate}' twice`);
|
|
307
345
|
}
|
|
308
346
|
const paths = [
|
|
309
347
|
...locations.flatMap((location) => "path" in location ? [location.path] : []),
|
|
@@ -328,10 +366,10 @@ function assertCompatiblePaths(path, other) {
|
|
|
328
366
|
const parting = path.findIndex((segment, position) => segment !== other[position]);
|
|
329
367
|
const both = `'${path.join(".")}' and '${other.join(".")}'`;
|
|
330
368
|
if (parting === -1 || parting === other.length) {
|
|
331
|
-
throw new
|
|
369
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`jsonEnvelope body paths ${both} overlap`);
|
|
332
370
|
}
|
|
333
371
|
if (ARRAY_INDEX.test(path[parting]) !== ARRAY_INDEX.test(other[parting])) {
|
|
334
|
-
throw new
|
|
372
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`jsonEnvelope body paths ${both} mix an array index and a name`);
|
|
335
373
|
}
|
|
336
374
|
}
|
|
337
375
|
|
|
@@ -699,14 +737,14 @@ function createJsonEnvelopeFormat(mapping, {
|
|
|
699
737
|
var HandedOutLedger = class {
|
|
700
738
|
#entries = /* @__PURE__ */ new Map();
|
|
701
739
|
register(lease, entry) {
|
|
702
|
-
this.#entries.set(
|
|
740
|
+
this.#entries.set(chunk2E6NSHGE_cjs.DeliveryLeaseIdentity.of(lease.deliveryId, lease.leaseToken), entry);
|
|
703
741
|
}
|
|
704
742
|
/** Whether the claim with this identity ({@link DeliveryLeaseIdentity.of}) is handed out. */
|
|
705
743
|
has(identity) {
|
|
706
744
|
return this.#entries.has(identity);
|
|
707
745
|
}
|
|
708
746
|
forget(lease) {
|
|
709
|
-
this.#entries.delete(
|
|
747
|
+
this.#entries.delete(chunk2E6NSHGE_cjs.DeliveryLeaseIdentity.of(lease.deliveryId, lease.leaseToken));
|
|
710
748
|
}
|
|
711
749
|
/** Forgets every entry `settled` says is settled. */
|
|
712
750
|
forgetWhere(settled) {
|
|
@@ -816,7 +854,7 @@ var BoundedInteger = class {
|
|
|
816
854
|
/** Returns `value` when it is an integer within the bounds, else throws a {@link ConfigurationError}. */
|
|
817
855
|
static of(value, { name, minimum, maximum }) {
|
|
818
856
|
if (!Number.isInteger(value) || value < minimum || value > maximum) {
|
|
819
|
-
throw new
|
|
857
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(
|
|
820
858
|
`${name} must be an integer from ${minimum} to ${maximum}, received ${value}`
|
|
821
859
|
);
|
|
822
860
|
}
|
|
@@ -866,7 +904,7 @@ var LaneLeaseTokenFormat = class {
|
|
|
866
904
|
var NonEmptyText = class _NonEmptyText {
|
|
867
905
|
static of(value, name) {
|
|
868
906
|
if (value.length === 0) {
|
|
869
|
-
throw new
|
|
907
|
+
throw new chunk2E6NSHGE_cjs.ConfigurationError(`${name} must not be empty`);
|
|
870
908
|
}
|
|
871
909
|
return value;
|
|
872
910
|
}
|
|
@@ -878,31 +916,31 @@ var NonEmptyText = class _NonEmptyText {
|
|
|
878
916
|
|
|
879
917
|
Object.defineProperty(exports, "CompositeKey", {
|
|
880
918
|
enumerable: true,
|
|
881
|
-
get: function () { return
|
|
919
|
+
get: function () { return chunk2E6NSHGE_cjs.CompositeKey; }
|
|
882
920
|
});
|
|
883
921
|
Object.defineProperty(exports, "DeliveryLeaseIdentity", {
|
|
884
922
|
enumerable: true,
|
|
885
|
-
get: function () { return
|
|
923
|
+
get: function () { return chunk2E6NSHGE_cjs.DeliveryLeaseIdentity; }
|
|
886
924
|
});
|
|
887
925
|
Object.defineProperty(exports, "LeaseSettlement", {
|
|
888
926
|
enumerable: true,
|
|
889
|
-
get: function () { return
|
|
927
|
+
get: function () { return chunk2E6NSHGE_cjs.LeaseSettlement; }
|
|
890
928
|
});
|
|
891
929
|
Object.defineProperty(exports, "Milliseconds", {
|
|
892
930
|
enumerable: true,
|
|
893
|
-
get: function () { return
|
|
931
|
+
get: function () { return chunk2E6NSHGE_cjs.Milliseconds; }
|
|
894
932
|
});
|
|
895
933
|
Object.defineProperty(exports, "PositiveInteger", {
|
|
896
934
|
enumerable: true,
|
|
897
|
-
get: function () { return
|
|
935
|
+
get: function () { return chunk2E6NSHGE_cjs.PositiveInteger; }
|
|
898
936
|
});
|
|
899
937
|
Object.defineProperty(exports, "schedule", {
|
|
900
938
|
enumerable: true,
|
|
901
|
-
get: function () { return
|
|
939
|
+
get: function () { return chunk2E6NSHGE_cjs.schedule; }
|
|
902
940
|
});
|
|
903
941
|
Object.defineProperty(exports, "sleep", {
|
|
904
942
|
enumerable: true,
|
|
905
|
-
get: function () { return
|
|
943
|
+
get: function () { return chunk2E6NSHGE_cjs.sleep; }
|
|
906
944
|
});
|
|
907
945
|
exports.BoundedInteger = BoundedInteger;
|
|
908
946
|
exports.DecodedEventReader = DecodedEventReader;
|
|
@@ -919,7 +957,9 @@ exports.fromHeader = fromHeader;
|
|
|
919
957
|
exports.fromPayloadField = fromPayloadField;
|
|
920
958
|
exports.isJsonObject = isJsonObject;
|
|
921
959
|
exports.mediaTypeOf = mediaTypeOf;
|
|
960
|
+
exports.mergeWireTypes = mergeWireTypes;
|
|
922
961
|
exports.observeRejection = observeRejection;
|
|
962
|
+
exports.withDeclaredWireTypes = withDeclaredWireTypes;
|
|
923
963
|
exports.writeStructuredCloudEvent = writeStructuredCloudEvent;
|
|
924
964
|
//# sourceMappingURL=index.cjs.map
|
|
925
965
|
//# sourceMappingURL=index.cjs.map
|