@labdigital/commercetools-mock 2.30.1 → 2.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2401,7 +2401,7 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
2401
2401
  resource.itemShippingAddresses.push(newAddress);
2402
2402
  }
2403
2403
  }
2404
- addLineItem(context, resource, { productId, variantId, sku, quantity = 1 }) {
2404
+ addLineItem(context, resource, { productId, variantId, sku, custom, quantity = 1 }) {
2405
2405
  let product = null;
2406
2406
  if (productId && variantId) {
2407
2407
  product = this._storage.get(context.projectKey, "product", productId, {});
@@ -2485,7 +2485,8 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
2485
2485
  discountedPricePerQuantity: [],
2486
2486
  lineItemMode: "Standard",
2487
2487
  priceMode: "Platform",
2488
- state: []
2488
+ state: [],
2489
+ custom: createCustomFields(custom, context.projectKey, this._storage)
2489
2490
  });
2490
2491
  }
2491
2492
  resource.totalPrice.centAmount = calculateCartTotalPrice(resource);
@@ -4507,19 +4508,346 @@ var PaymentRepository = class extends AbstractResourceRepository {
4507
4508
  }
4508
4509
  };
4509
4510
 
4510
- // src/lib/searchQueryTypeChecker.ts
4511
- var validateSearchQuery = (query) => {
4512
- if (isSearchAndExpression(query)) {
4513
- query.and.forEach((expr) => validateSearchQuery(expr));
4514
- } else if (isSearchOrExpression(query)) {
4515
- query.or.forEach((expr) => validateSearchQuery(expr));
4516
- } else if (isSearchNotExpression(query)) {
4517
- validateSearchQuery(query.not);
4518
- } else if (isSearchFilterExpression(query) || isSearchRangeExpression(query) || isSearchExactExpression(query) || isSearchExistsExpression(query) || isSearchFullTextExpression(query) || isSearchFullTextPrefixExpression(query) || isSearchPrefixExpression(query) || isSearchWildCardExpression(query) || isSearchAnyValue(query)) {
4519
- return;
4520
- } else {
4521
- throw new Error("Unsupported search query expression");
4511
+ // src/lib/projectionSearchFilter.ts
4512
+ var parseFilterExpression = (filter) => {
4513
+ const exprFunc = generateMatchFunc2(filter);
4514
+ const [source] = filter.split(":", 1);
4515
+ if (source.startsWith("variants.")) {
4516
+ return filterVariants(source, exprFunc);
4517
+ }
4518
+ return filterProduct(source, exprFunc);
4519
+ };
4520
+ var getLexer2 = (value) => new Lexer(value).token("MISSING", /missing(?![-_a-z0-9]+)/i).token("EXISTS", /exists(?![-_a-z0-9]+)/i).token("RANGE", /range(?![-_a-z0-9]+)/i).token("TO", /to(?![-_a-z0-9]+)/i).token("IDENTIFIER", /[-_.a-z]+/i).token("FLOAT", /\d+\.\d+/).token("INT", /\d+/).token("STRING", /"((?:\\.|[^"\\])*)"/).token("STRING", /'((?:\\.|[^'\\])*)'/).token("COMMA", ",").token("STAR", "*").token("(", "(").token(":", ":").token(")", ")").token('"', '"').token("WS", /\s+/, true);
4521
+ var parseFilter = (filter) => {
4522
+ const lexer = getLexer2(filter);
4523
+ const parser = new Parser(lexer).builder().nud("IDENTIFIER", 100, (t) => t.token.match).led(":", 100, ({ left, bp }) => {
4524
+ const parsed = parser.parse({ terminals: [bp - 1] });
4525
+ const expressions = !Array.isArray(parsed) ? [parsed] : parsed;
4526
+ const unique = new Set(expressions.map((expr) => expr.type));
4527
+ if (unique.size > 1) {
4528
+ throw new Error("Invalid expression");
4529
+ }
4530
+ if (expressions.some((expr) => expr.type == "Symbol")) {
4531
+ return {
4532
+ source: left,
4533
+ type: "FilterExpression",
4534
+ children: expressions.map((e) => {
4535
+ if (e.type != "Symbol") {
4536
+ throw new Error("Invalid expression");
4537
+ }
4538
+ return {
4539
+ type: "FilterExpression",
4540
+ match: (obj) => obj === e.value
4541
+ };
4542
+ })
4543
+ };
4544
+ }
4545
+ return {
4546
+ source: left,
4547
+ type: expressions[0].type,
4548
+ children: expressions
4549
+ };
4550
+ }).nud(
4551
+ "STRING",
4552
+ 20,
4553
+ (t) => ({
4554
+ type: "Symbol",
4555
+ kind: "string",
4556
+ // @ts-ignore
4557
+ value: t.token.groups[1]
4558
+ })
4559
+ ).nud(
4560
+ "INT",
4561
+ 5,
4562
+ (t) => ({
4563
+ type: "Symbol",
4564
+ kind: "int",
4565
+ value: parseInt(t.token.match, 10)
4566
+ })
4567
+ ).nud("STAR", 5, (_) => ({
4568
+ type: "Symbol",
4569
+ kind: "any",
4570
+ value: null
4571
+ })).nud(
4572
+ "EXISTS",
4573
+ 10,
4574
+ ({ bp }) => ({
4575
+ type: "FilterExpression",
4576
+ match: (obj) => obj !== void 0
4577
+ })
4578
+ ).nud(
4579
+ "MISSING",
4580
+ 10,
4581
+ ({ bp }) => ({
4582
+ type: "FilterExpression",
4583
+ match: (obj) => obj === void 0
4584
+ })
4585
+ ).led("COMMA", 200, ({ left, token, bp }) => {
4586
+ const expr = parser.parse({ terminals: [bp - 1] });
4587
+ if (Array.isArray(expr)) {
4588
+ return [left, ...expr];
4589
+ } else {
4590
+ return [left, expr];
4591
+ }
4592
+ }).nud("(", 100, (t) => {
4593
+ const expr = parser.parse({ terminals: [")"] });
4594
+ lexer.expect(")");
4595
+ return expr;
4596
+ }).bp(")", 0).led("TO", 20, ({ left, bp }) => {
4597
+ const expr = parser.parse({ terminals: [bp - 1] });
4598
+ return {
4599
+ start: left.value,
4600
+ stop: expr.value
4601
+ };
4602
+ }).nud("RANGE", 20, ({ bp }) => {
4603
+ let ranges = parser.parse();
4604
+ if (!Array.isArray(ranges)) {
4605
+ ranges = [ranges];
4606
+ }
4607
+ return ranges.map((range) => {
4608
+ let func;
4609
+ if (range.start !== null && range.stop !== null) {
4610
+ func = (obj) => obj >= range.start && obj <= range.stop;
4611
+ } else if (range.start === null && range.stop !== null) {
4612
+ func = (obj) => obj <= range.stop;
4613
+ } else if (range.start !== null && range.stop === null) {
4614
+ func = (obj) => obj >= range.start;
4615
+ } else {
4616
+ func = (obj) => true;
4617
+ }
4618
+ return {
4619
+ type: "RangeExpression",
4620
+ start: range.start,
4621
+ stop: range.stop,
4622
+ match: func
4623
+ };
4624
+ });
4625
+ }).build();
4626
+ return parser.parse();
4627
+ };
4628
+ var generateMatchFunc2 = (filter) => {
4629
+ const result = parseFilter(filter);
4630
+ if (!result) {
4631
+ throw new Error(`Syntax error while parsing '${filter}'.`);
4632
+ }
4633
+ if (result.type == "TermExpression") {
4634
+ throw new Error(`Syntax error while parsing '${filter}'.`);
4635
+ }
4636
+ return (obj) => {
4637
+ if (!result.children)
4638
+ return false;
4639
+ return result.children.some((c) => c.match(obj));
4640
+ };
4641
+ };
4642
+ var generateFacetFunc = (filter) => {
4643
+ if (!filter.includes(":")) {
4644
+ return {
4645
+ source: filter,
4646
+ type: "TermExpression"
4647
+ };
4648
+ }
4649
+ return parseFilter(filter);
4650
+ };
4651
+ var filterProduct = (source, exprFunc) => (p, markMatchingVariants) => {
4652
+ const value = nestedLookup(p, source);
4653
+ return exprFunc(value);
4654
+ };
4655
+ var filterVariants = (source, exprFunc) => (p, markMatchingVariants) => {
4656
+ const [, ...paths] = source.split(".");
4657
+ const path = paths.join(".");
4658
+ const variants = getVariants(p);
4659
+ for (const variant of variants) {
4660
+ const value = resolveVariantValue(variant, path);
4661
+ if (exprFunc(value)) {
4662
+ if (markMatchingVariants) {
4663
+ for (const v of variants) {
4664
+ v.isMatchingVariant = false;
4665
+ }
4666
+ variant.isMatchingVariant = true;
4667
+ }
4668
+ return true;
4669
+ }
4670
+ }
4671
+ return false;
4672
+ };
4673
+ var resolveVariantValue = (obj, path) => {
4674
+ if (path === void 0) {
4675
+ return obj;
4676
+ }
4677
+ if (path.startsWith("variants.")) {
4678
+ path = path.substring(path.indexOf(".") + 1);
4679
+ }
4680
+ if (path.startsWith("attributes.")) {
4681
+ const [, attrName, ...rest] = path.split(".");
4682
+ if (!obj.attributes) {
4683
+ return void 0;
4684
+ }
4685
+ for (const attr of obj.attributes) {
4686
+ if (attr.name === attrName) {
4687
+ return nestedLookup(attr.value, rest.join("."));
4688
+ }
4689
+ }
4690
+ }
4691
+ if (path === "price.centAmount") {
4692
+ return obj.prices && obj.prices.length > 0 ? obj.prices[0].value.centAmount : void 0;
4693
+ }
4694
+ return nestedLookup(obj, path);
4695
+ };
4696
+ var getVariants = (p) => [
4697
+ p.masterVariant,
4698
+ ...p.variants ?? []
4699
+ ];
4700
+
4701
+ // src/lib/productSearchFilter.ts
4702
+ var parseSearchQuery = (searchQuery) => {
4703
+ if (isSearchAndExpression(searchQuery)) {
4704
+ return (obj, markMatchingVariant) => searchQuery.and.every((expr) => {
4705
+ const filterFunc = parseSearchQuery(expr);
4706
+ return filterFunc(obj, markMatchingVariant);
4707
+ });
4708
+ }
4709
+ if (isSearchOrExpression(searchQuery)) {
4710
+ return (obj, markMatchingVariant) => searchQuery.or.some((expr) => {
4711
+ const filterFunc = parseSearchQuery(expr);
4712
+ return filterFunc(obj, markMatchingVariant);
4713
+ });
4714
+ }
4715
+ if (isSearchNotExpression(searchQuery)) {
4716
+ return (obj, markMatchingVariant) => !parseSearchQuery(searchQuery.not)(obj, markMatchingVariant);
4717
+ }
4718
+ if (isSearchFilterExpression(searchQuery)) {
4719
+ return (obj, markMatchingVariant) => searchQuery.filter.every((expr) => {
4720
+ const filterFunc = parseSearchQuery(expr);
4721
+ return filterFunc(obj, markMatchingVariant);
4722
+ });
4723
+ }
4724
+ if (isSearchRangeExpression(searchQuery)) {
4725
+ const generateRangeMatchFunc = (value) => {
4726
+ const rangeFilters = [];
4727
+ if (searchQuery.range.gte) {
4728
+ rangeFilters.push(value >= searchQuery.range.gte);
4729
+ }
4730
+ if (searchQuery.range.gt) {
4731
+ rangeFilters.push(value > searchQuery.range.gt);
4732
+ }
4733
+ if (searchQuery.range.lte) {
4734
+ rangeFilters.push(value <= searchQuery.range.lte);
4735
+ }
4736
+ if (searchQuery.range.lt) {
4737
+ rangeFilters.push(value < searchQuery.range.lt);
4738
+ }
4739
+ return rangeFilters.every((filter) => filter);
4740
+ };
4741
+ return generateFieldMatchFunc(generateRangeMatchFunc, searchQuery.range);
4742
+ }
4743
+ if (isSearchExactExpression(searchQuery)) {
4744
+ return generateFieldMatchFunc(
4745
+ (value) => value === searchQuery.exact.value,
4746
+ searchQuery.exact
4747
+ );
4748
+ }
4749
+ if (isSearchExistsExpression(searchQuery)) {
4750
+ return generateFieldMatchFunc((value) => !!value, searchQuery.exists);
4751
+ }
4752
+ if (isSearchFullTextExpression(searchQuery)) {
4753
+ return generateFieldMatchFunc(
4754
+ (value) => value.includes(searchQuery.fullText.value),
4755
+ searchQuery.fullText
4756
+ );
4757
+ }
4758
+ if (isSearchFullTextPrefixExpression(searchQuery)) {
4759
+ return generateFieldMatchFunc(
4760
+ (value) => value.startsWith(searchQuery.fullTextPrefix.value),
4761
+ searchQuery.fullTextPrefix
4762
+ );
4763
+ }
4764
+ if (isSearchPrefixExpression(searchQuery)) {
4765
+ return generateFieldMatchFunc(
4766
+ (value) => value.startsWith(searchQuery.prefix.value),
4767
+ searchQuery.prefix
4768
+ );
4769
+ }
4770
+ if (isSearchWildCardExpression(searchQuery)) {
4771
+ const generateWildcardMatchFunc = (value) => {
4772
+ const wildCardValues = searchQuery.wildcard.value.split("*").filter((v) => !!v);
4773
+ if (searchQuery.wildcard.caseInsensitive) {
4774
+ return wildCardValues.every(
4775
+ (wildCardValue) => value.toLowerCase().includes(wildCardValue.toLowerCase())
4776
+ );
4777
+ }
4778
+ return wildCardValues.every(
4779
+ (wildCardValue) => value.includes(wildCardValue)
4780
+ );
4781
+ };
4782
+ return generateFieldMatchFunc(
4783
+ generateWildcardMatchFunc,
4784
+ searchQuery.wildcard
4785
+ );
4786
+ }
4787
+ throw new Error("Unsupported search query expression");
4788
+ };
4789
+ var generateFieldMatchFunc = (matchFunc, searchQuery) => {
4790
+ const generateMatchFunc3 = (obj, markMatchingVariants) => {
4791
+ if (searchQuery.field.startsWith("variants.")) {
4792
+ const variantField = searchQuery.field.substring(
4793
+ searchQuery.field.indexOf(".") + 1
4794
+ );
4795
+ const variants = getVariants(obj);
4796
+ for (const variant of variants) {
4797
+ const value = resolveFieldValue(variant, {
4798
+ ...searchQuery,
4799
+ field: variantField
4800
+ });
4801
+ if (matchFunc(value)) {
4802
+ if (markMatchingVariants) {
4803
+ for (const v of variants) {
4804
+ v.isMatchingVariant = false;
4805
+ }
4806
+ variant.isMatchingVariant = true;
4807
+ }
4808
+ return true;
4809
+ }
4810
+ }
4811
+ return false;
4812
+ }
4813
+ return matchFunc(resolveFieldValue(obj, searchQuery));
4814
+ };
4815
+ return generateMatchFunc3;
4816
+ };
4817
+ var resolveFieldValue = (obj, searchQuery) => {
4818
+ if (searchQuery.field === void 0) {
4819
+ throw new Error("Missing field path in query expression");
4522
4820
  }
4821
+ let fieldPath = searchQuery.field;
4822
+ const language = "language" in searchQuery ? searchQuery.language : void 0;
4823
+ if (fieldPath.startsWith("variants.")) {
4824
+ fieldPath = fieldPath.substring(fieldPath.indexOf(".") + 1);
4825
+ }
4826
+ if (fieldPath.startsWith("attributes.")) {
4827
+ const [, attrName, ...rest] = fieldPath.split(".");
4828
+ if (!obj.attributes) {
4829
+ return void 0;
4830
+ }
4831
+ for (const attr of obj.attributes) {
4832
+ if (attr.name === attrName) {
4833
+ return nestedLookupByLanguage(attr.value, rest.join("."), language);
4834
+ }
4835
+ }
4836
+ }
4837
+ if (fieldPath === "prices.currentCentAmount") {
4838
+ return obj.prices && obj.prices.length > 0 ? obj.prices[0].value.centAmount : void 0;
4839
+ }
4840
+ return nestedLookupByLanguage(obj, fieldPath, language);
4841
+ };
4842
+ var nestedLookupByLanguage = (obj, path, language) => {
4843
+ const value = nestedLookup(obj, path);
4844
+ if (language && value && typeof value === "object") {
4845
+ const matchingLanguageKey = Object.keys(value).find(
4846
+ (key) => key.toLowerCase().startsWith(language.toLowerCase())
4847
+ );
4848
+ return matchingLanguageKey ? value[matchingLanguageKey] : void 0;
4849
+ }
4850
+ return value;
4523
4851
  };
