@flowcore/pathways 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.4.0...v0.5.0) (2025-03-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * **pathways:** :sparkles: Add event payload validation and improve handler typings ([228e262](https://github.com/flowcore-io/flowcore-pathways/commit/228e262527a9e1d26aaa68f959480b3a3d2ef70e))
9
+
10
+ ## [0.4.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.3.0...v0.4.0) (2025-03-15)
11
+
12
+
13
+ ### Features
14
+
15
+ * **postgres:** :sparkles: Add support for connection string and individual parameters in PostgreSQL configuration ([881fba2](https://github.com/flowcore-io/flowcore-pathways/commit/881fba26485349a3d4253cdb112928b9a9c31996))
16
+
3
17
  ## [0.3.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.2.4...v0.3.0) (2025-03-15)
4
18
 
5
19
 
@@ -134,20 +134,26 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
134
134
  * @param handler The function that will process events for this pathway
135
135
  * @throws Error if the pathway doesn't exist or already has a handler
136
136
  */
137
- handle<TPath extends keyof TPathway>(path: TPath, handler: (event: FlowcoreEvent) => (Promise<void> | void)): void;
137
+ handle<TPath extends keyof TPathway>(path: TPath, handler: (event: Omit<FlowcoreEvent, 'payload'> & {
138
+ payload: TPathway[TPath];
139
+ }) => (Promise<void> | void)): void;
138
140
  /**
139
141
  * Subscribe to pathway events (before or after processing)
140
142
  * @param path The pathway to subscribe to
141
143
  * @param handler The handler function for the events
142
144
  * @param type The event type to subscribe to (before, after, or all)
143
145
  */
144
- subscribe<TPath extends keyof TPathway>(path: TPath, handler: (event: FlowcoreEvent) => void, type?: "before" | "after" | "all"): void;
146
+ subscribe<TPath extends keyof TPathway>(path: TPath, handler: (event: Omit<FlowcoreEvent, 'payload'> & {
147
+ payload: TPathway[TPath];
148
+ }) => void, type?: "before" | "after" | "all"): void;
145
149
  /**
146
150
  * Subscribe to errors for a specific pathway
147
151
  * @param path The pathway to subscribe to errors for
148
152
  * @param handler The handler function that receives the error and event
149
153
  */
150
- onError<TPath extends keyof TPathway>(path: TPath, handler: (error: Error, event: FlowcoreEvent) => void): void;
154
+ onError<TPath extends keyof TPathway>(path: TPath, handler: (error: Error, event: Omit<FlowcoreEvent, 'payload'> & {
155
+ payload: TPathway[TPath];
156
+ }) => void): void;
151
157
  /**
152
158
  * Subscribe to errors for all pathways
153
159
  * @param handler The handler function that receives the error, event, and pathway name
@@ -1 +1 @@
1
- {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAExD,OAAO,KAAK,EAAyD,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAG/H,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,mBAAmB,EAA6B,eAAe,EAAE,MAAM,YAAY,CAAA;AAiB3J;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEzC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;AAEvE;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;AAElD;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,kBAAkB;IACjE;;OAEG;IACH,OAAO,CAAC,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,cAAc,EACtC,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EACrB,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;IA4F7B;;;;;;;;;;OAUG;YACW,2BAA2B;CA4C1C"}
@@ -219,6 +219,22 @@ export class PathwaysBuilder {
219
219
  this.logger.error(error);
220
220
  throw new Error(error);
221
221
  }
222
+ // Validate event payload against schema if available
223
+ if (this.schemas[pathway]) {
224
+ try {
225
+ const isValid = Value.Check(this.schemas[pathway], data.payload);
226
+ if (!isValid) {
227
+ const error = `Event payload does not match schema for pathway ${pathwayStr}`;
228
+ this.logger.error(error);
229
+ throw new Error(error);
230
+ }
231
+ }
232
+ catch (err) {
233
+ const error = `Error validating event payload against schema for pathway ${pathwayStr}: ${err instanceof Error ? err.message : String(err)}`;
234
+ this.logger.error(error);
235
+ throw new Error(error);
236
+ }
237
+ }
222
238
  // Call audit handler if configured
223
239
  if (this.auditHandler) {
224
240
  this.logger.debug(`Calling audit handler for pathway`, {
@@ -418,27 +434,22 @@ export class PathwaysBuilder {
418
434
  */
419
435
  subscribe(path, handler, type = "before") {
420
436
  const pathStr = String(path);
421
- this.logger.debug(`Subscribing to pathway events`, {
422
- pathway: pathStr,
423
- type
424
- });
425
- if (!this.pathways[path]) {
437
+ const pathway = this.pathways[path];
438
+ if (!pathway) {
426
439
  const error = `Pathway ${pathStr} not found`;
427
440
  this.logger.error(error);
428
441
  throw new Error(error);
429
442
  }
430
- if (type === "before") {
431
- this.beforeObservable[path].subscribe(handler);
432
- }
433
- else if (type === "after") {
434
- this.afterObservers[path].subscribe(handler);
443
+ const typedHandler = handler;
444
+ if (type === "before" || type === "all") {
445
+ this.beforeObservable[path].subscribe(typedHandler);
446
+ this.logger.debug(`Subscribed to 'before' events for pathway`, { pathway: pathStr });
435
447
  }
436
- else if (type === "all") {
437
- // Subscribe to both before and after events
438
- this.beforeObservable[path].subscribe(handler);
439
- this.afterObservers[path].subscribe(handler);
448
+ if (type === "after" || type === "all") {
449
+ this.afterObservers[path].subscribe(typedHandler);
450
+ this.logger.debug(`Subscribed to 'after' events for pathway`, { pathway: pathStr });
440
451
  }
441
- this.logger.debug(`Subscribed to pathway events`, {
452
+ this.logger.info(`Subscription to pathway events set up`, {
442
453
  pathway: pathStr,
443
454
  type
444
455
  });
@@ -450,14 +461,17 @@ export class PathwaysBuilder {
450
461
  */
451
462
  onError(path, handler) {
452
463
  const pathStr = String(path);
453
- this.logger.debug(`Subscribing to pathway errors`, { pathway: pathStr });
454
- if (!this.pathways[path]) {
464
+ this.logger.debug(`Setting error handler for pathway`, { pathway: pathStr });
465
+ const pathway = this.pathways[path];
466
+ if (!pathway) {
455
467
  const error = `Pathway ${pathStr} not found`;
456
468
  this.logger.error(error);
457
469
  throw new Error(error);
458
470
  }
459
- this.errorObservers[path].subscribe(({ event, error }) => handler(error, event));
460
- this.logger.debug(`Subscribed to pathway errors`, { pathway: pathStr });
471
+ // Type cast to maintain internal consistency while preserving external type safety
472
+ const typedHandler = (payload) => handler(payload.error, payload.event);
473
+ this.errorObservers[path].subscribe(typedHandler);
474
+ this.logger.info(`Error handler set for pathway`, { pathway: pathStr });
461
475
  }
462
476
  /**
463
477
  * Subscribe to errors for all pathways
@@ -1,8 +1,28 @@
1
1
  import type { PathwayState } from "../types.js";
2
2
  /**
3
- * Configuration options for PostgreSQL pathway state storage
3
+ * Configuration for PostgreSQL pathway state storage using a connection string
4
+ */
5
+ export interface PostgresPathwayStateConnectionStringConfig {
6
+ /** Complete PostgreSQL connection string (e.g., postgres://user:password@host:port/database?sslmode=require) */
7
+ connectionString: string;
8
+ /** These properties are not used when a connection string is provided */
9
+ host?: never;
10
+ port?: never;
11
+ user?: never;
12
+ password?: never;
13
+ database?: never;
14
+ ssl?: never;
15
+ /** Table name for storing pathway state (default: "pathway_state") */
16
+ tableName?: string;
17
+ /** Time-to-live in milliseconds for processed events (default: 5 minutes) */
18
+ ttlMs?: number;
19
+ }
20
+ /**
21
+ * Configuration for PostgreSQL pathway state storage using individual parameters
4
22
  */
5
- export interface PostgresPathwayStateConfig {
23
+ export interface PostgresPathwayStateParametersConfig {
24
+ /** Not used when individual parameters are provided */
25
+ connectionString?: never;
6
26
  /** PostgreSQL server hostname */
7
27
  host: string;
8
28
  /** PostgreSQL server port */
@@ -20,6 +40,14 @@ export interface PostgresPathwayStateConfig {
20
40
  /** Time-to-live in milliseconds for processed events (default: 5 minutes) */
21
41
  ttlMs?: number;
22
42
  }
43
+ /**
44
+ * Configuration options for PostgreSQL pathway state storage
45
+ *
46
+ * Can provide either:
47
+ * 1. A complete connection string, or
48
+ * 2. Individual connection parameters (host, port, user, etc.)
49
+ */
50
+ export type PostgresPathwayStateConfig = PostgresPathwayStateConnectionStringConfig | PostgresPathwayStateParametersConfig;
23
51
  /**
24
52
  * Implementation of PathwayState that uses PostgreSQL for storage
25
53
  *
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-pathway-state.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-pathway-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IA0C3C,OAAO,CAAC,MAAM;IAzC1B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAEvD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAmB;IAE7D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAkB;IAElC;;;OAGG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAS;IAEtB;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAS;IAE5B;;;;OAIG;gBACiB,MAAM,EAAE,0BAA0B;IAMtD;;;;;OAKG;YACW,UAAU;IAgCxB;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAcpD;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAelD;;;;;OAKG;YACW,cAAc;IAQ5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAGnG"}
1
+ {"version":3,"file":"postgres-pathway-state.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-pathway-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;GAEG;AACH,MAAM,WAAW,0CAA0C;IACzD,gHAAgH;IAChH,gBAAgB,EAAE,MAAM,CAAC;IAEzB,yEAAyE;IACzE,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,GA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,CAAC,OAAO,CAAC;IAcpD;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAelD;;;;;OAKG;YACW,cAAc;IAQ5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAGnG"}
@@ -72,14 +72,25 @@ export class PostgresPathwayState {
72
72
  if (this.initialized) {
73
73
  return;
74
74
  }
75
- this.postgres = await createPostgresAdapter({
76
- host: this.config.host,
77
- port: this.config.port,
78
- user: this.config.user,
79
- password: this.config.password,
80
- database: this.config.database,
81
- ssl: this.config.ssl,
82
- });
75
+ // Create adapter using either connection string or individual parameters
76
+ if ('connectionString' in this.config && this.config.connectionString) {
77
+ // Use connection string if provided
78
+ this.postgres = await createPostgresAdapter({
79
+ connectionString: this.config.connectionString
80
+ });
81
+ }
82
+ else {
83
+ // We know this must be the parameters config due to the type union
84
+ // TypeScript just needs help with narrowing the type
85
+ this.postgres = await createPostgresAdapter({
86
+ host: this.config.host,
87
+ port: this.config.port,
88
+ user: this.config.user,
89
+ password: this.config.password,
90
+ database: this.config.database,
91
+ ssl: this.config.ssl,
92
+ });
93
+ }
83
94
  // Create table if it doesn't exist
84
95
  await this.postgres.execute(`
85
96
  CREATE TABLE IF NOT EXISTS ${this.tableName} (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowcore/pathways",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "A TypeScript Library for creating Flowcore Pathways, simplifying the integration with the flowcore platform",
5
5
  "homepage": "https://github.com/flowcore-io/flowcore-sdk#readme",
6
6
  "repository": {
@@ -134,20 +134,26 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
134
134
  * @param handler The function that will process events for this pathway
135
135
  * @throws Error if the pathway doesn't exist or already has a handler
136
136
  */
137
- handle<TPath extends keyof TPathway>(path: TPath, handler: (event: FlowcoreEvent) => (Promise<void> | void)): void;
137
+ handle<TPath extends keyof TPathway>(path: TPath, handler: (event: Omit<FlowcoreEvent, 'payload'> & {
138
+ payload: TPathway[TPath];
139
+ }) => (Promise<void> | void)): void;
138
140
  /**
139
141
  * Subscribe to pathway events (before or after processing)
140
142
  * @param path The pathway to subscribe to
141
143
  * @param handler The handler function for the events
142
144
  * @param type The event type to subscribe to (before, after, or all)
143
145
  */
144
- subscribe<TPath extends keyof TPathway>(path: TPath, handler: (event: FlowcoreEvent) => void, type?: "before" | "after" | "all"): void;
146
+ subscribe<TPath extends keyof TPathway>(path: TPath, handler: (event: Omit<FlowcoreEvent, 'payload'> & {
147
+ payload: TPathway[TPath];
148
+ }) => void, type?: "before" | "after" | "all"): void;
145
149
  /**
146
150
  * Subscribe to errors for a specific pathway
147
151
  * @param path The pathway to subscribe to errors for
148
152
  * @param handler The handler function that receives the error and event
149
153
  */
150
- onError<TPath extends keyof TPathway>(path: TPath, handler: (error: Error, event: FlowcoreEvent) => void): void;
154
+ onError<TPath extends keyof TPathway>(path: TPath, handler: (error: Error, event: Omit<FlowcoreEvent, 'payload'> & {
155
+ payload: TPathway[TPath];
156
+ }) => void): void;
151
157
  /**
152
158
  * Subscribe to errors for all pathways
153
159
  * @param handler The handler function that receives the error, event, and pathway name
@@ -1 +1 @@
1
- {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAExD,OAAO,KAAK,EAAyD,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAG/H,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,U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,KAAK,SAAS,MAAM,QAAQ,EAClC,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG;QAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;KAAE,KAAK,IAAI,GACpG,IAAI;IAmBP;;;OAGG;IACH,UAAU,CACR,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GACrE,IAAI;IAMP;;;;;;;OAOG;IACG,KAAK,CAAC,KAAK,SAAS,cAAc,EACtC,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EACrB,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;IA4F7B;;;;;;;;;;OAUG;YACW,2BAA2B;CA4C1C"}
@@ -222,6 +222,22 @@ class PathwaysBuilder {
222
222
  this.logger.error(error);
223
223
  throw new Error(error);
224
224
  }
225
+ // Validate event payload against schema if available
226
+ if (this.schemas[pathway]) {
227
+ try {
228
+ const isValid = value_1.Value.Check(this.schemas[pathway], data.payload);
229
+ if (!isValid) {
230
+ const error = `Event payload does not match schema for pathway ${pathwayStr}`;
231
+ this.logger.error(error);
232
+ throw new Error(error);
233
+ }
234
+ }
235
+ catch (err) {
236
+ const error = `Error validating event payload against schema for pathway ${pathwayStr}: ${err instanceof Error ? err.message : String(err)}`;
237
+ this.logger.error(error);
238
+ throw new Error(error);
239
+ }
240
+ }
225
241
  // Call audit handler if configured
226
242
  if (this.auditHandler) {
227
243
  this.logger.debug(`Calling audit handler for pathway`, {
@@ -421,27 +437,22 @@ class PathwaysBuilder {
421
437
  */
422
438
  subscribe(path, handler, type = "before") {
423
439
  const pathStr = String(path);
424
- this.logger.debug(`Subscribing to pathway events`, {
425
- pathway: pathStr,
426
- type
427
- });
428
- if (!this.pathways[path]) {
440
+ const pathway = this.pathways[path];
441
+ if (!pathway) {
429
442
  const error = `Pathway ${pathStr} not found`;
430
443
  this.logger.error(error);
431
444
  throw new Error(error);
432
445
  }
433
- if (type === "before") {
434
- this.beforeObservable[path].subscribe(handler);
435
- }
436
- else if (type === "after") {
437
- this.afterObservers[path].subscribe(handler);
446
+ const typedHandler = handler;
447
+ if (type === "before" || type === "all") {
448
+ this.beforeObservable[path].subscribe(typedHandler);
449
+ this.logger.debug(`Subscribed to 'before' events for pathway`, { pathway: pathStr });
438
450
  }
439
- else if (type === "all") {
440
- // Subscribe to both before and after events
441
- this.beforeObservable[path].subscribe(handler);
442
- this.afterObservers[path].subscribe(handler);
451
+ if (type === "after" || type === "all") {
452
+ this.afterObservers[path].subscribe(typedHandler);
453
+ this.logger.debug(`Subscribed to 'after' events for pathway`, { pathway: pathStr });
443
454
  }
444
- this.logger.debug(`Subscribed to pathway events`, {
455
+ this.logger.info(`Subscription to pathway events set up`, {
445
456
  pathway: pathStr,
446
457
  type
447
458
  });
@@ -453,14 +464,17 @@ class PathwaysBuilder {
453
464
  */
454
465
  onError(path, handler) {
455
466
  const pathStr = String(path);
456
- this.logger.debug(`Subscribing to pathway errors`, { pathway: pathStr });
457
- if (!this.pathways[path]) {
467
+ this.logger.debug(`Setting error handler for pathway`, { pathway: pathStr });
468
+ const pathway = this.pathways[path];
469
+ if (!pathway) {
458
470
  const error = `Pathway ${pathStr} not found`;
459
471
  this.logger.error(error);
460
472
  throw new Error(error);
461
473
  }
462
- this.errorObservers[path].subscribe(({ event, error }) => handler(error, event));
463
- this.logger.debug(`Subscribed to pathway errors`, { pathway: pathStr });
474
+ // Type cast to maintain internal consistency while preserving external type safety
475
+ const typedHandler = (payload) => handler(payload.error, payload.event);
476
+ this.errorObservers[path].subscribe(typedHandler);
477
+ this.logger.info(`Error handler set for pathway`, { pathway: pathStr });
464
478
  }
465
479
  /**
466
480
  * Subscribe to errors for all pathways
@@ -1,8 +1,28 @@
1
1
  import type { PathwayState } from "../types.js";
2
2
  /**
3
- * Configuration options for PostgreSQL pathway state storage
3
+ * Configuration for PostgreSQL pathway state storage using a connection string
4
+ */
5
+ export interface PostgresPathwayStateConnectionStringConfig {
6
+ /** Complete PostgreSQL connection string (e.g., postgres://user:password@host:port/database?sslmode=require) */
7
+ connectionString: string;
8
+ /** These properties are not used when a connection string is provided */
9
+ host?: never;
10
+ port?: never;
11
+ user?: never;
12
+ password?: never;
13
+ database?: never;
14
+ ssl?: never;
15
+ /** Table name for storing pathway state (default: "pathway_state") */
16
+ tableName?: string;
17
+ /** Time-to-live in milliseconds for processed events (default: 5 minutes) */
18
+ ttlMs?: number;
19
+ }
20
+ /**
21
+ * Configuration for PostgreSQL pathway state storage using individual parameters
4
22
  */
5
- export interface PostgresPathwayStateConfig {
23
+ export interface PostgresPathwayStateParametersConfig {
24
+ /** Not used when individual parameters are provided */
25
+ connectionString?: never;
6
26
  /** PostgreSQL server hostname */
7
27
  host: string;
8
28
  /** PostgreSQL server port */
@@ -20,6 +40,14 @@ export interface PostgresPathwayStateConfig {
20
40
  /** Time-to-live in milliseconds for processed events (default: 5 minutes) */
21
41
  ttlMs?: number;
22
42
  }
43
+ /**
44
+ * Configuration options for PostgreSQL pathway state storage
45
+ *
46
+ * Can provide either:
47
+ * 1. A complete connection string, or
48
+ * 2. Individual connection parameters (host, port, user, etc.)
49
+ */
50
+ export type PostgresPathwayStateConfig = PostgresPathwayStateConnectionStringConfig | PostgresPathwayStateParametersConfig;
23
51
  /**
24
52
  * Implementation of PathwayState that uses PostgreSQL for storage
25
53
  *
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-pathway-state.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-pathway-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;GAEG;AACH,MAAM,WAAW,0BAA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,QAAQ,CAAC,cAAc,CAAiB;IAEvD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAmB;IAE7D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAkB;IAElC;;;OAGG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAS;IAEtB;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAS;IAE5B;;;;OAIG;gBACiB,MAAM,EAAE,0BAA0B;IAMtD;;;;;OAKG;YACW,UAAU;IA0CxB;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAcpD;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAelD;;;;;OAKG;YACW,cAAc;IAQ5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAGnG"}
@@ -76,14 +76,25 @@ class PostgresPathwayState {
76
76
  if (this.initialized) {
77
77
  return;
78
78
  }
79
- this.postgres = await (0, postgres_adapter_js_1.createPostgresAdapter)({
80
- host: this.config.host,
81
- port: this.config.port,
82
- user: this.config.user,
83
- password: this.config.password,
84
- database: this.config.database,
85
- ssl: this.config.ssl,
86
- });
79
+ // Create adapter using either connection string or individual parameters
80
+ if ('connectionString' in this.config && this.config.connectionString) {
81
+ // Use connection string if provided
82
+ this.postgres = await (0, postgres_adapter_js_1.createPostgresAdapter)({
83
+ connectionString: this.config.connectionString
84
+ });
85
+ }
86
+ else {
87
+ // We know this must be the parameters config due to the type union
88
+ // TypeScript just needs help with narrowing the type
89
+ this.postgres = await (0, postgres_adapter_js_1.createPostgresAdapter)({
90
+ host: this.config.host,
91
+ port: this.config.port,
92
+ user: this.config.user,
93
+ password: this.config.password,
94
+ database: this.config.database,
95
+ ssl: this.config.ssl,
96
+ });
97
+ }
87
98
  // Create table if it doesn't exist
88
99
  await this.postgres.execute(`
89
100
  CREATE TABLE IF NOT EXISTS ${this.tableName} (