@flowcore/pathways 0.2.1 → 0.2.3

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 (98) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/esm/common/flowcore.type.d.ts +3 -3
  3. package/esm/common/flowcore.type.d.ts.map +1 -1
  4. package/esm/common/index.d.ts +2 -0
  5. package/esm/common/index.d.ts.map +1 -1
  6. package/esm/common/index.js +2 -0
  7. package/esm/compatibility/flowcore-transformer-core.sdk.d.ts +4 -0
  8. package/esm/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -1
  9. package/esm/compatibility/flowcore-transformer-core.sdk.js +2 -0
  10. package/esm/contracts/index.d.ts +2 -0
  11. package/esm/contracts/index.d.ts.map +1 -1
  12. package/esm/contracts/index.js +2 -0
  13. package/esm/mod.d.ts +2 -0
  14. package/esm/mod.d.ts.map +1 -1
  15. package/esm/mod.js +2 -0
  16. package/esm/pathways/builder.d.ts +87 -0
  17. package/esm/pathways/builder.d.ts.map +1 -1
  18. package/esm/pathways/builder.js +83 -8
  19. package/esm/pathways/index.d.ts +2 -0
  20. package/esm/pathways/index.d.ts.map +1 -1
  21. package/esm/pathways/index.js +2 -0
  22. package/esm/pathways/internal-pathway.state.d.ts +5 -7
  23. package/esm/pathways/internal-pathway.state.d.ts.map +1 -1
  24. package/esm/pathways/internal-pathway.state.js +5 -7
  25. package/esm/pathways/kv/bun-kv-adapter.d.ts +5 -7
  26. package/esm/pathways/kv/bun-kv-adapter.d.ts.map +1 -1
  27. package/esm/pathways/kv/bun-kv-adapter.js +5 -7
  28. package/esm/pathways/kv/kv-adapter.d.ts +7 -7
  29. package/esm/pathways/kv/kv-adapter.js +1 -1
  30. package/esm/pathways/kv/node-kv-adapter.d.ts +6 -8
  31. package/esm/pathways/kv/node-kv-adapter.d.ts.map +1 -1
  32. package/esm/pathways/kv/node-kv-adapter.js +6 -8
  33. package/esm/pathways/logger.d.ts +65 -12
  34. package/esm/pathways/logger.d.ts.map +1 -1
  35. package/esm/pathways/logger.js +48 -3
  36. package/esm/pathways/postgres/index.d.ts +2 -0
  37. package/esm/pathways/postgres/index.d.ts.map +1 -1
  38. package/esm/pathways/postgres/index.js +2 -0
  39. package/esm/pathways/postgres/postgres-adapter.d.ts +20 -29
  40. package/esm/pathways/postgres/postgres-adapter.d.ts.map +1 -1
  41. package/esm/pathways/postgres/postgres-adapter.js +12 -17
  42. package/esm/pathways/postgres/postgres-pathway-state.d.ts +2 -6
  43. package/esm/pathways/postgres/postgres-pathway-state.d.ts.map +1 -1
  44. package/esm/pathways/postgres/postgres-pathway-state.js +2 -4
  45. package/esm/pathways/types.d.ts +48 -3
  46. package/esm/pathways/types.d.ts.map +1 -1
  47. package/esm/router/index.d.ts +17 -11
  48. package/esm/router/index.d.ts.map +1 -1
  49. package/esm/router/index.js +21 -24
  50. package/package.json +2 -2
  51. package/script/common/flowcore.type.d.ts +3 -3
  52. package/script/common/flowcore.type.d.ts.map +1 -1
  53. package/script/common/index.d.ts +2 -0
  54. package/script/common/index.d.ts.map +1 -1
  55. package/script/common/index.js +2 -0
  56. package/script/compatibility/flowcore-transformer-core.sdk.d.ts +4 -0
  57. package/script/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -1
  58. package/script/compatibility/flowcore-transformer-core.sdk.js +2 -0
  59. package/script/contracts/index.d.ts +2 -0
  60. package/script/contracts/index.d.ts.map +1 -1
  61. package/script/contracts/index.js +2 -0
  62. package/script/mod.d.ts +2 -0
  63. package/script/mod.d.ts.map +1 -1
  64. package/script/mod.js +2 -0
  65. package/script/pathways/builder.d.ts +87 -0
  66. package/script/pathways/builder.d.ts.map +1 -1
  67. package/script/pathways/builder.js +83 -8
  68. package/script/pathways/index.d.ts +2 -0
  69. package/script/pathways/index.d.ts.map +1 -1
  70. package/script/pathways/index.js +2 -0
  71. package/script/pathways/internal-pathway.state.d.ts +5 -7
  72. package/script/pathways/internal-pathway.state.d.ts.map +1 -1
  73. package/script/pathways/internal-pathway.state.js +5 -7
  74. package/script/pathways/kv/bun-kv-adapter.d.ts +5 -7
  75. package/script/pathways/kv/bun-kv-adapter.d.ts.map +1 -1
  76. package/script/pathways/kv/bun-kv-adapter.js +5 -7
  77. package/script/pathways/kv/kv-adapter.d.ts +7 -7
  78. package/script/pathways/kv/kv-adapter.js +1 -1
  79. package/script/pathways/kv/node-kv-adapter.d.ts +6 -8
  80. package/script/pathways/kv/node-kv-adapter.d.ts.map +1 -1
  81. package/script/pathways/kv/node-kv-adapter.js +6 -8
  82. package/script/pathways/logger.d.ts +65 -12
  83. package/script/pathways/logger.d.ts.map +1 -1
  84. package/script/pathways/logger.js +48 -3
  85. package/script/pathways/postgres/index.d.ts +2 -0
  86. package/script/pathways/postgres/index.d.ts.map +1 -1
  87. package/script/pathways/postgres/index.js +2 -0
  88. package/script/pathways/postgres/postgres-adapter.d.ts +20 -29
  89. package/script/pathways/postgres/postgres-adapter.d.ts.map +1 -1
  90. package/script/pathways/postgres/postgres-adapter.js +12 -17
  91. package/script/pathways/postgres/postgres-pathway-state.d.ts +2 -6
  92. package/script/pathways/postgres/postgres-pathway-state.d.ts.map +1 -1
  93. package/script/pathways/postgres/postgres-pathway-state.js +2 -4
  94. package/script/pathways/types.d.ts +48 -3
  95. package/script/pathways/types.d.ts.map +1 -1
  96. package/script/router/index.d.ts +17 -11
  97. package/script/router/index.d.ts.map +1 -1
  98. package/script/router/index.js +21 -24
