@flowcore/pathways 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -58
- package/README.md +128 -124
- package/esm/common/index.d.ts.map +1 -1
- package/esm/contracts/index.d.ts.map +1 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/pathways/builder.d.ts +56 -4
- package/esm/pathways/builder.d.ts.map +1 -1
- package/esm/pathways/builder.js +59 -4
- package/esm/pathways/index.d.ts.map +1 -1
- package/esm/pathways/internal-pathway.state.d.ts.map +1 -1
- package/esm/pathways/kv/bun-kv-adapter.d.ts.map +1 -1
- package/esm/pathways/kv/kv-adapter.d.ts +2 -2
- package/esm/pathways/kv/kv-adapter.d.ts.map +1 -1
- package/esm/pathways/kv/node-kv-adapter.d.ts.map +1 -1
- package/esm/pathways/kv/node-kv-adapter.js +1 -1
- package/esm/pathways/logger.js +7 -7
- package/esm/pathways/postgres/index.d.ts.map +1 -1
- package/esm/pathways/postgres/postgres-adapter.d.ts.map +1 -1
- package/esm/pathways/postgres/postgres-adapter.js +3 -2
- package/esm/pathways/session-pathway.d.ts.map +1 -1
- package/esm/pathways/session-pathway.js +3 -3
- package/esm/router/index.d.ts.map +1 -1
- package/esm/router/index.js +4 -4
- package/package.json +1 -1
- package/script/common/index.d.ts.map +1 -1
- package/script/contracts/index.d.ts.map +1 -1
- package/script/mod.d.ts.map +1 -1
- package/script/pathways/builder.d.ts +56 -4
- package/script/pathways/builder.d.ts.map +1 -1
- package/script/pathways/builder.js +61 -5
- package/script/pathways/index.d.ts.map +1 -1
- package/script/pathways/internal-pathway.state.d.ts.map +1 -1
- package/script/pathways/kv/bun-kv-adapter.d.ts.map +1 -1
- package/script/pathways/kv/kv-adapter.d.ts +2 -2
- package/script/pathways/kv/kv-adapter.d.ts.map +1 -1
- package/script/pathways/kv/node-kv-adapter.d.ts.map +1 -1
- package/script/pathways/kv/node-kv-adapter.js +1 -1
- package/script/pathways/logger.js +7 -7
- package/script/pathways/postgres/index.d.ts.map +1 -1
- package/script/pathways/postgres/postgres-adapter.d.ts.map +1 -1
- package/script/pathways/postgres/postgres-adapter.js +3 -2
- package/script/pathways/session-pathway.d.ts.map +1 -1
- package/script/pathways/session-pathway.js +3 -3
- package/script/router/index.d.ts.map +1 -1
- package/script/router/index.js +4 -4
package/esm/pathways/builder.js
CHANGED
|
@@ -20,6 +20,60 @@ const DEFAULT_RETRY_DELAY_MS = 500;
|
|
|
20
20
|
* Default TTL for session-specific user resolvers in milliseconds (10seconds)
|
|
21
21
|
*/
|
|
22
22
|
const DEFAULT_SESSION_USER_RESOLVER_TTL_MS = 10 * 1000;
|
|
23
|
+
/**
|
|
24
|
+
* SessionUserResolver implementation that uses a Map to store UserIdResolver functions
|
|
25
|
+
* with a TTL (time to live).
|
|
26
|
+
*/
|
|
27
|
+
export class SessionUser {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new SessionUser instance
|
|
30
|
+
*/
|
|
31
|
+
constructor() {
|
|
32
|
+
/**
|
|
33
|
+
* The underlying Map that stores UserIdResolver functions and their timeouts
|
|
34
|
+
* Using unknown for timeout to support both Node.js and Deno timer types
|
|
35
|
+
*/
|
|
36
|
+
Object.defineProperty(this, "store", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
42
|
+
this.store = new Map();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves a UserIdResolver from the session user resolver store
|
|
46
|
+
* @param key The key to retrieve the UserIdResolver for
|
|
47
|
+
* @returns The UserIdResolver or undefined if it doesn't exist
|
|
48
|
+
*/
|
|
49
|
+
get(key) {
|
|
50
|
+
const entry = this.store.get(key);
|
|
51
|
+
if (!entry) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return entry.value;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Stores a UserIdResolver in the session user resolver store
|
|
58
|
+
* @param key The key to store the UserIdResolver under
|
|
59
|
+
* @param value The UserIdResolver to store
|
|
60
|
+
* @param ttlMs The time to live for the UserIdResolver in milliseconds
|
|
61
|
+
* @default 5 minutes
|
|
62
|
+
*/
|
|
63
|
+
set(key, value, ttlMs = 1000 * 60 * 5) {
|
|
64
|
+
// Clear any existing timeout for this key
|
|
65
|
+
const existingEntry = this.store.get(key);
|
|
66
|
+
if (existingEntry) {
|
|
67
|
+
clearTimeout(existingEntry.timeout);
|
|
68
|
+
}
|
|
69
|
+
// Set up new timeout
|
|
70
|
+
const timeout = setTimeout(() => {
|
|
71
|
+
this.store.delete(key);
|
|
72
|
+
}, ttlMs);
|
|
73
|
+
// Store the new value and its timeout
|
|
74
|
+
this.store.set(key, { value, timeout });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
23
77
|
/**
|
|
24
78
|
* Main builder class for creating and managing Flowcore pathways
|
|
25
79
|
*
|
|
@@ -44,9 +98,10 @@ export class PathwaysBuilder {
|
|
|
44
98
|
* @param options.apiKey The API key for authentication
|
|
45
99
|
* @param options.pathwayTimeoutMs Optional timeout for pathway processing in milliseconds
|
|
46
100
|
* @param options.logger Optional logger instance
|
|
47
|
-
* @param options.
|
|
101
|
+
* @param options.enableSessionUserResolvers Whether to enable session user resolvers
|
|
102
|
+
* @param options.overrideSessionUserResolvers Optional SessionUserResolver instance to override the default
|
|
48
103
|
*/
|
|
49
|
-
constructor({ baseUrl, tenant, dataCore, apiKey, pathwayTimeoutMs, logger,
|
|
104
|
+
constructor({ baseUrl, tenant, dataCore, apiKey, pathwayTimeoutMs, logger, enableSessionUserResolvers, overrideSessionUserResolvers, }) {
|
|
50
105
|
Object.defineProperty(this, "pathways", {
|
|
51
106
|
enumerable: true,
|
|
52
107
|
configurable: true,
|
|
@@ -208,8 +263,8 @@ export class PathwaysBuilder {
|
|
|
208
263
|
this.tenant = tenant;
|
|
209
264
|
this.dataCore = dataCore;
|
|
210
265
|
this.apiKey = apiKey;
|
|
211
|
-
if (
|
|
212
|
-
this.sessionUserResolvers =
|
|
266
|
+
if (enableSessionUserResolvers) {
|
|
267
|
+
this.sessionUserResolvers = overrideSessionUserResolvers ?? new SessionUser();
|
|
213
268
|
}
|
|
214
269
|
this.logger.debug("Initializing PathwaysBuilder", {
|
|
215
270
|
baseUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pathways/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,cAAc,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pathways/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,cAAc,cAAc,CAAA;AAC5B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,YAAY,CAAA"}
|
|
@@ -1 +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,
|
|
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,CAAA;AAE9C;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAEtD;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAyB;IAEnC;;;;;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"}
|
|
@@ -1 +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,
|
|
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,CAAA;AAEhD;;;;GAIG;AACH,qBAAa,YAAa,YAAW,SAAS;IAC5C;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAmB;IAEhC;;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"}
|
|
@@ -39,7 +39,7 @@ export interface KvAdapter {
|
|
|
39
39
|
* @param key The key to retrieve
|
|
40
40
|
* @returns The stored value or null if not found
|
|
41
41
|
*/
|
|
42
|
-
get<T>(key: string):
|
|
42
|
+
get<T>(key: string): Promise<T | null> | T | null;
|
|
43
43
|
/**
|
|
44
44
|
* Stores a value in storage with the specified key and TTL
|
|
45
45
|
*
|
|
@@ -48,7 +48,7 @@ export interface KvAdapter {
|
|
|
48
48
|
* @param ttlMs Time-to-live in milliseconds
|
|
49
49
|
* @returns Promise or void when the operation completes
|
|
50
50
|
*/
|
|
51
|
-
set(key: string, value: unknown, ttlMs: number):
|
|
51
|
+
set(key: string, value: unknown, ttlMs: number): Promise<void> | void;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Creates an appropriate KV adapter based on the runtime environment
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/kv/kv-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"kv-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/kv/kv-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;IAEjD;;;;;;;OAOG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACtE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC,CAU1D"}
|
|
@@ -1 +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,
|
|
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,CAAA;AAEhD;;;;GAIG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC7C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAkB;IAErC;;;;;;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"}
|
package/esm/pathways/logger.js
CHANGED
|
@@ -11,7 +11,7 @@ export class ConsoleLogger {
|
|
|
11
11
|
* @param context Optional context data to include
|
|
12
12
|
*/
|
|
13
13
|
debug(message, context) {
|
|
14
|
-
console.debug(message, context ? JSON.stringify(context) :
|
|
14
|
+
console.debug(message, context ? JSON.stringify(context) : "");
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Log informational messages to the console
|
|
@@ -19,7 +19,7 @@ export class ConsoleLogger {
|
|
|
19
19
|
* @param context Optional context data to include
|
|
20
20
|
*/
|
|
21
21
|
info(message, context) {
|
|
22
|
-
console.info(message, context ? JSON.stringify(context) :
|
|
22
|
+
console.info(message, context ? JSON.stringify(context) : "");
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Log warning messages to the console
|
|
@@ -27,7 +27,7 @@ export class ConsoleLogger {
|
|
|
27
27
|
* @param context Optional context data to include
|
|
28
28
|
*/
|
|
29
29
|
warn(message, context) {
|
|
30
|
-
console.warn(message, context ? JSON.stringify(context) :
|
|
30
|
+
console.warn(message, context ? JSON.stringify(context) : "");
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Log error messages to the console
|
|
@@ -40,19 +40,19 @@ export class ConsoleLogger {
|
|
|
40
40
|
* @param context Optional context data (only for signature 1)
|
|
41
41
|
*/
|
|
42
42
|
error(messageOrError, errorOrContext, context) {
|
|
43
|
-
if (typeof messageOrError ===
|
|
43
|
+
if (typeof messageOrError === "string") {
|
|
44
44
|
if (errorOrContext instanceof Error) {
|
|
45
45
|
// Signature 1: error(message: string, error: Error, context?: LoggerMeta)
|
|
46
|
-
console.error(messageOrError, errorOrContext, context ? JSON.stringify(context) :
|
|
46
|
+
console.error(messageOrError, errorOrContext, context ? JSON.stringify(context) : "");
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
49
|
// Signature 1 (no error) or Signature 2: error(message: string, context?: LoggerMeta)
|
|
50
|
-
console.error(messageOrError, errorOrContext ? JSON.stringify(errorOrContext) :
|
|
50
|
+
console.error(messageOrError, errorOrContext ? JSON.stringify(errorOrContext) : "");
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
54
|
// Signature 2: error(error: Error, context?: LoggerMeta)
|
|
55
|
-
console.error(messageOrError, errorOrContext ? JSON.stringify(errorOrContext) :
|
|
55
|
+
console.error(messageOrError, errorOrContext ? JSON.stringify(errorOrContext) : "");
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,cAAc,uBAAuB,CAAA;AACrC,cAAc,6BAA6B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,gHAAgH;IAChH,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"postgres-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-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AAoBD;;GAEG;AACH,qBAAa,iBAAkB,YAAW,eAAe;IACvD,8CAA8C;IAC9C,OAAO,CAAC,QAAQ,CAA8D;IAC9E,oCAAoC;IACpC,OAAO,CAAC,GAAG,CAA8B;IACzC,mCAAmC;IACnC,OAAO,CAAC,MAAM,CAAgB;IAC9B,yDAAyD;IACzD,OAAO,CAAC,gBAAgB,CAAQ;IAEhC;;;;OAIG;gBACS,MAAM,EAAE,cAAc;IAgBlC;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAW9B;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;;;;;OAMG;IACG,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAO/D;;;;;OAKG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAMlE;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAI5F"}
|
|
@@ -37,13 +37,14 @@ export class PostgresJsAdapter {
|
|
|
37
37
|
value: void 0
|
|
38
38
|
});
|
|
39
39
|
this.config = config;
|
|
40
|
-
if (
|
|
40
|
+
if ("connectionString" in config && config.connectionString) {
|
|
41
41
|
// Use the provided connection string directly
|
|
42
42
|
this.connectionString = config.connectionString;
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
45
|
// Build connection string from individual parameters
|
|
46
|
-
this.connectionString =
|
|
46
|
+
this.connectionString =
|
|
47
|
+
`postgres://${config.user}:${config.password}@${config.host}:${config.port}/${config.database}`;
|
|
47
48
|
if (config.ssl) {
|
|
48
49
|
this.connectionString += "?sslmode=require";
|
|
49
50
|
}
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"session-pathway.d.ts","sourceRoot":"","sources":["../../src/pathways/session-pathway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAqBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,qBAAqB,CAEhC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,EAC7C,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;;;;;;;;OAQG;IACG,KAAK,CAAC,KAAK,SAAS,cAAc,EACtC,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EACrB,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;CAU9B"}
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
function generateUUID() {
|
|
6
6
|
// Check for Deno or browser crypto.randomUUID support
|
|
7
|
-
if (typeof crypto !==
|
|
7
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
8
8
|
return crypto.randomUUID();
|
|
9
9
|
}
|
|
10
10
|
// Fallback to manual UUID generation (compatible with all platforms)
|
|
11
11
|
// Implementation based on RFC4122 version 4
|
|
12
|
-
return
|
|
12
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
13
13
|
const r = Math.random() * 16 | 0;
|
|
14
|
-
const v = c ===
|
|
14
|
+
const v = c === "x" ? r : (r & 0x3 | 0x8);
|
|
15
15
|
return v.toString(16);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/router/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,qBAAa,aAAa;IAatB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAb5B,OAAO,CAAC,QAAQ,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/router/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,qBAAa,aAAa;IAatB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAb5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAE/B;;;;;;;OAOG;gBAGgB,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC9C,SAAS,EAAE,MAAM,EAClC,MAAM,CAAC,EAAE,MAAM;IAajB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACG,YAAY,CAChB,KAAK,EAAE,mBAAmB,EAC1B,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAkDlD"}
|
package/esm/router/index.js
CHANGED
|
@@ -142,7 +142,7 @@ export class PathwayRouter {
|
|
|
142
142
|
};
|
|
143
143
|
const pathwayKey = `${compatibleEvent.flowType}/${compatibleEvent.eventType}`;
|
|
144
144
|
this.logger.debug(`Processing event for pathway: ${pathwayKey}`, {
|
|
145
|
-
eventId: compatibleEvent.eventId
|
|
145
|
+
eventId: compatibleEvent.eventId,
|
|
146
146
|
});
|
|
147
147
|
const pathway = this.pathways.get(pathwayKey);
|
|
148
148
|
if (!pathway) {
|
|
@@ -153,19 +153,19 @@ export class PathwayRouter {
|
|
|
153
153
|
try {
|
|
154
154
|
this.logger.debug(`Delegating event processing to pathway handler`, {
|
|
155
155
|
pathwayKey,
|
|
156
|
-
eventId: compatibleEvent.eventId
|
|
156
|
+
eventId: compatibleEvent.eventId,
|
|
157
157
|
});
|
|
158
158
|
await this.pathways.process(pathwayKey, compatibleEvent);
|
|
159
159
|
this.logger.debug(`Event successfully processed through pathway`, {
|
|
160
160
|
pathwayKey,
|
|
161
|
-
eventId: compatibleEvent.eventId
|
|
161
|
+
eventId: compatibleEvent.eventId,
|
|
162
162
|
});
|
|
163
163
|
return { success: true, message: `Event processed through pathway ${pathwayKey}` };
|
|
164
164
|
}
|
|
165
165
|
catch (error) {
|
|
166
166
|
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
167
167
|
this.logger.error(`Error processing pathway ${pathwayKey}`, errorObj, {
|
|
168
|
-
eventId: compatibleEvent.eventId
|
|
168
|
+
eventId: compatibleEvent.eventId,
|
|
169
169
|
});
|
|
170
170
|
// Rethrow the error with additional context
|
|
171
171
|
throw new Error(`Failed to process event in pathway ${pathwayKey}: ${errorObj.message}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowcore/pathways",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "A TypeScript Library for creating Flowcore Pathways, simplifying the integration with the flowcore platform",
|
|
5
5
|
"homepage": "https://github.com/flowcore-io/flowcore-pathways#readme",
|
|
6
6
|
"repository": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,oBAAoB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,oBAAoB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,YAAY,CAAA"}
|
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAc,mBAAmB,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Static, type TSchema } from "@sinclair/typebox";
|
|
2
2
|
import type { WebhookSendOptions } from "@flowcore/sdk-transformer-core";
|
|
3
3
|
import type { FlowcoreEvent } from "../contracts/event.js";
|
|
4
|
-
import type { KvAdapter } from "./kv/kv-adapter.js";
|
|
5
4
|
import type { Logger } from "./logger.js";
|
|
6
5
|
import type { EventMetadata, PathwayContract, PathwayKey, PathwayState, PathwayWriteOptions, WritablePathway } from "./types.js";
|
|
7
6
|
/**
|
|
@@ -30,6 +29,57 @@ export interface AuditWebhookSendOptions extends WebhookSendOptions {
|
|
|
30
29
|
*/
|
|
31
30
|
headers?: Record<string, string>;
|
|
32
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* SessionUserResolver is a key-value store for storing and retrieving UserIdResolver functions
|
|
34
|
+
* with a TTL (time to live).
|
|
35
|
+
*
|
|
36
|
+
* This allows for session-specific user resolvers to be stored and reused across different
|
|
37
|
+
* sessions or operations.
|
|
38
|
+
*/
|
|
39
|
+
export interface SessionUserResolver {
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves a UserIdResolver from the session user resolver store
|
|
42
|
+
* @param key The key to retrieve the UserIdResolver for
|
|
43
|
+
* @returns The UserIdResolver or undefined if it doesn't exist
|
|
44
|
+
*/
|
|
45
|
+
get(key: string): Promise<UserIdResolver | undefined> | UserIdResolver | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Stores a UserIdResolver in the session user resolver store
|
|
48
|
+
* @param key The key to store the UserIdResolver under
|
|
49
|
+
* @param value The UserIdResolver to store
|
|
50
|
+
* @param ttlMs The time to live for the UserIdResolver in milliseconds
|
|
51
|
+
*/
|
|
52
|
+
set(key: string, value: UserIdResolver, ttlMs: number): Promise<void> | void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* SessionUserResolver implementation that uses a Map to store UserIdResolver functions
|
|
56
|
+
* with a TTL (time to live).
|
|
57
|
+
*/
|
|
58
|
+
export declare class SessionUser implements SessionUserResolver {
|
|
59
|
+
/**
|
|
60
|
+
* The underlying Map that stores UserIdResolver functions and their timeouts
|
|
61
|
+
* Using unknown for timeout to support both Node.js and Deno timer types
|
|
62
|
+
*/
|
|
63
|
+
private store;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new SessionUser instance
|
|
66
|
+
*/
|
|
67
|
+
constructor();
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves a UserIdResolver from the session user resolver store
|
|
70
|
+
* @param key The key to retrieve the UserIdResolver for
|
|
71
|
+
* @returns The UserIdResolver or undefined if it doesn't exist
|
|
72
|
+
*/
|
|
73
|
+
get(key: string): UserIdResolver | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Stores a UserIdResolver in the session user resolver store
|
|
76
|
+
* @param key The key to store the UserIdResolver under
|
|
77
|
+
* @param value The UserIdResolver to store
|
|
78
|
+
* @param ttlMs The time to live for the UserIdResolver in milliseconds
|
|
79
|
+
* @default 5 minutes
|
|
80
|
+
*/
|
|
81
|
+
set(key: string, value: UserIdResolver, ttlMs?: number): void;
|
|
82
|
+
}
|
|
33
83
|
/**
|
|
34
84
|
* Main builder class for creating and managing Flowcore pathways
|
|
35
85
|
*
|
|
@@ -79,16 +129,18 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
79
129
|
* @param options.apiKey The API key for authentication
|
|
80
130
|
* @param options.pathwayTimeoutMs Optional timeout for pathway processing in milliseconds
|
|
81
131
|
* @param options.logger Optional logger instance
|
|
82
|
-
* @param options.
|
|
132
|
+
* @param options.enableSessionUserResolvers Whether to enable session user resolvers
|
|
133
|
+
* @param options.overrideSessionUserResolvers Optional SessionUserResolver instance to override the default
|
|
83
134
|
*/
|
|
84
|
-
constructor({ baseUrl, tenant, dataCore, apiKey, pathwayTimeoutMs, logger,
|
|
135
|
+
constructor({ baseUrl, tenant, dataCore, apiKey, pathwayTimeoutMs, logger, enableSessionUserResolvers, overrideSessionUserResolvers, }: {
|
|
85
136
|
baseUrl: string;
|
|
86
137
|
tenant: string;
|
|
87
138
|
dataCore: string;
|
|
88
139
|
apiKey: string;
|
|
89
140
|
pathwayTimeoutMs?: number;
|
|
90
141
|
logger?: Logger;
|
|
91
|
-
|
|
142
|
+
enableSessionUserResolvers?: boolean;
|
|
143
|
+
overrideSessionUserResolvers?: SessionUserResolver;
|
|
92
144
|
});
|
|
93
145
|
/**
|
|
94
146
|
* Configures the PathwaysBuilder to use a custom pathway state implementation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAQ,MAAM,mBAAmB,CAAA;AAEnE,OAAO,KAAK,EAGV,kBAAkB,EACnB,MAAM,gCAAgC,CAAA;AAGvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAQ,MAAM,mBAAmB,CAAA;AAEnE,OAAO,KAAK,EAGV,kBAAkB,EACnB,MAAM,gCAAgC,CAAA;AAGvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EACV,aAAa,EACb,eAAe,E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QAAQ,EAAE,cAAc,CAAC;IAqB5C;;;OAGG;IACH,UAAU,CACR,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GACrE,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC;IAQ5C;;;;;;;OAOG;IACG,KAAK,CAAC,KAAK,SAAS,cAAc,EACtC,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EACrB,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;IA4HvB,UAAU,CAAC,KAAK,SAAS,cAAc,EAC3C,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,EACvB,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;IAsH7B;;;;;;;;;;OAUG;YACW,2BAA2B;CA4C1C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PathwaysBuilder = void 0;
|
|
3
|
+
exports.PathwaysBuilder = exports.SessionUser = void 0;
|
|
4
4
|
const typebox_1 = require("@sinclair/typebox");
|
|
5
5
|
const value_1 = require("@sinclair/typebox/value");
|
|
6
6
|
const rxjs_1 = require("rxjs");
|
|
@@ -23,6 +23,61 @@ const DEFAULT_RETRY_DELAY_MS = 500;
|
|
|
23
23
|
* Default TTL for session-specific user resolvers in milliseconds (10seconds)
|
|
24
24
|
*/
|
|
25
25
|
const DEFAULT_SESSION_USER_RESOLVER_TTL_MS = 10 * 1000;
|
|
26
|
+
/**
|
|
27
|
+
* SessionUserResolver implementation that uses a Map to store UserIdResolver functions
|
|
28
|
+
* with a TTL (time to live).
|
|
29
|
+
*/
|
|
30
|
+
class SessionUser {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new SessionUser instance
|
|
33
|
+
*/
|
|
34
|
+
constructor() {
|
|
35
|
+
/**
|
|
36
|
+
* The underlying Map that stores UserIdResolver functions and their timeouts
|
|
37
|
+
* Using unknown for timeout to support both Node.js and Deno timer types
|
|
38
|
+
*/
|
|
39
|
+
Object.defineProperty(this, "store", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
45
|
+
this.store = new Map();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves a UserIdResolver from the session user resolver store
|
|
49
|
+
* @param key The key to retrieve the UserIdResolver for
|
|
50
|
+
* @returns The UserIdResolver or undefined if it doesn't exist
|
|
51
|
+
*/
|
|
52
|
+
get(key) {
|
|
53
|
+
const entry = this.store.get(key);
|
|
54
|
+
if (!entry) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return entry.value;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Stores a UserIdResolver in the session user resolver store
|
|
61
|
+
* @param key The key to store the UserIdResolver under
|
|
62
|
+
* @param value The UserIdResolver to store
|
|
63
|
+
* @param ttlMs The time to live for the UserIdResolver in milliseconds
|
|
64
|
+
* @default 5 minutes
|
|
65
|
+
*/
|
|
66
|
+
set(key, value, ttlMs = 1000 * 60 * 5) {
|
|
67
|
+
// Clear any existing timeout for this key
|
|
68
|
+
const existingEntry = this.store.get(key);
|
|
69
|
+
if (existingEntry) {
|
|
70
|
+
clearTimeout(existingEntry.timeout);
|
|
71
|
+
}
|
|
72
|
+
// Set up new timeout
|
|
73
|
+
const timeout = setTimeout(() => {
|
|
74
|
+
this.store.delete(key);
|
|
75
|
+
}, ttlMs);
|
|
76
|
+
// Store the new value and its timeout
|
|
77
|
+
this.store.set(key, { value, timeout });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.SessionUser = SessionUser;
|
|
26
81
|
/**
|
|
27
82
|
* Main builder class for creating and managing Flowcore pathways
|
|
28
83
|
*
|
|
@@ -47,9 +102,10 @@ class PathwaysBuilder {
|
|
|
47
102
|
* @param options.apiKey The API key for authentication
|
|
48
103
|
* @param options.pathwayTimeoutMs Optional timeout for pathway processing in milliseconds
|
|
49
104
|
* @param options.logger Optional logger instance
|
|
50
|
-
* @param options.
|
|
105
|
+
* @param options.enableSessionUserResolvers Whether to enable session user resolvers
|
|
106
|
+
* @param options.overrideSessionUserResolvers Optional SessionUserResolver instance to override the default
|
|
51
107
|
*/
|
|
52
|
-
constructor({ baseUrl, tenant, dataCore, apiKey, pathwayTimeoutMs, logger,
|
|
108
|
+
constructor({ baseUrl, tenant, dataCore, apiKey, pathwayTimeoutMs, logger, enableSessionUserResolvers, overrideSessionUserResolvers, }) {
|
|
53
109
|
Object.defineProperty(this, "pathways", {
|
|
54
110
|
enumerable: true,
|
|
55
111
|
configurable: true,
|
|
@@ -211,8 +267,8 @@ class PathwaysBuilder {
|
|
|
211
267
|
this.tenant = tenant;
|
|
212
268
|
this.dataCore = dataCore;
|
|
213
269
|
this.apiKey = apiKey;
|
|
214
|
-
if (
|
|
215
|
-
this.sessionUserResolvers =
|
|
270
|
+
if (enableSessionUserResolvers) {
|
|
271
|
+
this.sessionUserResolvers = overrideSessionUserResolvers ?? new SessionUser();
|
|
216
272
|
}
|
|
217
273
|
this.logger.debug("Initializing PathwaysBuilder", {
|
|
218
274
|
baseUrl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pathways/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,cAAc,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pathways/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,cAAc,cAAc,CAAA;AAC5B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,YAAY,CAAA"}
|
|
@@ -1 +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,
|
|
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,CAAA;AAE9C;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAEtD;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAyB;IAEnC;;;;;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"}
|
|
@@ -1 +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,
|
|
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,CAAA;AAEhD;;;;GAIG;AACH,qBAAa,YAAa,YAAW,SAAS;IAC5C;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAmB;IAEhC;;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"}
|
|
@@ -39,7 +39,7 @@ export interface KvAdapter {
|
|
|
39
39
|
* @param key The key to retrieve
|
|
40
40
|
* @returns The stored value or null if not found
|
|
41
41
|
*/
|
|
42
|
-
get<T>(key: string):
|
|
42
|
+
get<T>(key: string): Promise<T | null> | T | null;
|
|
43
43
|
/**
|
|
44
44
|
* Stores a value in storage with the specified key and TTL
|
|
45
45
|
*
|
|
@@ -48,7 +48,7 @@ export interface KvAdapter {
|
|
|
48
48
|
* @param ttlMs Time-to-live in milliseconds
|
|
49
49
|
* @returns Promise or void when the operation completes
|
|
50
50
|
*/
|
|
51
|
-
set(key: string, value: unknown, ttlMs: number):
|
|
51
|
+
set(key: string, value: unknown, ttlMs: number): Promise<void> | void;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Creates an appropriate KV adapter based on the runtime environment
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/kv/kv-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"kv-adapter.d.ts","sourceRoot":"","sources":["../../../src/pathways/kv/kv-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;IAEjD;;;;;;;OAOG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACtE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC,CAU1D"}
|
|
@@ -1 +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,
|
|
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,CAAA;AAEhD;;;;GAIG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC7C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAkB;IAErC;;;;;;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"}
|
|
@@ -43,7 +43,7 @@ class NodeKvAdapter {
|
|
|
43
43
|
* @returns Promise that resolves when the operation completes
|
|
44
44
|
*/
|
|
45
45
|
async set(key, value, ttlMs) {
|
|
46
|
-
await this.kv.set(key, value,
|
|
46
|
+
await this.kv.set(key, value, ttlMs / 1000);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
exports.NodeKvAdapter = NodeKvAdapter;
|