@tscircuit/cli 0.1.1467 → 0.1.1469

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/cli/main.js CHANGED
@@ -7797,6 +7797,18 @@ var require_semver = __commonJS((exports2, module2) => {
7797
7797
  var { safeRe: re, t } = require_re();
7798
7798
  var parseOptions = require_parse_options();
7799
7799
  var { compareIdentifiers } = require_identifiers();
7800
+ var isPrereleaseIdentifier = (prerelease, identifier) => {
7801
+ const identifiers = identifier.split(".");
7802
+ if (identifiers.length > prerelease.length) {
7803
+ return false;
7804
+ }
7805
+ for (let i = 0;i < identifiers.length; i++) {
7806
+ if (compareIdentifiers(prerelease[i], identifiers[i]) !== 0) {
7807
+ return false;
7808
+ }
7809
+ }
7810
+ return true;
7811
+ };
7800
7812
 
7801
7813
  class SemVer {
7802
7814
  constructor(version2, options) {
@@ -8036,8 +8048,9 @@ var require_semver = __commonJS((exports2, module2) => {
8036
8048
  if (identifierBase === false) {
8037
8049
  prerelease = [identifier];
8038
8050
  }
8039
- if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
8040
- if (isNaN(this.prerelease[1])) {
8051
+ if (isPrereleaseIdentifier(this.prerelease, identifier)) {
8052
+ const prereleaseBase = this.prerelease[identifier.split(".").length];
8053
+ if (isNaN(prereleaseBase)) {
8041
8054
  this.prerelease = prerelease;
8042
8055
  }
8043
8056
  } else {
@@ -8508,6 +8521,7 @@ var require_range = __commonJS((exports2, module2) => {
8508
8521
  return this.range;
8509
8522
  }
8510
8523
  parseRange(range) {
8524
+ range = range.replace(BUILDSTRIPRE, "");
8511
8525
  const memoOpts = (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE);
8512
8526
  const memoKey = memoOpts + ":" + range;
8513
8527
  const cached = cache.get(memoKey);
@@ -8589,12 +8603,14 @@ var require_range = __commonJS((exports2, module2) => {
8589
8603
  var SemVer = require_semver();
8590
8604
  var {
8591
8605
  safeRe: re,
8606
+ src,
8592
8607
  t,
8593
8608
  comparatorTrimReplace,
8594
8609
  tildeTrimReplace,
8595
8610
  caretTrimReplace
8596
8611
  } = require_re();
8597
8612
  var { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require_constants();
8613
+ var BUILDSTRIPRE = new RegExp(src[t.BUILD], "g");
8598
8614
  var isNullSet = (c) => c.value === "<0.0.0-0";
8599
8615
  var isAny = (c) => c.value === "";
8600
8616
  var isSatisfiable = (comparators, options) => {
@@ -8623,6 +8639,7 @@ var require_range = __commonJS((exports2, module2) => {
8623
8639
  return comp;
8624
8640
  };
8625
8641
  var isX = (id) => !id || id.toLowerCase() === "x" || id === "*";
8642
+ var invalidXRangeOrder = (M, m, p) => isX(M) && !isX(m) || isX(m) && p && !isX(p);
8626
8643
  var replaceTildes = (comp, options) => {
8627
8644
  return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" ");
8628
8645
  };
@@ -8682,9 +8699,9 @@ var require_range = __commonJS((exports2, module2) => {
8682
8699
  debug("no pr");
8683
8700
  if (M === "0") {
8684
8701
  if (m === "0") {
8685
- ret = `>=${M}.${m}.${p}${z} <${M}.${m}.${+p + 1}-0`;
8702
+ ret = `>=${M}.${m}.${p} <${M}.${m}.${+p + 1}-0`;
8686
8703
  } else {
8687
- ret = `>=${M}.${m}.${p}${z} <${M}.${+m + 1}.0-0`;
8704
+ ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
8688
8705
  }
8689
8706
  } else {
8690
8707
  ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
@@ -8703,6 +8720,9 @@ var require_range = __commonJS((exports2, module2) => {
8703
8720
  const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
8704
8721
  return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
8705
8722
  debug("xRange", comp, ret, gtlt, M, m, p, pr);
8723
+ if (invalidXRangeOrder(M, m, p)) {
8724
+ return comp;
8725
+ }
8706
8726
  const xM = isX(M);
8707
8727
  const xm = xM || isX(m);
8708
8728
  const xp = xm || isX(p);
@@ -9311,7 +9331,7 @@ var require_subset = __commonJS((exports2, module2) => {
9311
9331
  if (higher === c && higher !== gt) {
9312
9332
  return false;
9313
9333
  }
9314
- } else if (gt.operator === ">=" && !satisfies(gt.semver, String(c), options)) {
9334
+ } else if (gt.operator === ">=" && !c.test(gt.semver)) {
9315
9335
  return false;
9316
9336
  }
9317
9337
  }
@@ -9326,7 +9346,7 @@ var require_subset = __commonJS((exports2, module2) => {
9326
9346
  if (lower === c && lower !== lt) {
9327
9347
  return false;
9328
9348
  }
9329
- } else if (lt.operator === "<=" && !satisfies(lt.semver, String(c), options)) {
9349
+ } else if (lt.operator === "<=" && !c.test(lt.semver)) {
9330
9350
  return false;
9331
9351
  }
9332
9352
  }
@@ -22721,7 +22741,7 @@ var require_isarray = __commonJS((exports2, module2) => {
22721
22741
  };
22722
22742
  });
22723
22743
 
22724
- // node_modules/safe-buffer/index.js
22744
+ // node_modules/readable-stream/node_modules/safe-buffer/index.js
22725
22745
  var require_safe_buffer = __commonJS((exports2, module2) => {
22726
22746
  var buffer = __require("buffer");
22727
22747
  var Buffer2 = buffer.Buffer;
@@ -23575,9 +23595,64 @@ var require__stream_duplex = __commonJS((exports2, module2) => {
23575
23595
  };
23576
23596
  });
23577
23597
 
23598
+ // node_modules/string_decoder/node_modules/safe-buffer/index.js
23599
+ var require_safe_buffer2 = __commonJS((exports2, module2) => {
23600
+ var buffer = __require("buffer");
23601
+ var Buffer2 = buffer.Buffer;
23602
+ function copyProps(src, dst) {
23603
+ for (var key in src) {
23604
+ dst[key] = src[key];
23605
+ }
23606
+ }
23607
+ if (Buffer2.from && Buffer2.alloc && Buffer2.allocUnsafe && Buffer2.allocUnsafeSlow) {
23608
+ module2.exports = buffer;
23609
+ } else {
23610
+ copyProps(buffer, exports2);
23611
+ exports2.Buffer = SafeBuffer;
23612
+ }
23613
+ function SafeBuffer(arg, encodingOrOffset, length) {
23614
+ return Buffer2(arg, encodingOrOffset, length);
23615
+ }
23616
+ copyProps(Buffer2, SafeBuffer);
23617
+ SafeBuffer.from = function(arg, encodingOrOffset, length) {
23618
+ if (typeof arg === "number") {
23619
+ throw new TypeError("Argument must not be a number");
23620
+ }
23621
+ return Buffer2(arg, encodingOrOffset, length);
23622
+ };
23623
+ SafeBuffer.alloc = function(size, fill, encoding) {
23624
+ if (typeof size !== "number") {
23625
+ throw new TypeError("Argument must be a number");
23626
+ }
23627
+ var buf = Buffer2(size);
23628
+ if (fill !== undefined) {
23629
+ if (typeof encoding === "string") {
23630
+ buf.fill(fill, encoding);
23631
+ } else {
23632
+ buf.fill(fill);
23633
+ }
23634
+ } else {
23635
+ buf.fill(0);
23636
+ }
23637
+ return buf;
23638
+ };
23639
+ SafeBuffer.allocUnsafe = function(size) {
23640
+ if (typeof size !== "number") {
23641
+ throw new TypeError("Argument must be a number");
23642
+ }
23643
+ return Buffer2(size);
23644
+ };
23645
+ SafeBuffer.allocUnsafeSlow = function(size) {
23646
+ if (typeof size !== "number") {
23647
+ throw new TypeError("Argument must be a number");
23648
+ }
23649
+ return buffer.SlowBuffer(size);
23650
+ };
23651
+ });
23652
+
23578
23653
  // node_modules/string_decoder/lib/string_decoder.js
23579
23654
  var require_string_decoder = __commonJS((exports2) => {
23580
- var Buffer2 = require_safe_buffer().Buffer;
23655
+ var Buffer2 = require_safe_buffer2().Buffer;
23581
23656
  var isEncoding = Buffer2.isEncoding || function(encoding) {
23582
23657
  encoding = "" + encoding;
23583
23658
  switch (encoding && encoding.toLowerCase()) {
@@ -100688,7 +100763,7 @@ var import_perfect_cli = __toESM2(require_dist2(), 1);
100688
100763
  // lib/getVersion.ts
100689
100764
  import { createRequire as createRequire2 } from "node:module";
100690
100765
  // package.json
100691
- var version = "0.1.1466";
100766
+ var version = "0.1.1468";
100692
100767
  var package_default = {
100693
100768
  name: "@tscircuit/cli",
100694
100769
  version,
@@ -100703,15 +100778,16 @@ var package_default = {
100703
100778
  "@tscircuit/circuit-json-placement-analysis": "^0.0.6",
100704
100779
  "@tscircuit/circuit-json-routing-analysis": "^0.0.1",
100705
100780
  "@tscircuit/circuit-json-schematic-placement-analysis": "github:tscircuit/circuit-json-schematic-placement-analysis#b6d5fe675adc26a2fc988aa081e6fb51e6bf696a",
100706
- "@tscircuit/eval": "^0.0.835",
100781
+ "@tscircuit/eval": "^0.0.915",
100707
100782
  "@tscircuit/fake-snippets": "^0.0.182",
100708
100783
  "@tscircuit/file-server": "^0.0.32",
100709
100784
  "@tscircuit/image-utils": "^0.0.3",
100710
100785
  "@tscircuit/krt-wasm": "^0.1.0",
100711
100786
  "@tscircuit/math-utils": "0.0.36",
100712
- "@tscircuit/props": "^0.0.536",
100787
+ "@tscircuit/props": "^0.0.546",
100713
100788
  "@tscircuit/runframe": "^0.0.2057",
100714
100789
  "@tscircuit/schematic-match-adapt": "^0.0.22",
100790
+ "@tscircuit/solver-utils": "0.0.16",
100715
100791
  "@types/bun": "^1.2.2",
100716
100792
  "@types/configstore": "^6.0.2",
100717
100793
  "@types/debug": "^4.1.12",
@@ -100762,7 +100838,7 @@ var package_default = {
100762
100838
  semver: "^7.6.3",
100763
100839
  stepts: "^0.0.3",
100764
100840
  tempy: "^3.1.0",
100765
- tscircuit: "0.0.1829-libonly",
100841
+ tscircuit: "^0.0.1849-libonly",
100766
100842
  tsx: "^4.7.1",
100767
100843
  "typed-ky": "^0.0.4",
100768
100844
  zod: "^3.23.8"
@@ -274069,12 +274145,10 @@ function isArray(value) {
274069
274145
  return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
274070
274146
  }
274071
274147
  function baseToString(value) {
274072
- if (typeof value == "string") {
274148
+ if (typeof value == "string")
274073
274149
  return value;
274074
- }
274075
- if (typeof value === "bigint") {
274150
+ if (typeof value === "bigint")
274076
274151
  return value.toString();
274077
- }
274078
274152
  const result = value + "";
274079
274153
  return result == "0" && 1 / value == -Infinity ? "-0" : result;
274080
274154
  }
@@ -274106,13 +274180,14 @@ function getTag(value) {
274106
274180
  return value == null ? value === undefined ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
274107
274181
  }
274108
274182
  var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
274183
+ var INVALID_DOC_INDEX = "Invalid doc index: must be a non-negative integer within the bounds of the docs array";
274109
274184
  var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
274110
274185
  var PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
274111
274186
  var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
274112
274187
  var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
274188
+ var FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED = "Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.";
274113
274189
  var hasOwn = Object.prototype.hasOwnProperty;
274114
-
274115
- class KeyStore {
274190
+ var KeyStore = class {
274116
274191
  constructor(keys) {
274117
274192
  this._keys = [];
274118
274193
  this._keyMap = {};
@@ -274136,7 +274211,7 @@ class KeyStore {
274136
274211
  toJSON() {
274137
274212
  return JSON.stringify(this._keys);
274138
274213
  }
274139
- }
274214
+ };
274140
274215
  function createKey(key) {
274141
274216
  let path67 = null;
274142
274217
  let id2 = null;
@@ -274148,20 +274223,18 @@ function createKey(key) {
274148
274223
  path67 = createKeyPath(key);
274149
274224
  id2 = createKeyId(key);
274150
274225
  } else {
274151
- if (!hasOwn.call(key, "name")) {
274226
+ if (!hasOwn.call(key, "name"))
274152
274227
  throw new Error(MISSING_KEY_PROPERTY("name"));
274153
- }
274154
274228
  const name = key.name;
274155
274229
  src = name;
274156
- if (hasOwn.call(key, "weight")) {
274230
+ if (hasOwn.call(key, "weight") && key.weight !== undefined) {
274157
274231
  weight = key.weight;
274158
- if (weight <= 0) {
274159
- throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
274160
- }
274232
+ if (weight <= 0)
274233
+ throw new Error(INVALID_KEY_WEIGHT_VALUE(createKeyId(name)));
274161
274234
  }
274162
274235
  path67 = createKeyPath(name);
274163
274236
  id2 = createKeyId(name);
274164
- getFn = key.getFn;
274237
+ getFn = key.getFn ?? null;
274165
274238
  }
274166
274239
  return {
274167
274240
  path: path67,
@@ -274181,33 +274254,28 @@ function get(obj, path67) {
274181
274254
  const list = [];
274182
274255
  let arr = false;
274183
274256
  const deepGet = (obj2, path68, index, arrayIndex) => {
274184
- if (!isDefined(obj2)) {
274257
+ if (!isDefined(obj2))
274185
274258
  return;
274186
- }
274187
- if (!path68[index]) {
274259
+ if (!path68[index])
274188
274260
  list.push(arrayIndex !== undefined ? {
274189
274261
  v: obj2,
274190
274262
  i: arrayIndex
274191
274263
  } : obj2);
274192
- } else {
274193
- const key = path68[index];
274194
- const value = obj2[key];
274195
- if (!isDefined(value)) {
274264
+ else {
274265
+ const value = obj2[path68[index]];
274266
+ if (!isDefined(value))
274196
274267
  return;
274197
- }
274198
- if (index === path68.length - 1 && (isString2(value) || isNumber2(value) || isBoolean(value) || typeof value === "bigint")) {
274268
+ if (index === path68.length - 1 && (isString2(value) || isNumber2(value) || isBoolean(value) || typeof value === "bigint"))
274199
274269
  list.push(arrayIndex !== undefined ? {
274200
274270
  v: toString2(value),
274201
274271
  i: arrayIndex
274202
274272
  } : toString2(value));
274203
- } else if (isArray(value)) {
274273
+ else if (isArray(value)) {
274204
274274
  arr = true;
274205
- for (let i2 = 0, len = value.length;i2 < len; i2 += 1) {
274275
+ for (let i2 = 0, len = value.length;i2 < len; i2 += 1)
274206
274276
  deepGet(value[i2], path68, index + 1, i2);
274207
- }
274208
- } else if (path68.length) {
274277
+ } else if (path68.length)
274209
274278
  deepGet(value, path68, index + 1, arrayIndex);
274210
- }
274211
274279
  }
274212
274280
  };
274213
274281
  deepGet(obj, isString2(path67) ? path67.split(".") : path67, 0);
@@ -274234,6 +274302,8 @@ var FuzzyOptions = {
274234
274302
  var AdvancedOptions = {
274235
274303
  useExtendedSearch: false,
274236
274304
  useTokenSearch: false,
274305
+ tokenize: undefined,
274306
+ tokenMatch: "any",
274237
274307
  getFn: get,
274238
274308
  ignoreLocation: false,
274239
274309
  ignoreFieldNorm: false,
@@ -274245,18 +274315,24 @@ var Config = Object.freeze({
274245
274315
  ...FuzzyOptions,
274246
274316
  ...AdvancedOptions
274247
274317
  });
274248
- var SPACE = /[^ ]+/g;
274249
274318
  function norm(weight = 1, mantissa = 3) {
274250
- const cache = new Map;
274319
+ const cache = /* @__PURE__ */ new Map;
274251
274320
  const m3 = Math.pow(10, mantissa);
274252
274321
  return {
274253
274322
  get(value) {
274254
- const numTokens = value.match(SPACE).length;
274255
- if (cache.has(numTokens)) {
274323
+ let numTokens = 1;
274324
+ let inSpace = false;
274325
+ for (let i2 = 0;i2 < value.length; i2++)
274326
+ if (value.charCodeAt(i2) === 32) {
274327
+ if (!inSpace) {
274328
+ numTokens++;
274329
+ inSpace = true;
274330
+ }
274331
+ } else
274332
+ inSpace = false;
274333
+ if (cache.has(numTokens))
274256
274334
  return cache.get(numTokens);
274257
- }
274258
- const norm2 = 1 / Math.pow(numTokens, 0.5 * weight);
274259
- const n3 = parseFloat(Math.round(norm2 * m3) / m3);
274335
+ const n3 = Math.round(m3 / Math.pow(numTokens, 0.5 * weight)) / m3;
274260
274336
  cache.set(numTokens, n3);
274261
274337
  return n3;
274262
274338
  },
@@ -274265,12 +274341,8 @@ function norm(weight = 1, mantissa = 3) {
274265
274341
  }
274266
274342
  };
274267
274343
  }
274268
-
274269
- class FuseIndex {
274270
- constructor({
274271
- getFn = Config.getFn,
274272
- fieldNormWeight = Config.fieldNormWeight
274273
- } = {}) {
274344
+ var FuseIndex = class {
274345
+ constructor({ getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
274274
274346
  this.norm = norm(fieldNormWeight, 3);
274275
274347
  this.getFn = getFn;
274276
274348
  this.isCreated = false;
@@ -274293,41 +274365,69 @@ class FuseIndex {
274293
274365
  });
274294
274366
  }
274295
274367
  create() {
274296
- if (this.isCreated || !this.docs.length) {
274368
+ if (this.isCreated || !this.docs.length)
274297
274369
  return;
274298
- }
274299
274370
  this.isCreated = true;
274300
- if (isString2(this.docs[0])) {
274301
- this.docs.forEach((doc, docIndex) => {
274302
- this._addString(doc, docIndex);
274303
- });
274304
- } else {
274305
- this.docs.forEach((doc, docIndex) => {
274306
- this._addObject(doc, docIndex);
274307
- });
274308
- }
274371
+ const len = this.docs.length;
274372
+ this.records = new Array(len);
274373
+ let recordCount = 0;
274374
+ if (isString2(this.docs[0]))
274375
+ for (let i2 = 0;i2 < len; i2++) {
274376
+ const record = this._createStringRecord(this.docs[i2], i2);
274377
+ if (record)
274378
+ this.records[recordCount++] = record;
274379
+ }
274380
+ else
274381
+ for (let i2 = 0;i2 < len; i2++)
274382
+ this.records[recordCount++] = this._createObjectRecord(this.docs[i2], i2);
274383
+ this.records.length = recordCount;
274309
274384
  this.norm.clear();
274310
274385
  }
274311
- add(doc) {
274312
- const idx = this.size();
274386
+ add(doc, docIndex) {
274387
+ if (!Number.isInteger(docIndex) || docIndex < 0)
274388
+ throw new Error(INVALID_DOC_INDEX);
274313
274389
  if (isString2(doc)) {
274314
- this._addString(doc, idx);
274315
- } else {
274316
- this._addObject(doc, idx);
274390
+ const record2 = this._createStringRecord(doc, docIndex);
274391
+ if (record2)
274392
+ this.records.push(record2);
274393
+ return record2;
274317
274394
  }
274395
+ const record = this._createObjectRecord(doc, docIndex);
274396
+ this.records.push(record);
274397
+ return record;
274318
274398
  }
274319
274399
  removeAt(idx) {
274320
- this.records.splice(idx, 1);
274321
- for (let i2 = idx, len = this.size();i2 < len; i2 += 1) {
274322
- this.records[i2].i -= 1;
274323
- }
274400
+ if (!Number.isInteger(idx) || idx < 0)
274401
+ throw new Error(INVALID_DOC_INDEX);
274402
+ for (let i2 = 0, len = this.records.length;i2 < len; i2 += 1)
274403
+ if (this.records[i2].i === idx) {
274404
+ this.records.splice(i2, 1);
274405
+ break;
274406
+ }
274407
+ for (let i2 = 0, len = this.records.length;i2 < len; i2 += 1)
274408
+ if (this.records[i2].i > idx)
274409
+ this.records[i2].i -= 1;
274324
274410
  }
274325
274411
  removeAll(indices) {
274326
- for (let i2 = indices.length - 1;i2 >= 0; i2 -= 1) {
274327
- this.records.splice(indices[i2], 1);
274328
- }
274329
- for (let i2 = 0, len = this.records.length;i2 < len; i2 += 1) {
274330
- this.records[i2].i = i2;
274412
+ const toRemove = /* @__PURE__ */ new Set;
274413
+ for (const v3 of indices)
274414
+ if (Number.isInteger(v3) && v3 >= 0)
274415
+ toRemove.add(v3);
274416
+ if (toRemove.size === 0)
274417
+ return;
274418
+ this.records = this.records.filter((r4) => !toRemove.has(r4.i));
274419
+ const sorted = Array.from(toRemove).sort((a2, b) => a2 - b);
274420
+ for (const record of this.records) {
274421
+ let lo3 = 0;
274422
+ let hi3 = sorted.length;
274423
+ while (lo3 < hi3) {
274424
+ const mid = lo3 + hi3 >>> 1;
274425
+ if (sorted[mid] < record.i)
274426
+ lo3 = mid + 1;
274427
+ else
274428
+ hi3 = mid;
274429
+ }
274430
+ record.i -= lo3;
274331
274431
  }
274332
274432
  }
274333
274433
  getValueForItemAtKeyId(item, keyId) {
@@ -274336,34 +274436,31 @@ class FuseIndex {
274336
274436
  size() {
274337
274437
  return this.records.length;
274338
274438
  }
274339
- _addString(doc, docIndex) {
274340
- if (!isDefined(doc) || isBlank(doc)) {
274341
- return;
274342
- }
274343
- const record = {
274439
+ _createStringRecord(doc, docIndex) {
274440
+ if (!isDefined(doc) || isBlank(doc))
274441
+ return null;
274442
+ return {
274344
274443
  v: doc,
274345
274444
  i: docIndex,
274346
274445
  n: this.norm.get(doc)
274347
274446
  };
274348
- this.records.push(record);
274349
274447
  }
274350
- _addObject(doc, docIndex) {
274448
+ _createObjectRecord(doc, docIndex) {
274351
274449
  const record = {
274352
274450
  i: docIndex,
274353
274451
  $: {}
274354
274452
  };
274355
- this.keys.forEach((key, keyIndex) => {
274453
+ for (let keyIndex = 0, keyLen = this.keys.length;keyIndex < keyLen; keyIndex++) {
274454
+ const key = this.keys[keyIndex];
274356
274455
  const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
274357
- if (!isDefined(value)) {
274358
- return;
274359
- }
274456
+ if (!isDefined(value))
274457
+ continue;
274360
274458
  if (isArray(value)) {
274361
274459
  const subRecords = [];
274362
274460
  for (let i2 = 0, len = value.length;i2 < len; i2 += 1) {
274363
274461
  const item = value[i2];
274364
- if (!isDefined(item)) {
274462
+ if (!isDefined(item))
274365
274463
  continue;
274366
- }
274367
274464
  if (isString2(item)) {
274368
274465
  if (!isBlank(item)) {
274369
274466
  const subRecord = {
@@ -274393,23 +274490,17 @@ class FuseIndex {
274393
274490
  };
274394
274491
  record.$[keyIndex] = subRecord;
274395
274492
  }
274396
- });
274397
- this.records.push(record);
274493
+ }
274494
+ return record;
274398
274495
  }
274399
274496
  toJSON() {
274400
274497
  return {
274401
- keys: this.keys.map(({
274402
- getFn,
274403
- ...key
274404
- }) => key),
274498
+ keys: this.keys.map(({ getFn, ...key }) => key),
274405
274499
  records: this.records
274406
274500
  };
274407
274501
  }
274408
- }
274409
- function createIndex(keys, docs, {
274410
- getFn = Config.getFn,
274411
- fieldNormWeight = Config.fieldNormWeight
274412
- } = {}) {
274502
+ };
274503
+ function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
274413
274504
  const myIndex = new FuseIndex({
274414
274505
  getFn,
274415
274506
  fieldNormWeight
@@ -274419,14 +274510,8 @@ function createIndex(keys, docs, {
274419
274510
  myIndex.create();
274420
274511
  return myIndex;
274421
274512
  }
274422
- function parseIndex(data, {
274423
- getFn = Config.getFn,
274424
- fieldNormWeight = Config.fieldNormWeight
274425
- } = {}) {
274426
- const {
274427
- keys,
274428
- records
274429
- } = data;
274513
+ function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
274514
+ const { keys, records } = data;
274430
274515
  const myIndex = new FuseIndex({
274431
274516
  getFn,
274432
274517
  fieldNormWeight
@@ -274442,34 +274527,22 @@ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMat
274442
274527
  let i2 = 0;
274443
274528
  for (let len = matchmask.length;i2 < len; i2 += 1) {
274444
274529
  const match = matchmask[i2];
274445
- if (match && start === -1) {
274530
+ if (match && start === -1)
274446
274531
  start = i2;
274447
- } else if (!match && start !== -1) {
274532
+ else if (!match && start !== -1) {
274448
274533
  end = i2 - 1;
274449
- if (end - start + 1 >= minMatchCharLength) {
274534
+ if (end - start + 1 >= minMatchCharLength)
274450
274535
  indices.push([start, end]);
274451
- }
274452
274536
  start = -1;
274453
274537
  }
274454
274538
  }
274455
- if (matchmask[i2 - 1] && i2 - start >= minMatchCharLength) {
274539
+ if (matchmask[i2 - 1] && i2 - start >= minMatchCharLength)
274456
274540
  indices.push([start, i2 - 1]);
274457
- }
274458
274541
  return indices;
274459
274542
  }
274460
- var MAX_BITS = 32;
274461
- function search(text, pattern, patternAlphabet, {
274462
- location = Config.location,
274463
- distance: distance7 = Config.distance,
274464
- threshold = Config.threshold,
274465
- findAllMatches = Config.findAllMatches,
274466
- minMatchCharLength = Config.minMatchCharLength,
274467
- includeMatches = Config.includeMatches,
274468
- ignoreLocation = Config.ignoreLocation
274469
- } = {}) {
274470
- if (pattern.length > MAX_BITS) {
274471
- throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
274472
- }
274543
+ function search(text, pattern, patternAlphabet, { location = Config.location, distance: distance7 = Config.distance, threshold = Config.threshold, findAllMatches = Config.findAllMatches, minMatchCharLength = Config.minMatchCharLength, includeMatches = Config.includeMatches, ignoreLocation = Config.ignoreLocation } = {}) {
274544
+ if (pattern.length > 32)
274545
+ throw new Error(PATTERN_LENGTH_TOO_LARGE(32));
274473
274546
  const patternLen = pattern.length;
274474
274547
  const textLen = text.length;
274475
274548
  const expectedLocation = Math.max(0, Math.min(location, textLen));
@@ -274502,18 +274575,17 @@ function search(text, pattern, patternAlphabet, {
274502
274575
  bestLocation = -1;
274503
274576
  let lastBitArr = [];
274504
274577
  let finalScore = 1;
274578
+ let bestErrors = 0;
274505
274579
  let binMax = patternLen + textLen;
274506
274580
  const mask = 1 << patternLen - 1;
274507
274581
  for (let i2 = 0;i2 < patternLen; i2 += 1) {
274508
274582
  let binMin = 0;
274509
274583
  let binMid = binMax;
274510
274584
  while (binMin < binMid) {
274511
- const score2 = calcScore(i2, expectedLocation + binMid);
274512
- if (score2 <= currentThreshold) {
274585
+ if (calcScore(i2, expectedLocation + binMid) <= currentThreshold)
274513
274586
  binMin = binMid;
274514
- } else {
274587
+ else
274515
274588
  binMax = binMid;
274516
- }
274517
274589
  binMid = Math.floor((binMax - binMin) / 2 + binMin);
274518
274590
  }
274519
274591
  binMax = binMid;
@@ -274524,42 +274596,41 @@ function search(text, pattern, patternAlphabet, {
274524
274596
  for (let j4 = finish;j4 >= start; j4 -= 1) {
274525
274597
  const currentLocation = j4 - 1;
274526
274598
  const charMatch = patternAlphabet[text[currentLocation]];
274527
- if (computeMatches) {
274528
- matchMask[currentLocation] = +!!charMatch;
274529
- }
274530
274599
  bitArr[j4] = (bitArr[j4 + 1] << 1 | 1) & charMatch;
274531
- if (i2) {
274600
+ if (i2)
274532
274601
  bitArr[j4] |= (lastBitArr[j4 + 1] | lastBitArr[j4]) << 1 | 1 | lastBitArr[j4 + 1];
274533
- }
274534
274602
  if (bitArr[j4] & mask) {
274535
274603
  finalScore = calcScore(i2, currentLocation);
274536
274604
  if (finalScore <= currentThreshold) {
274537
274605
  currentThreshold = finalScore;
274538
274606
  bestLocation = currentLocation;
274539
- if (bestLocation <= expectedLocation) {
274607
+ bestErrors = i2;
274608
+ if (bestLocation <= expectedLocation)
274540
274609
  break;
274541
- }
274542
274610
  start = Math.max(1, 2 * expectedLocation - bestLocation);
274543
274611
  }
274544
274612
  }
274545
274613
  }
274546
- const score = calcScore(i2 + 1, expectedLocation);
274547
- if (score > currentThreshold) {
274614
+ if (calcScore(i2 + 1, expectedLocation) > currentThreshold)
274548
274615
  break;
274549
- }
274550
274616
  lastBitArr = bitArr;
274551
274617
  }
274618
+ if (computeMatches && bestLocation >= 0) {
274619
+ const matchEnd = Math.min(textLen - 1, bestLocation + patternLen - 1 + bestErrors);
274620
+ for (let k4 = bestLocation;k4 <= matchEnd; k4 += 1)
274621
+ if (patternAlphabet[text[k4]])
274622
+ matchMask[k4] = 1;
274623
+ }
274552
274624
  const result = {
274553
274625
  isMatch: bestLocation >= 0,
274554
274626
  score: Math.max(0.001, finalScore)
274555
274627
  };
274556
274628
  if (computeMatches) {
274557
274629
  const indices = convertMaskToIndices(matchMask, minMatchCharLength);
274558
- if (!indices.length) {
274630
+ if (!indices.length)
274559
274631
  result.isMatch = false;
274560
- } else if (includeMatches) {
274632
+ else if (includeMatches)
274561
274633
  result.indices = indices;
274562
- }
274563
274634
  }
274564
274635
  return result;
274565
274636
  }
@@ -274579,11 +274650,10 @@ function mergeIndices(indices) {
274579
274650
  for (let i2 = 1, len = indices.length;i2 < len; i2 += 1) {
274580
274651
  const last = merged[merged.length - 1];
274581
274652
  const curr = indices[i2];
274582
- if (curr[0] <= last[1] + 1) {
274653
+ if (curr[0] <= last[1] + 1)
274583
274654
  last[1] = Math.max(last[1], curr[1]);
274584
- } else {
274655
+ else
274585
274656
  merged.push(curr);
274586
- }
274587
274657
  }
274588
274658
  return merged;
274589
274659
  }
@@ -274602,20 +274672,9 @@ var NON_DECOMPOSABLE_MAP = {
274602
274672
  "ß": "ss"
274603
274673
  };
274604
274674
  var NON_DECOMPOSABLE_RE = new RegExp("[" + Object.keys(NON_DECOMPOSABLE_MAP).join("") + "]", "g");
274605
- var stripDiacritics = String.prototype.normalize ? (str) => str.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "").replace(NON_DECOMPOSABLE_RE, (ch3) => NON_DECOMPOSABLE_MAP[ch3]) : (str) => str;
274606
-
274607
- class BitapSearch {
274608
- constructor(pattern, {
274609
- location = Config.location,
274610
- threshold = Config.threshold,
274611
- distance: distance7 = Config.distance,
274612
- includeMatches = Config.includeMatches,
274613
- findAllMatches = Config.findAllMatches,
274614
- minMatchCharLength = Config.minMatchCharLength,
274615
- isCaseSensitive = Config.isCaseSensitive,
274616
- ignoreDiacritics = Config.ignoreDiacritics,
274617
- ignoreLocation = Config.ignoreLocation
274618
- } = {}) {
274675
+ var stripDiacritics = typeof String.prototype.normalize === "function" ? (str) => str.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "").replace(NON_DECOMPOSABLE_RE, (ch3) => NON_DECOMPOSABLE_MAP[ch3]) : (str) => str;
274676
+ var BitapSearch = class {
274677
+ constructor(pattern, { location = Config.location, threshold = Config.threshold, distance: distance7 = Config.distance, includeMatches = Config.includeMatches, findAllMatches = Config.findAllMatches, minMatchCharLength = Config.minMatchCharLength, isCaseSensitive = Config.isCaseSensitive, ignoreDiacritics = Config.ignoreDiacritics, ignoreLocation = Config.ignoreLocation } = {}) {
274619
274678
  this.options = {
274620
274679
  location,
274621
274680
  threshold,
@@ -274631,9 +274690,8 @@ class BitapSearch {
274631
274690
  pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
274632
274691
  this.pattern = pattern;
274633
274692
  this.chunks = [];
274634
- if (!this.pattern.length) {
274693
+ if (!this.pattern.length)
274635
274694
  return;
274636
- }
274637
274695
  const addChunk = (pattern2, startIndex) => {
274638
274696
  this.chunks.push({
274639
274697
  pattern: pattern2,
@@ -274642,28 +274700,23 @@ class BitapSearch {
274642
274700
  });
274643
274701
  };
274644
274702
  const len = this.pattern.length;
274645
- if (len > MAX_BITS) {
274703
+ if (len > 32) {
274646
274704
  let i2 = 0;
274647
- const remainder = len % MAX_BITS;
274705
+ const remainder = len % 32;
274648
274706
  const end = len - remainder;
274649
274707
  while (i2 < end) {
274650
- addChunk(this.pattern.substr(i2, MAX_BITS), i2);
274651
- i2 += MAX_BITS;
274708
+ addChunk(this.pattern.substr(i2, 32), i2);
274709
+ i2 += 32;
274652
274710
  }
274653
274711
  if (remainder) {
274654
- const startIndex = len - MAX_BITS;
274712
+ const startIndex = len - 32;
274655
274713
  addChunk(this.pattern.substr(startIndex), startIndex);
274656
274714
  }
274657
- } else {
274715
+ } else
274658
274716
  addChunk(this.pattern, 0);
274659
- }
274660
274717
  }
274661
274718
  searchIn(text) {
274662
- const {
274663
- isCaseSensitive,
274664
- ignoreDiacritics,
274665
- includeMatches
274666
- } = this.options;
274719
+ const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
274667
274720
  text = isCaseSensitive ? text : text.toLowerCase();
274668
274721
  text = ignoreDiacritics ? stripDiacritics(text) : text;
274669
274722
  if (this.pattern === text) {
@@ -274671,32 +274724,16 @@ class BitapSearch {
274671
274724
  isMatch: true,
274672
274725
  score: 0
274673
274726
  };
274674
- if (includeMatches) {
274727
+ if (includeMatches)
274675
274728
  result2.indices = [[0, text.length - 1]];
274676
- }
274677
274729
  return result2;
274678
274730
  }
274679
- const {
274680
- location,
274681
- distance: distance7,
274682
- threshold,
274683
- findAllMatches,
274684
- minMatchCharLength,
274685
- ignoreLocation
274686
- } = this.options;
274731
+ const { location, distance: distance7, threshold, findAllMatches, minMatchCharLength, ignoreLocation } = this.options;
274687
274732
  const allIndices = [];
274688
274733
  let totalScore = 0;
274689
274734
  let hasMatches = false;
274690
- this.chunks.forEach(({
274691
- pattern,
274692
- alphabet,
274693
- startIndex
274694
- }) => {
274695
- const {
274696
- isMatch,
274697
- score,
274698
- indices
274699
- } = search(text, pattern, alphabet, {
274735
+ this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
274736
+ const { isMatch, score, indices } = search(text, pattern, alphabet, {
274700
274737
  location: location + startIndex,
274701
274738
  distance: distance7,
274702
274739
  threshold,
@@ -274705,257 +274742,172 @@ class BitapSearch {
274705
274742
  includeMatches,
274706
274743
  ignoreLocation
274707
274744
  });
274708
- if (isMatch) {
274745
+ if (isMatch)
274709
274746
  hasMatches = true;
274710
- }
274711
274747
  totalScore += score;
274712
- if (isMatch && indices) {
274748
+ if (isMatch && indices)
274713
274749
  allIndices.push(...indices);
274714
- }
274715
274750
  });
274716
274751
  const result = {
274717
274752
  isMatch: hasMatches,
274718
274753
  score: hasMatches ? totalScore / this.chunks.length : 1
274719
274754
  };
274720
- if (hasMatches && includeMatches) {
274755
+ if (hasMatches && includeMatches)
274721
274756
  result.indices = mergeIndices(allIndices);
274722
- }
274723
274757
  return result;
274724
274758
  }
274759
+ };
274760
+ var MULTI_MATCH_TYPES = new Set(["fuzzy", "include"]);
274761
+ function isInverse(type) {
274762
+ return type.startsWith("inverse");
274725
274763
  }
274726
-
274727
- class BaseMatch {
274728
- constructor(pattern) {
274729
- this.pattern = pattern;
274730
- }
274731
- static isMultiMatch(pattern) {
274732
- return getMatch(pattern, this.multiRegex);
274733
- }
274734
- static isSingleMatch(pattern) {
274735
- return getMatch(pattern, this.singleRegex);
274736
- }
274737
- search(_text) {
274738
- return {
274739
- isMatch: false,
274740
- score: 1
274741
- };
274742
- }
274743
- }
274744
- function getMatch(pattern, exp) {
274745
- const matches = pattern.match(exp);
274746
- return matches ? matches[1] : null;
274747
- }
274748
-
274749
- class ExactMatch extends BaseMatch {
274750
- constructor(pattern) {
274751
- super(pattern);
274752
- }
274753
- static get type() {
274754
- return "exact";
274755
- }
274756
- static get multiRegex() {
274757
- return /^="(.*)"$/;
274758
- }
274759
- static get singleRegex() {
274760
- return /^=(.*)$/;
274761
- }
274762
- search(text) {
274763
- const isMatch = text === this.pattern;
274764
- return {
274765
- isMatch,
274766
- score: isMatch ? 0 : 1,
274767
- indices: [0, this.pattern.length - 1]
274768
- };
274769
- }
274770
- }
274771
-
274772
- class InverseExactMatch extends BaseMatch {
274773
- constructor(pattern) {
274774
- super(pattern);
274775
- }
274776
- static get type() {
274777
- return "inverse-exact";
274778
- }
274779
- static get multiRegex() {
274780
- return /^!"(.*)"$/;
274781
- }
274782
- static get singleRegex() {
274783
- return /^!(.*)$/;
274784
- }
274785
- search(text) {
274786
- const index = text.indexOf(this.pattern);
274787
- const isMatch = index === -1;
274788
- return {
274789
- isMatch,
274790
- score: isMatch ? 0 : 1,
274791
- indices: [0, text.length - 1]
274792
- };
274793
- }
274794
- }
274795
-
274796
- class PrefixExactMatch extends BaseMatch {
274797
- constructor(pattern) {
274798
- super(pattern);
274799
- }
274800
- static get type() {
274801
- return "prefix-exact";
274802
- }
274803
- static get multiRegex() {
274804
- return /^\^"(.*)"$/;
274805
- }
274806
- static get singleRegex() {
274807
- return /^\^(.*)$/;
274808
- }
274809
- search(text) {
274810
- const isMatch = text.startsWith(this.pattern);
274811
- return {
274812
- isMatch,
274813
- score: isMatch ? 0 : 1,
274814
- indices: [0, this.pattern.length - 1]
274815
- };
274816
- }
274817
- }
274818
-
274819
- class InversePrefixExactMatch extends BaseMatch {
274820
- constructor(pattern) {
274821
- super(pattern);
274822
- }
274823
- static get type() {
274824
- return "inverse-prefix-exact";
274825
- }
274826
- static get multiRegex() {
274827
- return /^!\^"(.*)"$/;
274828
- }
274829
- static get singleRegex() {
274830
- return /^!\^(.*)$/;
274831
- }
274832
- search(text) {
274833
- const isMatch = !text.startsWith(this.pattern);
274834
- return {
274835
- isMatch,
274836
- score: isMatch ? 0 : 1,
274837
- indices: [0, text.length - 1]
274838
- };
274839
- }
274840
- }
274841
-
274842
- class SuffixExactMatch extends BaseMatch {
274843
- constructor(pattern) {
274844
- super(pattern);
274845
- }
274846
- static get type() {
274847
- return "suffix-exact";
274848
- }
274849
- static get multiRegex() {
274850
- return /^"(.*)"\$$/;
274851
- }
274852
- static get singleRegex() {
274853
- return /^(.*)\$$/;
274854
- }
274855
- search(text) {
274856
- const isMatch = text.endsWith(this.pattern);
274857
- return {
274858
- isMatch,
274859
- score: isMatch ? 0 : 1,
274860
- indices: [text.length - this.pattern.length, text.length - 1]
274861
- };
274862
- }
274863
- }
274864
-
274865
- class InverseSuffixExactMatch extends BaseMatch {
274866
- constructor(pattern) {
274867
- super(pattern);
274868
- }
274869
- static get type() {
274870
- return "inverse-suffix-exact";
274871
- }
274872
- static get multiRegex() {
274873
- return /^!"(.*)"\$$/;
274874
- }
274875
- static get singleRegex() {
274876
- return /^!(.*)\$$/;
274877
- }
274878
- search(text) {
274879
- const isMatch = !text.endsWith(this.pattern);
274880
- return {
274881
- isMatch,
274882
- score: isMatch ? 0 : 1,
274883
- indices: [0, text.length - 1]
274884
- };
274885
- }
274886
- }
274887
-
274888
- class FuzzyMatch extends BaseMatch {
274889
- constructor(pattern, {
274890
- location = Config.location,
274891
- threshold = Config.threshold,
274892
- distance: distance7 = Config.distance,
274893
- includeMatches = Config.includeMatches,
274894
- findAllMatches = Config.findAllMatches,
274895
- minMatchCharLength = Config.minMatchCharLength,
274896
- isCaseSensitive = Config.isCaseSensitive,
274897
- ignoreDiacritics = Config.ignoreDiacritics,
274898
- ignoreLocation = Config.ignoreLocation
274899
- } = {}) {
274900
- super(pattern);
274901
- this._bitapSearch = new BitapSearch(pattern, {
274902
- location,
274903
- threshold,
274904
- distance: distance7,
274905
- includeMatches,
274906
- findAllMatches,
274907
- minMatchCharLength,
274908
- isCaseSensitive,
274909
- ignoreDiacritics,
274910
- ignoreLocation
274911
- });
274912
- }
274913
- static get type() {
274914
- return "fuzzy";
274915
- }
274916
- static get multiRegex() {
274917
- return /^"(.*)"$/;
274918
- }
274919
- static get singleRegex() {
274920
- return /^(.*)$/;
274921
- }
274922
- search(text) {
274923
- return this._bitapSearch.searchIn(text);
274924
- }
274925
- }
274926
-
274927
- class IncludeMatch extends BaseMatch {
274928
- constructor(pattern) {
274929
- super(pattern);
274930
- }
274931
- static get type() {
274932
- return "include";
274933
- }
274934
- static get multiRegex() {
274935
- return /^'"(.*)"$/;
274936
- }
274937
- static get singleRegex() {
274938
- return /^'(.*)$/;
274939
- }
274940
- search(text) {
274941
- let location = 0;
274942
- let index;
274943
- const indices = [];
274944
- const patternLen = this.pattern.length;
274945
- while ((index = text.indexOf(this.pattern, location)) > -1) {
274946
- location = index + patternLen;
274947
- indices.push([index, location - 1]);
274764
+ var matchers = [
274765
+ {
274766
+ type: "exact",
274767
+ multiRegex: /^="(.*)"$/,
274768
+ singleRegex: /^=(.*)$/,
274769
+ create: (pattern) => ({
274770
+ type: "exact",
274771
+ search(text) {
274772
+ const isMatch = text === pattern;
274773
+ return {
274774
+ isMatch,
274775
+ score: isMatch ? 0 : 1,
274776
+ indices: [0, pattern.length - 1]
274777
+ };
274778
+ }
274779
+ })
274780
+ },
274781
+ {
274782
+ type: "include",
274783
+ multiRegex: /^'"(.*)"$/,
274784
+ singleRegex: /^'(.*)$/,
274785
+ create: (pattern) => ({
274786
+ type: "include",
274787
+ search(text) {
274788
+ let location = 0;
274789
+ let index;
274790
+ const indices = [];
274791
+ const patternLen = pattern.length;
274792
+ while ((index = text.indexOf(pattern, location)) > -1) {
274793
+ location = index + patternLen;
274794
+ indices.push([index, location - 1]);
274795
+ }
274796
+ const isMatch = !!indices.length;
274797
+ return {
274798
+ isMatch,
274799
+ score: isMatch ? 0 : 1,
274800
+ indices
274801
+ };
274802
+ }
274803
+ })
274804
+ },
274805
+ {
274806
+ type: "prefix-exact",
274807
+ multiRegex: /^\^"(.*)"$/,
274808
+ singleRegex: /^\^(.*)$/,
274809
+ create: (pattern) => ({
274810
+ type: "prefix-exact",
274811
+ search(text) {
274812
+ const isMatch = text.startsWith(pattern);
274813
+ return {
274814
+ isMatch,
274815
+ score: isMatch ? 0 : 1,
274816
+ indices: [0, pattern.length - 1]
274817
+ };
274818
+ }
274819
+ })
274820
+ },
274821
+ {
274822
+ type: "inverse-prefix-exact",
274823
+ multiRegex: /^!\^"(.*)"$/,
274824
+ singleRegex: /^!\^(.*)$/,
274825
+ create: (pattern) => ({
274826
+ type: "inverse-prefix-exact",
274827
+ search(text) {
274828
+ const isMatch = !text.startsWith(pattern);
274829
+ return {
274830
+ isMatch,
274831
+ score: isMatch ? 0 : 1,
274832
+ indices: [0, text.length - 1]
274833
+ };
274834
+ }
274835
+ })
274836
+ },
274837
+ {
274838
+ type: "inverse-suffix-exact",
274839
+ multiRegex: /^!"(.*)"\$$/,
274840
+ singleRegex: /^!(.*)\$$/,
274841
+ create: (pattern) => ({
274842
+ type: "inverse-suffix-exact",
274843
+ search(text) {
274844
+ const isMatch = !text.endsWith(pattern);
274845
+ return {
274846
+ isMatch,
274847
+ score: isMatch ? 0 : 1,
274848
+ indices: [0, text.length - 1]
274849
+ };
274850
+ }
274851
+ })
274852
+ },
274853
+ {
274854
+ type: "suffix-exact",
274855
+ multiRegex: /^"(.*)"\$$/,
274856
+ singleRegex: /^(.*)\$$/,
274857
+ create: (pattern) => ({
274858
+ type: "suffix-exact",
274859
+ search(text) {
274860
+ const isMatch = text.endsWith(pattern);
274861
+ return {
274862
+ isMatch,
274863
+ score: isMatch ? 0 : 1,
274864
+ indices: [text.length - pattern.length, text.length - 1]
274865
+ };
274866
+ }
274867
+ })
274868
+ },
274869
+ {
274870
+ type: "inverse-exact",
274871
+ multiRegex: /^!"(.*)"$/,
274872
+ singleRegex: /^!(.*)$/,
274873
+ create: (pattern) => ({
274874
+ type: "inverse-exact",
274875
+ search(text) {
274876
+ const isMatch = text.indexOf(pattern) === -1;
274877
+ return {
274878
+ isMatch,
274879
+ score: isMatch ? 0 : 1,
274880
+ indices: [0, text.length - 1]
274881
+ };
274882
+ }
274883
+ })
274884
+ },
274885
+ {
274886
+ type: "fuzzy",
274887
+ multiRegex: /^"(.*)"$/,
274888
+ singleRegex: /^(.*)$/,
274889
+ create: (pattern, options = {}) => {
274890
+ const bitap = new BitapSearch(pattern, {
274891
+ location: options.location ?? Config.location,
274892
+ threshold: options.threshold ?? Config.threshold,
274893
+ distance: options.distance ?? Config.distance,
274894
+ includeMatches: options.includeMatches ?? Config.includeMatches,
274895
+ findAllMatches: options.findAllMatches ?? Config.findAllMatches,
274896
+ minMatchCharLength: options.minMatchCharLength ?? Config.minMatchCharLength,
274897
+ isCaseSensitive: options.isCaseSensitive ?? Config.isCaseSensitive,
274898
+ ignoreDiacritics: options.ignoreDiacritics ?? Config.ignoreDiacritics,
274899
+ ignoreLocation: options.ignoreLocation ?? Config.ignoreLocation
274900
+ });
274901
+ return {
274902
+ type: "fuzzy",
274903
+ search(text) {
274904
+ return bitap.searchIn(text);
274905
+ }
274906
+ };
274948
274907
  }
274949
- const isMatch = !!indices.length;
274950
- return {
274951
- isMatch,
274952
- score: isMatch ? 0 : 1,
274953
- indices
274954
- };
274955
274908
  }
274956
- }
274957
- var searchers = [ExactMatch, IncludeMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch];
274958
- var searchersLen = searchers.length;
274909
+ ];
274910
+ var matchersLen = matchers.length;
274959
274911
  var ESCAPED_PIPE = "\x00";
274960
274912
  var OR_TOKEN = "|";
274961
274913
  function tokenize3(pattern) {
@@ -274997,33 +274949,34 @@ function tokenize3(pattern) {
274997
274949
  }
274998
274950
  return tokens;
274999
274951
  }
274952
+ function getMatch(pattern, exp) {
274953
+ const matches = pattern.match(exp);
274954
+ return matches ? matches[1] : null;
274955
+ }
275000
274956
  function parseQuery(pattern, options = {}) {
275001
- const escaped = pattern.replace(/\\\|/g, ESCAPED_PIPE);
275002
- return escaped.split(OR_TOKEN).map((item) => {
275003
- const restored = item.replace(/\u0000/g, "|");
275004
- const query = tokenize3(restored.trim()).filter((item2) => item2 && !!item2.trim());
274957
+ return pattern.replace(/\\\|/g, ESCAPED_PIPE).split(OR_TOKEN).map((item) => {
274958
+ const query = tokenize3(item.replace(/\u0000/g, "|").trim()).filter((item2) => item2 && !!item2.trim());
275005
274959
  const results = [];
275006
274960
  for (let i2 = 0, len = query.length;i2 < len; i2 += 1) {
275007
274961
  const queryItem = query[i2];
275008
274962
  let found = false;
275009
274963
  let idx = -1;
275010
- while (!found && ++idx < searchersLen) {
275011
- const searcher = searchers[idx];
275012
- const token = searcher.isMultiMatch(queryItem);
274964
+ while (!found && ++idx < matchersLen) {
274965
+ const def = matchers[idx];
274966
+ const token = getMatch(queryItem, def.multiRegex);
275013
274967
  if (token) {
275014
- results.push(new searcher(token, options));
274968
+ results.push(def.create(token, options));
275015
274969
  found = true;
275016
274970
  }
275017
274971
  }
275018
- if (found) {
274972
+ if (found)
275019
274973
  continue;
275020
- }
275021
274974
  idx = -1;
275022
- while (++idx < searchersLen) {
275023
- const searcher = searchers[idx];
275024
- const token = searcher.isSingleMatch(queryItem);
274975
+ while (++idx < matchersLen) {
274976
+ const def = matchers[idx];
274977
+ const token = getMatch(queryItem, def.singleRegex);
275025
274978
  if (token) {
275026
- results.push(new searcher(token, options));
274979
+ results.push(def.create(token, options));
275027
274980
  break;
275028
274981
  }
275029
274982
  }
@@ -275031,20 +274984,8 @@ function parseQuery(pattern, options = {}) {
275031
274984
  return results;
275032
274985
  });
275033
274986
  }
275034
- var MultiMatchSet = new Set([FuzzyMatch.type, IncludeMatch.type]);
275035
-
275036
- class ExtendedSearch {
275037
- constructor(pattern, {
275038
- isCaseSensitive = Config.isCaseSensitive,
275039
- ignoreDiacritics = Config.ignoreDiacritics,
275040
- includeMatches = Config.includeMatches,
275041
- minMatchCharLength = Config.minMatchCharLength,
275042
- ignoreLocation = Config.ignoreLocation,
275043
- findAllMatches = Config.findAllMatches,
275044
- location = Config.location,
275045
- threshold = Config.threshold,
275046
- distance: distance7 = Config.distance
275047
- } = {}) {
274987
+ var ExtendedSearch = class {
274988
+ constructor(pattern, { isCaseSensitive = Config.isCaseSensitive, ignoreDiacritics = Config.ignoreDiacritics, includeMatches = Config.includeMatches, minMatchCharLength = Config.minMatchCharLength, ignoreLocation = Config.ignoreLocation, findAllMatches = Config.findAllMatches, location = Config.location, threshold = Config.threshold, distance: distance7 = Config.distance } = {}) {
275048
274989
  this.query = null;
275049
274990
  this.options = {
275050
274991
  isCaseSensitive,
@@ -275067,17 +275008,12 @@ class ExtendedSearch {
275067
275008
  }
275068
275009
  searchIn(text) {
275069
275010
  const query = this.query;
275070
- if (!query) {
275011
+ if (!query)
275071
275012
  return {
275072
275013
  isMatch: false,
275073
275014
  score: 1
275074
275015
  };
275075
- }
275076
- const {
275077
- includeMatches,
275078
- isCaseSensitive,
275079
- ignoreDiacritics
275080
- } = this.options;
275016
+ const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
275081
275017
  text = isCaseSensitive ? text : text.toLowerCase();
275082
275018
  text = ignoreDiacritics ? stripDiacritics(text) : text;
275083
275019
  let numMatches = 0;
@@ -275085,31 +275021,23 @@ class ExtendedSearch {
275085
275021
  let totalScore = 0;
275086
275022
  let hasInverse = false;
275087
275023
  for (let i2 = 0, qLen = query.length;i2 < qLen; i2 += 1) {
275088
- const searchers2 = query[i2];
275024
+ const searchers = query[i2];
275089
275025
  allIndices.length = 0;
275090
275026
  numMatches = 0;
275091
275027
  hasInverse = false;
275092
- for (let j4 = 0, pLen = searchers2.length;j4 < pLen; j4 += 1) {
275093
- const searcher = searchers2[j4];
275094
- const {
275095
- isMatch,
275096
- indices,
275097
- score
275098
- } = searcher.search(text);
275028
+ for (let j4 = 0, pLen = searchers.length;j4 < pLen; j4 += 1) {
275029
+ const matcher = searchers[j4];
275030
+ const { isMatch, indices, score } = matcher.search(text);
275099
275031
  if (isMatch) {
275100
275032
  numMatches += 1;
275101
275033
  totalScore += score;
275102
- const type = searcher.constructor.type;
275103
- if (type.startsWith("inverse")) {
275034
+ if (isInverse(matcher.type))
275104
275035
  hasInverse = true;
275105
- }
275106
- if (includeMatches) {
275107
- if (MultiMatchSet.has(type)) {
275036
+ if (includeMatches)
275037
+ if (MULTI_MATCH_TYPES.has(matcher.type))
275108
275038
  allIndices.push(...indices);
275109
- } else {
275039
+ else
275110
275040
  allIndices.push(indices);
275111
- }
275112
- }
275113
275041
  } else {
275114
275042
  totalScore = 0;
275115
275043
  numMatches = 0;
@@ -275123,12 +275051,10 @@ class ExtendedSearch {
275123
275051
  isMatch: true,
275124
275052
  score: totalScore / numMatches
275125
275053
  };
275126
- if (hasInverse) {
275054
+ if (hasInverse)
275127
275055
  result.hasInverse = true;
275128
- }
275129
- if (includeMatches) {
275056
+ if (includeMatches)
275130
275057
  result.indices = mergeIndices(allIndices);
275131
- }
275132
275058
  return result;
275133
275059
  }
275134
275060
  }
@@ -275137,7 +275063,7 @@ class ExtendedSearch {
275137
275063
  score: 1
275138
275064
  };
275139
275065
  }
275140
- }
275066
+ };
275141
275067
  var registeredSearchers = [];
275142
275068
  function register2(...args) {
275143
275069
  registeredSearchers.push(...args);
@@ -275145,9 +275071,8 @@ function register2(...args) {
275145
275071
  function createSearcher(pattern, options) {
275146
275072
  for (let i2 = 0, len = registeredSearchers.length;i2 < len; i2 += 1) {
275147
275073
  const searcherClass = registeredSearchers[i2];
275148
- if (searcherClass.condition(pattern, options)) {
275074
+ if (searcherClass.condition(pattern, options))
275149
275075
  return new searcherClass(pattern, options);
275150
- }
275151
275076
  }
275152
275077
  return new BitapSearch(pattern, options);
275153
275078
  }
@@ -275162,43 +275087,33 @@ var KeyType = {
275162
275087
  var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
275163
275088
  var isPath = (query) => !!query[KeyType.PATH];
275164
275089
  var isLeaf = (query) => !isArray(query) && isObject3(query) && !isExpression(query);
275165
- var convertToExplicit = (query) => ({
275166
- [LogicalOperator.AND]: Object.keys(query).map((key) => ({
275167
- [key]: query[key]
275168
- }))
275169
- });
275170
- function parse3(query, options, {
275171
- auto = true
275172
- } = {}) {
275090
+ var convertToExplicit = (query) => ({ [LogicalOperator.AND]: Object.keys(query).map((key) => ({ [key]: query[key] })) });
275091
+ function parse3(query, options, { auto = true } = {}) {
275173
275092
  const next = (query2) => {
275174
275093
  if (isString2(query2)) {
275175
275094
  const obj = {
275176
275095
  keyId: null,
275177
275096
  pattern: query2
275178
275097
  };
275179
- if (auto) {
275098
+ if (auto)
275180
275099
  obj.searcher = createSearcher(query2, options);
275181
- }
275182
275100
  return obj;
275183
275101
  }
275184
275102
  const keys = Object.keys(query2);
275185
275103
  const isQueryPath = isPath(query2);
275186
- if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
275104
+ if (!isQueryPath && keys.length > 1 && !isExpression(query2))
275187
275105
  return next(convertToExplicit(query2));
275188
- }
275189
275106
  if (isLeaf(query2)) {
275190
275107
  const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
275191
275108
  const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
275192
- if (!isString2(pattern)) {
275109
+ if (!isString2(pattern))
275193
275110
  throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
275194
- }
275195
275111
  const obj = {
275196
275112
  keyId: createKeyId(key),
275197
275113
  pattern
275198
275114
  };
275199
- if (auto) {
275115
+ if (auto)
275200
275116
  obj.searcher = createSearcher(pattern, options);
275201
- }
275202
275117
  return obj;
275203
275118
  }
275204
275119
  const node = {
@@ -275207,44 +275122,31 @@ function parse3(query, options, {
275207
275122
  };
275208
275123
  keys.forEach((key) => {
275209
275124
  const value = query2[key];
275210
- if (isArray(value)) {
275125
+ if (isArray(value))
275211
275126
  value.forEach((item) => {
275212
275127
  node.children.push(next(item));
275213
275128
  });
275214
- }
275215
275129
  });
275216
275130
  return node;
275217
275131
  };
275218
- if (!isExpression(query)) {
275132
+ if (!isExpression(query))
275219
275133
  query = convertToExplicit(query);
275220
- }
275221
275134
  return next(query);
275222
275135
  }
275223
- function computeScoreSingle(matches, {
275224
- ignoreFieldNorm = Config.ignoreFieldNorm
275225
- }) {
275136
+ function computeScoreSingle(matches, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
275226
275137
  let totalScore = 1;
275227
- matches.forEach(({
275228
- key,
275229
- norm: norm2,
275230
- score
275231
- }) => {
275138
+ matches.forEach(({ key, norm: norm2, score }) => {
275232
275139
  const weight = key ? key.weight : null;
275233
275140
  totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm2));
275234
275141
  });
275235
275142
  return totalScore;
275236
275143
  }
275237
- function computeScore(results, {
275238
- ignoreFieldNorm = Config.ignoreFieldNorm
275239
- }) {
275144
+ function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
275240
275145
  results.forEach((result) => {
275241
- result.score = computeScoreSingle(result.matches, {
275242
- ignoreFieldNorm
275243
- });
275146
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
275244
275147
  });
275245
275148
  }
275246
-
275247
- class MaxHeap {
275149
+ var MaxHeap = class {
275248
275150
  constructor(limit) {
275249
275151
  this.limit = limit;
275250
275152
  this.heap = [];
@@ -275287,12 +275189,10 @@ class MaxHeap {
275287
275189
  i2 = largest;
275288
275190
  const left = 2 * i2 + 1;
275289
275191
  const right = 2 * i2 + 2;
275290
- if (left < len && heap[left].score > heap[largest].score) {
275192
+ if (left < len && heap[left].score > heap[largest].score)
275291
275193
  largest = left;
275292
- }
275293
- if (right < len && heap[right].score > heap[largest].score) {
275194
+ if (right < len && heap[right].score > heap[largest].score)
275294
275195
  largest = right;
275295
- }
275296
275196
  if (largest !== i2) {
275297
275197
  const tmp = heap[i2];
275298
275198
  heap[i2] = heap[largest];
@@ -275300,207 +275200,258 @@ class MaxHeap {
275300
275200
  }
275301
275201
  } while (largest !== i2);
275302
275202
  }
275303
- }
275304
- function transformMatches(result, data) {
275305
- const matches = result.matches;
275306
- data.matches = [];
275307
- if (!isDefined(matches)) {
275308
- return;
275309
- }
275310
- matches.forEach((match) => {
275311
- if (!isDefined(match.indices) || !match.indices.length) {
275203
+ };
275204
+ function formatMatches(result) {
275205
+ const matches = [];
275206
+ result.matches.forEach((match) => {
275207
+ if (!isDefined(match.indices) || !match.indices.length)
275312
275208
  return;
275313
- }
275314
- const {
275315
- indices,
275316
- value
275317
- } = match;
275318
275209
  const obj = {
275319
- indices,
275320
- value
275210
+ indices: match.indices,
275211
+ value: match.value
275321
275212
  };
275322
- if (match.key) {
275323
- obj.key = match.key.src;
275324
- }
275325
- if (match.idx > -1) {
275213
+ if (match.key)
275214
+ obj.key = match.key.id;
275215
+ if (match.idx > -1)
275326
275216
  obj.refIndex = match.idx;
275327
- }
275328
- data.matches.push(obj);
275217
+ matches.push(obj);
275329
275218
  });
275219
+ return matches;
275330
275220
  }
275331
- function transformScore(result, data) {
275332
- data.score = result.score;
275333
- }
275334
- function format(results, docs, {
275335
- includeMatches = Config.includeMatches,
275336
- includeScore = Config.includeScore
275337
- } = {}) {
275338
- const transformers = [];
275339
- if (includeMatches)
275340
- transformers.push(transformMatches);
275341
- if (includeScore)
275342
- transformers.push(transformScore);
275221
+ function format(results, docs, { includeMatches = Config.includeMatches, includeScore = Config.includeScore } = {}) {
275343
275222
  return results.map((result) => {
275344
- const {
275345
- idx
275346
- } = result;
275223
+ const { idx } = result;
275347
275224
  const data = {
275348
275225
  item: docs[idx],
275349
275226
  refIndex: idx
275350
275227
  };
275351
- if (transformers.length) {
275352
- transformers.forEach((transformer) => {
275353
- transformer(result, data);
275354
- });
275355
- }
275228
+ if (includeMatches)
275229
+ data.matches = formatMatches(result);
275230
+ if (includeScore)
275231
+ data.score = result.score;
275356
275232
  return data;
275357
275233
  });
275358
275234
  }
275359
- var WORD = /\b\w+\b/g;
275360
- function createAnalyzer({
275361
- isCaseSensitive = false,
275362
- ignoreDiacritics = false
275363
- } = {}) {
275364
- return {
275365
- tokenize(text) {
275366
- if (!isCaseSensitive) {
275367
- text = text.toLowerCase();
275368
- }
275369
- if (ignoreDiacritics) {
275370
- text = stripDiacritics(text);
275371
- }
275372
- return text.match(WORD) || [];
275373
- }
275374
- };
275235
+ var DEFAULT_TOKEN = /[\p{L}\p{M}\p{N}_]+/gu;
275236
+ var warned = /* @__PURE__ */ new WeakSet;
275237
+ function warnNonGlobal(regex2) {
275238
+ if (!warned.has(regex2)) {
275239
+ warned.add(regex2);
275240
+ console.warn(`[Fuse] tokenize regex ${regex2} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`);
275241
+ }
275375
275242
  }
275376
- function buildInvertedIndex(records, keyCount, analyzer) {
275377
- const terms = new Map;
275378
- const df3 = new Map;
275379
- let fieldCount = 0;
275380
- function addField(text, docIdx, keyIdx, subIdx) {
275381
- const tokens = analyzer.tokenize(text);
275382
- if (!tokens.length)
275383
- return;
275384
- fieldCount++;
275385
- const termFreqs = new Map;
275386
- for (const token of tokens) {
275387
- termFreqs.set(token, (termFreqs.get(token) || 0) + 1);
275388
- }
275389
- for (const [term, tf3] of termFreqs) {
275390
- const posting = {
275391
- docIdx,
275392
- keyIdx,
275393
- subIdx,
275394
- tf: tf3
275395
- };
275396
- let postings = terms.get(term);
275397
- if (!postings) {
275398
- postings = [];
275399
- terms.set(term, postings);
275243
+ function resolveTokenize(tokenize4) {
275244
+ if (typeof tokenize4 === "function") {
275245
+ let validated = false;
275246
+ return (text) => {
275247
+ const result = tokenize4(text);
275248
+ if (!validated) {
275249
+ validated = true;
275250
+ if (!Array.isArray(result) || result.some((t17) => typeof t17 !== "string"))
275251
+ throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(result) ? "array containing non-strings" : typeof result}.`);
275400
275252
  }
275401
- postings.push(posting);
275402
- df3.set(term, (df3.get(term) || 0) + 1);
275403
- }
275253
+ return result;
275254
+ };
275404
275255
  }
275405
- for (const record of records) {
275406
- const {
275407
- i: docIdx,
275408
- v: v3,
275409
- $: fields
275410
- } = record;
275411
- if (v3 !== undefined) {
275412
- addField(v3, docIdx, -1, -1);
275413
- continue;
275414
- }
275415
- if (fields) {
275416
- for (let keyIdx = 0;keyIdx < keyCount; keyIdx++) {
275417
- const value = fields[keyIdx];
275418
- if (!value)
275419
- continue;
275420
- if (Array.isArray(value)) {
275421
- for (const sub of value) {
275422
- addField(sub.v, docIdx, keyIdx, sub.i ?? -1);
275423
- }
275424
- } else {
275425
- addField(value.v, docIdx, keyIdx, -1);
275426
- }
275427
- }
275428
- }
275256
+ if (tokenize4 instanceof RegExp) {
275257
+ if (!tokenize4.global)
275258
+ warnNonGlobal(tokenize4);
275259
+ return (text) => text.match(tokenize4) || [];
275429
275260
  }
275430
- return {
275431
- terms,
275432
- fieldCount,
275433
- df: df3
275434
- };
275261
+ return (text) => text.match(DEFAULT_TOKEN) || [];
275435
275262
  }
275436
- function addToInvertedIndex(index, record, keyCount, analyzer) {
275437
- const {
275438
- i: docIdx,
275439
- v: v3,
275440
- $: fields
275441
- } = record;
275442
- function addField(text, keyIdx, subIdx) {
275443
- const tokens = analyzer.tokenize(text);
275444
- if (!tokens.length)
275445
- return;
275446
- index.fieldCount++;
275447
- const termFreqs = new Map;
275448
- for (const token of tokens) {
275449
- termFreqs.set(token, (termFreqs.get(token) || 0) + 1);
275450
- }
275451
- for (const [term, tf3] of termFreqs) {
275452
- const posting = {
275453
- docIdx,
275454
- keyIdx,
275455
- subIdx,
275456
- tf: tf3
275263
+ function createAnalyzer({ isCaseSensitive = false, ignoreDiacritics = false, tokenize: tokenize4 } = {}) {
275264
+ const tokenizeFn = resolveTokenize(tokenize4);
275265
+ return { tokenize(text) {
275266
+ if (!isCaseSensitive)
275267
+ text = text.toLowerCase();
275268
+ if (ignoreDiacritics)
275269
+ text = stripDiacritics(text);
275270
+ return tokenizeFn(text);
275271
+ } };
275272
+ }
275273
+ var TokenSearch = class {
275274
+ static condition(_4, options) {
275275
+ return options.useTokenSearch;
275276
+ }
275277
+ constructor(pattern, options) {
275278
+ this.options = options;
275279
+ this.analyzer = createAnalyzer({
275280
+ isCaseSensitive: options.isCaseSensitive,
275281
+ ignoreDiacritics: options.ignoreDiacritics,
275282
+ tokenize: options.tokenize
275283
+ });
275284
+ const queryTerms = this.analyzer.tokenize(pattern);
275285
+ const { df: df3, fieldCount } = options._invertedIndex;
275286
+ this.termSearchers = [];
275287
+ this.idfWeights = [];
275288
+ for (const term of queryTerms) {
275289
+ this.termSearchers.push(new BitapSearch(term, {
275290
+ location: options.location,
275291
+ threshold: options.threshold,
275292
+ distance: options.distance,
275293
+ includeMatches: options.includeMatches,
275294
+ findAllMatches: options.findAllMatches,
275295
+ minMatchCharLength: options.minMatchCharLength,
275296
+ isCaseSensitive: options.isCaseSensitive,
275297
+ ignoreDiacritics: options.ignoreDiacritics,
275298
+ ignoreLocation: true
275299
+ }));
275300
+ const docFreq = df3.get(term) || 0;
275301
+ const idf = Math.log(1 + (fieldCount - docFreq + 0.5) / (docFreq + 0.5));
275302
+ this.idfWeights.push(idf);
275303
+ }
275304
+ this.combineAll = options.tokenMatch === "all";
275305
+ this.numTerms = this.termSearchers.length;
275306
+ this.useMask = this.numTerms <= 31;
275307
+ }
275308
+ searchIn(text) {
275309
+ if (!this.termSearchers.length)
275310
+ return {
275311
+ isMatch: false,
275312
+ score: 1
275457
275313
  };
275458
- let postings = index.terms.get(term);
275459
- if (!postings) {
275460
- postings = [];
275461
- index.terms.set(term, postings);
275314
+ const allIndices = [];
275315
+ let weightedScore = 0;
275316
+ let maxPossibleScore = 0;
275317
+ let matchedCount = 0;
275318
+ let matchedMask = 0;
275319
+ const matchedTerms = this.combineAll && !this.useMask ? /* @__PURE__ */ new Set : null;
275320
+ for (let i2 = 0;i2 < this.termSearchers.length; i2++) {
275321
+ const result = this.termSearchers[i2].searchIn(text);
275322
+ const idf = this.idfWeights[i2];
275323
+ maxPossibleScore += idf;
275324
+ if (result.isMatch) {
275325
+ matchedCount++;
275326
+ weightedScore += idf * (1 - result.score);
275327
+ if (result.indices)
275328
+ allIndices.push(...result.indices);
275329
+ if (this.combineAll)
275330
+ if (this.useMask)
275331
+ matchedMask |= 1 << i2;
275332
+ else
275333
+ matchedTerms.add(i2);
275462
275334
  }
275463
- postings.push(posting);
275464
- index.df.set(term, (index.df.get(term) || 0) + 1);
275465
275335
  }
275336
+ if (matchedCount === 0)
275337
+ return {
275338
+ isMatch: false,
275339
+ score: 1
275340
+ };
275341
+ const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
275342
+ const searchResult = {
275343
+ isMatch: true,
275344
+ score: Math.max(0.001, normalized)
275345
+ };
275346
+ if (this.options.includeMatches && allIndices.length)
275347
+ searchResult.indices = mergeIndices(allIndices);
275348
+ if (this.combineAll) {
275349
+ if (this.useMask)
275350
+ searchResult.matchedMask = matchedMask;
275351
+ else
275352
+ searchResult.matchedTerms = matchedTerms;
275353
+ searchResult.termCount = this.numTerms;
275354
+ }
275355
+ return searchResult;
275356
+ }
275357
+ };
275358
+ function addField(index, text, docIdx, analyzer) {
275359
+ const tokens = analyzer.tokenize(text);
275360
+ if (!tokens.length)
275361
+ return;
275362
+ index.fieldCount++;
275363
+ index.docFieldCount.set(docIdx, (index.docFieldCount.get(docIdx) || 0) + 1);
275364
+ const distinctTerms = new Set(tokens);
275365
+ let perDocTerms = index.docTermFieldHits.get(docIdx);
275366
+ if (!perDocTerms) {
275367
+ perDocTerms = /* @__PURE__ */ new Map;
275368
+ index.docTermFieldHits.set(docIdx, perDocTerms);
275466
275369
  }
275370
+ for (const term of distinctTerms) {
275371
+ perDocTerms.set(term, (perDocTerms.get(term) || 0) + 1);
275372
+ index.df.set(term, (index.df.get(term) || 0) + 1);
275373
+ }
275374
+ }
275375
+ function ingestRecord(index, record, keyCount, analyzer) {
275376
+ const { i: docIdx, v: v3, $: fields } = record;
275467
275377
  if (v3 !== undefined) {
275468
- addField(v3, -1, -1);
275378
+ addField(index, v3, docIdx, analyzer);
275469
275379
  return;
275470
275380
  }
275471
- if (fields) {
275472
- for (let keyIdx = 0;keyIdx < keyCount; keyIdx++) {
275473
- const value = fields[keyIdx];
275474
- if (!value)
275475
- continue;
275476
- if (Array.isArray(value)) {
275477
- for (const sub of value) {
275478
- addField(sub.v, keyIdx, sub.i ?? -1);
275479
- }
275480
- } else {
275481
- addField(value.v, keyIdx, -1);
275482
- }
275483
- }
275381
+ if (!fields)
275382
+ return;
275383
+ for (let keyIdx = 0;keyIdx < keyCount; keyIdx++) {
275384
+ const value = fields[keyIdx];
275385
+ if (!value)
275386
+ continue;
275387
+ if (Array.isArray(value))
275388
+ for (const sub of value)
275389
+ addField(index, sub.v, docIdx, analyzer);
275390
+ else
275391
+ addField(index, value.v, docIdx, analyzer);
275484
275392
  }
275485
275393
  }
275394
+ function buildInvertedIndex(records, keyCount, analyzer) {
275395
+ const index = {
275396
+ fieldCount: 0,
275397
+ df: /* @__PURE__ */ new Map,
275398
+ docFieldCount: /* @__PURE__ */ new Map,
275399
+ docTermFieldHits: /* @__PURE__ */ new Map
275400
+ };
275401
+ for (const record of records)
275402
+ ingestRecord(index, record, keyCount, analyzer);
275403
+ return index;
275404
+ }
275405
+ function addToInvertedIndex(index, record, keyCount, analyzer) {
275406
+ ingestRecord(index, record, keyCount, analyzer);
275407
+ }
275486
275408
  function removeFromInvertedIndex(index, docIdx) {
275487
- for (const [term, postings] of index.terms) {
275488
- const filtered = postings.filter((p3) => p3.docIdx !== docIdx);
275489
- const removed = postings.length - filtered.length;
275490
- if (removed > 0) {
275491
- index.fieldCount -= removed;
275492
- index.df.set(term, (index.df.get(term) || 0) - removed);
275493
- if (filtered.length === 0) {
275494
- index.terms.delete(term);
275495
- index.df.delete(term);
275496
- } else {
275497
- index.terms.set(term, filtered);
275498
- }
275499
- }
275409
+ const fieldCount = index.docFieldCount.get(docIdx);
275410
+ if (fieldCount === undefined)
275411
+ return;
275412
+ index.fieldCount -= fieldCount;
275413
+ index.docFieldCount.delete(docIdx);
275414
+ const perDocTerms = index.docTermFieldHits.get(docIdx);
275415
+ if (!perDocTerms)
275416
+ return;
275417
+ for (const [term, hits] of perDocTerms) {
275418
+ const next = (index.df.get(term) || 0) - hits;
275419
+ if (next <= 0)
275420
+ index.df.delete(term);
275421
+ else
275422
+ index.df.set(term, next);
275500
275423
  }
275424
+ index.docTermFieldHits.delete(docIdx);
275501
275425
  }
275502
-
275503
- class Fuse2 {
275426
+ function removeAndShiftInvertedIndex(index, removedIndices) {
275427
+ if (removedIndices.length === 0)
275428
+ return;
275429
+ const sorted = Array.from(new Set(removedIndices)).sort((a2, b) => a2 - b);
275430
+ for (const idx of sorted)
275431
+ removeFromInvertedIndex(index, idx);
275432
+ const shift = (oldIdx) => {
275433
+ let lo3 = 0;
275434
+ let hi3 = sorted.length;
275435
+ while (lo3 < hi3) {
275436
+ const mid = lo3 + hi3 >>> 1;
275437
+ if (sorted[mid] < oldIdx)
275438
+ lo3 = mid + 1;
275439
+ else
275440
+ hi3 = mid;
275441
+ }
275442
+ return oldIdx - lo3;
275443
+ };
275444
+ const firstRemoved = sorted[0];
275445
+ const shiftedDocFieldCount = /* @__PURE__ */ new Map;
275446
+ for (const [oldKey, count] of index.docFieldCount)
275447
+ shiftedDocFieldCount.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, count);
275448
+ index.docFieldCount = shiftedDocFieldCount;
275449
+ const shiftedDocTermFieldHits = /* @__PURE__ */ new Map;
275450
+ for (const [oldKey, terms] of index.docTermFieldHits)
275451
+ shiftedDocTermFieldHits.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, terms);
275452
+ index.docTermFieldHits = shiftedDocTermFieldHits;
275453
+ }
275454
+ var Fuse2 = class {
275504
275455
  constructor(docs, options, index) {
275505
275456
  this.options = {
275506
275457
  ...Config,
@@ -275519,23 +275470,20 @@ class Fuse2 {
275519
275470
  this._lastSearcher = null;
275520
275471
  }
275521
275472
  _getSearcher(query) {
275522
- if (this._lastQuery === query) {
275473
+ if (this._lastQuery === query)
275523
275474
  return this._lastSearcher;
275524
- }
275525
- const opts = this._invertedIndex ? {
275475
+ const searcher = createSearcher(query, this._invertedIndex ? {
275526
275476
  ...this.options,
275527
275477
  _invertedIndex: this._invertedIndex
275528
- } : this.options;
275529
- const searcher = createSearcher(query, opts);
275478
+ } : this.options);
275530
275479
  this._lastQuery = query;
275531
275480
  this._lastSearcher = searcher;
275532
275481
  return searcher;
275533
275482
  }
275534
275483
  setCollection(docs, index) {
275535
275484
  this._docs = docs;
275536
- if (index && !(index instanceof FuseIndex)) {
275485
+ if (index && !(index instanceof FuseIndex))
275537
275486
  throw new Error(INCORRECT_INDEX_TYPE);
275538
- }
275539
275487
  this._myIndex = index || createIndex(this.options.keys, this._docs, {
275540
275488
  getFn: this.options.getFn,
275541
275489
  fieldNormWeight: this.options.fieldNormWeight
@@ -275543,155 +275491,137 @@ class Fuse2 {
275543
275491
  if (this.options.useTokenSearch) {
275544
275492
  const analyzer = createAnalyzer({
275545
275493
  isCaseSensitive: this.options.isCaseSensitive,
275546
- ignoreDiacritics: this.options.ignoreDiacritics
275494
+ ignoreDiacritics: this.options.ignoreDiacritics,
275495
+ tokenize: this.options.tokenize
275547
275496
  });
275548
275497
  this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
275549
275498
  }
275499
+ this._invalidateSearcherCache();
275550
275500
  }
275551
275501
  add(doc) {
275552
- if (!isDefined(doc)) {
275502
+ if (!isDefined(doc))
275553
275503
  return;
275554
- }
275555
275504
  this._docs.push(doc);
275556
- this._myIndex.add(doc);
275557
- if (this._invertedIndex) {
275558
- const record = this._myIndex.records[this._myIndex.records.length - 1];
275505
+ const record = this._myIndex.add(doc, this._docs.length - 1);
275506
+ if (this._invertedIndex && record) {
275559
275507
  const analyzer = createAnalyzer({
275560
275508
  isCaseSensitive: this.options.isCaseSensitive,
275561
- ignoreDiacritics: this.options.ignoreDiacritics
275509
+ ignoreDiacritics: this.options.ignoreDiacritics,
275510
+ tokenize: this.options.tokenize
275562
275511
  });
275563
275512
  addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
275564
275513
  }
275514
+ this._invalidateSearcherCache();
275565
275515
  }
275566
275516
  remove(predicate = () => false) {
275567
275517
  const results = [];
275568
275518
  const indicesToRemove = [];
275569
- for (let i2 = 0, len = this._docs.length;i2 < len; i2 += 1) {
275519
+ for (let i2 = 0, len = this._docs.length;i2 < len; i2 += 1)
275570
275520
  if (predicate(this._docs[i2], i2)) {
275571
275521
  results.push(this._docs[i2]);
275572
275522
  indicesToRemove.push(i2);
275573
275523
  }
275574
- }
275575
275524
  if (indicesToRemove.length) {
275576
- if (this._invertedIndex) {
275577
- for (const idx of indicesToRemove) {
275578
- removeFromInvertedIndex(this._invertedIndex, idx);
275579
- }
275580
- }
275581
- for (let i2 = indicesToRemove.length - 1;i2 >= 0; i2 -= 1) {
275582
- this._docs.splice(indicesToRemove[i2], 1);
275583
- }
275525
+ if (this._invertedIndex)
275526
+ removeAndShiftInvertedIndex(this._invertedIndex, indicesToRemove);
275527
+ const toRemove = new Set(indicesToRemove);
275528
+ this._docs = this._docs.filter((_4, i2) => !toRemove.has(i2));
275584
275529
  this._myIndex.removeAll(indicesToRemove);
275530
+ this._invalidateSearcherCache();
275585
275531
  }
275586
275532
  return results;
275587
275533
  }
275588
275534
  removeAt(idx) {
275589
- if (this._invertedIndex) {
275590
- removeFromInvertedIndex(this._invertedIndex, idx);
275591
- }
275535
+ if (!Number.isInteger(idx) || idx < 0 || idx >= this._docs.length)
275536
+ throw new Error(INVALID_DOC_INDEX);
275537
+ if (this._invertedIndex)
275538
+ removeAndShiftInvertedIndex(this._invertedIndex, [idx]);
275592
275539
  const doc = this._docs.splice(idx, 1)[0];
275593
275540
  this._myIndex.removeAt(idx);
275541
+ this._invalidateSearcherCache();
275594
275542
  return doc;
275595
275543
  }
275544
+ _invalidateSearcherCache() {
275545
+ this._lastQuery = null;
275546
+ this._lastSearcher = null;
275547
+ }
275596
275548
  getIndex() {
275597
275549
  return this._myIndex;
275598
275550
  }
275599
275551
  search(query, options) {
275600
- const {
275601
- limit = -1
275602
- } = options || {};
275603
- const {
275604
- includeMatches,
275605
- includeScore,
275606
- shouldSort,
275607
- sortFn,
275608
- ignoreFieldNorm
275609
- } = this.options;
275552
+ const { limit = -1 } = options || {};
275553
+ const { includeMatches, includeScore, shouldSort, sortFn, ignoreFieldNorm } = this.options;
275610
275554
  if (isString2(query) && !query.trim()) {
275611
275555
  let docs = this._docs.map((item, idx) => ({
275612
275556
  item,
275613
275557
  refIndex: idx
275614
275558
  }));
275615
- if (isNumber2(limit) && limit > -1) {
275559
+ if (isNumber2(limit) && limit > -1)
275616
275560
  docs = docs.slice(0, limit);
275617
- }
275618
275561
  return docs;
275619
275562
  }
275620
275563
  const useHeap = isNumber2(limit) && limit > 0 && isString2(query);
275621
275564
  let results;
275622
275565
  if (useHeap) {
275623
275566
  const heap = new MaxHeap(limit);
275624
- if (isString2(this._docs[0])) {
275567
+ if (isString2(this._docs[0]))
275625
275568
  this._searchStringList(query, {
275626
275569
  heap,
275627
275570
  ignoreFieldNorm
275628
275571
  });
275629
- } else {
275572
+ else
275630
275573
  this._searchObjectList(query, {
275631
275574
  heap,
275632
275575
  ignoreFieldNorm
275633
275576
  });
275634
- }
275635
275577
  results = heap.extractSorted(sortFn);
275636
275578
  } else {
275637
275579
  results = isString2(query) ? isString2(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
275638
- computeScore(results, {
275639
- ignoreFieldNorm
275640
- });
275641
- if (shouldSort) {
275580
+ computeScore(results, { ignoreFieldNorm });
275581
+ if (shouldSort)
275642
275582
  results.sort(sortFn);
275643
- }
275644
- if (isNumber2(limit) && limit > -1) {
275583
+ if (isNumber2(limit) && limit > -1)
275645
275584
  results = results.slice(0, limit);
275646
- }
275647
275585
  }
275648
275586
  return format(results, this._docs, {
275649
275587
  includeMatches,
275650
275588
  includeScore
275651
275589
  });
275652
275590
  }
275653
- _searchStringList(query, {
275654
- heap,
275655
- ignoreFieldNorm
275656
- } = {}) {
275591
+ _searchStringList(query, { heap, ignoreFieldNorm } = {}) {
275657
275592
  const searcher = this._getSearcher(query);
275658
- const {
275659
- records
275660
- } = this._myIndex;
275593
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
275594
+ const { records } = this._myIndex;
275661
275595
  const results = heap ? null : [];
275662
- records.forEach(({
275663
- v: text,
275664
- i: idx,
275665
- n: norm2
275666
- }) => {
275667
- if (!isDefined(text)) {
275596
+ records.forEach(({ v: text, i: idx, n: norm2 }) => {
275597
+ if (!isDefined(text))
275668
275598
  return;
275669
- }
275670
- const {
275671
- isMatch,
275672
- score,
275673
- indices
275674
- } = searcher.searchIn(text);
275675
- if (isMatch) {
275676
- const result = {
275677
- item: text,
275678
- idx,
275679
- matches: [{
275680
- score,
275681
- value: text,
275682
- norm: norm2,
275683
- indices
275684
- }]
275599
+ const searchResult = searcher.searchIn(text);
275600
+ if (searchResult.isMatch) {
275601
+ const match = {
275602
+ score: searchResult.score,
275603
+ value: text,
275604
+ norm: norm2,
275605
+ indices: searchResult.indices
275685
275606
  };
275686
- if (heap) {
275687
- result.score = computeScoreSingle(result.matches, {
275688
- ignoreFieldNorm
275689
- });
275690
- if (heap.shouldInsert(result.score)) {
275691
- heap.insert(result);
275692
- }
275693
- } else {
275694
- results.push(result);
275607
+ if (requireAllTokens) {
275608
+ match.matchedMask = searchResult.matchedMask;
275609
+ match.matchedTerms = searchResult.matchedTerms;
275610
+ match.termCount = searchResult.termCount;
275611
+ }
275612
+ const matches = [match];
275613
+ if (!requireAllTokens || this._coversAllTokens(matches)) {
275614
+ const result = {
275615
+ item: text,
275616
+ idx,
275617
+ matches
275618
+ };
275619
+ if (heap) {
275620
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
275621
+ if (heap.shouldInsert(result.score))
275622
+ heap.insert(result);
275623
+ } else
275624
+ results.push(result);
275695
275625
  }
275696
275626
  }
275697
275627
  });
@@ -275701,10 +275631,7 @@ class Fuse2 {
275701
275631
  const expression = parse3(query, this.options);
275702
275632
  const evaluate = (node, item, idx) => {
275703
275633
  if (!("children" in node)) {
275704
- const {
275705
- keyId,
275706
- searcher
275707
- } = node;
275634
+ const { keyId, searcher } = node;
275708
275635
  let matches;
275709
275636
  if (keyId === null) {
275710
275637
  matches = [];
@@ -275715,45 +275642,36 @@ class Fuse2 {
275715
275642
  searcher
275716
275643
  }));
275717
275644
  });
275718
- } else {
275645
+ } else
275719
275646
  matches = this._findMatches({
275720
275647
  key: this._keyStore.get(keyId),
275721
275648
  value: this._myIndex.getValueForItemAtKeyId(item, keyId),
275722
275649
  searcher
275723
275650
  });
275724
- }
275725
- if (matches && matches.length) {
275651
+ if (matches && matches.length)
275726
275652
  return [{
275727
275653
  idx,
275728
275654
  item,
275729
275655
  matches
275730
275656
  }];
275731
- }
275732
275657
  return [];
275733
275658
  }
275734
- const {
275735
- children,
275736
- operator
275737
- } = node;
275659
+ const { children, operator } = node;
275738
275660
  const res2 = [];
275739
275661
  for (let i2 = 0, len = children.length;i2 < len; i2 += 1) {
275740
275662
  const child = children[i2];
275741
275663
  const result = evaluate(child, item, idx);
275742
- if (result.length) {
275664
+ if (result.length)
275743
275665
  res2.push(...result);
275744
- } else if (operator === LogicalOperator.AND) {
275666
+ else if (operator === LogicalOperator.AND)
275745
275667
  return [];
275746
- }
275747
275668
  }
275748
275669
  return res2;
275749
275670
  };
275750
275671
  const records = this._myIndex.records;
275751
- const resultMap = new Map;
275672
+ const resultMap = /* @__PURE__ */ new Map;
275752
275673
  const results = [];
275753
- records.forEach(({
275754
- $: item,
275755
- i: idx
275756
- }) => {
275674
+ records.forEach(({ $: item, i: idx }) => {
275757
275675
  if (isDefined(item)) {
275758
275676
  const expResults = evaluate(expression, item, idx);
275759
275677
  if (expResults.length) {
@@ -275765,9 +275683,7 @@ class Fuse2 {
275765
275683
  });
275766
275684
  results.push(resultMap.get(idx));
275767
275685
  }
275768
- expResults.forEach(({
275769
- matches
275770
- }) => {
275686
+ expResults.forEach(({ matches }) => {
275771
275687
  resultMap.get(idx).matches.push(...matches);
275772
275688
  });
275773
275689
  }
@@ -275775,23 +275691,14 @@ class Fuse2 {
275775
275691
  });
275776
275692
  return results;
275777
275693
  }
275778
- _searchObjectList(query, {
275779
- heap,
275780
- ignoreFieldNorm
275781
- } = {}) {
275694
+ _searchObjectList(query, { heap, ignoreFieldNorm } = {}) {
275782
275695
  const searcher = this._getSearcher(query);
275783
- const {
275784
- keys,
275785
- records
275786
- } = this._myIndex;
275696
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
275697
+ const { keys, records } = this._myIndex;
275787
275698
  const results = heap ? null : [];
275788
- records.forEach(({
275789
- $: item,
275790
- i: idx
275791
- }) => {
275792
- if (!isDefined(item)) {
275699
+ records.forEach(({ $: item, i: idx }) => {
275700
+ if (!isDefined(item))
275793
275701
  return;
275794
- }
275795
275702
  const matches = [];
275796
275703
  let anyKeyFailed = false;
275797
275704
  let hasInverse = false;
@@ -275803,196 +275710,117 @@ class Fuse2 {
275803
275710
  });
275804
275711
  if (keyMatches.length) {
275805
275712
  matches.push(...keyMatches);
275806
- if (keyMatches[0].hasInverse) {
275713
+ if (keyMatches[0].hasInverse)
275807
275714
  hasInverse = true;
275808
- }
275809
- } else {
275715
+ } else
275810
275716
  anyKeyFailed = true;
275811
- }
275812
275717
  });
275813
- if (hasInverse && anyKeyFailed) {
275718
+ if (hasInverse && anyKeyFailed)
275814
275719
  return;
275815
- }
275816
- if (matches.length) {
275720
+ if (matches.length && (!requireAllTokens || this._coversAllTokens(matches))) {
275817
275721
  const result = {
275818
275722
  idx,
275819
275723
  item,
275820
275724
  matches
275821
275725
  };
275822
275726
  if (heap) {
275823
- result.score = computeScoreSingle(result.matches, {
275824
- ignoreFieldNorm
275825
- });
275826
- if (heap.shouldInsert(result.score)) {
275727
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
275728
+ if (heap.shouldInsert(result.score))
275827
275729
  heap.insert(result);
275828
- }
275829
- } else {
275730
+ } else
275830
275731
  results.push(result);
275831
- }
275832
275732
  }
275833
275733
  });
275834
275734
  return results;
275835
275735
  }
275836
- _findMatches({
275837
- key,
275838
- value,
275839
- searcher
275840
- }) {
275841
- if (!isDefined(value)) {
275736
+ _findMatches({ key, value, searcher }) {
275737
+ if (!isDefined(value))
275842
275738
  return [];
275843
- }
275844
275739
  const matches = [];
275845
- if (isArray(value)) {
275846
- value.forEach(({
275847
- v: text,
275848
- i: idx,
275849
- n: norm2
275850
- }) => {
275851
- if (!isDefined(text)) {
275740
+ if (isArray(value))
275741
+ value.forEach(({ v: text, i: idx, n: norm2 }) => {
275742
+ if (!isDefined(text))
275852
275743
  return;
275853
- }
275854
- const {
275855
- isMatch,
275856
- score,
275857
- indices,
275858
- hasInverse
275859
- } = searcher.searchIn(text);
275860
- if (isMatch) {
275861
- matches.push({
275862
- score,
275744
+ const searchResult = searcher.searchIn(text);
275745
+ if (searchResult.isMatch) {
275746
+ const match = {
275747
+ score: searchResult.score,
275863
275748
  key,
275864
275749
  value: text,
275865
275750
  idx,
275866
275751
  norm: norm2,
275867
- indices,
275868
- hasInverse
275869
- });
275752
+ indices: searchResult.indices,
275753
+ hasInverse: searchResult.hasInverse
275754
+ };
275755
+ if (searchResult.termCount !== undefined) {
275756
+ match.matchedMask = searchResult.matchedMask;
275757
+ match.matchedTerms = searchResult.matchedTerms;
275758
+ match.termCount = searchResult.termCount;
275759
+ }
275760
+ matches.push(match);
275870
275761
  }
275871
275762
  });
275872
- } else {
275873
- const {
275874
- v: text,
275875
- n: norm2
275876
- } = value;
275877
- const {
275878
- isMatch,
275879
- score,
275880
- indices,
275881
- hasInverse
275882
- } = searcher.searchIn(text);
275883
- if (isMatch) {
275884
- matches.push({
275885
- score,
275763
+ else {
275764
+ const { v: text, n: norm2 } = value;
275765
+ const searchResult = searcher.searchIn(text);
275766
+ if (searchResult.isMatch) {
275767
+ const match = {
275768
+ score: searchResult.score,
275886
275769
  key,
275887
275770
  value: text,
275888
275771
  norm: norm2,
275889
- indices,
275890
- hasInverse
275891
- });
275772
+ indices: searchResult.indices,
275773
+ hasInverse: searchResult.hasInverse
275774
+ };
275775
+ if (searchResult.termCount !== undefined) {
275776
+ match.matchedMask = searchResult.matchedMask;
275777
+ match.matchedTerms = searchResult.matchedTerms;
275778
+ match.termCount = searchResult.termCount;
275779
+ }
275780
+ matches.push(match);
275892
275781
  }
275893
275782
  }
275894
275783
  return matches;
275895
275784
  }
275896
- }
275897
-
275898
- class TokenSearch {
275899
- static condition(_4, options) {
275900
- return options.useTokenSearch;
275901
- }
275902
- constructor(pattern, options) {
275903
- this.options = options;
275904
- this.analyzer = createAnalyzer({
275905
- isCaseSensitive: options.isCaseSensitive,
275906
- ignoreDiacritics: options.ignoreDiacritics
275907
- });
275908
- const queryTerms = this.analyzer.tokenize(pattern);
275909
- const invertedIndex = options._invertedIndex;
275910
- const {
275911
- df: df3,
275912
- fieldCount
275913
- } = invertedIndex;
275914
- this.termSearchers = [];
275915
- this.idfWeights = [];
275916
- for (const term of queryTerms) {
275917
- this.termSearchers.push(new BitapSearch(term, {
275918
- location: options.location,
275919
- threshold: options.threshold,
275920
- distance: options.distance,
275921
- includeMatches: options.includeMatches,
275922
- findAllMatches: options.findAllMatches,
275923
- minMatchCharLength: options.minMatchCharLength,
275924
- isCaseSensitive: options.isCaseSensitive,
275925
- ignoreDiacritics: options.ignoreDiacritics,
275926
- ignoreLocation: true
275927
- }));
275928
- const docFreq = df3.get(term) || 0;
275929
- const idf = Math.log(1 + (fieldCount - docFreq + 0.5) / (docFreq + 0.5));
275930
- this.idfWeights.push(idf);
275931
- }
275932
- }
275933
- searchIn(text) {
275934
- if (!this.termSearchers.length) {
275935
- return {
275936
- isMatch: false,
275937
- score: 1
275938
- };
275939
- }
275940
- const allIndices = [];
275941
- let weightedScore = 0;
275942
- let maxPossibleScore = 0;
275943
- let matchedCount = 0;
275944
- for (let i2 = 0;i2 < this.termSearchers.length; i2++) {
275945
- const result = this.termSearchers[i2].searchIn(text);
275946
- const idf = this.idfWeights[i2];
275947
- maxPossibleScore += idf;
275948
- if (result.isMatch) {
275949
- matchedCount++;
275950
- weightedScore += idf * (1 - result.score);
275951
- if (result.indices) {
275952
- allIndices.push(...result.indices);
275953
- }
275954
- }
275955
- }
275956
- if (matchedCount === 0) {
275957
- return {
275958
- isMatch: false,
275959
- score: 1
275960
- };
275785
+ _coversAllTokens(matches) {
275786
+ const termCount = matches.length ? matches[0].termCount : undefined;
275787
+ if (termCount === undefined)
275788
+ return true;
275789
+ if (termCount <= 31) {
275790
+ let coverage2 = 0;
275791
+ for (let i2 = 0;i2 < matches.length; i2++)
275792
+ coverage2 |= matches[i2].matchedMask || 0;
275793
+ return coverage2 === 2 ** termCount - 1;
275961
275794
  }
275962
- const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
275963
- const searchResult = {
275964
- isMatch: true,
275965
- score: Math.max(0.001, normalized)
275966
- };
275967
- if (this.options.includeMatches && allIndices.length) {
275968
- searchResult.indices = mergeIndices(allIndices);
275795
+ const coverage = /* @__PURE__ */ new Set;
275796
+ for (let i2 = 0;i2 < matches.length; i2++) {
275797
+ const terms = matches[i2].matchedTerms;
275798
+ if (terms)
275799
+ for (const t17 of terms)
275800
+ coverage.add(t17);
275969
275801
  }
275970
- return searchResult;
275802
+ return coverage.size === termCount;
275971
275803
  }
275972
- }
275973
- Fuse2.version = "7.3.0";
275804
+ };
275805
+ Fuse2.version = "7.4.2";
275974
275806
  Fuse2.createIndex = createIndex;
275975
275807
  Fuse2.parseIndex = parseIndex;
275976
275808
  Fuse2.config = Config;
275977
275809
  Fuse2.match = function(pattern, text, options) {
275978
- const searcher = createSearcher(pattern, {
275810
+ if (options && options.useTokenSearch)
275811
+ throw new Error(FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED);
275812
+ return createSearcher(pattern, {
275979
275813
  ...Config,
275980
275814
  ...options
275981
- });
275982
- return searcher.searchIn(text);
275815
+ }).searchIn(text);
275983
275816
  };
275984
- {
275985
- Fuse2.parseQuery = parse3;
275986
- }
275987
- {
275988
- register2(ExtendedSearch);
275989
- }
275990
- {
275991
- register2(TokenSearch);
275992
- }
275817
+ Fuse2.parseQuery = parse3;
275818
+ register2(ExtendedSearch);
275819
+ register2(TokenSearch);
275993
275820
  Fuse2.use = function(...plugins) {
275994
275821
  plugins.forEach((plugin) => register2(plugin));
275995
275822
  };
275823
+ var entry_default = Fuse2;
275996
275824
 
275997
275825
  // cli/search/register.ts
275998
275826
  var registerSearch = (program3) => {
@@ -276019,7 +275847,7 @@ var registerSearch = (program3) => {
276019
275847
  }
276020
275848
  if (searchKicad) {
276021
275849
  const kicadFiles = await fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then((r4) => r4.json());
276022
- const fuse = new Fuse2(kicadFiles);
275850
+ const fuse = new entry_default(kicadFiles);
276023
275851
  kicadResults = fuse.search(query).slice(0, 10).map((r4) => r4.item);
276024
275852
  }
276025
275853
  } catch (error) {
@@ -279312,8 +279140,7 @@ var processSnapshotFile = async ({
279312
279140
  };
279313
279141
 
279314
279142
  // lib/shared/snapshot-project.ts
279315
- var hasConfiguredIncludeBoardFiles = (projectDir) => {
279316
- const projectConfig2 = loadProjectConfig(projectDir);
279143
+ var hasConfiguredIncludeBoardFiles = (projectConfig2) => {
279317
279144
  const hasConfiguredPatterns = Boolean(projectConfig2?.includeBoardFiles?.some((pattern) => pattern.trim()));
279318
279145
  return hasConfiguredPatterns;
279319
279146
  };
@@ -279338,7 +279165,7 @@ var snapshotProject = async ({
279338
279165
  threeD = true;
279339
279166
  }
279340
279167
  const projectDir = process.cwd();
279341
- const projectConfig2 = loadProjectConfig(projectDir);
279168
+ const projectConfig2 = await loadRuntimeProjectConfig(projectDir);
279342
279169
  const ignore = [
279343
279170
  ...DEFAULT_IGNORED_PATTERNS,
279344
279171
  ...ignored.map(normalizeIgnorePattern)
@@ -279350,7 +279177,7 @@ var snapshotProject = async ({
279350
279177
  }
279351
279178
  return fs66.statSync(resolvedPath).isDirectory();
279352
279179
  });
279353
- const boardFiles = findBoardFiles({
279180
+ const boardFiles = await findBoardFilesAsync({
279354
279181
  projectDir,
279355
279182
  ignore,
279356
279183
  filePaths: resolvedPaths
@@ -279358,8 +279185,9 @@ var snapshotProject = async ({
279358
279185
  if (boardFiles.length === 0) {
279359
279186
  if (explicitDirectoryTarget) {
279360
279187
  const relativeDirectory = path70.relative(projectDir, explicitDirectoryTarget) || ".";
279361
- const includeBoardFilePatterns = getBoardFilePatterns(projectDir);
279362
- const patternSourceMessage = hasConfiguredIncludeBoardFiles(projectDir) ? "Searched using tscircuit.config.json includeBoardFiles" : "Searched using default includeBoardFiles";
279188
+ const runtimeIncludeBoardFilePatterns = projectConfig2?.includeBoardFiles?.filter((pattern) => pattern.trim()) ?? [];
279189
+ const includeBoardFilePatterns = runtimeIncludeBoardFilePatterns.length > 0 ? runtimeIncludeBoardFilePatterns : getBoardFilePatterns(projectDir);
279190
+ const patternSourceMessage = hasConfiguredIncludeBoardFiles(projectConfig2) ? "Searched using tscircuit.config.json includeBoardFiles" : "Searched using default includeBoardFiles";
279363
279191
  onError([
279364
279192
  `No circuit files found to create snapshots in directory: "${relativeDirectory}"`,
279365
279193
  `${patternSourceMessage}: ${JSON.stringify(includeBoardFilePatterns)}`
@@ -279370,8 +279198,9 @@ var snapshotProject = async ({
279370
279198
  console.log("No entrypoint found. Run 'tsci init' to bootstrap a project or specify a file with 'tsci snapshot <file>'");
279371
279199
  return onExit2(0);
279372
279200
  }
279373
- const snapshotsDirName = getSnapshotsDir(projectDir);
279201
+ const snapshotsDirName = projectConfig2?.snapshotsDir ?? getSnapshotsDir(projectDir);
279374
279202
  const pcbSnapshotSettings = pcbSnapshotSettingsOverride ? { ...projectConfig2?.pcbSnapshotSettings, ...pcbSnapshotSettingsOverride } : projectConfig2?.pcbSnapshotSettings;
279203
+ const mergedPlatformConfig = mergePlatformConfigs(projectConfig2?.platformConfig, platformConfig2);
279375
279204
  const mismatches = [];
279376
279205
  let didUpdate = false;
279377
279206
  const concurrencyValue = Math.max(1, concurrency);
@@ -279439,7 +279268,7 @@ var snapshotProject = async ({
279439
279268
  pcbOnly,
279440
279269
  schematicOnly,
279441
279270
  forceUpdate,
279442
- platformConfig: platformConfig2,
279271
+ platformConfig: mergedPlatformConfig,
279443
279272
  pcbSnapshotSettings,
279444
279273
  createDiff: createDiff2,
279445
279274
  cameraPreset