nixamp 0.11.1 → 0.11.2

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.
package/dist/enrich.d.ts CHANGED
@@ -16,6 +16,12 @@ export declare const MIN_SCORE = 0.5;
16
16
  export declare const PREFIX_SCORE = 0.42;
17
17
  /** How many answers the cache keeps before the oldest go. */
18
18
  export declare const MAX_ENTRIES = 5000;
19
+ /**
20
+ * Which rules wrote the cache. Answers chosen by older rules are dropped on
21
+ * load: 0.11.0 remembered "Oppenheimer" as the row without the poster for
22
+ * seven days, and an update that chose better could not be seen through it.
23
+ */
24
+ export declare const CACHE_VERSION = 2;
19
25
  export type EnrichKind = "auto" | "title" | "channel" | "fixture";
20
26
  export interface Enriched {
21
27
  /** What nichedb says it is. */
package/dist/enrich.js CHANGED
@@ -34,6 +34,12 @@ export const MIN_SCORE = 0.5;
34
34
  export const PREFIX_SCORE = 0.42;
35
35
  /** How many answers the cache keeps before the oldest go. */
36
36
  export const MAX_ENTRIES = 5000;
37
+ /**
38
+ * Which rules wrote the cache. Answers chosen by older rules are dropped on
39
+ * load: 0.11.0 remembered "Oppenheimer" as the row without the poster for
40
+ * seven days, and an update that chose better could not be seen through it.
41
+ */
42
+ export const CACHE_VERSION = 2;
37
43
  /** The collection and kind a name is asked about, from what the caller knows. */
38
44
  export function whereToAsk(kind, parsedKind) {
39
45
  const k = kind === "auto" ? parsedKind ?? "" : kind;
@@ -217,7 +223,10 @@ export class Enricher {
217
223
  return;
218
224
  try {
219
225
  const parsed = JSON.parse(readFileSync(this.options.cacheFile, "utf8"));
220
- for (const [k, v] of Object.entries(parsed)) {
226
+ // A file from older rules is a file of answers those rules chose.
227
+ if (parsed.v !== CACHE_VERSION)
228
+ return;
229
+ for (const [k, v] of Object.entries(parsed.entries ?? {})) {
221
230
  if (v && typeof v.at === "number")
222
231
  this.cache.set(k, v);
223
232
  }
@@ -242,7 +251,7 @@ export class Enricher {
242
251
  try {
243
252
  mkdirSync(dirname(this.options.cacheFile), { recursive: true });
244
253
  const tmp = `${this.options.cacheFile}.tmp`;
245
- writeFileSync(tmp, JSON.stringify(Object.fromEntries(this.cache)));
254
+ writeFileSync(tmp, JSON.stringify({ v: CACHE_VERSION, entries: Object.fromEntries(this.cache) }));
246
255
  renameSync(tmp, this.options.cacheFile);
247
256
  this.dirty = false;
248
257
  }
package/dist/server.js CHANGED
@@ -2341,8 +2341,9 @@ export function createHandler(engine, options) {
2341
2341
  response.writeHead(200, {
2342
2342
  ...CORS,
2343
2343
  "content-type": "application/json; charset=utf-8",
2344
- // A miss is worth asking again in a few hours; a hit lasts the day.
2345
- "cache-control": match ? "public, max-age=3600" : "public, max-age=600",
2344
+ // Briefly: the server remembers for days, so the browser need not,
2345
+ // and an hour of browser cache hid a better answer for an hour.
2346
+ "cache-control": match ? "public, max-age=300" : "public, max-age=120",
2346
2347
  });
2347
2348
  response.end(JSON.stringify({ match }));
2348
2349
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nixamp",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "It really whips the terminal's ass. A Winamp-shaped audio player for your terminal.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/enrich.ts CHANGED
@@ -35,6 +35,12 @@ export const MIN_SCORE = 0.5;
35
35
  export const PREFIX_SCORE = 0.42;
36
36
  /** How many answers the cache keeps before the oldest go. */
37
37
  export const MAX_ENTRIES = 5000;
38
+ /**
39
+ * Which rules wrote the cache. Answers chosen by older rules are dropped on
40
+ * load: 0.11.0 remembered "Oppenheimer" as the row without the poster for
41
+ * seven days, and an update that chose better could not be seen through it.
42
+ */
43
+ export const CACHE_VERSION = 2;
38
44
 
39
45
  export type EnrichKind = "auto" | "title" | "channel" | "fixture";
40
46
 
@@ -263,8 +269,13 @@ export class Enricher {
263
269
  private load(): void {
264
270
  if (!this.options.cacheFile) return;
265
271
  try {
266
- const parsed = JSON.parse(readFileSync(this.options.cacheFile, "utf8")) as Record<string, Cached>;
267
- for (const [k, v] of Object.entries(parsed)) {
272
+ const parsed = JSON.parse(readFileSync(this.options.cacheFile, "utf8")) as {
273
+ v?: number;
274
+ entries?: Record<string, Cached>;
275
+ };
276
+ // A file from older rules is a file of answers those rules chose.
277
+ if (parsed.v !== CACHE_VERSION) return;
278
+ for (const [k, v] of Object.entries(parsed.entries ?? {})) {
268
279
  if (v && typeof v.at === "number") this.cache.set(k, v);
269
280
  }
270
281
  } catch {
@@ -287,7 +298,7 @@ export class Enricher {
287
298
  try {
288
299
  mkdirSync(dirname(this.options.cacheFile), { recursive: true });
289
300
  const tmp = `${this.options.cacheFile}.tmp`;
290
- writeFileSync(tmp, JSON.stringify(Object.fromEntries(this.cache)));
301
+ writeFileSync(tmp, JSON.stringify({ v: CACHE_VERSION, entries: Object.fromEntries(this.cache) }));
291
302
  renameSync(tmp, this.options.cacheFile);
292
303
  this.dirty = false;
293
304
  } catch (error) {
package/src/server.ts CHANGED
@@ -2815,8 +2815,9 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
2815
2815
  response.writeHead(200, {
2816
2816
  ...CORS,
2817
2817
  "content-type": "application/json; charset=utf-8",
2818
- // A miss is worth asking again in a few hours; a hit lasts the day.
2819
- "cache-control": match ? "public, max-age=3600" : "public, max-age=600",
2818
+ // Briefly: the server remembers for days, so the browser need not,
2819
+ // and an hour of browser cache hid a better answer for an hour.
2820
+ "cache-control": match ? "public, max-age=300" : "public, max-age=120",
2820
2821
  });
2821
2822
  response.end(JSON.stringify({ match }));
2822
2823
  return;
package/web/dist/sw.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* nixamp service worker — generated, do not edit */
2
- const CACHE = "nixamp-1789049889297";
2
+ const CACHE = "nixamp-1789050586501";
3
3
  const PRECACHE = [
4
4
  "/",
5
5
  "/apple-touch-icon.png",