@seneris/nosework 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ import { getClient } from "./client.js";
2
+ import { pageViews } from "./schema.js";
3
+ import { and, eq, lt } from "drizzle-orm";
4
+ /**
5
+ * Build the WHERE predicate for retention deletion.
6
+ *
7
+ * Ensures correct scoping: if siteId is provided, scopes to that site;
8
+ * if omitted, sweeps all sites. Uses explicit undefined check (not truthiness)
9
+ * so that an empty siteId "" scopes to that site rather than sweeping all.
10
+ */
11
+ export function buildRetentionWhere(olderThan, siteId) {
12
+ return siteId !== undefined
13
+ ? and(eq(pageViews.siteId, siteId), lt(pageViews.timestamp, olderThan))
14
+ : lt(pageViews.timestamp, olderThan);
15
+ }
16
+ /**
17
+ * Delete page views older than the given cutoff.
18
+ *
19
+ * Enforces the stated retention period. Omit siteId to sweep every site, which
20
+ * is what the scheduled retention job does — deleteOldErrors() requires a
21
+ * siteId, but a retention cron has no list of sites to iterate.
22
+ *
23
+ * @returns the number of rows deleted
24
+ */
25
+ export async function deleteOldPageViews(olderThan, siteId) {
26
+ const db = getClient();
27
+ const where = buildRetentionWhere(olderThan, siteId);
28
+ const deleted = await db
29
+ .delete(pageViews)
30
+ .where(where)
31
+ .returning({ id: pageViews.id });
32
+ return deleted.length;
33
+ }
34
+ //# sourceMappingURL=retention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retention.js","sourceRoot":"","sources":["../src/retention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAe,EAAE,MAAe;IAClE,OAAO,MAAM,KAAK,SAAS;QACzB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACvE,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,SAAe,EACf,MAAe;IAEf,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;IAEvB,MAAM,KAAK,GAAG,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAErD,MAAM,OAAO,GAAG,MAAM,EAAE;SACrB,MAAM,CAAC,SAAS,CAAC;SACjB,KAAK,CAAC,KAAK,CAAC;SACZ,SAAS,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;IAEnC,OAAO,OAAO,CAAC,MAAM,CAAC;AACxB,CAAC"}