@fjell/core 4.3.4 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{src/AItemService.d.ts → AItemService.d.ts} +1 -1
- package/dist/AItemService.js +38 -0
- package/dist/AItemService.js.map +1 -0
- package/dist/{src/dictionary.js → dictionary.js} +40 -17
- package/dist/dictionary.js.map +1 -0
- package/dist/{src/index.d.ts → index.d.ts} +5 -5
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/{src/item → item}/IFactory.js +35 -10
- package/dist/item/IFactory.js.map +1 -0
- package/dist/{src/item → item}/IQFactory.d.ts +1 -1
- package/dist/{src/item → item}/IQFactory.js +39 -18
- package/dist/item/IQFactory.js.map +1 -0
- package/dist/{src/item → item}/IQUtils.d.ts +3 -3
- package/dist/{src/item → item}/IQUtils.js +101 -74
- package/dist/item/IQUtils.js.map +1 -0
- package/dist/{src/item → item}/IUtils.d.ts +2 -2
- package/dist/{src/item → item}/IUtils.js +41 -32
- package/dist/item/IUtils.js.map +1 -0
- package/dist/item/ItemQuery.js +6 -0
- package/dist/item/ItemQuery.js.map +1 -0
- package/dist/{src/key → key}/KUtils.d.ts +1 -1
- package/dist/key/KUtils.js +271 -0
- package/dist/key/KUtils.js.map +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +6 -0
- package/dist/logger.js.map +1 -0
- package/package.json +17 -10
- package/src/logger.ts +1 -1
- package/dist/src/AItemService.js +0 -21
- package/dist/src/AItemService.js.map +0 -1
- package/dist/src/dictionary.js.map +0 -1
- package/dist/src/index.js +0 -12
- package/dist/src/index.js.map +0 -1
- package/dist/src/item/IFactory.js.map +0 -1
- package/dist/src/item/IQFactory.js.map +0 -1
- package/dist/src/item/IQUtils.js.map +0 -1
- package/dist/src/item/IUtils.js.map +0 -1
- package/dist/src/item/ItemQuery.js +0 -10
- package/dist/src/item/ItemQuery.js.map +0 -1
- package/dist/src/items.js +0 -4
- package/dist/src/items.js.map +0 -1
- package/dist/src/key/KUtils.js +0 -223
- package/dist/src/key/KUtils.js.map +0 -1
- package/dist/src/keys.js +0 -5
- package/dist/src/keys.js.map +0 -1
- package/dist/src/logger.d.ts +0 -2
- package/dist/src/logger.js +0 -4
- package/dist/src/logger.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/eslint.config.mjs +0 -70
- /package/dist/{src/dictionary.d.ts → dictionary.d.ts} +0 -0
- /package/dist/{src/item → item}/IFactory.d.ts +0 -0
- /package/dist/{src/item → item}/ItemQuery.d.ts +0 -0
- /package/dist/{src/items.d.ts → items.d.ts} +0 -0
- /package/dist/{src/keys.d.ts → keys.d.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AllItemTypeArrays } from
|
|
1
|
+
import { AllItemTypeArrays } from './keys';
|
|
2
2
|
export declare class AItemService<S extends string, L1 extends string, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> {
|
|
3
3
|
private pkType;
|
|
4
4
|
private parentService;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
class AItemService {
|
|
15
|
+
constructor(pkType, parentService){
|
|
16
|
+
_define_property(this, "pkType", void 0);
|
|
17
|
+
_define_property(this, "parentService", null);
|
|
18
|
+
_define_property(this, "getPkType", ()=>{
|
|
19
|
+
return this.pkType;
|
|
20
|
+
});
|
|
21
|
+
_define_property(this, "getKeyTypes", ()=>{
|
|
22
|
+
let keyTypes = [
|
|
23
|
+
this.getPkType()
|
|
24
|
+
];
|
|
25
|
+
if (this.parentService) {
|
|
26
|
+
keyTypes = keyTypes.concat(this.parentService.getKeyTypes());
|
|
27
|
+
}
|
|
28
|
+
return keyTypes;
|
|
29
|
+
});
|
|
30
|
+
this.pkType = pkType;
|
|
31
|
+
if (parentService) {
|
|
32
|
+
this.parentService = parentService;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { AItemService };
|
|
38
|
+
//# sourceMappingURL=AItemService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AItemService.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,33 +1,44 @@
|
|
|
1
|
-
import LibLogger from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import LibLogger from './logger.js';
|
|
2
|
+
|
|
3
|
+
function _define_property(obj, key, value) {
|
|
4
|
+
if (key in obj) {
|
|
5
|
+
Object.defineProperty(obj, key, {
|
|
6
|
+
value: value,
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true
|
|
10
|
+
});
|
|
11
|
+
} else {
|
|
12
|
+
obj[key] = value;
|
|
13
13
|
}
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
16
|
+
const logger = LibLogger.get("Dictionary");
|
|
17
|
+
class Dictionary {
|
|
14
18
|
set(key, item) {
|
|
15
|
-
logger.trace('set', {
|
|
19
|
+
logger.trace('set', {
|
|
20
|
+
key,
|
|
21
|
+
item
|
|
22
|
+
});
|
|
16
23
|
const hashedKey = this.hashFunction(key);
|
|
17
24
|
this.map[hashedKey] = item;
|
|
18
25
|
}
|
|
19
26
|
get(key) {
|
|
20
|
-
logger.trace('get', {
|
|
27
|
+
logger.trace('get', {
|
|
28
|
+
key
|
|
29
|
+
});
|
|
21
30
|
const hashedKey = this.hashFunction(key);
|
|
22
31
|
return this.map[hashedKey] || null;
|
|
23
32
|
}
|
|
24
33
|
delete(key) {
|
|
25
|
-
logger.trace('delete', {
|
|
34
|
+
logger.trace('delete', {
|
|
35
|
+
key
|
|
36
|
+
});
|
|
26
37
|
const hashedKey = this.hashFunction(key);
|
|
27
38
|
delete this.map[hashedKey];
|
|
28
39
|
}
|
|
29
40
|
keys() {
|
|
30
|
-
return Object.keys(this.map).map(key
|
|
41
|
+
return Object.keys(this.map).map((key)=>JSON.parse(key));
|
|
31
42
|
}
|
|
32
43
|
values() {
|
|
33
44
|
return Object.values(this.map);
|
|
@@ -40,5 +51,17 @@ export class Dictionary {
|
|
|
40
51
|
const clone = new Dictionary(clonedMap, this.hashFunction);
|
|
41
52
|
return clone;
|
|
42
53
|
}
|
|
54
|
+
constructor(map, hashFunction){
|
|
55
|
+
_define_property(this, "map", {});
|
|
56
|
+
_define_property(this, "hashFunction", (key)=>JSON.stringify(key));
|
|
57
|
+
if (map) {
|
|
58
|
+
this.map = map;
|
|
59
|
+
}
|
|
60
|
+
if (hashFunction) {
|
|
61
|
+
this.hashFunction = hashFunction;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
43
64
|
}
|
|
44
|
-
|
|
65
|
+
|
|
66
|
+
export { Dictionary };
|
|
67
|
+
//# sourceMappingURL=dictionary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionary.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export { IFactory } from
|
|
5
|
-
export { AItemService } from
|
|
1
|
+
export * from './dictionary';
|
|
2
|
+
export * from './keys';
|
|
3
|
+
export * from './items';
|
|
4
|
+
export { IFactory } from './item/IFactory';
|
|
5
|
+
export { AItemService } from './AItemService';
|
|
6
6
|
export * from './key/KUtils';
|
|
7
7
|
export * from './item/IFactory';
|
|
8
8
|
export * from './item/IQFactory';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Dictionary } from './dictionary.js';
|
|
2
|
+
export { IFactory } from './item/IFactory.js';
|
|
3
|
+
export { AItemService } from './AItemService.js';
|
|
4
|
+
export { abbrevIK, abbrevLKA, cPK, constructPriKey, generateKeyArray, ikToLKA, isComKey, isComKeyEqual, isItemKey, isItemKeyEqual, isLocKey, isLocKeyEqual, isPriKey, isPriKeyEqual, isValidComKey, isValidItemKey, isValidLocKey, isValidLocKeyArray, isValidPriKey, itemKeyToLocKeyArray, lkaToIK, locKeyArrayToItemKey, primaryType, toKeyTypeArray } from './key/KUtils.js';
|
|
5
|
+
export { IQFactory } from './item/IQFactory.js';
|
|
6
|
+
export { abbrevAgg, abbrevCompoundCondition, abbrevCondition, abbrevQuery, abbrevRef, isQueryMatch, paramsToQuery, queryToParams } from './item/IQUtils.js';
|
|
7
|
+
export { isComItem, isPriItem, validateKeys, validatePK } from './item/IUtils.js';
|
|
8
|
+
export { isCondition } from './item/ItemQuery.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import deepmerge from 'deepmerge';
|
|
2
|
-
import { primaryType } from '../key/KUtils';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { primaryType } from '../key/KUtils.js';
|
|
3
|
+
|
|
4
|
+
function _define_property(obj, key, value) {
|
|
5
|
+
if (key in obj) {
|
|
6
|
+
Object.defineProperty(obj, key, {
|
|
7
|
+
value: value,
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
obj[key] = value;
|
|
7
14
|
}
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
class IFactory {
|
|
8
18
|
addRef(i, name) {
|
|
9
19
|
const ik = i.key;
|
|
10
20
|
const refName = name || primaryType(ik);
|
|
@@ -23,13 +33,19 @@ export class IFactory {
|
|
|
23
33
|
}
|
|
24
34
|
const now = new Date();
|
|
25
35
|
if (!this.item.events.created) {
|
|
26
|
-
this.item.events.created = {
|
|
36
|
+
this.item.events.created = {
|
|
37
|
+
at: now
|
|
38
|
+
};
|
|
27
39
|
}
|
|
28
40
|
if (!this.item.events.updated) {
|
|
29
|
-
this.item.events.updated = {
|
|
41
|
+
this.item.events.updated = {
|
|
42
|
+
at: now
|
|
43
|
+
};
|
|
30
44
|
}
|
|
31
45
|
if (!this.item.events.deleted) {
|
|
32
|
-
this.item.events.deleted = {
|
|
46
|
+
this.item.events.deleted = {
|
|
47
|
+
at: null
|
|
48
|
+
};
|
|
33
49
|
}
|
|
34
50
|
return this;
|
|
35
51
|
}
|
|
@@ -37,7 +53,10 @@ export class IFactory {
|
|
|
37
53
|
if (!this.item.events) {
|
|
38
54
|
this.item.events = {};
|
|
39
55
|
}
|
|
40
|
-
this.item.events[name] = {
|
|
56
|
+
this.item.events[name] = {
|
|
57
|
+
at,
|
|
58
|
+
by
|
|
59
|
+
};
|
|
41
60
|
return this;
|
|
42
61
|
}
|
|
43
62
|
static addEvent(name, at, by) {
|
|
@@ -60,5 +79,11 @@ export class IFactory {
|
|
|
60
79
|
toItem() {
|
|
61
80
|
return this.item;
|
|
62
81
|
}
|
|
82
|
+
constructor(props = {}){
|
|
83
|
+
_define_property(this, "item", {});
|
|
84
|
+
this.item = deepmerge(this.item, props);
|
|
85
|
+
}
|
|
63
86
|
}
|
|
64
|
-
|
|
87
|
+
|
|
88
|
+
export { IFactory };
|
|
89
|
+
//# sourceMappingURL=IFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IFactory.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CompoundType, Condition, ConditionOperator, EventQuery, ItemQuery, OrderDirection } from
|
|
1
|
+
import { CompoundType, Condition, ConditionOperator, EventQuery, ItemQuery, OrderDirection } from './ItemQuery';
|
|
2
2
|
export declare class IQFactory {
|
|
3
3
|
private query;
|
|
4
4
|
constructor(query?: ItemQuery);
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import { cPK } from '../key/KUtils';
|
|
2
|
-
import { isCondition } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { cPK } from '../key/KUtils.js';
|
|
2
|
+
import { isCondition } from './ItemQuery.js';
|
|
3
|
+
|
|
4
|
+
function _define_property(obj, key, value) {
|
|
5
|
+
if (key in obj) {
|
|
6
|
+
Object.defineProperty(obj, key, {
|
|
7
|
+
value: value,
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
obj[key] = value;
|
|
14
|
+
}
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
class IQFactory {
|
|
8
18
|
orderBy(field, direction = 'asc') {
|
|
9
19
|
if (!this.query.orderBy) {
|
|
10
20
|
this.query.orderBy = [];
|
|
11
21
|
}
|
|
12
|
-
this.query.orderBy.push({
|
|
22
|
+
this.query.orderBy.push({
|
|
23
|
+
field,
|
|
24
|
+
direction
|
|
25
|
+
});
|
|
13
26
|
return this;
|
|
14
27
|
}
|
|
15
28
|
agg(name, query) {
|
|
@@ -27,7 +40,7 @@ export class IQFactory {
|
|
|
27
40
|
return this;
|
|
28
41
|
}
|
|
29
42
|
conditions(conditions, compoundType = 'AND') {
|
|
30
|
-
for (const condition of conditions)
|
|
43
|
+
for (const condition of conditions){
|
|
31
44
|
if (!isCondition(condition)) {
|
|
32
45
|
throw new Error(`Invalid condition: ${JSON.stringify(condition)}`);
|
|
33
46
|
}
|
|
@@ -37,15 +50,14 @@ export class IQFactory {
|
|
|
37
50
|
// with the given compound type. This will mostly likely be the most common case.
|
|
38
51
|
this.query.compoundCondition = {
|
|
39
52
|
compoundType,
|
|
40
|
-
conditions: conditions
|
|
53
|
+
conditions: conditions
|
|
41
54
|
};
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
55
|
+
} else {
|
|
44
56
|
// If there is already a top-level compound condition, create a new compound condition
|
|
45
57
|
// and add it to the conditions array of the top-level compound condition.
|
|
46
58
|
const compoundCondition = {
|
|
47
59
|
compoundType,
|
|
48
|
-
conditions
|
|
60
|
+
conditions
|
|
49
61
|
};
|
|
50
62
|
this.query.compoundCondition.conditions.push(compoundCondition);
|
|
51
63
|
}
|
|
@@ -69,20 +81,23 @@ export class IQFactory {
|
|
|
69
81
|
return this;
|
|
70
82
|
}
|
|
71
83
|
condition(column, value, operator = '==') {
|
|
72
|
-
const condition = {
|
|
84
|
+
const condition = {
|
|
85
|
+
column,
|
|
86
|
+
value,
|
|
87
|
+
operator
|
|
88
|
+
};
|
|
73
89
|
if (isCondition(condition)) {
|
|
74
90
|
if (!this.query.compoundCondition) {
|
|
75
91
|
// If there is no top-level compound condition, create one
|
|
76
92
|
// with the default compound type of 'AND'.
|
|
77
93
|
this.query.compoundCondition = {
|
|
78
94
|
compoundType: 'AND',
|
|
79
|
-
conditions: []
|
|
95
|
+
conditions: []
|
|
80
96
|
};
|
|
81
97
|
}
|
|
82
98
|
this.query.compoundCondition.conditions.push(condition);
|
|
83
99
|
return this;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
100
|
+
} else {
|
|
86
101
|
throw new Error(`Invalid condition: ${JSON.stringify(condition)}`);
|
|
87
102
|
}
|
|
88
103
|
}
|
|
@@ -125,5 +140,11 @@ export class IQFactory {
|
|
|
125
140
|
toQuery() {
|
|
126
141
|
return this.query;
|
|
127
142
|
}
|
|
143
|
+
constructor(query = {}){
|
|
144
|
+
_define_property(this, "query", {});
|
|
145
|
+
this.query = query;
|
|
146
|
+
}
|
|
128
147
|
}
|
|
129
|
-
|
|
148
|
+
|
|
149
|
+
export { IQFactory };
|
|
150
|
+
//# sourceMappingURL=IQFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IQFactory.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Item } from
|
|
2
|
-
import { ComKey, PriKey } from
|
|
3
|
-
import { CompoundCondition, Condition, ItemQuery, QueryParams } from
|
|
1
|
+
import { Item } from '../items';
|
|
2
|
+
import { ComKey, PriKey } from '../keys';
|
|
3
|
+
import { CompoundCondition, Condition, ItemQuery, QueryParams } from './ItemQuery';
|
|
4
4
|
/**
|
|
5
5
|
* When we query or search, we're sending a GET request. This converts everything in ItemQuery into a flat
|
|
6
6
|
* object that can be sent over a GET request.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import LibLogger from
|
|
3
|
-
import { DateTime } from
|
|
4
|
-
import { isCondition } from
|
|
1
|
+
import { isPriKey, isItemKeyEqual } from '../key/KUtils.js';
|
|
2
|
+
import LibLogger from '../logger.js';
|
|
3
|
+
import { DateTime } from 'luxon';
|
|
4
|
+
import { isCondition } from './ItemQuery.js';
|
|
5
|
+
|
|
5
6
|
const logger = LibLogger.get('IQUtils');
|
|
6
7
|
/**
|
|
7
8
|
* When we query or search, we're sending a GET request. This converts everything in ItemQuery into a flat
|
|
@@ -20,8 +21,7 @@ const logger = LibLogger.get('IQUtils');
|
|
|
20
21
|
*
|
|
21
22
|
* @param query
|
|
22
23
|
* @returns QueryParams ready to be get over a GET request.
|
|
23
|
-
*/
|
|
24
|
-
export const queryToParams = (query) => {
|
|
24
|
+
*/ const queryToParams = (query)=>{
|
|
25
25
|
const params = {};
|
|
26
26
|
if (query.compoundCondition) {
|
|
27
27
|
params.compoundCondition = JSON.stringify(query.compoundCondition);
|
|
@@ -44,12 +44,11 @@ export const queryToParams = (query) => {
|
|
|
44
44
|
return params;
|
|
45
45
|
};
|
|
46
46
|
// This is a dateTimeReviver used for JSON parse - when we convert a param back to a query, we need this.
|
|
47
|
-
const dateTimeReviver = function
|
|
47
|
+
const dateTimeReviver = function(key, value) {
|
|
48
48
|
if (typeof value === 'string') {
|
|
49
49
|
const parsedDate = DateTime.fromISO(value);
|
|
50
50
|
if (parsedDate.isValid) {
|
|
51
51
|
return parsedDate.toJSDate();
|
|
52
|
-
;
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
return value;
|
|
@@ -59,8 +58,7 @@ const dateTimeReviver = function (key, value) {
|
|
|
59
58
|
*
|
|
60
59
|
* @param params Parameters sent over a GET request
|
|
61
60
|
* @returns A fully hydrated ItemQuery object.
|
|
62
|
-
*/
|
|
63
|
-
export const paramsToQuery = (params) => {
|
|
61
|
+
*/ const paramsToQuery = (params)=>{
|
|
64
62
|
const query = {};
|
|
65
63
|
if (params.compoundCondition) {
|
|
66
64
|
query.compoundCondition = JSON.parse(params.compoundCondition);
|
|
@@ -82,36 +80,49 @@ export const paramsToQuery = (params) => {
|
|
|
82
80
|
}
|
|
83
81
|
return query;
|
|
84
82
|
};
|
|
85
|
-
const isRefQueryMatch = (refKey, queryRef, references)
|
|
86
|
-
logger.trace('doesRefMatch', {
|
|
87
|
-
|
|
83
|
+
const isRefQueryMatch = (refKey, queryRef, references)=>{
|
|
84
|
+
logger.trace('doesRefMatch', {
|
|
85
|
+
queryRef,
|
|
86
|
+
references
|
|
87
|
+
});
|
|
88
|
+
logger.debug('Comparing Ref', {
|
|
89
|
+
refKey,
|
|
90
|
+
itemRef: references[refKey],
|
|
91
|
+
queryRef
|
|
92
|
+
});
|
|
88
93
|
return isItemKeyEqual(queryRef, references[refKey]);
|
|
89
94
|
};
|
|
90
|
-
const isCompoundConditionQueryMatch = (queryCondition, item)
|
|
95
|
+
const isCompoundConditionQueryMatch = (queryCondition, item)=>{
|
|
91
96
|
if (queryCondition.compoundType === 'AND') {
|
|
92
97
|
// If this is an AND compound condition, we need to check if all of the conditions match
|
|
93
|
-
return queryCondition.conditions.every((condition)
|
|
94
|
-
|
|
95
|
-
isCompoundConditionQueryMatch(condition, item));
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
+
return queryCondition.conditions.every((condition)=>isCondition(condition) ? isConditionQueryMatch(condition, item) : isCompoundConditionQueryMatch(condition, item));
|
|
99
|
+
} else {
|
|
98
100
|
// If this is an OR compound condition, we need to check if any of the conditions match
|
|
99
|
-
return queryCondition.conditions.some((condition)
|
|
100
|
-
isConditionQueryMatch(condition, item) :
|
|
101
|
-
isCompoundConditionQueryMatch(condition, item));
|
|
101
|
+
return queryCondition.conditions.some((condition)=>isCondition(condition) ? isConditionQueryMatch(condition, item) : isCompoundConditionQueryMatch(condition, item));
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
|
-
const isConditionQueryMatch = (queryCondition, item)
|
|
104
|
+
const isConditionQueryMatch = (queryCondition, item)=>{
|
|
105
105
|
const propKey = queryCondition.column;
|
|
106
|
-
logger.trace('doesConditionMatch', {
|
|
106
|
+
logger.trace('doesConditionMatch', {
|
|
107
|
+
propKey,
|
|
108
|
+
queryCondition,
|
|
109
|
+
item
|
|
110
|
+
});
|
|
107
111
|
// eslint-disable-next-line no-undefined
|
|
108
112
|
if (item[propKey] === undefined) {
|
|
109
|
-
logger.debug('Item does not contain prop under key', {
|
|
113
|
+
logger.debug('Item does not contain prop under key', {
|
|
114
|
+
propKey,
|
|
115
|
+
item
|
|
116
|
+
});
|
|
110
117
|
return false;
|
|
111
118
|
}
|
|
112
|
-
logger.debug('Comparing Condition', {
|
|
119
|
+
logger.debug('Comparing Condition', {
|
|
120
|
+
propKey,
|
|
121
|
+
itemProp: item[propKey],
|
|
122
|
+
queryCondition
|
|
123
|
+
});
|
|
113
124
|
let result = false;
|
|
114
|
-
switch
|
|
125
|
+
switch(queryCondition.operator){
|
|
115
126
|
case '==':
|
|
116
127
|
result = item[propKey] === queryCondition.value;
|
|
117
128
|
break;
|
|
@@ -140,86 +151,104 @@ const isConditionQueryMatch = (queryCondition, item) => {
|
|
|
140
151
|
result = item[propKey].includes(queryCondition.value);
|
|
141
152
|
break;
|
|
142
153
|
case 'array-contains-any':
|
|
143
|
-
result = queryCondition.value
|
|
144
|
-
.some(value => item[propKey].includes(value));
|
|
154
|
+
result = queryCondition.value.some((value)=>item[propKey].includes(value));
|
|
145
155
|
break;
|
|
146
156
|
}
|
|
147
157
|
return result;
|
|
148
158
|
};
|
|
149
|
-
const isAggQueryMatch = (aggKey, aggQuery, agg)
|
|
159
|
+
const isAggQueryMatch = (aggKey, aggQuery, agg)=>{
|
|
150
160
|
const aggItem = agg.item;
|
|
151
|
-
logger.debug('Comparing Agg', {
|
|
161
|
+
logger.debug('Comparing Agg', {
|
|
162
|
+
aggKey,
|
|
163
|
+
aggItem,
|
|
164
|
+
aggQuery
|
|
165
|
+
});
|
|
152
166
|
// Fancy, right? This is a recursive call to isQueryMatch
|
|
153
167
|
return isQueryMatch(aggItem, aggQuery);
|
|
154
168
|
};
|
|
155
|
-
const isEventQueryMatch = (eventKey, eventQuery, item)
|
|
169
|
+
const isEventQueryMatch = (eventKey, eventQuery, item)=>{
|
|
156
170
|
if (!item.events[eventKey]) {
|
|
157
|
-
logger.debug('Item does not contain event under key', {
|
|
171
|
+
logger.debug('Item does not contain event under key', {
|
|
172
|
+
eventKey,
|
|
173
|
+
events: item.events
|
|
174
|
+
});
|
|
158
175
|
return false;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
176
|
+
} else {
|
|
161
177
|
const itemEvent = item.events[eventKey];
|
|
162
178
|
if (itemEvent.at !== null) {
|
|
163
179
|
if (eventQuery.start && !(eventQuery.start.getTime() <= itemEvent.at.getTime())) {
|
|
164
|
-
logger.debug('Item date before event start query', {
|
|
180
|
+
logger.debug('Item date before event start query', {
|
|
181
|
+
eventQuery,
|
|
182
|
+
itemEvent
|
|
183
|
+
});
|
|
165
184
|
return false;
|
|
166
185
|
}
|
|
167
186
|
if (eventQuery.end && !(eventQuery.end.getTime() > itemEvent.at.getTime())) {
|
|
168
|
-
logger.debug('Item date after event end query', {
|
|
187
|
+
logger.debug('Item date after event end query', {
|
|
188
|
+
eventQuery,
|
|
189
|
+
itemEvent
|
|
190
|
+
});
|
|
169
191
|
return false;
|
|
170
192
|
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
193
|
+
} else {
|
|
194
|
+
logger.debug('Item event does contains a null at', {
|
|
195
|
+
itemEvent
|
|
196
|
+
});
|
|
174
197
|
return false;
|
|
175
198
|
}
|
|
176
199
|
return true;
|
|
177
200
|
}
|
|
178
201
|
};
|
|
179
|
-
|
|
180
|
-
logger.trace('isMatch', {
|
|
202
|
+
const isQueryMatch = (item, query)=>{
|
|
203
|
+
logger.trace('isMatch', {
|
|
204
|
+
item,
|
|
205
|
+
query
|
|
206
|
+
});
|
|
181
207
|
if (query.refs && item.refs) {
|
|
182
|
-
for
|
|
208
|
+
for(const key in query.refs){
|
|
183
209
|
const queryRef = query.refs[key];
|
|
184
|
-
if (!isRefQueryMatch(key, queryRef, item.refs))
|
|
185
|
-
return false;
|
|
210
|
+
if (!isRefQueryMatch(key, queryRef, item.refs)) return false;
|
|
186
211
|
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
212
|
+
} else if (query.refs && !item.refs) {
|
|
213
|
+
logger.debug('Query contains refs but item does not have refs', {
|
|
214
|
+
query,
|
|
215
|
+
item
|
|
216
|
+
});
|
|
190
217
|
return false;
|
|
191
218
|
}
|
|
192
219
|
if (query.compoundCondition && item) {
|
|
193
|
-
if (!isCompoundConditionQueryMatch(query.compoundCondition, item))
|
|
194
|
-
return false;
|
|
220
|
+
if (!isCompoundConditionQueryMatch(query.compoundCondition, item)) return false;
|
|
195
221
|
}
|
|
196
222
|
if (query.events && item.events) {
|
|
197
|
-
for
|
|
223
|
+
for(const key in query.events){
|
|
198
224
|
const queryEvent = query.events[key];
|
|
199
|
-
if (!isEventQueryMatch(key, queryEvent, item))
|
|
200
|
-
return false;
|
|
225
|
+
if (!isEventQueryMatch(key, queryEvent, item)) return false;
|
|
201
226
|
}
|
|
202
227
|
return true;
|
|
203
228
|
}
|
|
204
229
|
if (query.aggs && item.aggs) {
|
|
205
|
-
for
|
|
230
|
+
for(const key in query.aggs){
|
|
206
231
|
const aggQuery = query.aggs[key];
|
|
207
|
-
if (item.aggs[key] && !isAggQueryMatch(key, aggQuery, item.aggs[key]))
|
|
208
|
-
return false;
|
|
232
|
+
if (item.aggs[key] && !isAggQueryMatch(key, aggQuery, item.aggs[key])) return false;
|
|
209
233
|
}
|
|
210
234
|
}
|
|
211
235
|
if (query.aggs && !item.aggs) {
|
|
212
|
-
logger.debug('Query contains aggs but item does not have aggs', {
|
|
236
|
+
logger.debug('Query contains aggs but item does not have aggs', {
|
|
237
|
+
query,
|
|
238
|
+
item
|
|
239
|
+
});
|
|
213
240
|
return false;
|
|
214
241
|
}
|
|
215
242
|
// If it hasn't returned false by now, it must be a match
|
|
216
243
|
return true;
|
|
217
244
|
};
|
|
218
|
-
|
|
219
|
-
const abbrev = [
|
|
245
|
+
const abbrevQuery = (query)=>{
|
|
246
|
+
const abbrev = [
|
|
247
|
+
'IQ'
|
|
248
|
+
];
|
|
220
249
|
if (query) {
|
|
221
250
|
if (query.refs) {
|
|
222
|
-
for
|
|
251
|
+
for(const key in query.refs){
|
|
223
252
|
const ref = abbrevRef(key, query.refs[key]);
|
|
224
253
|
abbrev.push(ref);
|
|
225
254
|
}
|
|
@@ -229,7 +258,7 @@ export const abbrevQuery = (query) => {
|
|
|
229
258
|
abbrev.push(props);
|
|
230
259
|
}
|
|
231
260
|
if (query.aggs) {
|
|
232
|
-
for
|
|
261
|
+
for(const key in query.aggs){
|
|
233
262
|
const agg = abbrevAgg(key, query.aggs[key]);
|
|
234
263
|
abbrev.push(agg);
|
|
235
264
|
}
|
|
@@ -244,35 +273,33 @@ export const abbrevQuery = (query) => {
|
|
|
244
273
|
if (query.offset) {
|
|
245
274
|
abbrev.push(`O${query.offset}`);
|
|
246
275
|
}
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
276
|
+
} else {
|
|
249
277
|
abbrev.push('(empty)');
|
|
250
278
|
}
|
|
251
279
|
return abbrev.join(' ');
|
|
252
280
|
};
|
|
253
|
-
|
|
281
|
+
const abbrevRef = (key, ref)=>{
|
|
254
282
|
if (isPriKey(ref)) {
|
|
255
283
|
const priKey = ref;
|
|
256
284
|
return `R(${key},${priKey.kt},${priKey.pk})`;
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
285
|
+
} else {
|
|
259
286
|
const comKey = ref;
|
|
260
287
|
return `R(${key},${JSON.stringify(comKey)})`;
|
|
261
288
|
}
|
|
262
289
|
};
|
|
263
|
-
|
|
290
|
+
const abbrevAgg = (key, agg)=>{
|
|
264
291
|
return `A(${key},${abbrevQuery(agg)})`;
|
|
265
292
|
};
|
|
266
|
-
|
|
267
|
-
return `CC(${compoundCondition.compoundType},` +
|
|
268
|
-
`${compoundCondition.conditions ? compoundCondition.conditions.map(abbrevCondition).join(',') : 'No Conditions'})`;
|
|
293
|
+
const abbrevCompoundCondition = (compoundCondition)=>{
|
|
294
|
+
return `CC(${compoundCondition.compoundType},` + `${compoundCondition.conditions ? compoundCondition.conditions.map(abbrevCondition).join(',') : 'No Conditions'})`;
|
|
269
295
|
};
|
|
270
|
-
|
|
296
|
+
const abbrevCondition = (condition)=>{
|
|
271
297
|
if (isCondition(condition)) {
|
|
272
298
|
return `(${condition.column},${condition.value},${condition.operator})`;
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
299
|
+
} else {
|
|
275
300
|
return abbrevCompoundCondition(condition);
|
|
276
301
|
}
|
|
277
302
|
};
|
|
278
|
-
|
|
303
|
+
|
|
304
|
+
export { abbrevAgg, abbrevCompoundCondition, abbrevCondition, abbrevQuery, abbrevRef, isQueryMatch, paramsToQuery, queryToParams };
|
|
305
|
+
//# sourceMappingURL=IQUtils.js.map
|