This commit is contained in:
728
2023-01-23 14:40:31 +08:00
parent 60ca0d750a
commit c26dd9eab3
4 changed files with 111 additions and 19 deletions

View File

@ -3,22 +3,6 @@ echo "building ismism.ts"
rm cli/*.js
rm -rf ui
mkdir ui
mkdir ui/54
cd ismism.ts
deno bundle src/serve.ts ../cli/serve.js
deno bundle cli/dbreset.ts ../cli/dbreset.js
deno bundle cli/smstst.ts ../cli/smstst.js
cp ui/index.html ../ui/index.html
deno bundle ui/bind.ts ../ui/bind.js
cp ui/54/index.html ../ui/54/index.html
cp ui/54/v1.pdf ../ui/54/v1.pdf
# mkdir ../ui/cast
# cp ui/cast/index.html ../ui/cast/index.html
# cp ui/cast/*.webp ../ui/cast/
# deno bundle ui/cast/bind.ts ../ui/cast/bind.js

4
ismism.ts/cli/dbreset.ts Normal file
View File

@ -0,0 +1,4 @@
import { reset } from "../src/db.ts"
const coll = await reset()
console.log(`doen resetting db with coll: ${coll.join(" ")}`)

94
ismism.ts/src/db.ts Normal file
View File

@ -0,0 +1,94 @@
import { Act, Agenda, Aut, Fund, Imgsrc, Soc, User, Work, Worker } from "./eidetic/dbtyp.ts"
import { MongoClient } from "https://deno.land/x/mongo@v0.31.1/mod.ts"
const conn = new MongoClient()
await conn.connect("mongodb://127.0.0.1:27017")
const db = conn.database("ismism")
export const coll = {
user: db.collection<User>("user"),
soc: db.collection<Soc>("soc"),
agenda: db.collection<Agenda>("agenda"),
worker: db.collection<Worker>("worker"),
work: db.collection<Work>("work"),
fund: db.collection<Fund>("fund"),
act: db.collection<Act>("act"),
aut: db.collection<Aut>("aut"),
imgsrc: db.collection<Imgsrc>("imgsrc"),
}
export type DocC<T> = Promise<NonNullable<T> | null>
export type DocR<T> = Promise<NonNullable<T> | null>
export type DocU = Promise<0 | 1 | null>
export type DocD = Promise<0 | 1 | null>
export type Doc<T> = DocC<T> | DocR<T> | DocU | DocD
export async function reset(
) {
try { await db.dropDatabase() } catch (e) { console.error(e) }
coll.user.createIndexes({
indexes: [{
key: { name: 1 }, name: "name", unique: true,
}, {
key: { nbr: 1 }, name: "nbr", unique: true,
partialFilterExpression: { nbr: { $exists: true } },
}]
})
await coll.soc.createIndexes({
indexes: [{
key: { name: 1 }, name: "name", unique: true,
}, {
key: { uid: 1 }, name: "uid",
}, {
key: { adm1: 1 }, name: "adm1",
}, {
key: { adm2: 1 }, name: "adm2",
}]
})
await coll.agenda.createIndexes({
indexes: [{
key: { name: 1 }, name: "name", unique: true,
}, {
key: { adm1: 1 }, name: "adm1",
}, {
key: { adm2: 1 }, name: "adm2",
}]
})
await coll.worker.createIndexes({
indexes: [{
key: { "_id.utc": -1 }, name: "utc"
}, {
key: { "_id.aid": 1, "_id.utc": -1 }, name: "aid-utc"
}, {
key: { "_id.aid": 1, role: 1, "_id.utc": -1 }, name: "aid-role-utc"
}, {
key: { "_id.uid": 1, "_id.utc": -1 }, name: "uid-utc"
}]
})
await coll.work.createIndexes({
indexes: [{
key: { "_id.aid": 1, "_id.utc": -1 }, name: "aid-utc"
}, {
key: { "_id.aid": 1, work: 1, "_id.utc": -1 }, name: "aid-work-utc"
}, {
key: { "_id.uid": 1, "_id.utc": -1 }, name: "uid-utc"
}, {
key: { "_id.utc": -1 }, name: "utc"
}]
})
await coll.fund.createIndexes({
indexes: [{
key: { "_id.aid": 1, "_id.utc": -1 }, name: "aid-utc"
}, {
key: { "_id.uid": 1, "_id.utc": -1 }, name: "uid-utc"
}, {
key: { "_id.utc": -1 }, name: "utc"
}]
})
return await db.listCollectionNames()
}

View File

@ -24,6 +24,7 @@ export type Agenda = Id & {
expense: number,
goal: { name: string, pct: number }[],
candidate: number,
imgsrc?: Imgsrc["_id"],
}
export type Rec = {
@ -40,11 +41,11 @@ export type Work = Rec & ({
msg: string,
} | {
work: "txt",
title: string,
src: string,
name: string,
txt: string,
} | {
work: "video",
title: string,
name: string,
src: string,
})
export type Fund = Rec & {
@ -66,3 +67,12 @@ export type Aut = {
_id: User["_id"],
p: string[],
}
export type Dat = {
_id: { uid: User["_id"], utc: number },
name: string,
utc_update: number,
}
export type Imgsrc = Dat & {
img: { title: string, src: string }[],
}