@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 CHANGED
@@ -72,6 +72,10 @@ await bus.transaction(async () => {
72
72
  });
73
73
  ```
74
74
 
75
+ `bus.transaction(work, { isolationLevel: 'serializable', maxAttempts })` runs the transaction at an isolation
76
+ level (PostgreSQL stores) and reruns `work` after a serialization failure; `work` may then run more than once. See
77
+ [Serializable transactions](https://berkcansavur.github.io/relaybus/recipes/serializable-transactions).
78
+
75
79
  Use a database store in production: [`@relaybus/postgres`](../postgres) or
76
80
  [`@relaybus/mongodb`](../mongodb). `InMemoryEventStore` refuses to start when
77
81
  `NODE_ENV=production` unless `allowInProduction: true`.
@@ -15,6 +15,22 @@ var ConfigurationError = class extends RelayBusError {
15
15
  name = "ConfigurationError";
16
16
  code = "RELAYBUS_CONFIGURATION";
17
17
  };
18
+ var UnknownCatalogEventError = class extends ConfigurationError {
19
+ name = "UnknownCatalogEventError";
20
+ code = "RELAYBUS_CATALOG_UNKNOWN_EVENT";
21
+ };
22
+ var DuplicateRouteEventError = class extends ConfigurationError {
23
+ name = "DuplicateRouteEventError";
24
+ code = "RELAYBUS_ROUTE_DUPLICATE_EVENT";
25
+ };
26
+ var WireTypeCollisionError = class extends ConfigurationError {
27
+ name = "WireTypeCollisionError";
28
+ code = "RELAYBUS_WIRE_TYPE_COLLISION";
29
+ };
30
+ var WireTypesUnsupportedError = class extends ConfigurationError {
31
+ name = "WireTypesUnsupportedError";
32
+ code = "RELAYBUS_WIRE_TYPES_UNSUPPORTED";
33
+ };
18
34
  var TransactionRequiredError = class extends RelayBusError {
19
35
  name = "TransactionRequiredError";
20
36
  code = "RELAYBUS_TRANSACTION_REQUIRED";
@@ -23,6 +39,10 @@ var TransactionTimeoutError = class extends RelayBusError {
23
39
  name = "TransactionTimeoutError";
24
40
  code = "RELAYBUS_TRANSACTION_TIMEOUT";
25
41
  };
42
+ var TransactionIsolationConflictError = class extends RelayBusError {
43
+ name = "TransactionIsolationConflictError";
44
+ code = "RELAYBUS_TRANSACTION_ISOLATION_CONFLICT";
45
+ };
26
46
  var NonRetryableError = class extends RelayBusError {
27
47
  name = "NonRetryableError";
28
48
  code = "RELAYBUS_NON_RETRYABLE";
@@ -298,6 +318,7 @@ exports.ConfigurationError = ConfigurationError;
298
318
  exports.DeliveryLeaseIdentity = DeliveryLeaseIdentity;
299
319
  exports.DispatcherStoppedError = DispatcherStoppedError;
300
320
  exports.DrainIncompleteError = DrainIncompleteError;
321
+ exports.DuplicateRouteEventError = DuplicateRouteEventError;
301
322
  exports.EventValidationError = EventValidationError;
302
323
  exports.HandlerTimeoutError = HandlerTimeoutError;
303
324
  exports.InvalidEnvelopeError = InvalidEnvelopeError;
@@ -309,8 +330,12 @@ exports.Milliseconds = Milliseconds;
309
330
  exports.NonRetryableError = NonRetryableError;
310
331
  exports.PositiveInteger = PositiveInteger;
311
332
  exports.RelayBusError = RelayBusError;
333
+ exports.TransactionIsolationConflictError = TransactionIsolationConflictError;
312
334
  exports.TransactionRequiredError = TransactionRequiredError;
313
335
  exports.TransactionTimeoutError = TransactionTimeoutError;
336
+ exports.UnknownCatalogEventError = UnknownCatalogEventError;
337
+ exports.WireTypeCollisionError = WireTypeCollisionError;
338
+ exports.WireTypesUnsupportedError = WireTypesUnsupportedError;
314
339
  exports.assertEventType = assertEventType;
315
340
  exports.defineEvent = defineEvent;
316
341
  exports.keyFromDefinition = keyFromDefinition;
@@ -319,5 +344,5 @@ exports.sleep = sleep;
319
344
  exports.toErrorInfo = toErrorInfo;
320
345
  exports.toMilliseconds = toMilliseconds;
321
346
  exports.validatePayload = validatePayload;
322
- //# sourceMappingURL=chunk-J76M7XTS.cjs.map
323
- //# sourceMappingURL=chunk-J76M7XTS.cjs.map
347
+ //# sourceMappingURL=chunk-2E6NSHGE.cjs.map
348
+ //# sourceMappingURL=chunk-2E6NSHGE.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/duration.ts","../src/event.ts","../src/store-kit/lease-settlement.ts","../src/values/composite-key.ts","../src/internal/timers.ts","../src/values/milliseconds.ts","../src/values/delivery-lease-identity.ts","../src/values/positive-integer.ts"],"names":[],"mappings":";;;AAGO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA;AAAA,EAE9B,IAAA,GAAO,eAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMP,IAAA,GAAe,gBAAA;AAC1B;AAGO,IAAM,kBAAA,GAAN,cAAiC,aAAA,CAAc;AAAA,EAC3C,IAAA,GAAO,oBAAA;AAAA,EACE,IAAA,GAAe,wBAAA;AACnC;AAMO,IAAM,wBAAA,GAAN,cAAuC,kBAAA,CAAmB;AAAA,EACtD,IAAA,GAAO,0BAAA;AAAA,EACE,IAAA,GAAe,gCAAA;AACnC;AAGO,IAAM,wBAAA,GAAN,cAAuC,kBAAA,CAAmB;AAAA,EACtD,IAAA,GAAO,0BAAA;AAAA,EACE,IAAA,GAAe,gCAAA;AACnC;AAMO,IAAM,sBAAA,GAAN,cAAqC,kBAAA,CAAmB;AAAA,EACpD,IAAA,GAAO,wBAAA;AAAA,EACE,IAAA,GAAe,8BAAA;AACnC;AAMO,IAAM,yBAAA,GAAN,cAAwC,kBAAA,CAAmB;AAAA,EACvD,IAAA,GAAO,2BAAA;AAAA,EACE,IAAA,GAAe,iCAAA;AACnC;AAOO,IAAM,wBAAA,GAAN,cAAuC,aAAA,CAAc;AAAA,EACjD,IAAA,GAAO,0BAAA;AAAA,EACE,IAAA,GAAe,+BAAA;AACnC;AAOO,IAAM,uBAAA,GAAN,cAAsC,aAAA,CAAc;AAAA,EAChD,IAAA,GAAO,yBAAA;AAAA,EACE,IAAA,GAAe,8BAAA;AACnC;AAQO,IAAM,iCAAA,GAAN,cAAgD,aAAA,CAAc;AAAA,EAC1D,IAAA,GAAO,mCAAA;AAAA,EACE,IAAA,GAAe,yCAAA;AACnC;A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AAG;AACzC,MAAA,MAAM,IAAI,mBAAmB,CAAA,EAAG,IAAI,yCAAyC,MAAA,CAAO,KAAK,CAAC,CAAA,CAAE,CAAA;AAAA,IAC9F;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACF","file":"chunk-2E6NSHGE.cjs","sourcesContent":["/**\n * Base class of every error thrown by relaybus.\n */\nexport class RelayBusError extends Error {\n // Explicit names survive minification, unlike `new.target.name`.\n override name = 'RelayBusError';\n /**\n * Stable, machine-readable identifier of the error class, such as `RELAYBUS_LEASE_LOST`.\n * Unlike `name` and `message`, a code is never renamed once released; branch on it in\n * alerts and dashboards. Subclasses declared outside relaybus inherit `RELAYBUS_ERROR`.\n */\n readonly code: string = 'RELAYBUS_ERROR';\n}\n\n/** Invalid options passed to a relaybus component. */\nexport class ConfigurationError extends RelayBusError {\n override name = 'ConfigurationError';\n override readonly code: string = 'RELAYBUS_CONFIGURATION';\n}\n\n/**\n * A catalog or a catalog route names an event that is not part of the catalog, for example a wire\n * name for an event the catalog does not have.\n */\nexport class UnknownCatalogEventError extends ConfigurationError {\n override name = 'UnknownCatalogEventError';\n override readonly code: string = 'RELAYBUS_CATALOG_UNKNOWN_EVENT';\n}\n\n/** A catalog route sends an event to a destination that another route already sends it to. */\nexport class DuplicateRouteEventError extends ConfigurationError {\n override name = 'DuplicateRouteEventError';\n override readonly code: string = 'RELAYBUS_ROUTE_DUPLICATE_EVENT';\n}\n\n/**\n * Wire names clash: one event type has two wire names on a transport, or two event types share one,\n * whether they come from catalogs, routes or the `wireTypes` of a codec.\n */\nexport class WireTypeCollisionError extends ConfigurationError {\n override name = 'WireTypeCollisionError';\n override readonly code: string = 'RELAYBUS_WIRE_TYPE_COLLISION';\n}\n\n/**\n * A route or catalog declares wire names for a transport whose codec cannot carry them: the\n * transport has no `declareWireTypes`, or its codec is not a `jsonEnvelope` with a type to map.\n */\nexport class WireTypesUnsupportedError extends ConfigurationError {\n override name = 'WireTypesUnsupportedError';\n override readonly code: string = 'RELAYBUS_WIRE_TYPES_UNSUPPORTED';\n}\n\n/**\n * Thrown by `publish` when no transaction can be found and the bus runs with\n * `transactionMode: 'required'` (the default). Publishing outside a transaction\n * would reintroduce the dual-write problem the outbox exists to prevent.\n */\nexport class TransactionRequiredError extends RelayBusError {\n override name = 'TransactionRequiredError';\n override readonly code: string = 'RELAYBUS_TRANSACTION_REQUIRED';\n}\n\n/**\n * A `bus.transaction` (or `@RelayBusTransaction()` method) ran past its `transactionTimeout` and\n * was rolled back. Its `cause` is the error the database raised when it ended the transaction,\n * when there was one. Usually a slow call to another service made inside the transaction.\n */\nexport class TransactionTimeoutError extends RelayBusError {\n override name = 'TransactionTimeoutError';\n override readonly code: string = 'RELAYBUS_TRANSACTION_TIMEOUT';\n}\n\n/**\n * A `@RelayBusTransaction({ isolationLevel })` method was called inside a transaction that was not\n * opened by relaybus at that same level. The isolation level of a running transaction cannot be\n * changed, so the method cannot join it: open the outer transaction at the level, or leave the\n * level off the inner method.\n */\nexport class TransactionIsolationConflictError extends RelayBusError {\n override name = 'TransactionIsolationConflictError';\n override readonly code: string = 'RELAYBUS_TRANSACTION_ISOLATION_CONFLICT';\n}\n\n/**\n * Throw from a handler to dead-letter the delivery immediately, skipping the\n * remaining retry attempts.\n */\nexport class NonRetryableError extends RelayBusError {\n override name = 'NonRetryableError';\n override readonly code: string = 'RELAYBUS_NON_RETRYABLE';\n}\n\n/** A payload failed its event schema. Never retried: the payload will not change. */\nexport class EventValidationError extends NonRetryableError {\n override name = 'EventValidationError';\n override readonly code: string = 'RELAYBUS_EVENT_VALIDATION';\n\n constructor(\n message: string,\n readonly issues: readonly ValidationIssue[],\n ) {\n super(message);\n }\n}\n\n/**\n * A message received from a broker is not a valid event. Never retried:\n * transports should dead-letter it instead of redelivering it forever.\n */\nexport class InvalidEnvelopeError extends NonRetryableError {\n override name = 'InvalidEnvelopeError';\n override readonly code: string = 'RELAYBUS_INVALID_ENVELOPE';\n}\n\n/** The worker no longer owns the delivery it was processing. */\nexport class LeaseLostError extends RelayBusError {\n override name = 'LeaseLostError';\n override readonly code: string = 'RELAYBUS_LEASE_LOST';\n /**\n * Whether the store said so (a fenced write returned false). A worker that only noticed\n * locally that its lease ran out may still own the delivery in the store and has to give it back.\n */\n readonly storeConfirmed: boolean;\n\n constructor(message: string, options: { readonly storeConfirmed?: boolean } = {}) {\n super(message);\n this.storeConfirmed = options.storeConfirmed ?? false;\n }\n}\n\n/** A handler did not settle within its configured timeout. Retried like any failure. */\nexport class HandlerTimeoutError extends RelayBusError {\n override name = 'HandlerTimeoutError';\n override readonly code: string = 'RELAYBUS_HANDLER_TIMEOUT';\n}\n\n/**\n * Reason of a handler's abort signal when the bus stops before the handler\n * finished. The delivery is released and runs again without losing an attempt.\n */\nexport class DispatcherStoppedError extends RelayBusError {\n override name = 'DispatcherStoppedError';\n override readonly code: string = 'RELAYBUS_DISPATCHER_STOPPED';\n}\n\n/**\n * A delivery came back after its lease expired on its last attempt, so it is\n * dead-lettered without running its handler again.\n */\nexport class AttemptsExhaustedError extends RelayBusError {\n override name = 'AttemptsExhaustedError';\n override readonly code: string = 'RELAYBUS_ATTEMPTS_EXHAUSTED';\n}\n\n/** A lifecycle method was called in a state that does not allow it, such as starting a bus twice. */\nexport class LifecycleError extends RelayBusError {\n override name = 'LifecycleError';\n override readonly code: string = 'RELAYBUS_LIFECYCLE';\n}\n\n/** `drain` still found due deliveries after its maximum number of batches. */\nexport class DrainIncompleteError extends RelayBusError {\n override name = 'DrainIncompleteError';\n override readonly code: string = 'RELAYBUS_DRAIN_INCOMPLETE';\n}\n\nexport interface ValidationIssue {\n readonly message: string;\n readonly path?: readonly PropertyKey[] | undefined;\n}\n\n/** Serializable snapshot of an error, stored with failed deliveries. */\nexport interface ErrorInfo {\n readonly name: string;\n readonly message: string;\n readonly stack?: string | undefined;\n /** The {@link RelayBusError.code} of a relaybus error; absent for any other error. */\n readonly code?: string | undefined;\n}\n\nexport function toErrorInfo(error: unknown): ErrorInfo {\n if (error instanceof RelayBusError) {\n return { name: error.name, message: error.message, stack: error.stack, code: error.code };\n }\n if (error instanceof Error) {\n return { name: error.name, message: error.message, stack: error.stack };\n }\n return { name: 'NonError', message: safeStringify(error) };\n}\n\nfunction safeStringify(value: unknown): string {\n if (typeof value === 'string') {\n return value;\n }\n try {\n return JSON.stringify(value) ?? String(value);\n } catch {\n return String(value);\n }\n}\n","import { ConfigurationError } from './errors.js';\n\n/**\n * A duration in milliseconds, or a string such as `'250ms'`, `'30s'`, `'5m'`,\n * `'1h'` or `'7d'`.\n */\nexport type Duration = number | `${number}${DurationUnit}`;\n\ntype DurationUnit = 'ms' | 's' | 'm' | 'h' | 'd';\n\nconst MILLISECONDS_PER_UNIT: Record<DurationUnit, number> = {\n ms: 1,\n s: 1_000,\n m: 60_000,\n h: 3_600_000,\n d: 86_400_000,\n};\n\nconst DURATION_PATTERN = /^(\\d+(?:\\.\\d+)?)(ms|s|m|h|d)$/;\n\nexport function toMilliseconds(value: Duration, name: string): number {\n if (typeof value === 'number') {\n if (!Number.isFinite(value) || value < 0) {\n throw new ConfigurationError(\n `${name} must be a non-negative finite number of milliseconds, received ${value}`,\n );\n }\n return value;\n }\n const match = DURATION_PATTERN.exec(value);\n if (match === null) {\n throw new ConfigurationError(\n `${name} must look like '500ms', '30s', '5m', '1h' or '7d', received '${value}'`,\n );\n }\n const [, amount, unit] = match as unknown as [string, string, DurationUnit];\n return Number(amount) * MILLISECONDS_PER_UNIT[unit];\n}\n\n/** Largest delay Node.js timers support. Longer values fire after 1ms instead. */\nexport const MAX_TIMER_DELAY_MS = 2_147_483_647;\n","import { ConfigurationError, EventValidationError } from './errors.js';\nimport type { StandardSchemaV1 } from './standard-schema.js';\n\n/** String metadata carried with an event, such as `traceparent`. */\nexport type EventHeaders = Readonly<Record<string, string>>;\n\n/**\n * An event as stored and delivered. Field names follow CloudEvents where they\n * overlap (`id`, `type`, `source`, `time` as `occurredAt`, `subject` as `key`).\n */\nexport interface EventEnvelope<TPayload = unknown> {\n /** Globally unique id. Handlers and transports deduplicate on it. */\n readonly id: string;\n /** Event type, for example `order.created.v1`. */\n readonly type: string;\n /** Logical name of the publishing service. */\n readonly source: string;\n /** Ordering and partition key. Events sharing a key are handled in publish order. */\n readonly key: string | null;\n readonly payload: TPayload;\n readonly headers: EventHeaders;\n /** Id shared by every event of one business flow. */\n readonly correlationId: string | null;\n /** Id of the event whose handler published this one. */\n readonly causationId: string | null;\n readonly occurredAt: Date;\n}\n\n/** An instance of a class created with {@link defineEvent}. */\nexport interface DomainEvent<TPayload = unknown> {\n readonly type: string;\n readonly payload: TPayload;\n}\n\n/**\n * Derives the ordering key of an event from its validated payload. Declared bivariantly so an\n * event class stays assignable wherever its payload type is widened.\n */\nexport type EventKeyFunction<TPayload> = {\n bivarianceHack(payload: TPayload): string;\n}['bivarianceHack'];\n\n/** A class created with {@link defineEvent}. */\nexport interface EventClass<TPayload = unknown> {\n new (payload: TPayload): DomainEvent<TPayload>;\n readonly type: string;\n readonly schema: StandardSchemaV1<unknown, TPayload> | undefined;\n /** The `key` given to {@link defineEvent}; undefined for events without one. */\n readonly key?: EventKeyFunction<TPayload> | undefined;\n}\n\n/** Payload type of an event class: `PayloadOf<typeof OrderPlaced>`. */\nexport type PayloadOf<TEvent> = TEvent extends EventClass<infer TPayload> ? TPayload : never;\n\n/** Anything that names an event type: an event class or the type string itself. */\nexport type EventReference = { readonly type: string } | string;\n\nexport interface DefineEventOptions<TSchema extends StandardSchemaV1> {\n /** Validates the payload on publish and before every handler call. */\n readonly schema: TSchema;\n /** Ordering key of every event of this type, from its validated payload. See {@link DefineEventKeyOptions}. */\n readonly key?: (payload: StandardSchemaV1.InferOutput<TSchema>) => string;\n}\n\nexport interface DefineEventKeyOptions<TPayload> {\n /**\n * Ordering key of every event of this type, from its payload: `(payload) => payload.orderId`.\n * Typed from the payload, so a missing field or a non-string fails to compile. `publish` uses it\n * when it is given no `key`; an explicit `key` option wins (for `publishAll`, the one key of the\n * call applies to every event). It must return a non-empty string.\n */\n readonly key: (payload: TPayload) => string;\n}\n\nconst EVENT_TYPE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,254}$/;\n\nexport function assertEventType(type: string): void {\n if (!EVENT_TYPE_PATTERN.test(type)) {\n throw new ConfigurationError(\n `Event type '${type}' must be 1-255 characters of letters, digits, '.', '_', ':', '/' or '-', starting with a letter or digit`,\n );\n }\n}\n\n/**\n * Defines an event type. Extend the returned class to name it:\n *\n * ```ts\n * export class OrderPlaced extends defineEvent<{ orderId: string }>('order.placed.v1') {}\n * export class OrderShipped extends defineEvent('order.shipped.v1', { schema: orderShippedSchema }) {}\n * export class OrderPaid extends defineEvent('order.paid.v1', {\n * schema: orderPaidSchema,\n * key: (payload) => payload.orderId,\n * }) {}\n * export class OrderCancelled extends defineEvent<{ orderId: string }>('order.cancelled.v1', {\n * key: (payload) => payload.orderId,\n * }) {}\n * ```\n */\nexport function defineEvent<TSchema extends StandardSchemaV1>(\n type: string,\n options: DefineEventOptions<TSchema>,\n): EventClass<StandardSchemaV1.InferOutput<TSchema>>;\nexport function defineEvent<TPayload>(\n type: string,\n options?: DefineEventKeyOptions<TPayload>,\n): EventClass<TPayload>;\nexport function defineEvent(\n type: string,\n options?: Partial<DefineEventOptions<StandardSchemaV1>>,\n): EventClass<unknown> {\n assertEventType(type);\n const schema = options?.schema;\n const key = options?.key;\n return class DefinedEvent implements DomainEvent<unknown> {\n static readonly type = type;\n static readonly schema = schema;\n static readonly key = key;\n readonly type = type;\n constructor(readonly payload: unknown) {}\n };\n}\n\n/** Runs a Standard Schema and returns its output, or throws {@link EventValidationError}. */\n// eslint-disable-next-line relaybus/max-two-params -- exported API validatePayload keeps its public signature\nexport async function validatePayload<TPayload>(\n type: string,\n schema: StandardSchemaV1<unknown, TPayload> | undefined,\n payload: unknown,\n): Promise<TPayload> {\n if (schema === undefined) {\n return payload as TPayload;\n }\n const result = await schema['~standard'].validate(payload);\n if (result.issues !== undefined) {\n const issues = result.issues.map((issue) => ({\n message: issue.message,\n path: issue.path?.map((segment) => (typeof segment === 'object' ? segment.key : segment)),\n }));\n throw new EventValidationError(\n `Payload of '${type}' failed validation: ${issues.map((issue) => issue.message).join('; ')}`,\n issues,\n );\n }\n return result.value;\n}\n\n/**\n * The ordering key an event of `event`'s class takes from its definition, or null when the class\n * defines no key.\n *\n * @throws ConfigurationError when the key function returns an empty string or no string.\n */\nexport function keyFromDefinition(event: DomainEvent, payload: unknown): string | null {\n const keyOf = (event.constructor as Partial<EventClass>).key;\n if (keyOf === undefined) {\n return null;\n }\n const key: unknown = keyOf(payload);\n if (typeof key !== 'string' || key.length === 0) {\n throw new ConfigurationError(\n `The key function of '${event.type}' must return a non-empty string | returned=${typeof key === 'string' ? \"''\" : typeof key}`,\n );\n }\n return key;\n}\n","import type { ErrorInfo } from '../errors.js';\nimport type { LeaseReference } from '../event-store.js';\n\n/** How a claim ends without completing: retried later, given back, or dead-lettered. */\nexport type SettlementChange =\n | {\n readonly kind: 'reschedule';\n readonly availableAt: Date;\n readonly error: ErrorInfo;\n readonly now: Date;\n }\n | { readonly kind: 'release'; readonly now: Date }\n | { readonly kind: 'bury'; readonly error: ErrorInfo; readonly now: Date };\n\n/** A change of the claim a lease names. */\nexport type LeaseChange = { readonly lease: LeaseReference; readonly change: SettlementChange };\n\n/** A lease renewal; `now` for a store that records when it happened. */\nexport type LeaseExtension = {\n readonly lease: LeaseReference;\n readonly leaseExpiresAt: Date;\n readonly now?: Date;\n};\n\n/**\n * What a store answers about a lease: at once when it answers from memory, later when it asks a\n * database. Answering at once keeps the in-memory store as fast (in microtasks) as it always was.\n */\nexport type StoreAnswer = boolean | Promise<boolean>;\n\n/**\n * The fenced settlement skeleton every event store shares: find the claim a lease names (a lease\n * this store cannot have issued, or whose claim ended, is not held and changes nothing), apply the\n * change fenced by the lease, then forget the lease as handed out once the store answered.\n * A store supplies only how it finds a held claim, how it writes a change and a renewal, and its\n * bookkeeping of handed-out leases.\n */\nexport abstract class LeaseSettlement<THeld> {\n /** Renews the lease when it is still held; false otherwise. */\n extendLease(extension: LeaseExtension): StoreAnswer {\n const held = this.findHeld(extension.lease);\n return held === undefined ? false : this.writeExtension(held, extension);\n }\n\n /**\n * Applies `change` when the lease is still held. Once the store answered (either way) the lease\n * is forgotten as handed out; when the write throws it stays registered, since the caller may\n * retry with the same lease.\n */\n changeClaim(request: LeaseChange): StoreAnswer {\n const held = this.findHeld(request.lease);\n if (held === undefined) {\n return false;\n }\n const changed = this.writeChange(held, request);\n if (typeof changed === 'boolean') {\n this.forgetHandedOut(request.lease);\n return changed;\n }\n return this.#forgetOnceAnswered(request.lease, changed);\n }\n\n /** The claim `lease` names, when this store issued the lease; undefined otherwise. */\n protected abstract findHeld(lease: LeaseReference): THeld | undefined;\n\n protected abstract writeChange(held: THeld, request: LeaseChange): StoreAnswer;\n\n protected abstract writeExtension(held: THeld, extension: LeaseExtension): StoreAnswer;\n\n /** Drops `lease` from the store's handed-out bookkeeping; nothing for a store that keeps none. */\n protected abstract forgetHandedOut(lease: LeaseReference): void;\n\n async #forgetOnceAnswered(lease: LeaseReference, answer: Promise<boolean>): Promise<boolean> {\n const changed = await answer;\n this.forgetHandedOut(lease);\n return changed;\n }\n}\n","/** Separates the parts of a composite key: no identifier, handler id or ordering key contains it. */\nconst SEPARATOR = '\\u0000';\n\n/**\n * Two identifiers joined into one map or set key, such as an event id and a handler id, or a\n * handler id and an ordering key. The NUL separator keeps `('a:b', 'c')` and `('a', 'b:c')` apart.\n * Keys are plain strings, so they cost nothing more than the template literal they replace.\n */\nexport abstract class CompositeKey {\n static of(first: string, second: string): string {\n return `${first}${SEPARATOR}${second}`;\n }\n\n /** The start every key of `first` shares, to find them all by prefix. */\n static startOf(first: string): string {\n return `${first}${SEPARATOR}`;\n }\n}\n","import type { Clock } from '../clock.js';\n\n/** A task for {@link schedule}: what runs, after how long, whether it repeats and keeps the process alive. */\nexport type ScheduledTask = Parameters<NonNullable<Clock['schedule']>>[0];\n\n/** Cancels a scheduled task; harmless once it ran or was cancelled. */\nexport type CancelTimer = () => void;\n\n/**\n * The one place relaybus starts timers: through `clock.schedule` when the clock controls timers,\n * else with the platform timers.\n */\nexport function schedule(clock: Clock, task: ScheduledTask): CancelTimer {\n return clock.schedule === undefined ? scheduleOnPlatform(task) : clock.schedule(task);\n}\n\n/** Resolves after `milliseconds` on the timers of `clock`. */\nexport function sleep(clock: Clock, milliseconds: number): Promise<void> {\n return new Promise((resolve) => {\n schedule(clock, { run: resolve, delayMs: milliseconds });\n });\n}\n\nfunction scheduleOnPlatform(task: ScheduledTask): CancelTimer {\n if (task.repeat === true) {\n const interval = setInterval(task.run, task.delayMs);\n if (task.unref === true) {\n interval.unref();\n }\n return () => clearInterval(interval);\n }\n const timeout = setTimeout(task.run, task.delayMs);\n if (task.unref === true) {\n timeout.unref();\n }\n return () => clearTimeout(timeout);\n}\n","import { MAX_TIMER_DELAY_MS, toMilliseconds, type Duration } from '../duration.js';\nimport { ConfigurationError } from '../errors.js';\n\n/**\n * A configured length of time, converted once from a {@link Duration} option. Each factory names\n * the option, so its refusal says which one was wrong.\n */\nexport abstract class Milliseconds {\n /** Zero or more milliseconds. */\n static of(value: Duration, name: string): number {\n return toMilliseconds(value, name);\n }\n\n /** More than zero milliseconds: a wait, a timeout or an age that must pass at all. */\n static positive(value: Duration, name: string): number {\n const milliseconds = toMilliseconds(value, name);\n if (milliseconds === 0) {\n throw new ConfigurationError(`${name} must be greater than zero`);\n }\n return milliseconds;\n }\n\n /** A duration that drives a timer: more than zero, and no longer than timers can represent. */\n static forTimer(value: Duration, name: string): number {\n const milliseconds = Milliseconds.positive(value, name);\n if (milliseconds > MAX_TIMER_DELAY_MS) {\n throw new ConfigurationError(\n `${name} must not exceed ${MAX_TIMER_DELAY_MS}ms (about 24.8 days), received ${milliseconds}ms`,\n );\n }\n return milliseconds;\n }\n}\n","import { CompositeKey } from './composite-key.js';\n\n/**\n * Identifies one claim of a delivery: the delivery id with the exact lease token it was handed out\n * with. Two claims of the same delivery (an expired one and the current one) have different\n * identities, so bookkeeping of the older can never replace or remove the newer one's.\n */\nexport abstract class DeliveryLeaseIdentity {\n static of(deliveryId: string, leaseToken: string): string {\n return CompositeKey.of(deliveryId, leaseToken);\n }\n\n /** The start of the identity of every claim of `deliveryId`. */\n static prefixOf(deliveryId: string): string {\n return CompositeKey.startOf(deliveryId);\n }\n}\n","import { ConfigurationError } from '../errors.js';\n\n/** A count option that must be a whole number of at least 1: a batch size, attempts, a limit. */\nexport abstract class PositiveInteger {\n /** Returns `value` when it is an integer of at least 1, else throws a {@link ConfigurationError} naming the option. */\n static of(value: number, name: string): number {\n if (!Number.isInteger(value) || value < 1) {\n throw new ConfigurationError(`${name} must be a positive integer, received ${String(value)}`);\n }\n return value;\n }\n}\n"]}
@@ -13,6 +13,22 @@ var ConfigurationError = class extends RelayBusError {
13
13
  name = "ConfigurationError";
14
14
  code = "RELAYBUS_CONFIGURATION";
15
15
  };
