Skip to content

Commit bdf8df8

Browse files
committed
we have a client!
1 parent a337973 commit bdf8df8

10 files changed

Lines changed: 146 additions & 20 deletions

File tree

‎src/apps/link-finder/config.ttl‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
# ns.trn.sourceFile
99

1010
:origin a :ConfigSet ;
11-
:sourceFile "workflowy_2025-09-21.md" .
11+
:sourceFile "test.md" .
12+
# :targetField "links" .
1213

13-
:exampleSettings2 a :ConfigSet ;
14-
:me "exampleSettings2" ;
15-
:common "common from 2" ;
16-
:something2 "something2 from config" ;
17-
:added " added from exampleSettings2" .
14+
:listField a :ConfigSet ;
15+
:forEach "links" .

‎src/apps/link-finder/data/test.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Kilohearts - Tape Stop](https://kilohearts.com/products/tape_stop) is a link, so is [Tensegrity](https://tensegrity.it)

‎src/apps/link-finder/transmissions.ttl‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
##################################################################
1818

1919
:linkFinder a :Transmission ;
20-
:pipe (:p10 :p20 :p30) .
20+
:pipe (:p10 :p20 :p30 :SM ) .
2121

2222
:p10 a :FileReader ;
2323
:settings :origin .
2424

2525
:p20 a :MarkdownToLinks ;
26-
:settings :exampleSettings2 .
26+
:settings :linksField .
2727

28-
:p30 a :ShowMessage .
28+
:p30 a :ForEach ;
29+
:settings :listField .

‎src/apps/test/http-client/about.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
`src/apps/example-application/about.md`
2+
3+
# Example Application `about.md`
4+
5+
## Runner
6+
7+
```sh
8+
cd ~/hyperdata/transmissions # my local path
9+
./trans example-application
10+
```
11+
12+
## Description
13+
14+
---
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
3+
4+
@prefix : <http://purl.org/stuff/transmissions/> .
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# src/apps/example-application/config.ttl
2+
3+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
4+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
5+
6+
@prefix : <http://purl.org/stuff/transmissions/> . # for custom terms & instances
7+
8+
:exampleSettings1 a :ConfigSet ;
9+
:me "exampleSettings1" ;
10+
:common "common from 1" ;
11+
:something1 "something1 from config" .
12+
13+
:exampleSettings2 a :ConfigSet ;
14+
:me "exampleSettings2" ;
15+
:common "common from 2" ;
16+
:something2 "something2 from config" ;
17+
:added " added from exampleSettings2" .
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# src/apps/example-application/transmissions.ttl
2+
3+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
4+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
5+
6+
@prefix : <http://purl.org/stuff/transmissions/> .
7+
8+
##################################################################
9+
# Utility Processors : insert into pipe for debugging #
10+
# #
11+
:SM a :ShowMessage . # verbose report, continues pipe #
12+
:SC a :ShowConfig . # verbose report, continues pipe #
13+
:DE a :DeadEnd . # ends the current pipe quietly #
14+
:H a :Halt . # kills everything #
15+
:N a :NOP . # no operation (except for showing stage in pipe) #
16+
:UF a :Unfork . # collapses all pipes but one #
17+
##################################################################
18+
19+
:example a :Transmission ;
20+
:pipe (:p10 :SM) .
21+
22+
:p10 a :HttpClient ;
23+
:url "https://example.org/" .

‎src/processors/flow/ForEach.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ForEach extends SlowableProcessor {
9999

100100
let limit = 0
101101
const limitString = super.getProperty(ns.trn.limit, null)
102-
logger.log(` ForEach limitString = ${limitString}`)
102+
// logger.log(` ForEach limitString = ${limitString}`)
103103
if (limitString) {
104104
limit = parseInt(limitString)
105105
logger.debug(` ForEach limit = ${limit}`)
@@ -121,9 +121,9 @@ class ForEach extends SlowableProcessor {
121121
}
122122
clonedMessage.currentItem = item
123123
// delete clonedMessage.foreach // Remove the original array to prevent infinite loops TODO needed?
124-
clonedMessage.foreach = null
124+
clonedMessage.foreach = undefined
125125

126-
logger.log(`ForEach: Emitting message for item: ${item}`)
126+
logger.log(`ForEach: Emitting message for item: ${JSON.stringify(item)}`)
127127
clonedMessage.eachCounter = this.eachCounter++
128128
this.emit('message', clonedMessage)
129129
}

‎src/processors/http/HttpClient.js‎

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logger from '../../utils/Logger.js' // path will likely change
44
import Processor from '../../model/Processor.js' // maybe more specific
5+
import fetch from 'node-fetch'
56

67
/**
78
* @class HttpClient
@@ -14,10 +15,10 @@ import Processor from '../../model/Processor.js' // maybe more specific
1415
* ### Service Signature
1516
*
1617
* #### __*Settings*__
17-
* * **`ns.trm.url`** - The URL to send the HTTP request to
18-
* * **`ns.trm.method`** - HTTP method (GET, POST, etc.)
19-
* * **`ns.trm.headers`** (optional) - HTTP headers as an object
20-
* * **`ns.trm.body`** (optional) - Request body for POST/PUT
18+
* * **`ns.trn.url`** - The URL to send the HTTP request to
19+
* * **`ns.trn.method`** - HTTP method (GET, POST, etc.)
20+
* * **`ns.trn.headers`** (optional) - HTTP headers as an object
21+
* * **`ns.trn.body`** (optional) - Request body for POST/PUT
2122
*
2223
* #### __*Input*__
2324
* * **`message.url`** (if no `configKey`) - The URL to request
@@ -55,14 +56,79 @@ class HttpClient extends Processor {
5556
}
5657

5758
/**
58-
* Does something with the message and emits a 'message' event with the processed message.
59+
* Sends an HTTP request and emits a 'message' event with the processed message.
5960
* @param {Object} message - The message object.
6061
*/
6162
async process(message) {
62-
// logger.setLogLevel('debug')
63+
try {
64+
const requestOptions = this._buildRequestOptions(message)
65+
logger.debug(`HttpClient: Sending request to ${requestOptions.url} with options: ${JSON.stringify(requestOptions)}`)
6366

64-
// processing goes here
65-
return this.emit('message', message)
67+
const response = await this._sendRequest(requestOptions)
68+
const processedResponse = await this._processResponse(response)
69+
70+
message.http = processedResponse
71+
logger.debug(`HttpClient: Received response with status ${response.status}`)
72+
73+
this.emit('message', message)
74+
} catch (err) {
75+
logger.error(`HttpClient: Error during HTTP request - ${err.message}`)
76+
message.httpError = err.message
77+
this.emit('message', message)
78+
}
79+
}
80+
81+
/**
82+
* Builds the HTTP request options from config and message.
83+
* @param {Object} message
84+
* @returns {Object} requestOptions
85+
*/
86+
_buildRequestOptions(message) {
87+
const url = super.getProperty('ns.trn.url', "https://example.org/")
88+
const method = super.getProperty('ns.trn.method', 'GET').toUpperCase()
89+
const headers = super.getProperty('ns.trn.headers', {})
90+
const body = super.getProperty('ns.trn.body', null)
91+
92+
const options = { method, headers }
93+
if (body && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
94+
options.body = typeof body === 'string' ? body : JSON.stringify(body)
95+
if (!headers['Content-Type']) {
96+
options.headers['Content-Type'] = 'application/json'
97+
}
98+
}
99+
100+
return { url, ...options }
101+
}
102+
103+
/**
104+
* Sends the HTTP request using fetch.
105+
* @param {Object} requestOptions
106+
* @returns {Promise<Response>}
107+
*/
108+
async _sendRequest(requestOptions) {
109+
const { url, ...options } = requestOptions
110+
return fetch(url, options)
111+
}
112+
113+
/**
114+
* Processes the HTTP response.
115+
* @param {Response} response
116+
* @returns {Promise<Object>} Processed response data
117+
*/
118+
async _processResponse(response) {
119+
const contentType = response.headers.get('content-type') || ''
120+
let data
121+
if (contentType.includes('application/json')) {
122+
data = await response.json()
123+
} else {
124+
data = await response.text()
125+
}
126+
return {
127+
status: response.status,
128+
statusText: response.statusText,
129+
headers: Object.fromEntries(response.headers.entries()),
130+
data
131+
}
66132
}
67133
}
68134

‎src/processors/markup/MarkdownToLinks.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class MarkdownToLinks extends Processor {
7272
// or simply return
7373
}
7474

75+
const linksField = this.getProperty(ns.trn.linksField, 'links')
76+
7577
message.links = await this.markdownToLinks(message.content)
7678

7779
return this.emit('message', message)

0 commit comments

Comments
 (0)