@furlow/pipes 0.1.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.
@@ -0,0 +1,3 @@
1
+ declare const createDatabasePipe: () => never;
2
+
3
+ export { createDatabasePipe };
@@ -0,0 +1,8 @@
1
+ // src/database/index.ts
2
+ var createDatabasePipe = () => {
3
+ throw new Error("Not implemented");
4
+ };
5
+ export {
6
+ createDatabasePipe
7
+ };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/database/index.ts"],"sourcesContent":["// External database pipe - placeholder\nexport const createDatabasePipe = () => { throw new Error('Not implemented'); };\n"],"mappings":";AACO,IAAM,qBAAqB,MAAM;AAAE,QAAM,IAAI,MAAM,iBAAiB;AAAG;","names":[]}
@@ -0,0 +1,3 @@
1
+ declare const createFilePipe: () => never;
2
+
3
+ export { createFilePipe };
@@ -0,0 +1,8 @@
1
+ // src/file/index.ts
2
+ var createFilePipe = () => {
3
+ throw new Error("Not implemented");
4
+ };
5
+ export {
6
+ createFilePipe
7
+ };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/file/index.ts"],"sourcesContent":["// File watcher pipe - placeholder\nexport const createFilePipe = () => { throw new Error('Not implemented'); };\n"],"mappings":";AACO,IAAM,iBAAiB,MAAM;AAAE,QAAM,IAAI,MAAM,iBAAiB;AAAG;","names":[]}
@@ -0,0 +1,61 @@
1
+ import { P as Pipe, b as HttpPipeConfig, f as PipeResponse } from '../types-BW9r2ksN.js';
2
+
3
+ /**
4
+ * HTTP pipe for REST API integrations
5
+ */
6
+
7
+ interface HttpPipeOptions {
8
+ name: string;
9
+ config: HttpPipeConfig;
10
+ }
11
+ declare class HttpPipe implements Pipe {
12
+ readonly name: string;
13
+ readonly type = "http";
14
+ private client;
15
+ private config;
16
+ private requestCount;
17
+ private windowStart;
18
+ constructor(options: HttpPipeOptions);
19
+ isConnected(): boolean;
20
+ /**
21
+ * Make an HTTP request
22
+ */
23
+ request<T = unknown>(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, options?: {
24
+ body?: Record<string, unknown>;
25
+ headers?: Record<string, string>;
26
+ params?: Record<string, string>;
27
+ }): Promise<PipeResponse<T>>;
28
+ /**
29
+ * Make a request with retry logic
30
+ */
31
+ private requestWithRetry;
32
+ /**
33
+ * Convenience methods
34
+ */
35
+ get<T = unknown>(path: string, options?: {
36
+ headers?: Record<string, string>;
37
+ params?: Record<string, string>;
38
+ }): Promise<PipeResponse<T>>;
39
+ post<T = unknown>(path: string, body?: Record<string, unknown>, options?: {
40
+ headers?: Record<string, string>;
41
+ }): Promise<PipeResponse<T>>;
42
+ put<T = unknown>(path: string, body?: Record<string, unknown>, options?: {
43
+ headers?: Record<string, string>;
44
+ }): Promise<PipeResponse<T>>;
45
+ patch<T = unknown>(path: string, body?: Record<string, unknown>, options?: {
46
+ headers?: Record<string, string>;
47
+ }): Promise<PipeResponse<T>>;
48
+ delete<T = unknown>(path: string, options?: {
49
+ headers?: Record<string, string>;
50
+ }): Promise<PipeResponse<T>>;
51
+ /**
52
+ * Parse duration string to milliseconds
53
+ */
54
+ private parseDuration;
55
+ }
56
+ /**
57
+ * Create an HTTP pipe
58
+ */
59
+ declare function createHttpPipe(options: HttpPipeOptions): HttpPipe;
60
+
61
+ export { HttpPipe, type HttpPipeOptions, createHttpPipe };
@@ -0,0 +1,156 @@
1
+ // src/http/index.ts
2
+ import axios from "axios";
3
+ var HttpPipe = class {
4
+ name;
5
+ type = "http";
6
+ client;
7
+ config;
8
+ requestCount = 0;
9
+ windowStart = Date.now();
10
+ constructor(options) {
11
+ this.name = options.name;
12
+ this.config = options.config;
13
+ this.client = axios.create({
14
+ baseURL: options.config.base_url,
15
+ timeout: this.parseDuration(options.config.timeout ?? "30s"),
16
+ headers: options.config.headers
17
+ });
18
+ if (options.config.auth) {
19
+ this.client.interceptors.request.use((config) => {
20
+ const auth = options.config.auth;
21
+ switch (auth.type) {
22
+ case "bearer":
23
+ config.headers.Authorization = `Bearer ${auth.token}`;
24
+ break;
25
+ case "basic":
26
+ const credentials = Buffer.from(`${auth.username}:${auth.password}`).toString("base64");
27
+ config.headers.Authorization = `Basic ${credentials}`;
28
+ break;
29
+ case "header":
30
+ const headerName = auth.header_name ?? "Authorization";
31
+ config.headers[headerName] = auth.token;
32
+ break;
33
+ }
34
+ return config;
35
+ });
36
+ }
37
+ }
38
+ isConnected() {
39
+ return true;
40
+ }
41
+ /**
42
+ * Make an HTTP request
43
+ */
44
+ async request(method, path, options = {}) {
45
+ if (this.config.rate_limit) {
46
+ const now = Date.now();
47
+ const windowMs = this.parseDuration(this.config.rate_limit.per);
48
+ if (now - this.windowStart >= windowMs) {
49
+ this.requestCount = 0;
50
+ this.windowStart = now;
51
+ }
52
+ if (this.requestCount >= this.config.rate_limit.requests) {
53
+ return {
54
+ success: false,
55
+ error: "Rate limit exceeded",
56
+ status: 429
57
+ };
58
+ }
59
+ this.requestCount++;
60
+ }
61
+ const config = {
62
+ method,
63
+ url: path,
64
+ data: options.body,
65
+ headers: options.headers,
66
+ params: options.params
67
+ };
68
+ try {
69
+ const response = await this.requestWithRetry(config);
70
+ return {
71
+ success: true,
72
+ data: response.data,
73
+ status: response.status,
74
+ headers: response.headers
75
+ };
76
+ } catch (error) {
77
+ if (axios.isAxiosError(error)) {
78
+ return {
79
+ success: false,
80
+ error: error.message,
81
+ status: error.response?.status,
82
+ data: error.response?.data
83
+ };
84
+ }
85
+ return {
86
+ success: false,
87
+ error: error instanceof Error ? error.message : "Unknown error"
88
+ };
89
+ }
90
+ }
91
+ /**
92
+ * Make a request with retry logic
93
+ */
94
+ async requestWithRetry(config, attempt = 0) {
95
+ try {
96
+ return await this.client.request(config);
97
+ } catch (error) {
98
+ const maxAttempts = this.config.retry?.attempts ?? 0;
99
+ const delay = this.parseDuration(this.config.retry?.delay ?? "1s");
100
+ if (attempt < maxAttempts && axios.isAxiosError(error)) {
101
+ if (!error.response || error.response.status >= 500) {
102
+ await new Promise((resolve) => setTimeout(resolve, delay));
103
+ return this.requestWithRetry(config, attempt + 1);
104
+ }
105
+ }
106
+ throw error;
107
+ }
108
+ }
109
+ /**
110
+ * Convenience methods
111
+ */
112
+ async get(path, options) {
113
+ return this.request("GET", path, options);
114
+ }
115
+ async post(path, body, options) {
116
+ return this.request("POST", path, { body, ...options });
117
+ }
118
+ async put(path, body, options) {
119
+ return this.request("PUT", path, { body, ...options });
120
+ }
121
+ async patch(path, body, options) {
122
+ return this.request("PATCH", path, { body, ...options });
123
+ }
124
+ async delete(path, options) {
125
+ return this.request("DELETE", path, options);
126
+ }
127
+ /**
128
+ * Parse duration string to milliseconds
129
+ */
130
+ parseDuration(duration) {
131
+ const match = duration.match(/^(\d+)(ms|s|m|h)?$/);
132
+ if (!match) return 3e4;
133
+ const value = parseInt(match[1], 10);
134
+ const unit = match[2] ?? "s";
135
+ switch (unit) {
136
+ case "ms":
137
+ return value;
138
+ case "s":
139
+ return value * 1e3;
140
+ case "m":
141
+ return value * 60 * 1e3;
142
+ case "h":
143
+ return value * 60 * 60 * 1e3;
144
+ default:
145
+ return value * 1e3;
146
+ }
147
+ }
148
+ };
149
+ function createHttpPipe(options) {
150
+ return new HttpPipe(options);
151
+ }
152
+ export {
153
+ HttpPipe,
154
+ createHttpPipe
155
+ };
156
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/http/index.ts"],"sourcesContent":["/**\n * HTTP pipe for REST API integrations\n */\n\nimport axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios';\nimport type { HttpPipeConfig, Pipe, PipeResponse } from '../types.js';\n\nexport interface HttpPipeOptions {\n name: string;\n config: HttpPipeConfig;\n}\n\nexport class HttpPipe implements Pipe {\n public readonly name: string;\n public readonly type = 'http';\n private client: AxiosInstance;\n private config: HttpPipeConfig;\n private requestCount = 0;\n private windowStart = Date.now();\n\n constructor(options: HttpPipeOptions) {\n this.name = options.name;\n this.config = options.config;\n\n this.client = axios.create({\n baseURL: options.config.base_url,\n timeout: this.parseDuration(options.config.timeout ?? '30s'),\n headers: options.config.headers as Record<string, string>,\n });\n\n // Add auth interceptor\n if (options.config.auth) {\n this.client.interceptors.request.use((config) => {\n const auth = options.config.auth!;\n switch (auth.type) {\n case 'bearer':\n config.headers.Authorization = `Bearer ${auth.token}`;\n break;\n case 'basic':\n const credentials = Buffer.from(`${auth.username}:${auth.password}`).toString('base64');\n config.headers.Authorization = `Basic ${credentials}`;\n break;\n case 'header':\n const headerName = auth.header_name ?? 'Authorization';\n config.headers[headerName] = auth.token as string;\n break;\n }\n return config;\n });\n }\n }\n\n isConnected(): boolean {\n return true; // HTTP is stateless\n }\n\n /**\n * Make an HTTP request\n */\n async request<T = unknown>(\n method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',\n path: string,\n options: {\n body?: Record<string, unknown>;\n headers?: Record<string, string>;\n params?: Record<string, string>;\n } = {}\n ): Promise<PipeResponse<T>> {\n // Check rate limit\n if (this.config.rate_limit) {\n const now = Date.now();\n const windowMs = this.parseDuration(this.config.rate_limit.per);\n\n if (now - this.windowStart >= windowMs) {\n this.requestCount = 0;\n this.windowStart = now;\n }\n\n if (this.requestCount >= this.config.rate_limit.requests) {\n return {\n success: false,\n error: 'Rate limit exceeded',\n status: 429,\n };\n }\n\n this.requestCount++;\n }\n\n const config: AxiosRequestConfig = {\n method,\n url: path,\n data: options.body,\n headers: options.headers,\n params: options.params,\n };\n\n try {\n const response = await this.requestWithRetry(config);\n\n return {\n success: true,\n data: response.data as T,\n status: response.status,\n headers: response.headers as Record<string, string>,\n };\n } catch (error) {\n if (axios.isAxiosError(error)) {\n return {\n success: false,\n error: error.message,\n status: error.response?.status,\n data: error.response?.data as T,\n };\n }\n\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n\n /**\n * Make a request with retry logic\n */\n private async requestWithRetry(\n config: AxiosRequestConfig,\n attempt = 0\n ): Promise<any> {\n try {\n return await this.client.request(config);\n } catch (error) {\n const maxAttempts = this.config.retry?.attempts ?? 0;\n const delay = this.parseDuration(this.config.retry?.delay ?? '1s');\n\n if (attempt < maxAttempts && axios.isAxiosError(error)) {\n // Retry on 5xx errors or network errors\n if (!error.response || error.response.status >= 500) {\n await new Promise((resolve) => setTimeout(resolve, delay));\n return this.requestWithRetry(config, attempt + 1);\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Convenience methods\n */\n async get<T = unknown>(\n path: string,\n options?: { headers?: Record<string, string>; params?: Record<string, string> }\n ): Promise<PipeResponse<T>> {\n return this.request<T>('GET', path, options);\n }\n\n async post<T = unknown>(\n path: string,\n body?: Record<string, unknown>,\n options?: { headers?: Record<string, string> }\n ): Promise<PipeResponse<T>> {\n return this.request<T>('POST', path, { body, ...options });\n }\n\n async put<T = unknown>(\n path: string,\n body?: Record<string, unknown>,\n options?: { headers?: Record<string, string> }\n ): Promise<PipeResponse<T>> {\n return this.request<T>('PUT', path, { body, ...options });\n }\n\n async patch<T = unknown>(\n path: string,\n body?: Record<string, unknown>,\n options?: { headers?: Record<string, string> }\n ): Promise<PipeResponse<T>> {\n return this.request<T>('PATCH', path, { body, ...options });\n }\n\n async delete<T = unknown>(\n path: string,\n options?: { headers?: Record<string, string> }\n ): Promise<PipeResponse<T>> {\n return this.request<T>('DELETE', path, options);\n }\n\n /**\n * Parse duration string to milliseconds\n */\n private parseDuration(duration: string): number {\n const match = duration.match(/^(\\d+)(ms|s|m|h)?$/);\n if (!match) return 30000;\n\n const value = parseInt(match[1]!, 10);\n const unit = match[2] ?? 's';\n\n switch (unit) {\n case 'ms':\n return value;\n case 's':\n return value * 1000;\n case 'm':\n return value * 60 * 1000;\n case 'h':\n return value * 60 * 60 * 1000;\n default:\n return value * 1000;\n }\n }\n}\n\n/**\n * Create an HTTP pipe\n */\nexport function createHttpPipe(options: HttpPipeOptions): HttpPipe {\n return new HttpPipe(options);\n}\n"],"mappings":";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EA,YAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,IACJ,MACA,SAC0B;AAC1B,WAAO,KAAK,QAAW,OAAO,MAAM,OAAO;AAAA,EAC7C;AAAA,EAEA,MAAM,KACJ,MACA,MACA,SAC0B;AAC1B,WAAO,KAAK,QAAW,QAAQ,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3D;AAAA,EAEA,MAAM,IACJ,MACA,MACA,SAC0B;AAC1B,WAAO,KAAK,QAAW,OAAO,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC1D;AAAA,EAEA,MAAM,MACJ,MACA,MACA,SAC0B;AAC1B,WAAO,KAAK,QAAW,SAAS,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5D;AAAA,EAEA,MAAM,OACJ,MACA,SAC0B;AAC1B,WAAO,KAAK,QAAW,UAAU,MAAM,OAAO;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKQ,cAAc,UAA0B;AAC9C,UAAM,QAAQ,SAAS,MAAM,oBAAoB;AACjD,QAAI,CAAC,MAAO,QAAO;AAEnB,UAAM,QAAQ,SAAS,MAAM,CAAC,GAAI,EAAE;AACpC,UAAM,OAAO,MAAM,CAAC,KAAK;AAEzB,YAAQ,MAAM;AAAA,MACZ,KAAK;AACH,eAAO;AAAA,MACT,KAAK;AACH,eAAO,QAAQ;AAAA,MACjB,KAAK;AACH,eAAO,QAAQ,KAAK;AAAA,MACtB,KAAK;AACH,eAAO,QAAQ,KAAK,KAAK;AAAA,MAC3B;AACE,eAAO,QAAQ;AAAA,IACnB;AAAA,EACF;AACF;AAKO,SAAS,eAAe,SAAoC;AACjE,SAAO,IAAI,SAAS,OAAO;AAC7B;","names":[]}
@@ -0,0 +1,7 @@
1
+ export { HttpPipe, HttpPipeOptions, createHttpPipe } from './http/index.js';
2
+ export { WebSocketMessageHandler, WebSocketPipe, WebSocketPipeOptions, createWebSocketPipe } from './websocket/index.js';
3
+ export { WebhookHandler, WebhookPipe, WebhookPipeOptions, WebhookSender, createWebhookPipe } from './webhook/index.js';
4
+ export { MqttMessageHandler, MqttPipe, MqttPipeOptions, createMqttPipe } from './mqtt/index.js';
5
+ export { TcpDataHandler, TcpEventHandler, TcpPipe, TcpPipeOptions, UdpEventHandler, UdpMessage, UdpMessageHandler, UdpPipe, UdpPipeOptions, createTcpPipe, createUdpPipe } from './tcp/index.js';
6
+ export { H as HttpAuthConfig, a as HttpAuthType, b as HttpPipeConfig, c as HttpRateLimitConfig, M as MqttAuthConfig, d as MqttPipeConfig, e as MqttQoS, P as Pipe, f as PipeResponse, T as TcpPipeConfig, U as UdpPipeConfig, W as WebSocketPipeConfig, g as WebhookPipeConfig, h as WebhookVerification } from './types-BW9r2ksN.js';
7
+ import 'dgram';