4524
4852
  var isSearchAndExpression = (expr) => expr.and !== void 0;
4525
4853
  var isSearchOrExpression = (expr) => expr.or !== void 0;
@@ -4532,6 +4860,32 @@ var isSearchFullTextExpression = (expr) => expr.fullText !== void 0;
4532
4860
  var isSearchFullTextPrefixExpression = (expr) => expr.fullTextPrefix !== void 0;
4533
4861
  var isSearchPrefixExpression = (expr) => expr.prefix !== void 0;
4534
4862
  var isSearchWildCardExpression = (expr) => expr.wildcard !== void 0;
4863
+
4864
+ // src/lib/searchQueryTypeChecker.ts
4865
+ var validateSearchQuery = (query) => {
4866
+ if (isSearchAndExpression2(query)) {
4867
+ query.and.forEach((expr) => validateSearchQuery(expr));
4868
+ } else if (isSearchOrExpression2(query)) {
4869
+ query.or.forEach((expr) => validateSearchQuery(expr));
4870
+ } else if (isSearchNotExpression2(query)) {
4871
+ validateSearchQuery(query.not);
4872
+ } else if (isSearchFilterExpression2(query) || isSearchRangeExpression2(query) || isSearchExactExpression2(query) || isSearchExistsExpression2(query) || isSearchFullTextExpression2(query) || isSearchFullTextPrefixExpression2(query) || isSearchPrefixExpression2(query) || isSearchWildCardExpression2(query) || isSearchAnyValue(query)) {
4873
+ return;
4874
+ } else {
4875
+ throw new Error("Unsupported search query expression");
4876
+ }
4877
+ };
4878
+ var isSearchAndExpression2 = (expr) => expr.and !== void 0;
4879
+ var isSearchOrExpression2 = (expr) => expr.or !== void 0;
4880
+ var isSearchNotExpression2 = (expr) => expr.not !== void 0;
4881
+ var isSearchFilterExpression2 = (expr) => expr.filter !== void 0;
4882
+ var isSearchRangeExpression2 = (expr) => expr.range !== void 0;
4883
+ var isSearchExactExpression2 = (expr) => expr.exact !== void 0;
4884
+ var isSearchExistsExpression2 = (expr) => expr.exists !== void 0;
4885
+ var isSearchFullTextExpression2 = (expr) => expr.fullText !== void 0;
4886
+ var isSearchFullTextPrefixExpression2 = (expr) => expr.fullTextPrefix !== void 0;
4887
+ var isSearchPrefixExpression2 = (expr) => expr.prefix !== void 0;
4888
+ var isSearchWildCardExpression2 = (expr) => expr.wildcard !== void 0;
4535
4889
  var isSearchAnyValue = (expr) => expr.value !== void 0;
