@omni-graph/omni-model 0.6.107 → 0.6.108
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/functions/billing/index.d.ts +2 -0
- package/dist/functions/billing/index.d.ts.map +1 -0
- package/dist/functions/billing/index.js +2 -0
- package/dist/functions/billing/index.js.map +1 -0
- package/dist/functions/filtering/baseHandler.d.ts +9 -0
- package/dist/functions/filtering/baseHandler.d.ts.map +1 -0
- package/dist/functions/filtering/baseHandler.js +12 -0
- package/dist/functions/filtering/baseHandler.js.map +1 -0
- package/dist/functions/filtering/booleanHandler.d.ts +16 -0
- package/dist/functions/filtering/booleanHandler.d.ts.map +1 -0
- package/dist/functions/filtering/booleanHandler.js +39 -0
- package/dist/functions/filtering/booleanHandler.js.map +1 -0
- package/dist/functions/filtering/dateHandler.d.ts +21 -0
- package/dist/functions/filtering/dateHandler.d.ts.map +1 -0
- package/dist/functions/filtering/dateHandler.js +67 -0
- package/dist/functions/filtering/dateHandler.js.map +1 -0
- package/dist/functions/filtering/dateRangeHandler.d.ts +14 -0
- package/dist/functions/filtering/dateRangeHandler.d.ts.map +1 -0
- package/dist/functions/filtering/dateRangeHandler.js +44 -0
- package/dist/functions/filtering/dateRangeHandler.js.map +1 -0
- package/dist/functions/filtering/filterPredicate.d.ts +2 -0
- package/dist/functions/filtering/filterPredicate.d.ts.map +1 -0
- package/dist/functions/filtering/filterPredicate.js +2 -0
- package/dist/functions/filtering/filterPredicate.js.map +1 -0
- package/dist/functions/filtering/generalFilterArgs.d.ts +6 -0
- package/dist/functions/filtering/generalFilterArgs.d.ts.map +1 -0
- package/dist/functions/filtering/generalFilterArgs.js +2 -0
- package/dist/functions/filtering/generalFilterArgs.js.map +1 -0
- package/dist/functions/filtering/handler.d.ts +8 -0
- package/dist/functions/filtering/handler.d.ts.map +1 -0
- package/dist/functions/filtering/handler.js +2 -0
- package/dist/functions/filtering/handler.js.map +1 -0
- package/dist/functions/filtering/index.d.ts +10 -0
- package/dist/functions/filtering/index.d.ts.map +1 -0
- package/dist/functions/filtering/index.js +2 -0
- package/dist/functions/filtering/index.js.map +1 -0
- package/dist/functions/filtering/multiSelectHandler.d.ts +14 -0
- package/dist/functions/filtering/multiSelectHandler.d.ts.map +1 -0
- package/dist/functions/filtering/multiSelectHandler.js +46 -0
- package/dist/functions/filtering/multiSelectHandler.js.map +1 -0
- package/dist/functions/filtering/numberHandler.d.ts +20 -0
- package/dist/functions/filtering/numberHandler.d.ts.map +1 -0
- package/dist/functions/filtering/numberHandler.js +48 -0
- package/dist/functions/filtering/numberHandler.js.map +1 -0
- package/dist/functions/filtering/numberRangeHandler.d.ts +13 -0
- package/dist/functions/filtering/numberRangeHandler.d.ts.map +1 -0
- package/dist/functions/filtering/numberRangeHandler.js +25 -0
- package/dist/functions/filtering/numberRangeHandler.js.map +1 -0
- package/dist/functions/filtering/queryFilters.d.ts +85 -0
- package/dist/functions/filtering/queryFilters.d.ts.map +1 -0
- package/dist/functions/filtering/queryFilters.js +172 -0
- package/dist/functions/filtering/queryFilters.js.map +1 -0
- package/dist/functions/filtering/textHandler.d.ts +20 -0
- package/dist/functions/filtering/textHandler.d.ts.map +1 -0
- package/dist/functions/filtering/textHandler.js +40 -0
- package/dist/functions/filtering/textHandler.js.map +1 -0
- package/dist/functions/filtering/utils.d.ts +12 -0
- package/dist/functions/filtering/utils.d.ts.map +1 -0
- package/dist/functions/filtering/utils.js +97 -0
- package/dist/functions/filtering/utils.js.map +1 -0
- package/dist/functions/index.d.ts +2 -1
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js +2 -1
- package/dist/functions/index.js.map +1 -1
- package/dist/zod/filtering/columnFilterItem.d.ts +13 -0
- package/dist/zod/filtering/columnFilterItem.d.ts.map +1 -0
- package/dist/zod/filtering/columnFilterItem.js +8 -0
- package/dist/zod/filtering/columnFilterItem.js.map +1 -0
- package/dist/zod/filtering/index.d.ts +3 -0
- package/dist/zod/filtering/index.d.ts.map +1 -0
- package/dist/zod/filtering/index.js +3 -0
- package/dist/zod/filtering/index.js.map +1 -0
- package/dist/zod/filtering/relativeDateFiltering.d.ts +35 -0
- package/dist/zod/filtering/relativeDateFiltering.d.ts.map +1 -0
- package/dist/zod/filtering/relativeDateFiltering.js +16 -0
- package/dist/zod/filtering/relativeDateFiltering.js.map +1 -0
- package/dist/zod/index.d.ts +1 -0
- package/dist/zod/index.d.ts.map +1 -1
- package/dist/zod/index.js +1 -0
- package/dist/zod/index.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Row } from '@tanstack/react-table';
|
|
2
|
+
import { RuleGroupType, RuleType } from 'react-querybuilder';
|
|
3
|
+
import { GeneralFilterArgs } from "./generalFilterArgs";
|
|
4
|
+
import { FilterPredicate } from "./filterPredicate";
|
|
5
|
+
/** ---------- Public factories ---------- */
|
|
6
|
+
/**
|
|
7
|
+
* Builds a predicate for a single cell given a filter config.
|
|
8
|
+
* Throws for unknown variant or irrelevant operators.
|
|
9
|
+
*/
|
|
10
|
+
export declare const createFilterPredicate: (args: GeneralFilterArgs) => FilterPredicate;
|
|
11
|
+
/**
|
|
12
|
+
* A type for defining a function that determines whether a specific row of data
|
|
13
|
+
* meets the conditions defined by a filter.
|
|
14
|
+
*
|
|
15
|
+
* @template TData - The type of data represented in the row.
|
|
16
|
+
* @param {Row<TData>} row - The row of data being evaluated.
|
|
17
|
+
* @param {string} columnId - The identifier for the column being filtered.
|
|
18
|
+
* @param {string} filterJson - The value to filter against serialized as JSON.
|
|
19
|
+
* @returns {boolean} - Returns true if the row matches the filter condition, otherwise false.
|
|
20
|
+
*/
|
|
21
|
+
export type GenericColumnFilterFunction<TData> = (row: Row<TData>, columnId: string, filterJson: string) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Factory function that creates a filter function to be applied to data rows.
|
|
24
|
+
* The generated filter function evaluates a row against a given filter condition
|
|
25
|
+
* and returns a boolean indicating whether the row satisfies the filter criteria
|
|
26
|
+
* for the specified column.
|
|
27
|
+
*
|
|
28
|
+
* The filter function is constructed dynamically based on the provided filter
|
|
29
|
+
* definition, which includes an operator, variant, and filter value. The filter
|
|
30
|
+
* value is serialized and deserialized as JSON to ensure proper handling of
|
|
31
|
+
* complex data structures.
|
|
32
|
+
*
|
|
33
|
+
* @template TData - The type of the data row objects.
|
|
34
|
+
* @returns {GenericColumnFilterFunction<TData>} A filter function that takes a row, column ID, and filter value, and returns a boolean.
|
|
35
|
+
*/
|
|
36
|
+
export declare const genericColumnFilter: <TData>() => GenericColumnFilterFunction<TData>;
|
|
37
|
+
/**
|
|
38
|
+
* A generic filter function type used to evaluate whether a given row of data satisfies
|
|
39
|
+
* a specified filter condition. This function is commonly used in tables or data grids
|
|
40
|
+
* to implement filtering logic.
|
|
41
|
+
*
|
|
42
|
+
* @template TData - The type of the row data being filtered.
|
|
43
|
+
* @param {TData} row - The data object or row being evaluated against the filter condition.
|
|
44
|
+
* @param {string} columnId - The identifier for the column being filtered.
|
|
45
|
+
* @param {string} filterValue - The value to compare against the specified column of the row data.
|
|
46
|
+
* @returns {boolean} Returns true if the row satisfies the filter condition, otherwise false.
|
|
47
|
+
*/
|
|
48
|
+
type genericFilterFunction<TData> = (row: TData, filterValue: RuleType) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* A higher-order function that creates a generic filter function.
|
|
51
|
+
*
|
|
52
|
+
* @template TData
|
|
53
|
+
* @returns {genericFilterFunction<TData>} A function that takes a data row and a filter schema,
|
|
54
|
+
* and evaluates whether the row matches the filter criteria.
|
|
55
|
+
*
|
|
56
|
+
* The returned function takes two arguments:
|
|
57
|
+
* - `row` (TData): The data row to be evaluated.
|
|
58
|
+
* - `filter` (FilterItemSchema): Defines the filtering criteria, including the operator and value to filter by.
|
|
59
|
+
*
|
|
60
|
+
* Internally, the function determines the variant based on the row and operator, creates a filter
|
|
61
|
+
* predicate using the specified operator and value, and applies the predicate on the row to determine
|
|
62
|
+
* whether it satisfies the filter.
|
|
63
|
+
*/
|
|
64
|
+
export declare const genericFilter: <TData>() => genericFilterFunction<TData>;
|
|
65
|
+
/**
|
|
66
|
+
* A type definition for a generic function that processes a row of data and determines
|
|
67
|
+
* whether it satisfies the conditions specified in a filter group.
|
|
68
|
+
*
|
|
69
|
+
* @callback genericFilterGroupFunction
|
|
70
|
+
* @template TData - The type of the data row being evaluated.
|
|
71
|
+
* @param {TData} row - The data row to evaluate against the filter group.
|
|
72
|
+
* @param {RuleGroupType} filter - The object representing the group of filtering rules. (React Query Builder format)
|
|
73
|
+
* @returns {boolean} A boolean indicating whether the data row satisfies the filter group.
|
|
74
|
+
*/
|
|
75
|
+
type genericFilterGroupFunction<TData> = (row: TData, filter: RuleGroupType) => boolean;
|
|
76
|
+
/**
|
|
77
|
+
* A generic filter group function that applies a set of filtering rules to a given data row.
|
|
78
|
+
* This function evaluates the rules based on the combinator provided ('and' or 'or') and applies the corresponding logical operation.
|
|
79
|
+
*
|
|
80
|
+
* @template TData The type of the data to which filtering rules will be applied.
|
|
81
|
+
* @returns {genericFilterGroupFunction<TData>} A function that evaluates a row against the given filter rules.
|
|
82
|
+
*/
|
|
83
|
+
export declare const genericFilterGroup: <TData>() => genericFilterGroupFunction<TData>;
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=queryFilters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryFilters.d.ts","sourceRoot":"","sources":["../../../src/functions/filtering/queryFilters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAA8B,aAAa,EAAE,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAGxF,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAoElD,6CAA6C;AAE7C;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,MAAM,iBAAiB,KAAG,eAI/D,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,2BAA2B,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;AAEpH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,GACvB,KAAK,OAAK,2BAA2B,CAAC,KAAK,CAUnC,CAAC;AAElB;;;;;;;;;;GAUG;AACH,KAAK,qBAAqB,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,KAAK,OAAO,CAAC;AAuCnF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GACjB,KAAK,OAAK,qBAAqB,CAAC,KAAK,CAU7B,CAAC;AAElB;;;;;;;;;GASG;AACH,KAAK,0BAA0B,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;AAExF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GACtB,KAAK,OAAK,0BAA0B,CAAC,KAAK,CAIlC,CAAC"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { isRuleGroupType, isRuleType } from 'react-querybuilder';
|
|
2
|
+
import { TextHandler } from "./textHandler";
|
|
3
|
+
import { NumberHandler } from "./numberHandler";
|
|
4
|
+
import { NumberRangeHandler } from "./numberRangeHandler";
|
|
5
|
+
import { DateRangeHandler } from "./dateRangeHandler";
|
|
6
|
+
import { BooleanHandler } from "./booleanHandler";
|
|
7
|
+
import { MultiSelectHandler } from "./multiSelectHandler";
|
|
8
|
+
import { DateHandler } from "./dateHandler";
|
|
9
|
+
import { DateTime } from "luxon";
|
|
10
|
+
/** ---------- Group Compilation ---------- */
|
|
11
|
+
const compileOrFilters = (filters) => {
|
|
12
|
+
const predicateBuilder = genericFilter();
|
|
13
|
+
return (row) => {
|
|
14
|
+
for (const filter of filters) {
|
|
15
|
+
if (isRuleType(filter)) {
|
|
16
|
+
const current = predicateBuilder(row, filter);
|
|
17
|
+
if (current)
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (isRuleGroupType(filter)) {
|
|
21
|
+
const current = genericFilterGroup()(row, filter);
|
|
22
|
+
if (current)
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const compileAndFilters = (filters) => {
|
|
30
|
+
const predicateBuilder = genericFilter();
|
|
31
|
+
return (row) => {
|
|
32
|
+
for (const filter of filters) {
|
|
33
|
+
if (isRuleType(filter)) {
|
|
34
|
+
const current = predicateBuilder(row, filter);
|
|
35
|
+
if (!current)
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (isRuleGroupType(filter)) {
|
|
39
|
+
const current = genericFilterGroup()(row, filter);
|
|
40
|
+
if (!current)
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/** ---------- Handler Chain ---------- */
|
|
48
|
+
const buildChain = () => {
|
|
49
|
+
const handlers = [
|
|
50
|
+
new TextHandler(),
|
|
51
|
+
new NumberHandler(),
|
|
52
|
+
new NumberRangeHandler(),
|
|
53
|
+
new DateHandler(),
|
|
54
|
+
new DateRangeHandler(),
|
|
55
|
+
new BooleanHandler(),
|
|
56
|
+
new MultiSelectHandler(),
|
|
57
|
+
];
|
|
58
|
+
const firstHandler = handlers.pop();
|
|
59
|
+
if (!firstHandler)
|
|
60
|
+
throw new Error('No handlers defined');
|
|
61
|
+
return handlers.reduce((prev, curr) => curr.setNext(prev), firstHandler);
|
|
62
|
+
};
|
|
63
|
+
// Actual handler chain to be used by the public factory functions
|
|
64
|
+
const handlerChain = buildChain();
|
|
65
|
+
/** ---------- Public factories ---------- */
|
|
66
|
+
/**
|
|
67
|
+
* Builds a predicate for a single cell given a filter config.
|
|
68
|
+
* Throws for unknown variant or irrelevant operators.
|
|
69
|
+
*/
|
|
70
|
+
export const createFilterPredicate = (args) => {
|
|
71
|
+
const pred = handlerChain.handle(args);
|
|
72
|
+
if (!pred)
|
|
73
|
+
throw new Error('No applicable filter handler');
|
|
74
|
+
return pred;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Factory function that creates a filter function to be applied to data rows.
|
|
78
|
+
* The generated filter function evaluates a row against a given filter condition
|
|
79
|
+
* and returns a boolean indicating whether the row satisfies the filter criteria
|
|
80
|
+
* for the specified column.
|
|
81
|
+
*
|
|
82
|
+
* The filter function is constructed dynamically based on the provided filter
|
|
83
|
+
* definition, which includes an operator, variant, and filter value. The filter
|
|
84
|
+
* value is serialized and deserialized as JSON to ensure proper handling of
|
|
85
|
+
* complex data structures.
|
|
86
|
+
*
|
|
87
|
+
* @template TData - The type of the data row objects.
|
|
88
|
+
* @returns {GenericColumnFilterFunction<TData>} A filter function that takes a row, column ID, and filter value, and returns a boolean.
|
|
89
|
+
*/
|
|
90
|
+
export const genericColumnFilter = () => (row, columnId, filterValue) => {
|
|
91
|
+
const columnFilter = JSON.parse(filterValue);
|
|
92
|
+
const value = getField(row, columnId);
|
|
93
|
+
const predicate = createFilterPredicate({
|
|
94
|
+
operator: columnFilter.operator,
|
|
95
|
+
variant: getVariant(value, columnFilter.operator, columnFilter.value),
|
|
96
|
+
valueJson: JSON.stringify(columnFilter.value),
|
|
97
|
+
});
|
|
98
|
+
return predicate(value);
|
|
99
|
+
};
|
|
100
|
+
const getSelectVariant = (filterValue) => {
|
|
101
|
+
if (Array.isArray(filterValue))
|
|
102
|
+
return 'multiSelect';
|
|
103
|
+
if (typeof filterValue === 'string')
|
|
104
|
+
return 'multiSelect';
|
|
105
|
+
if (filterValue == null)
|
|
106
|
+
return 'multiSelect';
|
|
107
|
+
throw new Error(`Unsupported operator "in" for filter-value "${JSON.stringify(filterValue)}"`);
|
|
108
|
+
};
|
|
109
|
+
const getRangeVariant = (value) => {
|
|
110
|
+
if (value.every((v) => typeof v === 'number'))
|
|
111
|
+
return 'range';
|
|
112
|
+
if (value.every((v) => typeof v === 'string' || v instanceof Date))
|
|
113
|
+
return 'dateRange';
|
|
114
|
+
throw new Error(`Unsupported range variant for value "${JSON.stringify(value)}"`);
|
|
115
|
+
};
|
|
116
|
+
const getVariant = (value, operator, filterValue) => {
|
|
117
|
+
if (["in", "notIn"].includes(operator)) {
|
|
118
|
+
return getSelectVariant(filterValue);
|
|
119
|
+
}
|
|
120
|
+
if (Array.isArray(value) && value.length == 2) {
|
|
121
|
+
return getRangeVariant(value);
|
|
122
|
+
}
|
|
123
|
+
if (value instanceof Date || value instanceof DateTime)
|
|
124
|
+
return 'date';
|
|
125
|
+
if (typeof value === 'boolean')
|
|
126
|
+
return 'boolean';
|
|
127
|
+
if (typeof value === 'number')
|
|
128
|
+
return 'number';
|
|
129
|
+
return "text";
|
|
130
|
+
};
|
|
131
|
+
const getField = (row, columnId) => {
|
|
132
|
+
if (row && typeof row === 'object' && columnId in row) {
|
|
133
|
+
return row[columnId];
|
|
134
|
+
}
|
|
135
|
+
return undefined;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* A higher-order function that creates a generic filter function.
|
|
139
|
+
*
|
|
140
|
+
* @template TData
|
|
141
|
+
* @returns {genericFilterFunction<TData>} A function that takes a data row and a filter schema,
|
|
142
|
+
* and evaluates whether the row matches the filter criteria.
|
|
143
|
+
*
|
|
144
|
+
* The returned function takes two arguments:
|
|
145
|
+
* - `row` (TData): The data row to be evaluated.
|
|
146
|
+
* - `filter` (FilterItemSchema): Defines the filtering criteria, including the operator and value to filter by.
|
|
147
|
+
*
|
|
148
|
+
* Internally, the function determines the variant based on the row and operator, creates a filter
|
|
149
|
+
* predicate using the specified operator and value, and applies the predicate on the row to determine
|
|
150
|
+
* whether it satisfies the filter.
|
|
151
|
+
*/
|
|
152
|
+
export const genericFilter = () => (row, filter) => {
|
|
153
|
+
const value = getField(row, filter.field);
|
|
154
|
+
const predicate = createFilterPredicate({
|
|
155
|
+
operator: filter.operator,
|
|
156
|
+
variant: getVariant(value, filter.operator, filter.value),
|
|
157
|
+
valueJson: JSON.stringify(filter.value),
|
|
158
|
+
});
|
|
159
|
+
return predicate(value);
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* A generic filter group function that applies a set of filtering rules to a given data row.
|
|
163
|
+
* This function evaluates the rules based on the combinator provided ('and' or 'or') and applies the corresponding logical operation.
|
|
164
|
+
*
|
|
165
|
+
* @template TData The type of the data to which filtering rules will be applied.
|
|
166
|
+
* @returns {genericFilterGroupFunction<TData>} A function that evaluates a row against the given filter rules.
|
|
167
|
+
*/
|
|
168
|
+
export const genericFilterGroup = () => (row, filter) => {
|
|
169
|
+
const predicate = filter.combinator === 'and' ? compileAndFilters(filter.rules) : compileOrFilters(filter.rules);
|
|
170
|
+
return predicate(row);
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=queryFilters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queryFilters.js","sourceRoot":"","sources":["../../../src/functions/filtering/queryFilters.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAE,UAAU,EAA0B,MAAM,oBAAoB,CAAC;AAKxF,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAC,QAAQ,EAA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AM,CAAC,MAAM,kBAAkB,GACvB,GAA6C,EAAE,CACvC,CAAC,GAAU,EAAE,MAAqB,EAAE,EAAE;IACpC,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAQ,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAQ,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/H,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { GeneralFilterArgs } from "./generalFilterArgs";
|
|
3
|
+
import { FilterPredicate } from "./filterPredicate";
|
|
4
|
+
import { BaseHandler } from "./baseHandler";
|
|
5
|
+
declare const TextOperators: z.ZodEnum<{
|
|
6
|
+
"=": "=";
|
|
7
|
+
"!=": "!=";
|
|
8
|
+
isEmpty: "isEmpty";
|
|
9
|
+
isNotEmpty: "isNotEmpty";
|
|
10
|
+
beginsWith: "beginsWith";
|
|
11
|
+
endsWith: "endsWith";
|
|
12
|
+
contains: "contains";
|
|
13
|
+
doesNotContain: "doesNotContain";
|
|
14
|
+
}>;
|
|
15
|
+
export type TextOperator = z.infer<typeof TextOperators>;
|
|
16
|
+
export declare class TextHandler extends BaseHandler {
|
|
17
|
+
handle({ variant, operator, valueJson }: GeneralFilterArgs): FilterPredicate | null;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=textHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textHandler.d.ts","sourceRoot":"","sources":["../../../src/functions/filtering/textHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C,QAAA,MAAM,aAAa;;;;;;;;;EAOF,CAAC;AAClB,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEzD,qBAAa,WAAY,SAAQ,WAAW;IACjC,MAAM,CAAC,EAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAC,EAAE,iBAAiB,GAAG,eAAe,GAAG,IAAI;CA2B3F"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { normalizeStr, parseJSONValue } from "./utils";
|
|
3
|
+
import { BaseHandler } from "./baseHandler";
|
|
4
|
+
const TextOperators = z.enum(['beginsWith',
|
|
5
|
+
'endsWith',
|
|
6
|
+
'=',
|
|
7
|
+
'!=',
|
|
8
|
+
'contains',
|
|
9
|
+
'doesNotContain',
|
|
10
|
+
'isEmpty',
|
|
11
|
+
'isNotEmpty',]);
|
|
12
|
+
export class TextHandler extends BaseHandler {
|
|
13
|
+
handle({ variant, operator, valueJson }) {
|
|
14
|
+
if (variant !== 'text')
|
|
15
|
+
return super.handle({ variant, operator, valueJson });
|
|
16
|
+
TextOperators.parse(operator);
|
|
17
|
+
const raw = parseJSONValue(valueJson);
|
|
18
|
+
const needle = Array.isArray(raw) ? raw.join(' ') : String(raw);
|
|
19
|
+
switch (operator) {
|
|
20
|
+
case 'beginsWith':
|
|
21
|
+
return (cell) => normalizeStr(cell).toLowerCase().startsWith(needle.toLowerCase());
|
|
22
|
+
case 'endsWith':
|
|
23
|
+
return (cell) => normalizeStr(cell).toLowerCase().endsWith(needle.toLowerCase());
|
|
24
|
+
case '=':
|
|
25
|
+
return (cell) => normalizeStr(cell) === needle;
|
|
26
|
+
case '!=':
|
|
27
|
+
return (cell) => normalizeStr(cell) !== needle;
|
|
28
|
+
case 'contains':
|
|
29
|
+
return (cell) => normalizeStr(cell).toLowerCase().includes(needle.toLowerCase());
|
|
30
|
+
case 'doesNotContain':
|
|
31
|
+
return (cell) => !normalizeStr(cell).toLowerCase().includes(needle.toLowerCase());
|
|
32
|
+
case 'isEmpty':
|
|
33
|
+
return (cell) => normalizeStr(cell) === '';
|
|
34
|
+
case 'isNotEmpty':
|
|
35
|
+
return (cell) => normalizeStr(cell) !== '';
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Unsupported text operator "${operator}"`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=textHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textHandler.js","sourceRoot":"","sources":["../../../src/functions/filtering/textHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,OAAO,EAAC,YAAY,EAAE,cAAc,EAAC,MAAM,SAAS,CAAC;AACrD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY;IACxC,UAAU;IACV,GAAG;IACH,IAAI;IACJ,UAAU;IACV,gBAAgB;IAChB,SAAS;IACT,YAAY,EAAE,CAAC,CAAC;AAGlB,MAAM,OAAO,WAAY,SAAQ,WAAW;IACjC,MAAM,CAAC,EAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAoB;QAC/D,IAAI,OAAO,KAAK,MAAM;YAAE,OAAO,KAAK,CAAC,MAAM,CAAC,EAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAC,CAAC,CAAC;QAC5E,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAE9B,MAAM,GAAG,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAA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1
|
+
import { RelativeDateRangeSchema, RelativeDateSchema } from "../../zod";
|
|
2
|
+
export declare const parseJSONValue: (json: string) => boolean | number | string | string[] | number[];
|
|
3
|
+
export declare const toNumber: (x: unknown) => number | null;
|
|
4
|
+
export declare const toDate: (x: unknown) => Date | null;
|
|
5
|
+
export declare const normalizeStr: (x: unknown) => string;
|
|
6
|
+
/** ---------- Date helpers ---------- */
|
|
7
|
+
export declare const startOfDay: (d: Date) => Date;
|
|
8
|
+
export declare const endOfDay: (d: Date) => Date;
|
|
9
|
+
export declare const compareDateOnly: (a: Date | null, b: Date | null) => number;
|
|
10
|
+
export declare const parseRelative: (json: string) => RelativeDateSchema | RelativeDateRangeSchema;
|
|
11
|
+
export declare const addDays: (d: Date, days: number) => Date;
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/functions/filtering/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,uBAAuB,EAAE,kBAAkB,EAAgD,MAAM,WAAW,CAAC;AAErH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAQ1F,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,GAAG,OAAO,KAAG,MAAM,GAAG,IAI9C,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,GAAG,OAAO,KAAG,IAAI,GAAG,IAe1C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,GAAG,OAAO,KAAG,MAOzC,CAAC;AAGF,yCAAyC;AACzC,eAAO,MAAM,UAAU,GAAI,GAAG,IAAI,KAAG,IAIpC,CAAC;AACF,eAAO,MAAM,QAAQ,GAAI,GAAG,IAAI,KAAG,IAIlC,CAAC;AACF,eAAO,MAAM,eAAe,GAAI,GAAG,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,KAAG,MAQhE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,kBAAkB,GAAG,uBAajE,CAAC;AAEF,eAAO,MAAM,OAAO,GAAI,GAAG,IAAI,EAAE,MAAM,MAAM,SAI5C,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
import { zRelativeDateRangeSchema, zRelativeDateSchema } from "../../zod";
|
|
3
|
+
export const parseJSONValue = (json) => {
|
|
4
|
+
const v = JSON.parse(json);
|
|
5
|
+
if (typeof v === 'string')
|
|
6
|
+
return v;
|
|
7
|
+
if (typeof v === 'boolean')
|
|
8
|
+
return v;
|
|
9
|
+
if (typeof v === 'number')
|
|
10
|
+
return v;
|
|
11
|
+
if (Array.isArray(v) && v.every((x) => typeof x === 'string'))
|
|
12
|
+
return v;
|
|
13
|
+
if (Array.isArray(v) && v.every((x) => typeof x === 'number'))
|
|
14
|
+
return v;
|
|
15
|
+
throw new Error('Invalid type for filter value');
|
|
16
|
+
};
|
|
17
|
+
export const toNumber = (x) => {
|
|
18
|
+
if (x == null || x === '')
|
|
19
|
+
return null;
|
|
20
|
+
const n = Number(x);
|
|
21
|
+
return Number.isFinite(n) ? n : null;
|
|
22
|
+
};
|
|
23
|
+
export const toDate = (x) => {
|
|
24
|
+
if (x == null || x === '')
|
|
25
|
+
return null;
|
|
26
|
+
// Accept Date, epoch number, Luxon, or ISO-like string
|
|
27
|
+
if (x instanceof Date && !Number.isNaN(x.getTime()))
|
|
28
|
+
return x;
|
|
29
|
+
if (x instanceof DateTime && !Number.isNaN(x.toJSDate().getTime()))
|
|
30
|
+
return x.toJSDate();
|
|
31
|
+
const n = Number(x);
|
|
32
|
+
if (Number.isFinite(n)) {
|
|
33
|
+
const d = new Date(n);
|
|
34
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
35
|
+
}
|
|
36
|
+
if (typeof x === 'string') {
|
|
37
|
+
const d = new Date(String(x));
|
|
38
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
39
|
+
}
|
|
40
|
+
throw new Error('Invalid date value');
|
|
41
|
+
};
|
|
42
|
+
export const normalizeStr = (x) => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
if (x == null || x === '')
|
|
45
|
+
return '';
|
|
46
|
+
if (typeof x === 'object' && x !== null)
|
|
47
|
+
return JSON.stringify(x);
|
|
48
|
+
if (typeof x === 'string')
|
|
49
|
+
return x.trim();
|
|
50
|
+
if (typeof x === 'number')
|
|
51
|
+
return String(x);
|
|
52
|
+
if (typeof x === 'boolean')
|
|
53
|
+
return String(x);
|
|
54
|
+
return (_b = (_a = JSON.stringify(x)) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
|
|
55
|
+
};
|
|
56
|
+
/** ---------- Date helpers ---------- */
|
|
57
|
+
export const startOfDay = (d) => {
|
|
58
|
+
const r = new Date(d);
|
|
59
|
+
r.setHours(0, 0, 0, 0);
|
|
60
|
+
return r;
|
|
61
|
+
};
|
|
62
|
+
export const endOfDay = (d) => {
|
|
63
|
+
const r = new Date(d);
|
|
64
|
+
r.setHours(23, 59, 59, 999);
|
|
65
|
+
return r;
|
|
66
|
+
};
|
|
67
|
+
export const compareDateOnly = (a, b) => {
|
|
68
|
+
if (!a && !b)
|
|
69
|
+
return 0;
|
|
70
|
+
if (!a)
|
|
71
|
+
return 1;
|
|
72
|
+
if (!b)
|
|
73
|
+
return -1;
|
|
74
|
+
const aa = startOfDay(a).getTime();
|
|
75
|
+
const bb = startOfDay(b).getTime();
|
|
76
|
+
if (aa === bb)
|
|
77
|
+
return 0;
|
|
78
|
+
return aa < bb ? -1 : 1;
|
|
79
|
+
};
|
|
80
|
+
export const parseRelative = (json) => {
|
|
81
|
+
const v = JSON.parse(json);
|
|
82
|
+
const asSingle = zRelativeDateSchema.safeParse(v);
|
|
83
|
+
if (asSingle.success) {
|
|
84
|
+
return asSingle.data;
|
|
85
|
+
}
|
|
86
|
+
const asRange = zRelativeDateRangeSchema.safeParse(v);
|
|
87
|
+
if (asRange.success) {
|
|
88
|
+
return asRange.data;
|
|
89
|
+
}
|
|
90
|
+
throw new Error('For "isRelativeToToday", value must be {"offsetDays":number,"compare":"lt|lte|gt|gte|eq|ne"} or {"startOffsetDays":number,"endOffsetDays":number}');
|
|
91
|
+
};
|
|
92
|
+
export const addDays = (d, days) => {
|
|
93
|
+
const copy = new Date(d);
|
|
94
|
+
copy.setDate(copy.getDate() + days);
|
|
95
|
+
return copy;
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/functions/filtering/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC/B,OAAO,EAA8C,wBAAwB,EAAE,mBAAmB,EAAC,MAAM,WAAW,CAAC;AAErH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAmD,EAAE;IAC9F,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACpC,IAAI,OAAO,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACpC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;QAAE,OAAO,CAAC,CAAC;IACxE,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;QAAE,OAAO,CAAC,CAA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AO,EAAE,IAAY,EAAE,EAAE;IAC/C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACpC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
package/dist/functions/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
declare const columnFilterItemSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
5
|
+
operator: z.ZodString;
|
|
6
|
+
filterId: z.ZodString;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
/**
|
|
9
|
+
* For use with MRT's ColumnFilterItem or Tanstack Table's ColumnFilterItem
|
|
10
|
+
*/
|
|
11
|
+
export type ColumnFilterItem = z.infer<typeof columnFilterItemSchema>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=columnFilterItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columnFilterItem.d.ts","sourceRoot":"","sources":["../../../src/zod/filtering/columnFilterItem.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,QAAA,MAAM,sBAAsB;;;;;iBAK1B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columnFilterItem.js","sourceRoot":"","sources":["../../../src/zod/filtering/columnFilterItem.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACjD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/zod/filtering/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/zod/filtering/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for defining a relative date. See `RelativeDateSchema`
|
|
4
|
+
*/
|
|
5
|
+
export declare const zRelativeDateSchema: z.ZodObject<{
|
|
6
|
+
offsetDays: z.ZodNumber;
|
|
7
|
+
compare: z.core.$ZodType<"=" | "!=" | "<" | "<=" | ">" | ">=" | "isEmpty" | "isNotEmpty", "=" | "!=" | "<" | "<=" | ">" | ">=" | "isEmpty" | "isNotEmpty", z.core.$ZodTypeInternals<"=" | "!=" | "<" | "<=" | ">" | ">=" | "isEmpty" | "isNotEmpty", "=" | "!=" | "<" | "<=" | ">" | ">=" | "isEmpty" | "isNotEmpty">>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
/**
|
|
10
|
+
* RelativeDateSchema defines the structure for representing a relative date configuration.
|
|
11
|
+
*
|
|
12
|
+
* This schema includes two properties:
|
|
13
|
+
* 1. offsetDays: A numeric value representing the amount of days to offset the relative date.
|
|
14
|
+
* 2. compare: A string value specifying the comparison operator, limited to a subset of DateOperator
|
|
15
|
+
* that excludes 'isBetween' and 'isRelativeToToday'.
|
|
16
|
+
*/
|
|
17
|
+
export type RelativeDateSchema = z.infer<typeof zRelativeDateSchema>;
|
|
18
|
+
/**
|
|
19
|
+
* Zod schema for defining a relative date range. See `RelativeDateRangeSchema`
|
|
20
|
+
*/
|
|
21
|
+
export declare const zRelativeDateRangeSchema: z.ZodObject<{
|
|
22
|
+
startOffsetDays: z.ZodNumber;
|
|
23
|
+
endOffsetDays: z.ZodNumber;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
/**
|
|
26
|
+
* Represents a schema for defining a relative date range.
|
|
27
|
+
*
|
|
28
|
+
* The schema includes the following properties:
|
|
29
|
+
* - `startOffsetDays`: A number indicating the offset in days from a reference point to specify the start of the date range.
|
|
30
|
+
* - `endOffsetDays`: A number indicating the offset in days from the same reference point to specify the end of the date range.
|
|
31
|
+
*
|
|
32
|
+
* This schema is used to represent a range of dates relative to a given point in time.
|
|
33
|
+
*/
|
|
34
|
+
export type RelativeDateRangeSchema = z.infer<typeof zRelativeDateRangeSchema>;
|
|
35
|
+
//# sourceMappingURL=relativeDateFiltering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relativeDateFiltering.d.ts","sourceRoot":"","sources":["../../../src/zod/filtering/relativeDateFiltering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;iBAG9B,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAGrE;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;iBAGnC,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for defining a relative date. See `RelativeDateSchema`
|
|
4
|
+
*/
|
|
5
|
+
export const zRelativeDateSchema = z.object({
|
|
6
|
+
offsetDays: z.number(),
|
|
7
|
+
compare: z.string()
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Zod schema for defining a relative date range. See `RelativeDateRangeSchema`
|
|
11
|
+
*/
|
|
12
|
+
export const zRelativeDateRangeSchema = z.object({
|
|
13
|
+
startOffsetDays: z.number(),
|
|
14
|
+
endOffsetDays: z.number()
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=relativeDateFiltering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relativeDateFiltering.js","sourceRoot":"","sources":["../../../src/zod/filtering/relativeDateFiltering.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAA4D;CAC9E,CAAC,CAAC;AAaH;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE;IAC3B,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;CAC1B,CAAC,CAAC"}
|
package/dist/zod/index.d.ts
CHANGED
package/dist/zod/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/zod/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/zod/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
package/dist/zod/index.js
CHANGED
package/dist/zod/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/zod/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/zod/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|