@defra/forms-model 3.0.161 → 3.0.163
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/package.json +1 -1
- package/dist/module/conditions/inline-condition-model.js +0 -385
- package/dist/module/conditions/inline-condition-model.js.map +0 -1
- package/dist/module/conditions/inline-condition-operators.js +0 -111
- package/dist/module/conditions/inline-condition-operators.js.map +0 -1
- package/dist/module/conditions/inline-condition-values.js +0 -134
- package/dist/module/conditions/inline-condition-values.js.map +0 -1
- package/dist/types/conditions/inline-condition-model.d.ts +0 -86
- package/dist/types/conditions/inline-condition-model.d.ts.map +0 -1
- package/dist/types/conditions/inline-condition-operators.d.ts +0 -175
- package/dist/types/conditions/inline-condition-operators.d.ts.map +0 -1
- package/dist/types/conditions/inline-condition-values.d.ts +0 -93
- package/dist/types/conditions/inline-condition-values.d.ts.map +0 -1
- package/src/conditions/inline-condition-model.ts +0 -553
- package/src/conditions/inline-condition-operators.ts +0 -166
- package/src/conditions/inline-condition-values.ts +0 -153
package/package.json
CHANGED
@@ -1,385 +0,0 @@
|
|
1
|
-
import { ComponentTypes } from "../components/component-types.js";
|
2
|
-
import { getExpression } from "./inline-condition-operators.js";
|
3
|
-
import { AbstractConditionValue, valueFrom } from "./inline-condition-values.js";
|
4
|
-
export const coordinators = {
|
5
|
-
AND: 'and',
|
6
|
-
OR: 'or'
|
7
|
-
};
|
8
|
-
export class ConditionsModel {
|
9
|
-
#groupedConditions;
|
10
|
-
#userGroupedConditions;
|
11
|
-
#conditionName;
|
12
|
-
constructor() {
|
13
|
-
this.#groupedConditions = [];
|
14
|
-
this.#userGroupedConditions = [];
|
15
|
-
}
|
16
|
-
clone() {
|
17
|
-
const toReturn = new ConditionsModel();
|
18
|
-
toReturn.#groupedConditions = this.#groupedConditions.map(it => it.clone());
|
19
|
-
toReturn.#userGroupedConditions = this.#userGroupedConditions.map(it => it.clone());
|
20
|
-
toReturn.#conditionName = this.#conditionName;
|
21
|
-
return toReturn;
|
22
|
-
}
|
23
|
-
clear() {
|
24
|
-
this.#userGroupedConditions = [];
|
25
|
-
this.#groupedConditions = [];
|
26
|
-
this.#conditionName = undefined;
|
27
|
-
return this;
|
28
|
-
}
|
29
|
-
set name(name) {
|
30
|
-
this.#conditionName = name;
|
31
|
-
}
|
32
|
-
get name() {
|
33
|
-
return this.#conditionName;
|
34
|
-
}
|
35
|
-
add(condition) {
|
36
|
-
const coordinatorExpected = this.#userGroupedConditions.length !== 0;
|
37
|
-
if (condition.getCoordinator() && !coordinatorExpected) {
|
38
|
-
throw Error('No coordinator allowed on the first condition');
|
39
|
-
} else if (!condition.getCoordinator() && coordinatorExpected) {
|
40
|
-
throw Error('Coordinator must be present on subsequent conditions');
|
41
|
-
}
|
42
|
-
this.#userGroupedConditions.push(condition);
|
43
|
-
this.#groupedConditions = this._applyGroups(this.#userGroupedConditions);
|
44
|
-
return this;
|
45
|
-
}
|
46
|
-
replace(index, condition) {
|
47
|
-
const coordinatorExpected = index !== 0;
|
48
|
-
if (condition.getCoordinator() && !coordinatorExpected) {
|
49
|
-
throw Error('No coordinator allowed on the first condition');
|
50
|
-
} else if (!condition.getCoordinator() && coordinatorExpected) {
|
51
|
-
throw Error('Coordinator must be present on subsequent conditions');
|
52
|
-
} else if (index >= this.#userGroupedConditions.length) {
|
53
|
-
throw Error(`Cannot replace condition ${index} as no such condition exists`);
|
54
|
-
}
|
55
|
-
this.#userGroupedConditions.splice(index, 1, condition);
|
56
|
-
this.#groupedConditions = this._applyGroups(this.#userGroupedConditions);
|
57
|
-
return this;
|
58
|
-
}
|
59
|
-
remove(indexes) {
|
60
|
-
this.#userGroupedConditions = this.#userGroupedConditions.filter((_condition, index) => !indexes.includes(index)).map((condition, index) => index === 0 ? condition.asFirstCondition() : condition);
|
61
|
-
this.#groupedConditions = this._applyGroups(this.#userGroupedConditions);
|
62
|
-
return this;
|
63
|
-
}
|
64
|
-
addGroups(groupDefs) {
|
65
|
-
this.#userGroupedConditions = this._group(this.#userGroupedConditions, groupDefs);
|
66
|
-
this.#groupedConditions = this._applyGroups(this.#userGroupedConditions);
|
67
|
-
return this;
|
68
|
-
}
|
69
|
-
splitGroup(index) {
|
70
|
-
this.#userGroupedConditions = this._ungroup(this.#userGroupedConditions, index);
|
71
|
-
this.#groupedConditions = this._applyGroups(this.#userGroupedConditions);
|
72
|
-
return this;
|
73
|
-
}
|
74
|
-
moveEarlier(index) {
|
75
|
-
if (index > 0 && index < this.#userGroupedConditions.length) {
|
76
|
-
this.#userGroupedConditions.splice(index - 1, 0, this.#userGroupedConditions.splice(index, 1)[0]);
|
77
|
-
if (index === 1) {
|
78
|
-
this.switchCoordinators();
|
79
|
-
}
|
80
|
-
this.#groupedConditions = this._applyGroups(this.#userGroupedConditions);
|
81
|
-
}
|
82
|
-
return this;
|
83
|
-
}
|
84
|
-
moveLater(index) {
|
85
|
-
if (index >= 0 && index < this.#userGroupedConditions.length - 1) {
|
86
|
-
this.#userGroupedConditions.splice(index + 1, 0, this.#userGroupedConditions.splice(index, 1)[0]);
|
87
|
-
if (index === 0) {
|
88
|
-
this.switchCoordinators();
|
89
|
-
}
|
90
|
-
this.#groupedConditions = this._applyGroups(this.#userGroupedConditions);
|
91
|
-
}
|
92
|
-
return this;
|
93
|
-
}
|
94
|
-
switchCoordinators() {
|
95
|
-
this.#userGroupedConditions[1].setCoordinator(this.#userGroupedConditions[0].getCoordinator());
|
96
|
-
this.#userGroupedConditions[0].setCoordinator(undefined);
|
97
|
-
}
|
98
|
-
get asPerUserGroupings() {
|
99
|
-
return [...this.#userGroupedConditions];
|
100
|
-
}
|
101
|
-
get hasConditions() {
|
102
|
-
return this.#userGroupedConditions.length > 0;
|
103
|
-
}
|
104
|
-
get lastIndex() {
|
105
|
-
return this.#userGroupedConditions.length - 1;
|
106
|
-
}
|
107
|
-
toPresentationString() {
|
108
|
-
return this.#groupedConditions.map(condition => toPresentationString(condition)).join(' ');
|
109
|
-
}
|
110
|
-
toExpression() {
|
111
|
-
return this.#groupedConditions.map(condition => toExpression(condition)).join(' ');
|
112
|
-
}
|
113
|
-
_applyGroups(userGroupedConditions) {
|
114
|
-
const correctedUserGroups = userGroupedConditions.map(condition => condition instanceof ConditionGroup && condition.conditions.length > 2 ? new ConditionGroup(this._group(condition.conditions, this._autoGroupDefs(condition.conditions))) : condition);
|
115
|
-
return this._group(correctedUserGroups, this._autoGroupDefs(correctedUserGroups));
|
116
|
-
}
|
117
|
-
_group(conditions, groupDefs) {
|
118
|
-
return conditions.reduce((groups, condition, index, conditions) => {
|
119
|
-
const groupDef = groupDefs.find(groupDef => groupDef.contains(index));
|
120
|
-
if (groupDef) {
|
121
|
-
if (groupDef.startsWith(index)) {
|
122
|
-
const groupConditions = groupDef.applyTo(conditions);
|
123
|
-
groups.push(new ConditionGroup(groupConditions));
|
124
|
-
}
|
125
|
-
} else {
|
126
|
-
groups.push(condition);
|
127
|
-
}
|
128
|
-
return groups;
|
129
|
-
}, []);
|
130
|
-
}
|
131
|
-
_ungroup(conditions, splitIndex) {
|
132
|
-
if (conditions[splitIndex].isGroup()) {
|
133
|
-
const copy = [...conditions];
|
134
|
-
copy.splice(splitIndex, 1, ...conditions[splitIndex].getGroupedConditions());
|
135
|
-
return copy;
|
136
|
-
}
|
137
|
-
return conditions;
|
138
|
-
}
|
139
|
-
_autoGroupDefs(conditions) {
|
140
|
-
const orPositions = [];
|
141
|
-
conditions.forEach((condition, index) => {
|
142
|
-
if (condition.getCoordinator() === coordinators.OR) {
|
143
|
-
orPositions.push(index);
|
144
|
-
}
|
145
|
-
});
|
146
|
-
const hasAnd = !!conditions.find(condition => condition.getCoordinator() === coordinators.AND);
|
147
|
-
const hasOr = orPositions.length > 0;
|
148
|
-
if (hasAnd && hasOr) {
|
149
|
-
let start = 0;
|
150
|
-
const groupDefs = [];
|
151
|
-
orPositions.forEach((position, index) => {
|
152
|
-
if (start < position - 1) {
|
153
|
-
groupDefs.push(new GroupDef(start, position - 1));
|
154
|
-
}
|
155
|
-
const thisIsTheLastOr = orPositions.length === index + 1;
|
156
|
-
const thereAreMoreConditions = conditions.length - 1 > position;
|
157
|
-
if (thisIsTheLastOr && thereAreMoreConditions) {
|
158
|
-
groupDefs.push(new GroupDef(position, conditions.length - 1));
|
159
|
-
}
|
160
|
-
start = position;
|
161
|
-
});
|
162
|
-
return groupDefs;
|
163
|
-
}
|
164
|
-
return [];
|
165
|
-
}
|
166
|
-
toJSON() {
|
167
|
-
const name = this.#conditionName;
|
168
|
-
const conditions = this.#userGroupedConditions;
|
169
|
-
return {
|
170
|
-
name,
|
171
|
-
conditions: conditions.map(it => it.clone())
|
172
|
-
};
|
173
|
-
}
|
174
|
-
static from(obj) {
|
175
|
-
if (obj instanceof ConditionsModel) {
|
176
|
-
return obj;
|
177
|
-
}
|
178
|
-
const toReturn = new ConditionsModel();
|
179
|
-
toReturn.#conditionName = obj.name;
|
180
|
-
toReturn.#userGroupedConditions = obj.conditions.map(it => conditionFrom(it));
|
181
|
-
toReturn.#groupedConditions = toReturn._applyGroups(toReturn.#userGroupedConditions);
|
182
|
-
return toReturn;
|
183
|
-
}
|
184
|
-
}
|
185
|
-
function conditionFrom(it) {
|
186
|
-
if (it.conditions) {
|
187
|
-
return new ConditionGroup(it.conditions.map(condition => conditionFrom(condition)));
|
188
|
-
}
|
189
|
-
if (it.conditionName) {
|
190
|
-
return new ConditionRef(it.conditionName, it.conditionDisplayName, it.coordinator);
|
191
|
-
}
|
192
|
-
return new Condition(Field.from(it.field), it.operator, valueFrom(it.value), it.coordinator);
|
193
|
-
}
|
194
|
-
export class GroupDef {
|
195
|
-
first;
|
196
|
-
last;
|
197
|
-
constructor(first, last) {
|
198
|
-
if (typeof first !== 'number' || typeof last !== 'number') {
|
199
|
-
throw Error(`Cannot construct a group from ${first} and ${last}`);
|
200
|
-
} else if (first >= last) {
|
201
|
-
throw Error(`Last (${last}) must be greater than first (${first})`);
|
202
|
-
}
|
203
|
-
this.first = first;
|
204
|
-
this.last = last;
|
205
|
-
}
|
206
|
-
contains(index) {
|
207
|
-
return this.first <= index && this.last >= index;
|
208
|
-
}
|
209
|
-
startsWith(index) {
|
210
|
-
return this.first === index;
|
211
|
-
}
|
212
|
-
applyTo(conditions) {
|
213
|
-
return [...conditions].splice(this.first, this.last - this.first + 1);
|
214
|
-
}
|
215
|
-
}
|
216
|
-
class ConditionGroup {
|
217
|
-
conditions;
|
218
|
-
constructor(conditions) {
|
219
|
-
if (!Array.isArray(conditions) || conditions.length < 2) {
|
220
|
-
throw Error('Cannot construct a condition group from a single condition');
|
221
|
-
}
|
222
|
-
this.conditions = conditions;
|
223
|
-
}
|
224
|
-
coordinatorString() {
|
225
|
-
return this.conditions[0].coordinatorString();
|
226
|
-
}
|
227
|
-
conditionString() {
|
228
|
-
const copy = [...this.conditions];
|
229
|
-
copy.splice(0, 1);
|
230
|
-
return `(${this.conditions[0].conditionString()} ${copy.map(condition => toPresentationString(condition)).join(' ')})`;
|
231
|
-
}
|
232
|
-
conditionExpression() {
|
233
|
-
const copy = [...this.conditions];
|
234
|
-
copy.splice(0, 1);
|
235
|
-
return `(${this.conditions[0].conditionExpression()} ${copy.map(condition => toExpression(condition)).join(' ')})`;
|
236
|
-
}
|
237
|
-
asFirstCondition() {
|
238
|
-
this.conditions[0].asFirstCondition();
|
239
|
-
return this;
|
240
|
-
}
|
241
|
-
getCoordinator() {
|
242
|
-
return this.conditions[0].getCoordinator();
|
243
|
-
}
|
244
|
-
setCoordinator(coordinator) {
|
245
|
-
this.conditions[0].setCoordinator(coordinator);
|
246
|
-
}
|
247
|
-
isGroup() {
|
248
|
-
return true;
|
249
|
-
}
|
250
|
-
getGroupedConditions() {
|
251
|
-
return this.conditions.map(condition => condition.clone());
|
252
|
-
}
|
253
|
-
clone() {
|
254
|
-
return new ConditionGroup(this.conditions.map(condition => condition.clone()));
|
255
|
-
}
|
256
|
-
}
|
257
|
-
export function toPresentationString(condition) {
|
258
|
-
return `${condition.coordinatorString()}${condition.conditionString()}`;
|
259
|
-
}
|
260
|
-
export function toExpression(condition) {
|
261
|
-
return `${condition.coordinatorString()}${condition.conditionExpression()}`;
|
262
|
-
}
|
263
|
-
export class Field {
|
264
|
-
name;
|
265
|
-
type;
|
266
|
-
display;
|
267
|
-
constructor(name, type, display) {
|
268
|
-
if (!name || typeof name !== 'string') {
|
269
|
-
throw Error(`name ${name} is not valid`);
|
270
|
-
}
|
271
|
-
if (!ComponentTypes.find(componentType => componentType.name === type)) {
|
272
|
-
throw Error(`type ${type} is not valid`);
|
273
|
-
}
|
274
|
-
if (!display || typeof display !== 'string') {
|
275
|
-
throw Error(`display ${display} is not valid`);
|
276
|
-
}
|
277
|
-
this.name = name;
|
278
|
-
this.type = type;
|
279
|
-
this.display = display;
|
280
|
-
}
|
281
|
-
static from(obj) {
|
282
|
-
return new Field(obj.name, obj.type, obj.display);
|
283
|
-
}
|
284
|
-
}
|
285
|
-
class AbstractCondition {
|
286
|
-
coordinator;
|
287
|
-
constructor(coordinator) {
|
288
|
-
if (coordinator && !Object.values(coordinators).includes(coordinator)) {
|
289
|
-
throw Error(`coordinator ${coordinator} is not a valid coordinator`);
|
290
|
-
}
|
291
|
-
this.coordinator = coordinator;
|
292
|
-
}
|
293
|
-
coordinatorString() {
|
294
|
-
return this.coordinator ? `${this.coordinator} ` : '';
|
295
|
-
}
|
296
|
-
getCoordinator() {
|
297
|
-
return this.coordinator;
|
298
|
-
}
|
299
|
-
setCoordinator(coordinator) {
|
300
|
-
this.coordinator = coordinator;
|
301
|
-
}
|
302
|
-
isGroup() {
|
303
|
-
return false;
|
304
|
-
}
|
305
|
-
getGroupedConditions() {
|
306
|
-
return [this];
|
307
|
-
}
|
308
|
-
_asFirstCondition() {
|
309
|
-
delete this.coordinator;
|
310
|
-
}
|
311
|
-
asFirstCondition() {
|
312
|
-
throw Error('Implement on the subclass (Why do we have to have this method here at all?!)');
|
313
|
-
}
|
314
|
-
clone() {
|
315
|
-
throw Error('Implement on the subclass (Why do we have to have this method here at all?!)');
|
316
|
-
}
|
317
|
-
conditionString() {
|
318
|
-
throw Error('Implement on the subclass (Why do we have to have this method here at all?!)');
|
319
|
-
}
|
320
|
-
conditionExpression() {
|
321
|
-
throw Error('Implement on the subclass (Why do we have to have this method here at all?!)');
|
322
|
-
}
|
323
|
-
}
|
324
|
-
export class Condition extends AbstractCondition {
|
325
|
-
field;
|
326
|
-
operator;
|
327
|
-
value;
|
328
|
-
constructor(field, operator, value, coordinator) {
|
329
|
-
super(coordinator);
|
330
|
-
if (!(field instanceof Field)) {
|
331
|
-
throw Error(`field ${field} is not a valid Field object`);
|
332
|
-
}
|
333
|
-
if (typeof operator !== 'string') {
|
334
|
-
throw Error(`operator ${operator} is not a valid operator`);
|
335
|
-
}
|
336
|
-
if (!(value instanceof AbstractConditionValue)) {
|
337
|
-
throw Error(`value ${value} is not a valid value type`);
|
338
|
-
}
|
339
|
-
this.field = field;
|
340
|
-
this.operator = operator;
|
341
|
-
this.value = value;
|
342
|
-
}
|
343
|
-
asFirstCondition() {
|
344
|
-
this._asFirstCondition();
|
345
|
-
return this;
|
346
|
-
}
|
347
|
-
conditionString() {
|
348
|
-
return `'${this.field.display}' ${this.operator} '${this.value.toPresentationString()}'`;
|
349
|
-
}
|
350
|
-
conditionExpression() {
|
351
|
-
return getExpression(this.field.type, this.field.name, this.operator, this.value);
|
352
|
-
}
|
353
|
-
clone() {
|
354
|
-
return new Condition(Field.from(this.field), this.operator, this.value.clone(), this.coordinator);
|
355
|
-
}
|
356
|
-
}
|
357
|
-
export class ConditionRef extends AbstractCondition {
|
358
|
-
conditionName;
|
359
|
-
conditionDisplayName;
|
360
|
-
constructor(conditionName, conditionDisplayName, coordinator) {
|
361
|
-
super(coordinator);
|
362
|
-
if (typeof conditionName !== 'string') {
|
363
|
-
throw Error(`condition name ${conditionName} is not valid`);
|
364
|
-
}
|
365
|
-
if (typeof conditionDisplayName !== 'string') {
|
366
|
-
throw Error(`condition display name ${conditionDisplayName} is not valid`);
|
367
|
-
}
|
368
|
-
this.conditionName = conditionName;
|
369
|
-
this.conditionDisplayName = conditionDisplayName;
|
370
|
-
}
|
371
|
-
asFirstCondition() {
|
372
|
-
this._asFirstCondition();
|
373
|
-
return this;
|
374
|
-
}
|
375
|
-
conditionString() {
|
376
|
-
return `'${this.conditionDisplayName}'`;
|
377
|
-
}
|
378
|
-
conditionExpression() {
|
379
|
-
return this.conditionName;
|
380
|
-
}
|
381
|
-
clone() {
|
382
|
-
return new ConditionRef(this.conditionName, this.conditionDisplayName, this.coordinator);
|
383
|
-
}
|
384
|
-
}
|
385
|
-
//# sourceMappingURL=inline-condition-model.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"inline-condition-model.js","names":["ComponentTypes","getExpression","AbstractConditionValue","valueFrom","coordinators","AND","OR","ConditionsModel","groupedConditions","userGroupedConditions","conditionName","constructor","clone","toReturn","map","it","clear","undefined","name","add","condition","coordinatorExpected","length","getCoordinator","Error","push","_applyGroups","replace","index","splice","remove","indexes","filter","_condition","includes","asFirstCondition","addGroups","groupDefs","_group","splitGroup","_ungroup","moveEarlier","switchCoordinators","moveLater","setCoordinator","asPerUserGroupings","hasConditions","lastIndex","toPresentationString","join","toExpression","correctedUserGroups","ConditionGroup","conditions","_autoGroupDefs","reduce","groups","groupDef","find","contains","startsWith","groupConditions","applyTo","splitIndex","isGroup","copy","getGroupedConditions","orPositions","forEach","hasAnd","hasOr","start","position","GroupDef","thisIsTheLastOr","thereAreMoreConditions","toJSON","from","obj","conditionFrom","ConditionRef","conditionDisplayName","coordinator","Condition","Field","field","operator","value","first","last","Array","isArray","coordinatorString","conditionString","conditionExpression","type","display","componentType","AbstractCondition","Object","values","_asFirstCondition"],"sources":["../../../src/conditions/inline-condition-model.ts"],"sourcesContent":["import { ComponentTypes } from '~/src/components/component-types.js'\nimport { getExpression } from '~/src/conditions/inline-condition-operators.js'\nimport {\n AbstractConditionValue,\n valueFrom\n} from '~/src/conditions/inline-condition-values.js'\n\nexport const coordinators = {\n AND: 'and',\n OR: 'or'\n}\n\nexport class ConditionsModel {\n #groupedConditions\n #userGroupedConditions\n #conditionName\n\n constructor() {\n this.#groupedConditions = []\n this.#userGroupedConditions = []\n }\n\n clone() {\n const toReturn = new ConditionsModel()\n toReturn.#groupedConditions = this.#groupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#userGroupedConditions = this.#userGroupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#conditionName = this.#conditionName\n return toReturn\n }\n\n clear() {\n this.#userGroupedConditions = []\n this.#groupedConditions = []\n this.#conditionName = undefined\n return this\n }\n\n set name(name) {\n this.#conditionName = name\n }\n\n get name() {\n return this.#conditionName\n }\n\n add(condition) {\n const coordinatorExpected = this.#userGroupedConditions.length !== 0\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n }\n this.#userGroupedConditions.push(condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n replace(index, condition) {\n const coordinatorExpected = index !== 0\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n } else if (index >= this.#userGroupedConditions.length) {\n throw Error(\n `Cannot replace condition ${index} as no such condition exists`\n )\n }\n this.#userGroupedConditions.splice(index, 1, condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n remove(indexes) {\n this.#userGroupedConditions = this.#userGroupedConditions\n .filter((_condition, index) => !indexes.includes(index))\n .map((condition, index) =>\n index === 0 ? condition.asFirstCondition() : condition\n )\n\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n addGroups(groupDefs) {\n this.#userGroupedConditions = this._group(\n this.#userGroupedConditions,\n groupDefs\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n splitGroup(index) {\n this.#userGroupedConditions = this._ungroup(\n this.#userGroupedConditions,\n index\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n moveEarlier(index) {\n if (index > 0 && index < this.#userGroupedConditions.length) {\n this.#userGroupedConditions.splice(\n index - 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 1) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n moveLater(index) {\n if (index >= 0 && index < this.#userGroupedConditions.length - 1) {\n this.#userGroupedConditions.splice(\n index + 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 0) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n switchCoordinators() {\n this.#userGroupedConditions[1].setCoordinator(\n this.#userGroupedConditions[0].getCoordinator()\n )\n this.#userGroupedConditions[0].setCoordinator(undefined)\n }\n\n get asPerUserGroupings() {\n return [...this.#userGroupedConditions]\n }\n\n get hasConditions() {\n return this.#userGroupedConditions.length > 0\n }\n\n get lastIndex() {\n return this.#userGroupedConditions.length - 1\n }\n\n toPresentationString() {\n return this.#groupedConditions\n .map((condition) => toPresentationString(condition))\n .join(' ')\n }\n\n toExpression() {\n return this.#groupedConditions\n .map((condition) => toExpression(condition))\n .join(' ')\n }\n\n _applyGroups(userGroupedConditions) {\n const correctedUserGroups = userGroupedConditions.map((condition) =>\n condition instanceof ConditionGroup && condition.conditions.length > 2\n ? new ConditionGroup(\n this._group(\n condition.conditions,\n this._autoGroupDefs(condition.conditions)\n )\n )\n : condition\n )\n return this._group(\n correctedUserGroups,\n this._autoGroupDefs(correctedUserGroups)\n )\n }\n\n _group(conditions, groupDefs) {\n return conditions.reduce((groups, condition, index, conditions) => {\n const groupDef = groupDefs.find((groupDef) => groupDef.contains(index))\n if (groupDef) {\n if (groupDef.startsWith(index)) {\n const groupConditions = groupDef.applyTo(conditions)\n groups.push(new ConditionGroup(groupConditions))\n }\n } else {\n groups.push(condition)\n }\n return groups\n }, [])\n }\n\n _ungroup(conditions, splitIndex) {\n if (conditions[splitIndex].isGroup()) {\n const copy = [...conditions]\n copy.splice(\n splitIndex,\n 1,\n ...conditions[splitIndex].getGroupedConditions()\n )\n return copy\n }\n return conditions\n }\n\n _autoGroupDefs(conditions) {\n const orPositions: number[] = []\n conditions.forEach((condition, index) => {\n if (condition.getCoordinator() === coordinators.OR) {\n orPositions.push(index)\n }\n })\n const hasAnd = !!conditions.find(\n (condition) => condition.getCoordinator() === coordinators.AND\n )\n const hasOr = orPositions.length > 0\n if (hasAnd && hasOr) {\n let start = 0\n const groupDefs: GroupDef[] = []\n orPositions.forEach((position, index) => {\n if (start < position - 1) {\n groupDefs.push(new GroupDef(start, position - 1))\n }\n const thisIsTheLastOr = orPositions.length === index + 1\n const thereAreMoreConditions = conditions.length - 1 > position\n if (thisIsTheLastOr && thereAreMoreConditions) {\n groupDefs.push(new GroupDef(position, conditions.length - 1))\n }\n start = position\n })\n return groupDefs\n }\n return []\n }\n\n toJSON() {\n const name = this.#conditionName\n const conditions = this.#userGroupedConditions\n return {\n name,\n conditions: conditions.map((it) => it.clone())\n }\n }\n\n static from(obj) {\n if (obj instanceof ConditionsModel) {\n return obj\n }\n const toReturn = new ConditionsModel()\n toReturn.#conditionName = obj.name\n toReturn.#userGroupedConditions = obj.conditions.map((it) =>\n conditionFrom(it)\n )\n toReturn.#groupedConditions = toReturn._applyGroups(\n toReturn.#userGroupedConditions\n )\n return toReturn\n }\n}\n\nfunction conditionFrom(it) {\n if (it.conditions) {\n return new ConditionGroup(\n it.conditions.map((condition) => conditionFrom(condition))\n )\n }\n if (it.conditionName) {\n return new ConditionRef(\n it.conditionName,\n it.conditionDisplayName,\n it.coordinator\n )\n }\n return new Condition(\n Field.from(it.field),\n it.operator,\n valueFrom(it.value),\n it.coordinator\n )\n}\n\nexport class GroupDef {\n first\n last\n\n constructor(first, last) {\n if (typeof first !== 'number' || typeof last !== 'number') {\n throw Error(`Cannot construct a group from ${first} and ${last}`)\n } else if (first >= last) {\n throw Error(`Last (${last}) must be greater than first (${first})`)\n }\n this.first = first\n this.last = last\n }\n\n contains(index) {\n return this.first <= index && this.last >= index\n }\n\n startsWith(index) {\n return this.first === index\n }\n\n applyTo(conditions) {\n return [...conditions].splice(this.first, this.last - this.first + 1)\n }\n}\n\nclass ConditionGroup {\n conditions\n\n constructor(conditions) {\n if (!Array.isArray(conditions) || conditions.length < 2) {\n throw Error('Cannot construct a condition group from a single condition')\n }\n this.conditions = conditions\n }\n\n coordinatorString() {\n return this.conditions[0].coordinatorString()\n }\n\n conditionString() {\n const copy = [...this.conditions]\n copy.splice(0, 1)\n return `(${this.conditions[0].conditionString()} ${copy\n .map((condition) => toPresentationString(condition))\n .join(' ')})`\n }\n\n conditionExpression() {\n const copy = [...this.conditions]\n copy.splice(0, 1)\n return `(${this.conditions[0].conditionExpression()} ${copy\n .map((condition) => toExpression(condition))\n .join(' ')})`\n }\n\n asFirstCondition() {\n this.conditions[0].asFirstCondition()\n return this\n }\n\n getCoordinator() {\n return this.conditions[0].getCoordinator()\n }\n\n setCoordinator(coordinator) {\n this.conditions[0].setCoordinator(coordinator)\n }\n\n isGroup() {\n return true\n }\n\n getGroupedConditions() {\n return this.conditions.map((condition) => condition.clone())\n }\n\n clone() {\n return new ConditionGroup(\n this.conditions.map((condition) => condition.clone())\n )\n }\n}\n\nexport function toPresentationString(condition) {\n return `${condition.coordinatorString()}${condition.conditionString()}`\n}\n\nexport function toExpression(condition) {\n return `${condition.coordinatorString()}${condition.conditionExpression()}`\n}\n\nexport class Field {\n name\n type\n display\n\n constructor(name, type, display) {\n if (!name || typeof name !== 'string') {\n throw Error(`name ${name} is not valid`)\n }\n if (!ComponentTypes.find((componentType) => componentType.name === type)) {\n throw Error(`type ${type} is not valid`)\n }\n if (!display || typeof display !== 'string') {\n throw Error(`display ${display} is not valid`)\n }\n this.name = name\n this.type = type\n this.display = display\n }\n\n static from(obj) {\n return new Field(obj.name, obj.type, obj.display)\n }\n}\n\nclass AbstractCondition {\n coordinator\n\n constructor(coordinator) {\n if (coordinator && !Object.values(coordinators).includes(coordinator)) {\n throw Error(`coordinator ${coordinator} is not a valid coordinator`)\n }\n this.coordinator = coordinator\n }\n\n coordinatorString() {\n return this.coordinator ? `${this.coordinator} ` : ''\n }\n\n getCoordinator() {\n return this.coordinator\n }\n\n setCoordinator(coordinator) {\n this.coordinator = coordinator\n }\n\n isGroup() {\n return false\n }\n\n getGroupedConditions() {\n return [this]\n }\n\n _asFirstCondition() {\n delete this.coordinator\n }\n\n asFirstCondition() {\n throw Error(\n 'Implement on the subclass (Why do we have to have this method here at all?!)'\n )\n }\n\n clone() {\n throw Error(\n 'Implement on the subclass (Why do we have to have this method here at all?!)'\n )\n }\n\n conditionString() {\n throw Error(\n 'Implement on the subclass (Why do we have to have this method here at all?!)'\n )\n }\n\n conditionExpression() {\n throw Error(\n 'Implement on the subclass (Why do we have to have this method here at all?!)'\n )\n }\n}\n\nexport class Condition extends AbstractCondition {\n field\n operator\n value\n\n constructor(field, operator, value, coordinator) {\n super(coordinator)\n if (!(field instanceof Field)) {\n throw Error(`field ${field} is not a valid Field object`)\n }\n if (typeof operator !== 'string') {\n throw Error(`operator ${operator} is not a valid operator`)\n }\n if (!(value instanceof AbstractConditionValue)) {\n throw Error(`value ${value} is not a valid value type`)\n }\n this.field = field\n this.operator = operator\n this.value = value\n }\n\n asFirstCondition() {\n this._asFirstCondition()\n return this\n }\n\n conditionString() {\n return `'${this.field.display}' ${\n this.operator\n } '${this.value.toPresentationString()}'`\n }\n\n conditionExpression() {\n return getExpression(\n this.field.type,\n this.field.name,\n this.operator,\n this.value\n )\n }\n\n clone() {\n return new Condition(\n Field.from(this.field),\n this.operator,\n this.value.clone(),\n this.coordinator\n )\n }\n}\n\nexport class ConditionRef extends AbstractCondition {\n conditionName\n conditionDisplayName\n\n constructor(conditionName, conditionDisplayName, coordinator) {\n super(coordinator)\n if (typeof conditionName !== 'string') {\n throw Error(`condition name ${conditionName} is not valid`)\n }\n if (typeof conditionDisplayName !== 'string') {\n throw Error(`condition display name ${conditionDisplayName} is not valid`)\n }\n this.conditionName = conditionName\n this.conditionDisplayName = conditionDisplayName\n }\n\n asFirstCondition() {\n this._asFirstCondition()\n return this\n }\n\n conditionString() {\n return `'${this.conditionDisplayName}'`\n }\n\n conditionExpression() {\n return this.conditionName\n }\n\n clone() {\n return new ConditionRef(\n this.conditionName,\n this.conditionDisplayName,\n this.coordinator\n )\n }\n}\n"],"mappings":"AAAA,SAASA,cAAc;AACvB,SAASC,aAAa;AACtB,SACEC,sBAAsB,EACtBC,SAAS;AAGX,OAAO,MAAMC,YAAY,GAAG;EAC1BC,GAAG,EAAE,KAAK;EACVC,EAAE,EAAE;AACN,CAAC;AAED,OAAO,MAAMC,eAAe,CAAC;EAC3B,CAACC,iBAAiB;EAClB,CAACC,qBAAqB;EACtB,CAACC,aAAa;EAEdC,WAAWA,CAAA,EAAG;IACZ,IAAI,CAAC,CAACH,iBAAiB,GAAG,EAAE;IAC5B,IAAI,CAAC,CAACC,qBAAqB,GAAG,EAAE;EAClC;EAEAG,KAAKA,CAAA,EAAG;IACN,MAAMC,QAAQ,GAAG,IAAIN,eAAe,CAAC,CAAC;IACtCM,QAAQ,CAAC,CAACL,iBAAiB,GAAG,IAAI,CAAC,CAACA,iBAAiB,CAACM,GAAG,CAAEC,EAAE,IAC3DA,EAAE,CAACH,KAAK,CAAC,CACX,CAAC;IACDC,QAAQ,CAAC,CAACJ,qBAAqB,GAAG,IAAI,CAAC,CAACA,qBAAqB,CAACK,GAAG,CAAEC,EAAE,IACnEA,EAAE,CAACH,KAAK,CAAC,CACX,CAAC;IACDC,QAAQ,CAAC,CAACH,aAAa,GAAG,IAAI,CAAC,CAACA,aAAa;IAC7C,OAAOG,QAAQ;EACjB;EAEAG,KAAKA,CAAA,EAAG;IACN,IAAI,CAAC,CAACP,qBAAqB,GAAG,E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;IACA,IAAI,OAAOuE,oBAAoB,KAAK,QAAQ,EAAE;MAC5C,MAAMzD,KAAK,CAAC,0BAA0ByD,oBAAoB,eAAe,CAAC;IAC5E;IACA,IAAI,CAACvE,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACuE,oBAAoB,GAAGA,oBAAoB;EAClD;EAEA9C,gBAAgBA,CAAA,EAAG;IACjB,IAAI,CAACkE,iBAAiB,CAAC,CAAC;IACxB,OAAO,IAAI;EACb;EAEAR,eAAeA,CAAA,EAAG;IAChB,OAAO,IAAI,IAAI,CAACZ,oBAAoB,GAAG;EACzC;EAEAa,mBAAmBA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACpF,aAAa;EAC3B;EAEAE,KAAKA,CAAA,EAAG;IACN,OAAO,IAAIoE,YAAY,CACrB,IAAI,CAACtE,aAAa,EAClB,IAAI,CAACuE,oBAAoB,EACzB,IAAI,CAACC,WACP,CAAC;EACH;AACF","ignoreList":[]}
|
@@ -1,111 +0,0 @@
|
|
1
|
-
import { ConditionValue, dateDirections, dateTimeUnits, dateUnits, RelativeTimeValue, timeUnits } from "./inline-condition-values.js";
|
2
|
-
const defaultOperators = {
|
3
|
-
is: inline('=='),
|
4
|
-
'is not': inline('!=')
|
5
|
-
};
|
6
|
-
function withDefaults(param) {
|
7
|
-
return Object.assign({}, param, defaultOperators);
|
8
|
-
}
|
9
|
-
const textBasedFieldCustomisations = {
|
10
|
-
'is longer than': lengthIs('>'),
|
11
|
-
'is shorter than': lengthIs('<'),
|
12
|
-
'has length': lengthIs('==')
|
13
|
-
};
|
14
|
-
const absoluteDateTimeOperators = {
|
15
|
-
is: absoluteDateTime('=='),
|
16
|
-
'is not': absoluteDateTime('!='),
|
17
|
-
'is before': absoluteDateTime('<'),
|
18
|
-
'is after': absoluteDateTime('>')
|
19
|
-
};
|
20
|
-
const relativeTimeOperators = units => ({
|
21
|
-
'is at least': relativeTime('<=', '>=', units),
|
22
|
-
'is at most': relativeTime('>=', '<=', units),
|
23
|
-
'is less than': relativeTime('>', '<', units),
|
24
|
-
'is more than': relativeTime('<', '>', units)
|
25
|
-
});
|
26
|
-
export const customOperators = {
|
27
|
-
CheckboxesField: {
|
28
|
-
contains: reverseInline('in'),
|
29
|
-
'does not contain': not(reverseInline('in'))
|
30
|
-
},
|
31
|
-
NumberField: withDefaults({
|
32
|
-
'is at least': inline('>='),
|
33
|
-
'is at most': inline('<='),
|
34
|
-
'is less than': inline('<'),
|
35
|
-
'is more than': inline('>')
|
36
|
-
}),
|
37
|
-
DateField: Object.assign({}, absoluteDateTimeOperators, relativeTimeOperators(dateUnits)),
|
38
|
-
TimeField: Object.assign({}, absoluteDateTimeOperators, relativeTimeOperators(timeUnits)),
|
39
|
-
DatePartsField: Object.assign({}, absoluteDateTimeOperators, relativeTimeOperators(dateUnits)),
|
40
|
-
DateTimeField: Object.assign({}, absoluteDateTimeOperators, relativeTimeOperators(dateTimeUnits)),
|
41
|
-
DateTimePartsField: Object.assign({}, absoluteDateTimeOperators, relativeTimeOperators(dateTimeUnits)),
|
42
|
-
TextField: withDefaults(textBasedFieldCustomisations),
|
43
|
-
MultilineTextField: withDefaults(textBasedFieldCustomisations),
|
44
|
-
EmailAddressField: withDefaults(textBasedFieldCustomisations)
|
45
|
-
};
|
46
|
-
export function getOperatorNames(fieldType) {
|
47
|
-
return Object.keys(getConditionals(fieldType)).sort();
|
48
|
-
}
|
49
|
-
export function getExpression(fieldType, fieldName, operator, value) {
|
50
|
-
return getConditionals(fieldType)[operator].expression({
|
51
|
-
type: fieldType,
|
52
|
-
name: fieldName
|
53
|
-
}, value);
|
54
|
-
}
|
55
|
-
export function getOperatorConfig(fieldType, operator) {
|
56
|
-
return getConditionals(fieldType)[operator];
|
57
|
-
}
|
58
|
-
function getConditionals(fieldType) {
|
59
|
-
return customOperators[fieldType] || defaultOperators;
|
60
|
-
}
|
61
|
-
function inline(operator) {
|
62
|
-
return {
|
63
|
-
expression: (field, value) => `${field.name} ${operator} ${formatValue(field.type, value.value)}`
|
64
|
-
};
|
65
|
-
}
|
66
|
-
function lengthIs(operator) {
|
67
|
-
return {
|
68
|
-
expression: (field, value) => `length(${field.name}) ${operator} ${value.value}`
|
69
|
-
};
|
70
|
-
}
|
71
|
-
function reverseInline(operator) {
|
72
|
-
return {
|
73
|
-
expression: (field, value) => `${formatValue(field.type, value.value)} ${operator} ${field.name}`
|
74
|
-
};
|
75
|
-
}
|
76
|
-
function not(operatorDefinition) {
|
77
|
-
return {
|
78
|
-
expression: (field, value) => `not (${operatorDefinition.expression(field, value)})`
|
79
|
-
};
|
80
|
-
}
|
81
|
-
function formatValue(fieldType, value) {
|
82
|
-
if (fieldType === 'NumberField' || fieldType === 'YesNoField') {
|
83
|
-
return value;
|
84
|
-
}
|
85
|
-
return `'${value}'`;
|
86
|
-
}
|
87
|
-
export const absoluteDateOrTimeOperatorNames = Object.keys(absoluteDateTimeOperators);
|
88
|
-
export const relativeDateOrTimeOperatorNames = Object.keys(relativeTimeOperators(dateTimeUnits));
|
89
|
-
function absoluteDateTime(operator) {
|
90
|
-
return {
|
91
|
-
expression: (field, value) => {
|
92
|
-
if (value instanceof ConditionValue) {
|
93
|
-
return `${field.name} ${operator} '${value.toExpression()}'`;
|
94
|
-
}
|
95
|
-
throw Error('only Value types are supported');
|
96
|
-
}
|
97
|
-
};
|
98
|
-
}
|
99
|
-
function relativeTime(pastOperator, futureOperator, units) {
|
100
|
-
return {
|
101
|
-
units,
|
102
|
-
expression: (field, value) => {
|
103
|
-
if (value instanceof RelativeTimeValue) {
|
104
|
-
const operator = value.direction === dateDirections.PAST ? pastOperator : futureOperator;
|
105
|
-
return `${field.name} ${operator} ${value.toExpression()}`;
|
106
|
-
}
|
107
|
-
throw Error('time shift requires a TimeShiftValue');
|
108
|
-
}
|
109
|
-
};
|
110
|
-
}
|
111
|
-
//# sourceMappingURL=inline-condition-operators.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"inline-condition-operators.js","names":["ConditionValue","dateDirections","dateTimeUnits","dateUnits","RelativeTimeValue","timeUnits","defaultOperators","is","inline","withDefaults","param","Object","assign","textBasedFieldCustomisations","lengthIs","absoluteDateTimeOperators","absoluteDateTime","relativeTimeOperators","units","relativeTime","customOperators","CheckboxesField","contains","reverseInline","not","NumberField","DateField","TimeField","DatePartsField","DateTimeField","DateTimePartsField","TextField","MultilineTextField","EmailAddressField","getOperatorNames","fieldType","keys","getConditionals","sort","getExpression","fieldName","operator","value","expression","type","name","getOperatorConfig","field","formatValue","operatorDefinition","absoluteDateOrTimeOperatorNames","relativeDateOrTimeOperatorNames","toExpression","Error","pastOperator","futureOperator","direction","PAST"],"sources":["../../../src/conditions/inline-condition-operators.ts"],"sourcesContent":["import {\n ConditionValue,\n dateDirections,\n dateTimeUnits,\n dateUnits,\n RelativeTimeValue,\n timeUnits\n} from '~/src/conditions/inline-condition-values.js'\n\nconst defaultOperators = {\n is: inline('=='),\n 'is not': inline('!=')\n}\n\nfunction withDefaults(param) {\n return Object.assign({}, param, defaultOperators)\n}\n\nconst textBasedFieldCustomisations = {\n 'is longer than': lengthIs('>'),\n 'is shorter than': lengthIs('<'),\n 'has length': lengthIs('==')\n}\n\nconst absoluteDateTimeOperators = {\n is: absoluteDateTime('=='),\n 'is not': absoluteDateTime('!='),\n 'is before': absoluteDateTime('<'),\n 'is after': absoluteDateTime('>')\n}\n\nconst relativeTimeOperators = (units) => ({\n 'is at least': relativeTime('<=', '>=', units),\n 'is at most': relativeTime('>=', '<=', units),\n 'is less than': relativeTime('>', '<', units),\n 'is more than': relativeTime('<', '>', units)\n})\n\nexport const customOperators = {\n CheckboxesField: {\n contains: reverseInline('in'),\n 'does not contain': not(reverseInline('in'))\n },\n NumberField: withDefaults({\n 'is at least': inline('>='),\n 'is at most': inline('<='),\n 'is less than': inline('<'),\n 'is more than': inline('>')\n }),\n DateField: Object.assign(\n {},\n absoluteDateTimeOperators,\n relativeTimeOperators(dateUnits)\n ),\n TimeField: Object.assign(\n {},\n absoluteDateTimeOperators,\n relativeTimeOperators(timeUnits)\n ),\n DatePartsField: Object.assign(\n {},\n absoluteDateTimeOperators,\n relativeTimeOperators(dateUnits)\n ),\n DateTimeField: Object.assign(\n {},\n absoluteDateTimeOperators,\n relativeTimeOperators(dateTimeUnits)\n ),\n DateTimePartsField: Object.assign(\n {},\n absoluteDateTimeOperators,\n relativeTimeOperators(dateTimeUnits)\n ),\n TextField: withDefaults(textBasedFieldCustomisations),\n MultilineTextField: withDefaults(textBasedFieldCustomisations),\n EmailAddressField: withDefaults(textBasedFieldCustomisations)\n}\n\nexport function getOperatorNames(fieldType) {\n return Object.keys(getConditionals(fieldType)).sort()\n}\n\nexport function getExpression(fieldType, fieldName, operator, value) {\n return getConditionals(fieldType)[operator].expression(\n { type: fieldType, name: fieldName },\n value\n )\n}\n\nexport function getOperatorConfig(fieldType, operator) {\n return getConditionals(fieldType)[operator]\n}\n\nfunction getConditionals(fieldType) {\n return customOperators[fieldType] || defaultOperators\n}\n\nfunction inline(operator) {\n return {\n expression: (field, value) =>\n `${field.name} ${operator} ${formatValue(field.type, value.value)}`\n }\n}\n\nfunction lengthIs(operator) {\n return {\n expression: (field, value) =>\n `length(${field.name}) ${operator} ${value.value}`\n }\n}\n\nfunction reverseInline(operator) {\n return {\n expression: (field, value) =>\n `${formatValue(field.type, value.value)} ${operator} ${field.name}`\n }\n}\n\nfunction not(operatorDefinition) {\n return {\n expression: (field, value) =>\n `not (${operatorDefinition.expression(field, value)})`\n }\n}\n\nfunction formatValue(fieldType, value) {\n if (fieldType === 'NumberField' || fieldType === 'YesNoField') {\n return value\n }\n return `'${value}'`\n}\n\nexport const absoluteDateOrTimeOperatorNames = Object.keys(\n absoluteDateTimeOperators\n)\nexport const relativeDateOrTimeOperatorNames = Object.keys(\n relativeTimeOperators(dateTimeUnits)\n)\n\nfunction absoluteDateTime(operator) {\n return {\n expression: (field, value) => {\n if (value instanceof ConditionValue) {\n return `${field.name} ${operator} '${value.toExpression()}'`\n }\n throw Error('only Value types are supported')\n }\n }\n}\n\nfunction relativeTime(pastOperator, futureOperator, units) {\n return {\n units,\n expression: (field, value) => {\n if (value instanceof RelativeTimeValue) {\n const operator =\n value.direction === dateDirections.PAST\n ? pastOperator\n : futureOperator\n return `${field.name} ${operator} ${value.toExpression()}`\n }\n throw Error('time shift requires a TimeShiftValue')\n }\n }\n}\n"],"mappings":"AAAA,SACEA,cAAc,EACdC,cAAc,EACdC,aAAa,EACbC,SAAS,EACTC,iBAAiB,EACjBC,SAAS;AAGX,MAAMC,gBAAgB,GAAG;EACvBC,EAAE,EAAEC,MAAM,CAAC,IAAI,CAAC;EAChB,QAAQ,EAAEA,MAAM,CAAC,IAAI;AACvB,CAAC;AAED,SAASC,YAAYA,CAACC,KAAK,EAAE;EAC3B,OAAOC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEF,KAAK,EAAEJ,gBAAgB,CAAC;AACnD;AAEA,MAAMO,4BAA4B,GAAG;EACnC,gBAAgB,EAAEC,QAAQ,CAAC,GAAG,CAAC;EAC/B,iBAAiB,EAAEA,QAAQ,CAAC,GAAG,CAAC;EAChC,YAAY,EAAEA,QAAQ,CAAC,IAAI;AAC7B,CAAC;AAED,MAAMC,yBAAyB,GAAG;EAChCR,EAAE,EAAES,gBAAgB,CAAC,IAAI,CAAC;EAC1B,QAAQ,EAAEA,gBAAgB,CAAC,IAAI,CAAC;EAChC,WAAW,EAAEA,gBAAgB,CAAC,GAAG,CAAC;EAClC,UAAU,EAAEA,gBAAgB,CAAC,GAAG;AAClC,CAAC;AAED,MAAMC,qBAAqB,GAAIC,KAAK,KAAM;EACxC,aAAa,EAAEC,YAAY,CAAC,IAAI,EAAE,IAAI,EAAED,KAAK,CAAC;EAC9C,YAAY,EAAEC,YAAY,CAAC,IAAI,EAAE,IAAI,EAAED,KAAK,CAAC;EAC7C,cAAc,EAAEC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAED,KAAK,CAAC;EAC7C,cAAc,EAAEC,YAAY,CAAC,GAAG,E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