toilscript 0.1.14 → 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.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/importmap.json +2 -2
- package/dist/toilscript.js +35 -16
- package/dist/toilscript.js.map +3 -3
- package/dist/web.js +3 -3
- package/package.json +1 -1
package/dist/importmap.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"imports": {
|
|
3
|
-
"toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
4
|
-
"toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.
|
|
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
|
}
|
package/dist/toilscript.js
CHANGED
|
@@ -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,19 +364,37 @@ declare interface __Record`),n.push(e.id.toString()),n.push(`<TOmittable> {
|
|
|
364
364
|
`,e+=` return path;
|
|
365
365
|
`,e+=`}
|
|
366
366
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
`,e
|
|
371
|
-
|
|
372
|
-
`,e
|
|
373
|
-
`,
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
`,e
|
|
377
|
-
|
|
378
|
-
`,e
|
|
379
|
-
|
|
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());
|
|
380
398
|
`,e+=` },
|
|
381
399
|
`}e+=` },
|
|
382
400
|
`}return e+=`};
|
|
@@ -395,8 +413,9 @@ declare interface __Record`),n.push(e.id.toString()),n.push(`<TOmittable> {
|
|
|
395
413
|
`}e+=` };
|
|
396
414
|
`}return e+=` };
|
|
397
415
|
`,e+=`}
|
|
398
|
-
`,e}function S0(t,i){let e=y0(t);if(e.data.length==0&&e.services.length==0&&e.remotes.length==0&&e.rest.length==0)return null;let r=new Set;for(let s=0,l=e.data.length;s<l;++s)r.add(e.data[s].name);let n
|
|
399
|
-
`;n+=`//
|
|
416
|
+
`,e}function S0(t,i){let e=y0(t);if(e.data.length==0&&e.services.length==0&&e.remotes.length==0&&e.rest.length==0)return null;let r=new Set;for(let s=0,l=e.data.length;s<l;++s)r.add(e.data[s].name);let n=`/* eslint-disable */
|
|
417
|
+
`;n+=`// AUTO-GENERATED by toilscript, do not edit.
|
|
418
|
+
`,n+=`// Working @data codec + the typed client-callable Server surface.
|
|
400
419
|
`,n+=`// The Server proxy + transport are provided by toiljs.
|
|
401
420
|
|
|
402
421
|
`,e.data.length&&(n+='import { DataWriter, DataReader } from "'+i+`";
|