@flowcore/pathways 0.2.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +420 -0
  3. package/esm/common/flowcore.type.d.ts +11 -0
  4. package/esm/common/flowcore.type.d.ts.map +1 -0
  5. package/esm/common/flowcore.type.js +1 -0
  6. package/esm/common/index.d.ts +7 -0
  7. package/esm/common/index.d.ts.map +1 -0
  8. package/esm/common/index.js +6 -0
  9. package/esm/compatibility/flowcore-transformer-core.sdk.d.ts +16 -0
  10. package/esm/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -0
  11. package/esm/compatibility/flowcore-transformer-core.sdk.js +11 -0
  12. package/esm/contracts/event.d.ts +20 -0
  13. package/esm/contracts/event.d.ts.map +1 -0
  14. package/esm/contracts/event.js +15 -0
  15. package/esm/contracts/index.d.ts +5 -0
  16. package/esm/contracts/index.d.ts.map +1 -0
  17. package/esm/contracts/index.js +4 -0
  18. package/esm/mod.d.ts +14 -0
  19. package/esm/mod.d.ts.map +1 -0
  20. package/esm/mod.js +13 -0
  21. package/esm/package.json +3 -0
  22. package/esm/pathways/builder.d.ts +91 -0
  23. package/esm/pathways/builder.d.ts.map +1 -0
  24. package/esm/pathways/builder.js +530 -0
  25. package/esm/pathways/index.d.ts +17 -0
  26. package/esm/pathways/index.d.ts.map +1 -0
  27. package/esm/pathways/index.js +16 -0
  28. package/esm/pathways/internal-pathway.state.d.ts +41 -0
  29. package/esm/pathways/internal-pathway.state.d.ts.map +1 -0
  30. package/esm/pathways/internal-pathway.state.js +64 -0
  31. package/esm/pathways/kv/bun-kv-adapter.d.ts +36 -0
  32. package/esm/pathways/kv/bun-kv-adapter.d.ts.map +1 -0
  33. package/esm/pathways/kv/bun-kv-adapter.js +47 -0
  34. package/esm/pathways/kv/kv-adapter.d.ts +34 -0
  35. package/esm/pathways/kv/kv-adapter.d.ts.map +1 -0
  36. package/esm/pathways/kv/kv-adapter.js +19 -0
  37. package/esm/pathways/kv/node-kv-adapter.d.ts +33 -0
  38. package/esm/pathways/kv/node-kv-adapter.d.ts.map +1 -0
  39. package/esm/pathways/kv/node-kv-adapter.js +44 -0
  40. package/esm/pathways/logger.d.ts +48 -0
  41. package/esm/pathways/logger.d.ts.map +1 -0
  42. package/esm/pathways/logger.js +26 -0
  43. package/esm/pathways/postgres/index.d.ts +9 -0
  44. package/esm/pathways/postgres/index.d.ts.map +1 -0
  45. package/esm/pathways/postgres/index.js +8 -0
  46. package/esm/pathways/postgres/postgres-adapter.d.ts +112 -0
  47. package/esm/pathways/postgres/postgres-adapter.d.ts.map +1 -0
  48. package/esm/pathways/postgres/postgres-adapter.js +113 -0
  49. package/esm/pathways/postgres/postgres-pathway-state.d.ts +113 -0
  50. package/esm/pathways/postgres/postgres-pathway-state.d.ts.map +1 -0
  51. package/esm/pathways/postgres/postgres-pathway-state.js +188 -0
  52. package/esm/pathways/types.d.ts +87 -0
  53. package/esm/pathways/types.d.ts.map +1 -0
  54. package/esm/pathways/types.js +1 -0
  55. package/esm/router/index.d.ts +35 -0
  56. package/esm/router/index.d.ts.map +1 -0
  57. package/esm/router/index.js +96 -0
  58. package/package.json +38 -0
  59. package/script/common/flowcore.type.d.ts +11 -0
  60. package/script/common/flowcore.type.d.ts.map +1 -0
  61. package/script/common/flowcore.type.js +2 -0
  62. package/script/common/index.d.ts +7 -0
  63. package/script/common/index.d.ts.map +1 -0
  64. package/script/common/index.js +22 -0
  65. package/script/compatibility/flowcore-transformer-core.sdk.d.ts +16 -0
  66. package/script/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -0
  67. package/script/compatibility/flowcore-transformer-core.sdk.js +17 -0
  68. package/script/contracts/event.d.ts +20 -0
  69. package/script/contracts/event.d.ts.map +1 -0
  70. package/script/contracts/event.js +18 -0
  71. package/script/contracts/index.d.ts +5 -0
  72. package/script/contracts/index.d.ts.map +1 -0
  73. package/script/contracts/index.js +20 -0
  74. package/script/mod.d.ts +14 -0
  75. package/script/mod.d.ts.map +1 -0
  76. package/script/mod.js +29 -0
  77. package/script/package.json +3 -0
  78. package/script/pathways/builder.d.ts +91 -0
  79. package/script/pathways/builder.d.ts.map +1 -0
  80. package/script/pathways/builder.js +534 -0
  81. package/script/pathways/index.d.ts +17 -0
  82. package/script/pathways/index.d.ts.map +1 -0
  83. package/script/pathways/index.js +32 -0
  84. package/script/pathways/internal-pathway.state.d.ts +41 -0
  85. package/script/pathways/internal-pathway.state.d.ts.map +1 -0
  86. package/script/pathways/internal-pathway.state.js +68 -0
  87. package/script/pathways/kv/bun-kv-adapter.d.ts +36 -0
  88. package/script/pathways/kv/bun-kv-adapter.d.ts.map +1 -0
  89. package/script/pathways/kv/bun-kv-adapter.js +51 -0
  90. package/script/pathways/kv/kv-adapter.d.ts +34 -0
  91. package/script/pathways/kv/kv-adapter.d.ts.map +1 -0
  92. package/script/pathways/kv/kv-adapter.js +45 -0
  93. package/script/pathways/kv/node-kv-adapter.d.ts +33 -0
  94. package/script/pathways/kv/node-kv-adapter.d.ts.map +1 -0
  95. package/script/pathways/kv/node-kv-adapter.js +51 -0
  96. package/script/pathways/logger.d.ts +48 -0
  97. package/script/pathways/logger.d.ts.map +1 -0
  98. package/script/pathways/logger.js +31 -0
  99. package/script/pathways/postgres/index.d.ts +9 -0
  100. package/script/pathways/postgres/index.d.ts.map +1 -0
  101. package/script/pathways/postgres/index.js +24 -0
  102. package/script/pathways/postgres/postgres-adapter.d.ts +112 -0
  103. package/script/pathways/postgres/postgres-adapter.d.ts.map +1 -0
  104. package/script/pathways/postgres/postgres-adapter.js +141 -0
  105. package/script/pathways/postgres/postgres-pathway-state.d.ts +113 -0
  106. package/script/pathways/postgres/postgres-pathway-state.d.ts.map +1 -0
  107. package/script/pathways/postgres/postgres-pathway-state.js +193 -0
  108. package/script/pathways/types.d.ts +87 -0
  109. package/script/pathways/types.d.ts.map +1 -0
  110. package/script/pathways/types.js +2 -0
  111. package/script/router/index.d.ts +35 -0
  112. package/script/router/index.d.ts.map +1 -0
  113. package/script/router/index.js +100 -0
