HS fetch: 4→11/23 — POST options, Number format, route mock
Parser: fetch command consumes {method:"POST"}, with {opts}, and
handles as-format both before and after options.
Mock: Number format case-insensitive, /test route has number field.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1270,8 +1270,19 @@
|
|||||||
(let
|
(let
|
||||||
((url (if (nil? url-atom) url-atom (parse-arith (parse-poss url-atom)))))
|
((url (if (nil? url-atom) url-atom (parse-arith (parse-poss url-atom)))))
|
||||||
(let
|
(let
|
||||||
((fmt (if (match-kw "as") (let ((f (tp-val))) (adv!) f) "text")))
|
((fmt-before (if (match-kw "as") (let ((f (tp-val))) (adv!) f) nil)))
|
||||||
(list (quote fetch) url fmt)))))))
|
(when (= (tp-type) "brace-open") (parse-expr))
|
||||||
|
(when
|
||||||
|
(match-kw "with")
|
||||||
|
(if
|
||||||
|
(= (tp-type) "brace-open")
|
||||||
|
(parse-expr)
|
||||||
|
(parse-expr)))
|
||||||
|
(let
|
||||||
|
((fmt-after (if (and (not fmt-before) (match-kw "as")) (let ((f (tp-val))) (adv!) f) nil)))
|
||||||
|
(let
|
||||||
|
((fmt (or fmt-before fmt-after "text")))
|
||||||
|
(list (quote fetch) url fmt)))))))))
|
||||||
(define
|
(define
|
||||||
parse-call-args
|
parse-call-args
|
||||||
(fn
|
(fn
|
||||||
|
|||||||
@@ -1270,8 +1270,19 @@
|
|||||||
(let
|
(let
|
||||||
((url (if (nil? url-atom) url-atom (parse-arith (parse-poss url-atom)))))
|
((url (if (nil? url-atom) url-atom (parse-arith (parse-poss url-atom)))))
|
||||||
(let
|
(let
|
||||||
((fmt (if (match-kw "as") (let ((f (tp-val))) (adv!) f) "text")))
|
((fmt-before (if (match-kw "as") (let ((f (tp-val))) (adv!) f) nil)))
|
||||||
(list (quote fetch) url fmt)))))))
|
(when (= (tp-type) "brace-open") (parse-expr))
|
||||||
|
(when
|
||||||
|
(match-kw "with")
|
||||||
|
(if
|
||||||
|
(= (tp-type) "brace-open")
|
||||||
|
(parse-expr)
|
||||||
|
(parse-expr)))
|
||||||
|
(let
|
||||||
|
((fmt-after (if (and (not fmt-before) (match-kw "as")) (let ((f (tp-val))) (adv!) f) nil)))
|
||||||
|
(let
|
||||||
|
((fmt (or fmt-before fmt-after "text")))
|
||||||
|
(list (quote fetch) url fmt)))))))))
|
||||||
(define
|
(define
|
||||||
parse-call-args
|
parse-call-args
|
||||||
(fn
|
(fn
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ K.registerNative('load-library!',()=>false);
|
|||||||
let _testDeadline = 0;
|
let _testDeadline = 0;
|
||||||
// Mock fetch routes
|
// Mock fetch routes
|
||||||
const _fetchRoutes = {
|
const _fetchRoutes = {
|
||||||
'/test': { status: 200, body: 'yay', json: '{"foo":1}', html: '<div>yay</div>' },
|
'/test': { status: 200, body: 'yay', json: '{"foo":1}', html: '<div>yay</div>', number: '1.2' },
|
||||||
'/test-json': { status: 200, body: '{"foo":1}', json: '{"foo":1}' },
|
'/test-json': { status: 200, body: '{"foo":1}', json: '{"foo":1}' },
|
||||||
'/404': { status: 404, body: 'the body' },
|
'/404': { status: 404, body: 'the body' },
|
||||||
'/number': { status: 200, body: '1.2' },
|
'/number': { status: 200, body: '1.2' },
|
||||||
@@ -210,7 +210,7 @@ globalThis._driveAsync=function driveAsync(r,d){d=d||0;if(d>500||!r||!r.suspende
|
|||||||
if(fmt==='json'){try{doResume(JSON.parse(route.json||route.body||'{}'));}catch(e){doResume(null);}}
|
if(fmt==='json'){try{doResume(JSON.parse(route.json||route.body||'{}'));}catch(e){doResume(null);}}
|
||||||
else if(fmt==='html'){const frag=new El('fragment');frag.nodeType=11;frag.innerHTML=route.html||route.body||'';frag.textContent=frag.innerHTML.replace(/<[^>]*>/g,'');doResume(frag);}
|
else if(fmt==='html'){const frag=new El('fragment');frag.nodeType=11;frag.innerHTML=route.html||route.body||'';frag.textContent=frag.innerHTML.replace(/<[^>]*>/g,'');doResume(frag);}
|
||||||
else if(fmt==='response')doResume({ok:(route.status||200)<400,status:route.status||200,url});
|
else if(fmt==='response')doResume({ok:(route.status||200)<400,status:route.status||200,url});
|
||||||
else if(fmt==='Number'||fmt==='number')doResume(parseFloat(route.body||'0'));
|
else if(fmt.toLowerCase()==='number')doResume(parseFloat(route.number||route.body||'0'));
|
||||||
else doResume(route.body||'');
|
else doResume(route.body||'');
|
||||||
}
|
}
|
||||||
else if(opName==='io-parse-text'){const resp=items&&items[1];doResume(resp&&resp._body?resp._body:typeof resp==='string'?resp:'');}
|
else if(opName==='io-parse-text'){const resp=items&&items[1];doResume(resp&&resp._body?resp._body:typeof resp==='string'?resp:'');}
|
||||||
|
|||||||
Reference in New Issue
Block a user