@crystaldesign/diva-utils 26.2.0-beta.3 → 26.2.0-beta.30
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/build/cjs/index.js +92 -0
- package/build/esm/index.js +92 -1
- package/build/types/utils/src/index.d.ts +2 -0
- package/build/types/utils/src/index.d.ts.map +1 -1
- package/build/types/utils/src/types/FilterParamTypes.d.ts +61 -0
- package/build/types/utils/src/types/FilterParamTypes.d.ts.map +1 -0
- package/build/types/utils/src/utils/parseFilterParam.d.ts +3 -0
- package/build/types/utils/src/utils/parseFilterParam.d.ts.map +1 -0
- package/package.json +2 -2
package/build/cjs/index.js
CHANGED
|
@@ -1525,6 +1525,97 @@ var UtmContent = /*#__PURE__*/function (UtmContent) {
|
|
|
1525
1525
|
return UtmContent;
|
|
1526
1526
|
}({});
|
|
1527
1527
|
|
|
1528
|
+
function parseFilterParam(param) {
|
|
1529
|
+
var query = {
|
|
1530
|
+
entries: []
|
|
1531
|
+
};
|
|
1532
|
+
if (param.startsWith('[') && param.endsWith(']')) {
|
|
1533
|
+
var _query$entries;
|
|
1534
|
+
//it contains multiple, remove brackets and split it up
|
|
1535
|
+
(_query$entries = query.entries).push.apply(_query$entries, _toConsumableArray__default["default"](parseList(param.substring(1, param.length - 1))));
|
|
1536
|
+
} else {
|
|
1537
|
+
query.entries.push(parseFilterField(param));
|
|
1538
|
+
}
|
|
1539
|
+
return query;
|
|
1540
|
+
}
|
|
1541
|
+
function parseList(param) {
|
|
1542
|
+
if (param.includes('[')) {
|
|
1543
|
+
return param.split(/(?<=]),|,(?=\+?\[)/g).flatMap(function (s) {
|
|
1544
|
+
//split at every comma, which is before or after a group
|
|
1545
|
+
if (s.startsWith('+[')) {
|
|
1546
|
+
return parseOrGroup(s);
|
|
1547
|
+
} else if (s.startsWith('[')) {
|
|
1548
|
+
return parseFieldList(s.substring(1, s.length - 1));
|
|
1549
|
+
} else {
|
|
1550
|
+
return parseFieldList(s);
|
|
1551
|
+
}
|
|
1552
|
+
});
|
|
1553
|
+
} else {
|
|
1554
|
+
return parseFieldList(param);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
function parseFieldList(param) {
|
|
1558
|
+
return param.split(/(?<=}),/g) //split at every comma, which is between curly brackets (get Filterfields)
|
|
1559
|
+
.map(parseFilterField);
|
|
1560
|
+
}
|
|
1561
|
+
function parseOrGroup(group) {
|
|
1562
|
+
var filterGroup = {
|
|
1563
|
+
entries: [],
|
|
1564
|
+
or: true,
|
|
1565
|
+
type: 'group'
|
|
1566
|
+
};
|
|
1567
|
+
if (group.startsWith('+[') && group.endsWith(']')) {
|
|
1568
|
+
filterGroup.entries = parseFieldList(group.replace(/\+\[|\]/g, '')); //remove encloseing brackets
|
|
1569
|
+
return filterGroup;
|
|
1570
|
+
}
|
|
1571
|
+
throw new Error('Wrong format: Or groups have to be in the form of "+[{<field>,<op>,<value>},...]"');
|
|
1572
|
+
}
|
|
1573
|
+
function parseFilterField(filter) {
|
|
1574
|
+
if (filter.startsWith('{') && filter.endsWith('}')) {
|
|
1575
|
+
var split = filter.replace(/[{}]/g, '') // Remove curly braces
|
|
1576
|
+
.split(/,(?=(?:[^']*'[^']*')*[^']*$)/g); // Split on commas outside of single quotes
|
|
1577
|
+
// Explanation of the regex:
|
|
1578
|
+
// - , matches the comma.
|
|
1579
|
+
// - (?=...) is a positive lookahead to ensure the next condition is met.
|
|
1580
|
+
// - (?:[^']*'[^']*')* matches zero or more pairs of single-quoted sections (to ensure commas inside quotes are ignored).
|
|
1581
|
+
// - [^']*$ ensures that we are splitting only if the comma is outside any single-quoted sections (i.e., we are not inside quotes at the time of the split).
|
|
1582
|
+
|
|
1583
|
+
if (split.length >= 3 && split[1] == 'in') {
|
|
1584
|
+
return {
|
|
1585
|
+
field: split[0],
|
|
1586
|
+
operator: split[1],
|
|
1587
|
+
value: split.slice(2).map(parseFieldValue)
|
|
1588
|
+
};
|
|
1589
|
+
} else if (split.length == 3) {
|
|
1590
|
+
var field = {
|
|
1591
|
+
field: split[0],
|
|
1592
|
+
operator: split[1],
|
|
1593
|
+
value: parseFieldValue(split[2])
|
|
1594
|
+
};
|
|
1595
|
+
return field;
|
|
1596
|
+
} else if (split.length == 2 && ['isnotnull', 'isnull', 'isnotempty', 'isempty'].includes(split[1])) {
|
|
1597
|
+
var _field = {
|
|
1598
|
+
field: split[0],
|
|
1599
|
+
operator: split[1]
|
|
1600
|
+
};
|
|
1601
|
+
return _field;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
throw new Error('Wrong format: Filter fields have to be in the form of "{<field>,<op>,<value>}"');
|
|
1605
|
+
}
|
|
1606
|
+
function parseFieldValue(value) {
|
|
1607
|
+
if (value == 'true' || value == 'false') {
|
|
1608
|
+
return value === 'true' ? true : false;
|
|
1609
|
+
}
|
|
1610
|
+
if (!isNaN(value)) {
|
|
1611
|
+
return Number(value);
|
|
1612
|
+
}
|
|
1613
|
+
if (value.startsWith("'") && value.endsWith("'") || value.startsWith('"') && value.endsWith('"')) {
|
|
1614
|
+
return value.substring(1, value.length - 1);
|
|
1615
|
+
}
|
|
1616
|
+
return value;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1528
1619
|
exports.DivaError = DivaError;
|
|
1529
1620
|
exports.UTMUtils = UTMUtils;
|
|
1530
1621
|
exports.UtmCampaign = UtmCampaign;
|
|
@@ -1534,3 +1625,4 @@ exports.UtmSource = UtmSource;
|
|
|
1534
1625
|
exports["default"] = DivaUtils$1;
|
|
1535
1626
|
exports.md5 = md5;
|
|
1536
1627
|
exports.nanoid = nanoid;
|
|
1628
|
+
exports.parseFilterParam = parseFilterParam;
|
package/build/esm/index.js
CHANGED
|
@@ -1506,4 +1506,95 @@ var UtmContent = /*#__PURE__*/function (UtmContent) {
|
|
|
1506
1506
|
return UtmContent;
|
|
1507
1507
|
}({});
|
|
1508
1508
|
|
|
1509
|
-
|
|
1509
|
+
function parseFilterParam(param) {
|
|
1510
|
+
var query = {
|
|
1511
|
+
entries: []
|
|
1512
|
+
};
|
|
1513
|
+
if (param.startsWith('[') && param.endsWith(']')) {
|
|
1514
|
+
var _query$entries;
|
|
1515
|
+
//it contains multiple, remove brackets and split it up
|
|
1516
|
+
(_query$entries = query.entries).push.apply(_query$entries, _toConsumableArray(parseList(param.substring(1, param.length - 1))));
|
|
1517
|
+
} else {
|
|
1518
|
+
query.entries.push(parseFilterField(param));
|
|
1519
|
+
}
|
|
1520
|
+
return query;
|
|
1521
|
+
}
|
|
1522
|
+
function parseList(param) {
|
|
1523
|
+
if (param.includes('[')) {
|
|
1524
|
+
return param.split(/(?<=]),|,(?=\+?\[)/g).flatMap(function (s) {
|
|
1525
|
+
//split at every comma, which is before or after a group
|
|
1526
|
+
if (s.startsWith('+[')) {
|
|
1527
|
+
return parseOrGroup(s);
|
|
1528
|
+
} else if (s.startsWith('[')) {
|
|
1529
|
+
return parseFieldList(s.substring(1, s.length - 1));
|
|
1530
|
+
} else {
|
|
1531
|
+
return parseFieldList(s);
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1534
|
+
} else {
|
|
1535
|
+
return parseFieldList(param);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
function parseFieldList(param) {
|
|
1539
|
+
return param.split(/(?<=}),/g) //split at every comma, which is between curly brackets (get Filterfields)
|
|
1540
|
+
.map(parseFilterField);
|
|
1541
|
+
}
|
|
1542
|
+
function parseOrGroup(group) {
|
|
1543
|
+
var filterGroup = {
|
|
1544
|
+
entries: [],
|
|
1545
|
+
or: true,
|
|
1546
|
+
type: 'group'
|
|
1547
|
+
};
|
|
1548
|
+
if (group.startsWith('+[') && group.endsWith(']')) {
|
|
1549
|
+
filterGroup.entries = parseFieldList(group.replace(/\+\[|\]/g, '')); //remove encloseing brackets
|
|
1550
|
+
return filterGroup;
|
|
1551
|
+
}
|
|
1552
|
+
throw new Error('Wrong format: Or groups have to be in the form of "+[{<field>,<op>,<value>},...]"');
|
|
1553
|
+
}
|
|
1554
|
+
function parseFilterField(filter) {
|
|
1555
|
+
if (filter.startsWith('{') && filter.endsWith('}')) {
|
|
1556
|
+
var split = filter.replace(/[{}]/g, '') // Remove curly braces
|
|
1557
|
+
.split(/,(?=(?:[^']*'[^']*')*[^']*$)/g); // Split on commas outside of single quotes
|
|
1558
|
+
// Explanation of the regex:
|
|
1559
|
+
// - , matches the comma.
|
|
1560
|
+
// - (?=...) is a positive lookahead to ensure the next condition is met.
|
|
1561
|
+
// - (?:[^']*'[^']*')* matches zero or more pairs of single-quoted sections (to ensure commas inside quotes are ignored).
|
|
1562
|
+
// - [^']*$ ensures that we are splitting only if the comma is outside any single-quoted sections (i.e., we are not inside quotes at the time of the split).
|
|
1563
|
+
|
|
1564
|
+
if (split.length >= 3 && split[1] == 'in') {
|
|
1565
|
+
return {
|
|
1566
|
+
field: split[0],
|
|
1567
|
+
operator: split[1],
|
|
1568
|
+
value: split.slice(2).map(parseFieldValue)
|
|
1569
|
+
};
|
|
1570
|
+
} else if (split.length == 3) {
|
|
1571
|
+
var field = {
|
|
1572
|
+
field: split[0],
|
|
1573
|
+
operator: split[1],
|
|
1574
|
+
value: parseFieldValue(split[2])
|
|
1575
|
+
};
|
|
1576
|
+
return field;
|
|
1577
|
+
} else if (split.length == 2 && ['isnotnull', 'isnull', 'isnotempty', 'isempty'].includes(split[1])) {
|
|
1578
|
+
var _field = {
|
|
1579
|
+
field: split[0],
|
|
1580
|
+
operator: split[1]
|
|
1581
|
+
};
|
|
1582
|
+
return _field;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
throw new Error('Wrong format: Filter fields have to be in the form of "{<field>,<op>,<value>}"');
|
|
1586
|
+
}
|
|
1587
|
+
function parseFieldValue(value) {
|
|
1588
|
+
if (value == 'true' || value == 'false') {
|
|
1589
|
+
return value === 'true' ? true : false;
|
|
1590
|
+
}
|
|
1591
|
+
if (!isNaN(value)) {
|
|
1592
|
+
return Number(value);
|
|
1593
|
+
}
|
|
1594
|
+
if (value.startsWith("'") && value.endsWith("'") || value.startsWith('"') && value.endsWith('"')) {
|
|
1595
|
+
return value.substring(1, value.length - 1);
|
|
1596
|
+
}
|
|
1597
|
+
return value;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
export { DivaError, UTMUtils, UtmCampaign, UtmContent, UtmMedium, UtmSource, DivaUtils$1 as default, md5, nanoid, parseFilterParam };
|
|
@@ -9,6 +9,8 @@ export * from './utils/nanoid';
|
|
|
9
9
|
export { DivaError };
|
|
10
10
|
export * from './utils/UTMUtils';
|
|
11
11
|
export * from './utils/UTMUtils/types';
|
|
12
|
+
export * from './utils/parseFilterParam';
|
|
12
13
|
export type { EventAction, EventModule, PriceFormat, ApplicationLoggerInterface, PfisterEventAction };
|
|
14
|
+
export type { Query, FilterQuery, FilterField, FilterGroup, Sort, Facets, QueryResult } from './types/FilterParamTypes';
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
14
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,eAAe,SAAS,CAAC;AAEzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,eAAe,SAAS,CAAC;AAEzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,CAAC;AACtG,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface Query {
|
|
2
|
+
/**
|
|
3
|
+
* Limits the number of returned documents
|
|
4
|
+
* */
|
|
5
|
+
limit?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Skips a defined number of documents, used mainly for paging
|
|
8
|
+
* */
|
|
9
|
+
skip?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Defines the sort order of the returned documents
|
|
12
|
+
*/
|
|
13
|
+
sort?: Sort[];
|
|
14
|
+
/**
|
|
15
|
+
* Used to return only some fields of the result documents.
|
|
16
|
+
*/
|
|
17
|
+
fields?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Used to filter the returned documents.
|
|
20
|
+
*/
|
|
21
|
+
filter?: FilterQuery;
|
|
22
|
+
/**
|
|
23
|
+
* Used to filter the returned documents, with the faster search index
|
|
24
|
+
*/
|
|
25
|
+
search?: FilterQuery;
|
|
26
|
+
queryParams?: {
|
|
27
|
+
[key: string]: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export type Operator = 'eq' | 'ne' | 'isnull' | 'isnotnull' | 'lt' | 'lte' | 'gt' | 'gte' | 'startswith' | 'endswith' | 'contains' | 'doesnotcontain' | 'isempty' | 'isnotempty' | 'in' | 'nin' | 'exists' | 'notexists' | 'custom';
|
|
31
|
+
export interface FilterField {
|
|
32
|
+
type?: 'field';
|
|
33
|
+
field: string;
|
|
34
|
+
operator: Operator;
|
|
35
|
+
value?: number | string | boolean | string[] | object;
|
|
36
|
+
}
|
|
37
|
+
export interface FilterGroup {
|
|
38
|
+
type: 'group';
|
|
39
|
+
entries: FilterField[];
|
|
40
|
+
or?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface FilterQuery {
|
|
43
|
+
entries: (FilterField | FilterGroup)[];
|
|
44
|
+
}
|
|
45
|
+
export interface Sort {
|
|
46
|
+
field: string;
|
|
47
|
+
desc?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface Facets {
|
|
50
|
+
[key: string]: {
|
|
51
|
+
type: 'string' | 'number' | 'date';
|
|
52
|
+
path: string;
|
|
53
|
+
boundaries?: number[];
|
|
54
|
+
default?: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface QueryResult<T> {
|
|
58
|
+
data: Partial<T>[];
|
|
59
|
+
total: number;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=FilterParamTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilterParamTypes.d.ts","sourceRoot":"","sources":["../../../../../src/types/FilterParamTypes.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB;;UAEM;IACN,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;SAEK;IACL,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB,WAAW,CAAC,EAAE;QAAE,CAAC,GAA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
+
{"version":3,"file":"parseFilterParam.d.ts","sourceRoot":"","sources":["../../../../../src/utils/parseFilterParam.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA4B,MAAM,2BAA2B,CAAC;AAElF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAS3D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crystaldesign/diva-utils",
|
|
3
|
-
"version": "26.2.0-beta.
|
|
3
|
+
"version": "26.2.0-beta.30",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"module": "build/esm/index.js",
|
|
25
25
|
"types": "./build/types/utils/src/index.d.ts",
|
|
26
26
|
"main": "build/cjs/index.js",
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "a316fda1fce1b951ec9a6b07bf99715b042f270b"
|
|
28
28
|
}
|