WIP message-delivery-method-web-push
Main daploy / deploy (push) Successful in 1m22s

This commit is contained in:
2024-11-27 15:57:11 +02:00
parent 056247a414
commit 1c8019d41a
48 changed files with 464 additions and 128 deletions
@@ -0,0 +1,38 @@
import { serviceDb, type ServiceDoc } from "./dbs";
const SERVICE_DOC_ID = "_local/service:message-delivery-method-web-push";
export class ServiceSeqTracker {
private serviceDoc: ServiceDoc;
async getSince() {
this.serviceDoc = await serviceDb.get(SERVICE_DOC_ID).catch((error) => {
if (error.name === "not_found") {
return {
_id: SERVICE_DOC_ID,
lastSeq: "0",
};
}
throw error; // Re-throw other errors
});
this.serviceDoc.lastSeq = 0;
return this.serviceDoc.lastSeq;
}
checkNextSeq(seq: number | string) {
const next = parseInt(seq as string, 10);
const current = parseInt(this.serviceDoc.lastSeq as string, 10);
if (next < current) {
throw new Error(
`Sequence number is too old: ${seq} (${next} < ${current})`,
);
}
}
saveSeq(seq: number | string) {
this.serviceDoc.lastSeq = seq;
return serviceDb.put(this.serviceDoc);
}
}