@vectoriahq/quac 0.18.0 → 0.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.
|
@@ -518,7 +518,7 @@ function parseFieldEditRules(maplayer, note) {
|
|
|
518
518
|
const defaultValue = parseDefaultExpression(expression, onUpdate);
|
|
519
519
|
if (defaultValue)
|
|
520
520
|
ruleFor(name).defaultValue = defaultValue;
|
|
521
|
-
else if (readQgisExpression(expression, { geometry: true, aggregates: true, lookups: true, variables: true, coordinates: true }))
|
|
521
|
+
else if (readQgisExpression(expression, { geometry: true, aggregates: true, lookups: true, variables: true, coordinates: true, dates: true }))
|
|
522
522
|
ruleFor(name).defaultExpression = { expression: expression.trim(), onUpdate };
|
|
523
523
|
else
|
|
524
524
|
note('default', name, expression.trim());
|
|
@@ -166,9 +166,15 @@ export declare function isQgisConditionFilter(filter: unknown): filter is {
|
|
|
166
166
|
*
|
|
167
167
|
* `format_date` is read where its pattern and any language are text written
|
|
168
168
|
* into the expression, and the pattern holds no `t` (`qtDateFormat.ts`).
|
|
169
|
-
* `now()`, or `$now`, is read
|
|
170
|
-
*
|
|
171
|
-
*
|
|
169
|
+
* `now()`, or `$now`, is read as the date of `format_date` or of a function
|
|
170
|
+
* that takes a part of a date, such as `year`. Where the caller says `dates`
|
|
171
|
+
* (a default value), it is read as a date in three more places: as the value
|
|
172
|
+
* of the whole expression, as a side of a comparison, and as the date an
|
|
173
|
+
* interval is added to or taken from. A branch of `if`, `CASE` or `coalesce`
|
|
174
|
+
* in any of those places is one too, as in
|
|
175
|
+
* `if("condition" IS NULL, "checked", now())`. Anywhere else, such as inside
|
|
176
|
+
* `||` or `to_string`, it would be used as text or a number, which the
|
|
177
|
+
* evaluator does not do (`findDatedNows`).
|
|
172
178
|
*
|
|
173
179
|
* A variable other than `@parent`, such as `@cloud_useremail`, is read only
|
|
174
180
|
* where the caller says `variables`: the caller then supplies each one's value
|
|
@@ -191,6 +197,7 @@ export declare function readQgisExpression(expression: string, options?: {
|
|
|
191
197
|
lookups?: boolean;
|
|
192
198
|
variables?: boolean;
|
|
193
199
|
coordinates?: boolean;
|
|
200
|
+
dates?: boolean;
|
|
194
201
|
}): ExpressionNode | null;
|
|
195
202
|
/**
|
|
196
203
|
* A QGIS rule's condition as a GeoStyler filter: the condition's GeoStyler
|
|
@@ -312,9 +312,15 @@ export function isQgisConditionFilter(filter) {
|
|
|
312
312
|
*
|
|
313
313
|
* `format_date` is read where its pattern and any language are text written
|
|
314
314
|
* into the expression, and the pattern holds no `t` (`qtDateFormat.ts`).
|
|
315
|
-
* `now()`, or `$now`, is read
|
|
316
|
-
*
|
|
317
|
-
*
|
|
315
|
+
* `now()`, or `$now`, is read as the date of `format_date` or of a function
|
|
316
|
+
* that takes a part of a date, such as `year`. Where the caller says `dates`
|
|
317
|
+
* (a default value), it is read as a date in three more places: as the value
|
|
318
|
+
* of the whole expression, as a side of a comparison, and as the date an
|
|
319
|
+
* interval is added to or taken from. A branch of `if`, `CASE` or `coalesce`
|
|
320
|
+
* in any of those places is one too, as in
|
|
321
|
+
* `if("condition" IS NULL, "checked", now())`. Anywhere else, such as inside
|
|
322
|
+
* `||` or `to_string`, it would be used as text or a number, which the
|
|
323
|
+
* evaluator does not do (`findDatedNows`).
|
|
318
324
|
*
|
|
319
325
|
* A variable other than `@parent`, such as `@cloud_useremail`, is read only
|
|
320
326
|
* where the caller says `variables`: the caller then supplies each one's value
|
|
@@ -365,7 +371,7 @@ export function readQgisExpression(expression, options = {}) {
|
|
|
365
371
|
const formatDateCalls = findCalls(parsed.node, 'format_date');
|
|
366
372
|
if (!formatDateCalls.every(isReadableFormatDate))
|
|
367
373
|
return null;
|
|
368
|
-
const datedNows = new Set(
|
|
374
|
+
const datedNows = new Set(findDatedNows(parsed.node, options.dates === true, options.dates === true));
|
|
369
375
|
if (findCalls(parsed.node, 'now').some((call) => !datedNows.has(call)))
|
|
370
376
|
return null;
|
|
371
377
|
if (!areLookupsReadable(parsed.node, options.lookups === true))
|
|
@@ -795,11 +801,46 @@ function childNodes(node) {
|
|
|
795
801
|
return [];
|
|
796
802
|
}
|
|
797
803
|
}
|
|
804
|
+
/** Whether a node is a `+` or `-` with a `make_interval` call as its right side. */
|
|
805
|
+
function isAddedInterval(node) {
|
|
806
|
+
return node.kind === 'arithmetic' && (node.op === '+' || node.op === '-') && node.right.kind === 'call' && node.right.name === 'make_interval';
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* The `now()` calls at or under a node that stand where the evaluator takes a
|
|
810
|
+
* date (`readQgisExpression`). `dated` says whether the node itself stands in
|
|
811
|
+
* one; `dates` is the caller's option, without which only the first argument
|
|
812
|
+
* of a `DATE_TAKERS` call does.
|
|
813
|
+
*/
|
|
814
|
+
function findDatedNows(node, dated, dates) {
|
|
815
|
+
if (node.kind === 'call' && node.name === 'now')
|
|
816
|
+
return dated ? [node] : [];
|
|
817
|
+
return datedChildren(node, dated, dates).flatMap(([child, childDated]) => findDatedNows(child, childDated, dates));
|
|
818
|
+
}
|
|
819
|
+
/** The nodes directly under a node, each with whether it stands where a date is taken. */
|
|
820
|
+
function datedChildren(node, dated, dates) {
|
|
821
|
+
if (node.kind === 'call' && DATE_TAKERS.includes(node.name))
|
|
822
|
+
return node.args.map((arg, index) => [arg, index === 0]);
|
|
823
|
+
if (dates) {
|
|
824
|
+
if (node.kind === 'compare')
|
|
825
|
+
return [[node.left, true], [node.right, true]];
|
|
826
|
+
if (isAddedInterval(node))
|
|
827
|
+
return [[node.left, dated], [node.right, false]];
|
|
828
|
+
if (node.kind === 'call' && node.name === 'if')
|
|
829
|
+
return node.args.map((arg, index) => [arg, dated && index > 0]);
|
|
830
|
+
if (node.kind === 'call' && node.name === 'coalesce')
|
|
831
|
+
return node.args.map((arg) => [arg, dated]);
|
|
832
|
+
if (node.kind === 'case') {
|
|
833
|
+
return [
|
|
834
|
+
...node.whens.flatMap(({ when, then }) => [[when, false], [then, dated]]),
|
|
835
|
+
...(node.otherwise ? [[node.otherwise, dated]] : [])
|
|
836
|
+
];
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return childNodes(node).map((child) => [child, false]);
|
|
840
|
+
}
|
|
798
841
|
/** The `make_interval` calls that are the right side of a `+` or `-` at or under a node. */
|
|
799
842
|
function findAddedIntervals(node) {
|
|
800
|
-
const own =
|
|
801
|
-
? [node.right]
|
|
802
|
-
: [];
|
|
843
|
+
const own = isAddedInterval(node) ? [node.right] : [];
|
|
803
844
|
return [...own, ...childNodes(node).flatMap(findAddedIntervals)];
|
|
804
845
|
}
|
|
805
846
|
/**
|