@react-querybuilder/datetime 8.20.1 → 8.21.0
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/README.md +9 -3
- package/dist/cjs/{getDatetimeRuleProcessorTanStackDB-CL79A1_x.js → getDatetimeRuleProcessorTanStackDB-CDEB9coD.js} +88 -218
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-CDEB9coD.js.map +1 -0
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-X6tZv7yV.js +2 -0
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-X6tZv7yV.js.map +1 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.development.d.ts +124 -260
- package/dist/cjs/react-querybuilder_datetime.cjs.development.date-fns.d.ts +50 -51
- package/dist/cjs/react-querybuilder_datetime.cjs.development.date-fns.js +3 -2
- package/dist/cjs/react-querybuilder_datetime.cjs.development.date-fns.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.development.dayjs.d.ts +50 -51
- package/dist/cjs/react-querybuilder_datetime.cjs.development.dayjs.js +53 -26
- package/dist/cjs/react-querybuilder_datetime.cjs.development.dayjs.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.development.js +11 -467
- package/dist/cjs/react-querybuilder_datetime.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.development.jsdate.d.ts +53 -54
- package/dist/cjs/react-querybuilder_datetime.cjs.development.jsdate.js +26 -144
- package/dist/cjs/react-querybuilder_datetime.cjs.development.jsdate.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.development.luxon.d.ts +50 -51
- package/dist/cjs/react-querybuilder_datetime.cjs.development.luxon.js +3 -2
- package/dist/cjs/react-querybuilder_datetime.cjs.development.luxon.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.development.ui.d.ts +214 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.development.ui.js +466 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.development.ui.js.map +1 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.production.d.ts +124 -260
- package/dist/cjs/react-querybuilder_datetime.cjs.production.date-fns.d.ts +50 -51
- package/dist/cjs/react-querybuilder_datetime.cjs.production.date-fns.js +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.date-fns.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.dayjs.d.ts +50 -51
- package/dist/cjs/react-querybuilder_datetime.cjs.production.dayjs.js +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.dayjs.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.js +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.jsdate.d.ts +53 -54
- package/dist/cjs/react-querybuilder_datetime.cjs.production.jsdate.js +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.jsdate.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.luxon.d.ts +50 -51
- package/dist/cjs/react-querybuilder_datetime.cjs.production.luxon.js +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.luxon.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.ui.d.ts +214 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.production.ui.js +2 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.production.ui.js.map +1 -0
- package/dist/cjs/rolldown-runtime-CMqjfN_6.js +1 -0
- package/dist/cjs/rolldown-runtime-D6vf50IK.js +28 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.jsdate-BuSiVdk7.js +2 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.jsdate-BuSiVdk7.js.map +1 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.jsdate-C3jJb6ip.js +128 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.jsdate-C3jJb6ip.js.map +1 -0
- package/dist/cjs/types-BKA1aoY6.d.ts +174 -0
- package/dist/cjs/ui.d.ts +1 -0
- package/dist/cjs/ui.js +6 -0
- package/dist/cjs/utils-DdBYGWHZ.js +2 -0
- package/dist/cjs/utils-DdBYGWHZ.js.map +1 -0
- package/dist/cjs/utils-_X97pUtk.js +166 -0
- package/dist/cjs/utils-_X97pUtk.js.map +1 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-6K1DsuEV.mjs +2 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-6K1DsuEV.mjs.map +1 -0
- package/dist/{getDatetimeRuleProcessorTanStackDB-BL8mbdbl.js → getDatetimeRuleProcessorTanStackDB-BrSD2e9G.js} +24 -198
- package/dist/getDatetimeRuleProcessorTanStackDB-BrSD2e9G.js.map +1 -0
- package/dist/{getDatetimeRuleProcessorTanStackDB-BcOC-o2A.mjs → getDatetimeRuleProcessorTanStackDB-DR8aYrUa.mjs} +24 -124
- package/dist/getDatetimeRuleProcessorTanStackDB-DR8aYrUa.mjs.map +1 -0
- package/dist/objectSpread2-MqoZ2hSz.js +187 -0
- package/dist/objectSpread2-MqoZ2hSz.js.map +1 -0
- package/dist/react-querybuilder_datetime.d.mts +124 -260
- package/dist/react-querybuilder_datetime.date-fns.d.mts +50 -51
- package/dist/react-querybuilder_datetime.date-fns.mjs +2 -1
- package/dist/react-querybuilder_datetime.date-fns.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.dayjs.d.mts +50 -51
- package/dist/react-querybuilder_datetime.dayjs.mjs +27 -2
- package/dist/react-querybuilder_datetime.dayjs.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.jsdate.d.mts +53 -54
- package/dist/react-querybuilder_datetime.jsdate.mjs +2 -120
- package/dist/react-querybuilder_datetime.jsdate.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.d.ts +124 -260
- package/dist/react-querybuilder_datetime.legacy-esm.date-fns.d.ts +50 -51
- package/dist/react-querybuilder_datetime.legacy-esm.date-fns.js +2 -1
- package/dist/react-querybuilder_datetime.legacy-esm.date-fns.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.dayjs.d.ts +50 -51
- package/dist/react-querybuilder_datetime.legacy-esm.dayjs.js +27 -2
- package/dist/react-querybuilder_datetime.legacy-esm.dayjs.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.js +5 -449
- package/dist/react-querybuilder_datetime.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.jsdate.d.ts +53 -54
- package/dist/react-querybuilder_datetime.legacy-esm.jsdate.js +2 -120
- package/dist/react-querybuilder_datetime.legacy-esm.jsdate.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.luxon.d.ts +50 -51
- package/dist/react-querybuilder_datetime.legacy-esm.luxon.js +2 -1
- package/dist/react-querybuilder_datetime.legacy-esm.luxon.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.ui.d.ts +214 -0
- package/dist/react-querybuilder_datetime.legacy-esm.ui.js +453 -0
- package/dist/react-querybuilder_datetime.legacy-esm.ui.js.map +1 -0
- package/dist/react-querybuilder_datetime.luxon.d.mts +50 -51
- package/dist/react-querybuilder_datetime.luxon.mjs +2 -1
- package/dist/react-querybuilder_datetime.luxon.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.mjs +5 -446
- package/dist/react-querybuilder_datetime.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.production.d.mts +124 -260
- package/dist/react-querybuilder_datetime.production.date-fns.d.mts +50 -51
- package/dist/react-querybuilder_datetime.production.date-fns.mjs +1 -1
- package/dist/react-querybuilder_datetime.production.date-fns.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.production.dayjs.d.mts +50 -51
- package/dist/react-querybuilder_datetime.production.dayjs.mjs +1 -1
- package/dist/react-querybuilder_datetime.production.dayjs.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.production.jsdate.d.mts +53 -54
- package/dist/react-querybuilder_datetime.production.jsdate.mjs +1 -1
- package/dist/react-querybuilder_datetime.production.jsdate.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.production.luxon.d.mts +50 -51
- package/dist/react-querybuilder_datetime.production.luxon.mjs +1 -1
- package/dist/react-querybuilder_datetime.production.luxon.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.production.mjs +1 -1
- package/dist/react-querybuilder_datetime.production.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.production.ui.d.mts +214 -0
- package/dist/react-querybuilder_datetime.production.ui.mjs +2 -0
- package/dist/react-querybuilder_datetime.production.ui.mjs.map +1 -0
- package/dist/react-querybuilder_datetime.ui.d.mts +214 -0
- package/dist/react-querybuilder_datetime.ui.mjs +450 -0
- package/dist/react-querybuilder_datetime.ui.mjs.map +1 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-COp9qTw_.js +123 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-COp9qTw_.js.map +1 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-DxBmxW2C.mjs +2 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-DxBmxW2C.mjs.map +1 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-WHnzblie.mjs +123 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-WHnzblie.mjs.map +1 -0
- package/dist/types-BKA1aoY6.d.mts +174 -0
- package/dist/types-BKA1aoY6.d.ts +174 -0
- package/dist/utils-BAgUBdyf.mjs +113 -0
- package/dist/utils-BAgUBdyf.mjs.map +1 -0
- package/dist/utils-DA8aluCt.mjs +2 -0
- package/dist/utils-DA8aluCt.mjs.map +1 -0
- package/package.json +36 -17
- package/ui/package.json +4 -0
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-CL79A1_x.js.map +0 -1
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-DgUg_arY.js +0 -2
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-DgUg_arY.js.map +0 -1
- package/dist/cjs/rqbDateTimeLibraryAPI.dayjs-BfILPx88.js +0 -2
- package/dist/cjs/rqbDateTimeLibraryAPI.dayjs-BfILPx88.js.map +0 -1
- package/dist/cjs/rqbDateTimeLibraryAPI.dayjs-CzLh_zi9.js +0 -63
- package/dist/cjs/rqbDateTimeLibraryAPI.dayjs-CzLh_zi9.js.map +0 -1
- package/dist/cjs/types-XYMw0jFT.d.ts +0 -265
- package/dist/getDatetimeRuleProcessorTanStackDB-BL8mbdbl.js.map +0 -1
- package/dist/getDatetimeRuleProcessorTanStackDB-BcOC-o2A.mjs.map +0 -1
- package/dist/getDatetimeRuleProcessorTanStackDB-Dloxv6k2.mjs +0 -2
- package/dist/getDatetimeRuleProcessorTanStackDB-Dloxv6k2.mjs.map +0 -1
- package/dist/rqbDateTimeLibraryAPI.dayjs-BW7faYFD.mjs +0 -29
- package/dist/rqbDateTimeLibraryAPI.dayjs-BW7faYFD.mjs.map +0 -1
- package/dist/rqbDateTimeLibraryAPI.dayjs-BoX90aqZ.mjs +0 -2
- package/dist/rqbDateTimeLibraryAPI.dayjs-BoX90aqZ.mjs.map +0 -1
- package/dist/rqbDateTimeLibraryAPI.dayjs-Da4VXvFM.js +0 -29
- package/dist/rqbDateTimeLibraryAPI.dayjs-Da4VXvFM.js.map +0 -1
- package/dist/types-CdjHqQ0k.d.mts +0 -265
- package/dist/types-CdjHqQ0k.d.ts +0 -265
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { RQBJsonLogic, RuleProcessor } from "@react-querybuilder/core";
|
|
2
|
+
import { RulesLogic } from "json-logic-js";
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
interface RQBJsonLogicDateBetween {
|
|
5
|
+
dateBetween: [RQBJsonLogic, RQBJsonLogic, RQBJsonLogic];
|
|
6
|
+
}
|
|
7
|
+
interface RQBJsonLogicDateNotBetween {
|
|
8
|
+
dateNotBetween: [RQBJsonLogic, RQBJsonLogic, RQBJsonLogic];
|
|
9
|
+
}
|
|
10
|
+
interface RQBJsonLogicDateIn {
|
|
11
|
+
dateIn: [RQBJsonLogic, RQBJsonLogic[]];
|
|
12
|
+
}
|
|
13
|
+
interface RQBJsonLogicDateNotIn {
|
|
14
|
+
dateNotIn: [RQBJsonLogic, RQBJsonLogic[]];
|
|
15
|
+
}
|
|
16
|
+
interface RQBJsonLogicDateBefore {
|
|
17
|
+
dateBefore: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
|
|
18
|
+
}
|
|
19
|
+
interface RQBJsonLogicDateOnOrBefore {
|
|
20
|
+
dateOnOrBefore: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
|
|
21
|
+
}
|
|
22
|
+
interface RQBJsonLogicDateOn {
|
|
23
|
+
dateOn: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
|
|
24
|
+
}
|
|
25
|
+
interface RQBJsonLogicDateNotOn {
|
|
26
|
+
dateNotOn: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
|
|
27
|
+
}
|
|
28
|
+
interface RQBJsonLogicDateAfter {
|
|
29
|
+
dateAfter: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
|
|
30
|
+
}
|
|
31
|
+
interface RQBJsonLogicDateOnOrAfter {
|
|
32
|
+
dateOnOrAfter: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
|
|
33
|
+
}
|
|
34
|
+
interface RQBJsonLogicDateRelative {
|
|
35
|
+
dateRelative: [RelativeDateTimeAnchor, number, RelativeDateTimeUnit, boolean];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* JsonLogic rule object with additional operators generated by
|
|
39
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} and accepted by
|
|
40
|
+
* {@link @react-querybuilder/core!parseJsonLogic parseJsonLogic}.
|
|
41
|
+
*/
|
|
42
|
+
type RQBDateTimeJsonLogic = RQBJsonLogic | RulesLogic<RQBJsonLogicDateAfter | RQBJsonLogicDateBefore | RQBJsonLogicDateBetween | RQBJsonLogicDateIn | RQBJsonLogicDateNotBetween | RQBJsonLogicDateNotIn | RQBJsonLogicDateNotOn | RQBJsonLogicDateOn | RQBJsonLogicDateOnOrAfter | RQBJsonLogicDateOnOrBefore | RQBJsonLogicDateRelative>;
|
|
43
|
+
type DateOrString = string | Date;
|
|
44
|
+
/**
|
|
45
|
+
* Unit of measure for a relative date/time offset.
|
|
46
|
+
*/
|
|
47
|
+
type RelativeDateTimeUnit = "minute" | "hour" | "day" | "week" | "month" | "year";
|
|
48
|
+
/**
|
|
49
|
+
* Unit of measure for truncating a date/time to the start or end of a period
|
|
50
|
+
* (the subset of {@link RelativeDateTimeUnit} that represents a calendar period).
|
|
51
|
+
*/
|
|
52
|
+
type RelativeDateTimeTruncationUnit = "day" | "week" | "month" | "year";
|
|
53
|
+
/**
|
|
54
|
+
* Reference point (zero-offset) for a {@link RelativeDateTimeValue}. `'now'` is the
|
|
55
|
+
* current date/time; the `startOf*`/`endOf*` anchors truncate to the start or end
|
|
56
|
+
* of the corresponding calendar period.
|
|
57
|
+
*/
|
|
58
|
+
type RelativeDateTimeAnchor = "now" | "startOfDay" | "endOfDay" | "startOfWeek" | "endOfWeek" | "startOfMonth" | "endOfMonth" | "startOfYear" | "endOfYear";
|
|
59
|
+
/**
|
|
60
|
+
* Structured representation of a relative date/time value, e.g. "three months ago"
|
|
61
|
+
* or "the beginning of this year". Stored as the `value` of a rule (in place of the
|
|
62
|
+
* usual ISO 8601 string) and recognized by the date/time rule processors.
|
|
63
|
+
*
|
|
64
|
+
* The final date/time is computed as: apply the `anchor` to the current date/time,
|
|
65
|
+
* then add `offset` units of `unit`. When `offset` is `0`, `unit` is irrelevant.
|
|
66
|
+
*/
|
|
67
|
+
interface RelativeDateTimeValue {
|
|
68
|
+
/** Discriminant identifying a relative (as opposed to absolute) value. */
|
|
69
|
+
mode: "relative";
|
|
70
|
+
/** Zero-offset reference point. */
|
|
71
|
+
anchor: RelativeDateTimeAnchor;
|
|
72
|
+
/** Signed offset from the anchor; negative = past, positive = future, 0 = exact anchor. */
|
|
73
|
+
offset: number;
|
|
74
|
+
/** Unit of the `offset`. */
|
|
75
|
+
unit: RelativeDateTimeUnit;
|
|
76
|
+
}
|
|
77
|
+
interface RQBDateTimeLibraryAPI {
|
|
78
|
+
/**
|
|
79
|
+
* Formats a date as a string.
|
|
80
|
+
*/
|
|
81
|
+
format: (d: DateOrString, fmt: string) => string;
|
|
82
|
+
/**
|
|
83
|
+
* Formats a date as an ISO 8601 string, only including
|
|
84
|
+
* the year, month, and day ('YYYY-MM-DD').
|
|
85
|
+
*/
|
|
86
|
+
toISOStringDateOnly: (d: DateOrString) => string;
|
|
87
|
+
/**
|
|
88
|
+
* Determines whether the first date is after the second date.
|
|
89
|
+
*/
|
|
90
|
+
isAfter: (a: DateOrString, b: DateOrString) => boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Determines whether the first date is before the second date.
|
|
93
|
+
*/
|
|
94
|
+
isBefore: (a: DateOrString, b: DateOrString) => boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Determines whether the first date is the same as the second date.
|
|
97
|
+
*
|
|
98
|
+
* If either the first date or the second date is a string in the
|
|
99
|
+
* format 'YYYY-MM-DD', then the dates will only be compared at
|
|
100
|
+
* the date level (no time component). Otherwise, they will be
|
|
101
|
+
* compared to the millisecond.
|
|
102
|
+
*/
|
|
103
|
+
isSame: (a: DateOrString, b: DateOrString) => boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Determines whether the date is either a valid `Date` object or an
|
|
106
|
+
* ISO 8601-formatted string representing a valid date.
|
|
107
|
+
*/
|
|
108
|
+
isValid: (d: DateOrString) => boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Converts a string to a `Date` object or returns a valid `Date` as is.
|
|
111
|
+
*/
|
|
112
|
+
toDate: (d: DateOrString) => Date;
|
|
113
|
+
/**
|
|
114
|
+
* Converts a `Date` or ISO 8601-formatted string into a full ISO 8601 UTC
|
|
115
|
+
* string, in the format 'YYYY-MM-DDTHH:mm:ss.SSSZ' (the "T" and "Z" are
|
|
116
|
+
* static; other parts represent standard time units, increasing in precision
|
|
117
|
+
* from left to right).
|
|
118
|
+
*/
|
|
119
|
+
toISOString: (d: DateOrString) => string;
|
|
120
|
+
/**
|
|
121
|
+
* Returns a new `Date` truncated to the start of the given period.
|
|
122
|
+
*
|
|
123
|
+
* Week start follows the date library's own default/locale (e.g. Luxon uses
|
|
124
|
+
* Monday per ISO 8601; Day.js and date-fns default to Sunday).
|
|
125
|
+
*/
|
|
126
|
+
startOf: (d: DateOrString, unit: RelativeDateTimeTruncationUnit) => Date;
|
|
127
|
+
/**
|
|
128
|
+
* Returns a new `Date` advanced to the end of the given period (the last
|
|
129
|
+
* representable instant within it).
|
|
130
|
+
*
|
|
131
|
+
* Week start follows the date library's own default/locale (see {@link RQBDateTimeLibraryAPI.startOf}).
|
|
132
|
+
*/
|
|
133
|
+
endOf: (d: DateOrString, unit: RelativeDateTimeTruncationUnit) => Date;
|
|
134
|
+
/**
|
|
135
|
+
* Returns a new `Date` offset from the input by `amount` units of `unit`
|
|
136
|
+
* (negative `amount` moves into the past).
|
|
137
|
+
*/
|
|
138
|
+
add: (d: DateOrString, amount: number, unit: RelativeDateTimeUnit) => Date;
|
|
139
|
+
}
|
|
140
|
+
type FnDateDate = (a: DateOrString, b: DateOrString) => boolean;
|
|
141
|
+
type FnDateArrayOfDates = (a: DateOrString, b: DateOrString[]) => boolean;
|
|
142
|
+
type FnDateDateDate = (a: DateOrString, b: DateOrString, c: DateOrString) => boolean;
|
|
143
|
+
type RQBJsonLogicDateTimeOperations = {
|
|
144
|
+
/** Determines if the first date is after the second date. */
|
|
145
|
+
dateAfter: FnDateDate;
|
|
146
|
+
/** Determines if the first date is before the second date. */
|
|
147
|
+
dateBefore: FnDateDate;
|
|
148
|
+
/** Determines if the second date is between the first and third dates (inclusive). */
|
|
149
|
+
dateBetween: FnDateDateDate;
|
|
150
|
+
/** Determines if the first date is one of the values in the array of dates. */
|
|
151
|
+
dateIn: FnDateArrayOfDates;
|
|
152
|
+
/** Determines if the second date is not between the first and third dates. */
|
|
153
|
+
dateNotBetween: FnDateDateDate;
|
|
154
|
+
/** Determines if the first date is not one of the values in the array of dates. */
|
|
155
|
+
dateNotIn: FnDateArrayOfDates;
|
|
156
|
+
/** Determines if the first date is not the same as the second date. */
|
|
157
|
+
dateNotOn: FnDateDate;
|
|
158
|
+
/** Determines if the first date is the same as the second date (at the level of least precision between the two). */
|
|
159
|
+
dateOn: FnDateDate;
|
|
160
|
+
/** Determines if the first date is either the same as the second date or after it. */
|
|
161
|
+
dateOnOrAfter: FnDateDate;
|
|
162
|
+
/** Determines if the first date is either the same as the second date or before it. */
|
|
163
|
+
dateOnOrBefore: FnDateDate;
|
|
164
|
+
/**
|
|
165
|
+
* Resolves a relative date/time descriptor (anchor, offset, unit, and date-only
|
|
166
|
+
* flag) to a concrete ISO 8601 string at evaluation time ("live" semantics).
|
|
167
|
+
*/
|
|
168
|
+
dateRelative: (anchor: RelativeDateTimeAnchor, offset: number, unit: RelativeDateTimeUnit, dateOnly: boolean) => string;
|
|
169
|
+
};
|
|
170
|
+
type IsDateFieldFunction = (...[rule, opts]: Parameters<RuleProcessor>) => boolean;
|
|
171
|
+
type IsDateField = IsDateFieldFunction | Record<string, unknown> | Record<string, unknown>[] | boolean | undefined;
|
|
172
|
+
//#endregion
|
|
173
|
+
export { RelativeDateTimeAnchor as _, RQBJsonLogicDateAfter as a, RelativeDateTimeValue as b, RQBJsonLogicDateIn as c, RQBJsonLogicDateNotOn as d, RQBJsonLogicDateOn as f, RQBJsonLogicDateTimeOperations as g, RQBJsonLogicDateRelative as h, RQBDateTimeLibraryAPI as i, RQBJsonLogicDateNotBetween as l, RQBJsonLogicDateOnOrBefore as m, IsDateFieldFunction as n, RQBJsonLogicDateBefore as o, RQBJsonLogicDateOnOrAfter as p, RQBDateTimeJsonLogic as r, RQBJsonLogicDateBetween as s, IsDateField as t, RQBJsonLogicDateNotIn as u, RelativeDateTimeTruncationUnit as v, RelativeDateTimeUnit as y };
|
|
174
|
+
//# sourceMappingURL=types-BKA1aoY6.d.ts.map
|
package/dist/cjs/ui.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './react-querybuilder_datetime.cjs.development.ui.js';
|
package/dist/cjs/ui.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=e=>typeof e==`string`&&/^\d{4}-\d{2}-\d{2}$/.test(e),t=e=>e===`field`||e===`parameter`,n=e=>typeof e==`object`&&!!e&&e.mode===`relative`&&typeof e.anchor==`string`,r=/^(start|end)Of(Day|Week|Month|Year)$/,i=(e,t,n=new Date)=>{let i=n;if(t.anchor!==`now`){let n=r.exec(t.anchor);if(n){let t=n[2].toLowerCase();i=n[1]===`start`?e.startOf(i,t):e.endOf(i,t)}}return t.offset&&(i=e.add(i,t.offset,t.unit)),i},a=e=>/^date\b/i.test(e),o=(e,t,r)=>{let o=r?.context?.relativeDateTimeBase,s=a(r?.fieldData?.datatype),c=t=>{if(!n(t))return t;let r=i(e,t,o);return s?e.toISOStringDateOnly(r):e.toISOString(r)};return Array.isArray(t)?t.map(c):c(t)},s=(...[e,t])=>t?.context?.relativeOperatorMap?.[e.operator]??e.operator,c=(e,t,n,r=!1)=>{let i=s(t,n),a=o(e,t.value,n),c=a;if(Array.isArray(a)&&a.length>=2){let t=i.toLowerCase();if(t===`between`||t===`notbetween`){let t=e.toDate(a[0]),n=e.toDate(a[1]);e.isValid(t)&&e.isValid(n)&&!e.isBefore(t,n)&&(c=[a[1],a[0],...a.slice(2)])}}if(!r)return{operator:i,value:c};let l=t=>{let n=e.toDate(t);return e.isValid(n)?n:t};return{operator:i,value:Array.isArray(c)?c.map(l):l(c)}},l=(...[e,t])=>e.operator!==`contains`&&e.operator!==`beginsWith`&&e.operator!==`endsWith`&&e.operator!==`doesNotContain`&&e.operator!==`doesNotBeginWith`&&e.operator!==`doesNotEndWith`&&e.operator!==`null`&&e.operator!==`notNull`&&/^(?:date|datetime|datetimeoffset|timestamp)\b/i.test(t?.fieldData?.datatype),u=(e,...[t,n])=>typeof e==`boolean`?e:typeof e==`function`?e(t,n):Array.isArray(e)?e.some(e=>Object.entries(e).every(([e,t])=>n?.fieldData?.[e]===t)):typeof e==`object`?Object.entries(e).every(([e,t])=>n?.fieldData?.[e]===t):l(t,n);Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
|
|
2
|
+
//# sourceMappingURL=utils-DdBYGWHZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-DdBYGWHZ.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import type { RuleProcessor, ValueSource } from '@react-querybuilder/core';\nimport type {\n IsDateField,\n IsDateFieldFunction,\n RelativeDateTimeTruncationUnit,\n RelativeDateTimeValue,\n RQBDateTimeLibraryAPI,\n} from './types';\n\nexport const isISOStringDateOnly = (\n date: unknown\n): date is `${number}${number}${number}${number}-${number}${number}-${number}${number}` =>\n typeof date === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(date);\n\n/**\n * Whether a rule's value source is one that datetime processors must NOT materialize as a\n * date (`field` references another column; `parameter` is a named bind placeholder). Both\n * are delegated to the core default processor, which serializes them per format.\n */\nexport const isNonDateValueSource = (valueSource: ValueSource | undefined): boolean =>\n valueSource === 'field' || valueSource === 'parameter';\n\n/**\n * Type guard for {@link RelativeDateTimeValue}. Relative values are stored as objects\n * (distinguishing them from the ISO 8601 strings used for absolute date/time values).\n */\nexport const isRelativeDateTimeValue = (value: unknown): value is RelativeDateTimeValue =>\n typeof value === 'object' &&\n value !== null &&\n (value as { mode?: unknown }).mode === 'relative' &&\n typeof (value as RelativeDateTimeValue).anchor === 'string';\n\nconst anchorRegExp = /^(start|end)Of(Day|Week|Month|Year)$/;\n\n/**\n * Resolves a {@link RelativeDateTimeValue} into a concrete `Date` using the given\n * date library API. The anchor is applied relative to `base` (defaulting to now),\n * then the signed offset is added.\n */\nexport const resolveRelativeDateTime = (\n apiFns: RQBDateTimeLibraryAPI,\n value: RelativeDateTimeValue,\n base: Date = new Date()\n): Date => {\n let result: Date = base;\n\n if (value.anchor !== 'now') {\n const match = anchorRegExp.exec(value.anchor);\n // v8 ignore next -- guarded by the RelativeDateTimeAnchor type\n if (match) {\n const unit = match[2].toLowerCase() as RelativeDateTimeTruncationUnit;\n result = match[1] === 'start' ? apiFns.startOf(result, unit) : apiFns.endOf(result, unit);\n }\n }\n\n if (value.offset) {\n result = apiFns.add(result, value.offset, value.unit);\n }\n\n return result;\n};\n\n/**\n * Whether a `datatype` represents a date-only (no time component) type, e.g. `date`\n * but not `datetime`/`datetimeoffset`/`timestamp`. Used to choose the precision when\n * materializing a relative value to an ISO 8601 string.\n */\nexport const isDateOnlyDatatype = (datatype: unknown): boolean =>\n /^date\\b/i.test(datatype as string);\n\n/**\n * Replaces any {@link RelativeDateTimeValue} in `value` (or in each element, if `value`\n * is an array) with a concrete ISO 8601 string, resolved via\n * {@link resolveRelativeDateTime}. The \"now\" reference can be pinned with\n * `opts.context.relativeDateTimeBase` for deterministic output; precision (date-only vs\n * full) follows the field's `datatype`. Non-relative values pass through unchanged.\n */\nexport const materializeRelativeValues = (\n apiFns: RQBDateTimeLibraryAPI,\n value: unknown,\n opts: Parameters<RuleProcessor>[1]\n): unknown => {\n const base = opts?.context?.relativeDateTimeBase as Date | undefined;\n const dateOnly = isDateOnlyDatatype(opts?.fieldData?.datatype);\n const conv = (v: unknown): unknown => {\n if (!isRelativeDateTimeValue(v)) return v;\n const resolved = resolveRelativeDateTime(apiFns, v, base);\n return dateOnly ? apiFns.toISOStringDateOnly(resolved) : apiFns.toISOString(resolved);\n };\n return Array.isArray(value) ? value.map(conv) : conv(value);\n};\n\n/**\n * Resolves a rule's operator for export, applying any `context.relativeOperatorMap`\n * entry. Operator-driven mode controllers (see `createOperatorModeController`) use\n * dedicated operator names to signal relative mode; this maps those names to the real\n * comparison operator at format time. Operators absent from the map pass through unchanged.\n */\nexport const resolveDatetimeOperator = (...[rule, opts]: Parameters<RuleProcessor>): string =>\n (opts?.context?.relativeOperatorMap as Record<string, string> | undefined)?.[rule.operator] ??\n rule.operator;\n\n/**\n * Prepares a date/time rule for delegation to a non-symbolic default rule processor\n * (e.g. \"parameterized\", \"spel\", \"ldap\", \"gremlin\", \"prisma\", \"sequelize\", \"drizzle\",\n * \"tanstack_db\"). Relative values are materialized to concrete dates (these formats have\n * no symbolic relative form), and `between`/`notBetween` operands are ordered\n * chronologically (defaults can't reorder non-numeric date operands). When `asDate` is\n * set, each valid value is converted to a `Date` (for object-based formats); otherwise\n * the materialized ISO 8601 strings are passed through. The resolved `operator` (after\n * any `relativeOperatorMap` mapping) is returned alongside the prepared `value`.\n */\nexport const materializeForExport = (\n apiFns: RQBDateTimeLibraryAPI,\n rule: Parameters<RuleProcessor>[0],\n opts: Parameters<RuleProcessor>[1],\n asDate = false\n): { operator: string; value: unknown } => {\n const operator = resolveDatetimeOperator(rule, opts);\n const materialized = materializeRelativeValues(apiFns, rule.value, opts);\n\n let prepared = materialized;\n if (Array.isArray(materialized) && materialized.length >= 2) {\n const opLC = operator.toLowerCase();\n if (opLC === 'between' || opLC === 'notbetween') {\n const first = apiFns.toDate(materialized[0] as string | Date);\n const second = apiFns.toDate(materialized[1] as string | Date);\n if (apiFns.isValid(first) && apiFns.isValid(second) && !apiFns.isBefore(first, second)) {\n prepared = [materialized[1], materialized[0], ...materialized.slice(2)];\n }\n }\n }\n\n if (!asDate) return { operator, value: prepared };\n\n const toDateVal = (v: unknown) => {\n const d = apiFns.toDate(v as string | Date);\n return apiFns.isValid(d) ? d : v;\n };\n return {\n operator,\n value: Array.isArray(prepared) ? prepared.map(toDateVal) : toDateVal(prepared),\n };\n};\n\nexport const defaultIsDateField: IsDateFieldFunction = (\n ...[rule, opts]: Parameters<RuleProcessor>\n): boolean =>\n rule.operator !== 'contains' &&\n rule.operator !== 'beginsWith' &&\n rule.operator !== 'endsWith' &&\n rule.operator !== 'doesNotContain' &&\n rule.operator !== 'doesNotBeginWith' &&\n rule.operator !== 'doesNotEndWith' &&\n rule.operator !== 'null' &&\n rule.operator !== 'notNull' &&\n /^(?:date|datetime|datetimeoffset|timestamp)\\b/i.test(opts?.fieldData?.datatype as string);\n\nexport const processIsDateField = (\n isDateField: IsDateField,\n ...[rule, opts]: Parameters<RuleProcessor>\n): boolean => {\n if (typeof isDateField === 'boolean') {\n return isDateField;\n }\n\n if (typeof isDateField === 'function') {\n return isDateField(rule, opts);\n }\n\n if (Array.isArray(isDateField)) {\n return isDateField.some(condition =>\n Object.entries(condition).every(([key, value]) => opts?.fieldData?.[key] === value)\n );\n }\n\n if (typeof isDateField === 'object') {\n return Object.entries(isDateField).every(([key, value]) => opts?.fieldData?.[key] === value);\n }\n\n return defaultIsDateField(rule, opts);\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
//#region src/utils.ts
|
|
2
|
+
const isISOStringDateOnly = (date) => typeof date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(date);
|
|
3
|
+
/**
|
|
4
|
+
* Whether a rule's value source is one that datetime processors must NOT materialize as a
|
|
5
|
+
* date (`field` references another column; `parameter` is a named bind placeholder). Both
|
|
6
|
+
* are delegated to the core default processor, which serializes them per format.
|
|
7
|
+
*/
|
|
8
|
+
const isNonDateValueSource = (valueSource) => valueSource === "field" || valueSource === "parameter";
|
|
9
|
+
/**
|
|
10
|
+
* Type guard for {@link RelativeDateTimeValue}. Relative values are stored as objects
|
|
11
|
+
* (distinguishing them from the ISO 8601 strings used for absolute date/time values).
|
|
12
|
+
*/
|
|
13
|
+
const isRelativeDateTimeValue = (value) => typeof value === "object" && value !== null && value.mode === "relative" && typeof value.anchor === "string";
|
|
14
|
+
const anchorRegExp = /^(start|end)Of(Day|Week|Month|Year)$/;
|
|
15
|
+
/**
|
|
16
|
+
* Resolves a {@link RelativeDateTimeValue} into a concrete `Date` using the given
|
|
17
|
+
* date library API. The anchor is applied relative to `base` (defaulting to now),
|
|
18
|
+
* then the signed offset is added.
|
|
19
|
+
*/
|
|
20
|
+
const resolveRelativeDateTime = (apiFns, value, base = /* @__PURE__ */ new Date()) => {
|
|
21
|
+
let result = base;
|
|
22
|
+
if (value.anchor !== "now") {
|
|
23
|
+
const match = anchorRegExp.exec(value.anchor);
|
|
24
|
+
// v8 ignore next -- guarded by the RelativeDateTimeAnchor type
|
|
25
|
+
if (match) {
|
|
26
|
+
const unit = match[2].toLowerCase();
|
|
27
|
+
result = match[1] === "start" ? apiFns.startOf(result, unit) : apiFns.endOf(result, unit);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (value.offset) result = apiFns.add(result, value.offset, value.unit);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Whether a `datatype` represents a date-only (no time component) type, e.g. `date`
|
|
35
|
+
* but not `datetime`/`datetimeoffset`/`timestamp`. Used to choose the precision when
|
|
36
|
+
* materializing a relative value to an ISO 8601 string.
|
|
37
|
+
*/
|
|
38
|
+
const isDateOnlyDatatype = (datatype) => /^date\b/i.test(datatype);
|
|
39
|
+
/**
|
|
40
|
+
* Replaces any {@link RelativeDateTimeValue} in `value` (or in each element, if `value`
|
|
41
|
+
* is an array) with a concrete ISO 8601 string, resolved via
|
|
42
|
+
* {@link resolveRelativeDateTime}. The "now" reference can be pinned with
|
|
43
|
+
* `opts.context.relativeDateTimeBase` for deterministic output; precision (date-only vs
|
|
44
|
+
* full) follows the field's `datatype`. Non-relative values pass through unchanged.
|
|
45
|
+
*/
|
|
46
|
+
const materializeRelativeValues = (apiFns, value, opts) => {
|
|
47
|
+
const base = opts?.context?.relativeDateTimeBase;
|
|
48
|
+
const dateOnly = isDateOnlyDatatype(opts?.fieldData?.datatype);
|
|
49
|
+
const conv = (v) => {
|
|
50
|
+
if (!isRelativeDateTimeValue(v)) return v;
|
|
51
|
+
const resolved = resolveRelativeDateTime(apiFns, v, base);
|
|
52
|
+
return dateOnly ? apiFns.toISOStringDateOnly(resolved) : apiFns.toISOString(resolved);
|
|
53
|
+
};
|
|
54
|
+
return Array.isArray(value) ? value.map(conv) : conv(value);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Resolves a rule's operator for export, applying any `context.relativeOperatorMap`
|
|
58
|
+
* entry. Operator-driven mode controllers (see `createOperatorModeController`) use
|
|
59
|
+
* dedicated operator names to signal relative mode; this maps those names to the real
|
|
60
|
+
* comparison operator at format time. Operators absent from the map pass through unchanged.
|
|
61
|
+
*/
|
|
62
|
+
const resolveDatetimeOperator = (...[rule, opts]) => (opts?.context?.relativeOperatorMap)?.[rule.operator] ?? rule.operator;
|
|
63
|
+
/**
|
|
64
|
+
* Prepares a date/time rule for delegation to a non-symbolic default rule processor
|
|
65
|
+
* (e.g. "parameterized", "spel", "ldap", "gremlin", "prisma", "sequelize", "drizzle",
|
|
66
|
+
* "tanstack_db"). Relative values are materialized to concrete dates (these formats have
|
|
67
|
+
* no symbolic relative form), and `between`/`notBetween` operands are ordered
|
|
68
|
+
* chronologically (defaults can't reorder non-numeric date operands). When `asDate` is
|
|
69
|
+
* set, each valid value is converted to a `Date` (for object-based formats); otherwise
|
|
70
|
+
* the materialized ISO 8601 strings are passed through. The resolved `operator` (after
|
|
71
|
+
* any `relativeOperatorMap` mapping) is returned alongside the prepared `value`.
|
|
72
|
+
*/
|
|
73
|
+
const materializeForExport = (apiFns, rule, opts, asDate = false) => {
|
|
74
|
+
const operator = resolveDatetimeOperator(rule, opts);
|
|
75
|
+
const materialized = materializeRelativeValues(apiFns, rule.value, opts);
|
|
76
|
+
let prepared = materialized;
|
|
77
|
+
if (Array.isArray(materialized) && materialized.length >= 2) {
|
|
78
|
+
const opLC = operator.toLowerCase();
|
|
79
|
+
if (opLC === "between" || opLC === "notbetween") {
|
|
80
|
+
const first = apiFns.toDate(materialized[0]);
|
|
81
|
+
const second = apiFns.toDate(materialized[1]);
|
|
82
|
+
if (apiFns.isValid(first) && apiFns.isValid(second) && !apiFns.isBefore(first, second)) prepared = [
|
|
83
|
+
materialized[1],
|
|
84
|
+
materialized[0],
|
|
85
|
+
...materialized.slice(2)
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!asDate) return {
|
|
90
|
+
operator,
|
|
91
|
+
value: prepared
|
|
92
|
+
};
|
|
93
|
+
const toDateVal = (v) => {
|
|
94
|
+
const d = apiFns.toDate(v);
|
|
95
|
+
return apiFns.isValid(d) ? d : v;
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
operator,
|
|
99
|
+
value: Array.isArray(prepared) ? prepared.map(toDateVal) : toDateVal(prepared)
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const defaultIsDateField = (...[rule, opts]) => rule.operator !== "contains" && rule.operator !== "beginsWith" && rule.operator !== "endsWith" && rule.operator !== "doesNotContain" && rule.operator !== "doesNotBeginWith" && rule.operator !== "doesNotEndWith" && rule.operator !== "null" && rule.operator !== "notNull" && /^(?:date|datetime|datetimeoffset|timestamp)\b/i.test(opts?.fieldData?.datatype);
|
|
103
|
+
const processIsDateField = (isDateField, ...[rule, opts]) => {
|
|
104
|
+
if (typeof isDateField === "boolean") return isDateField;
|
|
105
|
+
if (typeof isDateField === "function") return isDateField(rule, opts);
|
|
106
|
+
if (Array.isArray(isDateField)) return isDateField.some((condition) => Object.entries(condition).every(([key, value]) => opts?.fieldData?.[key] === value));
|
|
107
|
+
if (typeof isDateField === "object") return Object.entries(isDateField).every(([key, value]) => opts?.fieldData?.[key] === value);
|
|
108
|
+
return defaultIsDateField(rule, opts);
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
Object.defineProperty(exports, "isDateOnlyDatatype", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: function() {
|
|
114
|
+
return isDateOnlyDatatype;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(exports, "isISOStringDateOnly", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function() {
|
|
120
|
+
return isISOStringDateOnly;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
Object.defineProperty(exports, "isNonDateValueSource", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function() {
|
|
126
|
+
return isNonDateValueSource;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(exports, "isRelativeDateTimeValue", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function() {
|
|
132
|
+
return isRelativeDateTimeValue;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, "materializeForExport", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function() {
|
|
138
|
+
return materializeForExport;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(exports, "materializeRelativeValues", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function() {
|
|
144
|
+
return materializeRelativeValues;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, "processIsDateField", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function() {
|
|
150
|
+
return processIsDateField;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(exports, "resolveDatetimeOperator", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function() {
|
|
156
|
+
return resolveDatetimeOperator;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(exports, "resolveRelativeDateTime", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function() {
|
|
162
|
+
return resolveRelativeDateTime;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
//# sourceMappingURL=utils-_X97pUtk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-_X97pUtk.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import type { RuleProcessor, ValueSource } from '@react-querybuilder/core';\nimport type {\n IsDateField,\n IsDateFieldFunction,\n RelativeDateTimeTruncationUnit,\n RelativeDateTimeValue,\n RQBDateTimeLibraryAPI,\n} from './types';\n\nexport const isISOStringDateOnly = (\n date: unknown\n): date is `${number}${number}${number}${number}-${number}${number}-${number}${number}` =>\n typeof date === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(date);\n\n/**\n * Whether a rule's value source is one that datetime processors must NOT materialize as a\n * date (`field` references another column; `parameter` is a named bind placeholder). Both\n * are delegated to the core default processor, which serializes them per format.\n */\nexport const isNonDateValueSource = (valueSource: ValueSource | undefined): boolean =>\n valueSource === 'field' || valueSource === 'parameter';\n\n/**\n * Type guard for {@link RelativeDateTimeValue}. Relative values are stored as objects\n * (distinguishing them from the ISO 8601 strings used for absolute date/time values).\n */\nexport const isRelativeDateTimeValue = (value: unknown): value is RelativeDateTimeValue =>\n typeof value === 'object' &&\n value !== null &&\n (value as { mode?: unknown }).mode === 'relative' &&\n typeof (value as RelativeDateTimeValue).anchor === 'string';\n\nconst anchorRegExp = /^(start|end)Of(Day|Week|Month|Year)$/;\n\n/**\n * Resolves a {@link RelativeDateTimeValue} into a concrete `Date` using the given\n * date library API. The anchor is applied relative to `base` (defaulting to now),\n * then the signed offset is added.\n */\nexport const resolveRelativeDateTime = (\n apiFns: RQBDateTimeLibraryAPI,\n value: RelativeDateTimeValue,\n base: Date = new Date()\n): Date => {\n let result: Date = base;\n\n if (value.anchor !== 'now') {\n const match = anchorRegExp.exec(value.anchor);\n // v8 ignore next -- guarded by the RelativeDateTimeAnchor type\n if (match) {\n const unit = match[2].toLowerCase() as RelativeDateTimeTruncationUnit;\n result = match[1] === 'start' ? apiFns.startOf(result, unit) : apiFns.endOf(result, unit);\n }\n }\n\n if (value.offset) {\n result = apiFns.add(result, value.offset, value.unit);\n }\n\n return result;\n};\n\n/**\n * Whether a `datatype` represents a date-only (no time component) type, e.g. `date`\n * but not `datetime`/`datetimeoffset`/`timestamp`. Used to choose the precision when\n * materializing a relative value to an ISO 8601 string.\n */\nexport const isDateOnlyDatatype = (datatype: unknown): boolean =>\n /^date\\b/i.test(datatype as string);\n\n/**\n * Replaces any {@link RelativeDateTimeValue} in `value` (or in each element, if `value`\n * is an array) with a concrete ISO 8601 string, resolved via\n * {@link resolveRelativeDateTime}. The \"now\" reference can be pinned with\n * `opts.context.relativeDateTimeBase` for deterministic output; precision (date-only vs\n * full) follows the field's `datatype`. Non-relative values pass through unchanged.\n */\nexport const materializeRelativeValues = (\n apiFns: RQBDateTimeLibraryAPI,\n value: unknown,\n opts: Parameters<RuleProcessor>[1]\n): unknown => {\n const base = opts?.context?.relativeDateTimeBase as Date | undefined;\n const dateOnly = isDateOnlyDatatype(opts?.fieldData?.datatype);\n const conv = (v: unknown): unknown => {\n if (!isRelativeDateTimeValue(v)) return v;\n const resolved = resolveRelativeDateTime(apiFns, v, base);\n return dateOnly ? apiFns.toISOStringDateOnly(resolved) : apiFns.toISOString(resolved);\n };\n return Array.isArray(value) ? value.map(conv) : conv(value);\n};\n\n/**\n * Resolves a rule's operator for export, applying any `context.relativeOperatorMap`\n * entry. Operator-driven mode controllers (see `createOperatorModeController`) use\n * dedicated operator names to signal relative mode; this maps those names to the real\n * comparison operator at format time. Operators absent from the map pass through unchanged.\n */\nexport const resolveDatetimeOperator = (...[rule, opts]: Parameters<RuleProcessor>): string =>\n (opts?.context?.relativeOperatorMap as Record<string, string> | undefined)?.[rule.operator] ??\n rule.operator;\n\n/**\n * Prepares a date/time rule for delegation to a non-symbolic default rule processor\n * (e.g. \"parameterized\", \"spel\", \"ldap\", \"gremlin\", \"prisma\", \"sequelize\", \"drizzle\",\n * \"tanstack_db\"). Relative values are materialized to concrete dates (these formats have\n * no symbolic relative form), and `between`/`notBetween` operands are ordered\n * chronologically (defaults can't reorder non-numeric date operands). When `asDate` is\n * set, each valid value is converted to a `Date` (for object-based formats); otherwise\n * the materialized ISO 8601 strings are passed through. The resolved `operator` (after\n * any `relativeOperatorMap` mapping) is returned alongside the prepared `value`.\n */\nexport const materializeForExport = (\n apiFns: RQBDateTimeLibraryAPI,\n rule: Parameters<RuleProcessor>[0],\n opts: Parameters<RuleProcessor>[1],\n asDate = false\n): { operator: string; value: unknown } => {\n const operator = resolveDatetimeOperator(rule, opts);\n const materialized = materializeRelativeValues(apiFns, rule.value, opts);\n\n let prepared = materialized;\n if (Array.isArray(materialized) && materialized.length >= 2) {\n const opLC = operator.toLowerCase();\n if (opLC === 'between' || opLC === 'notbetween') {\n const first = apiFns.toDate(materialized[0] as string | Date);\n const second = apiFns.toDate(materialized[1] as string | Date);\n if (apiFns.isValid(first) && apiFns.isValid(second) && !apiFns.isBefore(first, second)) {\n prepared = [materialized[1], materialized[0], ...materialized.slice(2)];\n }\n }\n }\n\n if (!asDate) return { operator, value: prepared };\n\n const toDateVal = (v: unknown) => {\n const d = apiFns.toDate(v as string | Date);\n return apiFns.isValid(d) ? d : v;\n };\n return {\n operator,\n value: Array.isArray(prepared) ? prepared.map(toDateVal) : toDateVal(prepared),\n };\n};\n\nexport const defaultIsDateField: IsDateFieldFunction = (\n ...[rule, opts]: Parameters<RuleProcessor>\n): boolean =>\n rule.operator !== 'contains' &&\n rule.operator !== 'beginsWith' &&\n rule.operator !== 'endsWith' &&\n rule.operator !== 'doesNotContain' &&\n rule.operator !== 'doesNotBeginWith' &&\n rule.operator !== 'doesNotEndWith' &&\n rule.operator !== 'null' &&\n rule.operator !== 'notNull' &&\n /^(?:date|datetime|datetimeoffset|timestamp)\\b/i.test(opts?.fieldData?.datatype as string);\n\nexport const processIsDateField = (\n isDateField: IsDateField,\n ...[rule, opts]: Parameters<RuleProcessor>\n): boolean => {\n if (typeof isDateField === 'boolean') {\n return isDateField;\n }\n\n if (typeof isDateField === 'function') {\n return isDateField(rule, opts);\n }\n\n if (Array.isArray(isDateField)) {\n return isDateField.some(condition =>\n Object.entries(condition).every(([key, value]) => opts?.fieldData?.[key] === value)\n );\n }\n\n if (typeof isDateField === 'object') {\n return Object.entries(isDateField).every(([key, value]) => opts?.fieldData?.[key] === value);\n }\n\n return defaultIsDateField(rule, opts);\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as e,c as t,i as n,l as r,n as i,o as a,r as o,s}from"./utils-DA8aluCt.mjs";import{defaultOperatorProcessorNL as c,defaultRuleProcessorCEL as l,defaultRuleProcessorCypher as u,defaultRuleProcessorDrizzle as d,defaultRuleProcessorElasticSearch as f,defaultRuleProcessorGremlin as p,defaultRuleProcessorJSONata as m,defaultRuleProcessorLDAP as h,defaultRuleProcessorMongoDBQuery as g,defaultRuleProcessorNL as _,defaultRuleProcessorParameterized as v,defaultRuleProcessorPrisma as y,defaultRuleProcessorSPARQL as b,defaultRuleProcessorSQL as x,defaultRuleProcessorSequelize as S,defaultRuleProcessorSpEL as C,defaultRuleProcessorTanStackDB as w,defaultValueProcessorByRule as T,getQuotedFieldName as E,lc as D,mapSQLOperator as O,mongoOperators as k,normalizeConstituentWordOrder as ee,nullOrUndefinedOrEmpty as A,sparqlVar as te,toArray as j}from"@react-querybuilder/core";const ne=e=>{let{isAfter:t,isBefore:n,isSame:i}=e;return{dateAfter:(e,n)=>t(e,n),dateBefore:(e,t)=>n(e,t),dateBetween:(e,r,a)=>i(r,e)||i(r,a)||t(r,e)&&n(r,a)||t(r,a)&&n(r,e),dateNotBetween:(e,r,a)=>!i(r,e)&&!i(r,a)&&(n(e,a)&&(n(r,e)||t(r,a))||t(e,a)&&(n(r,a)||t(r,e))),dateIn:(e,t)=>t.some(t=>i(e,t)),dateNotIn:(e,t)=>t.every(t=>!i(e,t)),dateNotOn:(e,t)=>!i(e,t),dateOn:(e,t)=>i(e,t),dateOnOrAfter:(e,n)=>t(e,n)||i(e,n),dateOnOrBefore:(e,t)=>n(e,t)||i(e,t),dateRelative:(t,n,i,a)=>{let o=r(e,{mode:`relative`,anchor:t,offset:n,unit:i});return a?e.toISOStringDateOnly(o):e.toISOString(o)}}},re=e=>/^(does)?not/i.test(e),M=e=>(n,r)=>{let i=r??{},{context:c={}}=i;if(o(n.valueSource)||!s(c.isDateField,n,i))return l(n,i);let u=t=>`timestamp("${e.toISOString(t)}")`,d=a(e,n.value,i),f=D(t(n,i).replace(/^=$/,`==`));switch(f){case`<`:case`<=`:case`==`:case`!=`:case`>`:case`>=`:return`${n.field} ${f} ${u(d)}`}let p=j(d,{retainEmptyStrings:!1}).map(t=>e.toDate(t)).filter(t=>e.isValid(t));switch(f){case`in`:case`notin`:{if(p.length===0)return``;let[e,t]=re(f)?[`!(`,`)`]:[``,``];return`${e}${n.field} in [${p.map(e=>u(e)).join(`, `)}]${t}`}case`between`:case`notbetween`:{if(p.length<2)return``;let[t,r]=p,[i,a]=e.isBefore(t,r)?[t,r]:[r,t];return f===`between`?`(${n.field} >= ${u(i)} && ${n.field} <= ${u(a)})`:`(${n.field} < ${u(i)} || ${n.field} > ${u(a)})`}}return l(n,i)},N=e=>/^(does)?not/i.test(e),ie=(e,t)=>t?`date('${e}')`:`datetime('${e}')`,P=e=>(n,r)=>{let c=r??{},{context:l={}}=c;if(o(n.valueSource)||!s(l.isDateField,n,c))return u(n,c);let{field:d}=n,f=D(t(n,c));if(f===`olderthanduration`)return`datetime() - ${d} > duration('${n.value}')`;if(f===`withinduration`)return`datetime() - ${d} <= duration('${n.value}')`;let p=j(a(e,n.value,c),{retainEmptyStrings:!1}).map(t=>[t,e.toDate(t)]).filter(([,t])=>e.isValid(t)),m=t=>{let n=i(t),r=n?e.toISOStringDateOnly(t):e.toISOString(t);return ie(r,n)};switch(f){case`in`:case`notin`:{if(p.length===0)return``;let e=p.map(([e])=>m(e));return`${N(f)?`NOT `:``}${d} IN [${e.join(`, `)}]`}case`between`:case`notbetween`:{if(p.length<2)return``;let[t,n]=p,[r,i]=e.isBefore(t[1],n[1])?[t,n]:[n,t],a=`${m(r[0])} <= ${d} AND ${d} <= ${m(i[0])}`;return f===`notbetween`?`NOT (${a})`:a}default:{if(p.length===0)return``;let[e]=p[0];return`${d} ${f===`<>`?`<>`:f} ${m(e)}`}}},ae=t=>(n,r)=>{let i=r??{},{context:a={}}=i;if(o(n.valueSource)||!s(a.isDateField,n,i))return d(n,i);let{operator:c,value:l}=e(t,n,i,!0);return d({...n,operator:c,value:l},i)},oe=t=>(n,r)=>{let i=r??{},{context:a={}}=i;if(o(n.valueSource)||!s(a.isDateField,n,i))return f(n,i);let{operator:c,value:l}=e(t,n,i);return f({...n,operator:c,value:l},i)},se=t=>(n,r)=>{let i=r??{},{context:a={}}=i;if(o(n.valueSource)||!s(a.isDateField,n,i))return p(n,i);let{operator:c,value:l}=e(t,n,i);return p({...n,operator:c,value:l},i)},F=e=>/^(does)?not/i.test(e),I=(e,t)=>t?`$not(${e})`:`${e}`,ce=e=>(n,r)=>{let i=r??{},{context:o={}}=i,{quoteFieldNamesWith:c=[``,``],fieldIdentifierSeparator:l=``}=i,{field:u,valueSource:d}=n,f=t(n,i);if(!s(o.isDateField,n,i)||d===`parameter`)return m(n,i);let p=d===`field`,h=p?n.value:a(e,n.value,i),g=e=>`$toMillis(${E(e,{quoteFieldNamesWith:c,fieldIdentifierSeparator:l})})`,_=t=>`$toMillis("${e.toISOString(t)}")`;switch(f){case`<`:case`<=`:case`=`:case`!=`:case`>`:case`>=`:return`${g(u)} ${f} ${p?g(h):_(h)}`}let v=j(h,{retainEmptyStrings:!1}),y=v.map(t=>e.toDate(t)).filter(t=>e.isValid(t));switch(f){case`in`:case`notIn`:return p?v.length===0?``:I(`${g(u)} in [${v.map(e=>g(e)).join(`, `)}]`,F(f)):y.length===0?``:I(`${g(u)} in [${y.map(e=>_(e)).join(`, `)}]`,F(f));case`between`:case`notBetween`:{if(v.length<2||A(v[0])||A(v[1])||!p&&y.length<2)return``;if(p){let[e,t]=v,n=`${g(u)} >= ${g(e)} and ${g(u)} <= ${g(t)}`;return f===`between`?`(${n})`:I(n,!0)}let[t,n]=y,[r,i]=e.isBefore(t,n)?[t,n]:[n,t],a=`${g(u)} >= ${_(r)} and ${g(u)} <= ${_(i)}`;return f===`between`?`(${a})`:I(a,!0)}}return m(n,i)},L=t=>(n,r)=>{let i=r??{},{context:a={}}=i;if(o(n.valueSource)||!s(a.isDateField,n,i))return h(n,i);let{operator:c,value:l}=e(t,n,i);return h({...n,operator:c,value:l},i)},R=e=>(n,r)=>{let i=r??{},{field:c,valueSource:l}=n,u=t(n,i);if(o(l)||!s(i.context?.isDateField,n,i))return g(n,i);let d=a(e,n.value,i);if(u===`=`)return{[c]:e.toDate(d)};switch(u){case`<`:case`<=`:case`!=`:case`>`:case`>=`:return{[c]:{[k[u]]:e.toDate(d)}}}let f=j(d,{retainEmptyStrings:!1}).map(t=>e.toDate(t)).filter(t=>e.isValid(t));switch(u){case`in`:case`notIn`:return{[c]:{[k[u]]:f}};case`between`:case`notBetween`:{if(f.length<2)return``;let[t,n]=f,r=e.isBefore(t,n)?[t,n]:[n,t];return u===`between`?{[c]:{$gte:r[0],$lte:r[1]}}:{$or:[{[c]:{$lt:r[0]}},{[c]:{$gt:r[1]}}]}}}return g(n,i)},z=e=>{let t=R(e);return(e,n)=>{let r=t(e,n);return r?JSON.stringify(r):``}},B={"<":`is before`,">":`is after`,"<=":`is on or before`,">=":`is on or after`,in:[`is one of the dates`,`is the same as a date in`],notin:[`is not one of the dates`,`is not the same as any date in`],between:[`is between`,`is between the dates in`],notbetween:[`is not between`,`is not between the dates in`]},V=(e,t)=>i(t?.context?.originalValue)?new Intl.DateTimeFormat(t?.context?.locales,{dateStyle:`full`,...t?.context?.dateFormat}).format(e.value):new Intl.DateTimeFormat(t?.context?.locales,{dateStyle:`full`,timeStyle:`long`,...t?.context?.dateTimeFormat}).format(e.value),H=e=>(n,r)=>{let i=r??{},l=t(n,i),u=D(l),d=``,{fieldData:f,quoteFieldNamesWith:p=[``,``],fieldIdentifierSeparator:m=``,operatorProcessor:h=c,wordOrder:g=`SVO`,context:v={},operatorMap:y=B}=i;if(!s(v.isDateField,n,i))return _(n,i);if(o(n.valueSource))return _(n,{...i,operatorMap:B});if((u===`in`||u===`notin`||u===`between`||u===`notbetween`)&&!n.value)return``;let b=j(a(e,n.value,i),{retainEmptyStrings:!1}).map(t=>[t,e.toDate(t)]).filter(t=>e.isValid(t[1]));switch(u){case`in`:case`notin`:if(b.length===0)return``;d=`(${b.map(e=>V({field:n.field,operator:`=`,value:e[1]},{...i,context:{...v,originalValue:e[0]}})).join(`, `)})`;break;case`between`:case`notbetween`:{if(b.length<2)return``;let[t,r]=b;d=(e.isBefore(t[1],r[1])?[t,r]:[r,t]).map(([e,t])=>V({field:n.field,operator:`=`,value:t},{...i,context:{...v,originalValue:e}})).join(` ${i.translations?.and??`and`} `)}break;default:{let[e,t]=b[0]??[``,``];d=e?V({field:n.field,operator:`=`,value:t},{...i,context:{...v,originalValue:e}}):``}}let x={S:E(f?.label??n.field,{quoteFieldNamesWith:p,fieldIdentifierSeparator:m}),V:h({...n,operator:l},{...i,operatorMap:{...B,...y}}),O:d};return ee(g).map(e=>`${x[e]}`).join(` `).trim()},U=t=>(n,r,i)=>{let a=r??{},{context:c={}}=a;if(o(n.valueSource)||!s(c.isDateField,n,a))return v(n,a,i);let{operator:l,value:u}=e(t,n,a);return v({...n,operator:l,value:u},a,i)},W=t=>(n,r)=>{let i=r??{},{context:a={}}=i;if(o(n.valueSource)||!s(a.isDateField,n,i))return y(n,i);let{operator:c,value:l}=e(t,n,i,!0);return y({...n,operator:c,value:l},i)},G=t=>(n,r)=>{let i=r??{},{context:a={}}=i;if(o(n.valueSource)||!s(a.isDateField,n,i))return S(n,i);let{operator:c,value:l}=e(t,n,i,!0);return S({...n,operator:c,value:l},i)},le=e=>/^(does)?not/i.test(e),ue=(e,t)=>t?`"${e}"^^xsd:date`:`"${e}"^^xsd:dateTime`,de=e=>(n,r)=>{let c=r??{},{context:l={}}=c;if(o(n.valueSource)||!s(l.isDateField,n,c))return b(n,c);let{field:u,value:d}=n,f=t(n,c),p=te(u),m=D(f);if(m===`olderthanduration`)return`NOW() - ${p} > "${d}"^^xsd:duration`;if(m===`withinduration`)return`NOW() - ${p} <= "${d}"^^xsd:duration`;let h=j(a(e,d,c),{retainEmptyStrings:!1}).map(t=>[t,e.toDate(t)]).filter(([,t])=>e.isValid(t)),g=t=>{let n=i(t),r=n?e.toISOStringDateOnly(t):e.toISOString(t);return ue(r,n)};switch(m){case`in`:case`notin`:{if(h.length===0)return``;let e=h.map(([e])=>g(e));return`${p} ${le(m)?`NOT `:``}IN (${e.join(`, `)})`}case`between`:case`notbetween`:{if(h.length<2)return``;let[t,n]=h,[r,i]=e.isBefore(t[1],n[1])?[t,n]:[n,t];return m===`notbetween`?`(${p} < ${g(r[0])} || ${p} > ${g(i[0])})`:`${p} >= ${g(r[0])} && ${p} <= ${g(i[0])}`}default:{if(h.length===0)return``;let[e]=h[0];return`${p} ${m===`<>`?`!=`:m} ${g(e)}`}}},fe=t=>(n,r)=>{let i=r??{},{context:a={}}=i;if(o(n.valueSource)||!s(a.isDateField,n,i))return C(n,i);let{operator:c,value:l}=e(t,n,i);return C({...n,operator:c,value:l},i)},K=e=>{if(e===`now`)return{bound:`now`};let t=/^(start|end)Of(Day|Week|Month|Year)$/.exec(e);return{bound:t[1],unit:t[2].toLowerCase()}},q=e=>`${e}s`,J=(e,t)=>{let n=t?`current_date`:`current_timestamp`,{bound:r,unit:i}=K(e.anchor),a=n,o=!1;if(r===`start`&&i?(a=`date_trunc('${i}', ${n})`,o=!0):r===`end`&&i&&(a=`date_trunc('${i}', ${n}) + interval '1 ${i}' - ${t?`interval '1 day'`:`interval '1 microsecond'`}`,o=!0),e.offset){let t=e.offset<0?`-`:`+`;a=`${a} ${t} interval '${Math.abs(e.offset)} ${q(e.unit)}'`,o=!0}return t&&o?`cast(${a} as date)`:a},pe=(e,t,n)=>{if(t===`start`)switch(n){case`day`:return`date(${e})`;case`week`:return`date_sub(date(${e}), interval dayofweek(${e}) - 1 day)`;case`month`:return`date_format(${e}, '%Y-%m-01')`;case`year`:return`date_format(${e}, '%Y-01-01')`}switch(n){case`day`:return`date(${e})`;case`week`:return`date_add(date(${e}), interval 7 - dayofweek(${e}) day)`;case`month`:return`last_day(${e})`}return`date_format(${e}, '%Y-12-31')`},me=(e,t)=>{let n=t?`curdate()`:`now()`,{bound:r,unit:i}=K(e.anchor),a=n;return r!==`now`&&i&&(a=pe(n,r,i),r===`end`&&!t&&(a=`date_sub(date_add(${a}, interval 1 day), interval 1 microsecond)`)),e.offset&&(a=`${e.offset<0?`date_sub`:`date_add`}(${a}, interval ${Math.abs(e.offset)} ${e.unit})`),a},he=(e,t,n,r)=>{let i=`dateadd(${n}, datediff(${n}, 0, ${e}), 0)`;if(t===`start`)return i;let a=`dateadd(${n}, datediff(${n}, 0, ${e}) + 1, 0)`;return r?`dateadd(day, -1, ${a})`:`dateadd(nanosecond, -100, cast(${a} as datetime2))`},ge=(e,t)=>{let n=t?`cast(getdate() as date)`:`getdate()`,{bound:r,unit:i}=K(e.anchor),a=n;return r!==`now`&&i&&(a=he(n,r,i,t)),e.offset&&(a=`dateadd(${e.unit}, ${e.offset}, ${a})`),a},_e={day:`DDD`,week:`IW`,month:`MM`,year:`YYYY`},ve=(e,t)=>{let n=t?`trunc(sysdate)`:`systimestamp`,{bound:r,unit:i}=K(e.anchor),a=n,o=!1;if(r!==`now`&&i){let e=`trunc(${n}, '${_e[i]}')`;if(r===`start`)a=e;else{let n=i===`month`||i===`year`?`add_months(${e}, ${i===`month`?1:12})`:`${e} + interval '1' day${i===`week`?` * 7`:``}`;t?a=`${n} - interval '1' second`:(a=n,o=!0)}}if(e.offset)if(e.unit===`month`||e.unit===`year`)a=`add_months(${a}, ${e.offset*(e.unit===`year`?12:1)})`;else{let t={day:1,week:7}[e.unit];a=t?`${a} ${e.offset<0?`-`:`+`} ${Math.abs(e.offset)*t}`:`${a} + numtodsinterval(${e.offset}, '${e.unit.toUpperCase()}')`}return o&&(a=`cast(${a} as timestamp) - numtodsinterval(0.000001, 'second')`),a},ye={day:`'start of day'`,week:`'weekday 0', '-7 days'`,month:`'start of month'`,year:`'start of year'`},be={ansi:J,mssql:ge,mysql:me,oracle:ve,postgresql:J,sqlite:(e,t)=>{let n=t?`date`:`datetime`,r=[`'now'`],{bound:i,unit:a}=K(e.anchor);if(i!==`now`&&a)if(i===`start`)r.push(ye[a]);else switch(a){case`day`:r.push(`'start of day'`,`'+1 day'`,t?`'-1 day'`:`'-1 second'`);break;case`week`:r.push(`'weekday 0'`,t?`'-1 day'`:`'-1 second'`);break;case`month`:r.push(`'start of month'`,`'+1 month'`,t?`'-1 day'`:`'-1 second'`);break;case`year`:r.push(`'start of year'`,`'+1 year'`,t?`'-1 day'`:`'-1 second'`);break}if(e.offset){let t=e.offset<0?`-`:`+`;r.push(`'${t}${Math.abs(e.offset)} ${q(e.unit)}'`)}return`${n}(${r.join(`, `)})`}},xe=(e,t)=>{let n=t;switch(e){case`mssql`:return!/^(?:small)?datetime/i.test(n);case`mysql`:return!/^(?:datetime|timestamp)/i.test(n);case`oracle`:case`postgresql`:return!/^timestamp/i.test(n);default:return!/^(?:datetime|timestamp)/i.test(n)}},Se=(e,t,n)=>be[t](e,xe(t,n)),Y=({toISOStringDateOnly:e,toISOString:t})=>(n,r)=>i(r?.context?.originalValue)?T({...n,value:e(n.value)},r):T({...n,value:t(n.value)},r),X=({toISOStringDateOnly:e,toISOString:t})=>(n,r)=>{let i=/^(?:small)?datetime/i.test(r?.fieldData?.datatype)?`datetimeoffset`:`date`,a=i===`datetimeoffset`?t(n.value):e(n.value);return T({...n,value:a},{...r,wrapValueWith:[`cast(`,` as ${i})`]})},Z=({toISOStringDateOnly:e,toISOString:t})=>(n,r)=>{let i=/^(?:datetime|timestamp)/i.test(r?.fieldData?.datatype)?`datetime`:`date`,a=i===`datetime`?t(n.value):e(n.value);return T({...n,value:a},{...r,wrapValueWith:[`cast(`,` as ${i})`]})},Q=({toISOStringDateOnly:e,toISOString:t})=>(n,r)=>{let i=/^timestamp/i.test(r?.fieldData?.datatype)?`timestamp`:`date`,a=i===`timestamp`?t(n.value).replaceAll(`T`,` `).replace(`Z`,` UTC`):e(n.value);return T({...n,value:a},{...r,wrapValueWith:[i,``]})},$=({toISOStringDateOnly:e,toISOString:t})=>(n,r)=>{let i=/^timestamp/i.test(r?.fieldData?.datatype)?`timestamp`:`date`,a=i===`timestamp`?t(n.value):e(n.value);return T({...n,value:a},{...r,wrapValueWith:[i,``]})},Ce={ansi:Y,mssql:X,mysql:Z,oracle:Q,postgresql:$,sqlite:Y},we=e=>(r,i)=>{let c=i??{},l=O(t(r,c)),u=D(l),{quoteFieldNamesWith:d=[``,``],fieldIdentifierSeparator:f=``,context:p={}}=c,m=``;if(o(r.valueSource)||!s(p.isDateField,r,c))return x(r,c);let h=Ce[c.preset](e),g=E(r.field,{quoteFieldNamesWith:d,fieldIdentifierSeparator:f}),_=p.materializeRelativeDateTime?a(e,r.value,c):r.value,v=Array.isArray(_)?_:[_];if(v.some(n)){let t=t=>{if(n(t))return Se(t,c.preset,c.fieldData?.datatype);let i=e.toDate(t);if(e.isValid(i))return h({field:r.field,operator:`=`,value:i},{...c,context:{originalValue:t}})};switch(u){case`in`:case`not in`:{let e=v.map(t).filter(e=>e!==void 0);if(e.length===0)return``;m=`(${e.join(`, `)})`;break}case`between`:case`not between`:{let e=t(v[0]),n=t(v[1]);if(e===void 0||n===void 0)return``;m=`${e} and ${n}`;break}default:{let e=t(v[0]);if(e===void 0)return``;m=e}}return`${g} ${l} ${m}`.trim()}let y=j(_,{retainEmptyStrings:!1}).map(t=>[t,e.toDate(t)]).filter(t=>e.isValid(t[1]));switch(u){case`in`:case`not in`:if(y.length===0)return``;m=`(${y.map(e=>h({field:r.field,operator:`=`,value:e[1]},{...c,context:{originalValue:e[0]}})).join(`, `)})`;break;case`between`:case`not between`:{if(y.length<2)return``;let[t,n]=y;m=(e.isBefore(t[1],n[1])?[t,n]:[n,t]).map(([e,t])=>h({field:r.field,operator:`=`,value:t},{...c,context:{originalValue:e}})).join(` and `)}break;default:{let[e,t]=y[0]??[``,``];m=h({field:r.field,operator:`=`,value:t},{...c,context:{originalValue:e}})}}return`${g} ${l} ${m}`.trim()},Te=t=>(n,r)=>{let i=r??{},{context:a={}}=i;if(o(n.valueSource)||!s(a.isDateField,n,i))return w(n,i);let{operator:c,value:l}=e(t,n,i,!0);return w({...n,operator:c,value:l},i)};export{P as C,ae as S,ne as T,R as _,Z as a,se as b,fe as c,W as d,U as f,z as g,H as h,X as i,de as l,B as m,we as n,Q as o,V as p,Y as r,$ as s,Te as t,G as u,L as v,M as w,oe as x,ce as y};
|
|
2
|
+
//# sourceMappingURL=getDatetimeRuleProcessorTanStackDB-6K1DsuEV.mjs.map
|