@tinyshed/tinystore 0.4.0 → 0.4.1

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/logger.d.ts CHANGED
@@ -131,7 +131,12 @@ export declare class Logger {
131
131
  error(message: string, attrs?: Fields): void;
132
132
  /** An event of the stream: a record named for it, with no level and no body. */
133
133
  event(name: string, attrs?: Fields): void;
134
- /** The logger of the same stream, buffer and console, its context these fields besides its own. */
134
+ /**
135
+ * The logger of the same stream, buffer and console, its context these
136
+ * fields besides its own: a key it had already takes the new value where
137
+ * it stood, as an object spread does, where it prints, in what is kept
138
+ * and for a query's `where`.
139
+ */
135
140
  with(context: Fields): Logger;
136
141
  /** Hands what the buffer holds to the server now, as the timer does every second. */
137
142
  flush(): Promise<void>;
package/dist/logger.js CHANGED
@@ -303,12 +303,15 @@ export class Logger {
303
303
  }
304
304
  this.#emit({ event: name }, attrs);
305
305
  }
306
- /** The logger of the same stream, buffer and console, its context these fields besides its own. */
306
+ /**
307
+ * The logger of the same stream, buffer and console, its context these
308
+ * fields besides its own: a key it had already takes the new value where
309
+ * it stood, as an object spread does, where it prints, in what is kept
310
+ * and for a query's `where`.
311
+ */
307
312
  with(context) {
308
- return new Logger(this.#shared, [
309
- ...this.#context,
310
- ...encodeFields(context, this.#shared.redact, this.#shared.replace),
311
- ]);
313
+ const added = encodeFields(context, this.#shared.redact, this.#shared.replace);
314
+ return new Logger(this.#shared, onceEach(this.#context, added));
312
315
  }
313
316
  /** Hands what the buffer holds to the server now, as the timer does every second. */
314
317
  async flush() {
@@ -380,6 +383,27 @@ export class Logger {
380
383
  }
381
384
  }
382
385
  }
386
+ /**
387
+ * A context's key, JSON pairs with `added`'s after them, each key once: where
388
+ * it was first given, holding the value given last.
389
+ *
390
+ * ```text
391
+ * component=http user=7, then component=access → component=access user=7
392
+ * ```
393
+ */
394
+ function onceEach(context, added) {
395
+ const once = [...context];
396
+ for (let i = 0; i < added.length; i += 2) {
397
+ const at = once.findIndex((key, place) => place % 2 === 0 && key === added[i]);
398
+ if (at === -1) {
399
+ once.push(added[i], added[i + 1]);
400
+ }
401
+ else {
402
+ once[at + 1] = added[i + 1];
403
+ }
404
+ }
405
+ return once;
406
+ }
383
407
  /** Whether a logger prints a line of level: it has a console, and the level is the level printed or above. */
384
408
  function prints(shared, level) {
385
409
  return shared.print !== undefined && level >= (shared.printed ?? shared.kept);
package/dist/search.d.ts CHANGED
@@ -54,6 +54,12 @@ export interface Query {
54
54
  vectorWeight?: number | undefined;
55
55
  rerank?: boolean | undefined;
56
56
  } | undefined;
57
+ /**
58
+ * the last word read as the start of a word too, as a search box types:
59
+ * `crypt` finds `cryptography` as well, at half its field's weight; a
60
+ * word a space follows is whole, and so is one of a single letter
61
+ */
62
+ prefix?: boolean | undefined;
57
63
  /** 10 unless said; offset and limit together 1000 at most */
58
64
  limit?: number | undefined;
59
65
  offset?: number | undefined;
package/dist/search.js CHANGED
@@ -48,6 +48,7 @@ class Searchable {
48
48
  vector,
49
49
  vectorWeight: asked.hybrid?.vectorWeight,
50
50
  rerank: asked.hybrid?.rerank,
51
+ prefix: asked.prefix,
51
52
  where,
52
53
  offset: asked.offset,
53
54
  limit: asked.limit,
@@ -2399,6 +2399,8 @@ export declare const SearchQuery: import("./codec.ts").Message<{
2399
2399
  readonly offset: readonly [7, import("./codec.ts").Codec<number, number>];
2400
2400
  /** 10 when absent; offset and limit together 1000 at most */
2401
2401
  readonly limit: readonly [8, import("./codec.ts").Codec<number, number>];
2402
+ /** the last word read as the start of a word too, as a search box types */
2403
+ readonly prefix: readonly [9, import("./codec.ts").Codec<boolean, boolean>];
2402
2404
  }>;
2403
2405
  /**
2404
2406
  * A hit: a document and its value, or a table's row, a value a column of
@@ -9488,6 +9488,8 @@ export const SearchQuery = message('search.Query', {
9488
9488
  offset: [7, uint],
9489
9489
  /** 10 when absent; offset and limit together 1000 at most */
9490
9490
  limit: [8, uint],
9491
+ /** the last word read as the start of a word too, as a search box types */
9492
+ prefix: [9, bool],
9491
9493
  }, {
9492
9494
  write(w, v) {
9493
9495
  const head = w.openMap();
@@ -9532,6 +9534,11 @@ export const SearchQuery = message('search.Query', {
9532
9534
  w.uint(v.limit);
9533
9535
  n++;
9534
9536
  }
9537
+ if (v.prefix !== undefined) {
9538
+ w.field(9);
9539
+ w.bool(v.prefix);
9540
+ n++;
9541
+ }
9535
9542
  w.closeMap(head, n);
9536
9543
  },
9537
9544
  read(r) {
@@ -9543,6 +9550,7 @@ export const SearchQuery = message('search.Query', {
9543
9550
  let $where;
9544
9551
  let $offset;
9545
9552
  let $limit;
9553
+ let $prefix;
9546
9554
  for (let n = r.message(); n > 0; n--) {
9547
9555
  switch (r.field()) {
9548
9556
  case 1:
@@ -9569,6 +9577,9 @@ export const SearchQuery = message('search.Query', {
9569
9577
  case 8:
9570
9578
  $limit = r.uint();
9571
9579
  break;
9580
+ case 9:
9581
+ $prefix = r.bool();
9582
+ break;
9572
9583
  default:
9573
9584
  r.skip();
9574
9585
  }
@@ -9583,6 +9594,7 @@ export const SearchQuery = message('search.Query', {
9583
9594
  where: $where,
9584
9595
  offset: $offset,
9585
9596
  limit: $limit,
9597
+ prefix: $prefix,
9586
9598
  };
9587
9599
  },
9588
9600
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinyshed/tinystore",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "TinyStore for Bun and Node: kv, jobs, blobs, SQL, records and metrics in one directory, served by a sidecar",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://tinyshed.org/tinystore",
@@ -31,12 +31,12 @@
31
31
  "README.md"
32
32
  ],
33
33
  "optionalDependencies": {
34
- "@tinyshed/tinystore-linux-x64": "0.4.0",
35
- "@tinyshed/tinystore-linux-arm64": "0.4.0",
36
- "@tinyshed/tinystore-linux-x64-musl": "0.4.0",
37
- "@tinyshed/tinystore-linux-arm64-musl": "0.4.0",
38
- "@tinyshed/tinystore-darwin-arm64": "0.4.0",
39
- "@tinyshed/tinystore-darwin-x64": "0.4.0",
40
- "@tinyshed/tinystore-win32-x64": "0.4.0"
34
+ "@tinyshed/tinystore-linux-x64": "0.4.1",
35
+ "@tinyshed/tinystore-linux-arm64": "0.4.1",
36
+ "@tinyshed/tinystore-linux-x64-musl": "0.4.1",
37
+ "@tinyshed/tinystore-linux-arm64-musl": "0.4.1",
38
+ "@tinyshed/tinystore-darwin-arm64": "0.4.1",
39
+ "@tinyshed/tinystore-darwin-x64": "0.4.1",
40
+ "@tinyshed/tinystore-win32-x64": "0.4.1"
41
41
  }
42
42
  }
package/src/logger.ts CHANGED
@@ -460,12 +460,15 @@ export class Logger {
460
460
  this.#emit({ event: name }, attrs)
461
461
  }
462
462
 
463
- /** The logger of the same stream, buffer and console, its context these fields besides its own. */
463
+ /**
464
+ * The logger of the same stream, buffer and console, its context these
465
+ * fields besides its own: a key it had already takes the new value where
466
+ * it stood, as an object spread does, where it prints, in what is kept
467
+ * and for a query's `where`.
468
+ */
464
469
  with(context: Fields): Logger {
465
- return new Logger(this.#shared, [
466
- ...this.#context,
467
- ...encodeFields(context, this.#shared.redact, this.#shared.replace),
468
- ])
470
+ const added = encodeFields(context, this.#shared.redact, this.#shared.replace)
471
+ return new Logger(this.#shared, onceEach(this.#context, added))
469
472
  }
470
473
 
471
474
  /** Hands what the buffer holds to the server now, as the timer does every second. */
@@ -543,6 +546,27 @@ export class Logger {
543
546
  }
544
547
  }
545
548
 
549
+ /**
550
+ * A context's key, JSON pairs with `added`'s after them, each key once: where
551
+ * it was first given, holding the value given last.
552
+ *
553
+ * ```text
554
+ * component=http user=7, then component=access → component=access user=7
555
+ * ```
556
+ */
557
+ function onceEach(context: readonly string[], added: readonly string[]): string[] {
558
+ const once = [...context]
559
+ for (let i = 0; i < added.length; i += 2) {
560
+ const at = once.findIndex((key, place) => place % 2 === 0 && key === added[i])
561
+ if (at === -1) {
562
+ once.push(added[i] as string, added[i + 1] as string)
563
+ } else {
564
+ once[at + 1] = added[i + 1] as string
565
+ }
566
+ }
567
+ return once
568
+ }
569
+
546
570
  /** Whether a logger prints a line of level: it has a console, and the level is the level printed or above. */
547
571
  function prints(shared: Shared, level: number): boolean {
548
572
  return shared.print !== undefined && level >= (shared.printed ?? shared.kept)
package/src/search.ts CHANGED
@@ -85,6 +85,12 @@ export interface Query {
85
85
  where?: Where | undefined
86
86
  /** this search's way of combining its words and its vector, in place of the index's */
87
87
  hybrid?: { vectorWeight?: number | undefined; rerank?: boolean | undefined } | undefined
88
+ /**
89
+ * the last word read as the start of a word too, as a search box types:
90
+ * `crypt` finds `cryptography` as well, at half its field's weight; a
91
+ * word a space follows is whole, and so is one of a single letter
92
+ */
93
+ prefix?: boolean | undefined
88
94
  /** 10 unless said; offset and limit together 1000 at most */
89
95
  limit?: number | undefined
90
96
  offset?: number | undefined
@@ -187,6 +193,7 @@ abstract class Searchable<T> {
187
193
  vector,
188
194
  vectorWeight: asked.hybrid?.vectorWeight,
189
195
  rerank: asked.hybrid?.rerank,
196
+ prefix: asked.prefix,
190
197
  where,
191
198
  offset: asked.offset,
192
199
  limit: asked.limit,
@@ -10239,6 +10239,8 @@ export const SearchQuery = message(
10239
10239
  offset: [7, uint],
10240
10240
  /** 10 when absent; offset and limit together 1000 at most */
10241
10241
  limit: [8, uint],
10242
+ /** the last word read as the start of a word too, as a search box types */
10243
+ prefix: [9, bool],
10242
10244
  },
10243
10245
  {
10244
10246
  write(w, v) {
@@ -10284,6 +10286,11 @@ export const SearchQuery = message(
10284
10286
  w.uint(v.limit)
10285
10287
  n++
10286
10288
  }
10289
+ if (v.prefix !== undefined) {
10290
+ w.field(9)
10291
+ w.bool(v.prefix)
10292
+ n++
10293
+ }
10287
10294
  w.closeMap(head, n)
10288
10295
  },
10289
10296
  read(r) {
@@ -10295,6 +10302,7 @@ export const SearchQuery = message(
10295
10302
  let $where: string | undefined
10296
10303
  let $offset: number | undefined
10297
10304
  let $limit: number | undefined
10305
+ let $prefix: boolean | undefined
10298
10306
  for (let n = r.message(); n > 0; n--) {
10299
10307
  switch (r.field()) {
10300
10308
  case 1:
@@ -10321,6 +10329,9 @@ export const SearchQuery = message(
10321
10329
  case 8:
10322
10330
  $limit = r.uint()
10323
10331
  break
10332
+ case 9:
10333
+ $prefix = r.bool()
10334
+ break
10324
10335
  default:
10325
10336
  r.skip()
10326
10337
  }
@@ -10335,6 +10346,7 @@ export const SearchQuery = message(
10335
10346
  where: $where,
10336
10347
  offset: $offset,
10337
10348
  limit: $limit,
10349
+ prefix: $prefix,
10338
10350
  }
10339
10351
  },
10340
10352
  },