@relaybus/testing 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/dist/index.d.cts CHANGED
@@ -68,10 +68,13 @@ declare class InMemoryTransport implements Transport {
68
68
  #private;
69
69
  readonly name: string;
70
70
  readonly published: PublishedMessage[];
71
+ /** Wire names (event type to name) that routes and catalogs declared; the transport sends events as they are. */
72
+ readonly declaredWireTypes: Record<string, string>;
71
73
  connected: boolean;
72
74
  closed: boolean;
73
75
  constructor(name?: string);
74
76
  connect(): Promise<void>;
77
+ declareWireTypes(wireTypes: Readonly<Record<string, string>>): () => void;
75
78
  /** Makes the next `count` publishes reject, simulating a broker outage. */
76
79
  failNextPublishes(count: number): void;
77
80
  publish(envelope: EventEnvelope, destination: string): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -68,10 +68,13 @@ declare class InMemoryTransport implements Transport {
68
68
  #private;
69
69
  readonly name: string;
70
70
  readonly published: PublishedMessage[];
71
+ /** Wire names (event type to name) that routes and catalogs declared; the transport sends events as they are. */
72
+ readonly declaredWireTypes: Record<string, string>;
71
73
  connected: boolean;
72
74
  closed: boolean;
73
75
  constructor(name?: string);
74
76
  connect(): Promise<void>;
77
+ declareWireTypes(wireTypes: Readonly<Record<string, string>>): () => void;
75
78
  /** Makes the next `count` publishes reject, simulating a broker outage. */
76
79
  failNextPublishes(count: number): void;
77
80
  publish(envelope: EventEnvelope, destination: string): Promise<void>;
package/dist/index.js CHANGED
@@ -1297,6 +1297,49 @@ function payloadFidelityContract(suite) {
1297
1297
  });
1298
1298
  });
1299
1299
  }
1300
+ function transactionIsolationContract(suite) {
1301
+ let store;
1302
+ beforeEach(() => {
1303
+ store = suite.store();
1304
+ });
1305
+ describe("transaction isolation levels", () => {
1306
+ it("recognizes no unrelated error as a serialization failure", () => {
1307
+ for (const error of [new Error("boom"), void 0, null, "text", { code: "23505" }]) {
1308
+ expect(store.isSerializationFailure?.(error) ?? false).toBe(false);
1309
+ }
1310
+ });
1311
+ it("commits and rolls back at every level it lists", async () => {
1312
+ for (const isolationLevel of store.isolationLevels ?? []) {
1313
+ const committed = createEnvelope();
1314
+ await store.transaction(
1315
+ (transaction) => store.append(
1316
+ transaction,
1317
+ [{ event: committed, deliveries: [createDelivery("h")] }],
1318
+ /* @__PURE__ */ new Date(0)
1319
+ ),
1320
+ { timeoutMs: 5e3, isolationLevel }
1321
+ );
1322
+ const abandoned = createEnvelope();
1323
+ await expect(
1324
+ store.transaction(
1325
+ async (transaction) => {
1326
+ await store.append(
1327
+ transaction,
1328
+ [{ event: abandoned, deliveries: [createDelivery("h")] }],
1329
+ /* @__PURE__ */ new Date(0)
1330
+ );
1331
+ throw new Error(`rolled back at ${isolationLevel}`);
1332
+ },
1333
+ { timeoutMs: 5e3, isolationLevel }
1334
+ )
1335
+ ).rejects.toThrow(`rolled back at ${isolationLevel}`);
1336
+ const stored = (await store.listDeliveries({})).map((delivery) => delivery.event.id);
1337
+ expect(stored).toContain(committed.id);
1338
+ expect(stored).not.toContain(abandoned.id);
1339
+ }
1340
+ });
1341
+ });
1342
+ }
1300
1343
 
1301
1344
  // src/event-store-contract.ts
1302
1345
  function eventStoreContract(name, options) {
@@ -1346,6 +1389,7 @@ function eventStoreContract(name, options) {
1346
1389
  completionContract(suite);
1347
1390
  lostLeasesContract(suite);
1348
1391
  payloadFidelityContract(suite);
1392
+ transactionIsolationContract(suite);
1349
1393
  });
1350
1394
  }
1351
1395
 
@@ -1414,6 +1458,8 @@ var FakeClock = class {
1414
1458
  var InMemoryTransport = class {
1415
1459
  name;
1416
1460
  published = [];
1461
+ /** Wire names (event type to name) that routes and catalogs declared; the transport sends events as they are. */
1462
+ declaredWireTypes = {};
1417
1463
  #subscribers = /* @__PURE__ */ new Map();
1418
1464
  #failNextPublishes = 0;
1419
1465
  connected = false;
@@ -1424,6 +1470,11 @@ var InMemoryTransport = class {
1424
1470
  async connect() {
1425
1471
  this.connected = true;
1426
1472
  }
1473
+ declareWireTypes(wireTypes) {
1474
+ return () => {
1475
+ Object.assign(this.declaredWireTypes, wireTypes);
1476
+ };
1477
+ }
1427
1478
  /** Makes the next `count` publishes reject, simulating a broker outage. */
1428
1479
  failNextPublishes(count) {
1429
1480
  this.#failNextPublishes = count;