@websolutespa/bom-core 1.7.10 → 1.7.12

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.mjs CHANGED
@@ -1,174 +1,77 @@
1
- // src/category/category.ts
2
- function isCategory(value) {
3
- return Boolean(value) && typeof value === "object";
4
- }
5
- function asCategoryId(value) {
6
- return isCategory(value) ? value.id : value;
7
- }
8
- var ROOT_CATEGORY = process.env.ROOT_CATEGORY || "";
9
- function getRootCategory(categories) {
10
- const rootCategory = ROOT_CATEGORY && categories.find((x) => x.id == ROOT_CATEGORY);
11
- if (rootCategory) {
12
- return rootCategory;
13
- } else {
14
- return categories.find((x) => x.category == null);
15
- }
1
+ // src/utils/typeGuards.ts
2
+ function isNumber(item) {
3
+ return typeof item === "number";
16
4
  }
17
- function getParentCategoriesById(id, categories) {
18
- const rootCategory = getRootCategory(categories);
19
- const routeCategories = [];
20
- const segments = [];
21
- let parentId = id || null;
22
- while (parentId != null) {
23
- const parentCategory = categories.find((c) => c.id === parentId);
24
- if (parentCategory) {
25
- if (parentCategory.slug || parentCategory.id === rootCategory?.id) {
26
- const segment = { ...parentCategory };
27
- segments.unshift(segment);
28
- }
29
- parentId = parentCategory.category ? asCategoryId(parentCategory.category) : null;
30
- if (parentId) {
31
- if (routeCategories.includes(parentId)) {
32
- console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
33
- parentId = null;
34
- } else {
35
- routeCategories.push(parentId);
36
- }
37
- }
38
- } else {
39
- parentId = null;
40
- }
41
- }
42
- return segments;
5
+ function isString(item) {
6
+ return typeof item === "string";
43
7
  }
44
- function getCategorySegments(item, categories) {
45
- const categoryId = asCategoryId(item.category);
46
- const segments = getParentCategoriesById(categoryId, categories);
47
- return segments;
8
+ function isValidString(item) {
9
+ return typeof item === "string" && item.length > 0;
48
10
  }
49
- function getCategorySegmentsByCategory(item, categories) {
50
- const categoryId = item.category ? asCategoryId(item.category) : null;
51
- const segments = categoryId ? getParentCategoriesById(categoryId, categories) : [];
52
- segments.push(item);
53
- return segments;
11
+ function isArray(item) {
12
+ return Array.isArray(item);
54
13
  }
55
-
56
- // src/classNames/classNames.ts
57
- function isClassNameCollection(value) {
58
- return typeof value === "object" && !Array.isArray(value);
14
+ function isObject(item) {
15
+ return item != null && typeof item === "object" && !isArray(item);
59
16
  }
60
- function classNameCollectionToString(className) {
61
- const keys = Object.keys(className);
62
- const total = keys.length;
63
- let classNames = "";
64
- for (let i = 0; i < total; i++) {
65
- const key = keys[i];
66
- const value = className[keys[i]];
67
- if (!value) {
68
- continue;
69
- }
70
- classNames = classNames ? `${classNames} ${String(key)}` : String(key);
71
- }
72
- return classNames;
17
+ function isPromise(result) {
18
+ return isObject(result) && typeof result.then === "function";
73
19
  }
74
- function getClassNames(...props) {
75
- const total = props.length;
76
- let classNames = "";
77
- if (total === 0) {
78
- return classNames;
79
- }
80
- for (let i = 0; i < total; i++) {
81
- const value = props[i];
82
- if (!value) {
83
- continue;
84
- }
85
- if (isClassNameCollection(value)) {
86
- classNames += ` ${classNameCollectionToString(value)}`;
87
- } else {
88
- classNames += ` ${String(value).trim()}`;
89
- }
90
- }
91
- return classNames.trim();
20
+ function isNotNullString(item) {
21
+ return typeof item === "string" && Boolean(item);
92
22
  }
93
-
94
- // src/collection/collection.ts
95
- import pluralize from "pluralize";
96
- function getCollectionDescription(text) {
97
- text = toValidCollectionName(text);
98
- const displayName = toDisplayName(text);
99
- const pluralName = toPluralName(text);
100
- const pluralDisplayName = toDisplayName(pluralName);
101
- const singularName = text;
102
- const title = toTitleCase(text);
103
- return {
104
- displayName,
105
- pluralName,
106
- pluralDisplayName,
107
- singularName,
108
- title
109
- };
23
+ function isEquatable(item) {
24
+ return typeof item === "number" || isNotNullString(item);
110
25
  }
111
- function camelToSnakeCase(text) {
112
- return text.replace(/[A-Z]/g, (letter, index) => {
113
- return index > 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase();
114
- });
26
+ function isEntity(item) {
27
+ return isObject(item) && isEquatable(item.id);
115
28
  }
116
- function isValidCollectionDescription(description) {
117
- return description.singularName !== description.pluralName;
29
+ function isUnresolvedRelation(item) {
30
+ return isObject(item) && isNotNullString(item.relationTo) && (isEquatable(item.value) || isArray(item.value));
118
31
  }
119
- function isReservedCollectionDescription(description) {
120
- return [
121
- "category",
122
- "label",
123
- "locale",
124
- "market",
125
- "menu",
126
- "redirect",
127
- "route",
128
- "template"
129
- ].includes(description.singularName);
32
+ function isRelation(item) {
33
+ return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
130
34
  }
131
- function toDisplayName(text) {
132
- return toTitleCase(text).replace(/\s/g, "");
35
+ function isUndecoratedMenuItem(item) {
36
+ return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
133
37
  }
134
- function toPluralName(text) {
135
- const plural = pluralize.plural(text);
136
- return plural === text ? `${plural}es` : plural;
38
+ function isUndecoratedNav(item) {
39
+ return isObject(item) && isUndecoratedMenuPage(item.nav);
137
40
  }
138
- function toTitleCase(text) {
139
- return text.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase()).replace(/[-_]+(.)/g, (_, c) => " " + c.toUpperCase());
41
+ function isUndecoratedMenuCategory(item) {
42
+ return isObject(item) && item.type === "category" && isNotNullString(item.category) && item.id === void 0 && item.href === void 0;
140
43
  }
141
- function toValidCollectionName(text) {
142
- text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
143
- text = camelToSnakeCase(text);
144
- text = text.replace(/__/g, "_");
145
- return text.toLowerCase();
44
+ function isUndecoratedMenuPage(item) {
45
+ return isObject(item) && item.type === "page" && isObject(item.page) && isNotNullString(item.page.relationTo) && isEquatable(item.page.value);
146
46
  }
147
47
 
148
- // src/consoleWarn/consoleWarn.ts
149
- var warningStack = {};
150
- function consoleWarn(message, component) {
151
- if (typeof console === "undefined") {
152
- return;
153
- }
154
- const tag = component ? ` [${component}]` : " ";
155
- const log = `[DesignSystem]${tag}: ${message}`;
156
- if (warningStack[log]) {
157
- return;
48
+ // src/utils/asEquatable.ts
49
+ function asEquatable(value) {
50
+ const id = isEntity(value) ? value.id : value;
51
+ if (typeof id === "string") {
52
+ if (String(parseInt(id)) === id) {
53
+ return Number(id);
54
+ }
158
55
  }
159
- warningStack[log] = true;
160
- if (process.env.NODE_ENV !== "production") {
161
- return console.error(log);
56
+ return id;
57
+ }
58
+ function asEquatableString(value) {
59
+ const id = isEntity(value) ? value.id : value;
60
+ if (typeof id !== "undefined") {
61
+ return String(id);
162
62
  }
163
- console.warn(log);
63
+ return id;
164
64
  }
165
-
166
- // src/utils/asEquatable.ts
167
- function asEquatable(value) {
168
- if (String(parseInt(value)) === value) {
169
- return Number(value);
65
+ function asEquatableNumber(value) {
66
+ const id = isEntity(value) ? value.id : value;
67
+ if (typeof id === "string") {
68
+ if (String(parseInt(id)) === id) {
69
+ return Number(id);
70
+ } else {
71
+ return void 0;
72
+ }
170
73
  }
171
- return value;
74
+ return id;
172
75
  }
173
76
 
174
77
  // src/utils/asSortedOptions.ts
@@ -231,53 +134,6 @@ function toSnakeCase(unknownCase) {
231
134
  return snakeCase;
232
135
  }
233
136
 
234
- // src/utils/typeGuards.ts
235
- function isNumber(item) {
236
- return typeof item === "number";
237
- }
238
- function isString(item) {
239
- return typeof item === "string";
240
- }
241
- function isValidString(item) {
242
- return typeof item === "string" && item.length > 0;
243
- }
244
- function isArray(item) {
245
- return Array.isArray(item);
246
- }
247
- function isObject(item) {
248
- return item != null && typeof item === "object" && !isArray(item);
249
- }
250
- function isPromise(result) {
251
- return isObject(result) && typeof result.then === "function";
252
- }
253
- function isNotNullString(item) {
254
- return typeof item === "string" && Boolean(item);
255
- }
256
- function isEquatable(item) {
257
- return typeof item === "number" || isNotNullString(item);
258
- }
259
- function isEntity(item) {
260
- return isObject(item) && isEquatable(item.id);
261
- }
262
- function isUnresolvedRelation(item) {
263
- return isObject(item) && isNotNullString(item.relationTo) && (isEquatable(item.value) || isArray(item.value));
264
- }
265
- function isRelation(item) {
266
- return isObject(item) && isNotNullString(item.relationTo) && isEntity(item.value);
267
- }
268
- function isUndecoratedMenuItem(item) {
269
- return isObject(item) && (item.type === "category" && isEquatable(item.category) || item.type === "page" && isEquatable(item.page.value));
270
- }
271
- function isUndecoratedNav(item) {
272
- return isObject(item) && isUndecoratedMenuPage(item.nav);
273
- }
274
- function isUndecoratedMenuCategory(item) {
275
- return isObject(item) && item.type === "category" && isNotNullString(item.category) && item.id === void 0 && item.href === void 0;
276
- }
277
- function isUndecoratedMenuPage(item) {
278
- return isObject(item) && item.type === "page" && isObject(item.page) && isNotNullString(item.page.relationTo) && isEquatable(item.page.value);
279
- }
280
-
281
137
  // src/utils/cloneItem.ts
282
138
  function cloneItem(item) {
283
139
  if (isArray(item)) {
@@ -378,6 +234,14 @@ function enumToList(enumeration, separatorRegex = /_/g) {
378
234
  }));
379
235
  }
380
236
 
237
+ // src/utils/uuid.ts
238
+ function uuidv4() {
239
+ return "10000000-1000-4000-8000-100000000000".replace(
240
+ /[018]/g,
241
+ (c) => (+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
242
+ );
243
+ }
244
+
381
245
  // src/utils/index.ts
382
246
  function getIsDevelopment() {
383
247
  return process && (!process.env.NODE_ENV || process.env.NODE_ENV === "development");
@@ -431,6 +295,177 @@ function merge(target, source) {
431
295
  return target;
432
296
  }
433
297
 
298
+ // src/category/category.ts
299
+ var ROOT_CATEGORY = process.env.ROOT_CATEGORY || "";
300
+ function getRootCategory(categories) {
301
+ const rootCategory = ROOT_CATEGORY && categories.find((x) => x.id == ROOT_CATEGORY);
302
+ if (rootCategory) {
303
+ return rootCategory;
304
+ } else {
305
+ return categories.find((x) => x.category == null);
306
+ }
307
+ }
308
+ function getParentCategory(categories, item) {
309
+ const parentCategoryId = asCategoryId(item.category);
310
+ const parentCategory = parentCategoryId ? categories.find((x) => x.id === parentCategoryId) : void 0;
311
+ return parentCategory;
312
+ }
313
+ function getParentCategoriesById(categories, id) {
314
+ const routeCategories = [];
315
+ const segments = [];
316
+ let parentId = id;
317
+ while (parentId != null) {
318
+ const parentCategory = categories.find((c) => c.id === parentId);
319
+ if (parentCategory) {
320
+ const segment = { ...parentCategory };
321
+ segments.unshift(segment);
322
+ routeCategories.push(parentId);
323
+ parentId = asCategoryId(parentCategory.category);
324
+ if (parentId) {
325
+ if (routeCategories.includes(parentId)) {
326
+ console.log("ICategory.getParentCategoriesById", "circular reference found", parentId);
327
+ parentId = void 0;
328
+ }
329
+ }
330
+ } else {
331
+ parentId = void 0;
332
+ }
333
+ }
334
+ return segments;
335
+ }
336
+ function getCategorySegments(categories, item) {
337
+ const parentCategoryId = asCategoryId(item.category);
338
+ const segments = getParentCategoriesById(categories, parentCategoryId);
339
+ return segments;
340
+ }
341
+ function getCategorySegmentsByCategory(categories, item) {
342
+ const parentCategoryId = asCategoryId(item.category);
343
+ const segments = parentCategoryId ? getParentCategoriesById(categories, parentCategoryId) : [];
344
+ segments.push(item);
345
+ return segments;
346
+ }
347
+ function asCategoryId(value) {
348
+ return isEntity(value) ? String(value.id) : value ? String(value) : void 0;
349
+ }
350
+ function findCategoryInCategories(categories, item) {
351
+ const categoryId = asCategoryId(item);
352
+ return categoryId ? categories.find((x) => x.id === categoryId) : void 0;
353
+ }
354
+ function findChildCategories(categories, item) {
355
+ const categoryId = asCategoryId(item);
356
+ return categoryId ? categories.filter((x) => asCategoryId(x.category) === categoryId) : [];
357
+ }
358
+
359
+ // src/classNames/classNames.ts
360
+ function isClassNameCollection(value) {
361
+ return typeof value === "object" && !Array.isArray(value);
362
+ }
363
+ function classNameCollectionToString(className) {
364
+ const keys = Object.keys(className);
365
+ const total = keys.length;
366
+ let classNames = "";
367
+ for (let i = 0; i < total; i++) {
368
+ const key = keys[i];
369
+ const value = className[keys[i]];
370
+ if (!value) {
371
+ continue;
372
+ }
373
+ classNames = classNames ? `${classNames} ${String(key)}` : String(key);
374
+ }
375
+ return classNames;
376
+ }
377
+ function getClassNames(...props) {
378
+ const total = props.length;
379
+ let classNames = "";
380
+ if (total === 0) {
381
+ return classNames;
382
+ }
383
+ for (let i = 0; i < total; i++) {
384
+ const value = props[i];
385
+ if (!value) {
386
+ continue;
387
+ }
388
+ if (isClassNameCollection(value)) {
389
+ classNames += ` ${classNameCollectionToString(value)}`;
390
+ } else {
391
+ classNames += ` ${String(value).trim()}`;
392
+ }
393
+ }
394
+ return classNames.trim();
395
+ }
396
+
397
+ // src/collection/collection.ts
398
+ import pluralize from "pluralize";
399
+ function getCollectionDescription(text) {
400
+ text = toValidCollectionName(text);
401
+ const displayName = toDisplayName(text);
402
+ const pluralName = toPluralName(text);
403
+ const pluralDisplayName = toDisplayName(pluralName);
404
+ const singularName = text;
405
+ const title = toTitleCase(text);
406
+ return {
407
+ displayName,
408
+ pluralName,
409
+ pluralDisplayName,
410
+ singularName,
411
+ title
412
+ };
413
+ }
414
+ function camelToSnakeCase(text) {
415
+ return text.replace(/[A-Z]/g, (letter, index) => {
416
+ return index > 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase();
417
+ });
418
+ }
419
+ function isValidCollectionDescription(description) {
420
+ return description.singularName !== description.pluralName;
421
+ }
422
+ function isReservedCollectionDescription(description) {
423
+ return [
424
+ "category",
425
+ "label",
426
+ "locale",
427
+ "market",
428
+ "menu",
429
+ "redirect",
430
+ "route",
431
+ "template"
432
+ ].includes(description.singularName);
433
+ }
434
+ function toDisplayName(text) {
435
+ return toTitleCase(text).replace(/\s/g, "");
436
+ }
437
+ function toPluralName(text) {
438
+ const plural = pluralize.plural(text);
439
+ return plural === text ? `${plural}es` : plural;
440
+ }
441
+ function toTitleCase(text) {
442
+ return text.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase()).replace(/[-_]+(.)/g, (_, c) => " " + c.toUpperCase());
443
+ }
444
+ function toValidCollectionName(text) {
445
+ text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
446
+ text = camelToSnakeCase(text);
447
+ text = text.replace(/__/g, "_");
448
+ return text.toLowerCase();
449
+ }
450
+
451
+ // src/consoleWarn/consoleWarn.ts
452
+ var warningStack = {};
453
+ function consoleWarn(message, component) {
454
+ if (typeof console === "undefined") {
455
+ return;
456
+ }
457
+ const tag = component ? ` [${component}]` : " ";
458
+ const log = `[DesignSystem]${tag}: ${message}`;
459
+ if (warningStack[log]) {
460
+ return;
461
+ }
462
+ warningStack[log] = true;
463
+ if (process.env.NODE_ENV !== "production") {
464
+ return console.error(log);
465
+ }
466
+ console.warn(log);
467
+ }
468
+
434
469
  // src/http/http.service.ts
435
470
  var defaultOptions = {
436
471
  // method: 'POST', // *GET, POST, PUT, DELETE, etc.
@@ -503,11 +538,14 @@ var JsonService = class {
503
538
  params.pagination = false;
504
539
  let items = await this.getItems();
505
540
  if (params.where) {
506
- items = this.whereItems_(items, params.where);
541
+ items = this.whereItems_(items, params.where, params.limit);
507
542
  }
508
543
  if (params.sort) {
509
544
  items = this.sortCollection_(items, params.sort);
510
545
  }
546
+ if (params.limit && !params.where) {
547
+ items = this.limitCollection_(items, params.limit);
548
+ }
511
549
  return await this.decorateMany_(items, params);
512
550
  }
513
551
  async findPaged(params = {}) {
@@ -567,49 +605,45 @@ var JsonService = class {
567
605
  return (/* @__PURE__ */ new Date()).getTime();
568
606
  }
569
607
  // where
570
- evaluateValue_(value) {
571
- if (typeof value === "object" && value) {
572
- return value.id;
573
- } else {
574
- return value;
608
+ equalsClause_(value, equals) {
609
+ if (typeof equals !== "undefined") {
610
+ return value === equals;
575
611
  }
612
+ return true;
613
+ }
614
+ notEqualsClause_(value, not_equals) {
615
+ if (typeof not_equals !== "undefined") {
616
+ return value != not_equals;
617
+ }
618
+ return true;
576
619
  }
577
- /**
578
- equals The value must be exactly equal.
579
- not_equals The query will return all documents where the value is not equal.
580
- greater_than For numeric or date-based fields.
581
- greater_than_equal For numeric or date-based fields.
582
- less_than For numeric or date-based fields.
583
- less_than_equal For numeric or date-based fields.
584
- like Case-insensitive string must be present. If string of words, all words must be present, in any order.
585
- contains Must contain the value entered, case-insensitive.
586
- in The value must be found within the provided comma-delimited list of values.
587
- not_in The value must NOT be within the provided comma-delimited list of values.
588
- all The value must contain all values provided in the comma-delimited list.
589
- exists Only return documents where the value either exists (true) or does not exist (false).
590
- near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
591
- */
592
620
  existsClause_(value, exists) {
593
621
  if (typeof exists === "boolean") {
594
622
  return value != null === exists;
595
623
  }
596
624
  return true;
597
625
  }
598
- equalsClause_(value, equals) {
599
- if (typeof equals !== "undefined") {
600
- return this.evaluateValue_(value) === equals;
626
+ greaterThanClause_(value, greater_than) {
627
+ if (typeof greater_than === "number") {
628
+ return typeof value === "number" && value > greater_than;
601
629
  }
602
630
  return true;
603
631
  }
604
- inClause_(value, values) {
605
- if (Array.isArray(values)) {
606
- return values.indexOf(this.evaluateValue_(value)) !== -1;
632
+ greaterThanEqualClause_(value, greater_than_equal) {
633
+ if (typeof greater_than_equal === "number") {
634
+ return typeof value === "number" && value >= greater_than_equal;
607
635
  }
608
636
  return true;
609
637
  }
610
- notInClause_(value, values) {
611
- if (Array.isArray(values)) {
612
- return values.indexOf(this.evaluateValue_(value)) === -1;
638
+ lessThanClause_(value, less_than) {
639
+ if (typeof less_than === "number") {
640
+ return typeof value === "number" && value < less_than;
641
+ }
642
+ return true;
643
+ }
644
+ lessThanEqualClause_(value, less_than_equal) {
645
+ if (typeof less_than_equal === "number") {
646
+ return typeof value === "number" && value <= less_than_equal;
613
647
  }
614
648
  return true;
615
649
  }
@@ -632,6 +666,49 @@ var JsonService = class {
632
666
  }
633
667
  return true;
634
668
  }
669
+ inClause_(value, values) {
670
+ if (Array.isArray(values) && values.length > 0) {
671
+ return values.indexOf(value) !== -1;
672
+ }
673
+ return true;
674
+ }
675
+ notInClause_(value, values) {
676
+ if (Array.isArray(values) && values.length > 0) {
677
+ return values.indexOf(value) === -1;
678
+ }
679
+ return true;
680
+ }
681
+ allClause_(value, values) {
682
+ if (Array.isArray(values) && values.length > 0) {
683
+ return Array.isArray(value) ? values.reduce((p, c) => p && value.includes(c), true) : false;
684
+ }
685
+ return true;
686
+ }
687
+ nearClause_(value, near) {
688
+ if (Array.isArray(near) && near.reduce((p, c) => p && typeof c === "number", true)) {
689
+ if (!Array.isArray(value)) {
690
+ return false;
691
+ }
692
+ const itemLongitude = value[0];
693
+ if (typeof itemLongitude !== "number") {
694
+ return false;
695
+ }
696
+ const itemLatitude = value[1];
697
+ if (typeof itemLatitude !== "number") {
698
+ return false;
699
+ }
700
+ const [longitude, latitude, maxDistance, minDistance] = near;
701
+ const distance = calculateDistanceInMeters_(itemLongitude, itemLatitude, longitude, latitude);
702
+ if (typeof maxDistance === "number" && typeof minDistance === "number") {
703
+ return distance <= maxDistance && distance >= minDistance;
704
+ } else if (typeof maxDistance === "number") {
705
+ return distance <= maxDistance;
706
+ } else if (typeof minDistance === "number") {
707
+ return distance >= minDistance;
708
+ }
709
+ }
710
+ return true;
711
+ }
635
712
  whereItem_(item, where) {
636
713
  let has = true;
637
714
  if (typeof where === "object") {
@@ -654,22 +731,53 @@ var JsonService = class {
654
731
  default:
655
732
  if (Array.isArray(v)) {
656
733
  } else if (typeof v === "object") {
657
- const value = item[k];
658
- has = has && this.existsClause_(value, v.exists);
734
+ const value = getValue(item, k);
659
735
  has = has && this.equalsClause_(value, v.equals);
660
- has = has && this.inClause_(value, v.in);
661
- has = has && this.notInClause_(value, v.not_in);
736
+ has = has && this.notEqualsClause_(value, v.not_equals);
737
+ has = has && this.existsClause_(value, v.exists);
738
+ has = has && this.greaterThanClause_(value, v.greater_than);
739
+ has = has && this.greaterThanEqualClause_(value, v.greater_than_equal);
740
+ has = has && this.lessThanClause_(value, v.less_than);
741
+ has = has && this.lessThanEqualClause_(value, v.less_than_equal);
662
742
  has = has && this.likeClause_(value, v.like);
663
743
  has = has && this.containsClause_(value, v.contains);
744
+ has = has && this.inClause_(value, v.in);
745
+ has = has && this.notInClause_(value, v.not_in);
746
+ has = has && this.allClause_(value, v.all);
747
+ has = has && this.nearClause_(value, v.near);
664
748
  }
665
749
  }
666
750
  });
667
751
  }
668
752
  return has;
669
753
  }
670
- whereItems_(items, where) {
754
+ /**
755
+ equals The value must be exactly equal.
756
+ not_equals The query will return all documents where the value is not equal.
757
+ exists Only return documents where the value either exists (true) or does not exist (false).
758
+ greater_than For numeric or date-based fields.
759
+ greater_than_equal For numeric or date-based fields.
760
+ less_than For numeric or date-based fields.
761
+ less_than_equal For numeric or date-based fields.
762
+ like Case-insensitive string must be present. If string of words, all words must be present, in any order.
763
+ contains Must contain the value entered, case-insensitive.
764
+ in The value must be found within the provided comma-delimited list of values.
765
+ not_in The value must NOT be within the provided comma-delimited list of values.
766
+ all The value must contain all values provided in the comma-delimited list.
767
+ near For distance related to a point field comma separated as <longitude>, <latitude>, <maxDistance in meters (nullable)>, <minDistance in meters (nullable)>.
768
+ */
769
+ whereItems_(items, where, limit = -1) {
671
770
  if (typeof where === "object") {
672
- items = items.filter((item) => this.whereItem_(item, where));
771
+ const whereItems = [];
772
+ for (const item of items) {
773
+ if (limit > -1 && whereItems.length >= limit) {
774
+ return whereItems;
775
+ }
776
+ if (this.whereItem_(item, where)) {
777
+ whereItems.push(item);
778
+ }
779
+ }
780
+ return whereItems;
673
781
  }
674
782
  return items;
675
783
  }
@@ -695,14 +803,12 @@ var JsonService = class {
695
803
  }
696
804
  // ^ sort
697
805
  // limit
698
- /*
699
- protected limitCollection_<B extends T = T>(items: B[], limit?: number): B[] {
806
+ limitCollection_(items, limit) {
700
807
  if (limit) {
701
808
  items = items.slice(0, Math.min(limit, items.length));
702
809
  }
703
810
  return items;
704
811
  }
705
- */
706
812
  // ^ limit
707
813
  // pagination
708
814
  paginatedItems_(items, page = 1, limit = 10) {
@@ -732,6 +838,29 @@ var JsonService = class {
732
838
  }
733
839
  // ^ sort
734
840
  };
841
+ function getValue(item, key) {
842
+ const keys = key.split(".");
843
+ const value = keys.reduce((p, c) => {
844
+ if (isObject(p)) {
845
+ return p[c];
846
+ } else {
847
+ return void 0;
848
+ }
849
+ }, item);
850
+ return value;
851
+ }
852
+ function calculateDistanceInMeters_(lon1, lat1, lon2, lat2) {
853
+ const R = 6371;
854
+ const dLat = deg2rad_(lat2 - lat1);
855
+ const dLon = deg2rad_(lon2 - lon1);
856
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(deg2rad_(lat1)) * Math.cos(deg2rad_(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
857
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
858
+ const distance = R * c * 1e3;
859
+ return distance;
860
+ }
861
+ function deg2rad_(deg) {
862
+ return deg * (Math.PI / 180);
863
+ }
735
864
 
736
865
  // src/locale/locale.ts
737
866
  function getDefaultLocale() {
@@ -985,58 +1114,74 @@ function getOrigin(headers) {
985
1114
  }
986
1115
 
987
1116
  // src/route/route.ts
1117
+ var RouteStrategy = /* @__PURE__ */ ((RouteStrategy2) => {
1118
+ RouteStrategy2["Auto"] = "auto";
1119
+ RouteStrategy2["Default"] = "default";
1120
+ RouteStrategy2["Manual"] = "manual";
1121
+ return RouteStrategy2;
1122
+ })(RouteStrategy || {});
1123
+ var ROUTE_STRATEGY = process.env.ROUTE_STRATEGY || "auto" /* Auto */;
1124
+ function getPickedProps(item) {
1125
+ const pickedProps = Object.fromEntries(Object.entries(item).filter(([k, v]) => [
1126
+ "category",
1127
+ "isDefault",
1128
+ "media",
1129
+ "order",
1130
+ "template",
1131
+ "updatedAt",
1132
+ "useSplat"
1133
+ ].includes(k)));
1134
+ return pickedProps;
1135
+ }
988
1136
  function collectRoutes(store, categories, markets, locales) {
989
1137
  const routes = [];
990
1138
  if (locales.length > 0 && markets.length > 0) {
991
1139
  const rootCategory = getRootCategory(categories);
992
1140
  eachCategorized(store, (item, key) => {
993
- const segments = getCategorySegments(item, categories);
994
- const slugs = segments.map((x) => ({ slug: x.slug }));
995
- if (!item.isDefault) {
996
- slugs.push({ slug: item.slug });
997
- }
998
- eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
999
- if (!item.markets || item.markets.includes(market.id)) {
1000
- const title = localize(item.title, locale.id);
1001
- const id = getRouteHref(slugs, market, locale, markets2, locales2);
1141
+ const segments = getCategorySegments(categories, item);
1142
+ const visibleSegments = segments.filter((x) => Boolean(x.isHidden) === false);
1143
+ const visibleCategory = visibleSegments.length > 0 ? visibleSegments[visibleSegments.length - 1] : rootCategory;
1144
+ if (visibleCategory) {
1145
+ const slugs = visibleSegments.map((x) => ({ slug: x.slug }));
1146
+ if (Boolean(item.isDefault) === false) {
1147
+ slugs.push({ slug: item.slug });
1148
+ }
1149
+ if (rootCategory && item.category === rootCategory.id) {
1150
+ const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
1151
+ const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
1152
+ const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? defaultMarket2.defaultLanguage : defaultLocale2.id;
1153
+ const title = localize(item.title, defaultMarketLocale);
1154
+ const pickedProps = getPickedProps(item);
1002
1155
  const route = {
1003
- category: item.category,
1004
- id,
1005
- isDefault: item.isDefault,
1006
- locale: locale.id,
1007
- market: market.id,
1008
- media: item.media,
1009
- order: item.order,
1156
+ ...pickedProps,
1157
+ resolvedCategory: rootCategory.id,
1158
+ id: "/",
1159
+ market: defaultMarket2.id,
1160
+ locale: defaultMarketLocale,
1010
1161
  page: item.id,
1011
1162
  schema: key,
1012
- template: item.template,
1013
- title,
1014
- updatedAt: item.updatedAt,
1015
- useSplat: item.useSplat
1163
+ title
1016
1164
  };
1017
1165
  routes.push(route);
1018
1166
  }
1019
- });
1020
- if (rootCategory && item.category === rootCategory.id) {
1021
- const defaultLocale2 = locales.find((x) => x.isDefault) || locales[0];
1022
- const defaultMarket2 = markets.find((x) => x.isDefault) || markets[0];
1023
- const defaultMarketLocale = defaultMarket2 && defaultMarket2.defaultLanguage ? defaultMarket2.defaultLanguage : defaultLocale2.id;
1024
- const title = localize(item.title, defaultMarketLocale);
1025
- const route = {
1026
- id: "/",
1027
- market: defaultMarket2.id,
1028
- locale: defaultMarketLocale,
1029
- category: item.category,
1030
- page: item.id,
1031
- schema: key,
1032
- template: item.template,
1033
- title,
1034
- isDefault: item.isDefault,
1035
- order: item.order,
1036
- useSplat: item.useSplat,
1037
- updatedAt: item.updatedAt
1038
- };
1039
- routes.push(route);
1167
+ eachMarketLocale(markets, locales, (market, locale, markets2, locales2) => {
1168
+ if (!item.markets || item.markets.includes(market.id)) {
1169
+ const title = localize(item.title, locale.id);
1170
+ const id = getRouteHref(slugs, market, locale, markets2, locales2);
1171
+ const pickedProps = getPickedProps(item);
1172
+ const route = {
1173
+ ...pickedProps,
1174
+ resolvedCategory: visibleCategory.id,
1175
+ id,
1176
+ locale: locale.id,
1177
+ market: market.id,
1178
+ page: item.id,
1179
+ schema: key,
1180
+ title
1181
+ };
1182
+ routes.push(route);
1183
+ }
1184
+ });
1040
1185
  }
1041
1186
  });
1042
1187
  }
@@ -1061,13 +1206,17 @@ function eachCategorized(store, callback) {
1061
1206
  }
1062
1207
  }
1063
1208
  }
1064
- var RouteStrategy = /* @__PURE__ */ ((RouteStrategy2) => {
1065
- RouteStrategy2["Auto"] = "auto";
1066
- RouteStrategy2["Default"] = "default";
1067
- RouteStrategy2["Manual"] = "manual";
1068
- return RouteStrategy2;
1069
- })(RouteStrategy || {});
1070
- var ROUTE_STRATEGY = process.env.ROUTE_STRATEGY || "auto" /* Auto */;
1209
+ function findRouteOfCategory(routes, categoryId, market, locale) {
1210
+ const findRoute = market && locale ? (route2) => route2.isDefault && route2.resolvedCategory === categoryId && route2.market === market && route2.locale === locale : (route2) => route2.isDefault && route2.resolvedCategory === categoryId;
1211
+ const route = routes.find(findRoute);
1212
+ return route;
1213
+ }
1214
+ function findRoutesOfCategory(routes, categoryId, isDefault = true) {
1215
+ const filteredRoutes = routes.filter(
1216
+ (route) => route.resolvedCategory === categoryId && Boolean(route.isDefault) === isDefault
1217
+ );
1218
+ return filteredRoutes;
1219
+ }
1071
1220
  function getRouteHref(segments, market, locale, markets, locales) {
1072
1221
  const href = segments.reduce((p, c, i) => {
1073
1222
  let slug = localize(c.slug || "", locale.id);
@@ -1105,11 +1254,6 @@ function getRouteHref(segments, market, locale, markets, locales) {
1105
1254
  return `${prefix}${href}`;
1106
1255
  }
1107
1256
 
1108
- // src/slug/slug.ts
1109
- function textToSlug(title) {
1110
- return title.toString().normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, "-").replace(/&/g, "-and-").replace(/[^\w-]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
1111
- }
1112
-
1113
1257
  // src/types/media.ts
1114
1258
  function resolveMediaType(media) {
1115
1259
  if (typeof media.type === "string" && media.type.length > 0) {
@@ -1185,6 +1329,8 @@ export {
1185
1329
  RouteStrategy,
1186
1330
  asCategoryId,
1187
1331
  asEquatable,
1332
+ asEquatableNumber,
1333
+ asEquatableString,
1188
1334
  asServerProps,
1189
1335
  asSortedOptions,
1190
1336
  awaitAll,
@@ -1200,6 +1346,10 @@ export {
1200
1346
  eachCategorized,
1201
1347
  eachMarketLocale,
1202
1348
  enumToList,
1349
+ findCategoryInCategories,
1350
+ findChildCategories,
1351
+ findRouteOfCategory,
1352
+ findRoutesOfCategory,
1203
1353
  getCategorySegments,
1204
1354
  getCategorySegmentsByCategory,
1205
1355
  getClassNames,
@@ -1210,6 +1360,7 @@ export {
1210
1360
  getIsProduction,
1211
1361
  getOrigin,
1212
1362
  getParentCategoriesById,
1363
+ getParentCategory,
1213
1364
  getProto,
1214
1365
  getRootCategory,
1215
1366
  getRouteHref,
@@ -1221,7 +1372,6 @@ export {
1221
1372
  httpPut,
1222
1373
  isArray,
1223
1374
  isBrowser,
1224
- isCategory,
1225
1375
  isDevelopment,
1226
1376
  isEntity,
1227
1377
  isEquatable,
@@ -1263,7 +1413,6 @@ export {
1263
1413
  qsSerialize,
1264
1414
  qsSerializeRaw,
1265
1415
  resolveMediaType,
1266
- textToSlug,
1267
1416
  toCamelCase,
1268
1417
  toCharCase,
1269
1418
  toDisplayName,
@@ -1275,5 +1424,6 @@ export {
1275
1424
  toTitleCase,
1276
1425
  toValidCollectionName,
1277
1426
  unknownCaseToPascalCase,
1427
+ uuidv4,
1278
1428
  withSchema
1279
1429
  };