@flowcore/pathways 0.16.0 → 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 +41 -28
- package/README.md +253 -9
- package/esm/pathways/session-pathway.d.ts +16 -7
- package/esm/pathways/session-pathway.d.ts.map +1 -1
- package/esm/pathways/session-pathway.js +18 -8
- package/package.json +1 -1
- package/script/pathways/session-pathway.d.ts +16 -7
- package/script/pathways/session-pathway.d.ts.map +1 -1
- package/script/pathways/session-pathway.js +18 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,81 +1,94 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.16.
|
|
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
|
+
|
|
8
|
+
* **session-pathway:** :art: update write method to accept structured input ([86e54a7](https://github.com/flowcore-io/flowcore-pathways/commit/86e54a79cb8bef32677f308eb51a50eef6d1f071))
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
## [0.16.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.3...v0.16.0) (2025-06-03)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
9
13
|
|
|
14
|
+
- **postgres:** :sparkles: add connection pool configuration options for PostgreSQL
|
|
15
|
+
([9ba9966](https://github.com/flowcore-io/flowcore-pathways/commit/9ba9966706c13bba441ef8538a0ecfe405191307))
|
|
10
16
|
|
|
11
17
|
### Bug Fixes
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
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))
|
|
15
23
|
|
|
16
24
|
## [0.15.3](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.2...v0.15.3) (2025-06-03)
|
|
17
25
|
|
|
18
|
-
|
|
19
26
|
### Bug Fixes
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
- add debug
|
|
29
|
+
([c5b0776](https://github.com/flowcore-io/flowcore-pathways/commit/c5b0776af5edfb64a568e497e31ed5181c59bb2d))
|
|
22
30
|
|
|
23
31
|
## [0.15.2](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.1...v0.15.2) (2025-06-03)
|
|
24
32
|
|
|
25
|
-
|
|
26
33
|
### Bug Fixes
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
- update transformer core
|
|
36
|
+
([1b621ef](https://github.com/flowcore-io/flowcore-pathways/commit/1b621ef076016d6ef0cf378a883a113df6c022c0))
|
|
29
37
|
|
|
30
38
|
## [0.15.1](https://github.com/flowcore-io/flowcore-pathways/compare/v0.15.0...v0.15.1) (2025-05-28)
|
|
31
39
|
|
|
32
|
-
|
|
33
40
|
### Bug Fixes
|
|
34
41
|
|
|
35
|
-
|
|
42
|
+
- export file types
|
|
43
|
+
([203cc73](https://github.com/flowcore-io/flowcore-pathways/commit/203cc735aaedcf9bf44f045fd8a15916917b7ac1))
|
|
36
44
|
|
|
37
45
|
## [0.15.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.14.0...v0.15.0) (2025-05-27)
|
|
38
46
|
|
|
39
|
-
|
|
40
47
|
### Features
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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))
|
|
45
53
|
|
|
46
54
|
### Bug Fixes
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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))
|
|
52
64
|
|
|
53
65
|
## [0.14.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.13.2...v0.14.0) (2025-05-23)
|
|
54
66
|
|
|
55
|
-
|
|
56
67
|
### Features
|
|
57
68
|
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
- switch from typebox to zod
|
|
70
|
+
([e20e8f8](https://github.com/flowcore-io/flowcore-pathways/commit/e20e8f81a9cf68eaa598be5d43ef34f346f136ea))
|
|
60
71
|
|
|
61
72
|
### Bug Fixes
|
|
62
73
|
|
|
63
|
-
|
|
64
|
-
|
|
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))
|
|
65
78
|
|
|
66
79
|
## [0.13.2](https://github.com/flowcore-io/flowcore-pathways/compare/v0.13.1...v0.13.2) (2025-05-14)
|
|
67
80
|
|
|
68
|
-
|
|
69
81
|
### Performance Improvements
|
|
70
82
|
|
|
71
|
-
|
|
83
|
+
- ability to adjust the log level of internal logs
|
|
84
|
+
([eaeb9c5](https://github.com/flowcore-io/flowcore-pathways/commit/eaeb9c58a53be3effb6ba54621535a531b11e82e))
|
|
72
85
|
|
|
73
86
|
## [0.13.1](https://github.com/flowcore-io/flowcore-pathways/compare/v0.13.0...v0.13.1) (2025-04-22)
|
|
74
87
|
|
|
75
|
-
|
|
76
88
|
### Bug Fixes
|
|
77
89
|
|
|
78
|
-
|
|
90
|
+
- **pathways:** :art: extract audit constants for better readability
|
|
91
|
+
([9a349b8](https://github.com/flowcore-io/flowcore-pathways/commit/9a349b865e8bc5627a50a4b132d368fcba4bf986))
|
|
79
92
|
|
|
80
93
|
## [0.13.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.12.0...v0.13.0) (2025-04-22)
|
|
81
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
|
|
358
|
-
|
|
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
|
-
|
|
364
|
-
async () => {
|
|
377
|
+
})
|
|
378
|
+
.withUserResolver(async () => {
|
|
365
379
|
// Get the current user ID from context
|
|
366
|
-
return
|
|
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).
|
|
@@ -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
|
|
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,
|
|
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
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;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,OAAO,CAAC,QAAQ,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
|
|
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,
|
|
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, {
|
|
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.16.
|
|
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": {
|
|
@@ -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
|
|
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,
|
|
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
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;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,OAAO,CAAC,QAAQ,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"}
|
|
@@ -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
|
|
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,
|
|
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, {
|
|
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;
|