diff --git a/common/space_lua/parse.ts b/common/space_lua/parse.ts index e00811fe..b1bf2e7e 100644 --- a/common/space_lua/parse.ts +++ b/common/space_lua/parse.ts @@ -32,7 +32,7 @@ const luaStyleTags = styleTags({ CompareOp: t.operator, "true false": t.bool, Comment: t.lineComment, - "return break goto do end while repeat until function local if then else elseif in for nil or and not query where limit select order": + "return break goto do end while repeat until function local if then else elseif in for nil or and not query where limit select order by desc": t.keyword, }); diff --git a/common/space_lua/stdlib.ts b/common/space_lua/stdlib.ts index 90354da1..3945942d 100644 --- a/common/space_lua/stdlib.ts +++ b/common/space_lua/stdlib.ts @@ -20,6 +20,7 @@ import type { LuaCollectionQuery, LuaQueryCollection, } from "$common/space_lua/query_collection.ts"; +import { KV } from "@silverbulletmd/silverbullet/types"; const printFunction = new LuaBuiltinFunction(async (_sf, ...args) => { console.log("[Lua]", ...(await Promise.all(args))); @@ -134,11 +135,17 @@ const tagFunction = new LuaBuiltinFunction( throw new LuaRuntimeError("Global not found", sf); } return { - query: (query: LuaCollectionQuery): any => { - return global.get("datastore").get("query_lua").call(sf, [ - "idx", - tagName, - ], query); + query: async (query: LuaCollectionQuery): Promise => { + const kvs: KV[] = (await global.get("datastore").get("query_lua").call( + sf, + [ + "idx", + tagName, + ], + query, + )).asJSArray(); + console.log("Got kvs", kvs); + return kvs.map((kv) => kv.value); }, }; },