Refactor executable library handbooks and improve document reading
This commit is contained in:
1 parent
16c44588d5
commit
c50c515c4a
191 files changed
+29572
-7816
No files matched your search
+26
-9
@@ -7,20 +7,37 @@ import:
|
||||
sys: lib/sys.mq.md
|
||||
---
|
||||
|
||||
This file constructs the application Result record only; it does not implement an HTTP transport. For real HTTP requests, response limits and downloads, import lib/net.mq.md. The [network entry](index.mq.md) distinguishes pure URL transformations from native WebSocket exchanges. Keep these responsibilities explicit when extending the package so a readable tool name never implies a missing capability.
|
||||
|
||||
## _load
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | No business value on completion; a missing native plugin reports the cause and exits this run. |
|
||||
|
||||
Resolve and load the native web plugin before resource operations; missing binaries stop this run.
|
||||
|
||||
We retain **`p` = [Locate the installed native plugin](plugin.native_path(name="web"))**.
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
We **[Load the native plugin required by this operation](plugin.load(path=`p`))**.
|
||||
2. *
|
||||
> print text=ext/net: native web plugin not found
|
||||
> sys.exit code=1
|
||||
****
|
||||
We **[Print the prepared message](print(text="ext/net: native web plugin not found"))**.
|
||||
We **[End this run with the selected exit status](sys.exit(code=1))**.
|
||||
Return *None*.
|
||||
|
||||
## result
|
||||
+ `ok`
|
||||
+ `value`=None
|
||||
+ `error`=None
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| ok | any | required | Whether this application-level operation succeeded |
|
||||
| value | any | None | Value supplied to this operation; immutable transformations return a new value |
|
||||
| error | any | None | Structured failure information supplied by the caller |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Unified Result map `{ok, value, error}`. |
|
||||
|
||||
Use `ok`, `value`=None, `error`=None as the inputs for this operation.
|
||||
|
||||
Unified Result map `{ok, value, error}`.
|
||||
|
||||
@@ -30,4 +47,4 @@ Unified Result map `{ok, value, error}`.
|
||||
|----|-------|-------|
|
||||
| `ok` | `value` | `error` |
|
||||
|
||||
*out*
|
||||
Return *out*.
|
||||
@@ -0,0 +1,62 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Network resources — URL data and WebSocket exchanges
|
||||
import:
|
||||
url_api: ext/net/url.mq.md
|
||||
socket_api: ext/net/websocket.mq.md
|
||||
---
|
||||
|
||||
This package provides [URL encoding](url.mq.md), the small [HTTP result constructor](http.mq.md),
|
||||
and a native [WebSocket request/response resource](websocket.mq.md). For HTTP clients with
|
||||
status, timeout, response limits and downloads, read the standard library net.mq.md directly.
|
||||
The HTTP leaf here constructs a result record; its name does not imply an implemented HTTP client.
|
||||
|
||||
URL encoding is pure and needs no plugin. This command is ready to run from the repository root:
|
||||
|
||||
```sh
|
||||
marqdo call ext/net/index.mq.md encode 'text="Marqdo notes/one"' --json
|
||||
```
|
||||
|
||||
WebSocket exchanges need the native web plugin and an explicitly chosen server. Build the plugin
|
||||
with scripts/build-web-plugin.sh, then supply a controlled endpoint to exchange. No example opens
|
||||
a public socket implicitly. The resource closes after one bounded exchange; it is not a persistent
|
||||
subscription API. Read the returned ok/error as well as the reply data before using the outcome.
|
||||
|
||||
Develop URL transformations by composing the public standard library; native transport belongs in
|
||||
the web plugin. Preserve timeout units, byte/reply caps and close behavior. Add controlled local
|
||||
server tests for transport failures and timeouts instead of treating an empty reply as success.
|
||||
|
||||
## encode
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| text | text | required | Text component to percent-encode; this does not fetch a URL |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | text | Encoded URL component returned by the public encoding helper |
|
||||
|
||||
The input `text` is content for an encoded component, not an already assembled URL to navigate.
|
||||
Keeping this transformation separate makes it possible to build request data without network
|
||||
permission. We return *[Percent-encode the selected component](url_api.encode(text=`text`))*
|
||||
so the caller can place it in the intended path or query according to its own URL structure.
|
||||
|
||||
## exchange
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| url | text | required | Explicit ws/wss endpoint controlled by the caller |
|
||||
| message | text | "" | Single outgoing text message |
|
||||
| timeout_sec | number | 30 | Positive exchange timeout in seconds |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Native exchange result; failures carry ok=false/error instead of an empty successful reply |
|
||||
|
||||
The caller supplies `url`, optionally `message`="" and `timeout_sec`=30. This tool performs a
|
||||
real exchange, so it needs plugin permission and an available endpoint. The native leaf caps
|
||||
replies and frame sizes and closes the connection before returning; it does not retry a send.
|
||||
|
||||
We create **socket = [Configure a bounded WebSocket receiver](socket_api.ws(timeout_sec=`timeout_sec`))**,
|
||||
then return *[Send the message and collect the bounded reply](> `socket`.connect url=`url` message=`message` )*.
|
||||
Inspect the actual result before deciding whether a follow-up request is appropriate.
|
||||
+16
-3
@@ -6,7 +6,20 @@ import:
|
||||
net: lib/net.mq.md
|
||||
---
|
||||
|
||||
## encode
|
||||
+ `text`
|
||||
Use this leaf to encode data for a URL component, not to fetch or validate a remote service. The [network entry](index.mq.md) provides a directly runnable encoding example. Whole URLs, path components and query values have different escaping responsibilities; pass the intended component and let the caller assemble the final URL. Prefer composing lib/url.mq.md when adding pure transformations.
|
||||
|
||||
*> net.url_encode text=`text`*
|
||||
## encode
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| text | any | required | Text supplied to the transformation or adapter |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Percent-encode the supplied text using the public standard library URL helper. |
|
||||
|
||||
Use `text` as the inputs for this operation.
|
||||
|
||||
Percent-encode the supplied text using the public standard library URL helper.
|
||||
|
||||
Return *[Url encode](net.url_encode(text=`text`))*.
|
||||
+40
-13
@@ -8,36 +8,63 @@ import:
|
||||
table: lib/table.mq.md
|
||||
---
|
||||
|
||||
This resource performs one bounded native WebSocket exchange and closes it. The [network entry](index.mq.md) shows the input contract and the distinction from pure URL encoding. Configure a controlled ws/wss endpoint and inspect ok/error, timeout and reply data before acting. New transport behavior belongs in the web plugin, with local tests for failed connections and oversized replies; this resource is not a persistent subscription service.
|
||||
|
||||
## _load
|
||||
|
||||
**p = > plugin.native_path name="web"**
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | No business value on completion; a missing native plugin reports the cause and exits this run. |
|
||||
|
||||
Resolve and load the native web plugin before resource operations; missing binaries stop this run.
|
||||
|
||||
We retain **`p` = [Locate the installed native plugin](plugin.native_path(name="web"))**.
|
||||
1. `p`
|
||||
> plugin.load path=`p`
|
||||
We **[Load the native plugin required by this operation](plugin.load(path=`p`))**.
|
||||
2. *
|
||||
> print text=ext/net: native web plugin not found
|
||||
> sys.exit code=1
|
||||
****
|
||||
We **[Print the prepared message](print(text="ext/net: native web plugin not found"))**.
|
||||
We **[End this run with the selected exit status](sys.exit(code=1))**.
|
||||
Return *None*.
|
||||
|
||||
# ws
|
||||
+ `timeout_sec`=30
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| timeout_sec | any | 30 | Request/response timeout in seconds |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | WebSocket client helper. |
|
||||
|
||||
Use `timeout_sec`=30 as the inputs for this operation.
|
||||
|
||||
WebSocket client helper.
|
||||
|
||||
> _load
|
||||
We **[Load the native plugin required by this operation](_load())**.
|
||||
|
||||
`out` =
|
||||
|
||||
| timeout_sec | _type |
|
||||
|-------------|-------|
|
||||
| `timeout_sec` | ws |
|
||||
|
||||
*out*
|
||||
Return *out*.
|
||||
|
||||
## connect
|
||||
+ `url`
|
||||
+ `message`=""
|
||||
+ `headers`=None
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| url | any | required | Resource connection URL; scheme selects the documented backend |
|
||||
| message | any | "" | Outgoing WebSocket or application message |
|
||||
| headers | any | None | HTTP request header record or None |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Single request–response: connect to `url`, send `message`, collect up to 256 server text replies (each up to 1 MiB), close. Transport errors and timeouts return `{ok:false, error}` instead of looking like an empty successful reply. |
|
||||
|
||||
Use `url`, `message`="", `headers`=None as the inputs for this operation.
|
||||
|
||||
Single request–response: connect to `url`, send `message`, collect up to 256 server text replies (each up to 1 MiB), close. Transport errors and timeouts return `{ok:false, error}` instead of looking like an empty successful reply.
|
||||
|
||||
**timeout = [timeout_sec](access(self, "timeout_sec"))**
|
||||
*> web_ws_connect url=`url` message=`message` headers=`headers` timeout_sec=`timeout`*
|
||||
We retain **`timeout` = [Read timeout_sec field](access(`self`, "timeout_sec"))**.
|
||||
Return *[Single request–response: connect to url, send message, collect up to 256 server text replies (each up to 1 MiB), close](web_ws_connect(url=`url`, message=`message`, headers=`headers`, timeout_sec=`timeout`))*.
|
||||
Reference in new issue
Block a user