@crossdelta/cloudevents 0.3.2 → 0.3.4

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.
@@ -5,3 +5,4 @@ export { eventSchema, extractTypeFromSchema, handleEvent } from './domain';
5
5
  export { clearHandlerCache, cloudEvents } from './middlewares';
6
6
  export { checkAndMarkProcessed, createInMemoryIdempotencyStore, getDefaultIdempotencyStore, resetDefaultIdempotencyStore, } from './processing/idempotency';
7
7
  export * from './publishing';
8
+ export { consumeJetStreamEvents, consumeNatsEvents } from './transports/nats';
package/dist/src/index.js CHANGED
@@ -3,3 +3,4 @@ export { eventSchema, extractTypeFromSchema, handleEvent } from './domain';
3
3
  export { clearHandlerCache, cloudEvents } from './middlewares';
4
4
  export { checkAndMarkProcessed, createInMemoryIdempotencyStore, getDefaultIdempotencyStore, resetDefaultIdempotencyStore, } from './processing/idempotency';
5
5
  export * from './publishing';
6
+ export { consumeJetStreamEvents, consumeNatsEvents } from './transports/nats';
@@ -1,5 +1,14 @@
1
- import { AckPolicy, connect, DeliverPolicy, ReplayPolicy, RetentionPolicy, StorageType, StringCodec, } from 'nats';
1
+ import { connect, StringCodec, } from 'nats';
2
2
  import { discoverHandlers } from '../../domain';
3
+ // String literals matching NATS enum values (enums not reliably exported in CI/Bun)
4
+ // AckPolicy.Explicit = "explicit", DeliverPolicy.All/Last/New/StartTime, RetentionPolicy.Limits = "limits", StorageType.File = "file"
5
+ const ACK_EXPLICIT = 'explicit';
6
+ const DELIVER_ALL = 'all';
7
+ const DELIVER_LAST = 'last';
8
+ const DELIVER_NEW = 'new';
9
+ const DELIVER_START_TIME = 'by_start_time';
10
+ const RETENTION_LIMITS = 'limits';
11
+ const STORAGE_FILE = 'file';
3
12
  import { logger } from '../../infrastructure/logging';
4
13
  import { processHandler } from '../../processing/handler-cache';
5
14
  import { checkAndMarkProcessed, getDefaultIdempotencyStore } from '../../processing/idempotency';
@@ -42,8 +51,8 @@ async function ensureStream(jsm, name, subjects, config = {}) {
42
51
  await jsm.streams.add({
43
52
  name,
44
53
  subjects,
45
- retention: RetentionPolicy.Limits,
46
- storage: StorageType.File,
54
+ retention: RETENTION_LIMITS,
55
+ storage: STORAGE_FILE,
47
56
  max_age: streamConfig.maxAge * 1_000_000, // Convert ms to nanoseconds
48
57
  max_bytes: streamConfig.maxBytes,
49
58
  num_replicas: streamConfig.replicas,
@@ -58,11 +67,11 @@ async function ensureConsumer(jsm, streamName, consumerName, options) {
58
67
  const deliverPolicy = (() => {
59
68
  switch (options.startFrom) {
60
69
  case 'all':
61
- return DeliverPolicy.All;
70
+ return DELIVER_ALL;
62
71
  case 'last':
63
- return DeliverPolicy.Last;
72
+ return DELIVER_LAST;
64
73
  default:
65
- return DeliverPolicy.New;
74
+ return DELIVER_NEW;
66
75
  }
67
76
  })();
68
77
  const optStartTime = options.startFrom instanceof Date ? options.startFrom : undefined;
@@ -74,10 +83,10 @@ async function ensureConsumer(jsm, streamName, consumerName, options) {
74
83
  // Consumer doesn't exist, create it
75
84
  await jsm.consumers.add(streamName, {
76
85
  durable_name: consumerName,
77
- ack_policy: AckPolicy.Explicit,
78
- deliver_policy: optStartTime ? DeliverPolicy.StartTime : deliverPolicy,
86
+ ack_policy: ACK_EXPLICIT,
87
+ deliver_policy: optStartTime ? DELIVER_START_TIME : deliverPolicy,
79
88
  opt_start_time: optStartTime?.toISOString(),
80
- replay_policy: ReplayPolicy.Instant,
89
+ // replay_policy defaults to 'instant', no need to specify explicitly
81
90
  ack_wait: (options.ackWait ?? 30_000) * 1_000_000, // Convert to nanoseconds
82
91
  max_deliver: options.maxDeliver ?? 3,
83
92
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossdelta/cloudevents",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "CloudEvents toolkit for TypeScript - Zod validation, handler discovery, NATS JetStream",
5
5
  "author": "crossdelta",
6
6
  "license": "MIT",
@@ -37,11 +37,12 @@
37
37
  "start:dev": "tsc -p tsconfig.json --watch",
38
38
  "stryker": "bun stryker run",
39
39
  "lint": "biome lint --fix",
40
+ "pretest": "rm -rf dist",
40
41
  "test": "bun test",
41
42
  "prepublishOnly": "bun run build"
42
43
  },
43
44
  "dependencies": {
44
- "cloudevents": "7.0.2",
45
+ "cloudevents": "^10.0.0",
45
46
  "glob": "11.0.0",
46
47
  "nats": "^2.29.3"
47
48
  },