Update lstd to 0.2.0

This commit is contained in:
luaneko 2025-01-10 04:11:17 +11:00
parent bdebb22a0e
commit 60899d1a41
Signed by: luaneko
GPG Key ID: 406809B8763FF07A
5 changed files with 22 additions and 39 deletions

24
deno.lock generated
View File

@ -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/result.js": "001ff5e0c8d634674f483d07fbcd620a797e3101f842d6c20ca3ace936260465",
"https://deno.land/x/postgresjs@v3.4.5/src/subscribe.js": "9e4d0c3e573a6048e77ee2f15abbd5bcd17da9ca85a78c914553472c6d6c169b", "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://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.2.0/async.ts": "20bc54c7260c2d2cd27ffcca33b903dde57a3a3635386d8e0c6baca4b253ae4e",
"https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/bytes.ts": "39d4c08f6446041f1d078bbf285187c337d49f853b20ec637cf1516fae8b3729", "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/bytes.ts": "5ffb12787dc3f9ef9680b6e2e4f5f9903783aa4c33b69e725b5df1d1c116bfe6",
"https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/events.ts": "51bf13b819d1c4af792a40ff5d8d08407502d3f01d94f6b6866156f52cbe5d64", "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/events.ts": "28d395b8eea87f9bf7908a44b351d2d3c609ba7eab62bcecd0d43be8ee603438",
"https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/func.ts": "f1935f673365cd68939531d65ef18fe81b5d43dc795b03c34bb5ad821ab1c9ff", "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/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.2.0/jit.ts": "c1db7820de95c48521b057c7cdf9aa41f7eaba77462407c29d3932e7da252d53",
"https://git.lua.re/luaneko/lstd/raw/tag/0.1.2/mod.ts": "d7ef832245676b097c4fb7829c5cb2df80c02d2bd28767168c4f83bc309c9b1a", "https://git.lua.re/luaneko/lstd/raw/tag/0.2.0/mod.ts": "95d8b15048a54cb82391825831f695b74e7c8b206317264a99c906ce25c63f13"
"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"
} }
} }

View File

@ -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";

View File

@ -29,9 +29,7 @@ export function row_ctor(from_sql: FromSql, columns: RowDescription) {
const Row = jit.compiled<RowConstructor>`function Row(xs) { const Row = jit.compiled<RowConstructor>`function Row(xs) {
${jit.map(" ", columns, ({ name, type_oid }, i) => { ${jit.map(" ", columns, ({ name, type_oid }, i) => {
return jit`this[${jit.literal(name)}] = ${from_sql}( return jit`this[${name}] = ${from_sql}(new ${SqlValue}(${type_oid}, ${parse}(xs[${i}])));`;
new ${SqlValue}(${jit.literal(type_oid)}, ${parse}(xs[${jit.literal(i)}]))
);`;
})} })}
}`; }`;
@ -50,7 +48,7 @@ export function row_ctor(from_sql: FromSql, columns: RowDescription) {
configurable: true, configurable: true,
value: jit.compiled`function* iter() { value: jit.compiled`function* iter() {
${jit.map(" ", columns, ({ name }) => { ${jit.map(" ", columns, ({ name }) => {
return jit`yield this[${jit.literal(name)}];`; return jit`yield this[${name}];`;
})} })}
}`, }`,
}, },

26
ser.ts
View File

@ -41,15 +41,6 @@ export interface Encoder<T> {
export type EncoderType<E extends Encoder<unknown>> = export type EncoderType<E extends Encoder<unknown>> =
E extends Encoder<infer T> ? T : never; E extends Encoder<infer T> ? 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 // https://www.postgresql.org/docs/current/protocol-message-types.html#PROTOCOL-MESSAGE-TYPES
export const i8: Encoder<number> = { export const i8: Encoder<number> = {
const_size: 1, const_size: 1,
@ -216,7 +207,7 @@ export function array<T>(
): ArrayEncoder<T> { ): ArrayEncoder<T> {
const { const_size } = type; const { const_size } = type;
return { return {
const_size, const_size: null,
allocs: allocs:
const_size !== null const_size !== null
? function allocs(xs: T[]) { ? function allocs(xs: T[]) {
@ -250,21 +241,28 @@ export interface ObjectEncoder<S extends ObjectShape>
export function object<S extends ObjectShape>(shape: S): ObjectEncoder<S> { export function object<S extends ObjectShape>(shape: S): ObjectEncoder<S> {
const keys = Object.keys(shape); const keys = Object.keys(shape);
return jit.compiled`{ return jit.compiled`{
const_size: ${jit.literal(sum_const_size(...keys.map((k) => shape[k].const_size)))}, const_size: null,
allocs(x) { 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 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) { encode(buf, cur, x) {
${jit.map(" ", keys, (k) => { ${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) { decode(buf, cur) {
return { return {
${jit.map(", ", keys, (k) => { ${jit.map(", ", keys, (k) => {
return jit`[${jit.literal(k)}]: ${shape[k]}.decode(buf, cur)`; return jit`[${k}]: ${shape[k]}.decode(buf, cur)`;
})} })}
}; };
}, },

View File

@ -28,7 +28,6 @@ import {
i16, i16,
i32, i32,
i8, i8,
sum_const_size,
} from "./ser.ts"; } from "./ser.ts";
import { import {
is_sql, is_sql,
@ -123,7 +122,7 @@ function msg<T extends string, S extends ObjectShape>(
const fields = object(shape); const fields = object(shape);
return { return {
const_size: sum_const_size(header_size, fields.const_size), const_size: null,
get type() { get type() {
return type; return type;
}, },