@tscircuit/cli 0.1.1467 → 0.1.1468

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.1467";
100692
100767
  var package_default = {
100693
100768
  name: "@tscircuit/cli",
100694
100769
  version,
@@ -100709,7 +100784,7 @@ var package_default = {
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",
100715
100790
  "@types/bun": "^1.2.2",
@@ -274069,12 +274144,10 @@ function isArray(value) {
274069
274144
  return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
274070
274145
  }
274071
274146
  function baseToString(value) {
274072
- if (typeof value == "string") {
274147
+ if (typeof value == "string")
274073
274148
  return value;
274074
- }
274075
- if (typeof value === "bigint") {
274149
+ if (typeof value === "bigint")
274076
274150
  return value.toString();
274077
- }
274078
274151
  const result = value + "";
274079
274152
  return result == "0" && 1 / value == -Infinity ? "-0" : result;
274080
274153
  }
@@ -274106,13 +274179,14 @@ function getTag(value) {
274106
274179
  return value == null ? value === undefined ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
274107
274180
  }
274108
274181
  var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
274182
+ var INVALID_DOC_INDEX = "Invalid doc index: must be a non-negative integer within the bounds of the docs array";
274109
274183
  var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
274110
274184
  var PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
274111
274185
  var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
274112
274186
  var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
274187
+ 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
274188
  var hasOwn = Object.prototype.hasOwnProperty;
274114
-
274115
- class KeyStore {
274189
+ var KeyStore = class {
274116
274190
  constructor(keys) {
274117
274191
  this._keys = [];
274118
274192
  this._keyMap = {};
@@ -274136,7 +274210,7 @@ class KeyStore {
274136
274210
  toJSON() {
274137
274211
  return JSON.stringify(this._keys);
274138
274212
  }
274139
- }
274213
+ };
274140
274214
  function createKey(key) {
274141
274215
  let path67 = null;
274142
274216
  let id2 = null;
@@ -274148,20 +274222,18 @@ function createKey(key) {
274148
274222
  path67 = createKeyPath(key);
274149
274223
  id2 = createKeyId(key);
274150
274224
  } else {
274151
- if (!hasOwn.call(key, "name")) {
274225
+ if (!hasOwn.call(key, "name"))
274152
274226
  throw new Error(MISSING_KEY_PROPERTY("name"));
274153
- }
274154
274227
  const name = key.name;
274155
274228
  src = name;
274156
- if (hasOwn.call(key, "weight")) {
274229
+ if (hasOwn.call(key, "weight") && key.weight !== undefined) {
274157
274230
  weight = key.weight;
274158
- if (weight <= 0) {
274159
- throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
274160
- }
274231
+ if (weight <= 0)
274232
+ throw new Error(INVALID_KEY_WEIGHT_VALUE(createKeyId(name)));
274161
274233
  }
274162
274234
  path67 = createKeyPath(name);
274163
274235
  id2 = createKeyId(name);
274164
- getFn = key.getFn;
274236
+ getFn = key.getFn ?? null;
274165
274237
  }
274166
274238
  return {
274167
274239
  path: path67,
@@ -274181,33 +274253,28 @@ function get(obj, path67) {
274181
274253
  const list = [];
274182
274254
  let arr = false;
274183
274255
  const deepGet = (obj2, path68, index, arrayIndex) => {
274184
- if (!isDefined(obj2)) {
274256
+ if (!isDefined(obj2))
274185
274257
  return;
274186
- }
274187
- if (!path68[index]) {
274258
+ if (!path68[index])
274188
274259
  list.push(arrayIndex !== undefined ? {
274189
274260
  v: obj2,
274190
274261
  i: arrayIndex
274191
274262
  } : obj2);
274192
- } else {
274193
- const key = path68[index];
274194
- const value = obj2[key];
274195
- if (!isDefined(value)) {
274263
+ else {
274264
+ const value = obj2[path68[index]];
274265
+ if (!isDefined(value))
274196
274266
  return;
274197
- }
274198
- if (index === path68.length - 1 && (isString2(value) || isNumber2(value) || isBoolean(value) || typeof value === "bigint")) {
274267
+ if (index === path68.length - 1 && (isString2(value) || isNumber2(value) || isBoolean(value) || typeof value === "bigint"))
274199
274268
  list.push(arrayIndex !== undefined ? {
274200
274269
  v: toString2(value),
274201
274270
  i: arrayIndex
274202
274271
  } : toString2(value));
274203
- } else if (isArray(value)) {
274272
+ else if (isArray(value)) {
274204
274273
  arr = true;
274205
- for (let i2 = 0, len = value.length;i2 < len; i2 += 1) {
274274
+ for (let i2 = 0, len = value.length;i2 < len; i2 += 1)
274206
274275
  deepGet(value[i2], path68, index + 1, i2);
274207
- }
274208
- } else if (path68.length) {
274276
+ } else if (path68.length)
274209
274277
  deepGet(value, path68, index + 1, arrayIndex);
274210
- }
274211
274278
  }
274212
274279
  };
274213
274280
  deepGet(obj, isString2(path67) ? path67.split(".") : path67, 0);
@@ -274234,6 +274301,8 @@ var FuzzyOptions = {
274234
274301
  var AdvancedOptions = {
274235
274302
  useExtendedSearch: false,
274236
274303
  useTokenSearch: false,
274304
+ tokenize: undefined,
274305
+ tokenMatch: "any",
274237
274306
  getFn: get,
274238
274307
  ignoreLocation: false,
274239
274308
  ignoreFieldNorm: false,
@@ -274245,18 +274314,24 @@ var Config = Object.freeze({
274245
274314
  ...FuzzyOptions,
274246
274315
  ...AdvancedOptions
274247
274316
  });
274248
- var SPACE = /[^ ]+/g;
274249
274317
  function norm(weight = 1, mantissa = 3) {
274250
- const cache = new Map;
274318
+ const cache = /* @__PURE__ */ new Map;
274251
274319
  const m3 = Math.pow(10, mantissa);
274252
274320
  return {
274253
274321
  get(value) {
274254
- const numTokens = value.match(SPACE).length;
274255
- if (cache.has(numTokens)) {
274322
+ let numTokens = 1;
274323
+ let inSpace = false;
274324
+ for (let i2 = 0;i2 < value.length; i2++)
274325
+ if (value.charCodeAt(i2) === 32) {
274326
+ if (!inSpace) {
274327
+ numTokens++;
274328
+ inSpace = true;
274329
+ }
274330
+ } else
274331
+ inSpace = false;
274332
+ if (cache.has(numTokens))
274256
274333
  return cache.get(numTokens);
274257
- }
274258
- const norm2 = 1 / Math.pow(numTokens, 0.5 * weight);
274259
- const n3 = parseFloat(Math.round(norm2 * m3) / m3);
274334
+ const n3 = Math.round(m3 / Math.pow(numTokens, 0.5 * weight)) / m3;
274260
274335
  cache.set(numTokens, n3);
274261
274336
  return n3;
274262
274337
  },
@@ -274265,12 +274340,8 @@ function norm(weight = 1, mantissa = 3) {
274265
274340
  }
274266
274341
  };
274267
274342
  }
274268
-
274269
- class FuseIndex {
274270
- constructor({
274271
- getFn = Config.getFn,
274272
- fieldNormWeight = Config.fieldNormWeight
274273
- } = {}) {
274343
+ var FuseIndex = class {
274344
+ constructor({ getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
274274
274345
  this.norm = norm(fieldNormWeight, 3);
274275
274346
  this.getFn = getFn;
274276
274347
  this.isCreated = false;
@@ -274293,41 +274364,69 @@ class FuseIndex {
274293
274364
  });
274294
274365
  }
274295
274366
  create() {
274296
- if (this.isCreated || !this.docs.length) {
274367
+ if (this.isCreated || !this.docs.length)
274297
274368
  return;
274298
- }
274299
274369
  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
- }
274370
+ const len = this.docs.length;
274371
+ this.records = new Array(len);
274372
+ let recordCount = 0;
274373
+ if (isString2(this.docs[0]))
274374
+ for (let i2 = 0;i2 < len; i2++) {
274375
+ const record = this._createStringRecord(this.docs[i2], i2);
274376
+ if (record)
274377
+ this.records[recordCount++] = record;
274378
+ }
274379
+ else
274380
+ for (let i2 = 0;i2 < len; i2++)
274381
+ this.records[recordCount++] = this._createObjectRecord(this.docs[i2], i2);
274382
+ this.records.length = recordCount;
274309
274383
  this.norm.clear();
274310
274384
  }
274311
- add(doc) {
274312
- const idx = this.size();
274385
+ add(doc, docIndex) {
274386
+ if (!Number.isInteger(docIndex) || docIndex < 0)
274387
+ throw new Error(INVALID_DOC_INDEX);
274313
274388
  if (isString2(doc)) {
274314
- this._addString(doc, idx);
274315
- } else {
274316
- this._addObject(doc, idx);
274389
+ const record2 = this._createStringRecord(doc, docIndex);
274390
+ if (record2)
274391
+ this.records.push(record2);
274392
+ return record2;
274317
274393
  }
274394
+ const record = this._createObjectRecord(doc, docIndex);
274395
+ this.records.push(record);
274396
+ return record;
274318
274397
  }
274319
274398
  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
- }
274399
+ if (!Number.isInteger(idx) || idx < 0)
274400
+ throw new Error(INVALID_DOC_INDEX);
274401
+ for (let i2 = 0, len = this.records.length;i2 < len; i2 += 1)
274402
+ if (this.records[i2].i === idx) {
274403
+ this.records.splice(i2, 1);
274404
+ break;
274405
+ }
274406
+ for (let i2 = 0, len = this.records.length;i2 < len; i2 += 1)
274407
+ if (this.records[i2].i > idx)
274408
+ this.records[i2].i -= 1;
274324
274409
  }
274325
274410
  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;
274411
+ const toRemove = /* @__PURE__ */ new Set;
274412
+ for (const v3 of indices)
274413
+ if (Number.isInteger(v3) && v3 >= 0)
274414
+ toRemove.add(v3);
274415
+ if (toRemove.size === 0)
274416
+ return;
274417
+ this.records = this.records.filter((r4) => !toRemove.has(r4.i));
274418
+ const sorted = Array.from(toRemove).sort((a2, b) => a2 - b);
274419
+ for (const record of this.records) {
274420
+ let lo3 = 0;
274421
+ let hi3 = sorted.length;
274422
+ while (lo3 < hi3) {
274423
+ const mid = lo3 + hi3 >>> 1;
274424
+ if (sorted[mid] < record.i)
274425
+ lo3 = mid + 1;
274426
+ else
274427
+ hi3 = mid;
274428
+ }
274429
+ record.i -= lo3;
274331
274430
  }
274332
274431
  }
274333
274432
  getValueForItemAtKeyId(item, keyId) {
@@ -274336,34 +274435,31 @@ class FuseIndex {
274336
274435
  size() {
274337
274436
  return this.records.length;
274338
274437
  }
274339
- _addString(doc, docIndex) {
274340
- if (!isDefined(doc) || isBlank(doc)) {
274341
- return;
274342
- }
274343
- const record = {
274438
+ _createStringRecord(doc, docIndex) {
274439
+ if (!isDefined(doc) || isBlank(doc))
274440
+ return null;
274441
+ return {
274344
274442
  v: doc,
274345
274443
  i: docIndex,
274346
274444
  n: this.norm.get(doc)
274347
274445
  };
274348
- this.records.push(record);
274349
274446
  }
274350
- _addObject(doc, docIndex) {
274447
+ _createObjectRecord(doc, docIndex) {
274351
274448
  const record = {
274352
274449
  i: docIndex,
274353
274450
  $: {}
274354
274451
  };
274355
- this.keys.forEach((key, keyIndex) => {
274452
+ for (let keyIndex = 0, keyLen = this.keys.length;keyIndex < keyLen; keyIndex++) {
274453
+ const key = this.keys[keyIndex];
274356
274454
  const value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
274357
- if (!isDefined(value)) {
274358
- return;
274359
- }
274455
+ if (!isDefined(value))
274456
+ continue;
274360
274457
  if (isArray(value)) {
274361
274458
  const subRecords = [];
274362
274459
  for (let i2 = 0, len = value.length;i2 < len; i2 += 1) {
274363
274460
  const item = value[i2];
274364
- if (!isDefined(item)) {
274461
+ if (!isDefined(item))
274365
274462
  continue;
274366
- }
274367
274463
  if (isString2(item)) {
274368
274464
  if (!isBlank(item)) {
274369
274465
  const subRecord = {
@@ -274393,23 +274489,17 @@ class FuseIndex {
274393
274489
  };
274394
274490
  record.$[keyIndex] = subRecord;
274395
274491
  }
274396
- });
274397
- this.records.push(record);
274492
+ }
274493
+ return record;
274398
274494
  }
274399
274495
  toJSON() {
274400
274496
  return {
274401
- keys: this.keys.map(({
274402
- getFn,
274403
- ...key
274404
- }) => key),
274497
+ keys: this.keys.map(({ getFn, ...key }) => key),
274405
274498
  records: this.records
274406
274499
  };
274407
274500
  }
274408
- }
274409
- function createIndex(keys, docs, {
274410
- getFn = Config.getFn,
274411
- fieldNormWeight = Config.fieldNormWeight
274412
- } = {}) {
274501
+ };
274502
+ function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
274413
274503
  const myIndex = new FuseIndex({
274414
274504
  getFn,
274415
274505
  fieldNormWeight
@@ -274419,14 +274509,8 @@ function createIndex(keys, docs, {
274419
274509
  myIndex.create();
274420
274510
  return myIndex;
274421
274511
  }
274422
- function parseIndex(data, {
274423
- getFn = Config.getFn,
274424
- fieldNormWeight = Config.fieldNormWeight
274425
- } = {}) {
274426
- const {
274427
- keys,
274428
- records
274429
- } = data;
274512
+ function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
274513
+ const { keys, records } = data;
274430
274514
  const myIndex = new FuseIndex({
274431
274515
  getFn,
274432
274516
  fieldNormWeight
@@ -274442,34 +274526,22 @@ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMat
274442
274526
  let i2 = 0;
274443
274527
  for (let len = matchmask.length;i2 < len; i2 += 1) {
274444
274528
  const match = matchmask[i2];
274445
- if (match && start === -1) {
274529
+ if (match && start === -1)
274446
274530
  start = i2;
274447
- } else if (!match && start !== -1) {
274531
+ else if (!match && start !== -1) {
274448
274532
  end = i2 - 1;
274449
- if (end - start + 1 >= minMatchCharLength) {
274533
+ if (end - start + 1 >= minMatchCharLength)
274450
274534
  indices.push([start, end]);
274451
- }
274452
274535
  start = -1;
274453
274536
  }
274454
274537
  }
274455
- if (matchmask[i2 - 1] && i2 - start >= minMatchCharLength) {
274538
+ if (matchmask[i2 - 1] && i2 - start >= minMatchCharLength)
274456
274539
  indices.push([start, i2 - 1]);
274457
- }
274458
274540
  return indices;
274459
274541
  }
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
- }
274542
+ 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 } = {}) {
274543
+ if (pattern.length > 32)
274544
+ throw new Error(PATTERN_LENGTH_TOO_LARGE(32));
274473
274545
  const patternLen = pattern.length;
274474
274546
  const textLen = text.length;
274475
274547
  const expectedLocation = Math.max(0, Math.min(location, textLen));
@@ -274502,18 +274574,17 @@ function search(text, pattern, patternAlphabet, {
274502
274574
  bestLocation = -1;
274503
274575
  let lastBitArr = [];
274504
274576
  let finalScore = 1;
274577
+ let bestErrors = 0;
274505
274578
  let binMax = patternLen + textLen;
274506
274579
  const mask = 1 << patternLen - 1;
274507
274580
  for (let i2 = 0;i2 < patternLen; i2 += 1) {
274508
274581
  let binMin = 0;
274509
274582
  let binMid = binMax;
274510
274583
  while (binMin < binMid) {
274511
- const score2 = calcScore(i2, expectedLocation + binMid);
274512
- if (score2 <= currentThreshold) {
274584
+ if (calcScore(i2, expectedLocation + binMid) <= currentThreshold)
274513
274585
  binMin = binMid;
274514
- } else {
274586
+ else
274515
274587
  binMax = binMid;
274516
- }
274517
274588
  binMid = Math.floor((binMax - binMin) / 2 + binMin);
274518
274589
  }
274519
274590
  binMax = binMid;
@@ -274524,42 +274595,41 @@ function search(text, pattern, patternAlphabet, {
274524
274595
  for (let j4 = finish;j4 >= start; j4 -= 1) {
274525
274596
  const currentLocation = j4 - 1;
274526
274597
  const charMatch = patternAlphabet[text[currentLocation]];
274527
- if (computeMatches) {
274528
- matchMask[currentLocation] = +!!charMatch;
274529
- }
274530
274598
  bitArr[j4] = (bitArr[j4 + 1] << 1 | 1) & charMatch;
274531
- if (i2) {
274599
+ if (i2)
274532
274600
  bitArr[j4] |= (lastBitArr[j4 + 1] | lastBitArr[j4]) << 1 | 1 | lastBitArr[j4 + 1];
274533
- }
274534
274601
  if (bitArr[j4] & mask) {
274535
274602
  finalScore = calcScore(i2, currentLocation);
274536
274603
  if (finalScore <= currentThreshold) {
274537
274604
  currentThreshold = finalScore;
274538
274605
  bestLocation = currentLocation;
274539
- if (bestLocation <= expectedLocation) {
274606
+ bestErrors = i2;
274607
+ if (bestLocation <= expectedLocation)
274540
274608
  break;
274541
- }
274542
274609
  start = Math.max(1, 2 * expectedLocation - bestLocation);
274543
274610
  }
274544
274611
  }
274545
274612
  }
274546
- const score = calcScore(i2 + 1, expectedLocation);
274547
- if (score > currentThreshold) {
274613
+ if (calcScore(i2 + 1, expectedLocation) > currentThreshold)
274548
274614
  break;
274549
- }
274550
274615
  lastBitArr = bitArr;
274551
274616
  }
274617
+ if (computeMatches && bestLocation >= 0) {
274618
+ const matchEnd = Math.min(textLen - 1, bestLocation + patternLen - 1 + bestErrors);
274619
+ for (let k4 = bestLocation;k4 <= matchEnd; k4 += 1)
274620
+ if (patternAlphabet[text[k4]])
274621
+ matchMask[k4] = 1;
274622
+ }
274552
274623
  const result = {
274553
274624
  isMatch: bestLocation >= 0,
274554
274625
  score: Math.max(0.001, finalScore)
274555
274626
  };
274556
274627
  if (computeMatches) {
274557
274628
  const indices = convertMaskToIndices(matchMask, minMatchCharLength);
274558
- if (!indices.length) {
274629
+ if (!indices.length)
274559
274630
  result.isMatch = false;
274560
- } else if (includeMatches) {
274631
+ else if (includeMatches)
274561
274632
  result.indices = indices;
274562
- }
274563
274633
  }
274564
274634
  return result;
274565
274635
  }
@@ -274579,11 +274649,10 @@ function mergeIndices(indices) {
274579
274649
  for (let i2 = 1, len = indices.length;i2 < len; i2 += 1) {
274580
274650
  const last = merged[merged.length - 1];
274581
274651
  const curr = indices[i2];
274582
- if (curr[0] <= last[1] + 1) {
274652
+ if (curr[0] <= last[1] + 1)
274583
274653
  last[1] = Math.max(last[1], curr[1]);
274584
- } else {
274654
+ else
274585
274655
  merged.push(curr);
274586
- }
274587
274656
  }
274588
274657
  return merged;
274589
274658
  }
@@ -274602,20 +274671,9 @@ var NON_DECOMPOSABLE_MAP = {
274602
274671
  "ß": "ss"
274603
274672
  };
274604
274673
  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
- } = {}) {
274674
+ 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;
274675
+ var BitapSearch = class {
274676
+ 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
274677
  this.options = {
274620
274678
  location,
274621
274679
  threshold,
@@ -274631,9 +274689,8 @@ class BitapSearch {
274631
274689
  pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
274632
274690
  this.pattern = pattern;
274633
274691
  this.chunks = [];
274634
- if (!this.pattern.length) {
274692
+ if (!this.pattern.length)
274635
274693
  return;
274636
- }
274637
274694
  const addChunk = (pattern2, startIndex) => {
274638
274695
  this.chunks.push({
274639
274696
  pattern: pattern2,
@@ -274642,28 +274699,23 @@ class BitapSearch {
274642
274699
  });
274643
274700
  };
274644
274701
  const len = this.pattern.length;
274645
- if (len > MAX_BITS) {
274702
+ if (len > 32) {
274646
274703
  let i2 = 0;
274647
- const remainder = len % MAX_BITS;
274704
+ const remainder = len % 32;
274648
274705
  const end = len - remainder;
274649
274706
  while (i2 < end) {
274650
- addChunk(this.pattern.substr(i2, MAX_BITS), i2);
274651
- i2 += MAX_BITS;
274707
+ addChunk(this.pattern.substr(i2, 32), i2);
274708
+ i2 += 32;
274652
274709
  }
274653
274710
  if (remainder) {
274654
- const startIndex = len - MAX_BITS;
274711
+ const startIndex = len - 32;
274655
274712
  addChunk(this.pattern.substr(startIndex), startIndex);
274656
274713
  }
274657
- } else {
274714
+ } else
274658
274715
  addChunk(this.pattern, 0);
274659
- }
274660
274716
  }
274661
274717
  searchIn(text) {
274662
- const {
274663
- isCaseSensitive,
274664
- ignoreDiacritics,
274665
- includeMatches
274666
- } = this.options;
274718
+ const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
274667
274719
  text = isCaseSensitive ? text : text.toLowerCase();
274668
274720
  text = ignoreDiacritics ? stripDiacritics(text) : text;
274669
274721
  if (this.pattern === text) {
@@ -274671,32 +274723,16 @@ class BitapSearch {
274671
274723
  isMatch: true,
274672
274724
  score: 0
274673
274725
  };
274674
- if (includeMatches) {
274726
+ if (includeMatches)
274675
274727
  result2.indices = [[0, text.length - 1]];
274676
- }
274677
274728
  return result2;
274678
274729
  }
274679
- const {
274680
- location,
274681
- distance: distance7,
274682
- threshold,
274683
- findAllMatches,
274684
- minMatchCharLength,
274685
- ignoreLocation
274686
- } = this.options;
274730
+ const { location, distance: distance7, threshold, findAllMatches, minMatchCharLength, ignoreLocation } = this.options;
274687
274731
  const allIndices = [];
274688
274732
  let totalScore = 0;
274689
274733
  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, {
274734
+ this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
274735
+ const { isMatch, score, indices } = search(text, pattern, alphabet, {
274700
274736
  location: location + startIndex,
274701
274737
  distance: distance7,
274702
274738
  threshold,
@@ -274705,257 +274741,172 @@ class BitapSearch {
274705
274741
  includeMatches,
274706
274742
  ignoreLocation
274707
274743
  });
274708
- if (isMatch) {
274744
+ if (isMatch)
274709
274745
  hasMatches = true;
274710
- }
274711
274746
  totalScore += score;
274712
- if (isMatch && indices) {
274747
+ if (isMatch && indices)
274713
274748
  allIndices.push(...indices);
274714
- }
274715
274749
  });
274716
274750
  const result = {
274717
274751
  isMatch: hasMatches,
274718
274752
  score: hasMatches ? totalScore / this.chunks.length : 1
274719
274753
  };
274720
- if (hasMatches && includeMatches) {
274754
+ if (hasMatches && includeMatches)
274721
274755
  result.indices = mergeIndices(allIndices);
274722
- }
274723
274756
  return result;
274724
274757
  }
274758
+ };
274759
+ var MULTI_MATCH_TYPES = new Set(["fuzzy", "include"]);
274760
+ function isInverse(type) {
274761
+ return type.startsWith("inverse");
274725
274762
  }
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]);
274763
+ var matchers = [
274764
+ {
274765
+ type: "exact",
274766
+ multiRegex: /^="(.*)"$/,
274767
+ singleRegex: /^=(.*)$/,
274768
+ create: (pattern) => ({
274769
+ type: "exact",
274770
+ search(text) {
274771
+ const isMatch = text === pattern;
274772
+ return {
274773
+ isMatch,
274774
+ score: isMatch ? 0 : 1,
274775
+ indices: [0, pattern.length - 1]
274776
+ };
274777
+ }
274778
+ })
274779
+ },
274780
+ {
274781
+ type: "include",
274782
+ multiRegex: /^'"(.*)"$/,
274783
+ singleRegex: /^'(.*)$/,
274784
+ create: (pattern) => ({
274785
+ type: "include",
274786
+ search(text) {
274787
+ let location = 0;
274788
+ let index;
274789
+ const indices = [];
274790
+ const patternLen = pattern.length;
274791
+ while ((index = text.indexOf(pattern, location)) > -1) {
274792
+ location = index + patternLen;
274793
+ indices.push([index, location - 1]);
274794
+ }
274795
+ const isMatch = !!indices.length;
274796
+ return {
274797
+ isMatch,
274798
+ score: isMatch ? 0 : 1,
274799
+ indices
274800
+ };
274801
+ }
274802
+ })
274803
+ },
274804
+ {
274805
+ type: "prefix-exact",
274806
+ multiRegex: /^\^"(.*)"$/,
274807
+ singleRegex: /^\^(.*)$/,
274808
+ create: (pattern) => ({
274809
+ type: "prefix-exact",
274810
+ search(text) {
274811
+ const isMatch = text.startsWith(pattern);
274812
+ return {
274813
+ isMatch,
274814
+ score: isMatch ? 0 : 1,
274815
+ indices: [0, pattern.length - 1]
274816
+ };
274817
+ }
274818
+ })
274819
+ },
274820
+ {
274821
+ type: "inverse-prefix-exact",
274822
+ multiRegex: /^!\^"(.*)"$/,
274823
+ singleRegex: /^!\^(.*)$/,
274824
+ create: (pattern) => ({
274825
+ type: "inverse-prefix-exact",
274826
+ search(text) {
274827
+ const isMatch = !text.startsWith(pattern);
274828
+ return {
274829
+ isMatch,
274830
+ score: isMatch ? 0 : 1,
274831
+ indices: [0, text.length - 1]
274832
+ };
274833
+ }
274834
+ })
274835
+ },
274836
+ {
274837
+ type: "inverse-suffix-exact",
274838
+ multiRegex: /^!"(.*)"\$$/,
274839
+ singleRegex: /^!(.*)\$$/,
274840
+ create: (pattern) => ({
274841
+ type: "inverse-suffix-exact",
274842
+ search(text) {
274843
+ const isMatch = !text.endsWith(pattern);
274844
+ return {
274845
+ isMatch,
274846
+ score: isMatch ? 0 : 1,
274847
+ indices: [0, text.length - 1]
274848
+ };
274849
+ }
274850
+ })
274851
+ },
274852
+ {
274853
+ type: "suffix-exact",
274854
+ multiRegex: /^"(.*)"\$$/,
274855
+ singleRegex: /^(.*)\$$/,
274856
+ create: (pattern) => ({
274857
+ type: "suffix-exact",
274858
+ search(text) {
274859
+ const isMatch = text.endsWith(pattern);
274860
+ return {
274861
+ isMatch,
274862
+ score: isMatch ? 0 : 1,
274863
+ indices: [text.length - pattern.length, text.length - 1]
274864
+ };
274865
+ }
274866
+ })
274867
+ },
274868
+ {
274869
+ type: "inverse-exact",
274870
+ multiRegex: /^!"(.*)"$/,
274871
+ singleRegex: /^!(.*)$/,
274872
+ create: (pattern) => ({
274873
+ type: "inverse-exact",
274874
+ search(text) {
274875
+ const isMatch = text.indexOf(pattern) === -1;
274876
+ return {
274877
+ isMatch,
274878
+ score: isMatch ? 0 : 1,
274879
+ indices: [0, text.length - 1]
274880
+ };
274881
+ }
274882
+ })
274883
+ },
274884
+ {
274885
+ type: "fuzzy",
274886
+ multiRegex: /^"(.*)"$/,
274887
+ singleRegex: /^(.*)$/,
274888
+ create: (pattern, options = {}) => {
274889
+ const bitap = new BitapSearch(pattern, {
274890
+ location: options.location ?? Config.location,
274891
+ threshold: options.threshold ?? Config.threshold,
274892
+ distance: options.distance ?? Config.distance,
274893
+ includeMatches: options.includeMatches ?? Config.includeMatches,
274894
+ findAllMatches: options.findAllMatches ?? Config.findAllMatches,
274895
+ minMatchCharLength: options.minMatchCharLength ?? Config.minMatchCharLength,
274896
+ isCaseSensitive: options.isCaseSensitive ?? Config.isCaseSensitive,
274897
+ ignoreDiacritics: options.ignoreDiacritics ?? Config.ignoreDiacritics,
274898
+ ignoreLocation: options.ignoreLocation ?? Config.ignoreLocation
274899
+ });
274900
+ return {
274901
+ type: "fuzzy",
274902
+ search(text) {
274903
+ return bitap.searchIn(text);
274904
+ }
274905
+ };
274948
274906
  }
274949
- const isMatch = !!indices.length;
274950
- return {
274951
- isMatch,
274952
- score: isMatch ? 0 : 1,
274953
- indices
274954
- };
274955
274907
  }
274956
- }
274957
- var searchers = [ExactMatch, IncludeMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch];
274958
- var searchersLen = searchers.length;
274908
+ ];
274909
+ var matchersLen = matchers.length;
274959
274910
  var ESCAPED_PIPE = "\x00";
274960
274911
  var OR_TOKEN = "|";
274961
274912
  function tokenize3(pattern) {
@@ -274997,33 +274948,34 @@ function tokenize3(pattern) {
274997
274948
  }
274998
274949
  return tokens;
274999
274950
  }
274951
+ function getMatch(pattern, exp) {
274952
+ const matches = pattern.match(exp);
274953
+ return matches ? matches[1] : null;
274954
+ }
275000
274955
  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());
274956
+ return pattern.replace(/\\\|/g, ESCAPED_PIPE).split(OR_TOKEN).map((item) => {
274957
+ const query = tokenize3(item.replace(/\u0000/g, "|").trim()).filter((item2) => item2 && !!item2.trim());
275005
274958
  const results = [];
275006
274959
  for (let i2 = 0, len = query.length;i2 < len; i2 += 1) {
275007
274960
  const queryItem = query[i2];
275008
274961
  let found = false;
275009
274962
  let idx = -1;
275010
- while (!found && ++idx < searchersLen) {
275011
- const searcher = searchers[idx];
275012
- const token = searcher.isMultiMatch(queryItem);
274963
+ while (!found && ++idx < matchersLen) {
274964
+ const def = matchers[idx];
274965
+ const token = getMatch(queryItem, def.multiRegex);
275013
274966
  if (token) {
275014
- results.push(new searcher(token, options));
274967
+ results.push(def.create(token, options));
275015
274968
  found = true;
275016
274969
  }
275017
274970
  }
275018
- if (found) {
274971
+ if (found)
275019
274972
  continue;
275020
- }
275021
274973
  idx = -1;
275022
- while (++idx < searchersLen) {
275023
- const searcher = searchers[idx];
275024
- const token = searcher.isSingleMatch(queryItem);
274974
+ while (++idx < matchersLen) {
274975
+ const def = matchers[idx];
274976
+ const token = getMatch(queryItem, def.singleRegex);
275025
274977
  if (token) {
275026
- results.push(new searcher(token, options));
274978
+ results.push(def.create(token, options));
275027
274979
  break;
275028
274980
  }
275029
274981
  }
@@ -275031,20 +274983,8 @@ function parseQuery(pattern, options = {}) {
275031
274983
  return results;
275032
274984
  });
275033
274985
  }
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
- } = {}) {
274986
+ var ExtendedSearch = class {
274987
+ 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
274988
  this.query = null;
275049
274989
  this.options = {
275050
274990
  isCaseSensitive,
@@ -275067,17 +275007,12 @@ class ExtendedSearch {
275067
275007
  }
275068
275008
  searchIn(text) {
275069
275009
  const query = this.query;
275070
- if (!query) {
275010
+ if (!query)
275071
275011
  return {
275072
275012
  isMatch: false,
275073
275013
  score: 1
275074
275014
  };
275075
- }
275076
- const {
275077
- includeMatches,
275078
- isCaseSensitive,
275079
- ignoreDiacritics
275080
- } = this.options;
275015
+ const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
275081
275016
  text = isCaseSensitive ? text : text.toLowerCase();
275082
275017
  text = ignoreDiacritics ? stripDiacritics(text) : text;
275083
275018
  let numMatches = 0;
@@ -275085,31 +275020,23 @@ class ExtendedSearch {
275085
275020
  let totalScore = 0;
275086
275021
  let hasInverse = false;
275087
275022
  for (let i2 = 0, qLen = query.length;i2 < qLen; i2 += 1) {
275088
- const searchers2 = query[i2];
275023
+ const searchers = query[i2];
275089
275024
  allIndices.length = 0;
275090
275025
  numMatches = 0;
275091
275026
  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);
275027
+ for (let j4 = 0, pLen = searchers.length;j4 < pLen; j4 += 1) {
275028
+ const matcher = searchers[j4];
275029
+ const { isMatch, indices, score } = matcher.search(text);
275099
275030
  if (isMatch) {
275100
275031
  numMatches += 1;
275101
275032
  totalScore += score;
275102
- const type = searcher.constructor.type;
275103
- if (type.startsWith("inverse")) {
275033
+ if (isInverse(matcher.type))
275104
275034
  hasInverse = true;
275105
- }
275106
- if (includeMatches) {
275107
- if (MultiMatchSet.has(type)) {
275035
+ if (includeMatches)
275036
+ if (MULTI_MATCH_TYPES.has(matcher.type))
275108
275037
  allIndices.push(...indices);
275109
- } else {
275038
+ else
275110
275039
  allIndices.push(indices);
275111
- }
275112
- }
275113
275040
  } else {
275114
275041
  totalScore = 0;
275115
275042
  numMatches = 0;
@@ -275123,12 +275050,10 @@ class ExtendedSearch {
275123
275050
  isMatch: true,
275124
275051
  score: totalScore / numMatches
275125
275052
  };
275126
- if (hasInverse) {
275053
+ if (hasInverse)
275127
275054
  result.hasInverse = true;
275128
- }
275129
- if (includeMatches) {
275055
+ if (includeMatches)
275130
275056
  result.indices = mergeIndices(allIndices);
275131
- }
275132
275057
  return result;
275133
275058
  }
275134
275059
  }
@@ -275137,7 +275062,7 @@ class ExtendedSearch {
275137
275062
  score: 1
275138
275063
  };
275139
275064
  }
275140
- }
275065
+ };
275141
275066
  var registeredSearchers = [];
275142
275067
  function register2(...args) {
275143
275068
  registeredSearchers.push(...args);
@@ -275145,9 +275070,8 @@ function register2(...args) {
275145
275070
  function createSearcher(pattern, options) {
275146
275071
  for (let i2 = 0, len = registeredSearchers.length;i2 < len; i2 += 1) {
275147
275072
  const searcherClass = registeredSearchers[i2];
275148
- if (searcherClass.condition(pattern, options)) {
275073
+ if (searcherClass.condition(pattern, options))
275149
275074
  return new searcherClass(pattern, options);
275150
- }
275151
275075
  }
275152
275076
  return new BitapSearch(pattern, options);
275153
275077
  }
@@ -275162,43 +275086,33 @@ var KeyType = {
275162
275086
  var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
275163
275087
  var isPath = (query) => !!query[KeyType.PATH];
275164
275088
  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
- } = {}) {
275089
+ var convertToExplicit = (query) => ({ [LogicalOperator.AND]: Object.keys(query).map((key) => ({ [key]: query[key] })) });
275090
+ function parse3(query, options, { auto = true } = {}) {
275173
275091
  const next = (query2) => {
275174
275092
  if (isString2(query2)) {
275175
275093
  const obj = {
275176
275094
  keyId: null,
275177
275095
  pattern: query2
275178
275096
  };
275179
- if (auto) {
275097
+ if (auto)
275180
275098
  obj.searcher = createSearcher(query2, options);
275181
- }
275182
275099
  return obj;
275183
275100
  }
275184
275101
  const keys = Object.keys(query2);
275185
275102
  const isQueryPath = isPath(query2);
275186
- if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
275103
+ if (!isQueryPath && keys.length > 1 && !isExpression(query2))
275187
275104
  return next(convertToExplicit(query2));
275188
- }
275189
275105
  if (isLeaf(query2)) {
275190
275106
  const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
275191
275107
  const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
275192
- if (!isString2(pattern)) {
275108
+ if (!isString2(pattern))
275193
275109
  throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
275194
- }
275195
275110
  const obj = {
275196
275111
  keyId: createKeyId(key),
275197
275112
  pattern
275198
275113
  };
275199
- if (auto) {
275114
+ if (auto)
275200
275115
  obj.searcher = createSearcher(pattern, options);
275201
- }
275202
275116
  return obj;
275203
275117
  }
275204
275118
  const node = {
@@ -275207,44 +275121,31 @@ function parse3(query, options, {
275207
275121
  };
275208
275122
  keys.forEach((key) => {
275209
275123
  const value = query2[key];
275210
- if (isArray(value)) {
275124
+ if (isArray(value))
275211
275125
  value.forEach((item) => {
275212
275126
  node.children.push(next(item));
275213
275127
  });
275214
- }
275215
275128
  });
275216
275129
  return node;
275217
275130
  };
275218
- if (!isExpression(query)) {
275131
+ if (!isExpression(query))
275219
275132
  query = convertToExplicit(query);
275220
- }
275221
275133
  return next(query);
275222
275134
  }
275223
- function computeScoreSingle(matches, {
275224
- ignoreFieldNorm = Config.ignoreFieldNorm
275225
- }) {
275135
+ function computeScoreSingle(matches, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
275226
275136
  let totalScore = 1;
275227
- matches.forEach(({
275228
- key,
275229
- norm: norm2,
275230
- score
275231
- }) => {
275137
+ matches.forEach(({ key, norm: norm2, score }) => {
275232
275138
  const weight = key ? key.weight : null;
275233
275139
  totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm2));
275234
275140
  });
275235
275141
  return totalScore;
275236
275142
  }
275237
- function computeScore(results, {
275238
- ignoreFieldNorm = Config.ignoreFieldNorm
275239
- }) {
275143
+ function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
275240
275144
  results.forEach((result) => {
275241
- result.score = computeScoreSingle(result.matches, {
275242
- ignoreFieldNorm
275243
- });
275145
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
275244
275146
  });
275245
275147
  }
275246
-
275247
- class MaxHeap {
275148
+ var MaxHeap = class {
275248
275149
  constructor(limit) {
275249
275150
  this.limit = limit;
275250
275151
  this.heap = [];
@@ -275287,12 +275188,10 @@ class MaxHeap {
275287
275188
  i2 = largest;
275288
275189
  const left = 2 * i2 + 1;
275289
275190
  const right = 2 * i2 + 2;
275290
- if (left < len && heap[left].score > heap[largest].score) {
275191
+ if (left < len && heap[left].score > heap[largest].score)
275291
275192
  largest = left;
275292
- }
275293
- if (right < len && heap[right].score > heap[largest].score) {
275193
+ if (right < len && heap[right].score > heap[largest].score)
275294
275194
  largest = right;
275295
- }
275296
275195
  if (largest !== i2) {
275297
275196
  const tmp = heap[i2];
275298
275197
  heap[i2] = heap[largest];
@@ -275300,207 +275199,258 @@ class MaxHeap {
275300
275199
  }
275301
275200
  } while (largest !== i2);
275302
275201
  }
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) {
275202
+ };
275203
+ function formatMatches(result) {
275204
+ const matches = [];
275205
+ result.matches.forEach((match) => {
275206
+ if (!isDefined(match.indices) || !match.indices.length)
275312
275207
  return;
275313
- }
275314
- const {
275315
- indices,
275316
- value
275317
- } = match;
275318
275208
  const obj = {
275319
- indices,
275320
- value
275209
+ indices: match.indices,
275210
+ value: match.value
275321
275211
  };
275322
- if (match.key) {
275323
- obj.key = match.key.src;
275324
- }
275325
- if (match.idx > -1) {
275212
+ if (match.key)
275213
+ obj.key = match.key.id;
275214
+ if (match.idx > -1)
275326
275215
  obj.refIndex = match.idx;
275327
- }
275328
- data.matches.push(obj);
275216
+ matches.push(obj);
275329
275217
  });
275218
+ return matches;
275330
275219
  }
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);
275220
+ function format(results, docs, { includeMatches = Config.includeMatches, includeScore = Config.includeScore } = {}) {
275343
275221
  return results.map((result) => {
275344
- const {
275345
- idx
275346
- } = result;
275222
+ const { idx } = result;
275347
275223
  const data = {
275348
275224
  item: docs[idx],
275349
275225
  refIndex: idx
275350
275226
  };
275351
- if (transformers.length) {
275352
- transformers.forEach((transformer) => {
275353
- transformer(result, data);
275354
- });
275355
- }
275227
+ if (includeMatches)
275228
+ data.matches = formatMatches(result);
275229
+ if (includeScore)
275230
+ data.score = result.score;
275356
275231
  return data;
275357
275232
  });
275358
275233
  }
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
- };
275234
+ var DEFAULT_TOKEN = /[\p{L}\p{M}\p{N}_]+/gu;
275235
+ var warned = /* @__PURE__ */ new WeakSet;
275236
+ function warnNonGlobal(regex2) {
275237
+ if (!warned.has(regex2)) {
275238
+ warned.add(regex2);
275239
+ console.warn(`[Fuse] tokenize regex ${regex2} lacks the global flag; only the first match per text will be returned. Add the 'g' flag.`);
275240
+ }
275375
275241
  }
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);
275242
+ function resolveTokenize(tokenize4) {
275243
+ if (typeof tokenize4 === "function") {
275244
+ let validated = false;
275245
+ return (text) => {
275246
+ const result = tokenize4(text);
275247
+ if (!validated) {
275248
+ validated = true;
275249
+ if (!Array.isArray(result) || result.some((t17) => typeof t17 !== "string"))
275250
+ throw new Error(`[Fuse] tokenize function must return string[]; received ${Array.isArray(result) ? "array containing non-strings" : typeof result}.`);
275400
275251
  }
275401
- postings.push(posting);
275402
- df3.set(term, (df3.get(term) || 0) + 1);
275403
- }
275252
+ return result;
275253
+ };
275404
275254
  }
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
- }
275255
+ if (tokenize4 instanceof RegExp) {
275256
+ if (!tokenize4.global)
275257
+ warnNonGlobal(tokenize4);
275258
+ return (text) => text.match(tokenize4) || [];
275429
275259
  }
275430
- return {
275431
- terms,
275432
- fieldCount,
275433
- df: df3
275434
- };
275260
+ return (text) => text.match(DEFAULT_TOKEN) || [];
275435
275261
  }
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
275262
+ function createAnalyzer({ isCaseSensitive = false, ignoreDiacritics = false, tokenize: tokenize4 } = {}) {
275263
+ const tokenizeFn = resolveTokenize(tokenize4);
275264
+ return { tokenize(text) {
275265
+ if (!isCaseSensitive)
275266
+ text = text.toLowerCase();
275267
+ if (ignoreDiacritics)
275268
+ text = stripDiacritics(text);
275269
+ return tokenizeFn(text);
275270
+ } };
275271
+ }
275272
+ var TokenSearch = class {
275273
+ static condition(_4, options) {
275274
+ return options.useTokenSearch;
275275
+ }
275276
+ constructor(pattern, options) {
275277
+ this.options = options;
275278
+ this.analyzer = createAnalyzer({
275279
+ isCaseSensitive: options.isCaseSensitive,
275280
+ ignoreDiacritics: options.ignoreDiacritics,
275281
+ tokenize: options.tokenize
275282
+ });
275283
+ const queryTerms = this.analyzer.tokenize(pattern);
275284
+ const { df: df3, fieldCount } = options._invertedIndex;
275285
+ this.termSearchers = [];
275286
+ this.idfWeights = [];
275287
+ for (const term of queryTerms) {
275288
+ this.termSearchers.push(new BitapSearch(term, {
275289
+ location: options.location,
275290
+ threshold: options.threshold,
275291
+ distance: options.distance,
275292
+ includeMatches: options.includeMatches,
275293
+ findAllMatches: options.findAllMatches,
275294
+ minMatchCharLength: options.minMatchCharLength,
275295
+ isCaseSensitive: options.isCaseSensitive,
275296
+ ignoreDiacritics: options.ignoreDiacritics,
275297
+ ignoreLocation: true
275298
+ }));
275299
+ const docFreq = df3.get(term) || 0;
275300
+ const idf = Math.log(1 + (fieldCount - docFreq + 0.5) / (docFreq + 0.5));
275301
+ this.idfWeights.push(idf);
275302
+ }
275303
+ this.combineAll = options.tokenMatch === "all";
275304
+ this.numTerms = this.termSearchers.length;
275305
+ this.useMask = this.numTerms <= 31;
275306
+ }
275307
+ searchIn(text) {
275308
+ if (!this.termSearchers.length)
275309
+ return {
275310
+ isMatch: false,
275311
+ score: 1
275457
275312
  };
275458
- let postings = index.terms.get(term);
275459
- if (!postings) {
275460
- postings = [];
275461
- index.terms.set(term, postings);
275313
+ const allIndices = [];
275314
+ let weightedScore = 0;
275315
+ let maxPossibleScore = 0;
275316
+ let matchedCount = 0;
275317
+ let matchedMask = 0;
275318
+ const matchedTerms = this.combineAll && !this.useMask ? /* @__PURE__ */ new Set : null;
275319
+ for (let i2 = 0;i2 < this.termSearchers.length; i2++) {
275320
+ const result = this.termSearchers[i2].searchIn(text);
275321
+ const idf = this.idfWeights[i2];
275322
+ maxPossibleScore += idf;
275323
+ if (result.isMatch) {
275324
+ matchedCount++;
275325
+ weightedScore += idf * (1 - result.score);
275326
+ if (result.indices)
275327
+ allIndices.push(...result.indices);
275328
+ if (this.combineAll)
275329
+ if (this.useMask)
275330
+ matchedMask |= 1 << i2;
275331
+ else
275332
+ matchedTerms.add(i2);
275462
275333
  }
275463
- postings.push(posting);
275464
- index.df.set(term, (index.df.get(term) || 0) + 1);
275465
275334
  }
275335
+ if (matchedCount === 0)
275336
+ return {
275337
+ isMatch: false,
275338
+ score: 1
275339
+ };
275340
+ const normalized = maxPossibleScore > 0 ? 1 - weightedScore / maxPossibleScore : 0;
275341
+ const searchResult = {
275342
+ isMatch: true,
275343
+ score: Math.max(0.001, normalized)
275344
+ };
275345
+ if (this.options.includeMatches && allIndices.length)
275346
+ searchResult.indices = mergeIndices(allIndices);
275347
+ if (this.combineAll) {
275348
+ if (this.useMask)
275349
+ searchResult.matchedMask = matchedMask;
275350
+ else
275351
+ searchResult.matchedTerms = matchedTerms;
275352
+ searchResult.termCount = this.numTerms;
275353
+ }
275354
+ return searchResult;
275355
+ }
275356
+ };
275357
+ function addField(index, text, docIdx, analyzer) {
275358
+ const tokens = analyzer.tokenize(text);
275359
+ if (!tokens.length)
275360
+ return;
275361
+ index.fieldCount++;
275362
+ index.docFieldCount.set(docIdx, (index.docFieldCount.get(docIdx) || 0) + 1);
275363
+ const distinctTerms = new Set(tokens);
275364
+ let perDocTerms = index.docTermFieldHits.get(docIdx);
275365
+ if (!perDocTerms) {
275366
+ perDocTerms = /* @__PURE__ */ new Map;
275367
+ index.docTermFieldHits.set(docIdx, perDocTerms);
275466
275368
  }
275369
+ for (const term of distinctTerms) {
275370
+ perDocTerms.set(term, (perDocTerms.get(term) || 0) + 1);
275371
+ index.df.set(term, (index.df.get(term) || 0) + 1);
275372
+ }
275373
+ }
275374
+ function ingestRecord(index, record, keyCount, analyzer) {
275375
+ const { i: docIdx, v: v3, $: fields } = record;
275467
275376
  if (v3 !== undefined) {
275468
- addField(v3, -1, -1);
275377
+ addField(index, v3, docIdx, analyzer);
275469
275378
  return;
275470
275379
  }
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
- }
275380
+ if (!fields)
275381
+ return;
275382
+ for (let keyIdx = 0;keyIdx < keyCount; keyIdx++) {
275383
+ const value = fields[keyIdx];
275384
+ if (!value)
275385
+ continue;
275386
+ if (Array.isArray(value))
275387
+ for (const sub of value)
275388
+ addField(index, sub.v, docIdx, analyzer);
275389
+ else
275390
+ addField(index, value.v, docIdx, analyzer);
275484
275391
  }
275485
275392
  }
275393
+ function buildInvertedIndex(records, keyCount, analyzer) {
275394
+ const index = {
275395
+ fieldCount: 0,
275396
+ df: /* @__PURE__ */ new Map,
275397
+ docFieldCount: /* @__PURE__ */ new Map,
275398
+ docTermFieldHits: /* @__PURE__ */ new Map
275399
+ };
275400
+ for (const record of records)
275401
+ ingestRecord(index, record, keyCount, analyzer);
275402
+ return index;
275403
+ }
275404
+ function addToInvertedIndex(index, record, keyCount, analyzer) {
275405
+ ingestRecord(index, record, keyCount, analyzer);
275406
+ }
275486
275407
  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
- }
275408
+ const fieldCount = index.docFieldCount.get(docIdx);
275409
+ if (fieldCount === undefined)
275410
+ return;
275411
+ index.fieldCount -= fieldCount;
275412
+ index.docFieldCount.delete(docIdx);
275413
+ const perDocTerms = index.docTermFieldHits.get(docIdx);
275414
+ if (!perDocTerms)
275415
+ return;
275416
+ for (const [term, hits] of perDocTerms) {
275417
+ const next = (index.df.get(term) || 0) - hits;
275418
+ if (next <= 0)
275419
+ index.df.delete(term);
275420
+ else
275421
+ index.df.set(term, next);
275500
275422
  }
275423
+ index.docTermFieldHits.delete(docIdx);
275501
275424
  }
275502
-
275503
- class Fuse2 {
275425
+ function removeAndShiftInvertedIndex(index, removedIndices) {
275426
+ if (removedIndices.length === 0)
275427
+ return;
275428
+ const sorted = Array.from(new Set(removedIndices)).sort((a2, b) => a2 - b);
275429
+ for (const idx of sorted)
275430
+ removeFromInvertedIndex(index, idx);
275431
+ const shift = (oldIdx) => {
275432
+ let lo3 = 0;
275433
+ let hi3 = sorted.length;
275434
+ while (lo3 < hi3) {
275435
+ const mid = lo3 + hi3 >>> 1;
275436
+ if (sorted[mid] < oldIdx)
275437
+ lo3 = mid + 1;
275438
+ else
275439
+ hi3 = mid;
275440
+ }
275441
+ return oldIdx - lo3;
275442
+ };
275443
+ const firstRemoved = sorted[0];
275444
+ const shiftedDocFieldCount = /* @__PURE__ */ new Map;
275445
+ for (const [oldKey, count] of index.docFieldCount)
275446
+ shiftedDocFieldCount.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, count);
275447
+ index.docFieldCount = shiftedDocFieldCount;
275448
+ const shiftedDocTermFieldHits = /* @__PURE__ */ new Map;
275449
+ for (const [oldKey, terms] of index.docTermFieldHits)
275450
+ shiftedDocTermFieldHits.set(oldKey > firstRemoved ? shift(oldKey) : oldKey, terms);
275451
+ index.docTermFieldHits = shiftedDocTermFieldHits;
275452
+ }
275453
+ var Fuse2 = class {
275504
275454
  constructor(docs, options, index) {
275505
275455
  this.options = {
275506
275456
  ...Config,
@@ -275519,23 +275469,20 @@ class Fuse2 {
275519
275469
  this._lastSearcher = null;
275520
275470
  }
275521
275471
  _getSearcher(query) {
275522
- if (this._lastQuery === query) {
275472
+ if (this._lastQuery === query)
275523
275473
  return this._lastSearcher;
275524
- }
275525
- const opts = this._invertedIndex ? {
275474
+ const searcher = createSearcher(query, this._invertedIndex ? {
275526
275475
  ...this.options,
275527
275476
  _invertedIndex: this._invertedIndex
275528
- } : this.options;
275529
- const searcher = createSearcher(query, opts);
275477
+ } : this.options);
275530
275478
  this._lastQuery = query;
275531
275479
  this._lastSearcher = searcher;
275532
275480
  return searcher;
275533
275481
  }
275534
275482
  setCollection(docs, index) {
275535
275483
  this._docs = docs;
275536
- if (index && !(index instanceof FuseIndex)) {
275484
+ if (index && !(index instanceof FuseIndex))
275537
275485
  throw new Error(INCORRECT_INDEX_TYPE);
275538
- }
275539
275486
  this._myIndex = index || createIndex(this.options.keys, this._docs, {
275540
275487
  getFn: this.options.getFn,
275541
275488
  fieldNormWeight: this.options.fieldNormWeight
@@ -275543,155 +275490,137 @@ class Fuse2 {
275543
275490
  if (this.options.useTokenSearch) {
275544
275491
  const analyzer = createAnalyzer({
275545
275492
  isCaseSensitive: this.options.isCaseSensitive,
275546
- ignoreDiacritics: this.options.ignoreDiacritics
275493
+ ignoreDiacritics: this.options.ignoreDiacritics,
275494
+ tokenize: this.options.tokenize
275547
275495
  });
275548
275496
  this._invertedIndex = buildInvertedIndex(this._myIndex.records, this._myIndex.keys.length, analyzer);
275549
275497
  }
275498
+ this._invalidateSearcherCache();
275550
275499
  }
275551
275500
  add(doc) {
275552
- if (!isDefined(doc)) {
275501
+ if (!isDefined(doc))
275553
275502
  return;
275554
- }
275555
275503
  this._docs.push(doc);
275556
- this._myIndex.add(doc);
275557
- if (this._invertedIndex) {
275558
- const record = this._myIndex.records[this._myIndex.records.length - 1];
275504
+ const record = this._myIndex.add(doc, this._docs.length - 1);
275505
+ if (this._invertedIndex && record) {
275559
275506
  const analyzer = createAnalyzer({
275560
275507
  isCaseSensitive: this.options.isCaseSensitive,
275561
- ignoreDiacritics: this.options.ignoreDiacritics
275508
+ ignoreDiacritics: this.options.ignoreDiacritics,
275509
+ tokenize: this.options.tokenize
275562
275510
  });
275563
275511
  addToInvertedIndex(this._invertedIndex, record, this._myIndex.keys.length, analyzer);
275564
275512
  }
275513
+ this._invalidateSearcherCache();
275565
275514
  }
275566
275515
  remove(predicate = () => false) {
275567
275516
  const results = [];
275568
275517
  const indicesToRemove = [];
275569
- for (let i2 = 0, len = this._docs.length;i2 < len; i2 += 1) {
275518
+ for (let i2 = 0, len = this._docs.length;i2 < len; i2 += 1)
275570
275519
  if (predicate(this._docs[i2], i2)) {
275571
275520
  results.push(this._docs[i2]);
275572
275521
  indicesToRemove.push(i2);
275573
275522
  }
275574
- }
275575
275523
  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
- }
275524
+ if (this._invertedIndex)
275525
+ removeAndShiftInvertedIndex(this._invertedIndex, indicesToRemove);
275526
+ const toRemove = new Set(indicesToRemove);
275527
+ this._docs = this._docs.filter((_4, i2) => !toRemove.has(i2));
275584
275528
  this._myIndex.removeAll(indicesToRemove);
275529
+ this._invalidateSearcherCache();
275585
275530
  }
275586
275531
  return results;
275587
275532
  }
275588
275533
  removeAt(idx) {
275589
- if (this._invertedIndex) {
275590
- removeFromInvertedIndex(this._invertedIndex, idx);
275591
- }
275534
+ if (!Number.isInteger(idx) || idx < 0 || idx >= this._docs.length)
275535
+ throw new Error(INVALID_DOC_INDEX);
275536
+ if (this._invertedIndex)
275537
+ removeAndShiftInvertedIndex(this._invertedIndex, [idx]);
275592
275538
  const doc = this._docs.splice(idx, 1)[0];
275593
275539
  this._myIndex.removeAt(idx);
275540
+ this._invalidateSearcherCache();
275594
275541
  return doc;
275595
275542
  }
275543
+ _invalidateSearcherCache() {
275544
+ this._lastQuery = null;
275545
+ this._lastSearcher = null;
275546
+ }
275596
275547
  getIndex() {
275597
275548
  return this._myIndex;
275598
275549
  }
275599
275550
  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;
275551
+ const { limit = -1 } = options || {};
275552
+ const { includeMatches, includeScore, shouldSort, sortFn, ignoreFieldNorm } = this.options;
275610
275553
  if (isString2(query) && !query.trim()) {
275611
275554
  let docs = this._docs.map((item, idx) => ({
275612
275555
  item,
275613
275556
  refIndex: idx
275614
275557
  }));
275615
- if (isNumber2(limit) && limit > -1) {
275558
+ if (isNumber2(limit) && limit > -1)
275616
275559
  docs = docs.slice(0, limit);
275617
- }
275618
275560
  return docs;
275619
275561
  }
275620
275562
  const useHeap = isNumber2(limit) && limit > 0 && isString2(query);
275621
275563
  let results;
275622
275564
  if (useHeap) {
275623
275565
  const heap = new MaxHeap(limit);
275624
- if (isString2(this._docs[0])) {
275566
+ if (isString2(this._docs[0]))
275625
275567
  this._searchStringList(query, {
275626
275568
  heap,
275627
275569
  ignoreFieldNorm
275628
275570
  });
275629
- } else {
275571
+ else
275630
275572
  this._searchObjectList(query, {
275631
275573
  heap,
275632
275574
  ignoreFieldNorm
275633
275575
  });
275634
- }
275635
275576
  results = heap.extractSorted(sortFn);
275636
275577
  } else {
275637
275578
  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) {
275579
+ computeScore(results, { ignoreFieldNorm });
275580
+ if (shouldSort)
275642
275581
  results.sort(sortFn);
275643
- }
275644
- if (isNumber2(limit) && limit > -1) {
275582
+ if (isNumber2(limit) && limit > -1)
275645
275583
  results = results.slice(0, limit);
275646
- }
275647
275584
  }
275648
275585
  return format(results, this._docs, {
275649
275586
  includeMatches,
275650
275587
  includeScore
275651
275588
  });
275652
275589
  }
275653
- _searchStringList(query, {
275654
- heap,
275655
- ignoreFieldNorm
275656
- } = {}) {
275590
+ _searchStringList(query, { heap, ignoreFieldNorm } = {}) {
275657
275591
  const searcher = this._getSearcher(query);
275658
- const {
275659
- records
275660
- } = this._myIndex;
275592
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
275593
+ const { records } = this._myIndex;
275661
275594
  const results = heap ? null : [];
275662
- records.forEach(({
275663
- v: text,
275664
- i: idx,
275665
- n: norm2
275666
- }) => {
275667
- if (!isDefined(text)) {
275595
+ records.forEach(({ v: text, i: idx, n: norm2 }) => {
275596
+ if (!isDefined(text))
275668
275597
  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
- }]
275598
+ const searchResult = searcher.searchIn(text);
275599
+ if (searchResult.isMatch) {
275600
+ const match = {
275601
+ score: searchResult.score,
275602
+ value: text,
275603
+ norm: norm2,
275604
+ indices: searchResult.indices
275685
275605
  };
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);
275606
+ if (requireAllTokens) {
275607
+ match.matchedMask = searchResult.matchedMask;
275608
+ match.matchedTerms = searchResult.matchedTerms;
275609
+ match.termCount = searchResult.termCount;
275610
+ }
275611
+ const matches = [match];
275612
+ if (!requireAllTokens || this._coversAllTokens(matches)) {
275613
+ const result = {
275614
+ item: text,
275615
+ idx,
275616
+ matches
275617
+ };
275618
+ if (heap) {
275619
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
275620
+ if (heap.shouldInsert(result.score))
275621
+ heap.insert(result);
275622
+ } else
275623
+ results.push(result);
275695
275624
  }
275696
275625
  }
275697
275626
  });
@@ -275701,10 +275630,7 @@ class Fuse2 {
275701
275630
  const expression = parse3(query, this.options);
275702
275631
  const evaluate = (node, item, idx) => {
275703
275632
  if (!("children" in node)) {
275704
- const {
275705
- keyId,
275706
- searcher
275707
- } = node;
275633
+ const { keyId, searcher } = node;
275708
275634
  let matches;
275709
275635
  if (keyId === null) {
275710
275636
  matches = [];
@@ -275715,45 +275641,36 @@ class Fuse2 {
275715
275641
  searcher
275716
275642
  }));
275717
275643
  });
275718
- } else {
275644
+ } else
275719
275645
  matches = this._findMatches({
275720
275646
  key: this._keyStore.get(keyId),
275721
275647
  value: this._myIndex.getValueForItemAtKeyId(item, keyId),
275722
275648
  searcher
275723
275649
  });
275724
- }
275725
- if (matches && matches.length) {
275650
+ if (matches && matches.length)
275726
275651
  return [{
275727
275652
  idx,
275728
275653
  item,
275729
275654
  matches
275730
275655
  }];
275731
- }
275732
275656
  return [];
275733
275657
  }
275734
- const {
275735
- children,
275736
- operator
275737
- } = node;
275658
+ const { children, operator } = node;
275738
275659
  const res2 = [];
275739
275660
  for (let i2 = 0, len = children.length;i2 < len; i2 += 1) {
275740
275661
  const child = children[i2];
275741
275662
  const result = evaluate(child, item, idx);
275742
- if (result.length) {
275663
+ if (result.length)
275743
275664
  res2.push(...result);
275744
- } else if (operator === LogicalOperator.AND) {
275665
+ else if (operator === LogicalOperator.AND)
275745
275666
  return [];
275746
- }
275747
275667
  }
275748
275668
  return res2;
275749
275669
  };
275750
275670
  const records = this._myIndex.records;
275751
- const resultMap = new Map;
275671
+ const resultMap = /* @__PURE__ */ new Map;
275752
275672
  const results = [];
275753
- records.forEach(({
275754
- $: item,
275755
- i: idx
275756
- }) => {
275673
+ records.forEach(({ $: item, i: idx }) => {
275757
275674
  if (isDefined(item)) {
275758
275675
  const expResults = evaluate(expression, item, idx);
275759
275676
  if (expResults.length) {
@@ -275765,9 +275682,7 @@ class Fuse2 {
275765
275682
  });
275766
275683
  results.push(resultMap.get(idx));
275767
275684
  }
275768
- expResults.forEach(({
275769
- matches
275770
- }) => {
275685
+ expResults.forEach(({ matches }) => {
275771
275686
  resultMap.get(idx).matches.push(...matches);
275772
275687
  });
275773
275688
  }
@@ -275775,23 +275690,14 @@ class Fuse2 {
275775
275690
  });
275776
275691
  return results;
275777
275692
  }
275778
- _searchObjectList(query, {
275779
- heap,
275780
- ignoreFieldNorm
275781
- } = {}) {
275693
+ _searchObjectList(query, { heap, ignoreFieldNorm } = {}) {
275782
275694
  const searcher = this._getSearcher(query);
275783
- const {
275784
- keys,
275785
- records
275786
- } = this._myIndex;
275695
+ const requireAllTokens = this.options.useTokenSearch && this.options.tokenMatch === "all";
275696
+ const { keys, records } = this._myIndex;
275787
275697
  const results = heap ? null : [];
275788
- records.forEach(({
275789
- $: item,
275790
- i: idx
275791
- }) => {
275792
- if (!isDefined(item)) {
275698
+ records.forEach(({ $: item, i: idx }) => {
275699
+ if (!isDefined(item))
275793
275700
  return;
275794
- }
275795
275701
  const matches = [];
275796
275702
  let anyKeyFailed = false;
275797
275703
  let hasInverse = false;
@@ -275803,196 +275709,117 @@ class Fuse2 {
275803
275709
  });
275804
275710
  if (keyMatches.length) {
275805
275711
  matches.push(...keyMatches);
275806
- if (keyMatches[0].hasInverse) {
275712
+ if (keyMatches[0].hasInverse)
275807
275713
  hasInverse = true;
275808
- }
275809
- } else {
275714
+ } else
275810
275715
  anyKeyFailed = true;
275811
- }
275812
275716
  });
275813
- if (hasInverse && anyKeyFailed) {
275717
+ if (hasInverse && anyKeyFailed)
275814
275718
  return;
275815
- }
275816
- if (matches.length) {
275719
+ if (matches.length && (!requireAllTokens || this._coversAllTokens(matches))) {
275817
275720
  const result = {
275818
275721
  idx,
275819
275722
  item,
275820
275723
  matches
275821
275724
  };
275822
275725
  if (heap) {
275823
- result.score = computeScoreSingle(result.matches, {
275824
- ignoreFieldNorm
275825
- });
275826
- if (heap.shouldInsert(result.score)) {
275726
+ result.score = computeScoreSingle(result.matches, { ignoreFieldNorm });
275727
+ if (heap.shouldInsert(result.score))
275827
275728
  heap.insert(result);
275828
- }
275829
- } else {
275729
+ } else
275830
275730
  results.push(result);
275831
- }
275832
275731
  }
275833
275732
  });
275834
275733
  return results;
275835
275734
  }
275836
- _findMatches({
275837
- key,
275838
- value,
275839
- searcher
275840
- }) {
275841
- if (!isDefined(value)) {
275735
+ _findMatches({ key, value, searcher }) {
275736
+ if (!isDefined(value))
275842
275737
  return [];
275843
- }
275844
275738
  const matches = [];
275845
- if (isArray(value)) {
275846
- value.forEach(({
275847
- v: text,
275848
- i: idx,
275849
- n: norm2
275850
- }) => {
275851
- if (!isDefined(text)) {
275739
+ if (isArray(value))
275740
+ value.forEach(({ v: text, i: idx, n: norm2 }) => {
275741
+ if (!isDefined(text))
275852
275742
  return;
275853
- }
275854
- const {
275855
- isMatch,
275856
- score,
275857
- indices,
275858
- hasInverse
275859
- } = searcher.searchIn(text);
275860
- if (isMatch) {
275861
- matches.push({
275862
- score,
275743
+ const searchResult = searcher.searchIn(text);
275744
+ if (searchResult.isMatch) {
275745
+ const match = {
275746
+ score: searchResult.score,
275863
275747
  key,
275864
275748
  value: text,
275865
275749
  idx,
275866
275750
  norm: norm2,
275867
- indices,
275868
- hasInverse
275869
- });
275751
+ indices: searchResult.indices,
275752
+ hasInverse: searchResult.hasInverse
275753
+ };
275754
+ if (searchResult.termCount !== undefined) {
275755
+ match.matchedMask = searchResult.matchedMask;
275756
+ match.matchedTerms = searchResult.matchedTerms;
275757
+ match.termCount = searchResult.termCount;
275758
+ }
275759
+ matches.push(match);
275870
275760
  }
275871
275761
  });
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,
275762
+ else {
275763
+ const { v: text, n: norm2 } = value;
275764
+ const searchResult = searcher.searchIn(text);
275765
+ if (searchResult.isMatch) {
275766
+ const match = {
275767
+ score: searchResult.score,
275886
275768
  key,
275887
275769
  value: text,
275888
275770
  norm: norm2,
275889
- indices,
275890
- hasInverse
275891
- });
275771
+ indices: searchResult.indices,
275772
+ hasInverse: searchResult.hasInverse
275773
+ };
275774
+ if (searchResult.termCount !== undefined) {
275775
+ match.matchedMask = searchResult.matchedMask;
275776
+ match.matchedTerms = searchResult.matchedTerms;
275777
+ match.termCount = searchResult.termCount;
275778
+ }
275779
+ matches.push(match);
275892
275780
  }
275893
275781
  }
275894
275782
  return matches;
275895
275783
  }
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
- };
275784
+ _coversAllTokens(matches) {
275785
+ const termCount = matches.length ? matches[0].termCount : undefined;
275786
+ if (termCount === undefined)
275787
+ return true;
275788
+ if (termCount <= 31) {
275789
+ let coverage2 = 0;
275790
+ for (let i2 = 0;i2 < matches.length; i2++)
275791
+ coverage2 |= matches[i2].matchedMask || 0;
275792
+ return coverage2 === 2 ** termCount - 1;
275961
275793
  }
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);
275794
+ const coverage = /* @__PURE__ */ new Set;
275795
+ for (let i2 = 0;i2 < matches.length; i2++) {
275796
+ const terms = matches[i2].matchedTerms;
275797
+ if (terms)
275798
+ for (const t17 of terms)
275799
+ coverage.add(t17);
275969
275800
  }
275970
- return searchResult;
275801
+ return coverage.size === termCount;
275971
275802
  }
275972
- }
275973
- Fuse2.version = "7.3.0";
275803
+ };
275804
+ Fuse2.version = "7.4.2";
275974
275805
  Fuse2.createIndex = createIndex;
275975
275806
  Fuse2.parseIndex = parseIndex;
275976
275807
  Fuse2.config = Config;
275977
275808
  Fuse2.match = function(pattern, text, options) {
275978
- const searcher = createSearcher(pattern, {
275809
+ if (options && options.useTokenSearch)
275810
+ throw new Error(FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED);
275811
+ return createSearcher(pattern, {
275979
275812
  ...Config,
275980
275813
  ...options
275981
- });
275982
- return searcher.searchIn(text);
275814
+ }).searchIn(text);
275983
275815
  };
275984
- {
275985
- Fuse2.parseQuery = parse3;
275986
- }
275987
- {
275988
- register2(ExtendedSearch);
275989
- }
275990
- {
275991
- register2(TokenSearch);
275992
- }
275816
+ Fuse2.parseQuery = parse3;
275817
+ register2(ExtendedSearch);
275818
+ register2(TokenSearch);
275993
275819
  Fuse2.use = function(...plugins) {
275994
275820
  plugins.forEach((plugin) => register2(plugin));
275995
275821
  };
275822
+ var entry_default = Fuse2;
275996
275823
 
275997
275824
  // cli/search/register.ts
275998
275825
  var registerSearch = (program3) => {
@@ -276019,7 +275846,7 @@ var registerSearch = (program3) => {
276019
275846
  }
276020
275847
  if (searchKicad) {
276021
275848
  const kicadFiles = await fetch("https://kicad-mod-cache.tscircuit.com/kicad_files.json").then((r4) => r4.json());
276022
- const fuse = new Fuse2(kicadFiles);
275849
+ const fuse = new entry_default(kicadFiles);
276023
275850
  kicadResults = fuse.search(query).slice(0, 10).map((r4) => r4.item);
276024
275851
  }
276025
275852
  } catch (error) {
@@ -279312,8 +279139,7 @@ var processSnapshotFile = async ({
279312
279139
  };
279313
279140
 
279314
279141
  // lib/shared/snapshot-project.ts
279315
- var hasConfiguredIncludeBoardFiles = (projectDir) => {
279316
- const projectConfig2 = loadProjectConfig(projectDir);
279142
+ var hasConfiguredIncludeBoardFiles = (projectConfig2) => {
279317
279143
  const hasConfiguredPatterns = Boolean(projectConfig2?.includeBoardFiles?.some((pattern) => pattern.trim()));
279318
279144
  return hasConfiguredPatterns;
279319
279145
  };
@@ -279338,7 +279164,7 @@ var snapshotProject = async ({
279338
279164
  threeD = true;
279339
279165
  }
279340
279166
  const projectDir = process.cwd();
279341
- const projectConfig2 = loadProjectConfig(projectDir);
279167
+ const projectConfig2 = await loadRuntimeProjectConfig(projectDir);
279342
279168
  const ignore = [
279343
279169
  ...DEFAULT_IGNORED_PATTERNS,
279344
279170
  ...ignored.map(normalizeIgnorePattern)
@@ -279350,7 +279176,7 @@ var snapshotProject = async ({
279350
279176
  }
279351
279177
  return fs66.statSync(resolvedPath).isDirectory();
279352
279178
  });
279353
- const boardFiles = findBoardFiles({
279179
+ const boardFiles = await findBoardFilesAsync({
279354
279180
  projectDir,
279355
279181
  ignore,
279356
279182
  filePaths: resolvedPaths
@@ -279358,8 +279184,9 @@ var snapshotProject = async ({
279358
279184
  if (boardFiles.length === 0) {
279359
279185
  if (explicitDirectoryTarget) {
279360
279186
  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";
279187
+ const runtimeIncludeBoardFilePatterns = projectConfig2?.includeBoardFiles?.filter((pattern) => pattern.trim()) ?? [];
279188
+ const includeBoardFilePatterns = runtimeIncludeBoardFilePatterns.length > 0 ? runtimeIncludeBoardFilePatterns : getBoardFilePatterns(projectDir);
279189
+ const patternSourceMessage = hasConfiguredIncludeBoardFiles(projectConfig2) ? "Searched using tscircuit.config.json includeBoardFiles" : "Searched using default includeBoardFiles";
279363
279190
  onError([
279364
279191
  `No circuit files found to create snapshots in directory: "${relativeDirectory}"`,
279365
279192
  `${patternSourceMessage}: ${JSON.stringify(includeBoardFilePatterns)}`
@@ -279370,8 +279197,9 @@ var snapshotProject = async ({
279370
279197
  console.log("No entrypoint found. Run 'tsci init' to bootstrap a project or specify a file with 'tsci snapshot <file>'");
279371
279198
  return onExit2(0);
279372
279199
  }
279373
- const snapshotsDirName = getSnapshotsDir(projectDir);
279200
+ const snapshotsDirName = projectConfig2?.snapshotsDir ?? getSnapshotsDir(projectDir);
279374
279201
  const pcbSnapshotSettings = pcbSnapshotSettingsOverride ? { ...projectConfig2?.pcbSnapshotSettings, ...pcbSnapshotSettingsOverride } : projectConfig2?.pcbSnapshotSettings;
279202
+ const mergedPlatformConfig = mergePlatformConfigs(projectConfig2?.platformConfig, platformConfig2);
279375
279203
  const mismatches = [];
279376
279204
  let didUpdate = false;
279377
279205
  const concurrencyValue = Math.max(1, concurrency);
@@ -279439,7 +279267,7 @@ var snapshotProject = async ({
279439
279267
  pcbOnly,
279440
279268
  schematicOnly,
279441
279269
  forceUpdate,
279442
- platformConfig: platformConfig2,
279270
+ platformConfig: mergedPlatformConfig,
279443
279271
  pcbSnapshotSettings,
279444
279272
  createDiff: createDiff2,
279445
279273
  cameraPreset