@ironflow/node 0.20.2 → 0.21.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.
Files changed (145) hide show
  1. package/dist/agent/agent.d.ts +60 -0
  2. package/dist/agent/agent.d.ts.map +1 -0
  3. package/dist/agent/agent.js +133 -0
  4. package/dist/agent/agent.js.map +1 -0
  5. package/dist/agent/approve.d.ts +23 -0
  6. package/dist/agent/approve.d.ts.map +1 -0
  7. package/dist/agent/approve.js +42 -0
  8. package/dist/agent/approve.js.map +1 -0
  9. package/dist/agent/dispatch.d.ts +63 -0
  10. package/dist/agent/dispatch.d.ts.map +1 -0
  11. package/dist/agent/dispatch.js +130 -0
  12. package/dist/agent/dispatch.js.map +1 -0
  13. package/dist/agent/errors.d.ts +90 -0
  14. package/dist/agent/errors.d.ts.map +1 -0
  15. package/dist/agent/errors.js +136 -0
  16. package/dist/agent/errors.js.map +1 -0
  17. package/dist/agent/index.d.ts +35 -0
  18. package/dist/agent/index.d.ts.map +1 -0
  19. package/dist/agent/index.js +32 -0
  20. package/dist/agent/index.js.map +1 -0
  21. package/dist/agent/internal-registry.d.ts +27 -0
  22. package/dist/agent/internal-registry.d.ts.map +1 -0
  23. package/dist/agent/internal-registry.js +36 -0
  24. package/dist/agent/internal-registry.js.map +1 -0
  25. package/dist/agent/internal.d.ts +24 -0
  26. package/dist/agent/internal.d.ts.map +1 -0
  27. package/dist/agent/internal.js +29 -0
  28. package/dist/agent/internal.js.map +1 -0
  29. package/dist/agent/llm.d.ts +39 -0
  30. package/dist/agent/llm.d.ts.map +1 -0
  31. package/dist/agent/llm.js +59 -0
  32. package/dist/agent/llm.js.map +1 -0
  33. package/dist/agent/mcp.d.ts +51 -0
  34. package/dist/agent/mcp.d.ts.map +1 -0
  35. package/dist/agent/mcp.js +155 -0
  36. package/dist/agent/mcp.js.map +1 -0
  37. package/dist/agent/memory.d.ts +74 -0
  38. package/dist/agent/memory.d.ts.map +1 -0
  39. package/dist/agent/memory.js +130 -0
  40. package/dist/agent/memory.js.map +1 -0
  41. package/dist/agent/spawn.d.ts +20 -0
  42. package/dist/agent/spawn.d.ts.map +1 -0
  43. package/dist/agent/spawn.js +29 -0
  44. package/dist/agent/spawn.js.map +1 -0
  45. package/dist/agent/tool.d.ts +39 -0
  46. package/dist/agent/tool.d.ts.map +1 -0
  47. package/dist/agent/tool.js +103 -0
  48. package/dist/agent/tool.js.map +1 -0
  49. package/dist/agent/types.d.ts +363 -0
  50. package/dist/agent/types.d.ts.map +1 -0
  51. package/dist/agent/types.js +9 -0
  52. package/dist/agent/types.js.map +1 -0
  53. package/dist/client.d.ts +942 -0
  54. package/dist/client.d.ts.map +1 -0
  55. package/dist/client.js +1557 -0
  56. package/dist/client.js.map +1 -0
  57. package/dist/command-dedup.d.ts +61 -0
  58. package/dist/command-dedup.d.ts.map +1 -0
  59. package/dist/command-dedup.js +129 -0
  60. package/dist/command-dedup.js.map +1 -0
  61. package/dist/config-client.d.ts +58 -0
  62. package/dist/config-client.d.ts.map +1 -0
  63. package/dist/config-client.js +171 -0
  64. package/dist/config-client.js.map +1 -0
  65. package/dist/function.d.ts +53 -0
  66. package/dist/function.d.ts.map +1 -0
  67. package/dist/function.js +72 -0
  68. package/dist/function.js.map +1 -0
  69. package/dist/index.d.ts +71 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +70 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/internal/assert-defined.d.ts +10 -0
  74. package/dist/internal/assert-defined.d.ts.map +1 -0
  75. package/dist/internal/assert-defined.js +15 -0
  76. package/dist/internal/assert-defined.js.map +1 -0
  77. package/dist/internal/context.d.ts +142 -0
  78. package/dist/internal/context.d.ts.map +1 -0
  79. package/dist/internal/context.js +306 -0
  80. package/dist/internal/context.js.map +1 -0
  81. package/dist/internal/errors.d.ts +66 -0
  82. package/dist/internal/errors.d.ts.map +1 -0
  83. package/dist/internal/errors.js +29 -0
  84. package/dist/internal/errors.js.map +1 -0
  85. package/dist/internal/run-context.d.ts +10 -0
  86. package/dist/internal/run-context.d.ts.map +1 -0
  87. package/dist/internal/run-context.js +23 -0
  88. package/dist/internal/run-context.js.map +1 -0
  89. package/dist/kv.d.ts +86 -0
  90. package/dist/kv.d.ts.map +1 -0
  91. package/dist/kv.js +261 -0
  92. package/dist/kv.js.map +1 -0
  93. package/dist/projection-runner.d.ts +83 -0
  94. package/dist/projection-runner.d.ts.map +1 -0
  95. package/dist/projection-runner.js +498 -0
  96. package/dist/projection-runner.js.map +1 -0
  97. package/dist/projection.d.ts +36 -0
  98. package/dist/projection.d.ts.map +1 -0
  99. package/dist/projection.js +55 -0
  100. package/dist/projection.js.map +1 -0
  101. package/dist/secrets.d.ts +6 -0
  102. package/dist/secrets.d.ts.map +1 -0
  103. package/dist/secrets.js +19 -0
  104. package/dist/secrets.js.map +1 -0
  105. package/dist/serve.d.ts +71 -0
  106. package/dist/serve.d.ts.map +1 -0
  107. package/dist/serve.js +460 -0
  108. package/dist/serve.js.map +1 -0
  109. package/dist/step.d.ts +18 -0
  110. package/dist/step.d.ts.map +1 -0
  111. package/dist/step.js +581 -0
  112. package/dist/step.js.map +1 -0
  113. package/dist/subscribe.d.ts +164 -0
  114. package/dist/subscribe.d.ts.map +1 -0
  115. package/dist/subscribe.js +487 -0
  116. package/dist/subscribe.js.map +1 -0
  117. package/dist/test/index.d.ts +22 -0
  118. package/dist/test/index.d.ts.map +1 -0
  119. package/dist/test/index.js +112 -0
  120. package/dist/test/index.js.map +1 -0
  121. package/dist/test/test-step.d.ts +21 -0
  122. package/dist/test/test-step.d.ts.map +1 -0
  123. package/dist/test/test-step.js +83 -0
  124. package/dist/test/test-step.js.map +1 -0
  125. package/dist/types.d.ts +108 -0
  126. package/dist/types.d.ts.map +1 -0
  127. package/dist/types.js +5 -0
  128. package/dist/types.js.map +1 -0
  129. package/dist/version.d.ts +2 -0
  130. package/dist/version.d.ts.map +1 -0
  131. package/dist/version.js +4 -0
  132. package/dist/version.js.map +1 -0
  133. package/dist/webhook.d.ts +22 -0
  134. package/dist/webhook.d.ts.map +1 -0
  135. package/dist/webhook.js +23 -0
  136. package/dist/webhook.js.map +1 -0
  137. package/dist/worker-streaming.d.ts +17 -0
  138. package/dist/worker-streaming.d.ts.map +1 -0
  139. package/dist/worker-streaming.js +510 -0
  140. package/dist/worker-streaming.js.map +1 -0
  141. package/dist/worker.d.ts +28 -0
  142. package/dist/worker.d.ts.map +1 -0
  143. package/dist/worker.js +559 -0
  144. package/dist/worker.js.map +1 -0
  145. package/package.json +3 -3
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Internal error classes for step execution (Node.js specific)
3
+ */
4
+ /**
5
+ * Yield information union type
6
+ */
7
+ export type YieldInfo = SleepYieldInfo | WaitEventYieldInfo | InvokeFunctionYieldInfo | InvokeFunctionAsyncYieldInfo;
8
+ /**
9
+ * Sleep yield information
10
+ */
11
+ export interface SleepYieldInfo {
12
+ step_id: string;
13
+ type: "sleep";
14
+ until: string;
15
+ }
16
+ /**
17
+ * Wait for event yield information
18
+ */
19
+ export interface WaitEventYieldInfo {
20
+ step_id: string;
21
+ type: "wait_for_event";
22
+ event_filter: {
23
+ event: string;
24
+ match?: string;
25
+ timeout?: string;
26
+ };
27
+ }
28
+ /**
29
+ * Invoke function yield information
30
+ */
31
+ export interface InvokeFunctionYieldInfo {
32
+ step_id: string;
33
+ type: "invoke_function";
34
+ function_id: string;
35
+ input?: unknown;
36
+ invoke_timeout_ms?: number;
37
+ }
38
+ /**
39
+ * Invoke function async yield information
40
+ */
41
+ export interface InvokeFunctionAsyncYieldInfo {
42
+ step_id: string;
43
+ type: "invoke_function_async";
44
+ function_id: string;
45
+ input?: unknown;
46
+ }
47
+ /**
48
+ * Internal signal to yield execution (not a real error).
49
+ * Used internally to implement sleep and waitForEvent.
50
+ *
51
+ * @internal
52
+ */
53
+ export declare class YieldSignal extends Error {
54
+ /** Information about the yield operation */
55
+ readonly yieldInfo: YieldInfo;
56
+ constructor(yieldInfo: YieldInfo);
57
+ }
58
+ /**
59
+ * Check if an error is a YieldSignal
60
+ *
61
+ * @param error - The error to check
62
+ * @returns true if the error is a YieldSignal
63
+ * @internal
64
+ */
65
+ export declare function isYieldSignal(error: unknown): error is YieldSignal;
66
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,kBAAkB,GAAG,uBAAuB,GAAG,4BAA4B,CAAC;AAErH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;IACvB,YAAY,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,uBAAuB,CAAC;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,4CAA4C;IAC5C,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;CAKjC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Internal error classes for step execution (Node.js specific)
3
+ */
4
+ /**
5
+ * Internal signal to yield execution (not a real error).
6
+ * Used internally to implement sleep and waitForEvent.
7
+ *
8
+ * @internal
9
+ */
10
+ export class YieldSignal extends Error {
11
+ /** Information about the yield operation */
12
+ yieldInfo;
13
+ constructor(yieldInfo) {
14
+ super("Yield signal");
15
+ this.name = "YieldSignal";
16
+ this.yieldInfo = yieldInfo;
17
+ }
18
+ }
19
+ /**
20
+ * Check if an error is a YieldSignal
21
+ *
22
+ * @param error - The error to check
23
+ * @returns true if the error is a YieldSignal
24
+ * @internal
25
+ */
26
+ export function isYieldSignal(error) {
27
+ return error instanceof YieldSignal;
28
+ }
29
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/internal/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAkDH;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,4CAA4C;IACnC,SAAS,CAAY;IAE9B,YAAY,SAAoB;QAC9B,KAAK,CAAC,cAAc,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,KAAK,YAAY,WAAW,CAAC;AACtC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Execute a callback within a run context.
3
+ * Any createClient() calls inside will automatically include the run ID.
4
+ */
5
+ export declare function withRunContext<T>(runId: string, fn: () => T): T;
6
+ /**
7
+ * Get the current run ID from context, or undefined if not in a run.
8
+ */
9
+ export declare function getCurrentRunId(): string | undefined;
10
+ //# sourceMappingURL=run-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-context.d.ts","sourceRoot":"","sources":["../../src/internal/run-context.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE/D;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,GAAG,SAAS,CAEpD"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Run context propagation via AsyncLocalStorage.
3
+ *
4
+ * When a function handler executes, the SDK sets the current run ID.
5
+ * createClient() picks it up automatically and includes X-Ironflow-Run-ID
6
+ * header on all requests — linking entity events to the run that created them.
7
+ */
8
+ import { AsyncLocalStorage } from "node:async_hooks";
9
+ const runContextStorage = new AsyncLocalStorage();
10
+ /**
11
+ * Execute a callback within a run context.
12
+ * Any createClient() calls inside will automatically include the run ID.
13
+ */
14
+ export function withRunContext(runId, fn) {
15
+ return runContextStorage.run({ runId }, fn);
16
+ }
17
+ /**
18
+ * Get the current run ID from context, or undefined if not in a run.
19
+ */
20
+ export function getCurrentRunId() {
21
+ return runContextStorage.getStore()?.runId;
22
+ }
23
+ //# sourceMappingURL=run-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-context.js","sourceRoot":"","sources":["../../src/internal/run-context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAMrD,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAc,CAAC;AAE9D;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAI,KAAa,EAAE,EAAW;IAC1D,OAAO,iBAAiB,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,iBAAiB,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC;AAC7C,CAAC"}
package/dist/kv.d.ts ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Ironflow Node.js KV Client
3
+ *
4
+ * Key-Value store operations for the Ironflow server.
5
+ */
6
+ import type { KVBucketConfig, KVBucketInfo, KVEntry, KVPutResult } from "@ironflow/core";
7
+ import type { OnErrorHandler } from "./types.js";
8
+ /**
9
+ * Configuration for the KV client (inherited from parent client).
10
+ */
11
+ export interface KVClientConfig {
12
+ serverUrl: string;
13
+ apiKey?: string;
14
+ timeout: number;
15
+ onError?: OnErrorHandler;
16
+ }
17
+ /**
18
+ * KV bucket handle for key-level operations.
19
+ */
20
+ export declare class KVBucketHandle {
21
+ private readonly bucketName;
22
+ private readonly config;
23
+ constructor(bucketName: string, config: KVClientConfig);
24
+ /**
25
+ * Get a value by key.
26
+ */
27
+ get(key: string): Promise<KVEntry>;
28
+ /**
29
+ * Put a value unconditionally.
30
+ */
31
+ put(key: string, value: unknown): Promise<KVPutResult>;
32
+ /**
33
+ * Create a value only if the key doesn't exist (if-not-exists).
34
+ * Throws on conflict (HTTP 412).
35
+ */
36
+ create(key: string, value: unknown): Promise<KVPutResult>;
37
+ /**
38
+ * Update a value only if the revision matches (compare-and-swap).
39
+ * Throws on mismatch (HTTP 412).
40
+ */
41
+ update(key: string, value: unknown, revision: number): Promise<KVPutResult>;
42
+ /**
43
+ * Delete a key (soft delete / tombstone).
44
+ */
45
+ delete(key: string): Promise<void>;
46
+ /**
47
+ * Purge a key and all its history.
48
+ */
49
+ purge(key: string): Promise<void>;
50
+ /**
51
+ * List keys with an optional wildcard filter.
52
+ */
53
+ listKeys(filter?: string): Promise<string[]>;
54
+ private callOnError;
55
+ private restRequest;
56
+ }
57
+ /**
58
+ * KV client for bucket management and key operations.
59
+ */
60
+ export declare class KVClient {
61
+ private readonly config;
62
+ constructor(config: KVClientConfig);
63
+ /**
64
+ * Create a new bucket.
65
+ */
66
+ createBucket(config: KVBucketConfig): Promise<KVBucketInfo>;
67
+ /**
68
+ * Delete a bucket.
69
+ */
70
+ deleteBucket(name: string): Promise<void>;
71
+ /**
72
+ * List all buckets.
73
+ */
74
+ listBuckets(): Promise<KVBucketInfo[]>;
75
+ /**
76
+ * Get bucket info.
77
+ */
78
+ getBucketInfo(name: string): Promise<KVBucketInfo>;
79
+ /**
80
+ * Get a bucket handle for key-level operations.
81
+ */
82
+ bucket(name: string): KVBucketHandle;
83
+ private callOnError;
84
+ private restRequest;
85
+ }
86
+ //# sourceMappingURL=kv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kv.d.ts","sourceRoot":"","sources":["../src/kv.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,OAAO,EACP,WAAW,EAGZ,MAAM,gBAAgB,CAAC;AAOxB,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,YAAY,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc;IAGzC;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUxC;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IAU5D;;;OAGG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IAU/D;;;OAGG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC;IAUvB;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxC;;OAEG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvC;;OAEG;IACG,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YASpC,WAAW;YASX,WAAW;CAsE1B;AAED;;GAEG;AACH,qBAAa,QAAQ;IACP,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,cAAc;IAEnD;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAgBjE;;OAEG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/C;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAU5C;;OAEG;IACG,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IASxD;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc;YAItB,WAAW;YASX,WAAW;CAyD1B"}
package/dist/kv.js ADDED
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Ironflow Node.js KV Client
3
+ *
4
+ * Key-Value store operations for the Ironflow server.
5
+ */
6
+ import { IronflowError, UnauthenticatedError, EnterpriseRequiredError, UnauthorizedError, } from "@ironflow/core";
7
+ /**
8
+ * KV bucket handle for key-level operations.
9
+ */
10
+ export class KVBucketHandle {
11
+ bucketName;
12
+ config;
13
+ constructor(bucketName, config) {
14
+ this.bucketName = bucketName;
15
+ this.config = config;
16
+ }
17
+ /**
18
+ * Get a value by key.
19
+ */
20
+ async get(key) {
21
+ return this.restRequest("GET", `/api/v1/kv/buckets/${enc(this.bucketName)}/keys/${key}`, undefined, undefined, "kv.bucket.get");
22
+ }
23
+ /**
24
+ * Put a value unconditionally.
25
+ */
26
+ async put(key, value) {
27
+ return this.restRequest("PUT", `/api/v1/kv/buckets/${enc(this.bucketName)}/keys/${key}`, value, undefined, "kv.bucket.put");
28
+ }
29
+ /**
30
+ * Create a value only if the key doesn't exist (if-not-exists).
31
+ * Throws on conflict (HTTP 412).
32
+ */
33
+ async create(key, value) {
34
+ return this.restRequest("PUT", `/api/v1/kv/buckets/${enc(this.bucketName)}/keys/${key}`, value, { "If-None-Match": "*" }, "kv.bucket.create");
35
+ }
36
+ /**
37
+ * Update a value only if the revision matches (compare-and-swap).
38
+ * Throws on mismatch (HTTP 412).
39
+ */
40
+ async update(key, value, revision) {
41
+ return this.restRequest("PUT", `/api/v1/kv/buckets/${enc(this.bucketName)}/keys/${key}`, value, { "If-Match": String(revision) }, "kv.bucket.update");
42
+ }
43
+ /**
44
+ * Delete a key (soft delete / tombstone).
45
+ */
46
+ async delete(key) {
47
+ await this.restRequest("DELETE", `/api/v1/kv/buckets/${enc(this.bucketName)}/keys/${key}`, undefined, undefined, "kv.bucket.delete");
48
+ }
49
+ /**
50
+ * Purge a key and all its history.
51
+ */
52
+ async purge(key) {
53
+ await this.restRequest("DELETE", `/api/v1/kv/buckets/${enc(this.bucketName)}/keys/${key}?purge=true`, undefined, undefined, "kv.bucket.purge");
54
+ }
55
+ /**
56
+ * List keys with an optional wildcard filter.
57
+ */
58
+ async listKeys(filter) {
59
+ let path = `/api/v1/kv/buckets/${enc(this.bucketName)}/keys`;
60
+ if (filter) {
61
+ path += `?filter=${encodeURIComponent(filter)}`;
62
+ }
63
+ const result = await this.restRequest("GET", path, undefined, undefined, "kv.bucket.listKeys");
64
+ return result.keys;
65
+ }
66
+ async callOnError(error, context) {
67
+ if (!this.config.onError)
68
+ return;
69
+ try {
70
+ await this.config.onError(error, context);
71
+ }
72
+ catch (callbackError) {
73
+ console.error("[ironflow] onError callback threw:", callbackError);
74
+ }
75
+ }
76
+ async restRequest(httpMethod, path, body, extraHeaders, clientMethod) {
77
+ const url = `${this.config.serverUrl}${path}`;
78
+ const headers = {};
79
+ if (body !== undefined) {
80
+ headers["Content-Type"] =
81
+ typeof body === "string" || body instanceof Uint8Array
82
+ ? "application/octet-stream"
83
+ : "application/json";
84
+ }
85
+ if (this.config.apiKey) {
86
+ headers["Authorization"] = `Bearer ${this.config.apiKey}`;
87
+ }
88
+ if (extraHeaders) {
89
+ Object.assign(headers, extraHeaders);
90
+ }
91
+ const controller = new AbortController();
92
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
93
+ let status;
94
+ try {
95
+ const response = await fetch(url, {
96
+ method: httpMethod,
97
+ headers,
98
+ body: body !== undefined
99
+ ? typeof body === "string" || body instanceof Uint8Array
100
+ ? body
101
+ : JSON.stringify(body)
102
+ : undefined,
103
+ signal: controller.signal,
104
+ });
105
+ status = response.status;
106
+ if (!response.ok) {
107
+ const errorBody = await response.text();
108
+ let errorMessage = `KV request failed with status ${response.status}`;
109
+ try {
110
+ const errorJson = JSON.parse(errorBody);
111
+ if (errorJson.error)
112
+ errorMessage = errorJson.error;
113
+ }
114
+ catch {
115
+ if (errorBody)
116
+ errorMessage = errorBody;
117
+ }
118
+ throwTypedError(response.status, errorMessage);
119
+ }
120
+ if (response.status === 204) {
121
+ return undefined;
122
+ }
123
+ return response.json();
124
+ }
125
+ catch (error) {
126
+ if (clientMethod) {
127
+ await this.callOnError(error, { method: clientMethod, endpoint: path, statusCode: status });
128
+ }
129
+ throw error;
130
+ }
131
+ finally {
132
+ clearTimeout(timeoutId);
133
+ }
134
+ }
135
+ }
136
+ /**
137
+ * KV client for bucket management and key operations.
138
+ */
139
+ export class KVClient {
140
+ config;
141
+ constructor(config) {
142
+ this.config = config;
143
+ }
144
+ /**
145
+ * Create a new bucket.
146
+ */
147
+ async createBucket(config) {
148
+ const body = { name: config.name };
149
+ if (config.description)
150
+ body.description = config.description;
151
+ if (config.ttlSeconds)
152
+ body.ttl_seconds = config.ttlSeconds;
153
+ if (config.maxValueSize)
154
+ body.max_value_size = config.maxValueSize;
155
+ if (config.maxBytes)
156
+ body.max_bytes = config.maxBytes;
157
+ if (config.history)
158
+ body.history = config.history;
159
+ return this.restRequest("POST", "/api/v1/kv/buckets", body, "kv.createBucket");
160
+ }
161
+ /**
162
+ * Delete a bucket.
163
+ */
164
+ async deleteBucket(name) {
165
+ await this.restRequest("DELETE", `/api/v1/kv/buckets/${enc(name)}`, undefined, "kv.deleteBucket");
166
+ }
167
+ /**
168
+ * List all buckets.
169
+ */
170
+ async listBuckets() {
171
+ const result = await this.restRequest("GET", "/api/v1/kv/buckets", undefined, "kv.listBuckets");
172
+ return result.buckets;
173
+ }
174
+ /**
175
+ * Get bucket info.
176
+ */
177
+ async getBucketInfo(name) {
178
+ return this.restRequest("GET", `/api/v1/kv/buckets/${enc(name)}`, undefined, "kv.getBucketInfo");
179
+ }
180
+ /**
181
+ * Get a bucket handle for key-level operations.
182
+ */
183
+ bucket(name) {
184
+ return new KVBucketHandle(name, this.config);
185
+ }
186
+ async callOnError(error, context) {
187
+ if (!this.config.onError)
188
+ return;
189
+ try {
190
+ await this.config.onError(error, context);
191
+ }
192
+ catch (callbackError) {
193
+ console.error("[ironflow] onError callback threw:", callbackError);
194
+ }
195
+ }
196
+ async restRequest(httpMethod, path, body, clientMethod) {
197
+ const url = `${this.config.serverUrl}${path}`;
198
+ const headers = {};
199
+ if (body !== undefined) {
200
+ headers["Content-Type"] = "application/json";
201
+ }
202
+ if (this.config.apiKey) {
203
+ headers["Authorization"] = `Bearer ${this.config.apiKey}`;
204
+ }
205
+ const controller = new AbortController();
206
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
207
+ let status;
208
+ try {
209
+ const response = await fetch(url, {
210
+ method: httpMethod,
211
+ headers,
212
+ body: body !== undefined ? JSON.stringify(body) : undefined,
213
+ signal: controller.signal,
214
+ });
215
+ status = response.status;
216
+ if (!response.ok) {
217
+ const errorBody = await response.text();
218
+ let errorMessage = `KV request failed with status ${response.status}`;
219
+ try {
220
+ const errorJson = JSON.parse(errorBody);
221
+ if (errorJson.error)
222
+ errorMessage = errorJson.error;
223
+ }
224
+ catch {
225
+ if (errorBody)
226
+ errorMessage = errorBody;
227
+ }
228
+ throwTypedError(response.status, errorMessage);
229
+ }
230
+ if (response.status === 204) {
231
+ return undefined;
232
+ }
233
+ return response.json();
234
+ }
235
+ catch (error) {
236
+ if (clientMethod) {
237
+ await this.callOnError(error, { method: clientMethod, endpoint: path, statusCode: status });
238
+ }
239
+ throw error;
240
+ }
241
+ finally {
242
+ clearTimeout(timeoutId);
243
+ }
244
+ }
245
+ }
246
+ function enc(s) {
247
+ return encodeURIComponent(s);
248
+ }
249
+ function throwTypedError(status, message) {
250
+ switch (status) {
251
+ case 401:
252
+ throw new UnauthenticatedError(message);
253
+ case 402:
254
+ throw new EnterpriseRequiredError(message);
255
+ case 403:
256
+ throw new UnauthorizedError(message);
257
+ default:
258
+ throw new IronflowError(message, { code: `HTTP_${status}` });
259
+ }
260
+ }
261
+ //# sourceMappingURL=kv.js.map
package/dist/kv.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kv.js","sourceRoot":"","sources":["../src/kv.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAaxB;;GAEG;AACH,MAAM,OAAO,cAAc;IAEN;IACA;IAFnB,YACmB,UAAkB,EAClB,MAAsB;QADtB,eAAU,GAAV,UAAU,CAAQ;QAClB,WAAM,GAAN,MAAM,CAAgB;IACtC,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,WAAW,CACrB,KAAK,EACL,sBAA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 *
6
+ * 1. **Streaming (preferred):** Opens a persistent ConnectRPC server-stream
7
+ * that receives events in real-time as they arrive. Uses micro-batching
8
+ * (100ms window or batch_size events, whichever comes first) to amortize
9
+ * state saves.
10
+ *
11
+ * 2. **Polling (fallback):** If streaming is unavailable (older server), falls
12
+ * back to HTTP polling with exponential backoff (1s → 2s → 4s, max 10s).
13
+ *
14
+ * Both modes use the same handler execution and state persistence logic.
15
+ */
16
+ import type { IronflowProjection, Logger } from "@ironflow/core";
17
+ export interface ProjectionRunnerConfig {
18
+ projection: IronflowProjection<any, any>;
19
+ baseUrl: string;
20
+ headers: Record<string, string>;
21
+ logger: Logger;
22
+ signal?: AbortSignal;
23
+ }
24
+ export declare class ProjectionRunner {
25
+ private config;
26
+ private running;
27
+ private backoffMs;
28
+ private pendingEvents;
29
+ private flushTimer;
30
+ private flushChain;
31
+ private managedState;
32
+ private managedStateInitialized;
33
+ constructor(config: ProjectionRunnerConfig);
34
+ register(): Promise<void>;
35
+ /**
36
+ * Start in streaming mode (preferred). Opens a ConnectRPC server-stream
37
+ * that delivers events in real-time. Falls back to polling if the server
38
+ * returns Unimplemented or the stream fails to connect.
39
+ */
40
+ startStreaming(): Promise<void>;
41
+ /**
42
+ * Enqueue an event from the stream into the micro-batch.
43
+ * Flushes when batch is full or after FLUSH_INTERVAL_MS of inactivity.
44
+ * Flush calls are serialized via flushChain to prevent concurrent state mutations.
45
+ */
46
+ private enqueueEvent;
47
+ /** Serializes flush calls so only one runs at a time */
48
+ private scheduleFlush;
49
+ /**
50
+ * Flush pending events through the handler and persist state.
51
+ */
52
+ private flushPending;
53
+ /**
54
+ * Process a batch of events in managed mode: run reducer, save state.
55
+ */
56
+ private processManagedBatch;
57
+ /**
58
+ * Process a batch of events in external mode: run handler, ack.
59
+ */
60
+ private processExternalBatch;
61
+ /**
62
+ * Load existing projection state from the server so streaming resumes
63
+ * with the correct accumulated state.
64
+ */
65
+ private loadExistingState;
66
+ /**
67
+ * Start in poll mode (fallback). Uses the existing PollProjectionEvents RPC
68
+ * with exponential backoff.
69
+ */
70
+ start(): Promise<void>;
71
+ stop(): Promise<void>;
72
+ private poll;
73
+ private buildContext;
74
+ private saveState;
75
+ private ackEvents;
76
+ private sleep;
77
+ }
78
+ /** Error thrown when the server doesn't support the streaming RPC */
79
+ export declare class StreamingUnsupportedError extends Error {
80
+ constructor(message: string);
81
+ }
82
+ export declare function createProjectionRunner(config: ProjectionRunnerConfig): ProjectionRunner;
83
+ //# sourceMappingURL=projection-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection-runner.d.ts","sourceRoot":"","sources":["../src/projection-runner.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAElB,MAAM,EAGP,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,sBAAsB;IAErC,UAAU,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAuCD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAQ;IAGzB,OAAO,CAAC,aAAa,CAAmB;IACxC,OAAO,CAAC,UAAU,CAA8C;IAEhE,OAAO,CAAC,UAAU,CAAoC;IAEtD,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,uBAAuB,CAAS;gBAE5B,MAAM,EAAE,sBAAsB;IAIpC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB/B;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IA4KrC;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAgBpB,wDAAwD;IACx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