From cbaed217654f3a130c9e9194c3701f581c51cbb3 Mon Sep 17 00:00:00 2001 From: 728 Date: Wed, 31 May 2023 06:40:50 +0800 Subject: [PATCH] que dst --- ismism.ts/src/eid/is.ts | 2 +- ismism.ts/src/pra/doc.ts | 15 +++++++++++++++ ismism.ts/src/pra/que.ts | 5 ++++- ismism.ts/tst/eid.test.ts | 8 +++++--- ismism.ts/tst/que.test.ts | 16 +++++++++++++++- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/ismism.ts/src/eid/is.ts b/ismism.ts/src/eid/is.ts index 5099218..8c1b703 100644 --- a/ismism.ts/src/eid/is.ts +++ b/ismism.ts/src/eid/is.ts @@ -123,7 +123,7 @@ export function is_dstid( ): dstid is Dst["_id"] { const l = Object.keys(dstid).length return 1 <= l && l <= 3 && is_lim(dstid.rd, lim_rd) - && (l === 2 && is_id(dstid.aid!) || l === 3 && is_id(dstid.uid!)) + && (l === 1 || l === 2 && is_id(dstid.aid!) || l === 3 && is_id(dstid.uid!)) } export function is_aut( diff --git a/ismism.ts/src/pra/doc.ts b/ismism.ts/src/pra/doc.ts index c634886..891d5d0 100644 --- a/ismism.ts/src/pra/doc.ts +++ b/ismism.ts/src/pra/doc.ts @@ -9,6 +9,8 @@ import { id, idnam, nid_of_adm } from "../eid/id.ts" import { aut_g, aut_r } from "../eid/aut.ts" import { md_f, md_r } from "../eid/md.ts" import { ord_a, ord_f } from "../eid/ord.ts" +import { dst_f, dst_n, dst_r } from "../eid/dst.ts" +import { lim_rd } from "../eid/is.ts" export async function nid( ) { @@ -119,6 +121,19 @@ export async function live( return { live: l, unam, anam } } +export async function dst( +) { + const [rd, rdaid] = await Promise.all([ + dst_r({ rd: lim_rd }), dst_f({ rd: lim_rd }) + ]) + if (rd === null || rdaid === null) return null + const aid = rdaid.map(r => r._id.aid!) + const ndst = await Promise.all(aid.map(a => dst_n({ rd: lim_rd, aid: a }))) + const dst = aid.map((aid, n) => ({ aid, ndst: ndst[n] ?? 0 })).sort((a, b) => b.ndst - a.ndst) + const anam = await idnam(coll.agd, aid) + return { rd: rd.json, dst, anam } +} + export async function aut( ) { const a = await aut_g() diff --git a/ismism.ts/src/pra/que.ts b/ismism.ts/src/pra/que.ts index 1ccc83d..a1da43d 100644 --- a/ismism.ts/src/pra/que.ts +++ b/ismism.ts/src/pra/que.ts @@ -1,7 +1,7 @@ import type { Ret } from "./can.ts" import { is_id, is_nbr } from "../eid/is.ts" import { coll } from "../db.ts" -import { agd, aut, live, md, nid, ord, rec, soc, usr } from "./doc.ts" +import { agd, aut, dst, live, md, nid, ord, rec, soc, usr } from "./doc.ts" import { id, idnam } from "../eid/id.ts" import { nord_f } from "../eid/ord.ts" @@ -12,6 +12,7 @@ export type Agd = Ret export type Ord = Ret export type Rec = Ret export type Live = Ret +export type Dst = Ret export type Aut = Ret export type Md = Ret @@ -53,6 +54,8 @@ export async function que( } break } case "live": { return await live() + } case "dst": { + return await dst() } case "aut": { return await aut() } case "md": { diff --git a/ismism.ts/tst/eid.test.ts b/ismism.ts/tst/eid.test.ts index 8125fb3..a1d6ce0 100644 --- a/ismism.ts/tst/eid.test.ts +++ b/ismism.ts/tst/eid.test.ts @@ -10,7 +10,7 @@ import { md_c, md_f, md_r, md_u } from "../src/eid/md.ts" import { aut_c, aut_d, aut_g } from "../src/eid/aut.ts" import { utc_h } from "../src/ont/utc.ts" import { ord_c, ord_d, ord_f, ord_r, ord_u } from "../src/eid/ord.ts" -import { dst_c, dst_f, dst_n } from "../src/eid/dst.ts" +import { dst_c, dst_f, dst_n, dst_r } from "../src/eid/dst.ts" import { lim_rd } from "../src/eid/is.ts" await db("tst", true) @@ -158,14 +158,16 @@ Deno.test("rec", async () => { Deno.test("dst", async () => { assertEquals(0, await dst_n({ rd: lim_rd, aid: 1 })) + const rd = { _id: { rd: lim_rd }, json: JSON.stringify({ nam: "nam", c: 32 }) } await Promise.all([ - dst_c({ _id: { rd: lim_rd }, json: JSON.stringify({ nam: "nam", c: 32 }) }), + dst_c(rd), dst_c({ _id: { rd: lim_rd, aid: 1 } }), dst_c({ _id: { rd: lim_rd, aid: 2 } }), dst_c({ _id: { rd: lim_rd, aid: 1, uid: 1 } }), dst_c({ _id: { rd: lim_rd, aid: 1, uid: 2 } }), dst_c({ _id: { rd: lim_rd, aid: 2, uid: 2 } }), - ]) + ]) // deno-lint-ignore no-explicit-any + assertEquals(rd as any, await dst_r({ rd: lim_rd })) assertEquals(2, await dst_n({ rd: lim_rd, aid: 1 })) assertEquals(1, await dst_n({ rd: lim_rd, uid: 1 })) assertEquals([{ _id: { rd: lim_rd, aid: 1 } }, { _id: { rd: lim_rd, aid: 2 } }], await dst_f({ rd: lim_rd })) diff --git a/ismism.ts/tst/que.test.ts b/ismism.ts/tst/que.test.ts index 51f5646..d8cad4d 100644 --- a/ismism.ts/tst/que.test.ts +++ b/ismism.ts/tst/que.test.ts @@ -5,8 +5,10 @@ import { rec_c } from "../src/eid/rec.ts" import { md_c } from "../src/eid/md.ts" import { soc_c, soc_u } from "../src/eid/soc.ts" import { usr_c } from "../src/eid/usr.ts" -import { Agd, Md, Ord, que, Rec, Soc, Usr } from "../src/pra/que.ts" +import { Agd, Dst, Md, Ord, que, Rec, Soc, Usr } from "../src/pra/que.ts" import { ord_c } from "../src/eid/ord.ts" +import { dst_c } from "../src/eid/dst.ts"; +import { lim_rd } from "../src/eid/is.ts"; await db("tst", true) const utc = Date.now() @@ -33,6 +35,12 @@ await Promise.all([ rec_c(coll.work, { _id: { uid: 2, aid: 1, utc: utc + 1 }, rej: [], ref: [], work: "video", nam: "nam", src: "src" }), rec_c(coll.fund, { _id: { uid: 1, aid: 1, utc }, fund: 100, msg: "fund" }), rec_c(coll.fund, { _id: { uid: 3, aid: 2, utc: utc + 1 }, fund: 100, msg: "fund" }), + dst_c({ _id: { rd: lim_rd }, json: JSON.stringify({ nam: "nam", c: 32 }) }), + dst_c({ _id: { rd: lim_rd, aid: 1 } }), + dst_c({ _id: { rd: lim_rd, aid: 2 } }), + dst_c({ _id: { rd: lim_rd, aid: 1, uid: 1 } }), + dst_c({ _id: { rd: lim_rd, aid: 1, uid: 2 } }), + dst_c({ _id: { rd: lim_rd, aid: 2, uid: 2 } }), await md_c(coll.wsl, { nam: "标题一", uid: 1 }), md_c(coll.wsl, { nam: "标题二", uid: 2 }), md_c(coll.lit, { nam: "标题一", uid: 2 }), @@ -114,6 +122,12 @@ Deno.test("rec", async () => { assertEquals(fund_aid2, fund_sid2) }) +Deno.test("dst", async () => { + const dst = await que("dst", p({})) as Dst + assertEquals({ nam: "nam", c: 32 }, JSON.parse(dst?.rd!)) + assertEquals([{ aid: 1, ndst: 2 }, { aid: 2, ndst: 1 }], dst?.dst) +}) + Deno.test("md", async () => { const wsl = await que("md", p({ wslid: 0, f: "" })) as Md const lit = await que("md", p({ litid: 0, f: "" })) as Md