routeflow-api 0.2.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 (70) hide show
  1. package/README.md +93 -0
  2. package/dist/adapters/cassandra.cjs +117 -0
  3. package/dist/adapters/cassandra.cjs.map +1 -0
  4. package/dist/adapters/cassandra.d.cts +37 -0
  5. package/dist/adapters/cassandra.d.ts +37 -0
  6. package/dist/adapters/cassandra.js +90 -0
  7. package/dist/adapters/cassandra.js.map +1 -0
  8. package/dist/adapters/dynamodb.cjs +180 -0
  9. package/dist/adapters/dynamodb.cjs.map +1 -0
  10. package/dist/adapters/dynamodb.d.cts +48 -0
  11. package/dist/adapters/dynamodb.d.ts +48 -0
  12. package/dist/adapters/dynamodb.js +153 -0
  13. package/dist/adapters/dynamodb.js.map +1 -0
  14. package/dist/adapters/elasticsearch.cjs +120 -0
  15. package/dist/adapters/elasticsearch.cjs.map +1 -0
  16. package/dist/adapters/elasticsearch.d.cts +43 -0
  17. package/dist/adapters/elasticsearch.d.ts +43 -0
  18. package/dist/adapters/elasticsearch.js +93 -0
  19. package/dist/adapters/elasticsearch.js.map +1 -0
  20. package/dist/adapters/mongodb.cjs +159 -0
  21. package/dist/adapters/mongodb.cjs.map +1 -0
  22. package/dist/adapters/mongodb.d.cts +54 -0
  23. package/dist/adapters/mongodb.d.ts +54 -0
  24. package/dist/adapters/mongodb.js +132 -0
  25. package/dist/adapters/mongodb.js.map +1 -0
  26. package/dist/adapters/mysql.cjs +159 -0
  27. package/dist/adapters/mysql.cjs.map +1 -0
  28. package/dist/adapters/mysql.d.cts +63 -0
  29. package/dist/adapters/mysql.d.ts +63 -0
  30. package/dist/adapters/mysql.js +132 -0
  31. package/dist/adapters/mysql.js.map +1 -0
  32. package/dist/adapters/opensearch.cjs +120 -0
  33. package/dist/adapters/opensearch.cjs.map +1 -0
  34. package/dist/adapters/opensearch.d.cts +2 -0
  35. package/dist/adapters/opensearch.d.ts +2 -0
  36. package/dist/adapters/opensearch.js +93 -0
  37. package/dist/adapters/opensearch.js.map +1 -0
  38. package/dist/adapters/postgres.cjs +271 -0
  39. package/dist/adapters/postgres.cjs.map +1 -0
  40. package/dist/adapters/postgres.d.cts +81 -0
  41. package/dist/adapters/postgres.d.ts +81 -0
  42. package/dist/adapters/postgres.js +244 -0
  43. package/dist/adapters/postgres.js.map +1 -0
  44. package/dist/adapters/redis.cjs +153 -0
  45. package/dist/adapters/redis.cjs.map +1 -0
  46. package/dist/adapters/redis.d.cts +40 -0
  47. package/dist/adapters/redis.d.ts +40 -0
  48. package/dist/adapters/redis.js +126 -0
  49. package/dist/adapters/redis.js.map +1 -0
  50. package/dist/adapters/snowflake.cjs +117 -0
  51. package/dist/adapters/snowflake.cjs.map +1 -0
  52. package/dist/adapters/snowflake.d.cts +37 -0
  53. package/dist/adapters/snowflake.d.ts +37 -0
  54. package/dist/adapters/snowflake.js +90 -0
  55. package/dist/adapters/snowflake.js.map +1 -0
  56. package/dist/client/index.cjs +484 -0
  57. package/dist/client/index.cjs.map +1 -0
  58. package/dist/client/index.d.cts +174 -0
  59. package/dist/client/index.d.ts +174 -0
  60. package/dist/client/index.js +455 -0
  61. package/dist/client/index.js.map +1 -0
  62. package/dist/index.cjs +935 -0
  63. package/dist/index.cjs.map +1 -0
  64. package/dist/index.d.cts +190 -0
  65. package/dist/index.d.ts +190 -0
  66. package/dist/index.js +890 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/types-tPDla8AE.d.cts +75 -0
  69. package/dist/types-tPDla8AE.d.ts +75 -0
  70. package/package.json +157 -0
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Options passed to `createClient`.
3
+ */
4
+ interface ClientOptions {
5
+ /**
6
+ * Base URL of the RouteFlow server (e.g. 'http://localhost:3000').
7
+ * Trailing slash is trimmed automatically.
8
+ */
9
+ baseUrl: string;
10
+ /**
11
+ * Default headers added to every HTTP request.
12
+ */
13
+ headers?: Record<string, string>;
14
+ /**
15
+ * Real-time transport mechanism.
16
+ * - `'websocket'` (default) — uses WebSocket; full-duplex, supported everywhere.
17
+ * - `'sse'` — uses Server-Sent Events; simpler, works over plain HTTP/1.1.
18
+ */
19
+ transport?: 'websocket' | 'sse';
20
+ /**
21
+ * Reconnect / backoff settings for the real-time transport.
22
+ */
23
+ reconnect?: ReconnectOptions;
24
+ /**
25
+ * Global error handler called when the server sends an error message
26
+ * over the real-time channel, or when a subscription callback throws.
27
+ */
28
+ onError?: (error: {
29
+ code: string;
30
+ message: string;
31
+ }) => void;
32
+ }
33
+ /**
34
+ * Exponential-backoff reconnect configuration.
35
+ */
36
+ interface ReconnectOptions {
37
+ /** Maximum number of reconnect attempts. 0 = unlimited. Default: 0 */
38
+ maxAttempts?: number;
39
+ /** Initial delay in ms before first retry. Default: 500 */
40
+ initialDelayMs?: number;
41
+ /** Multiplier applied to the delay on each failure. Default: 2 */
42
+ backoffFactor?: number;
43
+ /** Maximum delay cap in ms. Default: 30_000 */
44
+ maxDelayMs?: number;
45
+ }
46
+ /**
47
+ * Options passed to `subscribe()`.
48
+ */
49
+ interface SubscribeOptions<T> {
50
+ /** Query string params forwarded with the subscription request. */
51
+ query?: Record<string, string>;
52
+ /** Called when the server sends an error for this subscription. */
53
+ onError?: (error: {
54
+ code: string;
55
+ message: string;
56
+ }) => void;
57
+ /** Called when the underlying connection closes unexpectedly. */
58
+ onClose?: () => void;
59
+ /** Called on each data update. Alias for the callback positional arg. */
60
+ onData?: SubscriptionCallback<T>;
61
+ }
62
+ /**
63
+ * Callback invoked when new data is pushed for a subscribed path.
64
+ */
65
+ type SubscriptionCallback<T> = (data: T) => void;
66
+ /**
67
+ * Call this function to cancel a subscription.
68
+ */
69
+ type Unsubscribe = () => void;
70
+
71
+ /**
72
+ * RouteFlow client.
73
+ *
74
+ * Provides:
75
+ * - HTTP helpers (`get`, `post`, `put`, `patch`, `del`) backed by the Fetch API
76
+ * - Real-time subscriptions (`subscribe`) via WebSocket or SSE
77
+ *
78
+ * Fully browser-compatible — no Node.js-specific APIs used.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const client = createClient('http://localhost:3000')
83
+ *
84
+ * // One-off REST request
85
+ * const orders = await client.get<Order[]>('/orders/123')
86
+ *
87
+ * // Real-time subscription
88
+ * const unsubscribe = client.subscribe<Order[]>('/orders/123/live', (data) => {
89
+ * console.log('updated:', data)
90
+ * })
91
+ *
92
+ * // Later…
93
+ * unsubscribe()
94
+ * client.destroy()
95
+ * ```
96
+ */
97
+ declare class ReactiveClient {
98
+ private readonly baseUrl;
99
+ private readonly defaultHeaders;
100
+ private socket;
101
+ /** path → ReactiveSSE instance (one per path for SSE) */
102
+ private readonly sseStreams;
103
+ private readonly options;
104
+ constructor(options: ClientOptions);
105
+ /**
106
+ * Perform a GET request.
107
+ * @param path - Path relative to baseUrl (e.g. '/orders/123')
108
+ * @param query - Optional query string parameters
109
+ * @param headers - Per-request header overrides
110
+ */
111
+ get<T>(path: string, query?: Record<string, string>, headers?: Record<string, string>): Promise<T>;
112
+ /** Perform a POST request. */
113
+ post<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
114
+ /** Perform a PUT request. */
115
+ put<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
116
+ /** Perform a PATCH request. */
117
+ patch<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
118
+ /**
119
+ * Perform a DELETE request.
120
+ * Named `del` because `delete` is a reserved keyword.
121
+ */
122
+ del<T>(path: string, headers?: Record<string, string>): Promise<T>;
123
+ /**
124
+ * Subscribe to real-time updates pushed by the server for `path`.
125
+ *
126
+ * Uses WebSocket or SSE depending on the `transport` option passed to `createClient`.
127
+ *
128
+ * @param path - The reactive endpoint path (e.g. '/orders/123/live')
129
+ * @param callback - Invoked with the latest data on each push
130
+ * @param query - Optional query params forwarded in the subscription request
131
+ * @returns An unsubscribe function — call it to stop receiving updates.
132
+ */
133
+ subscribe<T>(path: string, callback: SubscriptionCallback<T>, query?: Record<string, string>): Unsubscribe;
134
+ /**
135
+ * Close the real-time transport and release all resources.
136
+ * Call this when the client is no longer needed (e.g. component unmount).
137
+ */
138
+ destroy(): void;
139
+ private subscribeWS;
140
+ private subscribeSSE;
141
+ private request;
142
+ }
143
+ /**
144
+ * Create a new RouteFlow client instance.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * // WebSocket (default)
149
+ * const client = createClient('http://localhost:3000')
150
+ *
151
+ * // SSE transport
152
+ * const client = createClient('http://localhost:3000', { transport: 'sse' })
153
+ *
154
+ * // With auth header and custom error handler
155
+ * const client = createClient('http://localhost:3000', {
156
+ * headers: { Authorization: 'Bearer token' },
157
+ * onError: (err) => console.error('realtime error:', err),
158
+ * })
159
+ * ```
160
+ */
161
+ declare function createClient(baseUrl: string, options?: Omit<ClientOptions, 'baseUrl'>): ReactiveClient;
162
+
163
+ /**
164
+ * Error thrown by the RouteFlow client for HTTP or WebSocket failures.
165
+ */
166
+ declare class ReactiveClientError extends Error {
167
+ /** Machine-readable error code */
168
+ readonly code: string;
169
+ /** HTTP status code, if applicable */
170
+ readonly status?: number;
171
+ constructor(code: string, message: string, status?: number);
172
+ }
173
+
174
+ export { type ClientOptions, ReactiveClient, ReactiveClientError, type ReconnectOptions, type SubscribeOptions, type SubscriptionCallback, type Unsubscribe, createClient };
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Options passed to `createClient`.
3
+ */
4
+ interface ClientOptions {
5
+ /**
6
+ * Base URL of the RouteFlow server (e.g. 'http://localhost:3000').
7
+ * Trailing slash is trimmed automatically.
8
+ */
9
+ baseUrl: string;
10
+ /**
11
+ * Default headers added to every HTTP request.
12
+ */
13
+ headers?: Record<string, string>;
14
+ /**
15
+ * Real-time transport mechanism.
16
+ * - `'websocket'` (default) — uses WebSocket; full-duplex, supported everywhere.
17
+ * - `'sse'` — uses Server-Sent Events; simpler, works over plain HTTP/1.1.
18
+ */
19
+ transport?: 'websocket' | 'sse';
20
+ /**
21
+ * Reconnect / backoff settings for the real-time transport.
22
+ */
23
+ reconnect?: ReconnectOptions;
24
+ /**
25
+ * Global error handler called when the server sends an error message
26
+ * over the real-time channel, or when a subscription callback throws.
27
+ */
28
+ onError?: (error: {
29
+ code: string;
30
+ message: string;
31
+ }) => void;
32
+ }
33
+ /**
34
+ * Exponential-backoff reconnect configuration.
35
+ */
36
+ interface ReconnectOptions {
37
+ /** Maximum number of reconnect attempts. 0 = unlimited. Default: 0 */
38
+ maxAttempts?: number;
39
+ /** Initial delay in ms before first retry. Default: 500 */
40
+ initialDelayMs?: number;
41
+ /** Multiplier applied to the delay on each failure. Default: 2 */
42
+ backoffFactor?: number;
43
+ /** Maximum delay cap in ms. Default: 30_000 */
44
+ maxDelayMs?: number;
45
+ }
46
+ /**
47
+ * Options passed to `subscribe()`.
48
+ */
49
+ interface SubscribeOptions<T> {
50
+ /** Query string params forwarded with the subscription request. */
51
+ query?: Record<string, string>;
52
+ /** Called when the server sends an error for this subscription. */
53
+ onError?: (error: {
54
+ code: string;
55
+ message: string;
56
+ }) => void;
57
+ /** Called when the underlying connection closes unexpectedly. */
58
+ onClose?: () => void;
59
+ /** Called on each data update. Alias for the callback positional arg. */
60
+ onData?: SubscriptionCallback<T>;
61
+ }
62
+ /**
63
+ * Callback invoked when new data is pushed for a subscribed path.
64
+ */
65
+ type SubscriptionCallback<T> = (data: T) => void;
66
+ /**
67
+ * Call this function to cancel a subscription.
68
+ */
69
+ type Unsubscribe = () => void;
70
+
71
+ /**
72
+ * RouteFlow client.
73
+ *
74
+ * Provides:
75
+ * - HTTP helpers (`get`, `post`, `put`, `patch`, `del`) backed by the Fetch API
76
+ * - Real-time subscriptions (`subscribe`) via WebSocket or SSE
77
+ *
78
+ * Fully browser-compatible — no Node.js-specific APIs used.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const client = createClient('http://localhost:3000')
83
+ *
84
+ * // One-off REST request
85
+ * const orders = await client.get<Order[]>('/orders/123')
86
+ *
87
+ * // Real-time subscription
88
+ * const unsubscribe = client.subscribe<Order[]>('/orders/123/live', (data) => {
89
+ * console.log('updated:', data)
90
+ * })
91
+ *
92
+ * // Later…
93
+ * unsubscribe()
94
+ * client.destroy()
95
+ * ```
96
+ */
97
+ declare class ReactiveClient {
98
+ private readonly baseUrl;
99
+ private readonly defaultHeaders;
100
+ private socket;
101
+ /** path → ReactiveSSE instance (one per path for SSE) */
102
+ private readonly sseStreams;
103
+ private readonly options;
104
+ constructor(options: ClientOptions);
105
+ /**
106
+ * Perform a GET request.
107
+ * @param path - Path relative to baseUrl (e.g. '/orders/123')
108
+ * @param query - Optional query string parameters
109
+ * @param headers - Per-request header overrides
110
+ */
111
+ get<T>(path: string, query?: Record<string, string>, headers?: Record<string, string>): Promise<T>;
112
+ /** Perform a POST request. */
113
+ post<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
114
+ /** Perform a PUT request. */
115
+ put<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
116
+ /** Perform a PATCH request. */
117
+ patch<T>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
118
+ /**
119
+ * Perform a DELETE request.
120
+ * Named `del` because `delete` is a reserved keyword.
121
+ */
122
+ del<T>(path: string, headers?: Record<string, string>): Promise<T>;
123
+ /**
124
+ * Subscribe to real-time updates pushed by the server for `path`.
125
+ *
126
+ * Uses WebSocket or SSE depending on the `transport` option passed to `createClient`.
127
+ *
128
+ * @param path - The reactive endpoint path (e.g. '/orders/123/live')
129
+ * @param callback - Invoked with the latest data on each push
130
+ * @param query - Optional query params forwarded in the subscription request
131
+ * @returns An unsubscribe function — call it to stop receiving updates.
132
+ */
133
+ subscribe<T>(path: string, callback: SubscriptionCallback<T>, query?: Record<string, string>): Unsubscribe;
134
+ /**
135
+ * Close the real-time transport and release all resources.
136
+ * Call this when the client is no longer needed (e.g. component unmount).
137
+ */
138
+ destroy(): void;
139
+ private subscribeWS;
140
+ private subscribeSSE;
141
+ private request;
142
+ }
143
+ /**
144
+ * Create a new RouteFlow client instance.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * // WebSocket (default)
149
+ * const client = createClient('http://localhost:3000')
150
+ *
151
+ * // SSE transport
152
+ * const client = createClient('http://localhost:3000', { transport: 'sse' })
153
+ *
154
+ * // With auth header and custom error handler
155
+ * const client = createClient('http://localhost:3000', {
156
+ * headers: { Authorization: 'Bearer token' },
157
+ * onError: (err) => console.error('realtime error:', err),
158
+ * })
159
+ * ```
160
+ */
161
+ declare function createClient(baseUrl: string, options?: Omit<ClientOptions, 'baseUrl'>): ReactiveClient;
162
+
163
+ /**
164
+ * Error thrown by the RouteFlow client for HTTP or WebSocket failures.
165
+ */
166
+ declare class ReactiveClientError extends Error {
167
+ /** Machine-readable error code */
168
+ readonly code: string;
169
+ /** HTTP status code, if applicable */
170
+ readonly status?: number;
171
+ constructor(code: string, message: string, status?: number);
172
+ }
173
+
174
+ export { type ClientOptions, ReactiveClient, ReactiveClientError, type ReconnectOptions, type SubscribeOptions, type SubscriptionCallback, type Unsubscribe, createClient };