4536
4890
 
4537
4891
  // src/priceSelector.ts
@@ -4592,7 +4946,7 @@ var ProductSearch = class {
4592
4946
  this._storage = storage;
4593
4947
  }
4594
4948
  search(projectKey, params) {
4595
- const resources = this._storage.all(projectKey, "product").map(
4949
+ let resources = this._storage.all(projectKey, "product").map(
4596
4950
  (r) => this.transform(r, params.productProjectionParameters?.staged ?? false)
4597
4951
  ).filter((p) => {
4598
4952
  if (!params.productProjectionParameters?.staged) {
@@ -4600,9 +4954,14 @@ var ProductSearch = class {
4600
4954
  }
4601
4955
  return true;
4602
4956
  });
4957
+ const markMatchingVariant = params.markMatchingVariants ?? false;
4603
4958
  if (params.query) {
4604
4959
  try {
4605
4960
  validateSearchQuery(params.query);
4961
+ const matchFunc = parseSearchQuery(params.query);
4962
+ resources = resources.filter(
4963
+ (resource) => matchFunc(resource, markMatchingVariant)
4964
+ );
4606
4965
  } catch (err) {
4607
4966
  console.error(err);
4608
4967
  throw new CommercetoolsError(
@@ -5579,196 +5938,6 @@ var ProductDiscountUpdateHandler = class extends AbstractUpdateHandler {
5579
5938
  }
5580
5939
  };
5581
5940
 
5582
- // src/lib/projectionSearchFilter.ts
5583
- var parseFilterExpression = (filter) => {
5584
- const exprFunc = generateMatchFunc2(filter);
5585
- const [source] = filter.split(":", 1);
5586
- if (source.startsWith("variants.")) {
5587
- return filterVariants(source, exprFunc);
5588
- }
5589
- return filterProduct(source, exprFunc);
5590
- };
5591
- var getLexer2 = (value) => new Lexer(value).token("MISSING", /missing(?![-_a-z0-9]+)/i).token("EXISTS", /exists(?![-_a-z0-9]+)/i).token("RANGE", /range(?![-_a-z0-9]+)/i).token("TO", /to(?![-_a-z0-9]+)/i).token("IDENTIFIER", /[-_.a-z]+/i).token("FLOAT", /\d+\.\d+/).token("INT", /\d+/).token("STRING", /"((?:\\.|[^"\\])*)"/).token("STRING", /'((?:\\.|[^'\\])*)'/).token("COMMA", ",").token("STAR", "*").token("(", "(").token(":", ":").token(")", ")").token('"', '"').token("WS", /\s+/, true);
5592
- var parseFilter = (filter) => {
5593
- const lexer = getLexer2(filter);
5594
- const parser = new Parser(lexer).builder().nud("IDENTIFIER", 100, (t) => t.token.match).led(":", 100, ({ left, bp }) => {
5595
- const parsed = parser.parse({ terminals: [bp - 1] });
5596
- const expressions = !Array.isArray(parsed) ? [parsed] : parsed;
5597
- const unique = new Set(expressions.map((expr) => expr.type));
5598
- if (unique.size > 1) {
5599
- throw new Error("Invalid expression");
5600
- }
5601
- if (expressions.some((expr) => expr.type == "Symbol")) {
5602
- return {
5603
- source: left,
5604
- type: "FilterExpression",
5605
- children: expressions.map((e) => {
5606
- if (e.type != "Symbol") {
5607
- throw new Error("Invalid expression");
5608
- }
5609
- return {
5610
- type: "FilterExpression",
5611
- match: (obj) => obj === e.value
5612
- };
5613
- })
5614
- };
5615
- }
5616
- return {
5617
- source: left,
5618
- type: expressions[0].type,
5619
- children: expressions
5620
- };
5621
- }).nud(
5622
- "STRING",
5623
- 20,
5624
- (t) => ({
5625
- type: "Symbol",
5626
- kind: "string",
5627
- // @ts-ignore
5628
- value: t.token.groups[1]
5629
- })
5630
- ).nud(
5631
- "INT",
5632
- 5,
5633
- (t) => ({
5634
- type: "Symbol",
5635
- kind: "int",
5636
- value: parseInt(t.token.match, 10)
5637
- })
5638
- ).nud("STAR", 5, (_) => ({
5639
- type: "Symbol",
5640
- kind: "any",
5641
- value: null
5642
- })).nud(
5643
- "EXISTS",
5644
- 10,
5645
- ({ bp }) => ({
5646
- type: "FilterExpression",
5647
- match: (obj) => obj !== void 0
5648
- })
5649
- ).nud(
5650
- "MISSING",
5651
- 10,
5652
- ({ bp }) => ({
5653
- type: "FilterExpression",
5654
- match: (obj) => obj === void 0
5655
- })
5656
- ).led("COMMA", 200, ({ left, token, bp }) => {
5657
- const expr = parser.parse({ terminals: [bp - 1] });
5658
- if (Array.isArray(expr)) {
5659
- return [left, ...expr];
5660
- } else {
5661
- return [left, expr];
5662
- }
5663
- }).nud("(", 100, (t) => {
5664
- const expr = parser.parse({ terminals: [")"] });
5665
- lexer.expect(")");
5666
- return expr;
5667
- }).bp(")", 0).led("TO", 20, ({ left, bp }) => {
5668
- const expr = parser.parse({ terminals: [bp - 1] });
5669
- return {
5670
- start: left.value,
5671
- stop: expr.value
5672
- };
5673
- }).nud("RANGE", 20, ({ bp }) => {
5674
- let ranges = parser.parse();
5675
- if (!Array.isArray(ranges)) {
5676
- ranges = [ranges];
5677
- }
5678
- return ranges.map((range) => {
5679
- let func;
5680
- if (range.start !== null && range.stop !== null) {
5681
- func = (obj) => obj >= range.start && obj <= range.stop;
5682
- } else if (range.start === null && range.stop !== null) {
5683
- func = (obj) => obj <= range.stop;
5684
- } else if (range.start !== null && range.stop === null) {
5685
- func = (obj) => obj >= range.start;
5686
- } else {
5687
- func = (obj) => true;
5688
- }
5689
- return {
5690
- type: "RangeExpression",
5691
- start: range.start,
5692
- stop: range.stop,
5693
- match: func
5694
- };
5695
- });
5696
- }).build();
5697
- return parser.parse();
5698
- };
5699
- var generateMatchFunc2 = (filter) => {
5700
- const result = parseFilter(filter);
5701
- if (!result) {
5702
- throw new Error(`Syntax error while parsing '${filter}'.`);
5703
- }
5704
- if (result.type == "TermExpression") {
5705
- throw new Error(`Syntax error while parsing '${filter}'.`);
5706
- }
5707
- return (obj) => {
5708
- if (!result.children)
5709
- return false;
5710
- return result.children.some((c) => c.match(obj));
5711
- };
5712
- };
5713
- var generateFacetFunc = (filter) => {
5714
- if (!filter.includes(":")) {
5715
- return {
5716
- source: filter,
5717
- type: "TermExpression"
5718
- };
5719
- }
5720
- return parseFilter(filter);
5721
- };
5722
- var filterProduct = (source, exprFunc) => (p, markMatchingVariants) => {
5723
- const value = nestedLookup(p, source);
5724
- return exprFunc(value);
5725
- };
5726
- var filterVariants = (source, exprFunc) => (p, markMatchingVariants) => {
5727
- const [, ...paths] = source.split(".");
5728
- const path = paths.join(".");
5729
- const variants = getVariants(p);
5730
- for (const variant of variants) {
5731
- const value = resolveVariantValue(variant, path);
5732
- if (exprFunc(value)) {
5733
- if (markMatchingVariants) {
5734
- for (const v of variants) {
5735
- v.isMatchingVariant = false;
5736
- }
5737
- variant.isMatchingVariant = true;
5738
- }
5739
- return true;
5740
- }
5741
- }
5742
- return false;
5743
- };
5744
- var resolveVariantValue = (obj, path) => {
5745
- if (path === void 0) {
5746
- return obj;
5747
- }
5748
- if (path.startsWith("variants.")) {
5749
- path = path.substring(path.indexOf(".") + 1);
5750
- }
5751
- if (path.startsWith("attributes.")) {
5752
- const [, attrName, ...rest] = path.split(".");
5753
- if (!obj.attributes) {
5754
- return void 0;
5755
- }
5756
- for (const attr of obj.attributes) {
5757
- if (attr.name === attrName) {
5758
- return nestedLookup(attr.value, rest.join("."));
5759
- }
5760
- }
5761
- }
5762
- if (path === "price.centAmount") {
5763
- return obj.prices && obj.prices.length > 0 ? obj.prices[0].value.centAmount : void 0;
5764
- }
5765
- return nestedLookup(obj, path);
5766
- };
5767
- var getVariants = (p) => [
5768
- p.masterVariant,
5769
- ...p.variants ?? []
5770
- ];
5771
-
5772
5941
  // src/product-projection-search.ts
5773
5942
  var ProductProjectionSearch = class {
5774
5943
  _storage;