From 60899d1a410ae10d28733e5fe82d678f99fa2845 Mon Sep 17 00:00:00 2001 From: luaneko Date: Fri, 10 Jan 2025 04:11:17 +1100 Subject: [PATCH] Update lstd to 0.2.0 --- deno.lock | 24 ++++++------------------ lstd.ts | 2 +- query.ts | 6 ++---- ser.ts | 26 ++++++++++++-------------- wire.ts | 3 +-- 5 files changed, 22 insertions(+), 39 deletions(-) diff --git a/deno.lock b/deno.lock index 63d8442..76a7720 100644 --- a/deno.lock +++ b/deno.lock @@ -433,23 +433,11 @@ "https://deno.land/x/postgresjs@v3.4.5/src/result.js": "001ff5e0c8d634674f483d07fbcd620a797e3101f842d6c20ca3ace936260465", "https://deno.land/x/postgresjs@v3.4.5/src/subscribe.js": "9e4d0c3e573a6048e77ee2f15abbd5bcd17da9ca85a78c914553472c6d6c169b", "https://deno.land/x/postgresjs@v3.4.5/src/types.js": "471f4a6c35412aa202a7c177c0a7e5a7c3bd225f01bbde67c947894c1b8bf6ed", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/async.ts": "ec1a2d25af2320f136b8648b25b590b7b6603525474f0d10b3ebf2215a5c23e5", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/bytes.ts": "39d4c08f6446041f1d078bbf285187c337d49f853b20ec637cf1516fae8b3729", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/events.ts": "51bf13b819d1c4af792a40ff5d8d08407502d3f01d94f6b6866156f52cbe5d64", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/func.ts": "f1935f673365cd68939531d65ef18fe81b5d43dc795b03c34bb5ad821ab1c9ff", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/jit.ts": "1b7eec61ece15c05146446972a59d8d5787d4ba53ca1194f4450134d66a65f91", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/mod.ts": "d7ef832245676b097c4fb7829c5cb2df80c02d2bd28767168c4f83bc309c9b1a", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.3/async.ts": "20bc54c7260c2d2cd27ffcca33b903dde57a3a3635386d8e0c6baca4b253ae4e", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.3/bytes.ts": "39d4c08f6446041f1d078bbf285187c337d49f853b20ec637cf1516fae8b3729", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.3/events.ts": "c4f2c856cbc7ac5d93b9af9b83d9550db7427cead32514a10424082e492005ae", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.3/func.ts": "f1935f673365cd68939531d65ef18fe81b5d43dc795b03c34bb5ad821ab1c9ff", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.3/jit.ts": "260ab418fbc55a5dec594f023c84d36f8d420fd3239e3d27648cba1b9a0e05b1", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.3/mod.ts": "dd9271f4e5aae4bfb1ec6b0800697ded12e4178af915acb2b96b97614ae8c8d9", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.5/async.ts": "20bc54c7260c2d2cd27ffcca33b903dde57a3a3635386d8e0c6baca4b253ae4e", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.5/bytes.ts": "b9816e75afa878202529b11431dfd77f5f14f71e67c3f15852fd651f6801d8bb", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.5/events.ts": "c4f2c856cbc7ac5d93b9af9b83d9550db7427cead32514a10424082e492005ae", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.5/func.ts": "f1935f673365cd68939531d65ef18fe81b5d43dc795b03c34bb5ad821ab1c9ff", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.5/jit.ts": "260ab418fbc55a5dec594f023c84d36f8d420fd3239e3d27648cba1b9a0e05b1", - "https://git.lua.re/luaneko/lstd/raw/tag/0.1.5/mod.ts": "95d8b15048a54cb82391825831f695b74e7c8b206317264a99c906ce25c63f13" + "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/async.ts": "20bc54c7260c2d2cd27ffcca33b903dde57a3a3635386d8e0c6baca4b253ae4e", + "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/bytes.ts": "5ffb12787dc3f9ef9680b6e2e4f5f9903783aa4c33b69e725b5df1d1c116bfe6", + "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/events.ts": "28d395b8eea87f9bf7908a44b351d2d3c609ba7eab62bcecd0d43be8ee603438", + "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/func.ts": "f1935f673365cd68939531d65ef18fe81b5d43dc795b03c34bb5ad821ab1c9ff", + "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/jit.ts": "c1db7820de95c48521b057c7cdf9aa41f7eaba77462407c29d3932e7da252d53", + "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/mod.ts": "95d8b15048a54cb82391825831f695b74e7c8b206317264a99c906ce25c63f13" } } diff --git a/lstd.ts b/lstd.ts index e942db7..207af2e 100644 --- a/lstd.ts +++ b/lstd.ts @@ -1 +1 @@ -export * from "https://git.lua.re/luaneko/lstd/raw/tag/0.1.5/mod.ts"; +export * from "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/mod.ts"; diff --git a/query.ts b/query.ts index 367b081..9596447 100644 --- a/query.ts +++ b/query.ts @@ -29,9 +29,7 @@ export function row_ctor(from_sql: FromSql, columns: RowDescription) { const Row = jit.compiled`function Row(xs) { ${jit.map(" ", columns, ({ name, type_oid }, i) => { - return jit`this[${jit.literal(name)}] = ${from_sql}( - new ${SqlValue}(${jit.literal(type_oid)}, ${parse}(xs[${jit.literal(i)}])) - );`; + return jit`this[${name}] = ${from_sql}(new ${SqlValue}(${type_oid}, ${parse}(xs[${i}])));`; })} }`; @@ -50,7 +48,7 @@ export function row_ctor(from_sql: FromSql, columns: RowDescription) { configurable: true, value: jit.compiled`function* iter() { ${jit.map(" ", columns, ({ name }) => { - return jit`yield this[${jit.literal(name)}];`; + return jit`yield this[${name}];`; })} }`, }, diff --git a/ser.ts b/ser.ts index 154edea..6dc9560 100644 --- a/ser.ts +++ b/ser.ts @@ -41,15 +41,6 @@ export interface Encoder { export type EncoderType> = E extends Encoder ? T : never; -export function sum_const_size(...ns: (number | null)[]) { - let sum = 0; - for (const n of ns) { - if (n !== null) sum += n; - else return null; - } - return sum; -} - // https://www.postgresql.org/docs/current/protocol-message-types.html#PROTOCOL-MESSAGE-TYPES export const i8: Encoder = { const_size: 1, @@ -216,7 +207,7 @@ export function array( ): ArrayEncoder { const { const_size } = type; return { - const_size, + const_size: null, allocs: const_size !== null ? function allocs(xs: T[]) { @@ -250,21 +241,28 @@ export interface ObjectEncoder export function object(shape: S): ObjectEncoder { const keys = Object.keys(shape); return jit.compiled`{ - const_size: ${jit.literal(sum_const_size(...keys.map((k) => shape[k].const_size)))}, + const_size: null, allocs(x) { + return ${jit.if( + keys.length === 0, + jit`0`, + jit.map(" + ", keys, (k) => { + return shape[k].const_size ?? jit`${shape[k]}.allocs(x[${k}])`; + }) + )}; return 0${jit.map("", keys, (k) => { - return jit` + ${shape[k]}.allocs(x[${jit.literal(k)}])`; + return jit` + ${shape[k]}.allocs(x[${k}])`; })}; }, encode(buf, cur, x) { ${jit.map(" ", keys, (k) => { - return jit`${shape[k]}.encode(buf, cur, x[${jit.literal(k)}]);`; + return jit`${shape[k]}.encode(buf, cur, x[${k}]);`; })} }, decode(buf, cur) { return { ${jit.map(", ", keys, (k) => { - return jit`[${jit.literal(k)}]: ${shape[k]}.decode(buf, cur)`; + return jit`[${k}]: ${shape[k]}.decode(buf, cur)`; })} }; }, diff --git a/wire.ts b/wire.ts index 7b6d73f..bd20ccf 100644 --- a/wire.ts +++ b/wire.ts @@ -28,7 +28,6 @@ import { i16, i32, i8, - sum_const_size, } from "./ser.ts"; import { is_sql, @@ -123,7 +122,7 @@ function msg( const fields = object(shape); return { - const_size: sum_const_size(header_size, fields.const_size), + const_size: null, get type() { return type; },