@flowcore/pathways 0.15.3 → 0.16.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/CHANGELOG.md CHANGED
@@ -1,68 +1,94 @@
1
1
  # Changelog
2
2
 
3
- ## [0.15.3](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.2...v0.15.3) (2025-06-03)
3
+ ## [0.16.1](https://github.com/flowcore-io/flowcore-pathways/compare/v0.16.0...v0.16.1) (2025-06-04)
4
4
 
5
5
 
6
6
  ### Bug Fixes
7
7
 
8
- * add debug ([c5b0776](https://github.com/flowcore-io/flowcore-pathways/commit/c5b0776af5edfb64a568e497e31ed5181c59bb2d))
8
+ * **session-pathway:** :art: update write method to accept structured input ([86e54a7](https://github.com/flowcore-io/flowcore-pathways/commit/86e54a79cb8bef32677f308eb51a50eef6d1f071))
9
9
 
10
- ## [0.15.2](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.1...v0.15.2) (2025-06-03)
10
+ ## [0.16.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.3...v0.16.0) (2025-06-03)
11
+
12
+ ### Features
11
13
 
14
+ - **postgres:** :sparkles: add connection pool configuration options for PostgreSQL
15
+ ([9ba9966](https://github.com/flowcore-io/flowcore-pathways/commit/9ba9966706c13bba441ef8538a0ecfe405191307))
12
16
 
13
17
  ### Bug Fixes
14
18
 
15
- * update transformer core ([1b621ef](https://github.com/flowcore-io/flowcore-pathways/commit/1b621ef076016d6ef0cf378a883a113df6c022c0))
19
+ - **postgres:** :art: clean up whitespace in postgres-adapter.ts
20
+ ([d16e0a9](https://github.com/flowcore-io/flowcore-pathways/commit/d16e0a9dfc0b02e533143dfcc5fe34e57bf22cea))
21
+ - **postgres:** :art: update PostgresJsOptions interface for better type safety
22
+ ([0fee92e](https://github.com/flowcore-io/flowcore-pathways/commit/0fee92eaad3ceb9a387cb6cee9d3029a254b8c15))
16
23
 
17
- ## [0.15.1](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.0...v0.15.1) (2025-05-28)
24
+ ## [0.15.3](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.2...v0.15.3) (2025-06-03)
18
25
 
26
+ ### Bug Fixes
27
+
28
+ - add debug
29
+ ([c5b0776](https://github.com/flowcore-io/flowcore-pathways/commit/c5b0776af5edfb64a568e497e31ed5181c59bb2d))
30
+
31
+ ## [0.15.2](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.1...v0.15.2) (2025-06-03)
19
32
 
20
33
  ### Bug Fixes
21
34
 
22
- * export file types ([203cc73](https://github.com/flowcore-io/flowcore-pathways/commit/203cc735aaedcf9bf44f045fd8a15916917b7ac1))
35
+ - update transformer core
36
+ ([1b621ef](https://github.com/flowcore-io/flowcore-pathways/commit/1b621ef076016d6ef0cf378a883a113df6c022c0))
23
37
 
24
- ## [0.15.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.14.0...v0.15.0) (2025-05-27)
38
+ ## [0.15.1](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.0...v0.15.1) (2025-05-28)
25
39
 
40
+ ### Bug Fixes
26
41
 
27
- ### Features
42
+ - export file types
43
+ ([203cc73](https://github.com/flowcore-io/flowcore-pathways/commit/203cc735aaedcf9bf44f045fd8a15916917b7ac1))
44
+
45
+ ## [0.15.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.14.0...v0.15.0) (2025-05-27)
28
46
 
29
- * file writer + changes to write and writeBatch args ([5cbbb8f](https://github.com/flowcore-io/flowcore-pathways/commit/5cbbb8f83c5b8cdba11436565c4d36c1ad3faa61))
30
- * unified write method ([19f00bd](https://github.com/flowcore-io/flowcore-pathways/commit/19f00bd550d5b167e0104d9c8ef5a2751a909041))
47
+ ### Features
31
48
 
49
+ - file writer + changes to write and writeBatch args
50
+ ([5cbbb8f](https://github.com/flowcore-io/flowcore-pathways/commit/5cbbb8f83c5b8cdba11436565c4d36c1ad3faa61))
51
+ - unified write method
52
+ ([19f00bd](https://github.com/flowcore-io/flowcore-pathways/commit/19f00bd550d5b167e0104d9c8ef5a2751a909041))
32
53
 
33
54
  ### Bug Fixes
34
55
 
35
- * fix session pathway ([5b8b1a0](https://github.com/flowcore-io/flowcore-pathways/commit/5b8b1a0b846f97adb679ce79ddd61bdc8868caf9))
36
- * fix types ([2235058](https://github.com/flowcore-io/flowcore-pathways/commit/22350588845db0a1e320d80928653210048b9a29))
37
- * update readme ([2285c96](https://github.com/flowcore-io/flowcore-pathways/commit/2285c960d9f3d95c09092c91ab8b93b4fc98a94f))
38
- * update tests and readme ([c3af713](https://github.com/flowcore-io/flowcore-pathways/commit/c3af7133196bb5da5cf7f342c2922bb7ad778fe9))
56
+ - fix session pathway
57
+ ([5b8b1a0](https://github.com/flowcore-io/flowcore-pathways/commit/5b8b1a0b846f97adb679ce79ddd61bdc8868caf9))
58
+ - fix types
59
+ ([2235058](https://github.com/flowcore-io/flowcore-pathways/commit/22350588845db0a1e320d80928653210048b9a29))
60
+ - update readme
61
+ ([2285c96](https://github.com/flowcore-io/flowcore-pathways/commit/2285c960d9f3d95c09092c91ab8b93b4fc98a94f))
62
+ - update tests and readme
63
+ ([c3af713](https://github.com/flowcore-io/flowcore-pathways/commit/c3af7133196bb5da5cf7f342c2922bb7ad778fe9))
39
64
 
40
65
  ## [0.14.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.13.2...v0.14.0) (2025-05-23)
41
66
 
42
-
43
67
  ### Features
44
68
 
45
- * switch from typebox to zod ([e20e8f8](https://github.com/flowcore-io/flowcore-pathways/commit/e20e8f81a9cf68eaa598be5d43ef34f346f136ea))
46
-
69
+ - switch from typebox to zod
70
+ ([e20e8f8](https://github.com/flowcore-io/flowcore-pathways/commit/e20e8f81a9cf68eaa598be5d43ef34f346f136ea))
47
71
 
48
72
  ### Bug Fixes
49
73
 
50
- * fix tests ([05496b9](https://github.com/flowcore-io/flowcore-pathways/commit/05496b993669449d8bfe758e2647d4f2a2dbbf06))
51
- * set defaults on write and process ([c01ac59](https://github.com/flowcore-io/flowcore-pathways/commit/c01ac59cd4097d832c009e90e7259644e84a9612))
74
+ - fix tests
75
+ ([05496b9](https://github.com/flowcore-io/flowcore-pathways/commit/05496b993669449d8bfe758e2647d4f2a2dbbf06))
76
+ - set defaults on write and process
77
+ ([c01ac59](https://github.com/flowcore-io/flowcore-pathways/commit/c01ac59cd4097d832c009e90e7259644e84a9612))
52
78
 
53
79
  ## [0.13.2](https://github.com/flowcore-io/flowcore-pathways/compare/v0.13.1...v0.13.2) (2025-05-14)
54
80
 
55
-
56
81
  ### Performance Improvements
57
82
 
58
- * ability to adjust the log level of internal logs ([eaeb9c5](https://github.com/flowcore-io/flowcore-pathways/commit/eaeb9c58a53be3effb6ba54621535a531b11e82e))
83
+ - ability to adjust the log level of internal logs
84
+ ([eaeb9c5](https://github.com/flowcore-io/flowcore-pathways/commit/eaeb9c58a53be3effb6ba54621535a531b11e82e))
59
85
 
60
86
  ## [0.13.1](https://github.com/flowcore-io/flowcore-pathways/compare/v0.13.0...v0.13.1) (2025-04-22)
61
87
 
62
-
63
88
  ### Bug Fixes
64
89
 
65
- * **pathways:** :art: extract audit constants for better readability ([9a349b8](https://github.com/flowcore-io/flowcore-pathways/commit/9a349b865e8bc5627a50a4b132d368fcba4bf986))
90
+ - **pathways:** :art: extract audit constants for better readability
91
+ ([9a349b8](https://github.com/flowcore-io/flowcore-pathways/commit/9a349b865e8bc5627a50a4b132d368fcba4bf986))
66
92
 
67
93
  ## [0.13.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.12.0...v0.13.0) (2025-04-22)
68
94
 
package/README.md CHANGED
@@ -23,6 +23,7 @@ Pathways helps you build event-driven applications with type-safe pathways for p
23
23
  - [Custom Loggers](#custom-loggers)
24
24
  - [Retry Mechanisms](#retry-mechanisms)
25
25
  - [Session Pathways](#session-pathways)
26
+ - [File Pathways](#file-pathways)
26
27
  - [API Reference](#api-reference)
27
28
 
28
29
  ## Installation
@@ -210,6 +211,21 @@ const eventId3 = await pathways.write("order/placed", {
210
211
  fireAndForget: true,
211
212
  },
212
213
  })
214
+
215
+ // Batch write multiple events
216
+ const eventIds = await pathways.write("order/placed", {
217
+ batch: true,
218
+ data: [orderData1, orderData2, orderData3],
219
+ })
220
+
221
+ // Batch write with metadata
222
+ const eventIds2 = await pathways.write("order/placed", {
223
+ batch: true,
224
+ data: [orderData1, orderData2],
225
+ metadata: {
226
+ source: "bulk-import",
227
+ },
228
+ })
213
229
  ```
214
230
 
215
231
  ### Error Handling
@@ -354,18 +370,18 @@ Enable auditing to track events:
354
370
 
355
371
  ```typescript
356
372
  // Set up auditing
357
- pathways.withAudit(
358
- // Audit handler
359
- (path, event) => {
373
+ pathways
374
+ .withAudit((path, event) => {
360
375
  console.log(`Audit: ${path} event ${event.eventId}`)
361
376
  logToAuditSystem(path, event)
362
- },
363
- // User ID resolver
364
- async () => {
377
+ })
378
+ .withUserResolver(async () => {
365
379
  // Get the current user ID from context
366
- return getCurrentUserId()
367
- },
368
- )
380
+ return {
381
+ entityId: "user-123",
382
+ entityType: "user",
383
+ }
384
+ })
369
385
  ```
370
386
 
371
387
  ### Custom Loggers
@@ -502,6 +518,12 @@ await session.write("order/placed", {
502
518
  data: orderData,
503
519
  options: { sessionId: "different-session" },
504
520
  })
521
+
522
+ // Batch write events with session context
523
+ await session.write("user/actions", {
524
+ batch: true,
525
+ data: [actionData1, actionData2, actionData3],
526
+ })
505
527
  ```
506
528
 
507
529
  #### Session ID in Audit Events
@@ -520,6 +542,228 @@ await session.write("order/placed", { data: orderData })
520
542
  // The session ID is automatically included in the audit metadata
521
543
  ```
522
544
 
545
+ ### File Pathways
546
+
547
+ File pathways provide a specialized way to handle file uploads and processing in your Flowcore applications. They
548
+ automatically handle file type detection, binary content processing, and provide a structured approach to file
549
+ management.
550
+
551
+ #### Registering File Pathways
552
+
553
+ Register a file pathway by setting the `isFilePathway` flag to `true`:
554
+
555
+ ```typescript
556
+ import { z } from "zod"
557
+
558
+ // Define additional properties schema for your file
559
+ const documentSchema = z.object({
560
+ documentType: z.enum(["invoice", "receipt", "contract"]),
561
+ department: z.string(),
562
+ metadata: z.record(z.string()).optional(),
563
+ })
564
+
565
+ // Register a file pathway
566
+ pathways.register({
567
+ flowType: "document",
568
+ eventType: "uploaded",
569
+ schema: documentSchema, // Additional properties beyond the file itself
570
+ isFilePathway: true, // This marks it as a file pathway
571
+ writable: true,
572
+ })
573
+ ```
574
+
575
+ #### Writing Files to Pathways
576
+
577
+ File pathways use a special input format that includes file content and metadata:
578
+
579
+ ```typescript
580
+ import { readFile } from "node:fs/promises"
581
+
582
+ // Read file content (as Buffer for Node.js/Bun, Uint8Array for Deno)
583
+ const fileContent = await readFile("./invoice.pdf")
584
+
585
+ // Write a file to a pathway
586
+ const eventId = await pathways.write("document/uploaded", {
587
+ data: {
588
+ fileId: "file-123", // Unique identifier for the file
589
+ fileName: "invoice-2024.pdf", // Original filename
590
+ fileContent: fileContent, // File content as Buffer/Uint8Array
591
+ // Additional properties defined in your schema
592
+ documentType: "invoice",
593
+ department: "finance",
594
+ metadata: {
595
+ customer: "ACME Corp",
596
+ amount: "1500.00",
597
+ },
598
+ },
599
+ })
600
+ ```
601
+
602
+ #### File Input Schema
603
+
604
+ File pathways automatically include these required fields:
605
+
606
+ ```typescript
607
+ // Built-in file fields (automatically added)
608
+ interface FileInput {
609
+ fileId: string // Unique identifier for the file
610
+ fileName: string // Original filename with extension
611
+ fileContent: Buffer | Uint8Array // Binary file content
612
+ // ... your additional schema properties
613
+ }
614
+ ```
615
+
616
+ #### File Event Schema
617
+
618
+ When processed, file events include automatic file type detection:
619
+
620
+ ```typescript
621
+ // Built-in file event fields (automatically added to your schema)
622
+ interface FileEvent {
623
+ fileId: string // Unique identifier for the file
624
+ fileName: string // Original filename
625
+ fileType: string // MIME type (automatically detected)
626
+ fileContent: Blob // File content as Blob
627
+ // ... your additional schema properties
628
+ }
629
+ ```
630
+
631
+ #### Handling File Events
632
+
633
+ Handle file events just like regular events, but with access to file-specific properties:
634
+
635
+ ```typescript
636
+ pathways.handle("document/uploaded", async (event) => {
637
+ const { fileId, fileName, fileType, fileContent, documentType, department } = event.payload
638
+
639
+ console.log(`Processing file: ${fileName} (${fileType})`)
640
+ console.log(`Document type: ${documentType}, Department: ${department}`)
641
+
642
+ // Process the file content
643
+ if (fileType === "application/pdf") {
644
+ await processPDFDocument(fileContent, event.payload.metadata)
645
+ } else if (fileType.startsWith("image/")) {
646
+ await processImageFile(fileContent, documentType)
647
+ }
648
+
649
+ // Store file metadata
650
+ await storeFileMetadata({
651
+ fileId,
652
+ fileName,
653
+ fileType,
654
+ documentType,
655
+ department,
656
+ processedAt: new Date(),
657
+ })
658
+ })
659
+ ```
660
+
661
+ #### File Pathway Limitations
662
+
663
+ File pathways have some specific limitations:
664
+
665
+ ```typescript
666
+ // ❌ Batch writes are NOT supported for file pathways
667
+ // This will throw an error:
668
+ await pathways.write("document/uploaded", {
669
+ batch: true, // Error: Batch is not possible for file pathways
670
+ data: [fileData1, fileData2],
671
+ })
672
+
673
+ // ✅ Write files individually instead:
674
+ for (const fileData of fileDataArray) {
675
+ await pathways.write("document/uploaded", { data: fileData })
676
+ }
677
+ ```
678
+
679
+ #### Complete File Pathway Example
680
+
681
+ Here's a complete example of setting up and using file pathways:
682
+
683
+ ```typescript
684
+ import { PathwaysBuilder } from "@flowcore/pathways"
685
+ import { z } from "zod"
686
+ import { readFile } from "node:fs/promises"
687
+
688
+ // Define schema for additional file properties
689
+ const documentSchema = z.object({
690
+ documentType: z.enum(["invoice", "receipt", "contract", "report"]),
691
+ department: z.string(),
692
+ tags: z.array(z.string()).optional(),
693
+ metadata: z.record(z.string()).optional(),
694
+ })
695
+
696
+ const pathways = new PathwaysBuilder({
697
+ baseUrl: "https://api.flowcore.io",
698
+ tenant: "your-tenant",
699
+ dataCore: "your-data-core",
700
+ apiKey: "your-api-key",
701
+ })
702
+
703
+ // Register file pathway
704
+ pathways
705
+ .register({
706
+ flowType: "document",
707
+ eventType: "uploaded",
708
+ schema: documentSchema,
709
+ isFilePathway: true,
710
+ })
711
+ .handle("document/uploaded", async (event) => {
712
+ const { fileId, fileName, fileType, documentType, department } = event.payload
713
+
714
+ console.log(`Processing ${documentType} from ${department}: ${fileName}`)
715
+
716
+ // File type-specific processing
717
+ switch (fileType) {
718
+ case "application/pdf":
719
+ await extractPDFText(event.payload.fileContent)
720
+ break
721
+ case "image/jpeg":
722
+ case "image/png":
723
+ await extractImageMetadata(event.payload.fileContent)
724
+ break
725
+ default:
726
+ console.log(`Unsupported file type: ${fileType}`)
727
+ }
728
+
729
+ // Trigger downstream processing
730
+ await pathways.write("document/processed", {
731
+ data: {
732
+ fileId,
733
+ fileName,
734
+ documentType,
735
+ department,
736
+ processedAt: new Date().toISOString(),
737
+ status: "completed",
738
+ },
739
+ })
740
+ })
741
+
742
+ // Upload a file
743
+ async function uploadDocument(filePath: string, documentType: string, department: string) {
744
+ const fileContent = await readFile(filePath)
745
+ const fileName = filePath.split("/").pop() || "unknown"
746
+
747
+ return await pathways.write("document/uploaded", {
748
+ data: {
749
+ fileId: `doc-${Date.now()}`,
750
+ fileName,
751
+ fileContent,
752
+ documentType,
753
+ department,
754
+ tags: ["automated-upload"],
755
+ metadata: {
756
+ uploadedAt: new Date().toISOString(),
757
+ source: "api",
758
+ },
759
+ },
760
+ })
761
+ }
762
+
763
+ // Usage
764
+ await uploadDocument("./invoice.pdf", "invoice", "finance")
765
+ ```
766
+
523
767
  ## API Reference
524
768
 
525
769
  For a complete API reference, please see the [API documentation](https://jsr.io/@flowcore/pathways).
@@ -1,3 +1,16 @@
1
+ /**
2
+ * Connection pool configuration options for PostgreSQL
3
+ */
4
+ export interface PostgresPoolConfig {
5
+ /** Maximum number of connections in the pool (default: 10) */
6
+ max?: number;
7
+ /** Maximum lifetime in seconds for connections (default: random between 45-90 minutes) */
8
+ max_lifetime?: number;
9
+ /** Idle connection timeout in seconds (default: 0 - no timeout) */
10
+ idle_timeout?: number;
11
+ /** Connect timeout in seconds (default: 30) */
12
+ connect_timeout?: number;
13
+ }
1
14
  /**
2
15
  * Configuration for PostgreSQL connection using a connection string
3
16
  */
@@ -11,6 +24,8 @@ export interface PostgresConnectionStringConfig {
11
24
  password?: never;
12
25
  database?: never;
13
26
  ssl?: never;
27
+ /** Connection pool configuration */
28
+ pool?: PostgresPoolConfig;
14
29
  }
15
30
  /**
16
31
  * Configuration for PostgreSQL connection using individual parameters
@@ -30,6 +45,8 @@ export interface PostgresParametersConfig {
30
45
  database: string;
31
46
  /** Whether to use SSL for the connection */
32
47
  ssl?: boolean;
48
+ /** Connection pool configuration */
49
+ pool?: PostgresPoolConfig;
33
50
  }
34
51
  /**
35
52
  * Configuration options for PostgreSQL connection
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,gHAAgH;IAChH,gBAAgB,EAAE,MAAM,CAAA;IAExB,yEAAyE;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,GAAG,CAAC,EAAE,KAAK,CAAA;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,KAAK,CAAA;IAExB,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAA;IAChB,4CAA4C;IAC5C,GAAG,CAAC,EAAE,OAAO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dapter {
60
60
  try {
61
61
  const module = await import("postgres");
62
62
  this.postgres = module.default;
63
- this.sql = this.postgres(this.connectionString);
63
+ // Build postgres.js options from pool configuration
64
+ const postgresOptions = {};
65
+ if (this.config.pool) {
66
+ if (this.config.pool.max !== undefined) {
67
+ postgresOptions.max = this.config.pool.max;
68
+ }
69
+ if (this.config.pool.max_lifetime !== undefined) {
70
+ postgresOptions.max_lifetime = this.config.pool.max_lifetime;
71
+ }
72
+ if (this.config.pool.idle_timeout !== undefined) {
73
+ postgresOptions.idle_timeout = this.config.pool.idle_timeout;
74
+ }
75
+ if (this.config.pool.connect_timeout !== undefined) {
76
+ postgresOptions.connect_timeout = this.config.pool.connect_timeout;
77
+ }
78
+ }
79
+ this.sql = this.postgres(this.connectionString, postgresOptions);
64
80
  }
65
81
  catch (error) {
66
82
  console.error("Failed to connect to PostgreSQL:", error);
@@ -1,4 +1,5 @@
1
1
  import type { PathwayState } from "../types.js";
2
+ import type { PostgresPoolConfig } from "./postgres-adapter.js";
2
3
  /**
3
4
  * Configuration for PostgreSQL pathway state storage using a connection string
4
5
  */
@@ -16,6 +17,8 @@ export interface PostgresPathwayStateConnectionStringConfig {
16
17
  tableName?: string;
17
18
  /** Time-to-live in milliseconds for processed events (default: 5 minutes) */
18
19
  ttlMs?: number;
20
+ /** Connection pool configuration */
21
+ pool?: PostgresPoolConfig;
19
22
  }
20
23
  /**
21
24
  * Configuration for PostgreSQL pathway state storage using individual parameters
@@ -39,6 +42,8 @@ export interface PostgresPathwayStateParametersConfig {
39
42
  tableName?: string;
40
43
  /** Time-to-live in milliseconds for processed events (default: 5 minutes) */
41
44
  ttlMs?: number;
45
+ /** Connection pool configuration */
46
+ pool?: PostgresPoolConfig;
42
47
  }
43
48
  /**
44
49
  * Configuration options for PostgreSQL pathway state storage
@@ -74,7 +79,13 @@ export type PostgresPathwayStateConfig = PostgresPathwayStateConnectionStringCon
74
79
  * const postgresState = createPostgresPathwayState({
75
80
  * connectionString: "postgres://user:password@localhost:5432/mydb",
76
81
  * tableName: "event_processing_state", // Optional
77
- * ttlMs: 24 * 60 * 60 * 1000 // 24 hours (optional)
82
+ * ttlMs: 24 * 60 * 60 * 1000, // 24 hours (optional)
83
+ * pool: { // Optional connection pool configuration
84
+ * max: 20, // Maximum 20 connections in pool
85
+ * idle_timeout: 30, // Close idle connections after 30 seconds
86
+ * connect_timeout: 10, // 10 second connection timeout
87
+ * max_lifetime: 3600 // Connections live maximum 1 hour
88
+ * }
78
89
  * });
79
90
  *
80
91
  * // Or with individual parameters
@@ -86,7 +97,12 @@ export type PostgresPathwayStateConfig = PostgresPathwayStateConnectionStringCon
86
97
  * database: "mydb",
87
98
  * ssl: false,
88
99
  * tableName: "event_processing_state", // Optional
89
- * ttlMs: 30 * 60 * 1000 // 30 minutes (optional)
100
+ * ttlMs: 30 * 60 * 1000, // 30 minutes (optional)
101
+ * pool: { // Optional connection pool configuration
102
+ * max: 15, // Maximum 15 connections in pool
103
+ * idle_timeout: 60, // Close idle connections after 60 seconds
104
+ * connect_timeout: 5 // 5 second connection timeout
105
+ * }
90
106
  * });
91
107
  *
92
108
  * // Use with PathwaysBuilder
@@ -257,6 +273,17 @@ export declare class PostgresPathwayState implements PathwayState {
257
273
  * ttlMs: 7 * 24 * 60 * 60 * 1000 // 1 week
258
274
  * });
259
275
  *
276
+ * // With connection pool configuration
277
+ * const state = createPostgresPathwayState({
278
+ * connectionString: "postgres://user:pass@localhost:5432/db",
279
+ * pool: {
280
+ * max: 25, // Maximum 25 connections
281
+ * idle_timeout: 120, // Close idle connections after 2 minutes
282
+ * connect_timeout: 15, // 15 second connection timeout
283
+ * max_lifetime: 1800 // Connections live maximum 30 minutes
284
+ * }
285
+ * });
286
+ *
260
287
  * // Use with PathwaysBuilder
261
288
  * const pathways = new PathwaysBuilder({
262
289
  * // Other config
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-pathway-state.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-pathway-state.ts"],"names":[],"m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,CAAC,SAAS,CAAQ;IAEzB;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAQ;IAErB;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAQ;IAE3B;;;;OAIG;gBACiB,MAAM,EAAE,0BAA0B;IAMtD;;;;;OAKG;YACW,UAAU;IAyDxB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiBpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBlD;;;;;OAKG;YACW,cAAc;IAQ5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAGnG"}
@@ -25,7 +25,13 @@ import { createPostgresAdapter } from "./postgres-adapter.js";
25
25
  * const postgresState = createPostgresPathwayState({
26
26
  * connectionString: "postgres://user:password@localhost:5432/mydb",
27
27
  * tableName: "event_processing_state", // Optional
28
- * ttlMs: 24 * 60 * 60 * 1000 // 24 hours (optional)
28
+ * ttlMs: 24 * 60 * 60 * 1000, // 24 hours (optional)
29
+ * pool: { // Optional connection pool configuration
30
+ * max: 20, // Maximum 20 connections in pool
31
+ * idle_timeout: 30, // Close idle connections after 30 seconds
32
+ * connect_timeout: 10, // 10 second connection timeout
33
+ * max_lifetime: 3600 // Connections live maximum 1 hour
34
+ * }
29
35
  * });
30
36
  *
31
37
  * // Or with individual parameters
@@ -37,7 +43,12 @@ import { createPostgresAdapter } from "./postgres-adapter.js";
37
43
  * database: "mydb",
38
44
  * ssl: false,
39
45
  * tableName: "event_processing_state", // Optional
40
- * ttlMs: 30 * 60 * 1000 // 30 minutes (optional)
46
+ * ttlMs: 30 * 60 * 1000, // 30 minutes (optional)
47
+ * pool: { // Optional connection pool configuration
48
+ * max: 15, // Maximum 15 connections in pool
49
+ * idle_timeout: 60, // Close idle connections after 60 seconds
50
+ * connect_timeout: 5 // 5 second connection timeout
51
+ * }
41
52
  * });
42
53
  *
43
54
  * // Use with PathwaysBuilder
@@ -118,6 +129,7 @@ export class PostgresPathwayState {
118
129
  // Use connection string if provided
119
130
  this.postgres = await createPostgresAdapter({
120
131
  connectionString: this.config.connectionString,
132
+ pool: this.config.pool,
121
133
  });
122
134
  }
123
135
  else {
@@ -130,6 +142,7 @@ export class PostgresPathwayState {
130
142
  password: this.config.password,
131
143
  database: this.config.database,
132
144
  ssl: this.config.ssl,
145
+ pool: this.config.pool,
133
146
  });
134
147
  }
135
148
  // Check if the table exists
@@ -325,6 +338,17 @@ Object.defineProperty(PostgresPathwayState, "DEFAULT_TABLE_NAME", {
325
338
  * ttlMs: 7 * 24 * 60 * 60 * 1000 // 1 week
326
339
  * });
327
340
  *
341
+ * // With connection pool configuration
342
+ * const state = createPostgresPathwayState({
343
+ * connectionString: "postgres://user:pass@localhost:5432/db",
344
+ * pool: {
345
+ * max: 25, // Maximum 25 connections
346
+ * idle_timeout: 120, // Close idle connections after 2 minutes
347
+ * connect_timeout: 15, // 15 second connection timeout
348
+ * max_lifetime: 1800 // Connections live maximum 30 minutes
349
+ * }
350
+ * });
351
+ *
328
352
  * // Use with PathwaysBuilder
329
353
  * const pathways = new PathwaysBuilder({
330
354
  * // Other config
@@ -33,8 +33,14 @@ import type { EventMetadata, PathwayWriteOptions } from "./types.js";
33
33
  * session.withUserResolver(async () => getCurrentUserId());
34
34
  *
35
35
  * // Write events with session context
36
- * await session.write("order/placed", orderData);
37
- * await session.write("user/action", actionData);
36
+ * await session.write("order/placed", { data: orderData });
37
+ * await session.write("user/action", { data: actionData });
38
+ *
39
+ * // Write batch events with session context
40
+ * await session.write("user/actions", {
41
+ * batch: true,
42
+ * data: [actionData1, actionData2]
43
+ * });
38
44
  *
39
45
  * // All events will be associated with the same session ID
40
46
  * ```
@@ -84,7 +90,7 @@ export declare class SessionPathwayBuilder<TPathway extends Record<string, {
84
90
  * });
85
91
  *
86
92
  * // When writing events, the user ID will be automatically included
87
- * await session.write("user/action", actionData);
93
+ * await session.write("user/action", { data: actionData });
88
94
  * ```
89
95
  */
90
96
  withUserResolver(resolver: UserIdResolver): this;
@@ -92,11 +98,14 @@ export declare class SessionPathwayBuilder<TPathway extends Record<string, {
92
98
  * Writes data to a pathway, proxying to the underlying PathwaysBuilder
93
99
  *
94
100
  * @param path The pathway to write to
95
- * @param data The data to write
96
- * @param metadata Optional metadata to include with the event
97
- * @param options Optional write options
101
+ * @param input Object containing the data, metadata, options, and optional batch flag
98
102
  * @returns A promise that resolves to the event ID(s)
99
103
  */
100
- write<TPath extends TWritablePaths>(path: TPath, data: TPathway[TPath]["input"], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
104
+ write<TPath extends TWritablePaths, B extends boolean = false>(path: TPath, input: {
105
+ batch?: B;
106
+ data: B extends true ? TPathway[TPath]["input"][] : TPathway[TPath]["input"];
107
+ metadata?: EventMetadata;
108
+ options?: PathwayWriteOptions;
109
+ }): Promise<string | string[]>;
101
110
  }
102
111
  //# sourceMappingURL=session-pathway.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-pathway.d.ts","sourceRoot":"","sources":["../../src/pathways/session-pathway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAqBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,qBAAqB,CAEhC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MA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CAAC,SAAS,CAAQ;IAElC;;;;;OAKG;gBAED,eAAe,EAAE,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC,EAC1D,SAAS,CAAC,EAAE,MAAM;IAMpB;;;;OAIG;IACH,YAAY,IAAI,MAAM;IAItB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD;;;;;;OAMG;IACG,KAAK,CAAC,KAAK,SAAS,cAAc,EAAE,CAAC,SAAS,OAAO,GAAG,KAAK,EACjE,IAAI,EAAE,KAAK,EACX,KAAK,EAAE;QACL,KAAK,CAAC,EAAE,CAAC,CAAA;QACT,IAAI,EAAE,CAAC,SAAS,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAA;QAC5E,QAAQ,CAAC,EAAE,aAAa,CAAA;QACxB,OAAO,CAAC,EAAE,mBAAmB,CAAA;KAC9B,GACA,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;CAiB9B"}
@@ -48,8 +48,14 @@ function generateUUID() {
48
48
  * session.withUserResolver(async () => getCurrentUserId());
49
49
  *
50
50
  * // Write events with session context
51
- * await session.write("order/placed", orderData);
52
- * await session.write("user/action", actionData);
51
+ * await session.write("order/placed", { data: orderData });
52
+ * await session.write("user/action", { data: actionData });
53
+ *
54
+ * // Write batch events with session context
55
+ * await session.write("user/actions", {
56
+ * batch: true,
57
+ * data: [actionData1, actionData2]
58
+ * });
53
59
  *
54
60
  * // All events will be associated with the same session ID
55
61
  * ```
@@ -111,7 +117,7 @@ export class SessionPathwayBuilder {
111
117
  * });
112
118
  *
113
119
  * // When writing events, the user ID will be automatically included
114
- * await session.write("user/action", actionData);
120
+ * await session.write("user/action", { data: actionData });
115
121
  * ```
116
122
  */
117
123
  withUserResolver(resolver) {
@@ -122,17 +128,21 @@ export class SessionPathwayBuilder {
122
128
  * Writes data to a pathway, proxying to the underlying PathwaysBuilder
123
129
  *
124
130
  * @param path The pathway to write to
125
- * @param data The data to write
126
- * @param metadata Optional metadata to include with the event
127
- * @param options Optional write options
131
+ * @param input Object containing the data, metadata, options, and optional batch flag
128
132
  * @returns A promise that resolves to the event ID(s)
129
133
  */
130
- async write(path, data, metadata, options) {
134
+ async write(path, input) {
135
+ const { data, metadata, options, batch } = input;
131
136
  // Create new options object with session ID
132
137
  const finalOptions = options ? { ...options } : {};
133
138
  // Always include the session ID in the options
134
139
  finalOptions.sessionId = options?.sessionId ?? this.sessionId;
135
140
  // The PathwaysBuilder will handle session-specific user resolvers
136
- return await this.pathwaysBuilder.write(path, { data, metadata, options: finalOptions });
141
+ return await this.pathwaysBuilder.write(path, {
142
+ batch,
143
+ data,
144
+ metadata,
145
+ options: finalOptions,
146
+ });
137
147
  }
138
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowcore/pathways",
3
- "version": "0.15.3",
3
+ "version": "0.16.1",
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-pathways#readme",
6
6
  "repository": {
@@ -1,3 +1,16 @@
1
+ /**
2
+ * Connection pool configuration options for PostgreSQL
3
+ */
4
+ export interface PostgresPoolConfig {
5
+ /** Maximum number of connections in the pool (default: 10) */
6
+ max?: number;
7
+ /** Maximum lifetime in seconds for connections (default: random between 45-90 minutes) */
8
+ max_lifetime?: number;
9
+ /** Idle connection timeout in seconds (default: 0 - no timeout) */
10
+ idle_timeout?: number;
11
+ /** Connect timeout in seconds (default: 30) */
12
+ connect_timeout?: number;
13
+ }
1
14
  /**
2
15
  * Configuration for PostgreSQL connection using a connection string
3
16
  */
@@ -11,6 +24,8 @@ export interface PostgresConnectionStringConfig {
11
24
  password?: never;
12
25
  database?: never;
13
26
  ssl?: never;
27
+ /** Connection pool configuration */
28
+ pool?: PostgresPoolConfig;
14
29
  }
15
30
  /**
16
31
  * Configuration for PostgreSQL connection using individual parameters
@@ -30,6 +45,8 @@ export interface PostgresParametersConfig {
30
45
  database: string;
31
46
  /** Whether to use SSL for the connection */
32
47
  ssl?: boolean;
48
+ /** Connection pool configuration */
49
+ pool?: PostgresPoolConfig;
33
50
  }
34
51
  /**
35
52
  * Configuration options for PostgreSQL connection
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,gHAAgH;IAChH,gBAAgB,EAAE,MAAM,CAAA;IAExB,yEAAyE;IACzE,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,GAAG,CAAC,EAAE,KAAK,CAAA;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,KAAK,CAAA;IAExB,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAA;IAChB,4CAA4C;IAC5C,GAAG,CAAC,EAAE,OAAO,CAAA;CACd;AAED;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,8BAA8B,GAAG,wBAAwB,CAAA;AAEtF;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA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A;IAE3B;;;;;;OAMG;IACH,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IAErD;;;;;OAKG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxD;AAoBD;;GAEG;AACH,qBAAa,iBAAkB,YAAW,eAAe;IACvD,8CAA8C;IAC9C,OAAO,CAAC,QAAQ,CAA2F;IAC3G,oCAAoC;IACpC,OAAO,CAAC,GAAG,CAA8B;IACzC,mCAAmC;IACnC,OAAO,CAAC,MAAM,CAAgB;IAC9B,yDAAyD;IACzD,OAAO,CAAC,gBAAgB,CAAQ;IAEhC;;;;OAIG;gBACS,MAAM,EAAE,cAAc;IAgBlC;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA8B9B;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;;;;OAMG;IACG,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAO/D;;;;;OAKG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAMlE;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAI5F"}
@@ -87,7 +87,23 @@ class PostgresJsAdapter {
87
87
  try {
88
88
  const module = await Promise.resolve().then(() => __importStar(require("postgres")));
89
89
  this.postgres = module.default;
90
- this.sql = this.postgres(this.connectionString);
90
+ // Build postgres.js options from pool configuration
91
+ const postgresOptions = {};
92
+ if (this.config.pool) {
93
+ if (this.config.pool.max !== undefined) {
94
+ postgresOptions.max = this.config.pool.max;
95
+ }
96
+ if (this.config.pool.max_lifetime !== undefined) {
97
+ postgresOptions.max_lifetime = this.config.pool.max_lifetime;
98
+ }
99
+ if (this.config.pool.idle_timeout !== undefined) {
100
+ postgresOptions.idle_timeout = this.config.pool.idle_timeout;
101
+ }
102
+ if (this.config.pool.connect_timeout !== undefined) {
103
+ postgresOptions.connect_timeout = this.config.pool.connect_timeout;
104
+ }
105
+ }
106
+ this.sql = this.postgres(this.connectionString, postgresOptions);
91
107
  }
92
108
  catch (error) {
93
109
  console.error("Failed to connect to PostgreSQL:", error);
@@ -1,4 +1,5 @@
1
1
  import type { PathwayState } from "../types.js";
2
+ import type { PostgresPoolConfig } from "./postgres-adapter.js";
2
3
  /**
3
4
  * Configuration for PostgreSQL pathway state storage using a connection string
4
5
  */
@@ -16,6 +17,8 @@ export interface PostgresPathwayStateConnectionStringConfig {
16
17
  tableName?: string;
17
18
  /** Time-to-live in milliseconds for processed events (default: 5 minutes) */
18
19
  ttlMs?: number;
20
+ /** Connection pool configuration */
21
+ pool?: PostgresPoolConfig;
19
22
  }
20
23
  /**
21
24
  * Configuration for PostgreSQL pathway state storage using individual parameters
@@ -39,6 +42,8 @@ export interface PostgresPathwayStateParametersConfig {
39
42
  tableName?: string;
40
43
  /** Time-to-live in milliseconds for processed events (default: 5 minutes) */
41
44
  ttlMs?: number;
45
+ /** Connection pool configuration */
46
+ pool?: PostgresPoolConfig;
42
47
  }
43
48
  /**
44
49
  * Configuration options for PostgreSQL pathway state storage
@@ -74,7 +79,13 @@ export type PostgresPathwayStateConfig = PostgresPathwayStateConnectionStringCon
74
79
  * const postgresState = createPostgresPathwayState({
75
80
  * connectionString: "postgres://user:password@localhost:5432/mydb",
76
81
  * tableName: "event_processing_state", // Optional
77
- * ttlMs: 24 * 60 * 60 * 1000 // 24 hours (optional)
82
+ * ttlMs: 24 * 60 * 60 * 1000, // 24 hours (optional)
83
+ * pool: { // Optional connection pool configuration
84
+ * max: 20, // Maximum 20 connections in pool
85
+ * idle_timeout: 30, // Close idle connections after 30 seconds
86
+ * connect_timeout: 10, // 10 second connection timeout
87
+ * max_lifetime: 3600 // Connections live maximum 1 hour
88
+ * }
78
89
  * });
79
90
  *
80
91
  * // Or with individual parameters
@@ -86,7 +97,12 @@ export type PostgresPathwayStateConfig = PostgresPathwayStateConnectionStringCon
86
97
  * database: "mydb",
87
98
  * ssl: false,
88
99
  * tableName: "event_processing_state", // Optional
89
- * ttlMs: 30 * 60 * 1000 // 30 minutes (optional)
100
+ * ttlMs: 30 * 60 * 1000, // 30 minutes (optional)
101
+ * pool: { // Optional connection pool configuration
102
+ * max: 15, // Maximum 15 connections in pool
103
+ * idle_timeout: 60, // Close idle connections after 60 seconds
104
+ * connect_timeout: 5 // 5 second connection timeout
105
+ * }
90
106
  * });
91
107
  *
92
108
  * // Use with PathwaysBuilder
@@ -257,6 +273,17 @@ export declare class PostgresPathwayState implements PathwayState {
257
273
  * ttlMs: 7 * 24 * 60 * 60 * 1000 // 1 week
258
274
  * });
259
275
  *
276
+ * // With connection pool configuration
277
+ * const state = createPostgresPathwayState({
278
+ * connectionString: "postgres://user:pass@localhost:5432/db",
279
+ * pool: {
280
+ * max: 25, // Maximum 25 connections
281
+ * idle_timeout: 120, // Close idle connections after 2 minutes
282
+ * connect_timeout: 15, // 15 second connection timeout
283
+ * max_lifetime: 1800 // Connections live maximum 30 minutes
284
+ * }
285
+ * });
286
+ *
260
287
  * // Use with PathwaysBuilder
261
288
  * const pathways = new PathwaysBuilder({
262
289
  * // Other config
@@ -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,CAAA;AAI/C;;GAEG;AACH,MAAM,WAAW,0CAA0C;IACzD,gHAAgH;IAChH,gBAAgB,EAAE,MAAM,CAAA;IAExB,yEAAyE;IACzE,I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OAKG;YACW,UAAU;IAyDxB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiBpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBlD;;;;;OAKG;YACW,cAAc;IAQ5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAGnG"}
@@ -29,7 +29,13 @@ const postgres_adapter_js_1 = require("./postgres-adapter.js");
29
29
  * const postgresState = createPostgresPathwayState({
30
30
  * connectionString: "postgres://user:password@localhost:5432/mydb",
31
31
  * tableName: "event_processing_state", // Optional
32
- * ttlMs: 24 * 60 * 60 * 1000 // 24 hours (optional)
32
+ * ttlMs: 24 * 60 * 60 * 1000, // 24 hours (optional)
33
+ * pool: { // Optional connection pool configuration
34
+ * max: 20, // Maximum 20 connections in pool
35
+ * idle_timeout: 30, // Close idle connections after 30 seconds
36
+ * connect_timeout: 10, // 10 second connection timeout
37
+ * max_lifetime: 3600 // Connections live maximum 1 hour
38
+ * }
33
39
  * });
34
40
  *
35
41
  * // Or with individual parameters
@@ -41,7 +47,12 @@ const postgres_adapter_js_1 = require("./postgres-adapter.js");
41
47
  * database: "mydb",
42
48
  * ssl: false,
43
49
  * tableName: "event_processing_state", // Optional
44
- * ttlMs: 30 * 60 * 1000 // 30 minutes (optional)
50
+ * ttlMs: 30 * 60 * 1000, // 30 minutes (optional)
51
+ * pool: { // Optional connection pool configuration
52
+ * max: 15, // Maximum 15 connections in pool
53
+ * idle_timeout: 60, // Close idle connections after 60 seconds
54
+ * connect_timeout: 5 // 5 second connection timeout
55
+ * }
45
56
  * });
46
57
  *
47
58
  * // Use with PathwaysBuilder
@@ -122,6 +133,7 @@ class PostgresPathwayState {
122
133
  // Use connection string if provided
123
134
  this.postgres = await (0, postgres_adapter_js_1.createPostgresAdapter)({
124
135
  connectionString: this.config.connectionString,
136
+ pool: this.config.pool,
125
137
  });
126
138
  }
127
139
  else {
@@ -134,6 +146,7 @@ class PostgresPathwayState {
134
146
  password: this.config.password,
135
147
  database: this.config.database,
136
148
  ssl: this.config.ssl,
149
+ pool: this.config.pool,
137
150
  });
138
151
  }
139
152
  // Check if the table exists
@@ -330,6 +343,17 @@ Object.defineProperty(PostgresPathwayState, "DEFAULT_TABLE_NAME", {
330
343
  * ttlMs: 7 * 24 * 60 * 60 * 1000 // 1 week
331
344
  * });
332
345
  *
346
+ * // With connection pool configuration
347
+ * const state = createPostgresPathwayState({
348
+ * connectionString: "postgres://user:pass@localhost:5432/db",
349
+ * pool: {
350
+ * max: 25, // Maximum 25 connections
351
+ * idle_timeout: 120, // Close idle connections after 2 minutes
352
+ * connect_timeout: 15, // 15 second connection timeout
353
+ * max_lifetime: 1800 // Connections live maximum 30 minutes
354
+ * }
355
+ * });
356
+ *
333
357
  * // Use with PathwaysBuilder
334
358
  * const pathways = new PathwaysBuilder({
335
359
  * // Other config
@@ -33,8 +33,14 @@ import type { EventMetadata, PathwayWriteOptions } from "./types.js";
33
33
  * session.withUserResolver(async () => getCurrentUserId());
34
34
  *
35
35
  * // Write events with session context
36
- * await session.write("order/placed", orderData);
37
- * await session.write("user/action", actionData);
36
+ * await session.write("order/placed", { data: orderData });
37
+ * await session.write("user/action", { data: actionData });
38
+ *
39
+ * // Write batch events with session context
40
+ * await session.write("user/actions", {
41
+ * batch: true,
42
+ * data: [actionData1, actionData2]
43
+ * });
38
44
  *
39
45
  * // All events will be associated with the same session ID
40
46
  * ```
@@ -84,7 +90,7 @@ export declare class SessionPathwayBuilder<TPathway extends Record<string, {
84
90
  * });
85
91
  *
86
92
  * // When writing events, the user ID will be automatically included
87
- * await session.write("user/action", actionData);
93
+ * await session.write("user/action", { data: actionData });
88
94
  * ```
89
95
  */
90
96
  withUserResolver(resolver: UserIdResolver): this;
@@ -92,11 +98,14 @@ export declare class SessionPathwayBuilder<TPathway extends Record<string, {
92
98
  * Writes data to a pathway, proxying to the underlying PathwaysBuilder
93
99
  *
94
100
  * @param path The pathway to write to
95
- * @param data The data to write
96
- * @param metadata Optional metadata to include with the event
97
- * @param options Optional write options
101
+ * @param input Object containing the data, metadata, options, and optional batch flag
98
102
  * @returns A promise that resolves to the event ID(s)
99
103
  */
100
- write<TPath extends TWritablePaths>(path: TPath, data: TPathway[TPath]["input"], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
104
+ write<TPath extends TWritablePaths, B extends boolean = false>(path: TPath, input: {
105
+ batch?: B;
106
+ data: B extends true ? TPathway[TPath]["input"][] : TPathway[TPath]["input"];
107
+ metadata?: EventMetadata;
108
+ options?: PathwayWriteOptions;
109
+ }): Promise<string | string[]>;
101
110
  }
102
111
  //# sourceMappingURL=session-pathway.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-pathway.d.ts","sourceRoot":"","sources":["../../src/pathways/session-pathway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAqBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,qBAAqB,CAEhC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,GAAG,EAAE,EACzE,cAAc,SAAS,MAAM,QAAQ,GAAG,KAAK;IAE7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA2C;IAC3E,OAA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AAY,IAAI,MAAM;IAItB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD;;;;;;OAMG;IACG,KAAK,CAAC,KAAK,SAAS,cAAc,EAAE,CAAC,SAAS,OAAO,GAAG,KAAK,EACjE,IAAI,EAAE,KAAK,EACX,KAAK,EAAE;QACL,KAAK,CAAC,EAAE,CAAC,CAAA;QACT,IAAI,EAAE,CAAC,SAAS,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAA;QAC5E,QAAQ,CAAC,EAAE,aAAa,CAAA;QACxB,OAAO,CAAC,EAAE,mBAAmB,CAAA;KAC9B,GACA,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;CAiB9B"}
@@ -51,8 +51,14 @@ function generateUUID() {
51
51
  * session.withUserResolver(async () => getCurrentUserId());
52
52
  *
53
53
  * // Write events with session context
54
- * await session.write("order/placed", orderData);
55
- * await session.write("user/action", actionData);
54
+ * await session.write("order/placed", { data: orderData });
55
+ * await session.write("user/action", { data: actionData });
56
+ *
57
+ * // Write batch events with session context
58
+ * await session.write("user/actions", {
59
+ * batch: true,
60
+ * data: [actionData1, actionData2]
61
+ * });
56
62
  *
57
63
  * // All events will be associated with the same session ID
58
64
  * ```
@@ -114,7 +120,7 @@ class SessionPathwayBuilder {
114
120
  * });
115
121
  *
116
122
  * // When writing events, the user ID will be automatically included
117
- * await session.write("user/action", actionData);
123
+ * await session.write("user/action", { data: actionData });
118
124
  * ```
119
125
  */
120
126
  withUserResolver(resolver) {
@@ -125,18 +131,22 @@ class SessionPathwayBuilder {
125
131
  * Writes data to a pathway, proxying to the underlying PathwaysBuilder
126
132
  *
127
133
  * @param path The pathway to write to
128
- * @param data The data to write
129
- * @param metadata Optional metadata to include with the event
130
- * @param options Optional write options
134
+ * @param input Object containing the data, metadata, options, and optional batch flag
131
135
  * @returns A promise that resolves to the event ID(s)
132
136
  */
133
- async write(path, data, metadata, options) {
137
+ async write(path, input) {
138
+ const { data, metadata, options, batch } = input;
134
139
  // Create new options object with session ID
135
140
  const finalOptions = options ? { ...options } : {};
136
141
  // Always include the session ID in the options
137
142
  finalOptions.sessionId = options?.sessionId ?? this.sessionId;
138
143
  // The PathwaysBuilder will handle session-specific user resolvers
139
- return await this.pathwaysBuilder.write(path, { data, metadata, options: finalOptions });
144
+ return await this.pathwaysBuilder.write(path, {
145
+ batch,
146
+ data,
147
+ metadata,
148
+ options: finalOptions,
149
+ });
140
150
  }
141
151
  }
142
152
  exports.SessionPathwayBuilder = SessionPathwayBuilder;