@fjell/core 4.4.13 → 4.4.18
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/AItemService.d.ts +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +7911 -0
- package/dist/index.js.map +7 -0
- package/dist/item/IFactory.d.ts +2 -2
- package/dist/item/IQFactory.d.ts +1 -1
- package/dist/item/IQUtils.d.ts +3 -3
- package/dist/item/IUtils.d.ts +2 -2
- package/dist/item/ItemQuery.d.ts +1 -1
- package/dist/key/KUtils.d.ts +1 -1
- package/dist/logger.d.ts +1 -1
- package/package.json +15 -13
- package/dist/cjs/AItemService.js +0 -42
- package/dist/cjs/AItemService.js.map +0 -1
- package/dist/cjs/dictionary.js +0 -71
- package/dist/cjs/dictionary.js.map +0 -1
- package/dist/cjs/index.js +0 -62
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/item/IFactory.js +0 -93
- package/dist/cjs/item/IFactory.js.map +0 -1
- package/dist/cjs/item/IQFactory.js +0 -154
- package/dist/cjs/item/IQFactory.js.map +0 -1
- package/dist/cjs/item/IQUtils.js +0 -335
- package/dist/cjs/item/IQUtils.js.map +0 -1
- package/dist/cjs/item/IUtils.js +0 -76
- package/dist/cjs/item/IUtils.js.map +0 -1
- package/dist/cjs/item/ItemQuery.js +0 -10
- package/dist/cjs/item/ItemQuery.js.map +0 -1
- package/dist/cjs/key/KUtils.js +0 -397
- package/dist/cjs/key/KUtils.js.map +0 -1
- package/dist/cjs/logger.js +0 -10
- package/dist/cjs/logger.js.map +0 -1
- package/dist/esm/AItemService.js +0 -38
- package/dist/esm/AItemService.js.map +0 -1
- package/dist/esm/dictionary.js +0 -67
- package/dist/esm/dictionary.js.map +0 -1
- package/dist/esm/index.js +0 -9
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/item/IFactory.js +0 -89
- package/dist/esm/item/IFactory.js.map +0 -1
- package/dist/esm/item/IQFactory.js +0 -150
- package/dist/esm/item/IQFactory.js.map +0 -1
- package/dist/esm/item/IQUtils.js +0 -305
- package/dist/esm/item/IQUtils.js.map +0 -1
- package/dist/esm/item/IUtils.js +0 -69
- package/dist/esm/item/IUtils.js.map +0 -1
- package/dist/esm/item/ItemQuery.js +0 -6
- package/dist/esm/item/ItemQuery.js.map +0 -1
- package/dist/esm/key/KUtils.js +0 -365
- package/dist/esm/key/KUtils.js.map +0 -1
- package/dist/esm/logger.js +0 -6
- package/dist/esm/logger.js.map +0 -1
- package/dist/index.cjs +0 -1131
- package/dist/index.cjs.map +0 -1
- package/docs/README.md +0 -53
- package/docs/index.html +0 -18
- package/docs/package.json +0 -35
- package/docs/public/README.md +0 -227
- package/docs/public/api.md +0 -230
- package/docs/public/basic-usage.ts +0 -293
- package/docs/public/examples-README.md +0 -147
- package/docs/public/fjell-icon.svg +0 -1
- package/docs/public/package.json +0 -56
- package/docs/public/pano.png +0 -0
- package/docs/src/App.css +0 -1178
- package/docs/src/App.tsx +0 -683
- package/docs/src/index.css +0 -38
- package/docs/src/main.tsx +0 -10
- package/docs/tsconfig.node.json +0 -14
- package/docs/vitest.config.ts +0 -14
- package/examples/README.md +0 -147
- package/examples/basic-usage.ts +0 -293
- package/vitest.config.ts +0 -37
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import deepmerge from 'deepmerge';
|
|
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;
|
|
14
|
-
}
|
|
15
|
-
return obj;
|
|
16
|
-
}
|
|
17
|
-
class IFactory {
|
|
18
|
-
addRef(i, name) {
|
|
19
|
-
const ik = i.key;
|
|
20
|
-
const refName = name || primaryType(ik);
|
|
21
|
-
if (!this.item.refs) {
|
|
22
|
-
this.item.refs = {};
|
|
23
|
-
}
|
|
24
|
-
this.item.refs[refName] = ik;
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
static addRef(i, name) {
|
|
28
|
-
return new IFactory().addRef(i, name);
|
|
29
|
-
}
|
|
30
|
-
addDefaultEvents() {
|
|
31
|
-
if (!this.item.events) {
|
|
32
|
-
this.item.events = {};
|
|
33
|
-
}
|
|
34
|
-
const now = new Date();
|
|
35
|
-
if (!this.item.events.created) {
|
|
36
|
-
this.item.events.created = {
|
|
37
|
-
at: now
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (!this.item.events.updated) {
|
|
41
|
-
this.item.events.updated = {
|
|
42
|
-
at: now
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
if (!this.item.events.deleted) {
|
|
46
|
-
this.item.events.deleted = {
|
|
47
|
-
at: null
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
addEvent(name, at, by) {
|
|
53
|
-
if (!this.item.events) {
|
|
54
|
-
this.item.events = {};
|
|
55
|
-
}
|
|
56
|
-
this.item.events[name] = {
|
|
57
|
-
at,
|
|
58
|
-
by
|
|
59
|
-
};
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
static addEvent(name, at, by) {
|
|
63
|
-
return new IFactory().addEvent(name, at, by);
|
|
64
|
-
}
|
|
65
|
-
addProp(name, value) {
|
|
66
|
-
this.item[name] = value;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
static addProp(name, value) {
|
|
70
|
-
return new IFactory().addProp(name, value);
|
|
71
|
-
}
|
|
72
|
-
addProps(props) {
|
|
73
|
-
this.item = deepmerge(this.item, props);
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
static addProps(props) {
|
|
77
|
-
return new IFactory().addProps(props);
|
|
78
|
-
}
|
|
79
|
-
toItem() {
|
|
80
|
-
return this.item;
|
|
81
|
-
}
|
|
82
|
-
constructor(props = {}){
|
|
83
|
-
_define_property(this, "item", {});
|
|
84
|
-
this.item = deepmerge(this.item, props);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { IFactory };
|
|
89
|
-
//# sourceMappingURL=IFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IFactory.js","sources":["../../../src/item/IFactory.ts"],"sourcesContent":["import deepmerge from 'deepmerge';\nimport { Item } from '@/items';\nimport { primaryType } from '@/key/KUtils';\nimport { ComKey, PriKey } from '@/keys';\n\nexport class IFactory<\n V extends Item<S, L1, L2, L3, L4, L5>,\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never> {\n private item: any = {\n };\n\n public constructor(props: Record<string, any> = {}) {\n this.item = deepmerge(this.item, props);\n }\n\n public addRef(i: Item<any, any|never, any|never, any|never, any|never, any|never>, name?: string) {\n const ik: ComKey<any, any|never, any|never, any|never, any|never, any|never> | PriKey<any> = i.key;\n\n const refName = name || primaryType(ik);\n if (!this.item.refs) {\n this.item.refs = {};\n }\n this.item.refs[refName] = ik;\n return this;\n }\n\n public static addRef<\n V extends Item<S, L1, L2, L3, L4, L5>,\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n >(i: V, name?: string) {\n return new IFactory<V, S, L1, L2, L3, L4, L5>().addRef(i, name);\n }\n\n public addDefaultEvents() {\n if (!this.item.events) {\n this.item.events = {};\n }\n const now = new Date();\n if (!this.item.events.created) {\n this.item.events.created = { at: now };\n }\n if (!this.item.events.updated) {\n this.item.events.updated = { at: now };\n }\n if (!this.item.events.deleted) {\n this.item.events.deleted = { at: null };\n }\n return this;\n }\n\n public addEvent(\n name: string,\n at: Date | null,\n by?: ComKey<any, any|never, any|never, any|never, any|never, any|never> | PriKey<any>\n ) {\n if (!this.item.events) {\n this.item.events = {};\n }\n this.item.events[name] = { at, by };\n return this;\n }\n\n public static addEvent<\n V extends Item<S, L1, L2, L3, L4, L5>,\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n >(name: string, at: Date | null, by?: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>) {\n return new IFactory<V, S, L1, L2, L3, L4, L5>().addEvent(name, at, by);\n }\n\n public addProp(name: string, value: string | number | boolean | Date) {\n this.item[name] = value;\n return this;\n }\n\n public static addProp<\n V extends Item<S, L1, L2, L3, L4, L5>,\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n >(name: string, value: string | number | boolean | Date) {\n return new IFactory<V, S, L1, L2, L3, L4, L5>().addProp(name, value);\n }\n\n public addProps(props: Record<string, any>) {\n this.item = deepmerge(this.item, props);\n return this;\n }\n\n public static addProps<\n V extends Item<S, L1, L2, L3, L4, L5>,\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n >(props: Record<string, any>) {\n return new IFactory<V, S, L1, L2, L3, L4, L5>().addProps(props);\n }\n\n toItem(): V {\n return this.item as V;\n }\n}"],"names":["IFactory","addRef","i","name","ik","key","refName","primaryType","item","refs","addDefaultEvents","events","now","Date","created","at","updated","deleted","addEvent","by","addProp","value","addProps","props","deepmerge","toItem"],"mappings":";;;;;;;;;;;;;;;;AAKO,MAAMA,QAAAA,CAAAA;IAeJC,MAAAA,CAAOC,CAAmE,EAAEC,IAAa,EAAE;QAChG,MAAMC,EAAAA,GAAuFF,EAAEG,GAAG;QAElG,MAAMC,OAAAA,GAAUH,QAAQI,WAAAA,CAAYH,EAAAA,CAAAA;AACpC,QAAA,IAAI,CAAC,IAAI,CAACI,IAAI,CAACC,IAAI,EAAE;AACnB,YAAA,IAAI,CAACD,IAAI,CAACC,IAAI,GAAG,EAAC;AAC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PK } 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 {
|
|
18
|
-
orderBy(field, direction = 'asc') {
|
|
19
|
-
if (!this.query.orderBy) {
|
|
20
|
-
this.query.orderBy = [];
|
|
21
|
-
}
|
|
22
|
-
this.query.orderBy.push({
|
|
23
|
-
field,
|
|
24
|
-
direction
|
|
25
|
-
});
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
agg(name, query) {
|
|
29
|
-
if (!this.query.aggs) {
|
|
30
|
-
this.query.aggs = {};
|
|
31
|
-
}
|
|
32
|
-
this.query.aggs[name] = query;
|
|
33
|
-
return this;
|
|
34
|
-
}
|
|
35
|
-
event(name, query) {
|
|
36
|
-
if (!this.query.events) {
|
|
37
|
-
this.query.events = {};
|
|
38
|
-
}
|
|
39
|
-
this.query.events[name] = query;
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
conditions(conditions, compoundType = 'AND') {
|
|
43
|
-
for (const condition of conditions){
|
|
44
|
-
if (!isCondition(condition)) {
|
|
45
|
-
throw new Error(`Invalid condition: ${JSON.stringify(condition)}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (!this.query.compoundCondition) {
|
|
49
|
-
// If there is no top-level compound condition, create one
|
|
50
|
-
// with the given compound type. This will mostly likely be the most common case.
|
|
51
|
-
this.query.compoundCondition = {
|
|
52
|
-
compoundType,
|
|
53
|
-
conditions: conditions
|
|
54
|
-
};
|
|
55
|
-
} else {
|
|
56
|
-
// If there is already a top-level compound condition, create a new compound condition
|
|
57
|
-
// and add it to the conditions array of the top-level compound condition.
|
|
58
|
-
const compoundCondition = {
|
|
59
|
-
compoundType,
|
|
60
|
-
conditions
|
|
61
|
-
};
|
|
62
|
-
this.query.compoundCondition.conditions.push(compoundCondition);
|
|
63
|
-
}
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
limit(limit) {
|
|
67
|
-
this.query.limit = limit;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
offset(offset) {
|
|
71
|
-
this.query.offset = offset;
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
// TODO: right now, we're only supporting PK refs for queries. Should add support for CKs
|
|
75
|
-
pk(kt, pk, name) {
|
|
76
|
-
if (!this.query.refs) {
|
|
77
|
-
this.query.refs = {};
|
|
78
|
-
}
|
|
79
|
-
const refName = name || kt;
|
|
80
|
-
this.query.refs[refName] = cPK(pk, kt);
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
condition(column, value, operator = '==') {
|
|
84
|
-
const condition = {
|
|
85
|
-
column,
|
|
86
|
-
value,
|
|
87
|
-
operator
|
|
88
|
-
};
|
|
89
|
-
if (isCondition(condition)) {
|
|
90
|
-
if (!this.query.compoundCondition) {
|
|
91
|
-
// If there is no top-level compound condition, create one
|
|
92
|
-
// with the default compound type of 'AND'.
|
|
93
|
-
this.query.compoundCondition = {
|
|
94
|
-
compoundType: 'AND',
|
|
95
|
-
conditions: []
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
this.query.compoundCondition.conditions.push(condition);
|
|
99
|
-
return this;
|
|
100
|
-
} else {
|
|
101
|
-
throw new Error(`Invalid condition: ${JSON.stringify(condition)}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
static all() {
|
|
105
|
-
const iqFactory = new IQFactory();
|
|
106
|
-
return iqFactory;
|
|
107
|
-
}
|
|
108
|
-
static orderBy(field, direction = 'asc') {
|
|
109
|
-
const iqFactory = new IQFactory();
|
|
110
|
-
return iqFactory.orderBy(field, direction);
|
|
111
|
-
}
|
|
112
|
-
static agg(name, query) {
|
|
113
|
-
const iqFactory = new IQFactory();
|
|
114
|
-
return iqFactory.agg(name, query);
|
|
115
|
-
}
|
|
116
|
-
static event(name, query) {
|
|
117
|
-
const iqFactory = new IQFactory();
|
|
118
|
-
return iqFactory.event(name, query);
|
|
119
|
-
}
|
|
120
|
-
static limit(limit) {
|
|
121
|
-
const iqFactory = new IQFactory();
|
|
122
|
-
return iqFactory.limit(limit);
|
|
123
|
-
}
|
|
124
|
-
static offset(offset) {
|
|
125
|
-
const iqFactory = new IQFactory();
|
|
126
|
-
return iqFactory.offset(offset);
|
|
127
|
-
}
|
|
128
|
-
static pk(kt, pk, name) {
|
|
129
|
-
const iqFactory = new IQFactory();
|
|
130
|
-
return iqFactory.pk(kt, pk, name);
|
|
131
|
-
}
|
|
132
|
-
static condition(column, value, operator = '==') {
|
|
133
|
-
const iqFactory = new IQFactory();
|
|
134
|
-
return iqFactory.condition(column, value, operator);
|
|
135
|
-
}
|
|
136
|
-
static conditions(conditions, compoundType = 'AND') {
|
|
137
|
-
const iqFactory = new IQFactory();
|
|
138
|
-
return iqFactory.conditions(conditions, compoundType);
|
|
139
|
-
}
|
|
140
|
-
toQuery() {
|
|
141
|
-
return this.query;
|
|
142
|
-
}
|
|
143
|
-
constructor(query = {}){
|
|
144
|
-
_define_property(this, "query", {});
|
|
145
|
-
this.query = query;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export { IQFactory };
|
|
150
|
-
//# sourceMappingURL=IQFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IQFactory.js","sources":["../../../src/item/IQFactory.ts"],"sourcesContent":["import { cPK } from '@/key/KUtils';\nimport {\n CompoundType,\n Condition,\n ConditionOperator,\n EventQuery,\n isCondition,\n ItemQuery,\n OrderDirection\n} from \"./ItemQuery\";\n\nexport class IQFactory {\n\n private query: ItemQuery = {};\n\n public constructor(query: ItemQuery = {}) {\n this.query = query;\n }\n\n public orderBy(field: string, direction: OrderDirection = 'asc') {\n if (!this.query.orderBy) {\n this.query.orderBy = [];\n }\n this.query.orderBy.push({ field, direction });\n return this;\n }\n\n public agg(name: string, query: ItemQuery) {\n if (!this.query.aggs) {\n this.query.aggs = {};\n }\n this.query.aggs[name] = query;\n return this;\n }\n\n public event(name: string, query: EventQuery) {\n if (!this.query.events) {\n this.query.events = {};\n }\n this.query.events[name] = query;\n return this;\n }\n\n public conditions(conditions: Condition[], compoundType: CompoundType = 'AND') {\n for (const condition of conditions) {\n if (!isCondition(condition)) {\n throw new Error(`Invalid condition: ${JSON.stringify(condition)}`);\n }\n }\n if (!this.query.compoundCondition) {\n // If there is no top-level compound condition, create one\n // with the given compound type. This will mostly likely be the most common case.\n this.query.compoundCondition = {\n compoundType,\n conditions: conditions,\n };\n } else {\n // If there is already a top-level compound condition, create a new compound condition\n // and add it to the conditions array of the top-level compound condition.\n const compoundCondition = {\n compoundType,\n conditions,\n };\n this.query.compoundCondition.conditions.push(compoundCondition);\n }\n return this;\n }\n\n public limit(limit: number) {\n this.query.limit = limit;\n return this;\n }\n\n public offset(offset: number) {\n this.query.offset = offset;\n return this;\n }\n\n // TODO: right now, we're only supporting PK refs for queries. Should add support for CKs\n public pk(kt: string, pk: string, name?: string) {\n if (!this.query.refs) {\n this.query.refs = {};\n }\n const refName = name || kt;\n this.query.refs[refName] = cPK<string>(pk, kt);\n return this;\n }\n\n public condition(\n column: string,\n value: string[] | string | number[] | number | boolean | Date,\n operator: ConditionOperator = '==',\n ) {\n const condition: Condition = { column, value, operator };\n if (isCondition(condition)) {\n if (!this.query.compoundCondition) {\n // If there is no top-level compound condition, create one\n // with the default compound type of 'AND'.\n this.query.compoundCondition = {\n compoundType: 'AND',\n conditions: [],\n };\n }\n this.query.compoundCondition.conditions.push(condition);\n return this;\n } else {\n throw new Error(`Invalid condition: ${JSON.stringify(condition)}`);\n }\n }\n\n public static all() {\n const iqFactory = new IQFactory();\n return iqFactory;\n }\n\n public static orderBy(field: string, direction: OrderDirection = 'asc') {\n const iqFactory = new IQFactory();\n return iqFactory.orderBy(field, direction);\n }\n\n public static agg(name: string, query: ItemQuery) {\n const iqFactory = new IQFactory();\n return iqFactory.agg(name, query);\n }\n\n public static event(name: string, query: EventQuery) {\n const iqFactory = new IQFactory();\n return iqFactory.event(name, query);\n }\n\n public static limit(limit: number) {\n const iqFactory = new IQFactory();\n return iqFactory.limit(limit);\n }\n\n public static offset(offset: number) {\n const iqFactory = new IQFactory();\n return iqFactory.offset(offset);\n }\n\n public static pk(kt: string, pk: string, name?: string) {\n const iqFactory = new IQFactory();\n return iqFactory.pk(kt, pk, name);\n }\n\n public static condition(\n column: string,\n value: string[] | string | number[] | number | boolean | Date,\n operator: ConditionOperator = '=='\n ) {\n const iqFactory = new IQFactory();\n return iqFactory.condition(column, value, operator);\n }\n\n public static conditions(conditions: Condition[], compoundType: CompoundType = 'AND') {\n const iqFactory = new IQFactory();\n return iqFactory.conditions(conditions, compoundType);\n }\n\n toQuery() {\n return this.query;\n }\n}"],"names":["IQFactory","orderBy","field","direction","query","push","agg","name","aggs","event","events","conditions","compoundType","condition","isCondition","Error","JSON","stringify","compoundCondition","limit","offset","pk","kt","refs","refName","cPK","column","value","operator","all","iqFactory","toQuery"],"mappings":";;;;;;;;;;;;;;;;AAWO,MAAMA,SAAAA,CAAAA;AAQJC,IAAAA,OAAAA,CAAQC,KAAa,EAAEC,SAAAA,GAA4B,KAAK,EAAE;AAC/D,QAAA,IAAI,CAAC,IAAI,CAACC,KAAK,CAACH,OAAO,EAAE;AACvB,YAAA,IAAI,CAACG,KAAK,CAACH,OAAO,GAAG,EAAE;AACzB,QAAA;AACA,QAAA,IAAI,CAACG,KAAK,CAACH,OAAO,CAACI,IAAI,CAAC;AAAEH,YAAAA,KAAAA;AAAOC,YAAAA;AAAU,SAAA,CAAA;AAC3C,QAAA,OAAO,IAAI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A,MAAMuB,YAAY,IAAI9B,SAAAA,EAAAA;AACtB,QAAA,OAAO8B,SAAAA,CAAUT,EAAE,CAACC,EAAAA,EAAID,EAAAA,EAAId,IAAAA,CAAAA;AAC9B,IAAA;AAEA,IAAA,OAAcM,UACZa,MAAc,EACdC,KAA6D,EAC7DC,QAAAA,GAA8B,IAAI,EAClC;AACA,QAAA,MAAME,YAAY,IAAI9B,SAAAA,EAAAA;AACtB,QAAA,OAAO8B,SAAAA,CAAUjB,SAAS,CAACa,MAAAA,EAAQC,KAAAA,EAAOC,QAAAA,CAAAA;AAC5C,IAAA;AAEA,IAAA,OAAcjB,UAAAA,CAAWA,UAAuB,EAAEC,YAAAA,GAA6B,KAAK,EAAE;AACpF,QAAA,MAAMkB,YAAY,IAAI9B,SAAAA,EAAAA;QACtB,OAAO8B,SAAAA,CAAUnB,UAAU,CAACA,UAAAA,EAAYC,YAAAA,CAAAA;AAC1C,IAAA;IAEAmB,OAAAA,GAAU;QACR,OAAO,IAAI,CAAC3B,KAAK;AACnB,IAAA;IAlJA,WAAA,CAAmBA,KAAAA,GAAmB,EAAE,CAAE;AAF1C,QAAA,gBAAA,CAAA,IAAA,EAAQA,SAAmB,EAAC,CAAA;QAG1B,IAAI,CAACA,KAAK,GAAGA,KAAAA;AACf,IAAA;AAiJF;;;;"}
|
package/dist/esm/item/IQUtils.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import { isPriKey, isItemKeyEqual } from '../key/KUtils.js';
|
|
2
|
-
import LibLogger from '../logger.js';
|
|
3
|
-
import * as luxon from 'luxon';
|
|
4
|
-
import { isCondition } from './ItemQuery.js';
|
|
5
|
-
|
|
6
|
-
const logger = LibLogger.get('IQUtils');
|
|
7
|
-
/**
|
|
8
|
-
* When we query or search, we're sending a GET request. This converts everything in ItemQuery into a flat
|
|
9
|
-
* object that can be sent over a GET request.
|
|
10
|
-
*
|
|
11
|
-
* Note that there is some discussion about this. Evidently Elastic supports search with POST, but that also
|
|
12
|
-
* feels like a bit of a hack. It's not a RESTful way to do things. So we're sticking with GET for now.
|
|
13
|
-
*
|
|
14
|
-
* For reference, look at RFC 9110 "HTTP Semantics", June which clarified on top of and RFC 7231. It's possible
|
|
15
|
-
* but there are so many caveats and conditions in the standard, it's not worth it.
|
|
16
|
-
*
|
|
17
|
-
* Anticipating the next question - "isn't there a limit to the length of a URL?" The specification does not
|
|
18
|
-
* specify a limit, and there are limits in various browsers and servers - Apache is 4,000 chars, Chrome is 2M chars.
|
|
19
|
-
* Short answer is that if this query is being used to craft something that complex, it is probably a better idea
|
|
20
|
-
* to provide an action or a custom query endpoint on the server.
|
|
21
|
-
*
|
|
22
|
-
* @param query
|
|
23
|
-
* @returns QueryParams ready to be get over a GET request.
|
|
24
|
-
*/ const queryToParams = (query)=>{
|
|
25
|
-
const params = {};
|
|
26
|
-
if (query.compoundCondition) {
|
|
27
|
-
params.compoundCondition = JSON.stringify(query.compoundCondition);
|
|
28
|
-
}
|
|
29
|
-
if (query.refs) {
|
|
30
|
-
params.refs = JSON.stringify(query.refs);
|
|
31
|
-
}
|
|
32
|
-
if (query.limit) {
|
|
33
|
-
params.limit = query.limit;
|
|
34
|
-
}
|
|
35
|
-
if (query.offset) {
|
|
36
|
-
params.offset = query.offset;
|
|
37
|
-
}
|
|
38
|
-
if (query.aggs) {
|
|
39
|
-
params.aggs = JSON.stringify(query.aggs);
|
|
40
|
-
}
|
|
41
|
-
if (query.events) {
|
|
42
|
-
params.events = JSON.stringify(query.events);
|
|
43
|
-
}
|
|
44
|
-
return params;
|
|
45
|
-
};
|
|
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(key, value) {
|
|
48
|
-
if (typeof value === 'string') {
|
|
49
|
-
const parsedDate = luxon.DateTime.fromISO(value);
|
|
50
|
-
if (parsedDate.isValid) {
|
|
51
|
-
return parsedDate.toJSDate();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* This method translates from a flat QueryParams object with stringify'd JSON back to a full ItemQuery.
|
|
58
|
-
*
|
|
59
|
-
* @param params Parameters sent over a GET request
|
|
60
|
-
* @returns A fully hydrated ItemQuery object.
|
|
61
|
-
*/ const paramsToQuery = (params)=>{
|
|
62
|
-
const query = {};
|
|
63
|
-
if (params.compoundCondition) {
|
|
64
|
-
query.compoundCondition = JSON.parse(params.compoundCondition);
|
|
65
|
-
}
|
|
66
|
-
if (params.refs) {
|
|
67
|
-
query.refs = JSON.parse(params.refs);
|
|
68
|
-
}
|
|
69
|
-
if (params.limit) {
|
|
70
|
-
query.limit = Number(params.limit);
|
|
71
|
-
}
|
|
72
|
-
if (params.offset) {
|
|
73
|
-
query.offset = Number(params.offset);
|
|
74
|
-
}
|
|
75
|
-
if (params.aggs) {
|
|
76
|
-
query.aggs = JSON.parse(params.aggs);
|
|
77
|
-
}
|
|
78
|
-
if (params.events) {
|
|
79
|
-
query.events = JSON.parse(params.events, dateTimeReviver);
|
|
80
|
-
}
|
|
81
|
-
return query;
|
|
82
|
-
};
|
|
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
|
-
});
|
|
93
|
-
return isItemKeyEqual(queryRef, references[refKey]);
|
|
94
|
-
};
|
|
95
|
-
const isCompoundConditionQueryMatch = (queryCondition, item)=>{
|
|
96
|
-
if (queryCondition.compoundType === 'AND') {
|
|
97
|
-
// If this is an AND compound condition, we need to check if all of the conditions match
|
|
98
|
-
return queryCondition.conditions.every((condition)=>isCondition(condition) ? isConditionQueryMatch(condition, item) : isCompoundConditionQueryMatch(condition, item));
|
|
99
|
-
} else {
|
|
100
|
-
// If this is an OR compound condition, we need to check if any of the conditions match
|
|
101
|
-
return queryCondition.conditions.some((condition)=>isCondition(condition) ? isConditionQueryMatch(condition, item) : isCompoundConditionQueryMatch(condition, item));
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const isConditionQueryMatch = (queryCondition, item)=>{
|
|
105
|
-
const propKey = queryCondition.column;
|
|
106
|
-
logger.trace('doesConditionMatch', {
|
|
107
|
-
propKey,
|
|
108
|
-
queryCondition,
|
|
109
|
-
item
|
|
110
|
-
});
|
|
111
|
-
// eslint-disable-next-line no-undefined
|
|
112
|
-
if (item[propKey] === undefined) {
|
|
113
|
-
logger.debug('Item does not contain prop under key', {
|
|
114
|
-
propKey,
|
|
115
|
-
item
|
|
116
|
-
});
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
logger.debug('Comparing Condition', {
|
|
120
|
-
propKey,
|
|
121
|
-
itemProp: item[propKey],
|
|
122
|
-
queryCondition
|
|
123
|
-
});
|
|
124
|
-
let result = false;
|
|
125
|
-
switch(queryCondition.operator){
|
|
126
|
-
case '==':
|
|
127
|
-
result = item[propKey] === queryCondition.value;
|
|
128
|
-
break;
|
|
129
|
-
case '!=':
|
|
130
|
-
result = item[propKey] !== queryCondition.value;
|
|
131
|
-
break;
|
|
132
|
-
case '>':
|
|
133
|
-
result = item[propKey] > queryCondition.value;
|
|
134
|
-
break;
|
|
135
|
-
case '>=':
|
|
136
|
-
result = item[propKey] >= queryCondition.value;
|
|
137
|
-
break;
|
|
138
|
-
case '<':
|
|
139
|
-
result = item[propKey] < queryCondition.value;
|
|
140
|
-
break;
|
|
141
|
-
case '<=':
|
|
142
|
-
result = item[propKey] <= queryCondition.value;
|
|
143
|
-
break;
|
|
144
|
-
case 'in':
|
|
145
|
-
result = queryCondition.value.includes(item[propKey]);
|
|
146
|
-
break;
|
|
147
|
-
case 'not-in':
|
|
148
|
-
result = !queryCondition.value.includes(item[propKey]);
|
|
149
|
-
break;
|
|
150
|
-
case 'array-contains':
|
|
151
|
-
result = item[propKey].includes(queryCondition.value);
|
|
152
|
-
break;
|
|
153
|
-
case 'array-contains-any':
|
|
154
|
-
result = queryCondition.value.some((value)=>item[propKey].includes(value));
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
return result;
|
|
158
|
-
};
|
|
159
|
-
const isAggQueryMatch = (aggKey, aggQuery, agg)=>{
|
|
160
|
-
const aggItem = agg.item;
|
|
161
|
-
logger.debug('Comparing Agg', {
|
|
162
|
-
aggKey,
|
|
163
|
-
aggItem,
|
|
164
|
-
aggQuery
|
|
165
|
-
});
|
|
166
|
-
// Fancy, right? This is a recursive call to isQueryMatch
|
|
167
|
-
return isQueryMatch(aggItem, aggQuery);
|
|
168
|
-
};
|
|
169
|
-
const isEventQueryMatch = (eventKey, eventQuery, item)=>{
|
|
170
|
-
if (!item.events[eventKey]) {
|
|
171
|
-
logger.debug('Item does not contain event under key', {
|
|
172
|
-
eventKey,
|
|
173
|
-
events: item.events
|
|
174
|
-
});
|
|
175
|
-
return false;
|
|
176
|
-
} else {
|
|
177
|
-
const itemEvent = item.events[eventKey];
|
|
178
|
-
if (itemEvent.at !== null) {
|
|
179
|
-
if (eventQuery.start && !(eventQuery.start.getTime() <= itemEvent.at.getTime())) {
|
|
180
|
-
logger.debug('Item date before event start query', {
|
|
181
|
-
eventQuery,
|
|
182
|
-
itemEvent
|
|
183
|
-
});
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
if (eventQuery.end && !(eventQuery.end.getTime() > itemEvent.at.getTime())) {
|
|
187
|
-
logger.debug('Item date after event end query', {
|
|
188
|
-
eventQuery,
|
|
189
|
-
itemEvent
|
|
190
|
-
});
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
} else {
|
|
194
|
-
logger.debug('Item event does contains a null at', {
|
|
195
|
-
itemEvent
|
|
196
|
-
});
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
const isQueryMatch = (item, query)=>{
|
|
203
|
-
logger.trace('isMatch', {
|
|
204
|
-
item,
|
|
205
|
-
query
|
|
206
|
-
});
|
|
207
|
-
if (query.refs && item.refs) {
|
|
208
|
-
for(const key in query.refs){
|
|
209
|
-
const queryRef = query.refs[key];
|
|
210
|
-
if (!isRefQueryMatch(key, queryRef, item.refs)) return false;
|
|
211
|
-
}
|
|
212
|
-
} else if (query.refs && !item.refs) {
|
|
213
|
-
logger.debug('Query contains refs but item does not have refs', {
|
|
214
|
-
query,
|
|
215
|
-
item
|
|
216
|
-
});
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
if (query.compoundCondition && item) {
|
|
220
|
-
if (!isCompoundConditionQueryMatch(query.compoundCondition, item)) return false;
|
|
221
|
-
}
|
|
222
|
-
if (query.events && item.events) {
|
|
223
|
-
for(const key in query.events){
|
|
224
|
-
const queryEvent = query.events[key];
|
|
225
|
-
if (!isEventQueryMatch(key, queryEvent, item)) return false;
|
|
226
|
-
}
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
|
-
if (query.aggs && item.aggs) {
|
|
230
|
-
for(const key in query.aggs){
|
|
231
|
-
const aggQuery = query.aggs[key];
|
|
232
|
-
if (item.aggs[key] && !isAggQueryMatch(key, aggQuery, item.aggs[key])) return false;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
if (query.aggs && !item.aggs) {
|
|
236
|
-
logger.debug('Query contains aggs but item does not have aggs', {
|
|
237
|
-
query,
|
|
238
|
-
item
|
|
239
|
-
});
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
// If it hasn't returned false by now, it must be a match
|
|
243
|
-
return true;
|
|
244
|
-
};
|
|
245
|
-
const abbrevQuery = (query)=>{
|
|
246
|
-
const abbrev = [
|
|
247
|
-
'IQ'
|
|
248
|
-
];
|
|
249
|
-
if (query) {
|
|
250
|
-
if (query.refs) {
|
|
251
|
-
for(const key in query.refs){
|
|
252
|
-
const ref = abbrevRef(key, query.refs[key]);
|
|
253
|
-
abbrev.push(ref);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (query.compoundCondition) {
|
|
257
|
-
const props = abbrevCompoundCondition(query.compoundCondition);
|
|
258
|
-
abbrev.push(props);
|
|
259
|
-
}
|
|
260
|
-
if (query.aggs) {
|
|
261
|
-
for(const key in query.aggs){
|
|
262
|
-
const agg = abbrevAgg(key, query.aggs[key]);
|
|
263
|
-
abbrev.push(agg);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
if (query.events) {
|
|
267
|
-
const events = `(E${Object.keys(query.events).join(',')})`;
|
|
268
|
-
abbrev.push(events);
|
|
269
|
-
}
|
|
270
|
-
if (query.limit) {
|
|
271
|
-
abbrev.push(`L${query.limit}`);
|
|
272
|
-
}
|
|
273
|
-
if (query.offset) {
|
|
274
|
-
abbrev.push(`O${query.offset}`);
|
|
275
|
-
}
|
|
276
|
-
} else {
|
|
277
|
-
abbrev.push('(empty)');
|
|
278
|
-
}
|
|
279
|
-
return abbrev.join(' ');
|
|
280
|
-
};
|
|
281
|
-
const abbrevRef = (key, ref)=>{
|
|
282
|
-
if (isPriKey(ref)) {
|
|
283
|
-
const priKey = ref;
|
|
284
|
-
return `R(${key},${priKey.kt},${priKey.pk})`;
|
|
285
|
-
} else {
|
|
286
|
-
const comKey = ref;
|
|
287
|
-
return `R(${key},${JSON.stringify(comKey)})`;
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
const abbrevAgg = (key, agg)=>{
|
|
291
|
-
return `A(${key},${abbrevQuery(agg)})`;
|
|
292
|
-
};
|
|
293
|
-
const abbrevCompoundCondition = (compoundCondition)=>{
|
|
294
|
-
return `CC(${compoundCondition.compoundType},` + `${compoundCondition.conditions ? compoundCondition.conditions.map(abbrevCondition).join(',') : 'No Conditions'})`;
|
|
295
|
-
};
|
|
296
|
-
const abbrevCondition = (condition)=>{
|
|
297
|
-
if (isCondition(condition)) {
|
|
298
|
-
return `(${condition.column},${condition.value},${condition.operator})`;
|
|
299
|
-
} else {
|
|
300
|
-
return abbrevCompoundCondition(condition);
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
export { abbrevAgg, abbrevCompoundCondition, abbrevCondition, abbrevQuery, abbrevRef, isQueryMatch, paramsToQuery, queryToParams };
|
|
305
|
-
//# sourceMappingURL=IQUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IQUtils.js","sources":["../../../src/item/IQUtils.ts"],"sourcesContent":["import { Item, ReferenceItem, References } from \"@/items\";\nimport { isItemKeyEqual, isPriKey } from \"@/key/KUtils\";\nimport { ComKey, PriKey } from \"@/keys\";\nimport LibLogger from \"@/logger\";\nimport * as luxon from 'luxon';\nimport { CompoundCondition, Condition, EventQuery, isCondition, ItemQuery, QueryParams } from \"./ItemQuery\";\n\nconst logger = LibLogger.get('IQUtils');\n\n/**\n * When we query or search, we're sending a GET request. This converts everything in ItemQuery into a flat\n * object that can be sent over a GET request.\n *\n * Note that there is some discussion about this. Evidently Elastic supports search with POST, but that also\n * feels like a bit of a hack. It's not a RESTful way to do things. So we're sticking with GET for now.\n *\n * For reference, look at RFC 9110 \"HTTP Semantics\", June which clarified on top of and RFC 7231. It's possible\n * but there are so many caveats and conditions in the standard, it's not worth it.\n *\n * Anticipating the next question - \"isn't there a limit to the length of a URL?\" The specification does not\n * specify a limit, and there are limits in various browsers and servers - Apache is 4,000 chars, Chrome is 2M chars.\n * Short answer is that if this query is being used to craft something that complex, it is probably a better idea\n * to provide an action or a custom query endpoint on the server.\n *\n * @param query\n * @returns QueryParams ready to be get over a GET request.\n */\nexport const queryToParams = (query: ItemQuery): QueryParams => {\n const params: QueryParams = {};\n if (query.compoundCondition) {\n params.compoundCondition = JSON.stringify(query.compoundCondition);\n }\n if (query.refs) {\n params.refs = JSON.stringify(query.refs);\n }\n if (query.limit) {\n params.limit = query.limit;\n }\n if (query.offset) {\n params.offset = query.offset;\n }\n if (query.aggs) {\n params.aggs = JSON.stringify(query.aggs);\n }\n if (query.events) {\n params.events = JSON.stringify(query.events);\n }\n return params;\n}\n\n// This is a dateTimeReviver used for JSON parse - when we convert a param back to a query, we need this.\nconst dateTimeReviver = function (key: string, value: string) {\n if (typeof value === 'string') {\n const parsedDate = luxon.DateTime.fromISO(value);\n if (parsedDate.isValid) {\n return parsedDate.toJSDate();;\n }\n }\n return value;\n}\n\n/**\n * This method translates from a flat QueryParams object with stringify'd JSON back to a full ItemQuery.\n *\n * @param params Parameters sent over a GET request\n * @returns A fully hydrated ItemQuery object.\n */\nexport const paramsToQuery = (params: QueryParams): ItemQuery => {\n const query: ItemQuery = {};\n if (params.compoundCondition) {\n query.compoundCondition = JSON.parse(params.compoundCondition as string) as CompoundCondition;\n }\n if (params.refs) {\n query.refs = JSON.parse(params.refs as string) as References;\n }\n if (params.limit) {\n query.limit = Number(params.limit);\n }\n if (params.offset) {\n query.offset = Number(params.offset);\n }\n if (params.aggs) {\n query.aggs = JSON.parse(params.aggs as string) as Record<string, ItemQuery>;\n }\n if (params.events) {\n query.events = JSON.parse(params.events as string, dateTimeReviver) as Record<string, { start?: Date, end?: Date }>;\n }\n return query;\n}\n\nconst isRefQueryMatch =\n <\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n >(\n refKey: string,\n queryRef: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,\n references: References,\n ): boolean => {\n logger.trace('doesRefMatch', { queryRef, references });\n logger.debug('Comparing Ref', { refKey, itemRef: references[refKey], queryRef });\n return isItemKeyEqual(queryRef, references[refKey]);\n }\n\nconst isCompoundConditionQueryMatch = <\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n>(\n queryCondition: CompoundCondition,\n item: Item<S, L1, L2, L3, L4, L5>,\n ): boolean => {\n if (queryCondition.compoundType === 'AND') {\n // If this is an AND compound condition, we need to check if all of the conditions match\n return queryCondition.conditions.every(\n (condition: Condition | CompoundCondition) =>\n isCondition(condition) ?\n isConditionQueryMatch(condition, item) :\n isCompoundConditionQueryMatch(condition, item)\n );\n } else {\n // If this is an OR compound condition, we need to check if any of the conditions match\n return queryCondition.conditions.some(\n (condition: Condition | CompoundCondition) =>\n isCondition(condition) ?\n isConditionQueryMatch(condition, item) :\n isCompoundConditionQueryMatch(condition, item)\n );\n }\n}\n\nconst isConditionQueryMatch = <\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n>(\n queryCondition: Condition,\n item: Item<S, L1, L2, L3, L4, L5>,\n ): boolean => {\n const propKey = queryCondition.column;\n logger.trace('doesConditionMatch', { propKey, queryCondition, item });\n // eslint-disable-next-line no-undefined\n if (item[propKey] === undefined) {\n logger.debug('Item does not contain prop under key', { propKey, item });\n return false;\n }\n logger.debug('Comparing Condition', { propKey, itemProp: item[propKey], queryCondition });\n let result = false;\n switch (queryCondition.operator) {\n case '==':\n result = item[propKey] === queryCondition.value;\n break;\n case '!=':\n result = item[propKey] !== queryCondition.value;\n break;\n case '>':\n result = item[propKey] > queryCondition.value;\n break;\n case '>=':\n result = item[propKey] >= queryCondition.value;\n break;\n case '<':\n result = item[propKey] < queryCondition.value;\n break;\n case '<=':\n result = item[propKey] <= queryCondition.value;\n break;\n case 'in':\n result = (queryCondition.value as unknown as string[]).includes(item[propKey] as string);\n break;\n case 'not-in':\n result = !(queryCondition.value as unknown as string[]).includes(item[propKey] as string);\n break;\n case 'array-contains':\n result = (item[propKey] as unknown as string[]).includes(queryCondition.value as string);\n break;\n case 'array-contains-any':\n result = (queryCondition.value as unknown as string[])\n .some(value => (item[propKey] as unknown as string[]).includes(value));\n break;\n }\n return result;\n}\n\nconst isAggQueryMatch = <\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n>(\n aggKey: string,\n aggQuery: ItemQuery,\n agg: ReferenceItem<S, L1, L2, L3, L4, L5>\n ): boolean => {\n const aggItem = agg.item;\n logger.debug('Comparing Agg', { aggKey, aggItem, aggQuery });\n // Fancy, right? This is a recursive call to isQueryMatch\n return isQueryMatch(aggItem, aggQuery);\n}\n\nconst isEventQueryMatch = <\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n>(\n eventKey: string,\n eventQuery: EventQuery,\n item: Item<S, L1, L2, L3, L4, L5>,\n ): boolean => {\n if (!item.events[eventKey]) {\n logger.debug('Item does not contain event under key', { eventKey, events: item.events });\n return false;\n } else {\n const itemEvent = item.events[eventKey];\n if (itemEvent.at !== null) {\n if (eventQuery.start && !(eventQuery.start.getTime() <= itemEvent.at.getTime())) {\n logger.debug('Item date before event start query', { eventQuery, itemEvent });\n return false;\n }\n if (eventQuery.end && !(eventQuery.end.getTime() > itemEvent.at.getTime())) {\n logger.debug('Item date after event end query', { eventQuery, itemEvent });\n return false;\n }\n } else {\n logger.debug('Item event does contains a null at', { itemEvent });\n return false;\n }\n return true;\n }\n}\n\nexport const isQueryMatch = <\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n>(item: Item<S, L1, L2, L3, L4, L5>, query: ItemQuery): boolean => {\n\n logger.trace('isMatch', { item, query });\n if (query.refs && item.refs) {\n for (const key in query.refs) {\n const queryRef = query.refs[key];\n if (!isRefQueryMatch(key, queryRef, item.refs)) return false;\n }\n } else if (query.refs && !item.refs) {\n logger.debug('Query contains refs but item does not have refs', { query, item });\n return false;\n }\n\n if (query.compoundCondition && item) {\n if (!isCompoundConditionQueryMatch(query.compoundCondition, item)) return false;\n }\n\n if (query.events && item.events) {\n for (const key in query.events) {\n const queryEvent = query.events[key];\n if (!isEventQueryMatch(key, queryEvent, item)) return false\n }\n return true;\n }\n\n if (query.aggs && item.aggs) {\n for (const key in query.aggs) {\n const aggQuery = query.aggs[key];\n if (item.aggs[key] && !isAggQueryMatch(key, aggQuery, item.aggs[key])) return false;\n }\n } if (query.aggs && !item.aggs) {\n logger.debug('Query contains aggs but item does not have aggs', { query, item });\n return false;\n }\n\n // If it hasn't returned false by now, it must be a match\n return true;\n}\n\nexport const abbrevQuery = (query: ItemQuery | null | undefined): string => {\n const abbrev = ['IQ'];\n if( query ) {\n if (query.refs) {\n for (const key in query.refs) {\n const ref = abbrevRef(key, query.refs[key]);\n abbrev.push(ref);\n }\n }\n if (query.compoundCondition) {\n const props = abbrevCompoundCondition(query.compoundCondition);\n abbrev.push(props);\n }\n if (query.aggs) {\n for (const key in query.aggs) {\n const agg = abbrevAgg(key, query.aggs[key]);\n abbrev.push(agg);\n }\n }\n if (query.events) {\n const events = `(E${Object.keys(query.events).join(',')})`;\n abbrev.push(events);\n }\n if (query.limit) {\n abbrev.push(`L${query.limit}`);\n }\n if (query.offset) {\n abbrev.push(`O${query.offset}`);\n }\n } else {\n abbrev.push('(empty)');\n }\n return abbrev.join(' ');\n}\n\nexport const abbrevRef = <\n S extends string,\n L1 extends string = never,\n L2 extends string = never,\n L3 extends string = never,\n L4 extends string = never,\n L5 extends string = never\n>(key: string, ref: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): string => {\n if (isPriKey(ref)) {\n const priKey = ref as PriKey<S>;\n return `R(${key},${priKey.kt},${priKey.pk})`;\n } else {\n const comKey = ref as ComKey<S, L1, L2, L3, L4, L5>;\n return `R(${key},${JSON.stringify(comKey)})`;\n }\n}\n\nexport const abbrevAgg = (key: string, agg: ItemQuery): string => {\n return `A(${key},${abbrevQuery(agg)})`;\n}\n\nexport const abbrevCompoundCondition = (compoundCondition: CompoundCondition): string => {\n return `CC(${compoundCondition.compoundType},` +\n `${compoundCondition.conditions ? compoundCondition.conditions.map(abbrevCondition).join(',') : 'No Conditions'})`;\n}\n\nexport const abbrevCondition = (condition: Condition | CompoundCondition): string => {\n if (isCondition(condition)) {\n return `(${condition.column},${condition.value},${condition.operator})`;\n } else {\n return abbrevCompoundCondition(condition);\n }\n}\n"],"names":["logger","LibLogger","get","queryToParams","query","params","compoundCondition","JSON","stringify","refs","limit","offset","aggs","events","dateTimeReviver","key","value","parsedDate","luxon","DateTime","fromISO","isValid","toJSDate","paramsToQuery","parse","Number","isRefQueryMatch","refKey","queryRef","references","trace","debug","itemRef","isItemKeyEqual","isCompoundConditionQueryMatch","queryCondition","item","compoundType","conditions","every","condition","isCondition","isConditionQueryMatch","some","propKey","column","undefined","itemProp","result","operator","includes","isAggQueryMatch","aggKey","aggQuery","agg","aggItem","isQueryMatch","isEventQueryMatch","eventKey","eventQuery","itemEvent","at","start","getTime","end","queryEvent","abbrevQuery","abbrev","ref","abbrevRef","push","props","abbrevCompoundCondition","abbrevAgg","Object","keys","join","isPriKey","priKey","kt","pk","comKey","map","abbrevCondition"],"mappings":";;;;;AAOA,MAAMA,MAAAA,GAASC,SAAAA,CAAUC,GAAG,CAAC,SAAA,CAAA;AAE7B;;;;;;;;;;;;;;;;;IAkBO,MAAMC,aAAAA,GAAgB,CAACC,KAAAA,GAAAA;AAC5B,IAAA,MAAMC,SAAsB,EAAC;IAC7B,IAAID,KAAAA,CAAME,iBAAiB,EAAE;AAC3BD,QAAAA,MAAAA,CAAOC,iBAAiB,GAAGC,IAAAA,CAAKC,SAAS,CAACJ,MAAME,iBAAiB,CAAA;AACnE,IAAA;IACA,IAAIF,KAAAA,CAAMK,IAAI,EAAE;AACdJ,QAAAA,MAAAA,CAAOI,IAAI,GAAGF,IAAAA,CAAKC,SAAS,CAACJ,MAAMK,IAAI,CAAA;AACzC,IAAA;IACA,IAAIL,KAAAA,CAAMM,KAAK,EAAE;QACfL,MAAAA,CAAOK,KAAK,GAAGN,KAAAA,CAAMM,KAAK;AAC5B,IAAA;IACA,IAAIN,KAAAA,CAAMO,MAAM,EAAE;QAChBN,MAAAA,CAAOM,MAAM,GAAGP,KAAAA,CAAMO,MAAM;AAC9B,IAAA;IACA,IAAIP,K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