@@ -6,10 +6,43 @@ const rxjs_1 = require("rxjs");
6
6
  const flowcore_transformer_core_sdk_js_1 = require("../compatibility/flowcore-transformer-core.sdk.js");
7
7
  const internal_pathway_state_js_1 = require("./internal-pathway.state.js");
8
8
  const logger_js_1 = require("./logger.js");
9
+ /**
10
+ * Default timeout for pathway processing in milliseconds (10 seconds)
11
+ */
9
12
  const DEFAULT_PATHWAY_TIMEOUT_MS = 10000;
13
+ /**
14
+ * Default maximum number of retry attempts for failed pathway processing
15
+ */
10
16
  const DEFAULT_MAX_RETRIES = 3;
17
+ /**
18
+ * Default delay between retry attempts in milliseconds
19
+ */
11
20
  const DEFAULT_RETRY_DELAY_MS = 500;
21
+ /**
22
+ * Main builder class for creating and managing Flowcore pathways
23
+ *
24
+ * The PathwaysBuilder provides an interface for:
25
+ * - Registering pathways with type-safe schemas
26
+ * - Handling events sent to pathways
27
+ * - Writing data to pathways
28
+ * - Managing event processing and retries
29
+ * - Observing event lifecycle (before/after/error)
30
+ * - Audit logging of pathway operations
31
+ *
32
+ * @template TPathway Record type that maps pathway keys to their payload types
33
+ * @template TWritablePaths Union type of pathway keys that can be written to
34
+ */
12
35
  class PathwaysBuilder {
36
+ /**
37
+ * Creates a new PathwaysBuilder instance
38
+ * @param options Configuration options for the PathwaysBuilder
39
+ * @param options.baseUrl The base URL for the Flowcore API
40
+ * @param options.tenant The tenant name
41
+ * @param options.dataCore The data core name
42
+ * @param options.apiKey The API key for authentication
43
+ * @param options.pathwayTimeoutMs Optional timeout for pathway processing in milliseconds
44
+ * @param options.logger Optional logger instance
45
+ */
13
46
  constructor({ baseUrl, tenant, dataCore, apiKey, pathwayTimeoutMs, logger, }) {
14
47
  Object.defineProperty(this, "pathways", {
15
48
  enumerable: true,
@@ -150,6 +183,11 @@ class PathwaysBuilder {
150
183
  this.pathwayTimeoutMs = pathwayTimeoutMs;
151
184
  }
152
185
  }
186
+ /**
187
+ * Configures the PathwaysBuilder to use a custom pathway state implementation
188
+ * @param state The PathwayState implementation to use
189
+ * @returns The PathwaysBuilder instance with custom state configured
190
+ */
153
191
  withPathwayState(state) {
154
192
  this.logger.debug('Setting custom pathway state');
155
193
  this.pathwayState = state;
@@ -227,10 +265,9 @@ class PathwaysBuilder {
227
265
  catch (error) {
228
266
  // Create error object if needed
229
267
  const errorObj = error instanceof Error ? error : new Error(String(error));
230
- this.logger.error(`Error processing pathway event`, {
268
+ this.logger.error(`Error processing pathway event`, errorObj, {
231
269
  pathway: pathwayStr,
232
270
  eventId: data.eventId,
233
- error: errorObj.message,
234
271
  retryCount,
235
272
  maxRetries
236
273
  });
@@ -280,6 +317,15 @@ class PathwaysBuilder {
280
317
  await this.pathwayState.setProcessed(data.eventId);
281
318
  }
282
319
  }
320
+ /**
321
+ * Registers a new pathway with the given contract
322
+ * @template F The flow type string
323
+ * @template E The event type string
324
+ * @template S The schema type extending TSchema
325
+ * @template W Boolean indicating if the pathway is writable (defaults to true)
326
+ * @param contract The pathway contract describing the pathway
327
+ * @returns The PathwaysBuilder instance with the new pathway registered
328
+ */
283
329
  register(contract) {
284
330
  const path = `${contract.flowType}/${contract.eventType}`;
285
331
  const writable = contract.writable ?? true;
@@ -328,10 +374,28 @@ class PathwaysBuilder {
328
374
  });
329
375
  return this;
330
376
  }
377
+ /**
378
+ * Gets a pathway instance by its path
379
+ *
380
+ * @template TPath The specific pathway key to retrieve
381
+ * @param path The pathway key to get
382
+ * @returns The pathway instance
383
+ */
331
384
  get(path) {
332
385
  this.logger.debug(`Getting pathway`, { pathway: String(path) });
333
386
  return this.pathways[path];
334
387
  }
388
+ /**
389
+ * Sets a handler function for a pathway
390
+ *
391
+ * This handler will be called whenever an event is received for the specified pathway.
392
+ * Only one handler can be registered per pathway in a given PathwaysBuilder instance.
393
+ *
394
+ * @template TPath The specific pathway key to handle
395
+ * @param path The pathway key to handle
396
+ * @param handler The function that will process events for this pathway
397
+ * @throws Error if the pathway doesn't exist or already has a handler
398
+ */
335
399
  handle(path, handler) {
336
400
  const pathStr = String(path);
337
401
  this.logger.debug(`Setting handler for pathway`, { pathway: pathStr });
@@ -436,12 +500,12 @@ class PathwaysBuilder {
436
500
  }
437
501
  const schema = this.schemas[path];
438
502
  if (!value_1.Value.Check(schema, data)) {
439
- const error = `Invalid data for pathway ${pathStr}`;
440
- this.logger.error(error, {
503
+ const errorMessage = `Invalid data for pathway ${pathStr}`;
504
+ this.logger.error(errorMessage, new Error(errorMessage), {
441
505
  pathway: pathStr,
442
506
  schema: schema.toString()
443
507
  });
444
- throw new Error(error);
508
+ throw new Error(errorMessage);
445
509
  }
446
510
  // Create a copy of the metadata to avoid modifying the original
447
511
  const finalMetadata = metadata ? { ...metadata } : {};
@@ -493,6 +557,17 @@ class PathwaysBuilder {
493
557
  }
494
558
  return eventIds;
495
559
  }
560
+ /**
561
+ * Waits for a specific event to be processed
562
+ *
563
+ * This method polls the pathway state to check if an event has been processed,
564
+ * with a configurable timeout. It will throw an error if the timeout is exceeded.
565
+ *
566
+ * @private
567
+ * @param eventId The ID of the event to wait for
568
+ * @returns Promise that resolves when the event is processed
569
+ * @throws Error if the timeout is exceeded
570
+ */
496
571
  async waitForPathwayToBeProcessed(eventId) {
497
572
  const startTime = Date.now();
498
573
  const timeoutMs = this.timeouts[eventId] ?? this.pathwayTimeoutMs;
@@ -505,14 +580,14 @@ class PathwaysBuilder {
505
580
  attempts++;
506
581
  const elapsedTime = Date.now() - startTime;
507
582
  if (elapsedTime > timeoutMs) {
508
- const error = `Pathway processing timed out after ${timeoutMs}ms for event ${eventId}`;
509
- this.logger.error(error, {
583
+ const errorMessage = `Pathway processing timed out after ${timeoutMs}ms for event ${eventId}`;
584
+ this.logger.error(errorMessage, new Error(errorMessage), {
510
585
  eventId,
511
586
  timeoutMs,
512
587
  elapsedTime,
513
588
  attempts
514
589
  });
515
- throw new Error(error);
590
+ throw new Error(errorMessage);
516
591
  }
517
592
  if (attempts % 10 === 0) { // Log every 10 attempts (1 second)
518
593
  this.logger.debug(`Still waiting for event to be processed`, {
@@ -7,6 +7,8 @@
7
7
  * - Storage adapters (KV, Postgres)
8
8
  * - Logging
9
9
  * - Type definitions
10
+ *
11
+ * @module
10
12
  */
11
13
  export * from "./builder.js";
12
14
  export * from "./internal-pathway.state.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pathways/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,cAAc,CAAC;AAC7B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pathways/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,cAAc,cAAc,CAAC;AAC7B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC"}
@@ -23,6 +23,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  * - Storage adapters (KV, Postgres)
24
24
  * - Logging
25
25
  * - Type definitions
26
+ *
27
+ * @module
26
28
  */
27
29
  __exportStar(require("./builder.js"), exports);
28
30
  __exportStar(require("./internal-pathway.state.js"), exports);
@@ -2,8 +2,6 @@ import type { PathwayState } from "./types.js";
2
2
  /**
3
3
  * Internal implementation of PathwayState interface that uses KV storage
4
4
  * for tracking processed events to prevent duplicate processing
5
- *
6
- * @implements {PathwayState}
7
5
  */
8
6
  export declare class InternalPathwayState implements PathwayState {
9
7
  /**
@@ -20,21 +18,21 @@ export declare class InternalPathwayState implements PathwayState {
20
18
  * Gets or initializes the KV adapter
21
19
  *
22
20
  * @private
23
- * @returns {Promise<KvAdapter>} The KV adapter instance
21
+ * @returns The KV adapter instance
24
22
  */
25
23
  private getKv;
26
24
  /**
27
25
  * Checks if an event has already been processed
28
26
  *
29
- * @param {string} eventId - The ID of the event to check
30
- * @returns {Promise<boolean>} True if the event has been processed, false otherwise
27
+ * @param eventId The ID of the event to check
28
+ * @returns True if the event has been processed, false otherwise
31
29
  */
32
30
  isProcessed(eventId: string): Promise<boolean>;
33
31
  /**
34
32
  * Marks an event as processed
35
33
  *
36
- * @param {string} eventId - The ID of the event to mark as processed
37
- * @returns {Promise<void>}
34
+ * @param eventId The ID of the event to mark as processed
35
+ * @returns Promise that resolves when the operation completes
38
36
  */
39
37
  setProcessed(eventId: string): Promise<void>;
40
38
  }
@@ -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,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"}
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;;;GAGG;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"}
@@ -5,8 +5,6 @@ const kv_adapter_js_1 = require("./kv/kv-adapter.js");
5
5
  /**
6
6
  * Internal implementation of PathwayState interface that uses KV storage
7
7
  * for tracking processed events to prevent duplicate processing
8
- *
9
- * @implements {PathwayState}
10
8
  */
11
9
  class InternalPathwayState {
12
10
  constructor() {
@@ -25,7 +23,7 @@ class InternalPathwayState {
25
23
  * Gets or initializes the KV adapter
26
24
  *
27
25
  * @private
28
- * @returns {Promise<KvAdapter>} The KV adapter instance
26
+ * @returns The KV adapter instance
29
27
  */
30
28
  async getKv() {
31
29
  if (!this.kv) {
@@ -36,8 +34,8 @@ class InternalPathwayState {
36
34
  /**
37
35
  * Checks if an event has already been processed
38
36
  *
39
- * @param {string} eventId - The ID of the event to check
40
- * @returns {Promise<boolean>} True if the event has been processed, false otherwise
37
+ * @param eventId The ID of the event to check
38
+ * @returns True if the event has been processed, false otherwise
41
39
  */
42
40
  async isProcessed(eventId) {
43
41
  const kv = await this.getKv();
@@ -47,8 +45,8 @@ class InternalPathwayState {
47
45
  /**
48
46
  * Marks an event as processed
49
47
  *
50
- * @param {string} eventId - The ID of the event to mark as processed
51
- * @returns {Promise<void>}
48
+ * @param eventId The ID of the event to mark as processed
49
+ * @returns Promise that resolves when the operation completes
52
50
  */
53
51
  async setProcessed(eventId) {
54
52
  const kv = await this.getKv();
@@ -3,8 +3,6 @@ import type { KvAdapter } from "./kv-adapter.js";
3
3
  * KV adapter implementation for Bun runtime
4
4
  *
5
5
  * Uses Bun's SQLite-based key-value store for storage
6
- *
7
- * @implements {KvAdapter}
8
6
  */
9
7
  export declare class BunKvAdapter implements KvAdapter {
10
8
  /**
@@ -20,16 +18,16 @@ export declare class BunKvAdapter implements KvAdapter {
20
18
  * Retrieves a value from the Bun KV store
21
19
  *
22
20
  * @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
21
+ * @param key The key to retrieve
22
+ * @returns The stored value or null if not found
25
23
  */
26
24
  get<T>(key: string): T | null;
27
25
  /**
28
26
  * Stores a value in the Bun KV store with the specified TTL
29
27
  *
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
28
+ * @param key The key to store the value under
29
+ * @param value The value to store
30
+ * @param ttlMs Time-to-live in milliseconds
33
31
  */
34
32
  set(key: string, value: unknown, ttlMs: number): void;
35
33
  }
@@ -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,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"}
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;;;;GAIG;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"}
@@ -6,8 +6,6 @@ const bun_sqlite_key_value_1 = require("bun-sqlite-key-value");
6
6
  * KV adapter implementation for Bun runtime
7
7
  *
8
8
  * Uses Bun's SQLite-based key-value store for storage
9
- *
10
- * @implements {KvAdapter}
11
9
  */
12
10
  class BunKvAdapter {
13
11
  /**
@@ -30,8 +28,8 @@ class BunKvAdapter {
30
28
  * Retrieves a value from the Bun KV store
31
29
  *
32
30
  * @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
31
+ * @param key The key to retrieve
32
+ * @returns The stored value or null if not found
35
33
  */
36
34
  get(key) {
37
35
  const value = this.store.get(key);
@@ -40,9 +38,9 @@ class BunKvAdapter {
40
38
  /**
41
39
  * Stores a value in the Bun KV store with the specified TTL
42
40
  *
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
41
+ * @param key The key to store the value under
42
+ * @param value The value to store
43
+ * @param ttlMs Time-to-live in milliseconds
46
44
  */
47
45
  set(key, value, ttlMs) {
48
46
  this.store.set(key, value, ttlMs);
@@ -9,17 +9,17 @@ export interface KvAdapter {
9
9
  * Retrieves a value from storage by key
10
10
  *
11
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
12
+ * @param key The key to retrieve
13
+ * @returns The stored value or null if not found
14
14
  */
15
15
  get<T>(key: string): (Promise<T | null> | T | null);
16
16
  /**
17
17
  * Stores a value in storage with the specified key and TTL
18
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)}
19
+ * @param key The key to store the value under
20
+ * @param value The value to store
21
+ * @param ttlMs Time-to-live in milliseconds
22
+ * @returns Promise or void when the operation completes
23
23
  */
24
24
  set(key: string, value: unknown, ttlMs: number): (Promise<void> | void);
25
25
  }
@@ -28,7 +28,7 @@ export interface KvAdapter {
28
28
  *
29
29
  * Attempts to use Bun KV adapter if running in Bun, falls back to Node adapter otherwise
30
30
  *
31
- * @returns {Promise<KvAdapter>} A KV adapter instance
31
+ * @returns A KV adapter instance for the current runtime
32
32
  */
33
33
  export declare function createKvAdapter(): Promise<KvAdapter>;
34
34
  //# sourceMappingURL=kv-adapter.d.ts.map
@@ -29,7 +29,7 @@ exports.createKvAdapter = createKvAdapter;
29
29
  *
30
30
  * Attempts to use Bun KV adapter if running in Bun, falls back to Node adapter otherwise
31
31
  *
32
- * @returns {Promise<KvAdapter>} A KV adapter instance
32
+ * @returns A KV adapter instance for the current runtime
33
33
  */
34
34
  async function createKvAdapter() {
35
35
  try {
@@ -3,8 +3,6 @@ import type { KvAdapter } from "./kv-adapter.js";
3
3
  * KV adapter implementation for Node.js runtime
4
4
  *
5
5
  * Uses node-cache for in-memory key-value storage
6
- *
7
- * @implements {KvAdapter}
8
6
  */
9
7
  export declare class NodeKvAdapter implements KvAdapter {
10
8
  /**
@@ -16,17 +14,17 @@ export declare class NodeKvAdapter implements KvAdapter {
16
14
  * Retrieves a value from the Node.js cache
17
15
  *
18
16
  * @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
17
+ * @param key The key to retrieve
18
+ * @returns The stored value or null if not found
21
19
  */
22
20
  get<T>(key: string): Promise<T | null>;
23
21
  /**
24
22
  * Stores a value in the Node.js cache with the specified TTL
25
23
  *
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>}
24
+ * @param key The key to store the value under
25
+ * @param value The value to store
26
+ * @param ttlMs Time-to-live in milliseconds
27
+ * @returns Promise that resolves when the operation completes
30
28
  */
31
29
  set(key: string, value: unknown, ttlMs: number): Promise<void>;
32
30
  }
@@ -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,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"}
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;;;;GAIG;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"}
@@ -9,8 +9,6 @@ const node_cache_1 = __importDefault(require("node-cache"));
9
9
  * KV adapter implementation for Node.js runtime
10
10
  *
11
11
  * Uses node-cache for in-memory key-value storage
12
- *
13
- * @implements {KvAdapter}
14
12
  */
15
13
  class NodeKvAdapter {
16
14
  constructor() {
@@ -29,8 +27,8 @@ class NodeKvAdapter {
29
27
  * Retrieves a value from the Node.js cache
30
28
  *
31
29
  * @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
30
+ * @param key The key to retrieve
31
+ * @returns The stored value or null if not found
34
32
  */
35
33
  async get(key) {
36
34
  const result = await this.kv.get(key);
@@ -39,10 +37,10 @@ class NodeKvAdapter {
39
37
  /**
40
38
  * Stores a value in the Node.js cache with the specified TTL
41
39
  *
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>}
40
+ * @param key The key to store the value under
41
+ * @param value The value to store
42
+ * @param ttlMs Time-to-live in milliseconds
43
+ * @returns Promise that resolves when the operation completes
46
44
  */
47
45
  async set(key, value, ttlMs) {
48
46
  await this.kv.set(key, value, (ttlMs / 1000));
@@ -1,48 +1,101 @@
1
1
  /**
2
2
  * Logger interface that can be implemented by users to capture logs from pathways
3
3
  */
4
+ /**
5
+ * Metadata interface for logger context
6
+ */
7
+ export interface LoggerMeta {
8
+ [key: string]: unknown;
9
+ label?: never;
10
+ level?: never;
11
+ message?: never;
12
+ timestamp?: never;
13
+ }
4
14
  export interface Logger {
5
15
  /**
6
16
  * Log debug information
7
17
  * @param message The message to log
8
18
  * @param context Optional context data to include
9
19
  */
10
- debug(message: string, context?: Record<string, unknown>): void;
20
+ debug(message: string, context?: LoggerMeta): void;
11
21
  /**
12
22
  * Log informational messages
13
23
  * @param message The message to log
14
24
  * @param context Optional context data to include
15
25
  */
16
- info(message: string, context?: Record<string, unknown>): void;
26
+ info(message: string, context?: LoggerMeta): void;
17
27
  /**
18
28
  * Log warning messages
19
29
  * @param message The message to log
20
30
  * @param context Optional context data to include
21
31
  */
22
- warn(message: string, context?: Record<string, unknown>): void;
32
+ warn(message: string, context?: LoggerMeta): void;
23
33
  /**
24
34
  * Log error messages
25
35
  * @param message The message to log
36
+ * @param error Optional error object
26
37
  * @param context Optional context data to include
27
38
  */
28
- error(message: string, context?: Record<string, unknown>): void;
39
+ error(message: string, error?: Error, context?: LoggerMeta): void;
29
40
  }
30
41
  /**
31
42
  * A default console logger that logs to the console
32
43
  */
33
44
  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;
45
+ /**
46
+ * Log debug information to the console
47
+ * @param message The message to log
48
+ * @param context Optional context data to include
49
+ */
50
+ debug(message: string, context?: LoggerMeta): void;
51
+ /**
52
+ * Log informational messages to the console
53
+ * @param message The message to log
54
+ * @param context Optional context data to include
55
+ */
56
+ info(message: string, context?: LoggerMeta): void;
57
+ /**
58
+ * Log warning messages to the console
59
+ * @param message The message to log
60
+ * @param context Optional context data to include
61
+ */
62
+ warn(message: string, context?: LoggerMeta): void;
63
+ /**
64
+ * Log error messages to the console
65
+ * @param message The message to log
66
+ * @param error Optional error object
67
+ * @param context Optional context data to include
68
+ */
69
+ error(message: string, error?: Error, context?: LoggerMeta): void;
38
70
  }
39
71
  /**
40
72
  * A no-operation logger that does nothing
41
73
  */
42
74
  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;
75
+ /**
76
+ * No-op debug log
77
+ * @param _message The message to log (ignored)
78
+ * @param _context Optional context data (ignored)
79
+ */
80
+ debug(_message: string, _context?: LoggerMeta): void;
81
+ /**
82
+ * No-op info log
83
+ * @param _message The message to log (ignored)
84
+ * @param _context Optional context data (ignored)
85
+ */
86
+ info(_message: string, _context?: LoggerMeta): void;
87
+ /**
88
+ * No-op warning log
89
+ * @param _message The message to log (ignored)
90
+ * @param _context Optional context data (ignored)
91
+ */
92
+ warn(_message: string, _context?: LoggerMeta): void;
93
+ /**
94
+ * No-op error log
95
+ * @param _message The message to log (ignored)
96
+ * @param _error Optional error object (ignored)
97
+ * @param _context Optional context data (ignored)
98
+ */
99
+ error(_message: string, _error?: Error, _context?: LoggerMeta): void;
47
100
  }
48
101
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/pathways/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MA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,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI;IAIjD;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI;IAIjD;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI;CAGlE;AAED;;GAEG;AACH,qBAAa,UAAW,YAAW,MAAM;IACvC;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,IAAI;IAEpD;;;;OAIG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,IAAI;IAEnD;;;;OAIG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,IAAI;IAEnD;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,IAAI;CACrE"}
@@ -1,21 +1,45 @@
1
1
  "use strict";
2
+ /**
3
+ * Logger interface that can be implemented by users to capture logs from pathways
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.NoopLogger = exports.ConsoleLogger = void 0;
4
7
  /**
5
8
  * A default console logger that logs to the console
6
9
  */
7
10
  class ConsoleLogger {
11
+ /**
12
+ * Log debug information to the console
13
+ * @param message The message to log
14
+ * @param context Optional context data to include
15
+ */
8
16
  debug(message, context) {
9
17
  console.debug(message, context ? JSON.stringify(context) : '');
10
18
  }
19
+ /**
20
+ * Log informational messages to the console
21
+ * @param message The message to log
22
+ * @param context Optional context data to include
23
+ */
11
24
  info(message, context) {
12
25
  console.info(message, context ? JSON.stringify(context) : '');
13
26
  }
27
+ /**
28
+ * Log warning messages to the console
29
+ * @param message The message to log
30
+ * @param context Optional context data to include
31
+ */
14
32
  warn(message, context) {
15
33
  console.warn(message, context ? JSON.stringify(context) : '');
16
34
  }
17
- error(message, context) {
18
- console.error(message, context ? JSON.stringify(context) : '');
35
+ /**
36
+ * Log error messages to the console
37
+ * @param message The message to log
38
+ * @param error Optional error object
39
+ * @param context Optional context data to include
40
+ */
41
+ error(message, error, context) {
42
+ console.error(message, error, context ? JSON.stringify(context) : '');
19
43
  }
20
44
  }
21
45
  exports.ConsoleLogger = ConsoleLogger;
@@ -23,9 +47,30 @@ exports.ConsoleLogger = ConsoleLogger;
23
47
  * A no-operation logger that does nothing
24
48
  */
25
49
  class NoopLogger {
50
+ /**
51
+ * No-op debug log
52
+ * @param _message The message to log (ignored)
53
+ * @param _context Optional context data (ignored)
54
+ */
26
55
  debug(_message, _context) { }
56
+ /**
57
+ * No-op info log
58
+ * @param _message The message to log (ignored)
59
+ * @param _context Optional context data (ignored)
60
+ */
27
61
  info(_message, _context) { }
62
+ /**
63
+ * No-op warning log
64
+ * @param _message The message to log (ignored)
65
+ * @param _context Optional context data (ignored)
66
+ */
28
67
  warn(_message, _context) { }
29
- error(_message, _context) { }
68
+ /**
69
+ * No-op error log
70
+ * @param _message The message to log (ignored)
71
+ * @param _error Optional error object (ignored)
72
+ * @param _context Optional context data (ignored)
73
+ */
74
+ error(_message, _error, _context) { }
30
75
  }
31
76
  exports.NoopLogger = NoopLogger;