Complete redo of content indexing and querying (#517)

Complete redo of data store
Introduces live queries and live templates
This commit is contained in:
Zef Hemel
2023-10-03 14:16:33 +02:00
committed by GitHub
parent 7af98e7c7b
commit 0313565610
200 changed files with 4675 additions and 4363 deletions
+39
View File
@@ -0,0 +1,39 @@
import type { FunctionMap } from "$sb/types.ts";
import { niceDate } from "$sb/lib/dates.ts";
export const builtinFunctions: FunctionMap = {
today() {
return niceDate(new Date());
},
max(...args: number[]) {
return Math.max(...args);
},
min(...args: number[]) {
return Math.min(...args);
},
toJSON(obj: any) {
return JSON.stringify(obj);
},
// Note: these assume Monday as the first day of the week
firstDayOfWeek(dateString: string): string {
const date = new Date(dateString);
const dayOfWeek = date.getDay();
const daysToSubtract = (dayOfWeek + 7 - 1) % 7;
const firstDayOfWeek = new Date(date);
firstDayOfWeek.setDate(date.getDate() - daysToSubtract);
return niceDate(firstDayOfWeek);
},
lastDayOfWeek(dateString: string): string {
const date = new Date(dateString);
const dayOfWeek = date.getDay();
const daysToAdd = (7 - dayOfWeek) % 7;
const lastDayOfWeek = new Date(date);
lastDayOfWeek.setDate(date.getDate() + daysToAdd);
return niceDate(lastDayOfWeek);
},
addDays(dateString: string, daysToAdd: number): string {
const date = new Date(dateString);
date.setDate(date.getDate() + daysToAdd);
return niceDate(date);
},
};