@react-querybuilder/datetime 8.18.0 → 8.19.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/dist/cjs/getDatetimeRuleProcessorTanStackDB-CL79A1_x.js +1208 -0
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-CL79A1_x.js.map +1 -0
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-DgUg_arY.js +2 -0
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-DgUg_arY.js.map +1 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.development.d.ts +214 -8
- package/dist/cjs/react-querybuilder_datetime.cjs.development.date-fns.d.ts +46 -2
- package/dist/cjs/react-querybuilder_datetime.cjs.development.date-fns.js +93 -15
- 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 +46 -2
- package/dist/cjs/react-querybuilder_datetime.cjs.development.dayjs.js +70 -59
- package/dist/cjs/react-querybuilder_datetime.cjs.development.dayjs.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.development.js +482 -71
- package/dist/cjs/react-querybuilder_datetime.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.development.jsdate.d.ts +46 -2
- package/dist/cjs/react-querybuilder_datetime.cjs.development.jsdate.js +129 -15
- package/dist/cjs/react-querybuilder_datetime.cjs.development.jsdate.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.development.luxon.d.ts +46 -2
- package/dist/cjs/react-querybuilder_datetime.cjs.development.luxon.js +81 -15
- package/dist/cjs/react-querybuilder_datetime.cjs.development.luxon.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.production.d.ts +214 -8
- package/dist/cjs/react-querybuilder_datetime.cjs.production.date-fns.d.ts +46 -2
- 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 +46 -2
- 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 +46 -2
- 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 +46 -2
- 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/rqbDateTimeLibraryAPI.dayjs-BfILPx88.js +2 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.dayjs-BfILPx88.js.map +1 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.dayjs-CzLh_zi9.js +63 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.dayjs-CzLh_zi9.js.map +1 -0
- package/dist/cjs/types-XYMw0jFT.d.ts +265 -0
- package/dist/datetime-layout.css +1 -0
- package/dist/datetime-layout.css.map +1 -0
- package/dist/datetime-layout.scss +3 -0
- package/dist/datetime.css +1 -0
- package/dist/datetime.css.map +1 -0
- package/dist/datetime.scss +1 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-BcOC-o2A.mjs +1029 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-BcOC-o2A.mjs.map +1 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-Dloxv6k2.mjs +2 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-Dloxv6k2.mjs.map +1 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-LDwhMJg0.js +1035 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-LDwhMJg0.js.map +1 -0
- package/dist/react-querybuilder_datetime.d.mts +214 -8
- package/dist/react-querybuilder_datetime.date-fns.d.mts +46 -2
- package/dist/react-querybuilder_datetime.date-fns.mjs +71 -4
- package/dist/react-querybuilder_datetime.date-fns.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.dayjs.d.mts +46 -2
- package/dist/react-querybuilder_datetime.dayjs.mjs +47 -24
- package/dist/react-querybuilder_datetime.dayjs.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.jsdate.d.mts +46 -2
- package/dist/react-querybuilder_datetime.jsdate.mjs +106 -3
- package/dist/react-querybuilder_datetime.jsdate.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.d.ts +214 -8
- package/dist/react-querybuilder_datetime.legacy-esm.date-fns.d.ts +46 -2
- package/dist/react-querybuilder_datetime.legacy-esm.date-fns.js +71 -4
- package/dist/react-querybuilder_datetime.legacy-esm.date-fns.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.dayjs.d.ts +46 -2
- package/dist/react-querybuilder_datetime.legacy-esm.dayjs.js +47 -24
- package/dist/react-querybuilder_datetime.legacy-esm.dayjs.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.js +425 -58
- package/dist/react-querybuilder_datetime.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.jsdate.d.ts +46 -2
- package/dist/react-querybuilder_datetime.legacy-esm.jsdate.js +106 -3
- package/dist/react-querybuilder_datetime.legacy-esm.jsdate.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.luxon.d.ts +46 -2
- package/dist/react-querybuilder_datetime.legacy-esm.luxon.js +58 -3
- package/dist/react-querybuilder_datetime.legacy-esm.luxon.js.map +1 -1
- package/dist/react-querybuilder_datetime.luxon.d.mts +46 -2
- package/dist/react-querybuilder_datetime.luxon.mjs +58 -3
- package/dist/react-querybuilder_datetime.luxon.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.mjs +443 -57
- package/dist/react-querybuilder_datetime.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.production.d.mts +214 -8
- package/dist/react-querybuilder_datetime.production.date-fns.d.mts +46 -2
- 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 +46 -2
- 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 +46 -2
- 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 +46 -2
- 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/rqbDateTimeLibraryAPI.dayjs-BW7faYFD.mjs +29 -0
- package/dist/rqbDateTimeLibraryAPI.dayjs-BW7faYFD.mjs.map +1 -0
- package/dist/rqbDateTimeLibraryAPI.dayjs-BoX90aqZ.mjs +2 -0
- package/dist/rqbDateTimeLibraryAPI.dayjs-BoX90aqZ.mjs.map +1 -0
- package/dist/rqbDateTimeLibraryAPI.dayjs-DvFSxPKu.js +29 -0
- package/dist/rqbDateTimeLibraryAPI.dayjs-DvFSxPKu.js.map +1 -0
- package/dist/styles/_layout.scss +30 -0
- package/dist/styles/_root.scss +5 -0
- package/dist/styles/_variables.scss +8 -0
- package/dist/types-CdjHqQ0k.d.mts +265 -0
- package/dist/types-CdjHqQ0k.d.ts +265 -0
- package/package.json +27 -12
- package/dist/cjs/getDatetimeRuleProcessorSQL-Cca9pzSn.js +0 -2
- package/dist/cjs/getDatetimeRuleProcessorSQL-Cca9pzSn.js.map +0 -1
- package/dist/cjs/getDatetimeRuleProcessorSQL-CrA2ZrSe.js +0 -563
- package/dist/cjs/getDatetimeRuleProcessorSQL-CrA2ZrSe.js.map +0 -1
- package/dist/cjs/types-c6_k1Tpr.d.ts +0 -105
- package/dist/getDatetimeRuleProcessorSQL-Crw01Jo-.js +0 -482
- package/dist/getDatetimeRuleProcessorSQL-Crw01Jo-.js.map +0 -1
- package/dist/getDatetimeRuleProcessorSQL-CvGKzojM.mjs +0 -2
- package/dist/getDatetimeRuleProcessorSQL-CvGKzojM.mjs.map +0 -1
- package/dist/getDatetimeRuleProcessorSQL-Nz_XjNeY.mjs +0 -468
- package/dist/getDatetimeRuleProcessorSQL-Nz_XjNeY.mjs.map +0 -1
- package/dist/types-c6_k1Tpr.d.mts +0 -105
- package/dist/types-c6_k1Tpr.d.ts +0 -105
|
@@ -0,0 +1,1035 @@
|
|
|
1
|
+
import { defaultOperatorProcessorNL, defaultRuleProcessorCEL, defaultRuleProcessorCypher, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorGremlin, defaultRuleProcessorJSONata, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSPARQL, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultRuleProcessorTanStackDB, defaultValueProcessorByRule, getQuotedFieldName, lc, mapSQLOperator, mongoOperators, normalizeConstituentWordOrder, nullOrUndefinedOrEmpty, sparqlVar, toArray } from "react-querybuilder";
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
const isISOStringDateOnly = (date) => typeof date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(date);
|
|
4
|
+
/**
|
|
5
|
+
* Type guard for {@link RelativeDateTimeValue}. Relative values are stored as objects
|
|
6
|
+
* (distinguishing them from the ISO 8601 strings used for absolute date/time values).
|
|
7
|
+
*/
|
|
8
|
+
const isRelativeDateTimeValue = (value) => typeof value === "object" && value !== null && value.mode === "relative" && typeof value.anchor === "string";
|
|
9
|
+
const anchorRegExp = /^(start|end)Of(Day|Week|Month|Year)$/;
|
|
10
|
+
/**
|
|
11
|
+
* Resolves a {@link RelativeDateTimeValue} into a concrete `Date` using the given
|
|
12
|
+
* date library API. The anchor is applied relative to `base` (defaulting to now),
|
|
13
|
+
* then the signed offset is added.
|
|
14
|
+
*/
|
|
15
|
+
const resolveRelativeDateTime = (apiFns, value, base = /* @__PURE__ */ new Date()) => {
|
|
16
|
+
let result = base;
|
|
17
|
+
if (value.anchor !== "now") {
|
|
18
|
+
const match = anchorRegExp.exec(value.anchor);
|
|
19
|
+
// v8 ignore next -- guarded by the RelativeDateTimeAnchor type
|
|
20
|
+
if (match) {
|
|
21
|
+
const unit = match[2].toLowerCase();
|
|
22
|
+
result = match[1] === "start" ? apiFns.startOf(result, unit) : apiFns.endOf(result, unit);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (value.offset) result = apiFns.add(result, value.offset, value.unit);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Whether a `datatype` represents a date-only (no time component) type, e.g. `date`
|
|
30
|
+
* but not `datetime`/`datetimeoffset`/`timestamp`. Used to choose the precision when
|
|
31
|
+
* materializing a relative value to an ISO 8601 string.
|
|
32
|
+
*/
|
|
33
|
+
const isDateOnlyDatatype = (datatype) => /^date\b/i.test(datatype);
|
|
34
|
+
/**
|
|
35
|
+
* Replaces any {@link RelativeDateTimeValue} in `value` (or in each element, if `value`
|
|
36
|
+
* is an array) with a concrete ISO 8601 string, resolved via
|
|
37
|
+
* {@link resolveRelativeDateTime}. The "now" reference can be pinned with
|
|
38
|
+
* `opts.context.relativeDateTimeBase` for deterministic output; precision (date-only vs
|
|
39
|
+
* full) follows the field's `datatype`. Non-relative values pass through unchanged.
|
|
40
|
+
*/
|
|
41
|
+
const materializeRelativeValues = (apiFns, value, opts) => {
|
|
42
|
+
var _opts$context, _opts$fieldData;
|
|
43
|
+
const base = opts === null || opts === void 0 || (_opts$context = opts.context) === null || _opts$context === void 0 ? void 0 : _opts$context.relativeDateTimeBase;
|
|
44
|
+
const dateOnly = isDateOnlyDatatype(opts === null || opts === void 0 || (_opts$fieldData = opts.fieldData) === null || _opts$fieldData === void 0 ? void 0 : _opts$fieldData.datatype);
|
|
45
|
+
const conv = (v) => {
|
|
46
|
+
if (!isRelativeDateTimeValue(v)) return v;
|
|
47
|
+
const resolved = resolveRelativeDateTime(apiFns, v, base);
|
|
48
|
+
return dateOnly ? apiFns.toISOStringDateOnly(resolved) : apiFns.toISOString(resolved);
|
|
49
|
+
};
|
|
50
|
+
return Array.isArray(value) ? value.map(conv) : conv(value);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Resolves a rule's operator for export, applying any `context.relativeOperatorMap`
|
|
54
|
+
* entry. Operator-driven mode controllers (see `createOperatorModeController`) use
|
|
55
|
+
* dedicated operator names to signal relative mode; this maps those names to the real
|
|
56
|
+
* comparison operator at format time. Operators absent from the map pass through unchanged.
|
|
57
|
+
*/
|
|
58
|
+
const resolveDatetimeOperator = (...[rule, opts]) => {
|
|
59
|
+
var _rule$operator, _opts$context2;
|
|
60
|
+
return (_rule$operator = opts === null || opts === void 0 || (_opts$context2 = opts.context) === null || _opts$context2 === void 0 || (_opts$context2 = _opts$context2.relativeOperatorMap) === null || _opts$context2 === void 0 ? void 0 : _opts$context2[rule.operator]) !== null && _rule$operator !== void 0 ? _rule$operator : rule.operator;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Prepares a date/time rule for delegation to a non-symbolic default rule processor
|
|
64
|
+
* (e.g. "parameterized", "spel", "ldap", "gremlin", "prisma", "sequelize", "drizzle",
|
|
65
|
+
* "tanstack_db"). Relative values are materialized to concrete dates (these formats have
|
|
66
|
+
* no symbolic relative form), and `between`/`notBetween` operands are ordered
|
|
67
|
+
* chronologically (defaults can't reorder non-numeric date operands). When `asDate` is
|
|
68
|
+
* set, each valid value is converted to a `Date` (for object-based formats); otherwise
|
|
69
|
+
* the materialized ISO 8601 strings are passed through. The resolved `operator` (after
|
|
70
|
+
* any `relativeOperatorMap` mapping) is returned alongside the prepared `value`.
|
|
71
|
+
*/
|
|
72
|
+
const materializeForExport = (apiFns, rule, opts, asDate = false) => {
|
|
73
|
+
const operator = resolveDatetimeOperator(rule, opts);
|
|
74
|
+
const materialized = materializeRelativeValues(apiFns, rule.value, opts);
|
|
75
|
+
let prepared = materialized;
|
|
76
|
+
if (Array.isArray(materialized) && materialized.length >= 2) {
|
|
77
|
+
const opLC = operator.toLowerCase();
|
|
78
|
+
if (opLC === "between" || opLC === "notbetween") {
|
|
79
|
+
const first = apiFns.toDate(materialized[0]);
|
|
80
|
+
const second = apiFns.toDate(materialized[1]);
|
|
81
|
+
if (apiFns.isValid(first) && apiFns.isValid(second) && !apiFns.isBefore(first, second)) prepared = [
|
|
82
|
+
materialized[1],
|
|
83
|
+
materialized[0],
|
|
84
|
+
...materialized.slice(2)
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!asDate) return {
|
|
89
|
+
operator,
|
|
90
|
+
value: prepared
|
|
91
|
+
};
|
|
92
|
+
const toDateVal = (v) => {
|
|
93
|
+
const d = apiFns.toDate(v);
|
|
94
|
+
return apiFns.isValid(d) ? d : v;
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
operator,
|
|
98
|
+
value: Array.isArray(prepared) ? prepared.map(toDateVal) : toDateVal(prepared)
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const defaultIsDateField = (...[rule, opts]) => {
|
|
102
|
+
var _opts$fieldData2;
|
|
103
|
+
return 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 === null || opts === void 0 || (_opts$fieldData2 = opts.fieldData) === null || _opts$fieldData2 === void 0 ? void 0 : _opts$fieldData2.datatype);
|
|
104
|
+
};
|
|
105
|
+
const processIsDateField = (isDateField, ...[rule, opts]) => {
|
|
106
|
+
if (typeof isDateField === "boolean") return isDateField;
|
|
107
|
+
if (typeof isDateField === "function") return isDateField(rule, opts);
|
|
108
|
+
if (Array.isArray(isDateField)) return isDateField.some((condition) => Object.entries(condition).every(([key, value]) => {
|
|
109
|
+
var _opts$fieldData3;
|
|
110
|
+
return (opts === null || opts === void 0 || (_opts$fieldData3 = opts.fieldData) === null || _opts$fieldData3 === void 0 ? void 0 : _opts$fieldData3[key]) === value;
|
|
111
|
+
}));
|
|
112
|
+
if (typeof isDateField === "object") return Object.entries(isDateField).every(([key, value]) => {
|
|
113
|
+
var _opts$fieldData4;
|
|
114
|
+
return (opts === null || opts === void 0 || (_opts$fieldData4 = opts.fieldData) === null || _opts$fieldData4 === void 0 ? void 0 : _opts$fieldData4[key]) === value;
|
|
115
|
+
});
|
|
116
|
+
return defaultIsDateField(rule, opts);
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/getDatetimeJsonLogicOperations.ts
|
|
120
|
+
/**
|
|
121
|
+
* Custom operations for use with JsonLogic objects generated by
|
|
122
|
+
* {@link datetimeRuleProcessorJsonLogic}.
|
|
123
|
+
*/
|
|
124
|
+
const getDatetimeJsonLogicOperations = (apiFns) => {
|
|
125
|
+
const { isAfter, isBefore, isSame } = apiFns;
|
|
126
|
+
return {
|
|
127
|
+
dateAfter: (a, b) => isAfter(a, b),
|
|
128
|
+
dateBefore: (a, b) => isBefore(a, b),
|
|
129
|
+
dateBetween: (a, b, c) => isSame(b, a) || isSame(b, c) || isAfter(b, a) && isBefore(b, c) || isAfter(b, c) && isBefore(b, a),
|
|
130
|
+
dateNotBetween: (a, b, c) => !isSame(b, a) && !isSame(b, c) && (isBefore(a, c) && (isBefore(b, a) || isAfter(b, c)) || isAfter(a, c) && (isBefore(b, c) || isAfter(b, a))),
|
|
131
|
+
dateIn: (a, b) => b.some((v) => isSame(a, v)),
|
|
132
|
+
dateNotIn: (a, b) => b.every((v) => !isSame(a, v)),
|
|
133
|
+
dateNotOn: (a, b) => !isSame(a, b),
|
|
134
|
+
dateOn: (a, b) => isSame(a, b),
|
|
135
|
+
dateOnOrAfter: (a, b) => isAfter(a, b) || isSame(a, b),
|
|
136
|
+
dateOnOrBefore: (a, b) => isBefore(a, b) || isSame(a, b),
|
|
137
|
+
dateRelative: (anchor, offset, unit, dateOnly) => {
|
|
138
|
+
const resolved = resolveRelativeDateTime(apiFns, {
|
|
139
|
+
mode: "relative",
|
|
140
|
+
anchor,
|
|
141
|
+
offset,
|
|
142
|
+
unit
|
|
143
|
+
});
|
|
144
|
+
return dateOnly ? apiFns.toISOStringDateOnly(resolved) : apiFns.toISOString(resolved);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/getDatetimeRuleProcessorCEL.ts
|
|
150
|
+
const shouldNegate$3 = (op) => /^(does)?not/i.test(op);
|
|
151
|
+
/**
|
|
152
|
+
* Generates a rule processor with date/time features for use by
|
|
153
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "cel" format.
|
|
154
|
+
*/
|
|
155
|
+
const getDatetimeRuleProcessorCEL = (apiFns) => (rule, options) => {
|
|
156
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
157
|
+
const { context = {} } = opts;
|
|
158
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorCEL(rule, opts);
|
|
159
|
+
const ts = (d) => `timestamp("${apiFns.toISOString(d)}")`;
|
|
160
|
+
const value = materializeRelativeValues(apiFns, rule.value, opts);
|
|
161
|
+
const operatorTL = lc(resolveDatetimeOperator(rule, opts).replace(/^=$/, "=="));
|
|
162
|
+
switch (operatorTL) {
|
|
163
|
+
case "<":
|
|
164
|
+
case "<=":
|
|
165
|
+
case "==":
|
|
166
|
+
case "!=":
|
|
167
|
+
case ">":
|
|
168
|
+
case ">=": return `${rule.field} ${operatorTL} ${ts(value)}`;
|
|
169
|
+
}
|
|
170
|
+
const valueAsDateArray = toArray(value, { retainEmptyStrings: false }).map((v) => apiFns.toDate(v)).filter((dateVal) => apiFns.isValid(dateVal));
|
|
171
|
+
switch (operatorTL) {
|
|
172
|
+
case "in":
|
|
173
|
+
case "notin": {
|
|
174
|
+
if (valueAsDateArray.length === 0) return "";
|
|
175
|
+
const [prefix, suffix] = shouldNegate$3(operatorTL) ? ["!(", ")"] : ["", ""];
|
|
176
|
+
return `${prefix}${rule.field} in [${valueAsDateArray.map((val) => ts(val)).join(", ")}]${suffix}`;
|
|
177
|
+
}
|
|
178
|
+
case "between":
|
|
179
|
+
case "notbetween": {
|
|
180
|
+
if (valueAsDateArray.length < 2) return "";
|
|
181
|
+
const [first, second] = valueAsDateArray;
|
|
182
|
+
const [firstDate, secondDate] = apiFns.isBefore(first, second) ? [first, second] : [second, first];
|
|
183
|
+
return operatorTL === "between" ? `(${rule.field} >= ${ts(firstDate)} && ${rule.field} <= ${ts(secondDate)})` : `(${rule.field} < ${ts(firstDate)} || ${rule.field} > ${ts(secondDate)})`;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return defaultRuleProcessorCEL(rule, opts);
|
|
187
|
+
};
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/getDatetimeRuleProcessorCypher.ts
|
|
190
|
+
const shouldNegate$2 = (op) => /^(does)?not/i.test(op);
|
|
191
|
+
/**
|
|
192
|
+
* Wraps a date string in the appropriate Cypher temporal constructor.
|
|
193
|
+
* - Date-only strings (YYYY-MM-DD) become `date('...')`
|
|
194
|
+
* - Full ISO strings become `datetime('...')`
|
|
195
|
+
*/
|
|
196
|
+
const cypherTemporal = (iso, dateOnly) => dateOnly ? `date('${iso}')` : `datetime('${iso}')`;
|
|
197
|
+
/**
|
|
198
|
+
* Generates a rule processor with date/time features for use by
|
|
199
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "cypher" or "gql" format.
|
|
200
|
+
*
|
|
201
|
+
* Supports:
|
|
202
|
+
* - Standard comparison operators (`=`, `!=`, `<`, `>`, `<=`, `>=`)
|
|
203
|
+
* - Range operators (between, notBetween, in, notIn)
|
|
204
|
+
* - Duration math via custom operators: `olderThanDuration` and `withinDuration`
|
|
205
|
+
* (e.g., value `"P30D"` → `datetime() - field > duration('P30D')`)
|
|
206
|
+
*/
|
|
207
|
+
const getDatetimeRuleProcessorCypher = (apiFns) => (rule, options) => {
|
|
208
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
209
|
+
const { context = {} } = opts;
|
|
210
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorCypher(rule, opts);
|
|
211
|
+
const { field } = rule;
|
|
212
|
+
const operatorTL = lc(resolveDatetimeOperator(rule, opts));
|
|
213
|
+
if (operatorTL === "olderthanduration") return `datetime() - ${field} > duration('${rule.value}')`;
|
|
214
|
+
if (operatorTL === "withinduration") return `datetime() - ${field} <= duration('${rule.value}')`;
|
|
215
|
+
const valueAsDateArray = toArray(materializeRelativeValues(apiFns, rule.value, opts), { retainEmptyStrings: false }).map((v) => [v, apiFns.toDate(v)]).filter(([, d]) => apiFns.isValid(d));
|
|
216
|
+
const fmtDate = (originalValue) => {
|
|
217
|
+
const dateOnly = isISOStringDateOnly(originalValue);
|
|
218
|
+
return cypherTemporal(dateOnly ? apiFns.toISOStringDateOnly(originalValue) : apiFns.toISOString(originalValue), dateOnly);
|
|
219
|
+
};
|
|
220
|
+
switch (operatorTL) {
|
|
221
|
+
case "in":
|
|
222
|
+
case "notin": {
|
|
223
|
+
if (valueAsDateArray.length === 0) return "";
|
|
224
|
+
const items = valueAsDateArray.map(([orig]) => fmtDate(orig));
|
|
225
|
+
return `${shouldNegate$2(operatorTL) ? "NOT " : ""}${field} IN [${items.join(", ")}]`;
|
|
226
|
+
}
|
|
227
|
+
case "between":
|
|
228
|
+
case "notbetween": {
|
|
229
|
+
if (valueAsDateArray.length < 2) return "";
|
|
230
|
+
const [first, second] = valueAsDateArray;
|
|
231
|
+
const [lo, hi] = apiFns.isBefore(first[1], second[1]) ? [first, second] : [second, first];
|
|
232
|
+
const expr = `${fmtDate(lo[0])} <= ${field} AND ${field} <= ${fmtDate(hi[0])}`;
|
|
233
|
+
return operatorTL === "notbetween" ? `NOT (${expr})` : expr;
|
|
234
|
+
}
|
|
235
|
+
default: {
|
|
236
|
+
if (valueAsDateArray.length === 0) return "";
|
|
237
|
+
const [orig] = valueAsDateArray[0];
|
|
238
|
+
return `${field} ${operatorTL === "<>" ? "<>" : operatorTL} ${fmtDate(orig)}`;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
|
|
244
|
+
function _typeof(o) {
|
|
245
|
+
"@babel/helpers - typeof";
|
|
246
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
247
|
+
return typeof o;
|
|
248
|
+
} : function(o) {
|
|
249
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
250
|
+
}, _typeof(o);
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
|
|
254
|
+
function toPrimitive(t, r) {
|
|
255
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
256
|
+
var e = t[Symbol.toPrimitive];
|
|
257
|
+
if (void 0 !== e) {
|
|
258
|
+
var i = e.call(t, r || "default");
|
|
259
|
+
if ("object" != _typeof(i)) return i;
|
|
260
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
261
|
+
}
|
|
262
|
+
return ("string" === r ? String : Number)(t);
|
|
263
|
+
}
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
|
|
266
|
+
function toPropertyKey(t) {
|
|
267
|
+
var i = toPrimitive(t, "string");
|
|
268
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
|
|
272
|
+
function _defineProperty(e, r, t) {
|
|
273
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
274
|
+
value: t,
|
|
275
|
+
enumerable: !0,
|
|
276
|
+
configurable: !0,
|
|
277
|
+
writable: !0
|
|
278
|
+
}) : e[r] = t, e;
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region \0@oxc-project+runtime@0.134.0/helpers/esm/objectSpread2.js
|
|
282
|
+
function ownKeys(e, r) {
|
|
283
|
+
var t = Object.keys(e);
|
|
284
|
+
if (Object.getOwnPropertySymbols) {
|
|
285
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
286
|
+
r && (o = o.filter(function(r) {
|
|
287
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
288
|
+
})), t.push.apply(t, o);
|
|
289
|
+
}
|
|
290
|
+
return t;
|
|
291
|
+
}
|
|
292
|
+
function _objectSpread2(e) {
|
|
293
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
294
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
295
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
296
|
+
_defineProperty(e, r, t[r]);
|
|
297
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
298
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
return e;
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/getDatetimeRuleProcessorDrizzle.ts
|
|
305
|
+
/**
|
|
306
|
+
* Generates a rule processor with date/time features for use by
|
|
307
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "drizzle" format.
|
|
308
|
+
* Relative values are materialized and all date/time values are converted to `Date`
|
|
309
|
+
* objects (Drizzle column operators compare against native `Date` values).
|
|
310
|
+
*/
|
|
311
|
+
const getDatetimeRuleProcessorDrizzle = (apiFns) => (rule, options) => {
|
|
312
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
313
|
+
const { context = {} } = opts;
|
|
314
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorDrizzle(rule, opts);
|
|
315
|
+
const { operator, value } = materializeForExport(apiFns, rule, opts, true);
|
|
316
|
+
return defaultRuleProcessorDrizzle(_objectSpread2(_objectSpread2({}, rule), {}, {
|
|
317
|
+
operator,
|
|
318
|
+
value
|
|
319
|
+
}), opts);
|
|
320
|
+
};
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/getDatetimeRuleProcessorElasticSearch.ts
|
|
323
|
+
/**
|
|
324
|
+
* Generates a rule processor with date/time features for use by
|
|
325
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "elasticsearch" format.
|
|
326
|
+
* Relative values are materialized to concrete ISO 8601 strings (ElasticSearch has no
|
|
327
|
+
* symbolic relative form); absolute values pass through.
|
|
328
|
+
*/
|
|
329
|
+
const getDatetimeRuleProcessorElasticSearch = (apiFns) => (rule, options) => {
|
|
330
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
331
|
+
const { context = {} } = opts;
|
|
332
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorElasticSearch(rule, opts);
|
|
333
|
+
const { operator, value } = materializeForExport(apiFns, rule, opts);
|
|
334
|
+
return defaultRuleProcessorElasticSearch(_objectSpread2(_objectSpread2({}, rule), {}, {
|
|
335
|
+
operator,
|
|
336
|
+
value
|
|
337
|
+
}), opts);
|
|
338
|
+
};
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/getDatetimeRuleProcessorGremlin.ts
|
|
341
|
+
/**
|
|
342
|
+
* Generates a rule processor with date/time features for use by
|
|
343
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "gremlin" format.
|
|
344
|
+
* Relative values are materialized to concrete ISO 8601 strings (Gremlin has no symbolic
|
|
345
|
+
* relative form); absolute values pass through.
|
|
346
|
+
*/
|
|
347
|
+
const getDatetimeRuleProcessorGremlin = (apiFns) => (rule, options) => {
|
|
348
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
349
|
+
const { context = {} } = opts;
|
|
350
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorGremlin(rule, opts);
|
|
351
|
+
const { operator, value } = materializeForExport(apiFns, rule, opts);
|
|
352
|
+
return defaultRuleProcessorGremlin(_objectSpread2(_objectSpread2({}, rule), {}, {
|
|
353
|
+
operator,
|
|
354
|
+
value
|
|
355
|
+
}), opts);
|
|
356
|
+
};
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/getDatetimeRuleProcessorJSONata.ts
|
|
359
|
+
const shouldNegate$1 = (op) => /^(does)?not/i.test(op);
|
|
360
|
+
const negate = (clause, neg) => neg ? `$not(${clause})` : `${clause}`;
|
|
361
|
+
/**
|
|
362
|
+
* Generates a rule processor with date/time features for use by
|
|
363
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "jsonata" format.
|
|
364
|
+
*/
|
|
365
|
+
const getDatetimeRuleProcessorJSONata = (apiFns) => (rule, options) => {
|
|
366
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
367
|
+
const { context = {} } = opts;
|
|
368
|
+
// v8 ignore next
|
|
369
|
+
const { quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "" } = opts;
|
|
370
|
+
const { field, valueSource } = rule;
|
|
371
|
+
const operator = resolveDatetimeOperator(rule, opts);
|
|
372
|
+
if (!processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorJSONata(rule, opts);
|
|
373
|
+
const valueIsField = valueSource === "field";
|
|
374
|
+
const value = valueIsField ? rule.value : materializeRelativeValues(apiFns, rule.value, opts);
|
|
375
|
+
const fldToMs = (f) => `$toMillis(${getQuotedFieldName(f, {
|
|
376
|
+
quoteFieldNamesWith,
|
|
377
|
+
fieldIdentifierSeparator
|
|
378
|
+
})})`;
|
|
379
|
+
const valToMs = (v) => `$toMillis("${apiFns.toISOString(v)}")`;
|
|
380
|
+
switch (operator) {
|
|
381
|
+
case "<":
|
|
382
|
+
case "<=":
|
|
383
|
+
case "=":
|
|
384
|
+
case "!=":
|
|
385
|
+
case ">":
|
|
386
|
+
case ">=": return `${fldToMs(field)} ${operator} ${valueIsField ? fldToMs(value) : valToMs(value)}`;
|
|
387
|
+
}
|
|
388
|
+
const valueAsArray = toArray(value, { retainEmptyStrings: false });
|
|
389
|
+
const valueAsDateArray = valueAsArray.map((v) => apiFns.toDate(v)).filter((dateVal) => apiFns.isValid(dateVal));
|
|
390
|
+
switch (operator) {
|
|
391
|
+
case "in":
|
|
392
|
+
case "notIn":
|
|
393
|
+
if (valueIsField) {
|
|
394
|
+
if (valueAsArray.length === 0) return "";
|
|
395
|
+
return negate(`${fldToMs(field)} in [${valueAsArray.map((val) => fldToMs(val)).join(", ")}]`, shouldNegate$1(operator));
|
|
396
|
+
}
|
|
397
|
+
if (valueAsDateArray.length === 0) return "";
|
|
398
|
+
return negate(`${fldToMs(field)} in [${valueAsDateArray.map((val) => valToMs(val)).join(", ")}]`, shouldNegate$1(operator));
|
|
399
|
+
case "between":
|
|
400
|
+
case "notBetween": {
|
|
401
|
+
if (valueAsArray.length < 2 || nullOrUndefinedOrEmpty(valueAsArray[0]) || nullOrUndefinedOrEmpty(valueAsArray[1]) || !valueIsField && valueAsDateArray.length < 2) return "";
|
|
402
|
+
if (valueIsField) {
|
|
403
|
+
const [firstValue, secondValue] = valueAsArray;
|
|
404
|
+
const expression = `${fldToMs(field)} >= ${fldToMs(firstValue)} and ${fldToMs(field)} <= ${fldToMs(secondValue)}`;
|
|
405
|
+
return operator === "between" ? `(${expression})` : negate(expression, true);
|
|
406
|
+
}
|
|
407
|
+
const [first, second] = valueAsDateArray;
|
|
408
|
+
const [firstDate, secondDate] = apiFns.isBefore(first, second) ? [first, second] : [second, first];
|
|
409
|
+
const expression = `${fldToMs(field)} >= ${valToMs(firstDate)} and ${fldToMs(field)} <= ${valToMs(secondDate)}`;
|
|
410
|
+
return operator === "between" ? `(${expression})` : negate(expression, true);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return defaultRuleProcessorJSONata(rule, opts);
|
|
414
|
+
};
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/getDatetimeRuleProcessorLDAP.ts
|
|
417
|
+
/**
|
|
418
|
+
* Generates a rule processor with date/time features for use by
|
|
419
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "ldap" format.
|
|
420
|
+
* Relative values are materialized to concrete ISO 8601 strings (LDAP has no symbolic
|
|
421
|
+
* relative form); absolute values pass through.
|
|
422
|
+
*/
|
|
423
|
+
const getDatetimeRuleProcessorLDAP = (apiFns) => (rule, options) => {
|
|
424
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
425
|
+
const { context = {} } = opts;
|
|
426
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorLDAP(rule, opts);
|
|
427
|
+
const { operator, value } = materializeForExport(apiFns, rule, opts);
|
|
428
|
+
return defaultRuleProcessorLDAP(_objectSpread2(_objectSpread2({}, rule), {}, {
|
|
429
|
+
operator,
|
|
430
|
+
value
|
|
431
|
+
}), opts);
|
|
432
|
+
};
|
|
433
|
+
//#endregion
|
|
434
|
+
//#region src/getDatetimeRuleProcessorMongoDBQuery.ts
|
|
435
|
+
/**
|
|
436
|
+
* Generates a rule processor with date/time features for use by
|
|
437
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "mongodb_query" format.
|
|
438
|
+
*/
|
|
439
|
+
const getDatetimeRuleProcessorMongoDBQuery = (apiFns) => (rule, options) => {
|
|
440
|
+
var _opts$context;
|
|
441
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
442
|
+
const { field, valueSource } = rule;
|
|
443
|
+
const operator = resolveDatetimeOperator(rule, opts);
|
|
444
|
+
if (valueSource === "field" || !processIsDateField((_opts$context = opts.context) === null || _opts$context === void 0 ? void 0 : _opts$context.isDateField, rule, opts)) return defaultRuleProcessorMongoDBQuery(rule, opts);
|
|
445
|
+
const value = materializeRelativeValues(apiFns, rule.value, opts);
|
|
446
|
+
if (operator === "=") return { [field]: apiFns.toDate(value) };
|
|
447
|
+
switch (operator) {
|
|
448
|
+
case "<":
|
|
449
|
+
case "<=":
|
|
450
|
+
case "!=":
|
|
451
|
+
case ">":
|
|
452
|
+
case ">=": return { [field]: { [mongoOperators[operator]]: apiFns.toDate(value) } };
|
|
453
|
+
}
|
|
454
|
+
const valueAsDateArray = toArray(value, { retainEmptyStrings: false }).map((v) => apiFns.toDate(v)).filter((dateVal) => apiFns.isValid(dateVal));
|
|
455
|
+
switch (operator) {
|
|
456
|
+
case "in":
|
|
457
|
+
case "notIn": return { [field]: { [mongoOperators[operator]]: valueAsDateArray } };
|
|
458
|
+
case "between":
|
|
459
|
+
case "notBetween": {
|
|
460
|
+
if (valueAsDateArray.length < 2) return "";
|
|
461
|
+
const [first, second] = valueAsDateArray;
|
|
462
|
+
const orderedArray = apiFns.isBefore(first, second) ? [first, second] : [second, first];
|
|
463
|
+
return operator === "between" ? { [field]: {
|
|
464
|
+
$gte: orderedArray[0],
|
|
465
|
+
$lte: orderedArray[1]
|
|
466
|
+
} } : { $or: [{ [field]: { $lt: orderedArray[0] } }, { [field]: { $gt: orderedArray[1] } }] };
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return defaultRuleProcessorMongoDBQuery(rule, opts);
|
|
470
|
+
};
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/getDatetimeRuleProcessorMongoDB.ts
|
|
473
|
+
/**
|
|
474
|
+
* Generates a rule processor with date/time features for use by
|
|
475
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the (deprecated) "mongodb"
|
|
476
|
+
* format. Delegates to the "mongodb_query" date/time processor and serializes the result;
|
|
477
|
+
* `Date` values serialize to ISO 8601 strings.
|
|
478
|
+
*/
|
|
479
|
+
const getDatetimeRuleProcessorMongoDB = (apiFns) => {
|
|
480
|
+
const mongoDBQueryProcessor = getDatetimeRuleProcessorMongoDBQuery(apiFns);
|
|
481
|
+
return (rule, options) => {
|
|
482
|
+
const queryObj = mongoDBQueryProcessor(rule, options);
|
|
483
|
+
return queryObj ? JSON.stringify(queryObj) : "";
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/getDatetimeRuleProcessorNL.ts
|
|
488
|
+
const defaultDateTimeNLOperatorMap = {
|
|
489
|
+
"<": "is before",
|
|
490
|
+
">": "is after",
|
|
491
|
+
"<=": "is on or before",
|
|
492
|
+
">=": "is on or after",
|
|
493
|
+
in: ["is one of the dates", "is the same as a date in"],
|
|
494
|
+
notin: ["is not one of the dates", "is not the same as any date in"],
|
|
495
|
+
between: ["is between", "is between the dates in"],
|
|
496
|
+
notbetween: ["is not between", "is not between the dates in"]
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* Generates a value processor with date/time features for use by
|
|
500
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "natural_language" format.
|
|
501
|
+
*/
|
|
502
|
+
const datetimeValueProcessorNL = (rule, opts) => {
|
|
503
|
+
var _opts$context, _opts$context4, _opts$context5;
|
|
504
|
+
if (isISOStringDateOnly(opts === null || opts === void 0 || (_opts$context = opts.context) === null || _opts$context === void 0 ? void 0 : _opts$context.originalValue)) {
|
|
505
|
+
var _opts$context2, _opts$context3;
|
|
506
|
+
return new Intl.DateTimeFormat(opts === null || opts === void 0 || (_opts$context2 = opts.context) === null || _opts$context2 === void 0 ? void 0 : _opts$context2.locales, _objectSpread2({ dateStyle: "full" }, opts === null || opts === void 0 || (_opts$context3 = opts.context) === null || _opts$context3 === void 0 ? void 0 : _opts$context3.dateFormat)).format(rule.value);
|
|
507
|
+
}
|
|
508
|
+
return new Intl.DateTimeFormat(opts === null || opts === void 0 || (_opts$context4 = opts.context) === null || _opts$context4 === void 0 ? void 0 : _opts$context4.locales, _objectSpread2({
|
|
509
|
+
dateStyle: "full",
|
|
510
|
+
timeStyle: "long"
|
|
511
|
+
}, opts === null || opts === void 0 || (_opts$context5 = opts.context) === null || _opts$context5 === void 0 ? void 0 : _opts$context5.dateTimeFormat)).format(rule.value);
|
|
512
|
+
};
|
|
513
|
+
/**
|
|
514
|
+
* Generates a rule processor with date/time features for use by {@link @react-querybuilder/core!formatQuery formatQuery} with
|
|
515
|
+
* the "natural_language" format.
|
|
516
|
+
*/
|
|
517
|
+
const getDatetimeRuleProcessorNL = (apiFns) => (rule, options) => {
|
|
518
|
+
var _fieldData$label;
|
|
519
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
520
|
+
const operator = resolveDatetimeOperator(rule, opts);
|
|
521
|
+
const operatorLowerCase = lc(operator);
|
|
522
|
+
let finalValue = "";
|
|
523
|
+
// v8 ignore next
|
|
524
|
+
const { fieldData, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "", operatorProcessor = defaultOperatorProcessorNL, wordOrder = "SVO", context = {}, operatorMap = defaultDateTimeNLOperatorMap } = opts;
|
|
525
|
+
if (!processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorNL(rule, opts);
|
|
526
|
+
if (rule.valueSource === "field") return defaultRuleProcessorNL(rule, _objectSpread2(_objectSpread2({}, opts), {}, { operatorMap: defaultDateTimeNLOperatorMap }));
|
|
527
|
+
if ((operatorLowerCase === "in" || operatorLowerCase === "notin" || operatorLowerCase === "between" || operatorLowerCase === "notbetween") && !rule.value) return "";
|
|
528
|
+
const valueAsDateArray = toArray(materializeRelativeValues(apiFns, rule.value, opts), { retainEmptyStrings: false }).map((v) => [v, apiFns.toDate(v)]).filter((v) => apiFns.isValid(v[1]));
|
|
529
|
+
switch (operatorLowerCase) {
|
|
530
|
+
case "in":
|
|
531
|
+
case "notin":
|
|
532
|
+
if (valueAsDateArray.length === 0) return "";
|
|
533
|
+
finalValue = `(${valueAsDateArray.map((value) => datetimeValueProcessorNL({
|
|
534
|
+
field: rule.field,
|
|
535
|
+
operator: "=",
|
|
536
|
+
value: value[1]
|
|
537
|
+
}, _objectSpread2(_objectSpread2({}, opts), {}, { context: _objectSpread2(_objectSpread2({}, context), {}, { originalValue: value[0] }) }))).join(", ")})`;
|
|
538
|
+
break;
|
|
539
|
+
case "between":
|
|
540
|
+
case "notbetween":
|
|
541
|
+
{
|
|
542
|
+
var _opts$translations$an, _opts$translations;
|
|
543
|
+
if (valueAsDateArray.length < 2) return "";
|
|
544
|
+
const [first, second] = valueAsDateArray;
|
|
545
|
+
finalValue = (apiFns.isBefore(first[1], second[1]) ? [first, second] : [second, first]).map(([originalValue, value]) => datetimeValueProcessorNL({
|
|
546
|
+
field: rule.field,
|
|
547
|
+
operator: "=",
|
|
548
|
+
value
|
|
549
|
+
}, _objectSpread2(_objectSpread2({}, opts), {}, { context: _objectSpread2(_objectSpread2({}, context), {}, { originalValue }) }))).join(` ${(_opts$translations$an = (_opts$translations = opts.translations) === null || _opts$translations === void 0 ? void 0 : _opts$translations.and) !== null && _opts$translations$an !== void 0 ? _opts$translations$an : "and"} `);
|
|
550
|
+
}
|
|
551
|
+
break;
|
|
552
|
+
default: {
|
|
553
|
+
var _valueAsDateArray$;
|
|
554
|
+
const [originalValue, value] = (_valueAsDateArray$ = valueAsDateArray[0]) !== null && _valueAsDateArray$ !== void 0 ? _valueAsDateArray$ : ["", ""];
|
|
555
|
+
finalValue = originalValue ? datetimeValueProcessorNL({
|
|
556
|
+
field: rule.field,
|
|
557
|
+
operator: "=",
|
|
558
|
+
value
|
|
559
|
+
}, _objectSpread2(_objectSpread2({}, opts), {}, { context: _objectSpread2(_objectSpread2({}, context), {}, { originalValue }) })) : "";
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
const wordOrderMap = {
|
|
563
|
+
S: getQuotedFieldName((_fieldData$label = fieldData === null || fieldData === void 0 ? void 0 : fieldData.label) !== null && _fieldData$label !== void 0 ? _fieldData$label : rule.field, {
|
|
564
|
+
quoteFieldNamesWith,
|
|
565
|
+
fieldIdentifierSeparator
|
|
566
|
+
}),
|
|
567
|
+
V: operatorProcessor(_objectSpread2(_objectSpread2({}, rule), {}, { operator }), _objectSpread2(_objectSpread2({}, opts), {}, { operatorMap: _objectSpread2(_objectSpread2({}, defaultDateTimeNLOperatorMap), operatorMap) })),
|
|
568
|
+
O: finalValue
|
|
569
|
+
};
|
|
570
|
+
return normalizeConstituentWordOrder(wordOrder).map((term) => `${wordOrderMap[term]}`).join(" ").trim();
|
|
571
|
+
};
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/getDatetimeRuleProcessorParameterized.ts
|
|
574
|
+
/**
|
|
575
|
+
* Generates a rule processor with date/time features for use by
|
|
576
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "parameterized" and
|
|
577
|
+
* "parameterized_named" formats. Relative values are materialized to concrete ISO 8601
|
|
578
|
+
* strings (these formats have no symbolic relative form); absolute values pass through.
|
|
579
|
+
*/
|
|
580
|
+
const getDatetimeRuleProcessorParameterized = (apiFns) => (rule, options, meta) => {
|
|
581
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
582
|
+
const { context = {} } = opts;
|
|
583
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorParameterized(rule, opts, meta);
|
|
584
|
+
const { operator, value } = materializeForExport(apiFns, rule, opts);
|
|
585
|
+
return defaultRuleProcessorParameterized(_objectSpread2(_objectSpread2({}, rule), {}, {
|
|
586
|
+
operator,
|
|
587
|
+
value
|
|
588
|
+
}), opts, meta);
|
|
589
|
+
};
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region src/getDatetimeRuleProcessorPrisma.ts
|
|
592
|
+
/**
|
|
593
|
+
* Generates a rule processor with date/time features for use by
|
|
594
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "prisma" format.
|
|
595
|
+
* Relative values are materialized and all date/time values are converted to `Date`
|
|
596
|
+
* objects (Prisma's `where` clauses use native `Date` values for date columns).
|
|
597
|
+
*/
|
|
598
|
+
const getDatetimeRuleProcessorPrisma = (apiFns) => (rule, options) => {
|
|
599
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
600
|
+
const { context = {} } = opts;
|
|
601
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorPrisma(rule, opts);
|
|
602
|
+
const { operator, value } = materializeForExport(apiFns, rule, opts, true);
|
|
603
|
+
return defaultRuleProcessorPrisma(_objectSpread2(_objectSpread2({}, rule), {}, {
|
|
604
|
+
operator,
|
|
605
|
+
value
|
|
606
|
+
}), opts);
|
|
607
|
+
};
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region src/getDatetimeRuleProcessorSequelize.ts
|
|
610
|
+
/**
|
|
611
|
+
* Generates a rule processor with date/time features for use by
|
|
612
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "sequelize" format.
|
|
613
|
+
* Relative values are materialized and all date/time values are converted to `Date`
|
|
614
|
+
* objects (Sequelize `where` clauses use native `Date` values for date columns).
|
|
615
|
+
*/
|
|
616
|
+
const getDatetimeRuleProcessorSequelize = (apiFns) => (rule, options) => {
|
|
617
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
618
|
+
const { context = {} } = opts;
|
|
619
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorSequelize(rule, opts);
|
|
620
|
+
const { operator, value } = materializeForExport(apiFns, rule, opts, true);
|
|
621
|
+
return defaultRuleProcessorSequelize(_objectSpread2(_objectSpread2({}, rule), {}, {
|
|
622
|
+
operator,
|
|
623
|
+
value
|
|
624
|
+
}), opts);
|
|
625
|
+
};
|
|
626
|
+
//#endregion
|
|
627
|
+
//#region src/getDatetimeRuleProcessorSPARQL.ts
|
|
628
|
+
const shouldNegate = (op) => /^(does)?not/i.test(op);
|
|
629
|
+
/**
|
|
630
|
+
* Wraps a date string in the appropriate SPARQL typed literal.
|
|
631
|
+
* - Date-only strings (YYYY-MM-DD) become `"..."^^xsd:date`
|
|
632
|
+
* - Full ISO strings become `"..."^^xsd:dateTime`
|
|
633
|
+
*/
|
|
634
|
+
const sparqlTemporal = (iso, dateOnly) => dateOnly ? `"${iso}"^^xsd:date` : `"${iso}"^^xsd:dateTime`;
|
|
635
|
+
/**
|
|
636
|
+
* Generates a rule processor with date/time features for use by
|
|
637
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "sparql" format.
|
|
638
|
+
*
|
|
639
|
+
* Supports:
|
|
640
|
+
* - Standard comparison operators (`=`, `!=`, `<`, `>`, `<=`, `>=`)
|
|
641
|
+
* - Range operators (between, notBetween, in, notIn)
|
|
642
|
+
* - Duration math via custom operators: `olderThanDuration` and `withinDuration`
|
|
643
|
+
* (e.g., value `"P30D"` → `NOW() - ?field > "P30D"^^xsd:duration`)
|
|
644
|
+
*/
|
|
645
|
+
const getDatetimeRuleProcessorSPARQL = (apiFns) => (rule, options) => {
|
|
646
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
647
|
+
const { context = {} } = opts;
|
|
648
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorSPARQL(rule, opts);
|
|
649
|
+
const { field: rawField, value } = rule;
|
|
650
|
+
const operator = resolveDatetimeOperator(rule, opts);
|
|
651
|
+
const field = sparqlVar(rawField);
|
|
652
|
+
const operatorTL = lc(operator);
|
|
653
|
+
if (operatorTL === "olderthanduration") return `NOW() - ${field} > "${value}"^^xsd:duration`;
|
|
654
|
+
if (operatorTL === "withinduration") return `NOW() - ${field} <= "${value}"^^xsd:duration`;
|
|
655
|
+
const valueAsDateArray = toArray(materializeRelativeValues(apiFns, value, opts), { retainEmptyStrings: false }).map((v) => [v, apiFns.toDate(v)]).filter(([, d]) => apiFns.isValid(d));
|
|
656
|
+
const fmtDate = (originalValue) => {
|
|
657
|
+
const dateOnly = isISOStringDateOnly(originalValue);
|
|
658
|
+
return sparqlTemporal(dateOnly ? apiFns.toISOStringDateOnly(originalValue) : apiFns.toISOString(originalValue), dateOnly);
|
|
659
|
+
};
|
|
660
|
+
switch (operatorTL) {
|
|
661
|
+
case "in":
|
|
662
|
+
case "notin": {
|
|
663
|
+
if (valueAsDateArray.length === 0) return "";
|
|
664
|
+
const items = valueAsDateArray.map(([orig]) => fmtDate(orig));
|
|
665
|
+
return `${field} ${shouldNegate(operatorTL) ? "NOT " : ""}IN (${items.join(", ")})`;
|
|
666
|
+
}
|
|
667
|
+
case "between":
|
|
668
|
+
case "notbetween": {
|
|
669
|
+
if (valueAsDateArray.length < 2) return "";
|
|
670
|
+
const [first, second] = valueAsDateArray;
|
|
671
|
+
const [lo, hi] = apiFns.isBefore(first[1], second[1]) ? [first, second] : [second, first];
|
|
672
|
+
if (operatorTL === "notbetween") return `(${field} < ${fmtDate(lo[0])} || ${field} > ${fmtDate(hi[0])})`;
|
|
673
|
+
return `${field} >= ${fmtDate(lo[0])} && ${field} <= ${fmtDate(hi[0])}`;
|
|
674
|
+
}
|
|
675
|
+
default: {
|
|
676
|
+
if (valueAsDateArray.length === 0) return "";
|
|
677
|
+
const [orig] = valueAsDateArray[0];
|
|
678
|
+
return `${field} ${operatorTL === "<>" ? "!=" : operatorTL} ${fmtDate(orig)}`;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
//#endregion
|
|
683
|
+
//#region src/getDatetimeRuleProcessorSpEL.ts
|
|
684
|
+
/**
|
|
685
|
+
* Generates a rule processor with date/time features for use by
|
|
686
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "spel" format.
|
|
687
|
+
* Relative values are materialized to concrete ISO 8601 strings (SpEL has no symbolic
|
|
688
|
+
* relative form); absolute values pass through.
|
|
689
|
+
*/
|
|
690
|
+
const getDatetimeRuleProcessorSpEL = (apiFns) => (rule, options) => {
|
|
691
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
692
|
+
const { context = {} } = opts;
|
|
693
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorSpEL(rule, opts);
|
|
694
|
+
const { operator, value } = materializeForExport(apiFns, rule, opts);
|
|
695
|
+
return defaultRuleProcessorSpEL(_objectSpread2(_objectSpread2({}, rule), {}, {
|
|
696
|
+
operator,
|
|
697
|
+
value
|
|
698
|
+
}), opts);
|
|
699
|
+
};
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region src/getRelativeDateTimeSQL.ts
|
|
702
|
+
const parseAnchor = (anchor) => {
|
|
703
|
+
if (anchor === "now") return { bound: "now" };
|
|
704
|
+
const match = /^(start|end)Of(Day|Week|Month|Year)$/.exec(anchor);
|
|
705
|
+
return {
|
|
706
|
+
bound: match[1],
|
|
707
|
+
unit: match[2].toLowerCase()
|
|
708
|
+
};
|
|
709
|
+
};
|
|
710
|
+
const pluralUnit = (unit) => `${unit}s`;
|
|
711
|
+
const pgBuild = (value, asDate) => {
|
|
712
|
+
const now = asDate ? "current_date" : "current_timestamp";
|
|
713
|
+
const { bound, unit } = parseAnchor(value.anchor);
|
|
714
|
+
let expr = now;
|
|
715
|
+
let modified = false;
|
|
716
|
+
if (bound === "start" && unit) {
|
|
717
|
+
expr = `date_trunc('${unit}', ${now})`;
|
|
718
|
+
modified = true;
|
|
719
|
+
} else if (bound === "end" && unit) {
|
|
720
|
+
expr = `date_trunc('${unit}', ${now}) + interval '1 ${unit}' - ${asDate ? `interval '1 day'` : `interval '1 microsecond'`}`;
|
|
721
|
+
modified = true;
|
|
722
|
+
}
|
|
723
|
+
if (value.offset) {
|
|
724
|
+
const op = value.offset < 0 ? "-" : "+";
|
|
725
|
+
expr = `${expr} ${op} interval '${Math.abs(value.offset)} ${pluralUnit(value.unit)}'`;
|
|
726
|
+
modified = true;
|
|
727
|
+
}
|
|
728
|
+
return asDate && modified ? `cast(${expr} as date)` : expr;
|
|
729
|
+
};
|
|
730
|
+
const mysqlTrunc = (now, bound, unit) => {
|
|
731
|
+
if (bound === "start") switch (unit) {
|
|
732
|
+
case "day": return `date(${now})`;
|
|
733
|
+
case "week": return `date_sub(date(${now}), interval dayofweek(${now}) - 1 day)`;
|
|
734
|
+
case "month": return `date_format(${now}, '%Y-%m-01')`;
|
|
735
|
+
case "year": return `date_format(${now}, '%Y-01-01')`;
|
|
736
|
+
}
|
|
737
|
+
switch (unit) {
|
|
738
|
+
case "day": return `date(${now})`;
|
|
739
|
+
case "week": return `date_add(date(${now}), interval 7 - dayofweek(${now}) day)`;
|
|
740
|
+
case "month": return `last_day(${now})`;
|
|
741
|
+
}
|
|
742
|
+
return `date_format(${now}, '%Y-12-31')`;
|
|
743
|
+
};
|
|
744
|
+
const mysqlBuild = (value, asDate) => {
|
|
745
|
+
const now = asDate ? "curdate()" : "now()";
|
|
746
|
+
const { bound, unit } = parseAnchor(value.anchor);
|
|
747
|
+
let expr = now;
|
|
748
|
+
if (bound !== "now" && unit) {
|
|
749
|
+
expr = mysqlTrunc(now, bound, unit);
|
|
750
|
+
if (bound === "end" && !asDate) expr = `date_sub(date_add(${expr}, interval 1 day), interval 1 microsecond)`;
|
|
751
|
+
}
|
|
752
|
+
if (value.offset) expr = `${value.offset < 0 ? "date_sub" : "date_add"}(${expr}, interval ${Math.abs(value.offset)} ${value.unit})`;
|
|
753
|
+
return expr;
|
|
754
|
+
};
|
|
755
|
+
const mssqlTrunc = (now, bound, unit, asDate) => {
|
|
756
|
+
const start = `dateadd(${unit}, datediff(${unit}, 0, ${now}), 0)`;
|
|
757
|
+
if (bound === "start") return start;
|
|
758
|
+
const nextStart = `dateadd(${unit}, datediff(${unit}, 0, ${now}) + 1, 0)`;
|
|
759
|
+
return asDate ? `dateadd(day, -1, ${nextStart})` : `dateadd(nanosecond, -100, cast(${nextStart} as datetime2))`;
|
|
760
|
+
};
|
|
761
|
+
const mssqlBuild = (value, asDate) => {
|
|
762
|
+
const now = asDate ? "cast(getdate() as date)" : "getdate()";
|
|
763
|
+
const { bound, unit } = parseAnchor(value.anchor);
|
|
764
|
+
let expr = now;
|
|
765
|
+
if (bound !== "now" && unit) expr = mssqlTrunc(now, bound, unit, asDate);
|
|
766
|
+
if (value.offset) expr = `dateadd(${value.unit}, ${value.offset}, ${expr})`;
|
|
767
|
+
return expr;
|
|
768
|
+
};
|
|
769
|
+
const oracleTruncFormat = {
|
|
770
|
+
day: "DDD",
|
|
771
|
+
week: "IW",
|
|
772
|
+
month: "MM",
|
|
773
|
+
year: "YYYY"
|
|
774
|
+
};
|
|
775
|
+
const oracleBuild = (value, asDate) => {
|
|
776
|
+
const now = asDate ? "trunc(sysdate)" : "systimestamp";
|
|
777
|
+
const { bound, unit } = parseAnchor(value.anchor);
|
|
778
|
+
let expr = now;
|
|
779
|
+
let endTimestampStepBack = false;
|
|
780
|
+
if (bound !== "now" && unit) {
|
|
781
|
+
const start = `trunc(${now}, '${oracleTruncFormat[unit]}')`;
|
|
782
|
+
if (bound === "start") expr = start;
|
|
783
|
+
else {
|
|
784
|
+
const next = unit === "month" || unit === "year" ? `add_months(${start}, ${unit === "month" ? 1 : 12})` : `${start} + interval '1' day${unit === "week" ? " * 7" : ""}`;
|
|
785
|
+
if (asDate) expr = `${next} - interval '1' second`;
|
|
786
|
+
else {
|
|
787
|
+
expr = next;
|
|
788
|
+
endTimestampStepBack = true;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (value.offset) if (value.unit === "month" || value.unit === "year") expr = `add_months(${expr}, ${value.offset * (value.unit === "year" ? 12 : 1)})`;
|
|
793
|
+
else {
|
|
794
|
+
const days = {
|
|
795
|
+
day: 1,
|
|
796
|
+
week: 7
|
|
797
|
+
}[value.unit];
|
|
798
|
+
expr = days ? `${expr} ${value.offset < 0 ? "-" : "+"} ${Math.abs(value.offset) * days}` : `${expr} + numtodsinterval(${value.offset}, '${value.unit.toUpperCase()}')`;
|
|
799
|
+
}
|
|
800
|
+
if (endTimestampStepBack) expr = `cast(${expr} as timestamp) - numtodsinterval(0.000001, 'second')`;
|
|
801
|
+
return expr;
|
|
802
|
+
};
|
|
803
|
+
const sqliteStartModifier = {
|
|
804
|
+
day: `'start of day'`,
|
|
805
|
+
week: `'weekday 0', '-7 days'`,
|
|
806
|
+
month: `'start of month'`,
|
|
807
|
+
year: `'start of year'`
|
|
808
|
+
};
|
|
809
|
+
const sqliteBuild = (value, asDate) => {
|
|
810
|
+
const fn = asDate ? "date" : "datetime";
|
|
811
|
+
const args = [`'now'`];
|
|
812
|
+
const { bound, unit } = parseAnchor(value.anchor);
|
|
813
|
+
if (bound !== "now" && unit) if (bound === "start") args.push(sqliteStartModifier[unit]);
|
|
814
|
+
else switch (unit) {
|
|
815
|
+
case "day":
|
|
816
|
+
args.push(`'start of day'`, `'+1 day'`, asDate ? `'-1 day'` : `'-1 second'`);
|
|
817
|
+
break;
|
|
818
|
+
case "week":
|
|
819
|
+
args.push(`'weekday 0'`, asDate ? `'-1 day'` : `'-1 second'`);
|
|
820
|
+
break;
|
|
821
|
+
case "month":
|
|
822
|
+
args.push(`'start of month'`, `'+1 month'`, asDate ? `'-1 day'` : `'-1 second'`);
|
|
823
|
+
break;
|
|
824
|
+
case "year":
|
|
825
|
+
args.push(`'start of year'`, `'+1 year'`, asDate ? `'-1 day'` : `'-1 second'`);
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
if (value.offset) {
|
|
829
|
+
const sign = value.offset < 0 ? "-" : "+";
|
|
830
|
+
args.push(`'${sign}${Math.abs(value.offset)} ${pluralUnit(value.unit)}'`);
|
|
831
|
+
}
|
|
832
|
+
return `${fn}(${args.join(", ")})`;
|
|
833
|
+
};
|
|
834
|
+
const presetToRelativeBuilderMap = {
|
|
835
|
+
ansi: pgBuild,
|
|
836
|
+
mssql: mssqlBuild,
|
|
837
|
+
mysql: mysqlBuild,
|
|
838
|
+
oracle: oracleBuild,
|
|
839
|
+
postgresql: pgBuild,
|
|
840
|
+
sqlite: sqliteBuild
|
|
841
|
+
};
|
|
842
|
+
/**
|
|
843
|
+
* Determines whether the SQL expression for a relative date/time should be a
|
|
844
|
+
* date (vs. a timestamp/datetime) based on the field's declared `datatype` and
|
|
845
|
+
* the SQL dialect. Mirrors the per-dialect logic used for literal date values.
|
|
846
|
+
*/
|
|
847
|
+
const isDateGranularity = (preset, datatype) => {
|
|
848
|
+
const dt = datatype;
|
|
849
|
+
switch (preset) {
|
|
850
|
+
case "mssql": return !/^(?:small)?datetime/i.test(dt);
|
|
851
|
+
case "mysql": return !/^(?:datetime|timestamp)/i.test(dt);
|
|
852
|
+
case "oracle":
|
|
853
|
+
case "postgresql": return !/^timestamp/i.test(dt);
|
|
854
|
+
default: return !/^(?:datetime|timestamp)/i.test(dt);
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
/**
|
|
858
|
+
* Builds a dialect-specific symbolic SQL expression for a {@link RelativeDateTimeValue}.
|
|
859
|
+
*/
|
|
860
|
+
const getRelativeDateTimeSQL = (value, preset, datatype) => presetToRelativeBuilderMap[preset](value, isDateGranularity(preset, datatype));
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region src/getDatetimeRuleProcessorSQL.ts
|
|
863
|
+
/**
|
|
864
|
+
* Generates a value processor with date/time features for use by
|
|
865
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "sql" format and "ansi" preset.
|
|
866
|
+
*/
|
|
867
|
+
const getDatetimeValueProcessorANSI = ({ toISOStringDateOnly, toISOString }) => (rule, opts) => {
|
|
868
|
+
var _opts$context;
|
|
869
|
+
if (isISOStringDateOnly(opts === null || opts === void 0 || (_opts$context = opts.context) === null || _opts$context === void 0 ? void 0 : _opts$context.originalValue)) return defaultValueProcessorByRule(_objectSpread2(_objectSpread2({}, rule), {}, { value: toISOStringDateOnly(rule.value) }), opts);
|
|
870
|
+
return defaultValueProcessorByRule(_objectSpread2(_objectSpread2({}, rule), {}, { value: toISOString(rule.value) }), opts);
|
|
871
|
+
};
|
|
872
|
+
/**
|
|
873
|
+
* Generates a value processor with date/time features for use by {@link @react-querybuilder/core!formatQuery formatQuery} with
|
|
874
|
+
* the "sql" format and "mssql" preset.
|
|
875
|
+
*/
|
|
876
|
+
const getDatetimeValueProcessorMSSQL = ({ toISOStringDateOnly, toISOString }) => (rule, opts) => {
|
|
877
|
+
var _opts$fieldData;
|
|
878
|
+
const datatype = /^(?:small)?datetime/i.test(opts === null || opts === void 0 || (_opts$fieldData = opts.fieldData) === null || _opts$fieldData === void 0 ? void 0 : _opts$fieldData.datatype) ? "datetimeoffset" : "date";
|
|
879
|
+
const value = datatype === "datetimeoffset" ? toISOString(rule.value) : toISOStringDateOnly(rule.value);
|
|
880
|
+
return defaultValueProcessorByRule(_objectSpread2(_objectSpread2({}, rule), {}, { value }), _objectSpread2(_objectSpread2({}, opts), {}, { wrapValueWith: [`cast(`, ` as ${datatype})`] }));
|
|
881
|
+
};
|
|
882
|
+
/**
|
|
883
|
+
* Generates a value processor with date/time features for use by {@link @react-querybuilder/core!formatQuery formatQuery} with
|
|
884
|
+
* the "sql" format and "mysql" preset.
|
|
885
|
+
*/
|
|
886
|
+
const getDatetimeValueProcessorMySQL = ({ toISOStringDateOnly, toISOString }) => (rule, opts) => {
|
|
887
|
+
var _opts$fieldData2;
|
|
888
|
+
const datatype = /^(?:datetime|timestamp)/i.test(opts === null || opts === void 0 || (_opts$fieldData2 = opts.fieldData) === null || _opts$fieldData2 === void 0 ? void 0 : _opts$fieldData2.datatype) ? "datetime" : "date";
|
|
889
|
+
const value = datatype === "datetime" ? toISOString(rule.value) : toISOStringDateOnly(rule.value);
|
|
890
|
+
return defaultValueProcessorByRule(_objectSpread2(_objectSpread2({}, rule), {}, { value }), _objectSpread2(_objectSpread2({}, opts), {}, { wrapValueWith: [`cast(`, ` as ${datatype})`] }));
|
|
891
|
+
};
|
|
892
|
+
/**
|
|
893
|
+
* Generates a value processor with date/time features for use by {@link @react-querybuilder/core!formatQuery formatQuery} with
|
|
894
|
+
* the "sql" format and "oracle" preset.
|
|
895
|
+
*/
|
|
896
|
+
const getDatetimeValueProcessorOracle = ({ toISOStringDateOnly, toISOString }) => (rule, opts) => {
|
|
897
|
+
var _opts$fieldData3;
|
|
898
|
+
const datatype = /^timestamp/i.test(opts === null || opts === void 0 || (_opts$fieldData3 = opts.fieldData) === null || _opts$fieldData3 === void 0 ? void 0 : _opts$fieldData3.datatype) ? "timestamp" : "date";
|
|
899
|
+
const value = datatype === "timestamp" ? toISOString(rule.value).replaceAll("T", " ").replace("Z", " UTC") : toISOStringDateOnly(rule.value);
|
|
900
|
+
return defaultValueProcessorByRule(_objectSpread2(_objectSpread2({}, rule), {}, { value }), _objectSpread2(_objectSpread2({}, opts), {}, { wrapValueWith: [datatype, ``] }));
|
|
901
|
+
};
|
|
902
|
+
/**
|
|
903
|
+
* Generates a value processor with date/time features for use by {@link @react-querybuilder/core!formatQuery formatQuery} with
|
|
904
|
+
* the "sql" format and "postgresql" preset.
|
|
905
|
+
*/
|
|
906
|
+
const getDatetimeValueProcessorPostgreSQL = ({ toISOStringDateOnly, toISOString }) => (rule, opts) => {
|
|
907
|
+
var _opts$fieldData4;
|
|
908
|
+
const datatype = /^timestamp/i.test(opts === null || opts === void 0 || (_opts$fieldData4 = opts.fieldData) === null || _opts$fieldData4 === void 0 ? void 0 : _opts$fieldData4.datatype) ? "timestamp" : "date";
|
|
909
|
+
const value = datatype === "timestamp" ? toISOString(rule.value) : toISOStringDateOnly(rule.value);
|
|
910
|
+
return defaultValueProcessorByRule(_objectSpread2(_objectSpread2({}, rule), {}, { value }), _objectSpread2(_objectSpread2({}, opts), {}, { wrapValueWith: [datatype, ``] }));
|
|
911
|
+
};
|
|
912
|
+
const presetToValueProcessorMap = {
|
|
913
|
+
ansi: getDatetimeValueProcessorANSI,
|
|
914
|
+
mssql: getDatetimeValueProcessorMSSQL,
|
|
915
|
+
mysql: getDatetimeValueProcessorMySQL,
|
|
916
|
+
oracle: getDatetimeValueProcessorOracle,
|
|
917
|
+
postgresql: getDatetimeValueProcessorPostgreSQL,
|
|
918
|
+
sqlite: getDatetimeValueProcessorANSI
|
|
919
|
+
};
|
|
920
|
+
/**
|
|
921
|
+
* Generates a rule processor with date/time features for use by {@link @react-querybuilder/core!formatQuery formatQuery} with
|
|
922
|
+
* the "sql" format.
|
|
923
|
+
*/
|
|
924
|
+
const getDatetimeRuleProcessorSQL = (apiFns) => (rule, options) => {
|
|
925
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
926
|
+
const operator = mapSQLOperator(resolveDatetimeOperator(rule, opts));
|
|
927
|
+
const operatorLowerCase = lc(operator);
|
|
928
|
+
// v8 ignore next
|
|
929
|
+
const { quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "", context = {} } = opts;
|
|
930
|
+
let finalValue = "";
|
|
931
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorSQL(rule, opts);
|
|
932
|
+
const valueProcessor = presetToValueProcessorMap[opts.preset](apiFns);
|
|
933
|
+
const quotedField = getQuotedFieldName(rule.field, {
|
|
934
|
+
quoteFieldNamesWith,
|
|
935
|
+
fieldIdentifierSeparator
|
|
936
|
+
});
|
|
937
|
+
const ruleValue = context.materializeRelativeDateTime ? materializeRelativeValues(apiFns, rule.value, opts) : rule.value;
|
|
938
|
+
const rawValues = Array.isArray(ruleValue) ? ruleValue : [ruleValue];
|
|
939
|
+
if (rawValues.some(isRelativeDateTimeValue)) {
|
|
940
|
+
const exprFor = (v) => {
|
|
941
|
+
if (isRelativeDateTimeValue(v)) {
|
|
942
|
+
var _opts$fieldData5;
|
|
943
|
+
return getRelativeDateTimeSQL(v, opts.preset, (_opts$fieldData5 = opts.fieldData) === null || _opts$fieldData5 === void 0 ? void 0 : _opts$fieldData5.datatype);
|
|
944
|
+
}
|
|
945
|
+
const dateVal = apiFns.toDate(v);
|
|
946
|
+
if (!apiFns.isValid(dateVal)) return void 0;
|
|
947
|
+
return valueProcessor({
|
|
948
|
+
field: rule.field,
|
|
949
|
+
operator: "=",
|
|
950
|
+
value: dateVal
|
|
951
|
+
}, _objectSpread2(_objectSpread2({}, opts), {}, { context: { originalValue: v } }));
|
|
952
|
+
};
|
|
953
|
+
switch (operatorLowerCase) {
|
|
954
|
+
case "in":
|
|
955
|
+
case "not in": {
|
|
956
|
+
const exprs = rawValues.map(exprFor).filter((e) => e !== void 0);
|
|
957
|
+
// v8 ignore next -- a relative operand always yields an expression
|
|
958
|
+
if (exprs.length === 0) return "";
|
|
959
|
+
finalValue = `(${exprs.join(", ")})`;
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
case "between":
|
|
963
|
+
case "not between": {
|
|
964
|
+
const first = exprFor(rawValues[0]);
|
|
965
|
+
const second = exprFor(rawValues[1]);
|
|
966
|
+
if (first === void 0 || second === void 0) return "";
|
|
967
|
+
finalValue = `${first} and ${second}`;
|
|
968
|
+
break;
|
|
969
|
+
}
|
|
970
|
+
default: {
|
|
971
|
+
const expr = exprFor(rawValues[0]);
|
|
972
|
+
// v8 ignore next -- a single relative operand always yields an expression
|
|
973
|
+
if (expr === void 0) return "";
|
|
974
|
+
finalValue = expr;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
return `${quotedField} ${operator} ${finalValue}`.trim();
|
|
978
|
+
}
|
|
979
|
+
const valueAsDateArray = toArray(ruleValue, { retainEmptyStrings: false }).map((v) => [v, apiFns.toDate(v)]).filter((v) => apiFns.isValid(v[1]));
|
|
980
|
+
switch (operatorLowerCase) {
|
|
981
|
+
case "in":
|
|
982
|
+
case "not in":
|
|
983
|
+
if (valueAsDateArray.length === 0) return "";
|
|
984
|
+
finalValue = `(${valueAsDateArray.map((value) => valueProcessor({
|
|
985
|
+
field: rule.field,
|
|
986
|
+
operator: "=",
|
|
987
|
+
value: value[1]
|
|
988
|
+
}, _objectSpread2(_objectSpread2({}, opts), {}, { context: { originalValue: value[0] } }))).join(", ")})`;
|
|
989
|
+
break;
|
|
990
|
+
case "between":
|
|
991
|
+
case "not between":
|
|
992
|
+
{
|
|
993
|
+
if (valueAsDateArray.length < 2) return "";
|
|
994
|
+
const [first, second] = valueAsDateArray;
|
|
995
|
+
finalValue = (apiFns.isBefore(first[1], second[1]) ? [first, second] : [second, first]).map(([originalValue, value]) => valueProcessor({
|
|
996
|
+
field: rule.field,
|
|
997
|
+
operator: "=",
|
|
998
|
+
value
|
|
999
|
+
}, _objectSpread2(_objectSpread2({}, opts), {}, { context: { originalValue } }))).join(" and ");
|
|
1000
|
+
}
|
|
1001
|
+
break;
|
|
1002
|
+
default: {
|
|
1003
|
+
var _valueAsDateArray$;
|
|
1004
|
+
const [originalValue, value] = (_valueAsDateArray$ = valueAsDateArray[0]) !== null && _valueAsDateArray$ !== void 0 ? _valueAsDateArray$ : ["", ""];
|
|
1005
|
+
finalValue = valueProcessor({
|
|
1006
|
+
field: rule.field,
|
|
1007
|
+
operator: "=",
|
|
1008
|
+
value
|
|
1009
|
+
}, _objectSpread2(_objectSpread2({}, opts), {}, { context: { originalValue } }));
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
return `${quotedField} ${operator} ${finalValue}`.trim();
|
|
1013
|
+
};
|
|
1014
|
+
//#endregion
|
|
1015
|
+
//#region src/getDatetimeRuleProcessorTanStackDB.ts
|
|
1016
|
+
/**
|
|
1017
|
+
* Generates a rule processor with date/time features for use by
|
|
1018
|
+
* {@link @react-querybuilder/core!formatQuery formatQuery} with the "tanstack_db" format.
|
|
1019
|
+
* Relative values are materialized and all date/time values are converted to `Date`
|
|
1020
|
+
* objects (TanStack DB collection filters compare against native `Date` values).
|
|
1021
|
+
*/
|
|
1022
|
+
const getDatetimeRuleProcessorTanStackDB = (apiFns) => (rule, options) => {
|
|
1023
|
+
const opts = options !== null && options !== void 0 ? options : /* v8 ignore start -- @preserve */ {};
|
|
1024
|
+
const { context = {} } = opts;
|
|
1025
|
+
if (rule.valueSource === "field" || !processIsDateField(context.isDateField, rule, opts)) return defaultRuleProcessorTanStackDB(rule, opts);
|
|
1026
|
+
const { operator, value } = materializeForExport(apiFns, rule, opts, true);
|
|
1027
|
+
return defaultRuleProcessorTanStackDB(_objectSpread2(_objectSpread2({}, rule), {}, {
|
|
1028
|
+
operator,
|
|
1029
|
+
value
|
|
1030
|
+
}), opts);
|
|
1031
|
+
};
|
|
1032
|
+
//#endregion
|
|
1033
|
+
export { processIsDateField as A, _objectSpread2 as C, isDateOnlyDatatype as D, getDatetimeJsonLogicOperations as E, isISOStringDateOnly as O, getDatetimeRuleProcessorDrizzle as S, getDatetimeRuleProcessorCEL as T, getDatetimeRuleProcessorMongoDBQuery as _, getDatetimeValueProcessorMySQL as a, getDatetimeRuleProcessorGremlin as b, getDatetimeRuleProcessorSpEL as c, getDatetimeRuleProcessorPrisma as d, getDatetimeRuleProcessorParameterized as f, getDatetimeRuleProcessorMongoDB as g, getDatetimeRuleProcessorNL as h, getDatetimeValueProcessorMSSQL as i, resolveDatetimeOperator as j, isRelativeDateTimeValue as k, getDatetimeRuleProcessorSPARQL as l, defaultDateTimeNLOperatorMap as m, getDatetimeRuleProcessorSQL as n, getDatetimeValueProcessorOracle as o, datetimeValueProcessorNL as p, getDatetimeValueProcessorANSI as r, getDatetimeValueProcessorPostgreSQL as s, getDatetimeRuleProcessorTanStackDB as t, getDatetimeRuleProcessorSequelize as u, getDatetimeRuleProcessorLDAP as v, getDatetimeRuleProcessorCypher as w, getDatetimeRuleProcessorElasticSearch as x, getDatetimeRuleProcessorJSONata as y };
|
|
1034
|
+
|
|
1035
|
+
//# sourceMappingURL=getDatetimeRuleProcessorTanStackDB-LDwhMJg0.js.map
|