16
+ var UnknownCatalogEventError = class extends ConfigurationError {
17
+ name = "UnknownCatalogEventError";
18
+ code = "RELAYBUS_CATALOG_UNKNOWN_EVENT";
19
+ };
20
+ var DuplicateRouteEventError = class extends ConfigurationError {
21
+ name = "DuplicateRouteEventError";
22
+ code = "RELAYBUS_ROUTE_DUPLICATE_EVENT";
23
+ };
24
+ var WireTypeCollisionError = class extends ConfigurationError {
25
+ name = "WireTypeCollisionError";
26
+ code = "RELAYBUS_WIRE_TYPE_COLLISION";
27
+ };
28
+ var WireTypesUnsupportedError = class extends ConfigurationError {
29
+ name = "WireTypesUnsupportedError";
30
+ code = "RELAYBUS_WIRE_TYPES_UNSUPPORTED";
31
+ };
16
32
  var TransactionRequiredError = class extends RelayBusError {
17
33
  name = "TransactionRequiredError";
18
34
  code = "RELAYBUS_TRANSACTION_REQUIRED";
@@ -21,6 +37,10 @@ var TransactionTimeoutError = class extends RelayBusError {
21
37
  name = "TransactionTimeoutError";
22
38
  code = "RELAYBUS_TRANSACTION_TIMEOUT";
23
39
  };
40
+ var TransactionIsolationConflictError = class extends RelayBusError {
41
+ name = "TransactionIsolationConflictError";
42
+ code = "RELAYBUS_TRANSACTION_ISOLATION_CONFLICT";
43
+ };
24
44
  var NonRetryableError = class extends RelayBusError {
25
45
  name = "NonRetryableError";
26
46
  code = "RELAYBUS_NON_RETRYABLE";
@@ -290,6 +310,6 @@ var PositiveInteger = class {
290
310
  }
291
311
  };
292
312
 
293
- export { AttemptsExhaustedError, CompositeKey, ConfigurationError, DeliveryLeaseIdentity, DispatcherStoppedError, DrainIncompleteError, EventValidationError, HandlerTimeoutError, InvalidEnvelopeError, LeaseLostError, LeaseSettlement, LifecycleError, MAX_TIMER_DELAY_MS, Milliseconds, NonRetryableError, PositiveInteger, RelayBusError, TransactionRequiredError, TransactionTimeoutError, assertEventType, defineEvent, keyFromDefinition, schedule, sleep, toErrorInfo, toMilliseconds, validatePayload };
294
- //# sourceMappingURL=chunk-NOR5JHVN.js.map
295
- //# sourceMappingURL=chunk-NOR5JHVN.js.map
313
+ export { AttemptsExhaustedError, CompositeKey, ConfigurationError, DeliveryLeaseIdentity, DispatcherStoppedError, DrainIncompleteError, DuplicateRouteEventError, EventValidationError, HandlerTimeoutError, InvalidEnvelopeError, LeaseLostError, LeaseSettlement, LifecycleError, MAX_TIMER_DELAY_MS, Milliseconds, NonRetryableError, PositiveInteger, RelayBusError, TransactionIsolationConflictError, TransactionRequiredError, TransactionTimeoutError, UnknownCatalogEventError, WireTypeCollisionError, WireTypesUnsupportedError, assertEventType, defineEvent, keyFromDefinition, schedule, sleep, toErrorInfo, toMilliseconds, validatePayload };
314
+ //# sourceMappingURL=chunk-6PQ673MW.js.map
315
+ //# sourceMappingURL=chunk-6PQ673MW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/duration.ts","../src/event.ts","../src/store-kit/lease-settlement.ts","../src/values/composite-key.ts","../src/internal/timers.ts","../src/values/milliseconds.ts","../src/values/delivery-lease-identity.ts","../src/values/positive-integer.ts"],"names":[],"mappings":";AAG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sourcesContent":["/**\n * Base class of every error thrown by relaybus.\n */\nexport class RelayBusError extends Error {\n // Explicit names survive minification, unlike `new.target.name`.\n override name = 'RelayBusError';\n /**\n * Stable, machine-readable identifier of the error class, such as `RELAYBUS_LEASE_LOST`.\n * Unlike `name` and `message`, a code is never renamed once released; branch on it in\n * alerts and dashboards. Subclasses declared outside relaybus inherit `RELAYBUS_ERROR`.\n */\n readonly code: string = 'RELAYBUS_ERROR';\n}\n\n/** Invalid options passed to a relaybus component. */\nexport class ConfigurationError extends RelayBusError {\n override name = 'ConfigurationError';\n override readonly code: string = 'RELAYBUS_CONFIGURATION';\n}\n\n/**\n * A catalog or a catalog route names an event that is not part of the catalog, for example a wire\n * name for an event the catalog does not have.\n */\nexport class UnknownCatalogEventError extends ConfigurationError {\n override name = 'UnknownCatalogEventError';\n override readonly code: string = 'RELAYBUS_CATALOG_UNKNOWN_EVENT';\n}\n\n/** A catalog route sends an event to a destination that another route already sends it to. */\nexport class DuplicateRouteEventError extends ConfigurationError {\n override name = 'DuplicateRouteEventError';\n override readonly code: string = 'RELAYBUS_ROUTE_DUPLICATE_EVENT';\n}\n\n/**\n * Wire names clash: one event type has two wire names on a transport, or two event types share one,\n * whether they come from catalogs, routes or the `wireTypes` of a codec.\n */\nexport class WireTypeCollisionError extends ConfigurationError {\n override name = 'WireTypeCollisionError';\n override readonly code: string = 'RELAYBUS_WIRE_TYPE_COLLISION';\n}\n\n/**\n * A route or catalog declares wire names for a transport whose codec cannot carry them: the\n * transport has no `declareWireTypes`, or its codec is not a `jsonEnvelope` with a type to map.\n */\nexport class WireTypesUnsupportedError extends ConfigurationError {\n override name = 'WireTypesUnsupportedError';\n override readonly code: string = 'RELAYBUS_WIRE_TYPES_UNSUPPORTED';\n}\n\n/**\n * Thrown by `publish` when no transaction can be found and the bus runs with\n * `transactionMode: 'required'` (the default). Publishing outside a transaction\n * would reintroduce the dual-write problem the outbox exists to prevent.\n */\nexport class TransactionRequiredError extends RelayBusError {\n override name = 'TransactionRequiredError';\n override readonly code: string = 'RELAYBUS_TRANSACTION_REQUIRED';\n}\n\n/**\n * A `bus.transaction` (or `@RelayBusTransaction()` method) ran past its `transactionTimeout` and\n * was rolled back. Its `cause` is the error the database raised when it ended the transaction,\n * when there was one. Usually a slow call to another service made inside the transaction.\n */\nexport class TransactionTimeoutError extends RelayBusError {\n override name = 'TransactionTimeoutError';\n override readonly code: string = 'RELAYBUS_TRANSACTION_TIMEOUT';\n}\n\n/**\n * A `@RelayBusTransaction({ isolationLevel })` method was called inside a transaction that was not\n * opened by relaybus at that same level. The isolation level of a running transaction cannot be\n * changed, so the method cannot join it: open the outer transaction at the level, or leave the\n * level off the inner method.\n */\nexport class TransactionIsolationConflictError extends RelayBusError {\n override name = 'TransactionIsolationConflictError';\n override readonly code: string = 'RELAYBUS_TRANSACTION_ISOLATION_CONFLICT';\n}\n\n/**\n * Throw from a handler to dead-letter the delivery immediately, skipping the\n * remaining retry attempts.\n */\nexport class NonRetryableError extends RelayBusError {\n override name = 'NonRetryableError';\n override readonly code: string = 'RELAYBUS_NON_RETRYABLE';\n}\n\n/** A payload failed its event schema. Never retried: the payload will not change. */\nexport class EventValidationError extends NonRetryableError {\n override name = 'EventValidationError';\n override readonly code: string = 'RELAYBUS_EVENT_VALIDATION';\n\n constructor(\n message: string,\n readonly issues: readonly ValidationIssue[],\n ) {\n super(message);\n }\n}\n\n/**\n * A message received from a broker is not a valid event. Never retried:\n * transports should dead-letter it instead of redelivering it forever.\n */\nexport class InvalidEnvelopeError extends NonRetryableError {\n override name = 'InvalidEnvelopeError';\n override readonly code: string = 'RELAYBUS_INVALID_ENVELOPE';\n}\n\n/** The worker no longer owns the delivery it was processing. */\nexport class LeaseLostError extends RelayBusError {\n override name = 'LeaseLostError';\n override readonly code: string = 'RELAYBUS_LEASE_LOST';\n /**\n * Whether the store said so (a fenced write returned false). A worker that only noticed\n * locally that its lease ran out may still own the delivery in the store and has to give it back.\n */\n readonly storeConfirmed: boolean;\n\n constructor(message: string, options: { readonly storeConfirmed?: boolean } = {}) {\n super(message);\n this.storeConfirmed = options.storeConfirmed ?? false;\n }\n}\n\n/** A handler did not settle within its configured timeout. Retried like any failure. */\nexport class HandlerTimeoutError extends RelayBusError {\n override name = 'HandlerTimeoutError';\n override readonly code: string = 'RELAYBUS_HANDLER_TIMEOUT';\n}\n\n/**\n * Reason of a handler's abort signal when the bus stops before the handler\n * finished. The delivery is released and runs again without losing an attempt.\n */\nexport class DispatcherStoppedError extends RelayBusError {\n override name = 'DispatcherStoppedError';\n override readonly code: string = 'RELAYBUS_DISPATCHER_STOPPED';\n}\n\n/**\n * A delivery came back after its lease expired on its last attempt, so it is\n * dead-lettered without running its handler again.\n */\nexport class AttemptsExhaustedError extends RelayBusError {\n override name = 'AttemptsExhaustedError';\n override readonly code: string = 'RELAYBUS_ATTEMPTS_EXHAUSTED';\n}\n\n/** A lifecycle method was called in a state that does not allow it, such as starting a bus twice. */\nexport class LifecycleError extends RelayBusError {\n override name = 'LifecycleError';\n override readonly code: string = 'RELAYBUS_LIFECYCLE';\n}\n\n/** `drain` still found due deliveries after its maximum number of batches. */\nexport class DrainIncompleteError extends RelayBusError {\n override name = 'DrainIncompleteError';\n override readonly code: string = 'RELAYBUS_DRAIN_INCOMPLETE';\n}\n\nexport interface ValidationIssue {\n readonly message: string;\n readonly path?: readonly PropertyKey[] | undefined;\n}\n\n/** Serializable snapshot of an error, stored with failed deliveries. */\nexport interface ErrorInfo {\n readonly name: string;\n readonly message: string;\n readonly stack?: string | undefined;\n /** The {@link RelayBusError.code} of a relaybus error; absent for any other error. */\n readonly code?: string | undefined;\n}\n\nexport function toErrorInfo(error: unknown): ErrorInfo {\n if (error instanceof RelayBusError) {\n return { name: error.name, message: error.message, stack: error.stack, code: error.code };\n }\n if (error instanceof Error) {\n return { name: error.name, message: error.message, stack: error.stack };\n }\n return { name: 'NonError', message: safeStringify(error) };\n}\n\nfunction safeStringify(value: unknown): string {\n if (typeof value === 'string') {\n return value;\n }\n try {\n return JSON.stringify(value) ?? String(value);\n } catch {\n return String(value);\n }\n}\n","import { ConfigurationError } from './errors.js';\n\n/**\n * A duration in milliseconds, or a string such as `'250ms'`, `'30s'`, `'5m'`,\n * `'1h'` or `'7d'`.\n */\nexport type Duration = number | `${number}${DurationUnit}`;\n\ntype DurationUnit = 'ms' | 's' | 'm' | 'h' | 'd';\n\nconst MILLISECONDS_PER_UNIT: Record<DurationUnit, number> = {\n ms: 1,\n s: 1_000,\n m: 60_000,\n h: 3_600_000,\n d: 86_400_000,\n};\n\nconst DURATION_PATTERN = /^(\\d+(?:\\.\\d+)?)(ms|s|m|h|d)$/;\n\nexport function toMilliseconds(value: Duration, name: string): number {\n if (typeof value === 'number') {\n if (!Number.isFinite(value) || value < 0) {\n throw new ConfigurationError(\n `${name} must be a non-negative finite number of milliseconds, received ${value}`,\n );\n }\n return value;\n }\n const match = DURATION_PATTERN.exec(value);\n if (match === null) {\n throw new ConfigurationError(\n `${name} must look like '500ms', '30s', '5m', '1h' or '7d', received '${value}'`,\n );\n }\n const [, amount, unit] = match as unknown as [string, string, DurationUnit];\n return Number(amount) * MILLISECONDS_PER_UNIT[unit];\n}\n\n/** Largest delay Node.js timers support. Longer values fire after 1ms instead. */\nexport const MAX_TIMER_DELAY_MS = 2_147_483_647;\n","import { ConfigurationError, EventValidationError } from './errors.js';\nimport type { StandardSchemaV1 } from './standard-schema.js';\n\n/** String metadata carried with an event, such as `traceparent`. */\nexport type EventHeaders = Readonly<Record<string, string>>;\n\n/**\n * An event as stored and delivered. Field names follow CloudEvents where they\n * overlap (`id`, `type`, `source`, `time` as `occurredAt`, `subject` as `key`).\n */\nexport interface EventEnvelope<TPayload = unknown> {\n /** Globally unique id. Handlers and transports deduplicate on it. */\n readonly id: string;\n /** Event type, for example `order.created.v1`. */\n readonly type: string;\n /** Logical name of the publishing service. */\n readonly source: string;\n /** Ordering and partition key. Events sharing a key are handled in publish order. */\n readonly key: string | null;\n readonly payload: TPayload;\n readonly headers: EventHeaders;\n /** Id shared by every event of one business flow. */\n readonly correlationId: string | null;\n /** Id of the event whose handler published this one. */\n readonly causationId: string | null;\n readonly occurredAt: Date;\n}\n\n/** An instance of a class created with {@link defineEvent}. */\nexport interface DomainEvent<TPayload = unknown> {\n readonly type: string;\n readonly payload: TPayload;\n}\n\n/**\n * Derives the ordering key of an event from its validated payload. Declared bivariantly so an\n * event class stays assignable wherever its payload type is widened.\n */\nexport type EventKeyFunction<TPayload> = {\n bivarianceHack(payload: TPayload): string;\n}['bivarianceHack'];\n\n/** A class created with {@link defineEvent}. */\nexport interface EventClass<TPayload = unknown> {\n new (payload: TPayload): DomainEvent<TPayload>;\n readonly type: string;\n readonly schema: StandardSchemaV1<unknown, TPayload> | undefined;\n /** The `key` given to {@link defineEvent}; undefined for events without one. */\n readonly key?: EventKeyFunction<TPayload> | undefined;\n}\n\n/** Payload type of an event class: `PayloadOf<typeof OrderPlaced>`. */\nexport type PayloadOf<TEvent> = TEvent extends EventClass<infer TPayload> ? TPayload : never;\n\n/** Anything that names an event type: an event class or the type string itself. */\nexport type EventReference = { readonly type: string } | string;\n\nexport interface DefineEventOptions<TSchema extends StandardSchemaV1> {\n /** Validates the payload on publish and before every handler call. */\n readonly schema: TSchema;\n /** Ordering key of every event of this type, from its validated payload. See {@link DefineEventKeyOptions}. */\n readonly key?: (payload: StandardSchemaV1.InferOutput<TSchema>) => string;\n}\n\nexport interface DefineEventKeyOptions<TPayload> {\n /**\n * Ordering key of every event of this type, from its payload: `(payload) => payload.orderId`.\n * Typed from the payload, so a missing field or a non-string fails to compile. `publish` uses it\n * when it is given no `key`; an explicit `key` option wins (for `publishAll`, the one key of the\n * call applies to every event). It must return a non-empty string.\n */\n readonly key: (payload: TPayload) => string;\n}\n\nconst EVENT_TYPE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,254}$/;\n\nexport function assertEventType(type: string): void {\n if (!EVENT_TYPE_PATTERN.test(type)) {\n throw new ConfigurationError(\n `Event type '${type}' must be 1-255 characters of letters, digits, '.', '_', ':', '/' or '-', starting with a letter or digit`,\n );\n }\n}\n\n/**\n * Defines an event type. Extend the returned class to name it:\n *\n * ```ts\n * export class OrderPlaced extends defineEvent<{ orderId: string }>('order.placed.v1') {}\n * export class OrderShipped extends defineEvent('order.shipped.v1', { schema: orderShippedSchema }) {}\n * export class OrderPaid extends defineEvent('order.paid.v1', {\n * schema: orderPaidSchema,\n * key: (payload) => payload.orderId,\n * }) {}\n * export class OrderCancelled extends defineEvent<{ orderId: string }>('order.cancelled.v1', {\n * key: (payload) => payload.orderId,\n * }) {}\n * ```\n */\nexport function defineEvent<TSchema extends StandardSchemaV1>(\n type: string,\n options: DefineEventOptions<TSchema>,\n): EventClass<StandardSchemaV1.InferOutput<TSchema>>;\nexport function defineEvent<TPayload>(\n type: string,\n options?: DefineEventKeyOptions<TPayload>,\n): EventClass<TPayload>;\nexport function defineEvent(\n type: string,\n options?: Partial<DefineEventOptions<StandardSchemaV1>>,\n): EventClass<unknown> {\n assertEventType(type);\n const schema = options?.schema;\n const key = options?.key;\n return class DefinedEvent implements DomainEvent<unknown> {\n static readonly type = type;\n static readonly schema = schema;\n static readonly key = key;\n readonly type = type;\n constructor(readonly payload: unknown) {}\n };\n}\n\n/** Runs a Standard Schema and returns its output, or throws {@link EventValidationError}. */\n// eslint-disable-next-line relaybus/max-two-params -- exported API validatePayload keeps its public signature\nexport async function validatePayload<TPayload>(\n type: string,\n schema: StandardSchemaV1<unknown, TPayload> | undefined,\n payload: unknown,\n): Promise<TPayload> {\n if (schema === undefined) {\n return payload as TPayload;\n }\n const result = await schema['~standard'].validate(payload);\n if (result.issues !== undefined) {\n const issues = result.issues.map((issue) => ({\n message: issue.message,\n path: issue.path?.map((segment) => (typeof segment === 'object' ? segment.key : segment)),\n }));\n throw new EventValidationError(\n `Payload of '${type}' failed validation: ${issues.map((issue) => issue.message).join('; ')}`,\n issues,\n );\n }\n return result.value;\n}\n\n/**\n * The ordering key an event of `event`'s class takes from its definition, or null when the class\n * defines no key.\n *\n * @throws ConfigurationError when the key function returns an empty string or no string.\n */\nexport function keyFromDefinition(event: DomainEvent, payload: unknown): string | null {\n const keyOf = (event.constructor as Partial<EventClass>).key;\n if (keyOf === undefined) {\n return null;\n }\n const key: unknown = keyOf(payload);\n if (typeof key !== 'string' || key.length === 0) {\n throw new ConfigurationError(\n `The key function of '${event.type}' must return a non-empty string | returned=${typeof key === 'string' ? \"''\" : typeof key}`,\n );\n }\n return key;\n}\n","import type { ErrorInfo } from '../errors.js';\nimport type { LeaseReference } from '../event-store.js';\n\n/** How a claim ends without completing: retried later, given back, or dead-lettered. */\nexport type SettlementChange =\n | {\n readonly kind: 'reschedule';\n readonly availableAt: Date;\n readonly error: ErrorInfo;\n readonly now: Date;\n }\n | { readonly kind: 'release'; readonly now: Date }\n | { readonly kind: 'bury'; readonly error: ErrorInfo; readonly now: Date };\n\n/** A change of the claim a lease names. */\nexport type LeaseChange = { readonly lease: LeaseReference; readonly change: SettlementChange };\n\n/** A lease renewal; `now` for a store that records when it happened. */\nexport type LeaseExtension = {\n readonly lease: LeaseReference;\n readonly leaseExpiresAt: Date;\n readonly now?: Date;\n};\n\n/**\n * What a store answers about a lease: at once when it answers from memory, later when it asks a\n * database. Answering at once keeps the in-memory store as fast (in microtasks) as it always was.\n */\nexport type StoreAnswer = boolean | Promise<boolean>;\n\n/**\n * The fenced settlement skeleton every event store shares: find the claim a lease names (a lease\n * this store cannot have issued, or whose claim ended, is not held and changes nothing), apply the\n * change fenced by the lease, then forget the lease as handed out once the store answered.\n * A store supplies only how it finds a held claim, how it writes a change and a renewal, and its\n * bookkeeping of handed-out leases.\n */\nexport abstract class LeaseSettlement<THeld> {\n /** Renews the lease when it is still held; false otherwise. */\n extendLease(extension: LeaseExtension): StoreAnswer {\n const held = this.findHeld(extension.lease);\n return held === undefined ? false : this.writeExtension(held, extension);\n }\n\n /**\n * Applies `change` when the lease is still held. Once the store answered (either way) the lease\n * is forgotten as handed out; when the write throws it stays registered, since the caller may\n * retry with the same lease.\n */\n changeClaim(request: LeaseChange): StoreAnswer {\n const held = this.findHeld(request.lease);\n if (held === undefined) {\n return false;\n }\n const changed = this.writeChange(held, request);\n if (typeof changed === 'boolean') {\n this.forgetHandedOut(request.lease);\n return changed;\n }\n return this.#forgetOnceAnswered(request.lease, changed);\n }\n\n /** The claim `lease` names, when this store issued the lease; undefined otherwise. */\n protected abstract findHeld(lease: LeaseReference): THeld | undefined;\n\n protected abstract writeChange(held: THeld, request: LeaseChange): StoreAnswer;\n\n protected abstract writeExtension(held: THeld, extension: LeaseExtension): StoreAnswer;\n\n /** Drops `lease` from the store's handed-out bookkeeping; nothing for a store that keeps none. */\n protected abstract forgetHandedOut(lease: LeaseReference): void;\n\n async #forgetOnceAnswered(lease: LeaseReference, answer: Promise<boolean>): Promise<boolean> {\n const changed = await answer;\n this.forgetHandedOut(lease);\n return changed;\n }\n}\n","/** Separates the parts of a composite key: no identifier, handler id or ordering key contains it. */\nconst SEPARATOR = '\\u0000';\n\n/**\n * Two identifiers joined into one map or set key, such as an event id and a handler id, or a\n * handler id and an ordering key. The NUL separator keeps `('a:b', 'c')` and `('a', 'b:c')` apart.\n * Keys are plain strings, so they cost nothing more than the template literal they replace.\n */\nexport abstract class CompositeKey {\n static of(first: string, second: string): string {\n return `${first}${SEPARATOR}${second}`;\n }\n\n /** The start every key of `first` shares, to find them all by prefix. */\n static startOf(first: string): string {\n return `${first}${SEPARATOR}`;\n }\n}\n","import type { Clock } from '../clock.js';\n\n/** A task for {@link schedule}: what runs, after how long, whether it repeats and keeps the process alive. */\nexport type ScheduledTask = Parameters<NonNullable<Clock['schedule']>>[0];\n\n/** Cancels a scheduled task; harmless once it ran or was cancelled. */\nexport type CancelTimer = () => void;\n\n/**\n * The one place relaybus starts timers: through `clock.schedule` when the clock controls timers,\n * else with the platform timers.\n */\nexport function schedule(clock: Clock, task: ScheduledTask): CancelTimer {\n return clock.schedule === undefined ? scheduleOnPlatform(task) : clock.schedule(task);\n}\n\n/** Resolves after `milliseconds` on the timers of `clock`. */\nexport function sleep(clock: Clock, milliseconds: number): Promise<void> {\n return new Promise((resolve) => {\n schedule(clock, { run: resolve, delayMs: milliseconds });\n });\n}\n\nfunction scheduleOnPlatform(task: ScheduledTask): CancelTimer {\n if (task.repeat === true) {\n const interval = setInterval(task.run, task.delayMs);\n if (task.unref === true) {\n interval.unref();\n }\n return () => clearInterval(interval);\n }\n const timeout = setTimeout(task.run, task.delayMs);\n if (task.unref === true) {\n timeout.unref();\n }\n return () => clearTimeout(timeout);\n}\n","import { MAX_TIMER_DELAY_MS, toMilliseconds, type Duration } from '../duration.js';\nimport { ConfigurationError } from '../errors.js';\n\n/**\n * A configured length of time, converted once from a {@link Duration} option. Each factory names\n * the option, so its refusal says which one was wrong.\n */\nexport abstract class Milliseconds {\n /** Zero or more milliseconds. */\n static of(value: Duration, name: string): number {\n return toMilliseconds(value, name);\n }\n\n /** More than zero milliseconds: a wait, a timeout or an age that must pass at all. */\n static positive(value: Duration, name: string): number {\n const milliseconds = toMilliseconds(value, name);\n if (milliseconds === 0) {\n throw new ConfigurationError(`${name} must be greater than zero`);\n }\n return milliseconds;\n }\n\n /** A duration that drives a timer: more than zero, and no longer than timers can represent. */\n static forTimer(value: Duration, name: string): number {\n const milliseconds = Milliseconds.positive(value, name);\n if (milliseconds > MAX_TIMER_DELAY_MS) {\n throw new ConfigurationError(\n `${name} must not exceed ${MAX_TIMER_DELAY_MS}ms (about 24.8 days), received ${milliseconds}ms`,\n );\n }\n return milliseconds;\n }\n}\n","import { CompositeKey } from './composite-key.js';\n\n/**\n * Identifies one claim of a delivery: the delivery id with the exact lease token it was handed out\n * with. Two claims of the same delivery (an expired one and the current one) have different\n * identities, so bookkeeping of the older can never replace or remove the newer one's.\n */\nexport abstract class DeliveryLeaseIdentity {\n static of(deliveryId: string, leaseToken: string): string {\n return CompositeKey.of(deliveryId, leaseToken);\n }\n\n /** The start of the identity of every claim of `deliveryId`. */\n static prefixOf(deliveryId: string): string {\n return CompositeKey.startOf(deliveryId);\n }\n}\n","import { ConfigurationError } from '../errors.js';\n\n/** A count option that must be a whole number of at least 1: a batch size, attempts, a limit. */\nexport abstract class PositiveInteger {\n /** Returns `value` when it is an integer of at least 1, else throws a {@link ConfigurationError} naming the option. */\n static of(value: number, name: string): number {\n if (!Number.isInteger(value) || value < 1) {\n throw new ConfigurationError(`${name} must be a positive integer, received ${String(value)}`);\n }\n return value;\n }\n}\n"]}