@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.
- package/CHANGELOG.md +36 -0
- package/README.md +420 -0
- package/esm/common/flowcore.type.d.ts +11 -0
- package/esm/common/flowcore.type.d.ts.map +1 -0
- package/esm/common/flowcore.type.js +1 -0
- package/esm/common/index.d.ts +7 -0
- package/esm/common/index.d.ts.map +1 -0
- package/esm/common/index.js +6 -0
- package/esm/compatibility/flowcore-transformer-core.sdk.d.ts +16 -0
- package/esm/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -0
- package/esm/compatibility/flowcore-transformer-core.sdk.js +11 -0
- package/esm/contracts/event.d.ts +20 -0
- package/esm/contracts/event.d.ts.map +1 -0
- package/esm/contracts/event.js +15 -0
- package/esm/contracts/index.d.ts +5 -0
- package/esm/contracts/index.d.ts.map +1 -0
- package/esm/contracts/index.js +4 -0
- package/esm/mod.d.ts +14 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +13 -0
- package/esm/package.json +3 -0
- package/esm/pathways/builder.d.ts +91 -0
- package/esm/pathways/builder.d.ts.map +1 -0
- package/esm/pathways/builder.js +530 -0
- package/esm/pathways/index.d.ts +17 -0
- package/esm/pathways/index.d.ts.map +1 -0
- package/esm/pathways/index.js +16 -0
- package/esm/pathways/internal-pathway.state.d.ts +41 -0
- package/esm/pathways/internal-pathway.state.d.ts.map +1 -0
- package/esm/pathways/internal-pathway.state.js +64 -0
- package/esm/pathways/kv/bun-kv-adapter.d.ts +36 -0
- package/esm/pathways/kv/bun-kv-adapter.d.ts.map +1 -0
- package/esm/pathways/kv/bun-kv-adapter.js +47 -0
- package/esm/pathways/kv/kv-adapter.d.ts +34 -0
- package/esm/pathways/kv/kv-adapter.d.ts.map +1 -0
- package/esm/pathways/kv/kv-adapter.js +19 -0
- package/esm/pathways/kv/node-kv-adapter.d.ts +33 -0
- package/esm/pathways/kv/node-kv-adapter.d.ts.map +1 -0
- package/esm/pathways/kv/node-kv-adapter.js +44 -0
- package/esm/pathways/logger.d.ts +48 -0
- package/esm/pathways/logger.d.ts.map +1 -0
- package/esm/pathways/logger.js +26 -0
- package/esm/pathways/postgres/index.d.ts +9 -0
- package/esm/pathways/postgres/index.d.ts.map +1 -0
- package/esm/pathways/postgres/index.js +8 -0
- package/esm/pathways/postgres/postgres-adapter.d.ts +112 -0
- package/esm/pathways/postgres/postgres-adapter.d.ts.map +1 -0
- package/esm/pathways/postgres/postgres-adapter.js +113 -0
- package/esm/pathways/postgres/postgres-pathway-state.d.ts +113 -0
- package/esm/pathways/postgres/postgres-pathway-state.d.ts.map +1 -0
- package/esm/pathways/postgres/postgres-pathway-state.js +188 -0
- package/esm/pathways/types.d.ts +87 -0
- package/esm/pathways/types.d.ts.map +1 -0
- package/esm/pathways/types.js +1 -0
- package/esm/router/index.d.ts +35 -0
- package/esm/router/index.d.ts.map +1 -0
- package/esm/router/index.js +96 -0
- package/package.json +38 -0
- package/script/common/flowcore.type.d.ts +11 -0
- package/script/common/flowcore.type.d.ts.map +1 -0
- package/script/common/flowcore.type.js +2 -0
- package/script/common/index.d.ts +7 -0
- package/script/common/index.d.ts.map +1 -0
- package/script/common/index.js +22 -0
- package/script/compatibility/flowcore-transformer-core.sdk.d.ts +16 -0
- package/script/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -0
- package/script/compatibility/flowcore-transformer-core.sdk.js +17 -0
- package/script/contracts/event.d.ts +20 -0
- package/script/contracts/event.d.ts.map +1 -0
- package/script/contracts/event.js +18 -0
- package/script/contracts/index.d.ts +5 -0
- package/script/contracts/index.d.ts.map +1 -0
- package/script/contracts/index.js +20 -0
- package/script/mod.d.ts +14 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +29 -0
- package/script/package.json +3 -0
- package/script/pathways/builder.d.ts +91 -0
- package/script/pathways/builder.d.ts.map +1 -0
- package/script/pathways/builder.js +534 -0
- package/script/pathways/index.d.ts +17 -0
- package/script/pathways/index.d.ts.map +1 -0
- package/script/pathways/index.js +32 -0
- package/script/pathways/internal-pathway.state.d.ts +41 -0
- package/script/pathways/internal-pathway.state.d.ts.map +1 -0
- package/script/pathways/internal-pathway.state.js +68 -0
- package/script/pathways/kv/bun-kv-adapter.d.ts +36 -0
- package/script/pathways/kv/bun-kv-adapter.d.ts.map +1 -0
- package/script/pathways/kv/bun-kv-adapter.js +51 -0
- package/script/pathways/kv/kv-adapter.d.ts +34 -0
- package/script/pathways/kv/kv-adapter.d.ts.map +1 -0
- package/script/pathways/kv/kv-adapter.js +45 -0
- package/script/pathways/kv/node-kv-adapter.d.ts +33 -0
- package/script/pathways/kv/node-kv-adapter.d.ts.map +1 -0
- package/script/pathways/kv/node-kv-adapter.js +51 -0
- package/script/pathways/logger.d.ts +48 -0
- package/script/pathways/logger.d.ts.map +1 -0
- package/script/pathways/logger.js +31 -0
- package/script/pathways/postgres/index.d.ts +9 -0
- package/script/pathways/postgres/index.d.ts.map +1 -0
- package/script/pathways/postgres/index.js +24 -0
- package/script/pathways/postgres/postgres-adapter.d.ts +112 -0
- package/script/pathways/postgres/postgres-adapter.d.ts.map +1 -0
- package/script/pathways/postgres/postgres-adapter.js +141 -0
- package/script/pathways/postgres/postgres-pathway-state.d.ts +113 -0
- package/script/pathways/postgres/postgres-pathway-state.d.ts.map +1 -0
- package/script/pathways/postgres/postgres-pathway-state.js +193 -0
- package/script/pathways/types.d.ts +87 -0
- package/script/pathways/types.d.ts.map +1 -0
- package/script/pathways/types.js +2 -0
- package/script/router/index.d.ts +35 -0
- package/script/router/index.d.ts.map +1 -0
- package/script/router/index.js +100 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalPathwayState = void 0;
|
|
4
|
+
const kv_adapter_js_1 = require("./kv/kv-adapter.js");
|
|
5
|
+
/**
|
|
6
|
+
* Internal implementation of PathwayState interface that uses KV storage
|
|
7
|
+
* for tracking processed events to prevent duplicate processing
|
|
8
|
+
*
|
|
9
|
+
* @implements {PathwayState}
|
|
10
|
+
*/
|
|
11
|
+
class InternalPathwayState {
|
|
12
|
+
constructor() {
|
|
13
|
+
/**
|
|
14
|
+
* The KV adapter instance for storage
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(this, "kv", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: null
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets or initializes the KV adapter
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
* @returns {Promise<KvAdapter>} The KV adapter instance
|
|
29
|
+
*/
|
|
30
|
+
async getKv() {
|
|
31
|
+
if (!this.kv) {
|
|
32
|
+
this.kv = await (0, kv_adapter_js_1.createKvAdapter)();
|
|
33
|
+
}
|
|
34
|
+
return this.kv;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Checks if an event has already been processed
|
|
38
|
+
*
|
|
39
|
+
* @param {string} eventId - The ID of the event to check
|
|
40
|
+
* @returns {Promise<boolean>} True if the event has been processed, false otherwise
|
|
41
|
+
*/
|
|
42
|
+
async isProcessed(eventId) {
|
|
43
|
+
const kv = await this.getKv();
|
|
44
|
+
const result = await kv.get(eventId);
|
|
45
|
+
return result === true;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Marks an event as processed
|
|
49
|
+
*
|
|
50
|
+
* @param {string} eventId - The ID of the event to mark as processed
|
|
51
|
+
* @returns {Promise<void>}
|
|
52
|
+
*/
|
|
53
|
+
async setProcessed(eventId) {
|
|
54
|
+
const kv = await this.getKv();
|
|
55
|
+
await kv.set(eventId, true, InternalPathwayState.DEFAULT_TTL_MS);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.InternalPathwayState = InternalPathwayState;
|
|
59
|
+
/**
|
|
60
|
+
* Default time-to-live for processed event records (5 minutes)
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
Object.defineProperty(InternalPathwayState, "DEFAULT_TTL_MS", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: 5 * 60 * 1000
|
|
68
|
+
}); // 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,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BunKvAdapter = void 0;
|
|
4
|
+
const bun_sqlite_key_value_1 = require("bun-sqlite-key-value");
|
|
5
|
+
/**
|
|
6
|
+
* KV adapter implementation for Bun runtime
|
|
7
|
+
*
|
|
8
|
+
* Uses Bun's SQLite-based key-value store for storage
|
|
9
|
+
*
|
|
10
|
+
* @implements {KvAdapter}
|
|
11
|
+
*/
|
|
12
|
+
class BunKvAdapter {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new in-memory Bun KV adapter
|
|
15
|
+
*/
|
|
16
|
+
constructor() {
|
|
17
|
+
/**
|
|
18
|
+
* The underlying Bun SQLite key-value store
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(this, "store", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
this.store = new bun_sqlite_key_value_1.BunSqliteKeyValue(":memory:");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves a value from the Bun KV store
|
|
31
|
+
*
|
|
32
|
+
* @template T The expected type of the stored value
|
|
33
|
+
* @param {string} key The key to retrieve
|
|
34
|
+
* @returns {T | null} The stored value or null if not found
|
|
35
|
+
*/
|
|
36
|
+
get(key) {
|
|
37
|
+
const value = this.store.get(key);
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Stores a value in the Bun KV store with the specified TTL
|
|
42
|
+
*
|
|
43
|
+
* @param {string} key The key to store the value under
|
|
44
|
+
* @param {unknown} value The value to store
|
|
45
|
+
* @param {number} ttlMs Time-to-live in milliseconds
|
|
46
|
+
*/
|
|
47
|
+
set(key, value, ttlMs) {
|
|
48
|
+
this.store.set(key, value, ttlMs);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.BunKvAdapter = BunKvAdapter;
|
|
@@ -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,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createKvAdapter = createKvAdapter;
|
|
27
|
+
/**
|
|
28
|
+
* Creates an appropriate KV adapter based on the runtime environment
|
|
29
|
+
*
|
|
30
|
+
* Attempts to use Bun KV adapter if running in Bun, falls back to Node adapter otherwise
|
|
31
|
+
*
|
|
32
|
+
* @returns {Promise<KvAdapter>} A KV adapter instance
|
|
33
|
+
*/
|
|
34
|
+
async function createKvAdapter() {
|
|
35
|
+
try {
|
|
36
|
+
// Try to import Bun adapter
|
|
37
|
+
const { BunKvAdapter } = await Promise.resolve().then(() => __importStar(require("./bun-kv-adapter.js")));
|
|
38
|
+
return new BunKvAdapter();
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Default to node-cache if Bun is not available
|
|
42
|
+
const { NodeKvAdapter } = await Promise.resolve().then(() => __importStar(require("./node-kv-adapter.js")));
|
|
43
|
+
return new NodeKvAdapter();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -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,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NodeKvAdapter = void 0;
|
|
7
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
8
|
+
/**
|
|
9
|
+
* KV adapter implementation for Node.js runtime
|
|
10
|
+
*
|
|
11
|
+
* Uses node-cache for in-memory key-value storage
|
|
12
|
+
*
|
|
13
|
+
* @implements {KvAdapter}
|
|
14
|
+
*/
|
|
15
|
+
class NodeKvAdapter {
|
|
16
|
+
constructor() {
|
|
17
|
+
/**
|
|
18
|
+
* The underlying Node.js cache instance
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(this, "kv", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: new node_cache_1.default()
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves a value from the Node.js cache
|
|
30
|
+
*
|
|
31
|
+
* @template T The expected type of the stored value
|
|
32
|
+
* @param {string} key The key to retrieve
|
|
33
|
+
* @returns {Promise<T | null>} The stored value or null if not found
|
|
34
|
+
*/
|
|
35
|
+
async get(key) {
|
|
36
|
+
const result = await this.kv.get(key);
|
|
37
|
+
return result ?? null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Stores a value in the Node.js cache with the specified TTL
|
|
41
|
+
*
|
|
42
|
+
* @param {string} key The key to store the value under
|
|
43
|
+
* @param {unknown} value The value to store
|
|
44
|
+
* @param {number} ttlMs Time-to-live in milliseconds
|
|
45
|
+
* @returns {Promise<void>}
|
|
46
|
+
*/
|
|
47
|
+
async set(key, value, ttlMs) {
|
|
48
|
+
await this.kv.set(key, value, (ttlMs / 1000));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.NodeKvAdapter = NodeKvAdapter;
|
|
@@ -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,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoopLogger = exports.ConsoleLogger = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A default console logger that logs to the console
|
|
6
|
+
*/
|
|
7
|
+
class ConsoleLogger {
|
|
8
|
+
debug(message, context) {
|
|
9
|
+
console.debug(message, context ? JSON.stringify(context) : '');
|
|
10
|
+
}
|
|
11
|
+
info(message, context) {
|
|
12
|
+
console.info(message, context ? JSON.stringify(context) : '');
|
|
13
|
+
}
|
|
14
|
+
warn(message, context) {
|
|
15
|
+
console.warn(message, context ? JSON.stringify(context) : '');
|
|
16
|
+
}
|
|
17
|
+
error(message, context) {
|
|
18
|
+
console.error(message, context ? JSON.stringify(context) : '');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
22
|
+
/**
|
|
23
|
+
* A no-operation logger that does nothing
|
|
24
|
+
*/
|
|
25
|
+
class NoopLogger {
|
|
26
|
+
debug(_message, _context) { }
|
|
27
|
+
info(_message, _context) { }
|
|
28
|
+
warn(_message, _context) { }
|
|
29
|
+
error(_message, _context) { }
|
|
30
|
+
}
|
|
31
|
+
exports.NoopLogger = NoopLogger;
|
|
@@ -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,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* PostgreSQL integration for Flowcore Pathways
|
|
19
|
+
*
|
|
20
|
+
* This module exports components for using PostgreSQL as a storage backend
|
|
21
|
+
* for pathway state and other persistent data.
|
|
22
|
+
*/
|
|
23
|
+
__exportStar(require("./postgres-adapter.js"), exports);
|
|
24
|
+
__exportStar(require("./postgres-pathway-state.js"), exports);
|
|
@@ -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"}
|