@tallpond/cli 0.0.3 → 0.0.4
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.
- package/README.md +2 -1
- package/cli.js +8 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,7 +72,8 @@ export default async (ctx: FunctionContext, args: { resourceId: string; move: un
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
The ctx surface is exactly `userId`, `resourceId`, `fn`, `invocationId`,
|
|
75
|
-
`db.query`/`db.batch` (raw `/v1/db` wire shape), and `gateway(path, body)`
|
|
75
|
+
`db.query`/`db.batch` (raw `/v1/db` wire shape), and `gateway(path, body?, opts?)`
|
|
76
|
+
(POST by default, `{ method: 'GET' }` for read routes) —
|
|
76
77
|
annotate with `FunctionContext` so the compiler enforces it. Full contract:
|
|
77
78
|
<https://tallpond.com/docs/functions/>.
|
|
78
79
|
|
package/cli.js
CHANGED
|
@@ -382,11 +382,15 @@ function decodeInvocation(token) {
|
|
|
382
382
|
function makeCtx(env, token) {
|
|
383
383
|
const fetchImpl = env.TALLPOND_FETCH ?? fetch
|
|
384
384
|
const base = String(env.TALLPOND_GATEWAY_URL ?? '').replace(/\\/$/, '')
|
|
385
|
-
async function call(path, body) {
|
|
385
|
+
async function call(path, body, opts) {
|
|
386
|
+
const method = (opts && opts.method) || 'POST'
|
|
387
|
+
const bodyless = method === 'GET' || method === 'HEAD'
|
|
388
|
+
const headers = { authorization: 'Bearer ' + token }
|
|
389
|
+
if (!bodyless) headers['content-type'] = 'application/json'
|
|
386
390
|
const res = await fetchImpl(base + path, {
|
|
387
|
-
method
|
|
388
|
-
headers
|
|
389
|
-
body: JSON.stringify(body),
|
|
391
|
+
method,
|
|
392
|
+
headers,
|
|
393
|
+
body: bodyless ? undefined : JSON.stringify(body),
|
|
390
394
|
})
|
|
391
395
|
const data = await res.json().catch(() => null)
|
|
392
396
|
if (!res.ok) {
|