@@ -0,0 +1,41 @@
1
+ import type { PathwayState } from "./types.js";
2
+ /**
3
+ * Internal implementation of PathwayState interface that uses KV storage
4
+ * for tracking processed events to prevent duplicate processing
5
+ *
6
+ * @implements {PathwayState}
7
+ */
8
+ export declare class InternalPathwayState implements PathwayState {
9
+ /**
10
+ * Default time-to-live for processed event records (5 minutes)
11
+ * @private
12
+ */
13
+ private static readonly DEFAULT_TTL_MS;
14
+ /**
15
+ * The KV adapter instance for storage
16
+ * @private
17
+ */
18
+ private kv;
19
+ /**
20
+ * Gets or initializes the KV adapter
21
+ *
22
+ * @private
23
+ * @returns {Promise<KvAdapter>} The KV adapter instance
24
+ */
25
+ private getKv;
26
+ /**
27
+ * Checks if an event has already been processed
28
+ *
29
+ * @param {string} eventId - The ID of the event to check
30
+ * @returns {Promise<boolean>} True if the event has been processed, false otherwise
31
+ */
32
+ isProcessed(eventId: string): Promise<boolean>;
33
+ /**
34
+ * Marks an event as processed
35
+ *
36
+ * @param {string} eventId - The ID of the event to mark as processed
37
+ * @returns {Promise<void>}
38
+ */
39
+ setProcessed(eventId: string): Promise<void>;
40
+ }
41
+ //# sourceMappingURL=internal-pathway.state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-pathway.state.d.ts","sourceRoot":"","sources":["../../src/pathways/internal-pathway.state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAEvD;;;OAGG;IACH,OAAO,CAAC,EAAE,CAA0B;IAEpC;;;;;OAKG;YACW,KAAK;IAOnB;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMpD;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAInD"}
@@ -0,0 +1,64 @@
1
+ import { createKvAdapter } from "./kv/kv-adapter.js";
2
+ /**
3
+ * Internal implementation of PathwayState interface that uses KV storage
4
+ * for tracking processed events to prevent duplicate processing
5
+ *
6
+ * @implements {PathwayState}
7
+ */
8
+ export class InternalPathwayState {
9
+ constructor() {
10
+ /**
11
+ * The KV adapter instance for storage
12
+ * @private
13
+ */
14
+ Object.defineProperty(this, "kv", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: null
19
+ });
20
+ }
21
+ /**
22
+ * Gets or initializes the KV adapter
23
+ *
24
+ * @private
25
+ * @returns {Promise<KvAdapter>} The KV adapter instance
26
+ */
27
+ async getKv() {
28
+ if (!this.kv) {
29
+ this.kv = await createKvAdapter();
30
+ }
31
+ return this.kv;
32
+ }
33
+ /**
34
+ * Checks if an event has already been processed
35
+ *
36
+ * @param {string} eventId - The ID of the event to check
37
+ * @returns {Promise<boolean>} True if the event has been processed, false otherwise
38
+ */
39
+ async isProcessed(eventId) {
40
+ const kv = await this.getKv();
41
+ const result = await kv.get(eventId);
42
+ return result === true;
43
+ }
44
+ /**
45
+ * Marks an event as processed
46
+ *
47
+ * @param {string} eventId - The ID of the event to mark as processed
48
+ * @returns {Promise<void>}
49
+ */
50
+ async setProcessed(eventId) {
51
+ const kv = await this.getKv();
52
+ await kv.set(eventId, true, InternalPathwayState.DEFAULT_TTL_MS);
53
+ }
54
+ }
55
+ /**
56
+ * Default time-to-live for processed event records (5 minutes)
57
+ * @private
58
+ */
59
+ Object.defineProperty(InternalPathwayState, "DEFAULT_TTL_MS", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: 5 * 60 * 1000
64
+ }); // 5 minutes
@@ -0,0 +1,36 @@
1
+ import type { KvAdapter } from "./kv-adapter.js";
2
+ /**
3
+ * KV adapter implementation for Bun runtime
4
+ *
5
+ * Uses Bun's SQLite-based key-value store for storage
6
+ *
7
+ * @implements {KvAdapter}
8
+ */
9
+ export declare class BunKvAdapter implements KvAdapter {
10
+ /**
11
+ * The underlying Bun SQLite key-value store
12
+ * @private
13
+ */
14
+ private store;
15
+ /**
16
+ * Creates a new in-memory Bun KV adapter
17
+ */
18
+ constructor();
19
+ /**
20
+ * Retrieves a value from the Bun KV store
21
+ *
22
+ * @template T The expected type of the stored value
23
+ * @param {string} key The key to retrieve
24
+ * @returns {T | null} The stored value or null if not found
25
+ */
26
+ get<T>(key: string): T | null;
27
+ /**
28
+ * Stores a value in the Bun KV store with the specified TTL
29
+ *
30
+ * @param {string} key The key to store the value under
31
+ * @param {unknown} value The value to store
32
+ * @param {number} ttlMs Time-to-live in milliseconds
33
+ */
34
+ set(key: string, value: unknown, ttlMs: number): void;
35
+ }
36
+ //# sourceMappingURL=bun-kv-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun-kv-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/kv/bun-kv-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;;;GAMG;AACH,qBAAa,YAAa,YAAW,SAAS;IAC5C;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAoB;IAEjC;;OAEG;;IAKH;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAK7B;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAGtD"}
@@ -0,0 +1,47 @@
1
+ import { BunSqliteKeyValue } from "bun-sqlite-key-value";
2
+ /**
3
+ * KV adapter implementation for Bun runtime
4
+ *
5
+ * Uses Bun's SQLite-based key-value store for storage
6
+ *
7
+ * @implements {KvAdapter}
8
+ */
9
+ export class BunKvAdapter {
10
+ /**
11
+ * Creates a new in-memory Bun KV adapter
12
+ */
13
+ constructor() {
14
+ /**
15
+ * The underlying Bun SQLite key-value store
16
+ * @private
17
+ */
18
+ Object.defineProperty(this, "store", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ this.store = new BunSqliteKeyValue(":memory:");
25
+ }
26
+ /**
27
+ * Retrieves a value from the Bun KV store
28
+ *
29
+ * @template T The expected type of the stored value
30
+ * @param {string} key The key to retrieve
31
+ * @returns {T | null} The stored value or null if not found
32
+ */
33
+ get(key) {
34
+ const value = this.store.get(key);
35
+ return value;
36
+ }
37
+ /**
38
+ * Stores a value in the Bun KV store with the specified TTL
39
+ *
40
+ * @param {string} key The key to store the value under
41
+ * @param {unknown} value The value to store
42
+ * @param {number} ttlMs Time-to-live in milliseconds
43
+ */
44
+ set(key, value, ttlMs) {
45
+ this.store.set(key, value, ttlMs);
46
+ }
47
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Interface for key-value storage adapters
3
+ *
4
+ * Provides a common interface for different KV storage implementations
5
+ * that can be used for storing pathway state.
6
+ */
7
+ export interface KvAdapter {
8
+ /**
9
+ * Retrieves a value from storage by key
10
+ *
11
+ * @template T The expected type of the stored value
12
+ * @param {string} key The key to retrieve
13
+ * @returns {(Promise<T | null> | T | null)} The stored value or null if not found
14
+ */
15
+ get<T>(key: string): (Promise<T | null> | T | null);
16
+ /**
17
+ * Stores a value in storage with the specified key and TTL
18
+ *
19
+ * @param {string} key The key to store the value under
20
+ * @param {unknown} value The value to store
21
+ * @param {number} ttlMs Time-to-live in milliseconds
22
+ * @returns {(Promise<void> | void)}
23
+ */
24
+ set(key: string, value: unknown, ttlMs: number): (Promise<void> | void);
25
+ }
26
+ /**
27
+ * Creates an appropriate KV adapter based on the runtime environment
28
+ *
29
+ * Attempts to use Bun KV adapter if running in Bun, falls back to Node adapter otherwise
30
+ *
31
+ * @returns {Promise<KvAdapter>} A KV adapter instance
32
+ */
33
+ export declare function createKvAdapter(): Promise<KvAdapter>;
34
+ //# sourceMappingURL=kv-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kv-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/kv/kv-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAEpD;;;;;;;OAOG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;CACzE;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC,CAU1D"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Creates an appropriate KV adapter based on the runtime environment
3
+ *
4
+ * Attempts to use Bun KV adapter if running in Bun, falls back to Node adapter otherwise
5
+ *
6
+ * @returns {Promise<KvAdapter>} A KV adapter instance
7
+ */
8
+ export async function createKvAdapter() {
9
+ try {
10
+ // Try to import Bun adapter
11
+ const { BunKvAdapter } = await import("./bun-kv-adapter.js");
12
+ return new BunKvAdapter();
13
+ }
14
+ catch {
15
+ // Default to node-cache if Bun is not available
16
+ const { NodeKvAdapter } = await import("./node-kv-adapter.js");
17
+ return new NodeKvAdapter();
18
+ }
19
+ }
@@ -0,0 +1,33 @@
1
+ import type { KvAdapter } from "./kv-adapter.js";
2
+ /**
3
+ * KV adapter implementation for Node.js runtime
4
+ *
5
+ * Uses node-cache for in-memory key-value storage
6
+ *
7
+ * @implements {KvAdapter}
8
+ */
9
+ export declare class NodeKvAdapter implements KvAdapter {
10
+ /**
11
+ * The underlying Node.js cache instance
12
+ * @private
13
+ */
14
+ private readonly kv;
15
+ /**
16
+ * Retrieves a value from the Node.js cache
17
+ *
18
+ * @template T The expected type of the stored value
19
+ * @param {string} key The key to retrieve
20
+ * @returns {Promise<T | null>} The stored value or null if not found
21
+ */
22
+ get<T>(key: string): Promise<T | null>;
23
+ /**
24
+ * Stores a value in the Node.js cache with the specified TTL
25
+ *
26
+ * @param {string} key The key to store the value under
27
+ * @param {unknown} value The value to store
28
+ * @param {number} ttlMs Time-to-live in milliseconds
29
+ * @returns {Promise<void>}
30
+ */
31
+ set(key: string, value: unknown, ttlMs: number): Promise<void>;
32
+ }
33
+ //# sourceMappingURL=node-kv-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-kv-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/kv/node-kv-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;;;;GAMG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC7C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAmB;IAEtC;;;;;;OAMG;IACG,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAK5C;;;;;;;OAOG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGrE"}
@@ -0,0 +1,44 @@
1
+ import NodeCache from "node-cache";
2
+ /**
3
+ * KV adapter implementation for Node.js runtime
4
+ *
5
+ * Uses node-cache for in-memory key-value storage
6
+ *
7
+ * @implements {KvAdapter}
8
+ */
9
+ export class NodeKvAdapter {
10
+ constructor() {
11
+ /**
12
+ * The underlying Node.js cache instance
13
+ * @private
14
+ */
15
+ Object.defineProperty(this, "kv", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: new NodeCache()
20
+ });
21
+ }
22
+ /**
23
+ * Retrieves a value from the Node.js cache
24
+ *
25
+ * @template T The expected type of the stored value
26
+ * @param {string} key The key to retrieve
27
+ * @returns {Promise<T | null>} The stored value or null if not found
28
+ */
29
+ async get(key) {
30
+ const result = await this.kv.get(key);
31
+ return result ?? null;
32
+ }
33
+ /**
34
+ * Stores a value in the Node.js cache with the specified TTL
35
+ *
36
+ * @param {string} key The key to store the value under
37
+ * @param {unknown} value The value to store
38
+ * @param {number} ttlMs Time-to-live in milliseconds
39
+ * @returns {Promise<void>}
40
+ */
41
+ async set(key, value, ttlMs) {
42
+ await this.kv.set(key, value, (ttlMs / 1000));
43
+ }
44
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Logger interface that can be implemented by users to capture logs from pathways
3
+ */
4
+ export interface Logger {
5
+ /**
6
+ * Log debug information
7
+ * @param message The message to log
8
+ * @param context Optional context data to include
9
+ */
10
+ debug(message: string, context?: Record<string, unknown>): void;
11
+ /**
12
+ * Log informational messages
13
+ * @param message The message to log
14
+ * @param context Optional context data to include
15
+ */
16
+ info(message: string, context?: Record<string, unknown>): void;
17
+ /**
18
+ * Log warning messages
19
+ * @param message The message to log
20
+ * @param context Optional context data to include
21
+ */
22
+ warn(message: string, context?: Record<string, unknown>): void;
23
+ /**
24
+ * Log error messages
25
+ * @param message The message to log
26
+ * @param context Optional context data to include
27
+ */
28
+ error(message: string, context?: Record<string, unknown>): void;
29
+ }
30
+ /**
31
+ * A default console logger that logs to the console
32
+ */
33
+ export declare class ConsoleLogger implements Logger {
34
+ debug(message: string, context?: Record<string, unknown>): void;
35
+ info(message: string, context?: Record<string, unknown>): void;
36
+ warn(message: string, context?: Record<string, unknown>): void;
37
+ error(message: string, context?: Record<string, unknown>): void;
38
+ }
39
+ /**
40
+ * A no-operation logger that does nothing
41
+ */
42
+ export declare class NoopLogger implements Logger {
43
+ debug(_message: string, _context?: Record<string, unknown>): void;
44
+ info(_message: string, _context?: Record<string, unknown>): void;
45
+ warn(_message: string, _context?: Record<string, unknown>): void;
46
+ error(_message: string, _context?: Record<string, unknown>): void;
47
+ }
48
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/pathways/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAE/D;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAE9D;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAE9D;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;CAChE;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,MAAM;IAC1C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI/D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI9D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAGhE;AAED;;GAEG;AACH,qBAAa,UAAW,YAAW,MAAM;IACvC,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IACjE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAChE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAChE,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAClE"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * A default console logger that logs to the console
3
+ */
4
+ export class ConsoleLogger {
5
+ debug(message, context) {
6
+ console.debug(message, context ? JSON.stringify(context) : '');
7
+ }
8
+ info(message, context) {
9
+ console.info(message, context ? JSON.stringify(context) : '');
10
+ }
11
+ warn(message, context) {
12
+ console.warn(message, context ? JSON.stringify(context) : '');
13
+ }
14
+ error(message, context) {
15
+ console.error(message, context ? JSON.stringify(context) : '');
16
+ }
17
+ }
18
+ /**
19
+ * A no-operation logger that does nothing
20
+ */
21
+ export class NoopLogger {
22
+ debug(_message, _context) { }
23
+ info(_message, _context) { }
24
+ warn(_message, _context) { }
25
+ error(_message, _context) { }
26
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * PostgreSQL integration for Flowcore Pathways
3
+ *
4
+ * This module exports components for using PostgreSQL as a storage backend
5
+ * for pathway state and other persistent data.
6
+ */
7
+ export * from "./postgres-adapter.js";
8
+ export * from "./postgres-pathway-state.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * PostgreSQL integration for Flowcore Pathways
3
+ *
4
+ * This module exports components for using PostgreSQL as a storage backend
5
+ * for pathway state and other persistent data.
6
+ */
7
+ export * from "./postgres-adapter.js";
8
+ export * from "./postgres-pathway-state.js";
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Configuration options for PostgreSQL connection
3
+ *
4
+ * @interface PostgresConfig
5
+ */
6
+ export interface PostgresConfig {
7
+ /** PostgreSQL server hostname */
8
+ host: string;
9
+ /** PostgreSQL server port */
10
+ port: number;
11
+ /** PostgreSQL username */
12
+ user: string;
13
+ /** PostgreSQL password */
14
+ password: string;
15
+ /** PostgreSQL database name */
16
+ database: string;
17
+ /** Whether to use SSL for the connection */
18
+ ssl?: boolean;
19
+ }
20
+ /**
21
+ * Interface for PostgreSQL database operations
22
+ *
23
+ * Provides methods for connecting, querying, and executing SQL statements
24
+ *
25
+ * @interface PostgresAdapter
26
+ */
27
+ export interface PostgresAdapter {
28
+ /**
29
+ * Establishes a connection to the PostgreSQL database
30
+ * @returns {Promise<void>}
31
+ */
32
+ connect(): Promise<void>;
33
+ /**
34
+ * Closes the connection to the PostgreSQL database
35
+ * @returns {Promise<void>}
36
+ */
37
+ disconnect(): Promise<void>;
38
+ /**
39
+ * Executes a SQL query and returns the results
40
+ * @template T The expected result type
41
+ * @param {string} sql The SQL query to execute
42
+ * @param {unknown[]} [params] Optional parameters for the query
43
+ * @returns {Promise<T>} The query results
44
+ */
45
+ query<T>(sql: string, params?: unknown[]): Promise<T>;
46
+ /**
47
+ * Executes a SQL statement without returning results
48
+ * @param {string} sql The SQL statement to execute
49
+ * @param {unknown[]} [params] Optional parameters for the statement
50
+ * @returns {Promise<void>}
51
+ */
52
+ execute(sql: string, params?: unknown[]): Promise<void>;
53
+ }
54
+ /**
55
+ * Implementation of PostgresAdapter using the postgres.js library
56
+ *
57
+ * @implements {PostgresAdapter}
58
+ */
59
+ export declare class PostgresJsAdapter implements PostgresAdapter {
60
+ /** The postgres.js client factory function */
61
+ private postgres;
62
+ /** The active postgres.js client */
63
+ private sql;
64
+ /** The PostgreSQL configuration */
65
+ private config;
66
+ /** The connection string built from the configuration */
67
+ private connectionString;
68
+ /**
69
+ * Creates a new PostgresJsAdapter instance
70
+ *
71
+ * @param {PostgresConfig} config The PostgreSQL connection configuration
72
+ */
73
+ constructor(config: PostgresConfig);
74
+ /**
75
+ * Establishes a connection to the PostgreSQL database
76
+ *
77
+ * @returns {Promise<void>}
78
+ * @throws {Error} If connection fails
79
+ */
80
+ connect(): Promise<void>;
81
+ /**
82
+ * Closes the connection to the PostgreSQL database
83
+ *
84
+ * @returns {Promise<void>}
85
+ */
86
+ disconnect(): Promise<void>;
87
+ /**
88
+ * Executes a SQL query and returns the results
89
+ *
90
+ * @template T The expected result type
91
+ * @param {string} sql The SQL query to execute
92
+ * @param {unknown[]} [params=[]] Optional parameters for the query
93
+ * @returns {Promise<T>} The query results
94
+ */
95
+ query<T>(sql: string, params?: unknown[]): Promise<T>;
96
+ /**
97
+ * Executes a SQL statement without returning results
98
+ *
99
+ * @param {string} sql The SQL statement to execute
100
+ * @param {unknown[]} [params=[]] Optional parameters for the statement
101
+ * @returns {Promise<void>}
102
+ */
103
+ execute(sql: string, params?: unknown[]): Promise<void>;
104
+ }
105
+ /**
106
+ * Creates and initializes a PostgreSQL adapter
107
+ *
108
+ * @param {PostgresConfig} config The PostgreSQL connection configuration
109
+ * @returns {Promise<PostgresAdapter>} An initialized PostgreSQL adapter
110
+ */
111
+ export declare function createPostgresAdapter(config: PostgresConfig): Promise<PostgresAdapter>;
112
+ //# sourceMappingURL=postgres-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,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;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;OAGG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;;;;OAMG;IACH,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAEtD;;;;;OAKG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAoBD;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,eAAe;IACvD,8CAA8C;IAC9C,OAAO,CAAC,QAAQ,CAA+D;IAC/E,oCAAoC;IACpC,OAAO,CAAC,GAAG,CAA+B;IAC1C,mCAAmC;IACnC,OAAO,CAAC,MAAM,CAAiB;IAC/B,yDAAyD;IACzD,OAAO,CAAC,gBAAgB,CAAS;IAEjC;;;;OAIG;gBACS,MAAM,EAAE,cAAc;IAQlC;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAW9B;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;;;;;OAOG;IACG,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAO/D;;;;;;OAMG;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"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Implementation of PostgresAdapter using the postgres.js library
3
+ *
4
+ * @implements {PostgresAdapter}
5
+ */
6
+ export class PostgresJsAdapter {
7
+ /**
8
+ * Creates a new PostgresJsAdapter instance
9
+ *
10
+ * @param {PostgresConfig} config The PostgreSQL connection configuration
11
+ */
12
+ constructor(config) {
13
+ /** The postgres.js client factory function */
14
+ Object.defineProperty(this, "postgres", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: null
19
+ });
20
+ /** The active postgres.js client */
21
+ Object.defineProperty(this, "sql", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: null
26
+ });
27
+ /** The PostgreSQL configuration */
28
+ Object.defineProperty(this, "config", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: void 0
33
+ });
34
+ /** The connection string built from the configuration */
35
+ Object.defineProperty(this, "connectionString", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ this.config = config;
42
+ this.connectionString = `postgres://${config.user}:${config.password}@${config.host}:${config.port}/${config.database}`;
43
+ if (config.ssl) {
44
+ this.connectionString += "?sslmode=require";
45
+ }
46
+ }
47
+ /**
48
+ * Establishes a connection to the PostgreSQL database
49
+ *
50
+ * @returns {Promise<void>}
51
+ * @throws {Error} If connection fails
52
+ */
53
+ async connect() {
54
+ try {
55
+ const module = await import("postgres");
56
+ this.postgres = module.default;
57
+ this.sql = this.postgres(this.connectionString);
58
+ }
59
+ catch (error) {
60
+ console.error("Failed to connect to PostgreSQL:", error);
61
+ throw error;
62
+ }
63
+ }
64
+ /**
65
+ * Closes the connection to the PostgreSQL database
66
+ *
67
+ * @returns {Promise<void>}
68
+ */
69
+ async disconnect() {
70
+ if (this.sql) {
71
+ await this.sql.end();
72
+ this.sql = null;
73
+ }
74
+ }
75
+ /**
76
+ * Executes a SQL query and returns the results
77
+ *
78
+ * @template T The expected result type
79
+ * @param {string} sql The SQL query to execute
80
+ * @param {unknown[]} [params=[]] Optional parameters for the query
81
+ * @returns {Promise<T>} The query results
82
+ */
83
+ async query(sql, params = []) {
84
+ if (!this.sql) {
85
+ await this.connect();
86
+ }
87
+ return await this.sql.unsafe(sql, params);
88
+ }
89
+ /**
90
+ * Executes a SQL statement without returning results
91
+ *
92
+ * @param {string} sql The SQL statement to execute
93
+ * @param {unknown[]} [params=[]] Optional parameters for the statement
94
+ * @returns {Promise<void>}
95
+ */
96
+ async execute(sql, params = []) {
97
+ if (!this.sql) {
98
+ await this.connect();
99
+ }
100
+ await this.sql.unsafe(sql, params);
101
+ }
102
+ }
103
+ /**
104
+ * Creates and initializes a PostgreSQL adapter
105
+ *
106
+ * @param {PostgresConfig} config The PostgreSQL connection configuration
107
+ * @returns {Promise<PostgresAdapter>} An initialized PostgreSQL adapter
108
+ */
109
+ export async function createPostgresAdapter(config) {
110
+ const adapter = new PostgresJsAdapter(config);
111
+ await adapter.connect();
112
+ return adapter;
113
+ }