@react-querybuilder/datetime 8.20.1 → 8.20.2
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-BVNfYaIj.js +2 -0
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-BVNfYaIj.js.map +1 -0
- package/dist/cjs/{getDatetimeRuleProcessorTanStackDB-CL79A1_x.js → getDatetimeRuleProcessorTanStackDB-cmGqMT0Q.js} +83 -216
- package/dist/cjs/getDatetimeRuleProcessorTanStackDB-cmGqMT0Q.js.map +1 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.development.d.ts +3 -123
- package/dist/cjs/react-querybuilder_datetime.cjs.development.date-fns.d.ts +2 -2
- 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 +2 -2
- 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 +10 -467
- package/dist/cjs/react-querybuilder_datetime.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_datetime.cjs.development.jsdate.d.ts +2 -2
- 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 +2 -2
- 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 +228 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.development.ui.js +464 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.development.ui.js.map +1 -0
- package/dist/cjs/react-querybuilder_datetime.cjs.production.d.ts +3 -123
- package/dist/cjs/react-querybuilder_datetime.cjs.production.date-fns.d.ts +2 -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 +2 -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 +2 -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 +2 -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/react-querybuilder_datetime.cjs.production.ui.d.ts +228 -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-BPEcMhhr.js +128 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.jsdate-BPEcMhhr.js.map +1 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.jsdate-ioz2B1zh.js +2 -0
- package/dist/cjs/rqbDateTimeLibraryAPI.jsdate-ioz2B1zh.js.map +1 -0
- package/dist/cjs/{types-XYMw0jFT.d.ts → types-Di8kFIXV.d.ts} +3 -103
- package/dist/cjs/ui.d.ts +1 -0
- package/dist/cjs/ui.js +6 -0
- package/dist/cjs/utils-DUePrC--.js +154 -0
- package/dist/cjs/utils-DUePrC--.js.map +1 -0
- package/dist/cjs/utils-jkW5R1AA.js +2 -0
- package/dist/cjs/utils-jkW5R1AA.js.map +1 -0
- package/dist/{getDatetimeRuleProcessorTanStackDB-BcOC-o2A.mjs → getDatetimeRuleProcessorTanStackDB-B93XaPdB.mjs} +4 -107
- package/dist/getDatetimeRuleProcessorTanStackDB-B93XaPdB.mjs.map +1 -0
- package/dist/{getDatetimeRuleProcessorTanStackDB-BL8mbdbl.js → getDatetimeRuleProcessorTanStackDB-BDFJlfJh.js} +4 -181
- package/dist/getDatetimeRuleProcessorTanStackDB-BDFJlfJh.js.map +1 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-Czg9Fbb8.mjs +2 -0
- package/dist/getDatetimeRuleProcessorTanStackDB-Czg9Fbb8.mjs.map +1 -0
- package/dist/objectSpread2-73AKOozq.js +181 -0
- package/dist/objectSpread2-73AKOozq.js.map +1 -0
- package/dist/react-querybuilder_datetime.d.mts +3 -123
- package/dist/react-querybuilder_datetime.date-fns.d.mts +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +3 -123
- package/dist/react-querybuilder_datetime.legacy-esm.date-fns.d.ts +2 -2
- 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 +2 -2
- 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 +4 -449
- package/dist/react-querybuilder_datetime.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_datetime.legacy-esm.jsdate.d.ts +2 -2
- 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 +2 -2
- 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 +228 -0
- package/dist/react-querybuilder_datetime.legacy-esm.ui.js +451 -0
- package/dist/react-querybuilder_datetime.legacy-esm.ui.js.map +1 -0
- package/dist/react-querybuilder_datetime.luxon.d.mts +2 -2
- 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 +4 -446
- package/dist/react-querybuilder_datetime.mjs.map +1 -1
- package/dist/react-querybuilder_datetime.production.d.mts +3 -123
- package/dist/react-querybuilder_datetime.production.date-fns.d.mts +2 -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 +2 -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 +2 -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 +2 -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/react-querybuilder_datetime.production.ui.d.mts +228 -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 +228 -0
- package/dist/react-querybuilder_datetime.ui.mjs +448 -0
- package/dist/react-querybuilder_datetime.ui.mjs.map +1 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-CDOtydFq.mjs +2 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-CDOtydFq.mjs.map +1 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-CpGoQAje.js +123 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-CpGoQAje.js.map +1 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-D66yJ1hK.mjs +123 -0
- package/dist/rqbDateTimeLibraryAPI.jsdate-D66yJ1hK.mjs.map +1 -0
- package/dist/{types-CdjHqQ0k.d.ts → types-Di8kFIXV.d.mts} +3 -103
- package/dist/{types-CdjHqQ0k.d.mts → types-Di8kFIXV.d.ts} +3 -103
- package/dist/utils-BC2SALFm.mjs +107 -0
- package/dist/utils-BC2SALFm.mjs.map +1 -0
- package/dist/utils-VKS8YY2D.mjs +2 -0
- package/dist/utils-VKS8YY2D.mjs.map +1 -0
- package/package.json +27 -8
- 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/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
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RQBJsonLogic, RuleProcessor } from "@react-querybuilder/core";
|
|
2
2
|
import { RulesLogic } from "json-logic-js";
|
|
3
|
-
import { ComponentType, ReactNode } from "react";
|
|
4
3
|
|
|
5
4
|
//#region src/types.d.ts
|
|
6
5
|
interface RQBJsonLogicDateBetween {
|
|
@@ -159,107 +158,8 @@ type RQBJsonLogicDateTimeOperations = {
|
|
|
159
158
|
*/
|
|
160
159
|
dateRelative: (anchor: RelativeDateTimeAnchor, offset: number, unit: RelativeDateTimeUnit, dateOnly: boolean) => string;
|
|
161
160
|
};
|
|
162
|
-
/**
|
|
163
|
-
* Customizable content/labels for the absolute/relative mode toggle rendered by
|
|
164
|
-
* {@link toggleModeController}. The default glyphs come from CSS pseudo-elements, so
|
|
165
|
-
* `absoluteContent`/`relativeContent` are only needed to override them (e.g. to render
|
|
166
|
-
* an icon component or localized text).
|
|
167
|
-
*/
|
|
168
|
-
interface RelativeDateTimeToggleLabels {
|
|
169
|
-
/** Accessible label (`aria-label`) for the toggle button. */
|
|
170
|
-
label?: string;
|
|
171
|
-
/** Tooltip shown while in absolute mode (clicking switches to relative). */
|
|
172
|
-
absoluteTitle?: string;
|
|
173
|
-
/** Tooltip shown while in relative mode (clicking switches to absolute). */
|
|
174
|
-
relativeTitle?: string;
|
|
175
|
-
/** Custom content rendered while in absolute mode. Defaults to a CSS glyph. */
|
|
176
|
-
absoluteContent?: ReactNode;
|
|
177
|
-
/** Custom content rendered while in relative mode. Defaults to a CSS glyph. */
|
|
178
|
-
relativeContent?: ReactNode;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Props passed to a {@link RelativeDateTimeModeController}'s `ModeControl` component —
|
|
182
|
-
* the affordance (e.g. a toggle button) that switches a rule between absolute and
|
|
183
|
-
* relative date/time entry.
|
|
184
|
-
*/
|
|
185
|
-
interface RelativeDateTimeModeControlProps {
|
|
186
|
-
/** Whether the rule is currently in relative mode. */
|
|
187
|
-
isRelative: boolean;
|
|
188
|
-
/** Switches the rule between absolute and relative mode. */
|
|
189
|
-
setMode: (mode: "absolute" | "relative") => void;
|
|
190
|
-
/** The value editor's schema (for theme-aware rendering). */
|
|
191
|
-
schema: ValueEditorProps["schema"];
|
|
192
|
-
/** Whether the control is disabled. */
|
|
193
|
-
disabled?: boolean;
|
|
194
|
-
/** Class name applied to the control. */
|
|
195
|
-
className?: string;
|
|
196
|
-
/** Title/tooltip from the value editor (fallback when labels omit titles). */
|
|
197
|
-
title?: string;
|
|
198
|
-
/** Test ID from the value editor. */
|
|
199
|
-
testID?: string;
|
|
200
|
-
/** Resolved toggle labels (merged with defaults). */
|
|
201
|
-
labels: Required<RelativeDateTimeToggleLabels>;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* A pluggable strategy that governs how a user switches between absolute and relative
|
|
205
|
-
* date/time entry in the {@link RelativeDateTimeValueEditor}. The stored value shape is
|
|
206
|
-
* unaffected — a controller only decides the current mode and (optionally) renders an
|
|
207
|
-
* affordance to change it.
|
|
208
|
-
*
|
|
209
|
-
* Ships with {@link toggleModeController} (the zero-config default); build an
|
|
210
|
-
* operator-driven controller with {@link createOperatorModeController}, or supply a custom
|
|
211
|
-
* object to fully control the UX.
|
|
212
|
-
*/
|
|
213
|
-
interface RelativeDateTimeModeController {
|
|
214
|
-
/** Derives the current mode from the rule (its operator and/or value). */
|
|
215
|
-
isRelative: (props: ValueEditorProps) => boolean;
|
|
216
|
-
/**
|
|
217
|
-
* Optional affordance rendered inside the editor to switch modes. Omit it (as the
|
|
218
|
-
* operator-driven controller does) when the mode is selected elsewhere, e.g. via the
|
|
219
|
-
* operator selector.
|
|
220
|
-
*/
|
|
221
|
-
ModeControl?: ComponentType<RelativeDateTimeModeControlProps>;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Configuration for the {@link RelativeDateTimeValueEditor}, supplied as props to
|
|
225
|
-
* {@link QueryBuilderDateTime} (or via the relative date/time config context). Every
|
|
226
|
-
* field is optional; omitting all of them yields the zero-config toggle experience.
|
|
227
|
-
*/
|
|
228
|
-
interface RelativeDateTimeEditorConfig {
|
|
229
|
-
/** Strategy for switching between absolute and relative modes. Defaults to {@link toggleModeController}. */
|
|
230
|
-
modeController?: RelativeDateTimeModeController;
|
|
231
|
-
/** Anchor (reference-point) options. Defaults to {@link defaultRelativeDateTimeAnchors}. */
|
|
232
|
-
anchors?: FullOption<RelativeDateTimeAnchor>[];
|
|
233
|
-
/** Unit options. Defaults to {@link defaultRelativeDateTimeUnits}. */
|
|
234
|
-
units?: FullOption<RelativeDateTimeUnit>[];
|
|
235
|
-
/** Content/labels for the absolute/relative toggle. */
|
|
236
|
-
toggleLabels?: RelativeDateTimeToggleLabels;
|
|
237
|
-
/**
|
|
238
|
-
* Date/time library adapter used by the value editor to parse/validate the rule value
|
|
239
|
-
* for the native date input. Defaults to the Day.js adapter. Pass the adapter matching
|
|
240
|
-
* your chosen entry point (e.g. from `@react-querybuilder/datetime/luxon`) so the editor
|
|
241
|
-
* interprets values consistently with the rule processors.
|
|
242
|
-
*/
|
|
243
|
-
dateTimeAPI?: RQBDateTimeLibraryAPI;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Maps operator names that are used only to _signal_ relative mode (see
|
|
247
|
-
* {@link createOperatorModeController}) to the real comparison operator that should be used
|
|
248
|
-
* when exporting via `formatQuery`. Supplied through `context.relativeOperatorMap`. Operators
|
|
249
|
-
* not present in the map are exported unchanged.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```ts
|
|
253
|
-
* formatQuery(query, {
|
|
254
|
-
* format: 'sql',
|
|
255
|
-
* ruleProcessor: datetimeRuleProcessorSQL,
|
|
256
|
-
* context: { relativeOperatorMap: { relativeEq: '=' } },
|
|
257
|
-
* });
|
|
258
|
-
* ```
|
|
259
|
-
*/
|
|
260
|
-
type RelativeOperatorMap = Record<string, string>;
|
|
261
161
|
type IsDateFieldFunction = (...[rule, opts]: Parameters<RuleProcessor>) => boolean;
|
|
262
162
|
type IsDateField = IsDateFieldFunction | Record<string, unknown> | Record<string, unknown>[] | boolean | undefined;
|
|
263
163
|
//#endregion
|
|
264
|
-
export {
|
|
265
|
-
//# sourceMappingURL=types-
|
|
164
|
+
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 };
|
|
165
|
+
//# sourceMappingURL=types-Di8kFIXV.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,154 @@
|
|
|
1
|
+
//#region src/utils.ts
|
|
2
|
+
const isISOStringDateOnly = (date) => typeof date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(date);
|
|
3
|
+
/**
|
|
4
|
+
* Type guard for {@link RelativeDateTimeValue}. Relative values are stored as objects
|
|
5
|
+
* (distinguishing them from the ISO 8601 strings used for absolute date/time values).
|
|
6
|
+
*/
|
|
7
|
+
const isRelativeDateTimeValue = (value) => typeof value === "object" && value !== null && value.mode === "relative" && typeof value.anchor === "string";
|
|
8
|
+
const anchorRegExp = /^(start|end)Of(Day|Week|Month|Year)$/;
|
|
9
|
+
/**
|
|
10
|
+
* Resolves a {@link RelativeDateTimeValue} into a concrete `Date` using the given
|
|
11
|
+
* date library API. The anchor is applied relative to `base` (defaulting to now),
|
|
12
|
+
* then the signed offset is added.
|
|
13
|
+
*/
|
|
14
|
+
const resolveRelativeDateTime = (apiFns, value, base = /* @__PURE__ */ new Date()) => {
|
|
15
|
+
let result = base;
|
|
16
|
+
if (value.anchor !== "now") {
|
|
17
|
+
const match = anchorRegExp.exec(value.anchor);
|
|
18
|
+
// v8 ignore next -- guarded by the RelativeDateTimeAnchor type
|
|
19
|
+
if (match) {
|
|
20
|
+
const unit = match[2].toLowerCase();
|
|
21
|
+
result = match[1] === "start" ? apiFns.startOf(result, unit) : apiFns.endOf(result, unit);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (value.offset) result = apiFns.add(result, value.offset, value.unit);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Whether a `datatype` represents a date-only (no time component) type, e.g. `date`
|
|
29
|
+
* but not `datetime`/`datetimeoffset`/`timestamp`. Used to choose the precision when
|
|
30
|
+
* materializing a relative value to an ISO 8601 string.
|
|
31
|
+
*/
|
|
32
|
+
const isDateOnlyDatatype = (datatype) => /^date\b/i.test(datatype);
|
|
33
|
+
/**
|
|
34
|
+
* Replaces any {@link RelativeDateTimeValue} in `value` (or in each element, if `value`
|
|
35
|
+
* is an array) with a concrete ISO 8601 string, resolved via
|
|
36
|
+
* {@link resolveRelativeDateTime}. The "now" reference can be pinned with
|
|
37
|
+
* `opts.context.relativeDateTimeBase` for deterministic output; precision (date-only vs
|
|
38
|
+
* full) follows the field's `datatype`. Non-relative values pass through unchanged.
|
|
39
|
+
*/
|
|
40
|
+
const materializeRelativeValues = (apiFns, value, opts) => {
|
|
41
|
+
const base = opts?.context?.relativeDateTimeBase;
|
|
42
|
+
const dateOnly = isDateOnlyDatatype(opts?.fieldData?.datatype);
|
|
43
|
+
const conv = (v) => {
|
|
44
|
+
if (!isRelativeDateTimeValue(v)) return v;
|
|
45
|
+
const resolved = resolveRelativeDateTime(apiFns, v, base);
|
|
46
|
+
return dateOnly ? apiFns.toISOStringDateOnly(resolved) : apiFns.toISOString(resolved);
|
|
47
|
+
};
|
|
48
|
+
return Array.isArray(value) ? value.map(conv) : conv(value);
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Resolves a rule's operator for export, applying any `context.relativeOperatorMap`
|
|
52
|
+
* entry. Operator-driven mode controllers (see `createOperatorModeController`) use
|
|
53
|
+
* dedicated operator names to signal relative mode; this maps those names to the real
|
|
54
|
+
* comparison operator at format time. Operators absent from the map pass through unchanged.
|
|
55
|
+
*/
|
|
56
|
+
const resolveDatetimeOperator = (...[rule, opts]) => (opts?.context?.relativeOperatorMap)?.[rule.operator] ?? rule.operator;
|
|
57
|
+
/**
|
|
58
|
+
* Prepares a date/time rule for delegation to a non-symbolic default rule processor
|
|
59
|
+
* (e.g. "parameterized", "spel", "ldap", "gremlin", "prisma", "sequelize", "drizzle",
|
|
60
|
+
* "tanstack_db"). Relative values are materialized to concrete dates (these formats have
|
|
61
|
+
* no symbolic relative form), and `between`/`notBetween` operands are ordered
|
|
62
|
+
* chronologically (defaults can't reorder non-numeric date operands). When `asDate` is
|
|
63
|
+
* set, each valid value is converted to a `Date` (for object-based formats); otherwise
|
|
64
|
+
* the materialized ISO 8601 strings are passed through. The resolved `operator` (after
|
|
65
|
+
* any `relativeOperatorMap` mapping) is returned alongside the prepared `value`.
|
|
66
|
+
*/
|
|
67
|
+
const materializeForExport = (apiFns, rule, opts, asDate = false) => {
|
|
68
|
+
const operator = resolveDatetimeOperator(rule, opts);
|
|
69
|
+
const materialized = materializeRelativeValues(apiFns, rule.value, opts);
|
|
70
|
+
let prepared = materialized;
|
|
71
|
+
if (Array.isArray(materialized) && materialized.length >= 2) {
|
|
72
|
+
const opLC = operator.toLowerCase();
|
|
73
|
+
if (opLC === "between" || opLC === "notbetween") {
|
|
74
|
+
const first = apiFns.toDate(materialized[0]);
|
|
75
|
+
const second = apiFns.toDate(materialized[1]);
|
|
76
|
+
if (apiFns.isValid(first) && apiFns.isValid(second) && !apiFns.isBefore(first, second)) prepared = [
|
|
77
|
+
materialized[1],
|
|
78
|
+
materialized[0],
|
|
79
|
+
...materialized.slice(2)
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!asDate) return {
|
|
84
|
+
operator,
|
|
85
|
+
value: prepared
|
|
86
|
+
};
|
|
87
|
+
const toDateVal = (v) => {
|
|
88
|
+
const d = apiFns.toDate(v);
|
|
89
|
+
return apiFns.isValid(d) ? d : v;
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
operator,
|
|
93
|
+
value: Array.isArray(prepared) ? prepared.map(toDateVal) : toDateVal(prepared)
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
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);
|
|
97
|
+
const processIsDateField = (isDateField, ...[rule, opts]) => {
|
|
98
|
+
if (typeof isDateField === "boolean") return isDateField;
|
|
99
|
+
if (typeof isDateField === "function") return isDateField(rule, opts);
|
|
100
|
+
if (Array.isArray(isDateField)) return isDateField.some((condition) => Object.entries(condition).every(([key, value]) => opts?.fieldData?.[key] === value));
|
|
101
|
+
if (typeof isDateField === "object") return Object.entries(isDateField).every(([key, value]) => opts?.fieldData?.[key] === value);
|
|
102
|
+
return defaultIsDateField(rule, opts);
|
|
103
|
+
};
|
|
104
|
+
//#endregion
|
|
105
|
+
Object.defineProperty(exports, "isDateOnlyDatatype", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function() {
|
|
108
|
+
return isDateOnlyDatatype;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(exports, "isISOStringDateOnly", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: function() {
|
|
114
|
+
return isISOStringDateOnly;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(exports, "isRelativeDateTimeValue", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function() {
|
|
120
|
+
return isRelativeDateTimeValue;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
Object.defineProperty(exports, "materializeForExport", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function() {
|
|
126
|
+
return materializeForExport;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(exports, "materializeRelativeValues", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function() {
|
|
132
|
+
return materializeRelativeValues;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, "processIsDateField", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function() {
|
|
138
|
+
return processIsDateField;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(exports, "resolveDatetimeOperator", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function() {
|
|
144
|
+
return resolveDatetimeOperator;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, "resolveRelativeDateTime", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function() {
|
|
150
|
+
return resolveRelativeDateTime;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=utils-DUePrC--.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-DUePrC--.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import type { RuleProcessor } 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 * 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
|
+
const e=e=>typeof e==`string`&&/^\d{4}-\d{2}-\d{2}$/.test(e),t=e=>typeof e==`object`&&!!e&&e.mode===`relative`&&typeof e.anchor==`string`,n=/^(start|end)Of(Day|Week|Month|Year)$/,r=(e,t,r=new Date)=>{let i=r;if(t.anchor!==`now`){let r=n.exec(t.anchor);if(r){let t=r[2].toLowerCase();i=r[1]===`start`?e.startOf(i,t):e.endOf(i,t)}}return t.offset&&(i=e.add(i,t.offset,t.unit)),i},i=e=>/^date\b/i.test(e),a=(e,n,a)=>{let o=a?.context?.relativeDateTimeBase,s=i(a?.fieldData?.datatype),c=n=>{if(!t(n))return n;let i=r(e,n,o);return s?e.toISOStringDateOnly(i):e.toISOString(i)};return Array.isArray(n)?n.map(c):c(n)},o=(...[e,t])=>t?.context?.relativeOperatorMap?.[e.operator]??e.operator,s=(e,t,n,r=!1)=>{let i=o(t,n),s=a(e,t.value,n),c=s;if(Array.isArray(s)&&s.length>=2){let t=i.toLowerCase();if(t===`between`||t===`notbetween`){let t=e.toDate(s[0]),n=e.toDate(s[1]);e.isValid(t)&&e.isValid(n)&&!e.isBefore(t,n)&&(c=[s[1],s[0],...s.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)}},c=(...[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),l=(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):c(t,n);Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
|
|
2
|
+
//# sourceMappingURL=utils-jkW5R1AA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-jkW5R1AA.js","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import type { RuleProcessor } 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 * 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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"}
|
|
@@ -1,108 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
const base = opts?.context?.relativeDateTimeBase;
|
|
43
|
-
const dateOnly = isDateOnlyDatatype(opts?.fieldData?.datatype);
|
|
44
|
-
const conv = (v) => {
|
|
45
|
-
if (!isRelativeDateTimeValue(v)) return v;
|
|
46
|
-
const resolved = resolveRelativeDateTime(apiFns, v, base);
|
|
47
|
-
return dateOnly ? apiFns.toISOStringDateOnly(resolved) : apiFns.toISOString(resolved);
|
|
48
|
-
};
|
|
49
|
-
return Array.isArray(value) ? value.map(conv) : conv(value);
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Resolves a rule's operator for export, applying any `context.relativeOperatorMap`
|
|
53
|
-
* entry. Operator-driven mode controllers (see `createOperatorModeController`) use
|
|
54
|
-
* dedicated operator names to signal relative mode; this maps those names to the real
|
|
55
|
-
* comparison operator at format time. Operators absent from the map pass through unchanged.
|
|
56
|
-
*/
|
|
57
|
-
const resolveDatetimeOperator = (...[rule, opts]) => (opts?.context?.relativeOperatorMap)?.[rule.operator] ?? rule.operator;
|
|
58
|
-
/**
|
|
59
|
-
* Prepares a date/time rule for delegation to a non-symbolic default rule processor
|
|
60
|
-
* (e.g. "parameterized", "spel", "ldap", "gremlin", "prisma", "sequelize", "drizzle",
|
|
61
|
-
* "tanstack_db"). Relative values are materialized to concrete dates (these formats have
|
|
62
|
-
* no symbolic relative form), and `between`/`notBetween` operands are ordered
|
|
63
|
-
* chronologically (defaults can't reorder non-numeric date operands). When `asDate` is
|
|
64
|
-
* set, each valid value is converted to a `Date` (for object-based formats); otherwise
|
|
65
|
-
* the materialized ISO 8601 strings are passed through. The resolved `operator` (after
|
|
66
|
-
* any `relativeOperatorMap` mapping) is returned alongside the prepared `value`.
|
|
67
|
-
*/
|
|
68
|
-
const materializeForExport = (apiFns, rule, opts, asDate = false) => {
|
|
69
|
-
const operator = resolveDatetimeOperator(rule, opts);
|
|
70
|
-
const materialized = materializeRelativeValues(apiFns, rule.value, opts);
|
|
71
|
-
let prepared = materialized;
|
|
72
|
-
if (Array.isArray(materialized) && materialized.length >= 2) {
|
|
73
|
-
const opLC = operator.toLowerCase();
|
|
74
|
-
if (opLC === "between" || opLC === "notbetween") {
|
|
75
|
-
const first = apiFns.toDate(materialized[0]);
|
|
76
|
-
const second = apiFns.toDate(materialized[1]);
|
|
77
|
-
if (apiFns.isValid(first) && apiFns.isValid(second) && !apiFns.isBefore(first, second)) prepared = [
|
|
78
|
-
materialized[1],
|
|
79
|
-
materialized[0],
|
|
80
|
-
...materialized.slice(2)
|
|
81
|
-
];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (!asDate) return {
|
|
85
|
-
operator,
|
|
86
|
-
value: prepared
|
|
87
|
-
};
|
|
88
|
-
const toDateVal = (v) => {
|
|
89
|
-
const d = apiFns.toDate(v);
|
|
90
|
-
return apiFns.isValid(d) ? d : v;
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
operator,
|
|
94
|
-
value: Array.isArray(prepared) ? prepared.map(toDateVal) : toDateVal(prepared)
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
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);
|
|
98
|
-
const processIsDateField = (isDateField, ...[rule, opts]) => {
|
|
99
|
-
if (typeof isDateField === "boolean") return isDateField;
|
|
100
|
-
if (typeof isDateField === "function") return isDateField(rule, opts);
|
|
101
|
-
if (Array.isArray(isDateField)) return isDateField.some((condition) => Object.entries(condition).every(([key, value]) => opts?.fieldData?.[key] === value));
|
|
102
|
-
if (typeof isDateField === "object") return Object.entries(isDateField).every(([key, value]) => opts?.fieldData?.[key] === value);
|
|
103
|
-
return defaultIsDateField(rule, opts);
|
|
104
|
-
};
|
|
105
|
-
//#endregion
|
|
1
|
+
import { a as materializeRelativeValues, c as resolveRelativeDateTime, i as materializeForExport, n as isISOStringDateOnly, o as processIsDateField, r as isRelativeDateTimeValue, s as resolveDatetimeOperator } from "./utils-BC2SALFm.mjs";
|
|
2
|
+
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/core";
|
|
106
3
|
//#region src/getDatetimeJsonLogicOperations.ts
|
|
107
4
|
/**
|
|
108
5
|
* Custom operations for use with JsonLogic objects generated by
|
|
@@ -1024,6 +921,6 @@ const getDatetimeRuleProcessorTanStackDB = (apiFns) => (rule, options) => {
|
|
|
1024
921
|
}, opts);
|
|
1025
922
|
};
|
|
1026
923
|
//#endregion
|
|
1027
|
-
export {
|
|
924
|
+
export { getDatetimeRuleProcessorCypher as C, getDatetimeRuleProcessorDrizzle as S, getDatetimeJsonLogicOperations 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, 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, getDatetimeRuleProcessorCEL as w, getDatetimeRuleProcessorElasticSearch as x, getDatetimeRuleProcessorJSONata as y };
|
|
1028
925
|
|
|
1029
|
-
//# sourceMappingURL=getDatetimeRuleProcessorTanStackDB-
|
|
926
|
+
//# sourceMappingURL=getDatetimeRuleProcessorTanStackDB-B93XaPdB.mjs.map
|