@yoch/frozenminisearch 1.0.2 → 1.2.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.
@@ -113,7 +113,7 @@ type SearchOptionsWithDefaults = SearchOptions & {
113
113
  bm25: BM25Params;
114
114
  };
115
115
  /**
116
- * Configuration options passed to the {@link MiniSearch} constructor.
116
+ * Configuration options compatible with the MiniSearch constructor.
117
117
  *
118
118
  * @typeParam T The type of documents being indexed.
119
119
  */
@@ -134,7 +134,7 @@ type Options<T = any> = {
134
134
  processTerm?: (term: string, fieldName?: string) => string | string[] | null | undefined | false;
135
135
  /** Function called to log messages from the library. */
136
136
  logger?: (level: LogLevel, message: string, code?: string) => void;
137
- /** Auto-vacuum behaviour after {@link MiniSearch.discard}; defaults to `true`. */
137
+ /** Auto-vacuum behaviour after MiniSearch `discard`; defaults to `true`. */
138
138
  autoVacuum?: boolean | AutoVacuumOptions;
139
139
  /** Default search options. */
140
140
  searchOptions?: SearchOptions;
@@ -158,6 +158,20 @@ type OptionsWithDefaults<T = any> = Options<T> & {
158
158
  searchOptions: SearchOptionsWithDefaults;
159
159
  autoSuggestOptions: SearchOptions;
160
160
  };
161
+ /** Compression codec selection for frozen binary snapshots. */
162
+ type BinaryCompression = 'auto' | 'raw' | 'zstd' | 'zlib';
163
+ /** Options for `saveBinarySync()` / `saveBinaryAsync()`. */
164
+ type SaveBinaryOptions = {
165
+ /**
166
+ * Compression codec for the payload.
167
+ * - `auto`: one pass; payloads under 64 B stay raw; otherwise zstd when available
168
+ * (else zlib on Node < 22.15), kept only when strictly smaller than raw
169
+ * - `raw`: never compress
170
+ * - `zstd`: always zstd-compress, even when larger than raw; requires Node 22.15+ to write
171
+ * - `zlib`: always deflate, even when larger than raw; readable on Node 20+
172
+ */
173
+ compression?: BinaryCompression;
174
+ };
161
175
  /**
162
176
  * A search-completion suggestion.
163
177
  */
@@ -459,7 +473,7 @@ interface FrozenMemoryBreakdown {
459
473
  /**
460
474
  * Low-level parameters for {@link assembleFrozen} (custom frozen index pipelines).
461
475
  * Field types are part of the public surface for advanced assembly; typical apps use
462
- * {@link buildFrozenFromDocuments}, {@link FrozenMiniSearch.fromMiniSearchJson}, or binary load instead.
476
+ * {@link buildFrozenFromDocuments}, {@link FrozenMiniSearch.fromJson}, or binary load instead.
463
477
  */
464
478
  interface FrozenAssembleParams<T = any> {
465
479
  options: OptionsWithDefaults<T>;
@@ -479,7 +493,7 @@ interface FrozenAssembleParams<T = any> {
479
493
  postings: FrozenPostingsLayout;
480
494
  }
481
495
 
482
- /** Lucaong MiniSearch JSON snapshot (`toJSON` / `loadJSON` wire format). */
496
+ /** MiniSearch JSON snapshot (`toJSON` wire format, `serializationVersion` 1 or 2). */
483
497
  type SerializedIndexEntry = Record<string, number>;
484
498
  type MiniSearchSnapshot = {
485
499
  documentCount: number;
@@ -596,28 +610,37 @@ declare class FrozenMiniSearch<T = any> {
596
610
  search(query: Query, searchOptions?: SearchOptions): SearchResult[];
597
611
  autoSuggest(queryString: string, options?: SearchOptions): Suggestion[];
598
612
  /** Serialize this index as a frozen binary snapshot (synchronous). */
599
- saveBinarySync(): Buffer;
600
- /** Non-blocking zstd compression; same output as {@link saveBinarySync}. */
601
- saveBinaryAsync(): Promise<Buffer>;
613
+ saveBinarySync(saveOptions?: SaveBinaryOptions): Buffer;
614
+ /** Non-blocking snapshot serialization with the selected compression codec. */
615
+ saveBinaryAsync(saveOptions?: SaveBinaryOptions): Promise<Buffer>;
602
616
  /** Load a frozen binary snapshot. */
603
617
  static loadBinarySync<T>(buffer: Buffer, options?: Options<T>): FrozenMiniSearch<T>;
604
- /** Load a frozen binary snapshot with streaming zstd decompression (bounded memory). */
618
+ /** Load a frozen binary snapshot with streaming decompression when needed (bounded memory). */
605
619
  static loadBinaryAsync<T>(buffer: Buffer, options?: Options<T>): Promise<FrozenMiniSearch<T>>;
606
620
  private static fromBinarySnapshot;
607
621
  /** Build a read-only index in one pass from documents. */
608
622
  static fromDocuments<T>(documents: readonly T[], options: Options<T>): FrozenMiniSearch<T>;
609
623
  /**
610
- * Convert a lucaong MiniSearch JSON snapshot (`toJSON` / `loadJSON` wire format) into a
611
- * frozen index. No runtime dependency on the `minisearch` package.
624
+ * Export this index as a MiniSearch wire snapshot (`serializationVersion: 2`).
625
+ * Use for migration or interchange with the `minisearch` package (`JSON.stringify` works via this method).
626
+ * Not the primary persistence format — prefer {@link saveBinarySync} for production (size and load time).
627
+ * Term order in `index` may differ from MiniSearch native `toJSON`; search scores stay equivalent.
628
+ */
629
+ toJSON(): MiniSearchSnapshot;
630
+ /**
631
+ * Build a new frozen index **from** a MiniSearch JSON snapshot string (import / migration).
632
+ * Accepts the wire format produced by MiniSearch `toJSON` or by {@link toJSON} on this class.
633
+ * Distinct from {@link loadBinarySync}: JSON is MiniSearch interchange, not the native frozen binary.
634
+ * No runtime dependency on the `minisearch` package.
612
635
  */
613
- static fromMiniSearchJson<T>(json: string, options?: Options<T>): FrozenMiniSearch<T>;
636
+ static fromJson<T>(json: string, options?: Options<T>): FrozenMiniSearch<T>;
614
637
  /**
615
- * Same as {@link fromMiniSearchJson} with a pre-parsed snapshot object.
638
+ * Same as {@link fromJson} with a pre-parsed snapshot object.
616
639
  * `storedFields` are shallow-copied; callers must not mutate nested values
617
640
  * after load if they intend to keep the index immutable.
618
641
  */
619
642
  static fromMiniSearchSnapshot<T>(snapshot: MiniSearchSnapshot, options?: Options<T>): FrozenMiniSearch<T>;
620
- /** Accepts any object exposing `toJSON()` in lucaong MiniSearch snapshot shape. */
643
+ /** Accepts any object exposing `toJSON()` in MiniSearch snapshot shape. */
621
644
  static fromMiniSearch<T>(source: {
622
645
  toJSON(): MiniSearchSnapshot;
623
646
  }, options?: Options<T>): FrozenMiniSearch<T>;
@@ -634,4 +657,4 @@ declare class FrozenMiniSearch<T = any> {
634
657
  }
635
658
 
636
659
  export { AND, AND_NOT, FrozenIndexBuilder, FrozenMiniSearch, OR, assembleFrozen, buildFrozenFromDocuments, createFrozenIndexBuilder, FrozenMiniSearch as default, freezeFrozenIndexBuilder, frozenMemoryBreakdown };
637
- export type { BM25Params, CombinationOperator, FrozenAssembleParams, FrozenIndexBuilderHints, FrozenMemoryBreakdown, LogLevel, LowercaseCombinationOperator, MatchInfo, MiniSearchSnapshot, Options, Query, QueryCombination, SearchOptions, SearchResult, SerializedIndexEntry, Suggestion, Wildcard };
660
+ export type { BM25Params, BinaryCompression, CombinationOperator, FrozenAssembleParams, FrozenIndexBuilderHints, FrozenMemoryBreakdown, LogLevel, LowercaseCombinationOperator, MatchInfo, MiniSearchSnapshot, Options, Query, QueryCombination, SaveBinaryOptions, SearchOptions, SearchResult, SerializedIndexEntry, Suggestion, Wildcard };