toilscript 0.1.15 → 0.1.16

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "imports": {
3
- "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.15/dist/toilscript.js",
4
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.15/dist/cli.js",
3
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.16/dist/toilscript.js",
4
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.16/dist/cli.js",
5
5
  "binaryen": "https://cdn.jsdelivr.net/npm/binaryen@129.0.0-nightly.20260428/index.js",
6
6
  "long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
7
7
  }
@@ -322,7 +322,7 @@ declare interface __Record`),n.push(e.id.toString()),n.push(`<TOmittable> {
322
322
  `):r+=" "+Ag(o.ref.type,u)+`
323
323
  `}r+=` }
324
324
 
325
- `,r+=` public encode(): Uint8Array {
325
+ `,r+=` public encode(): Uint8Array<ArrayBuffer> {
326
326
  `,r+=` const w = new DataWriter();
327
327
  `,r+=" w.writeU32("+e+`);
328
328
  `,r+=` this.encodeInto(w);
@@ -364,18 +364,37 @@ declare interface __Record`),n.push(e.id.toString()),n.push(`<TOmittable> {
364
364
  `,e+=` return path;
365
365
  `,e+=`}
366
366
 
367
- `,e+=`const __toilRest = {
368
- `;for(let r=0,n=t.rest.length;r<n;++r){let a=t.rest[r];e+=" "+a.key+`: {
369
- `;for(let s=0,l=a.routes.length;s<l;++s){let o=a.routes[s],u=Fg(o,i);e+=" async "+o.name+"("+u.argsParam+"): "+u.ret+` {
370
- `,e+=" const __url = __toilUrl("+JSON.stringify(o.pattern)+", "+(o.params.length?"args.params as any":"undefined")+`, args?.query);
371
- `;let c=o.bodyType!=null?o.stream=="Binary"?"application/octet-stream":"application/json":"",_="{ ";c.length&&(_+=JSON.stringify("content-type")+": "+JSON.stringify(c)+", "),_+="...(args?.headers ?? {}) }";let f=o.bodyType!=null?o.stream=="Binary"?", body: args.body.encode()":", body: JSON.stringify(args.body)":"";e+=" const __res = await fetch(__url, { method: "+JSON.stringify(o.http)+", headers: "+_+f+` });
372
- `,e+=" if (!__res.ok) throw new Error(`Server.REST."+a.key+"."+o.name+" ${__res.status}`);\n",o.returnsResponse?e+=` return __res;
373
- `:o.returns.type=="void"?e+=` return;
374
- `:o.stream=="Binary"?(e+=` const __buf = new Uint8Array(await __res.arrayBuffer());
375
- `,e+=" return "+o.returns.type+`.decode(__buf);
376
- `):o.returns.array?(e+=` const __j = await __res.json();
377
- `,e+=" return (Array.isArray(__j) ? __j : []).map((x: any) => "+o.returns.type+`.fromJSONValue(x));
378
- `):e+=" return "+o.returns.type+`.fromJSONValue(await __res.json());
367
+ `;let r=!1;for(let n=0,a=t.rest.length;n<a&&!r;++n){let s=t.rest[n];for(let l=0,o=s.routes.length;l<o;++l){let u=s.routes[l];if(u.bodyType!=null&&u.stream!="Binary"){r=!0;break}}}r&&(e+=`function __toilJson(v: any): string {
368
+ `,e+=` if (v === null || v === undefined) return "null";
369
+ `,e+=` const t = typeof v;
370
+ `,e+=` if (t === "bigint") return v.toString();
371
+ `,e+=` if (t === "number") return Number.isFinite(v) ? String(v) : "null";
372
+ `,e+=` if (t === "boolean") return v ? "true" : "false";
373
+ `,e+=` if (t === "string") return JSON.stringify(v);
374
+ `,e+=` if (Array.isArray(v)) return "[" + v.map((x: any) => __toilJson(x)).join(",") + "]";
375
+ `,e+=` let s = "{", first = true;
376
+ `,e+=` for (const k in v) {
377
+ `,e+=` if (!Object.prototype.hasOwnProperty.call(v, k)) continue;
378
+ `,e+=` const val = v[k];
379
+ `,e+=` if (val === undefined || typeof val === "function") continue;
380
+ `,e+=` s += (first ? "" : ",") + JSON.stringify(k) + ":" + __toilJson(val);
381
+ `,e+=` first = false;
382
+ `,e+=` }
383
+ `,e+=` return s + "}";
384
+ `,e+=`}
385
+
386
+ `),e+=`const __toilRest = {
387
+ `;for(let n=0,a=t.rest.length;n<a;++n){let s=t.rest[n];e+=" "+s.key+`: {
388
+ `;for(let l=0,o=s.routes.length;l<o;++l){let u=s.routes[l],c=Fg(u,i);e+=" async "+u.name+"("+c.argsParam+"): "+c.ret+` {
389
+ `,e+=" const __url = __toilUrl("+JSON.stringify(u.pattern)+", "+(u.params.length?"args.params as any":"undefined")+`, args?.query);
390
+ `;let _=u.bodyType!=null?u.stream=="Binary"?"application/octet-stream":"application/json":"",f="{ ";_.length&&(f+=JSON.stringify("content-type")+": "+JSON.stringify(_)+", "),f+="...(args?.headers ?? {}) }";let h=u.bodyType!=null?u.stream=="Binary"?", body: args.body.encode()":", body: __toilJson(args.body)":"";e+=" const __res = await fetch(__url, { method: "+JSON.stringify(u.http)+", headers: "+f+h+` });
391
+ `,e+=" if (!__res.ok) throw new Error(`Server.REST."+s.key+"."+u.name+" ${__res.status}`);\n",u.returnsResponse?e+=` return __res;
392
+ `:u.returns.type=="void"?e+=` return;
393
+ `:u.stream=="Binary"?(e+=` const __buf = new Uint8Array(await __res.arrayBuffer());
394
+ `,e+=" return "+u.returns.type+`.decode(__buf);
395
+ `):u.returns.array?(e+=` const __j = await __res.json();
396
+ `,e+=" return (Array.isArray(__j) ? __j : []).map((x: any) => "+u.returns.type+`.fromJSONValue(x));
397
+ `):e+=" return "+u.returns.type+`.fromJSONValue(await __res.json());
379
398
  `,e+=` },
380
399
  `}e+=` },
381
400
  `}return e+=`};