@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.
Files changed (73) hide show
  1. package/dist/AItemService.d.ts +1 -1
  2. package/dist/index.d.ts +5 -5
  3. package/dist/index.js +7911 -0
  4. package/dist/index.js.map +7 -0
  5. package/dist/item/IFactory.d.ts +2 -2
  6. package/dist/item/IQFactory.d.ts +1 -1
  7. package/dist/item/IQUtils.d.ts +3 -3
  8. package/dist/item/IUtils.d.ts +2 -2
  9. package/dist/item/ItemQuery.d.ts +1 -1
  10. package/dist/key/KUtils.d.ts +1 -1
  11. package/dist/logger.d.ts +1 -1
  12. package/package.json +15 -13
  13. package/dist/cjs/AItemService.js +0 -42
  14. package/dist/cjs/AItemService.js.map +0 -1
  15. package/dist/cjs/dictionary.js +0 -71
  16. package/dist/cjs/dictionary.js.map +0 -1
  17. package/dist/cjs/index.js +0 -62
  18. package/dist/cjs/index.js.map +0 -1
  19. package/dist/cjs/item/IFactory.js +0 -93
  20. package/dist/cjs/item/IFactory.js.map +0 -1
  21. package/dist/cjs/item/IQFactory.js +0 -154
  22. package/dist/cjs/item/IQFactory.js.map +0 -1
  23. package/dist/cjs/item/IQUtils.js +0 -335
  24. package/dist/cjs/item/IQUtils.js.map +0 -1
  25. package/dist/cjs/item/IUtils.js +0 -76
  26. package/dist/cjs/item/IUtils.js.map +0 -1
  27. package/dist/cjs/item/ItemQuery.js +0 -10
  28. package/dist/cjs/item/ItemQuery.js.map +0 -1
  29. package/dist/cjs/key/KUtils.js +0 -397
  30. package/dist/cjs/key/KUtils.js.map +0 -1
  31. package/dist/cjs/logger.js +0 -10
  32. package/dist/cjs/logger.js.map +0 -1
  33. package/dist/esm/AItemService.js +0 -38
  34. package/dist/esm/AItemService.js.map +0 -1
  35. package/dist/esm/dictionary.js +0 -67
  36. package/dist/esm/dictionary.js.map +0 -1
  37. package/dist/esm/index.js +0 -9
  38. package/dist/esm/index.js.map +0 -1
  39. package/dist/esm/item/IFactory.js +0 -89
  40. package/dist/esm/item/IFactory.js.map +0 -1
  41. package/dist/esm/item/IQFactory.js +0 -150
  42. package/dist/esm/item/IQFactory.js.map +0 -1
  43. package/dist/esm/item/IQUtils.js +0 -305
  44. package/dist/esm/item/IQUtils.js.map +0 -1
  45. package/dist/esm/item/IUtils.js +0 -69
  46. package/dist/esm/item/IUtils.js.map +0 -1
  47. package/dist/esm/item/ItemQuery.js +0 -6
  48. package/dist/esm/item/ItemQuery.js.map +0 -1
  49. package/dist/esm/key/KUtils.js +0 -365
  50. package/dist/esm/key/KUtils.js.map +0 -1
  51. package/dist/esm/logger.js +0 -6
  52. package/dist/esm/logger.js.map +0 -1
  53. package/dist/index.cjs +0 -1131
  54. package/dist/index.cjs.map +0 -1
  55. package/docs/README.md +0 -53
  56. package/docs/index.html +0 -18
  57. package/docs/package.json +0 -35
  58. package/docs/public/README.md +0 -227
  59. package/docs/public/api.md +0 -230
  60. package/docs/public/basic-usage.ts +0 -293
  61. package/docs/public/examples-README.md +0 -147
  62. package/docs/public/fjell-icon.svg +0 -1
  63. package/docs/public/package.json +0 -56
  64. package/docs/public/pano.png +0 -0
  65. package/docs/src/App.css +0 -1178
  66. package/docs/src/App.tsx +0 -683
  67. package/docs/src/index.css +0 -38
  68. package/docs/src/main.tsx +0 -10
  69. package/docs/tsconfig.node.json +0 -14
  70. package/docs/vitest.config.ts +0 -14
  71. package/examples/README.md +0 -147
  72. package/examples/basic-usage.ts +0 -293
  73. package/vitest.config.ts +0 -37
@@ -1,335 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const KUtils = require('../key/KUtils.js');
6
- const logger$1 = require('../logger.js');
7
- const luxon = require('luxon');
8
- const ItemQuery = require('./ItemQuery.js');
9
-
10
- function _interopNamespaceDefault(e) {
11
- const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
12
- if (e) {
13
- for (const k in e) {
14
- if (k !== 'default') {
15
- const d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: () => e[k]
19
- });
20
- }
21
- }
22
- }
23
- n.default = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- const luxon__namespace = /*#__PURE__*/_interopNamespaceDefault(luxon);
28
-
29
- const logger = logger$1.default.get('IQUtils');
30
- /**
31
- * When we query or search, we're sending a GET request. This converts everything in ItemQuery into a flat
32
- * object that can be sent over a GET request.
33
- *
34
- * Note that there is some discussion about this. Evidently Elastic supports search with POST, but that also
35
- * feels like a bit of a hack. It's not a RESTful way to do things. So we're sticking with GET for now.
36
- *
37
- * For reference, look at RFC 9110 "HTTP Semantics", June which clarified on top of and RFC 7231. It's possible
38
- * but there are so many caveats and conditions in the standard, it's not worth it.
39
- *
40
- * Anticipating the next question - "isn't there a limit to the length of a URL?" The specification does not
41
- * specify a limit, and there are limits in various browsers and servers - Apache is 4,000 chars, Chrome is 2M chars.
42
- * Short answer is that if this query is being used to craft something that complex, it is probably a better idea
43
- * to provide an action or a custom query endpoint on the server.
44
- *
45
- * @param query
46
- * @returns QueryParams ready to be get over a GET request.
47
- */ const queryToParams = (query)=>{
48
- const params = {};
49
- if (query.compoundCondition) {
50
- params.compoundCondition = JSON.stringify(query.compoundCondition);
51
- }
52
- if (query.refs) {
53
- params.refs = JSON.stringify(query.refs);
54
- }
55
- if (query.limit) {
56
- params.limit = query.limit;
57
- }
58
- if (query.offset) {
59
- params.offset = query.offset;
60
- }
61
- if (query.aggs) {
62
- params.aggs = JSON.stringify(query.aggs);
63
- }
64
- if (query.events) {
65
- params.events = JSON.stringify(query.events);
66
- }
67
- return params;
68
- };
69
- // This is a dateTimeReviver used for JSON parse - when we convert a param back to a query, we need this.
70
- const dateTimeReviver = function(key, value) {
71
- if (typeof value === 'string') {
72
- const parsedDate = luxon__namespace.DateTime.fromISO(value);
73
- if (parsedDate.isValid) {
74
- return parsedDate.toJSDate();
75
- }
76
- }
77
- return value;
78
- };
79
- /**
80
- * This method translates from a flat QueryParams object with stringify'd JSON back to a full ItemQuery.
81
- *
82
- * @param params Parameters sent over a GET request
83
- * @returns A fully hydrated ItemQuery object.
84
- */ const paramsToQuery = (params)=>{
85
- const query = {};
86
- if (params.compoundCondition) {
87
- query.compoundCondition = JSON.parse(params.compoundCondition);
88
- }
89
- if (params.refs) {
90
- query.refs = JSON.parse(params.refs);
91
- }
92
- if (params.limit) {
93
- query.limit = Number(params.limit);
94
- }
95
- if (params.offset) {
96
- query.offset = Number(params.offset);
97
- }
98
- if (params.aggs) {
99
- query.aggs = JSON.parse(params.aggs);
100
- }
101
- if (params.events) {
102
- query.events = JSON.parse(params.events, dateTimeReviver);
103
- }
104
- return query;
105
- };
106
- const isRefQueryMatch = (refKey, queryRef, references)=>{
107
- logger.trace('doesRefMatch', {
108
- queryRef,
109
- references
110
- });
111
- logger.debug('Comparing Ref', {
112
- refKey,
113
- itemRef: references[refKey],
114
- queryRef
115
- });
116
- return KUtils.isItemKeyEqual(queryRef, references[refKey]);
117
- };
118
- const isCompoundConditionQueryMatch = (queryCondition, item)=>{
119
- if (queryCondition.compoundType === 'AND') {
120
- // If this is an AND compound condition, we need to check if all of the conditions match
121
- return queryCondition.conditions.every((condition)=>ItemQuery.isCondition(condition) ? isConditionQueryMatch(condition, item) : isCompoundConditionQueryMatch(condition, item));
122
- } else {
123
- // If this is an OR compound condition, we need to check if any of the conditions match
124
- return queryCondition.conditions.some((condition)=>ItemQuery.isCondition(condition) ? isConditionQueryMatch(condition, item) : isCompoundConditionQueryMatch(condition, item));
125
- }
126
- };
127
- const isConditionQueryMatch = (queryCondition, item)=>{
128
- const propKey = queryCondition.column;
129
- logger.trace('doesConditionMatch', {
130
- propKey,
131
- queryCondition,
132
- item
133
- });
134
- // eslint-disable-next-line no-undefined
135
- if (item[propKey] === undefined) {
136
- logger.debug('Item does not contain prop under key', {
137
- propKey,
138
- item
139
- });
140
- return false;
141
- }
142
- logger.debug('Comparing Condition', {
143
- propKey,
144
- itemProp: item[propKey],
145
- queryCondition
146
- });
147
- let result = false;
148
- switch(queryCondition.operator){
149
- case '==':
150
- result = item[propKey] === queryCondition.value;
151
- break;
152
- case '!=':
153
- result = item[propKey] !== queryCondition.value;
154
- break;
155
- case '>':
156
- result = item[propKey] > queryCondition.value;
157
- break;
158
- case '>=':
159
- result = item[propKey] >= queryCondition.value;
160
- break;
161
- case '<':
162
- result = item[propKey] < queryCondition.value;
163
- break;
164
- case '<=':
165
- result = item[propKey] <= queryCondition.value;
166
- break;
167
- case 'in':
168
- result = queryCondition.value.includes(item[propKey]);
169
- break;
170
- case 'not-in':
171
- result = !queryCondition.value.includes(item[propKey]);
172
- break;
173
- case 'array-contains':
174
- result = item[propKey].includes(queryCondition.value);
175
- break;
176
- case 'array-contains-any':
177
- result = queryCondition.value.some((value)=>item[propKey].includes(value));
178
- break;
179
- }
180
- return result;
181
- };
182
- const isAggQueryMatch = (aggKey, aggQuery, agg)=>{
183
- const aggItem = agg.item;
184
- logger.debug('Comparing Agg', {
185
- aggKey,
186
- aggItem,
187
- aggQuery
188
- });
189
- // Fancy, right? This is a recursive call to isQueryMatch
190
- return isQueryMatch(aggItem, aggQuery);
191
- };
192
- const isEventQueryMatch = (eventKey, eventQuery, item)=>{
193
- if (!item.events[eventKey]) {
194
- logger.debug('Item does not contain event under key', {
195
- eventKey,
196
- events: item.events
197
- });
198
- return false;
199
- } else {
200
- const itemEvent = item.events[eventKey];
201
- if (itemEvent.at !== null) {
202
- if (eventQuery.start && !(eventQuery.start.getTime() <= itemEvent.at.getTime())) {
203
- logger.debug('Item date before event start query', {
204
- eventQuery,
205
- itemEvent
206
- });
207
- return false;
208
- }
209
- if (eventQuery.end && !(eventQuery.end.getTime() > itemEvent.at.getTime())) {
210
- logger.debug('Item date after event end query', {
211
- eventQuery,
212
- itemEvent
213
- });
214
- return false;
215
- }
216
- } else {
217
- logger.debug('Item event does contains a null at', {
218
- itemEvent
219
- });
220
- return false;
221
- }
222
- return true;
223
- }
224
- };
225
- const isQueryMatch = (item, query)=>{
226
- logger.trace('isMatch', {
227
- item,
228
- query
229
- });
230
- if (query.refs && item.refs) {
231
- for(const key in query.refs){
232
- const queryRef = query.refs[key];
233
- if (!isRefQueryMatch(key, queryRef, item.refs)) return false;
234
- }
235
- } else if (query.refs && !item.refs) {
236
- logger.debug('Query contains refs but item does not have refs', {
237
- query,
238
- item
239
- });
240
- return false;
241
- }
242
- if (query.compoundCondition && item) {
243
- if (!isCompoundConditionQueryMatch(query.compoundCondition, item)) return false;
244
- }
245
- if (query.events && item.events) {
246
- for(const key in query.events){
247
- const queryEvent = query.events[key];
248
- if (!isEventQueryMatch(key, queryEvent, item)) return false;
249
- }
250
- return true;
251
- }
252
- if (query.aggs && item.aggs) {
253
- for(const key in query.aggs){
254
- const aggQuery = query.aggs[key];
255
- if (item.aggs[key] && !isAggQueryMatch(key, aggQuery, item.aggs[key])) return false;
256
- }
257
- }
258
- if (query.aggs && !item.aggs) {
259
- logger.debug('Query contains aggs but item does not have aggs', {
260
- query,
261
- item
262
- });
263
- return false;
264
- }
265
- // If it hasn't returned false by now, it must be a match
266
- return true;
267
- };
268
- const abbrevQuery = (query)=>{
269
- const abbrev = [
270
- 'IQ'
271
- ];
272
- if (query) {
273
- if (query.refs) {
274
- for(const key in query.refs){
275
- const ref = abbrevRef(key, query.refs[key]);
276
- abbrev.push(ref);
277
- }
278
- }
279
- if (query.compoundCondition) {
280
- const props = abbrevCompoundCondition(query.compoundCondition);
281
- abbrev.push(props);
282
- }
283
- if (query.aggs) {
284
- for(const key in query.aggs){
285
- const agg = abbrevAgg(key, query.aggs[key]);
286
- abbrev.push(agg);
287
- }
288
- }
289
- if (query.events) {
290
- const events = `(E${Object.keys(query.events).join(',')})`;
291
- abbrev.push(events);
292
- }
293
- if (query.limit) {
294
- abbrev.push(`L${query.limit}`);
295
- }
296
- if (query.offset) {
297
- abbrev.push(`O${query.offset}`);
298
- }
299
- } else {
300
- abbrev.push('(empty)');
301
- }
302
- return abbrev.join(' ');
303
- };
304
- const abbrevRef = (key, ref)=>{
305
- if (KUtils.isPriKey(ref)) {
306
- const priKey = ref;
307
- return `R(${key},${priKey.kt},${priKey.pk})`;
308
- } else {
309
- const comKey = ref;
310
- return `R(${key},${JSON.stringify(comKey)})`;
311
- }
312
- };
313
- const abbrevAgg = (key, agg)=>{
314
- return `A(${key},${abbrevQuery(agg)})`;
315
- };
316
- const abbrevCompoundCondition = (compoundCondition)=>{
317
- return `CC(${compoundCondition.compoundType},` + `${compoundCondition.conditions ? compoundCondition.conditions.map(abbrevCondition).join(',') : 'No Conditions'})`;
318
- };
319
- const abbrevCondition = (condition)=>{
320
- if (ItemQuery.isCondition(condition)) {
321
- return `(${condition.column},${condition.value},${condition.operator})`;
322
- } else {
323
- return abbrevCompoundCondition(condition);
324
- }
325
- };
326
-
327
- exports.abbrevAgg = abbrevAgg;
328
- exports.abbrevCompoundCondition = abbrevCompoundCondition;
329
- exports.abbrevCondition = abbrevCondition;
330
- exports.abbrevQuery = abbrevQuery;
331
- exports.abbrevRef = abbrevRef;
332
- exports.isQueryMatch = isQueryMatch;
333
- exports.paramsToQuery = paramsToQuery;
334
- exports.queryToParams = queryToParams;
335
- //# 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,gBAAAA,CAAUC,GAAG,CAAC,SAAA,CAAA;AAE7B;;;;;;;;;;;;;;;;;IAkBO,MAAMC,aAAAA,GAAgB,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AMO,kBAAkB,CAAC3C,SAAAA,GAAAA;AAC9B,IAAA,IAAIC,sBAAYD,SAAAA,CAAAA,EAAY;AAC1B,QAAA,OAAO,CAAC,CAAC,EAAEA,SAAAA,CAAUK,MAAM,CAAC,CAAC,EAAEL,SAAAA,CAAUxB,KAAK,CAAC,CAAC,EAAEwB,UAAUS,QAAQ,CAAC,CAAC,CAAC;IACzE,CAAA,MAAO;AACL,QAAA,OAAOuB,uBAAAA,CAAwBhC,SAAAA,CAAAA;AACjC,IAAA;AACF;;;;;;;;;;;"}
@@ -1,76 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const KUtils = require('../key/KUtils.js');
6
- const logger$1 = require('../logger.js');
7
-
8
- const logger = logger$1.default.get('IUtils');
9
- const validatePKForItem = (item, pkType)=>{
10
- if (!item) {
11
- logger.error('Validating PK, Item is undefined', {
12
- item
13
- });
14
- throw new Error('Validating PK, Item is undefined');
15
- }
16
- if (!item.key) {
17
- logger.error('Validating PK, Item does not have a key', {
18
- item
19
- });
20
- throw new Error('Validating PK, Item does not have a key');
21
- }
22
- const keyTypeArray = KUtils.toKeyTypeArray(item.key);
23
- if (keyTypeArray[0] !== pkType) {
24
- logger.error('Key Type Array Mismatch', {
25
- keyTypeArray,
26
- pkType
27
- });
28
- throw new Error(`Item does not have the correct primary key type. Expected ${pkType}, got ${keyTypeArray[0]}`);
29
- }
30
- return item;
31
- };
32
- const validatePK = (input, pkType)=>{
33
- logger.trace('Checking Return Type', {
34
- input
35
- });
36
- if (Array.isArray(input)) {
37
- return input.map((item)=>validatePKForItem(item, pkType));
38
- }
39
- return validatePKForItem(input, pkType);
40
- };
41
- const validateKeys = (item, keyTypes)=>{
42
- logger.trace('Checking Return Type', {
43
- item
44
- });
45
- if (!item) {
46
- throw new Error('validating keys, item is undefined');
47
- }
48
- if (!item.key) {
49
- throw new Error('validating keys, item does not have a key: ' + JSON.stringify(item));
50
- }
51
- const keyTypeArray = KUtils.toKeyTypeArray(item.key);
52
- if (keyTypeArray.length !== keyTypes.length) {
53
- throw new Error(`Item does not have the correct number of keys. Expected ${keyTypes.length}, but got ${keyTypeArray.length}`);
54
- }
55
- const match = JSON.stringify(keyTypeArray) === JSON.stringify(keyTypes);
56
- if (!match) {
57
- logger.error('Key Type Array Mismatch', {
58
- keyTypeArray,
59
- thisKeyTypes: keyTypes
60
- });
61
- throw new Error(`Item does not have the correct key types. Expected [${keyTypes.join(', ')}], but got [${keyTypeArray.join(', ')}]`);
62
- }
63
- return item;
64
- };
65
- const isPriItem = (item)=>{
66
- return !!(item && item.key && KUtils.isPriKey(item.key));
67
- };
68
- const isComItem = (item)=>{
69
- return !!(item && item.key && KUtils.isComKey(item.key));
70
- };
71
-
72
- exports.isComItem = isComItem;
73
- exports.isPriItem = isPriItem;
74
- exports.validateKeys = validateKeys;
75
- exports.validatePK = validatePK;
76
- //# sourceMappingURL=IUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IUtils.js","sources":["../../../src/item/IUtils.ts"],"sourcesContent":["/* eslint-disable indent */\n \nimport { Item } from \"@/items\";\nimport { isComKey, isPriKey, toKeyTypeArray } from \"@/key/KUtils\";\nimport { AllItemTypeArrays, ComKey, PriKey } from \"@/keys\";\n\nimport LibLogger from '@/logger';\n\nconst logger = LibLogger.get('IUtils');\n\nconst validatePKForItem = <\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>, pkType: S): Item<S, L1, L2, L3, L4, L5> => {\n if (!item) {\n logger.error('Validating PK, Item is undefined', { item });\n throw new Error('Validating PK, Item is undefined');\n }\n if (!item.key) {\n logger.error('Validating PK, Item does not have a key', { item });\n throw new Error('Validating PK, Item does not have a key');\n }\n\n const keyTypeArray = toKeyTypeArray(item.key as ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>);\n if (keyTypeArray[0] !== pkType) {\n logger.error('Key Type Array Mismatch', { keyTypeArray, pkType });\n throw new Error(`Item does not have the correct primary key type. Expected ${pkType}, got ${keyTypeArray[0]}`);\n }\n return item;\n};\n\nexport const validatePK = <\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 input: Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[],\n pkType: S,\n): Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[] => {\n logger.trace('Checking Return Type', { input });\n\n if (Array.isArray(input)) {\n return input.map((item) => validatePKForItem(item, pkType));\n }\n return validatePKForItem(input, pkType);\n};\n\nexport const validateKeys = <\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 item: Item<S, L1, L2, L3, L4, L5>,\n keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>,\n): Item<S, L1, L2, L3, L4, L5> => {\n logger.trace('Checking Return Type', { item });\n if (!item) {\n throw new Error('validating keys, item is undefined');\n }\n if (!item.key) {\n throw new Error('validating keys, item does not have a key: ' + JSON.stringify(item));\n }\n\n const keyTypeArray = toKeyTypeArray(item.key as ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>);\n if (keyTypeArray.length !== keyTypes.length) {\n throw new Error(`Item does not have the correct number of keys. Expected ${keyTypes.length}, but got ${keyTypeArray.length}`);\n }\n\n const match: boolean = JSON.stringify(keyTypeArray) === JSON.stringify(keyTypes);\n if (!match) {\n logger.error('Key Type Array Mismatch', { keyTypeArray, thisKeyTypes: keyTypes });\n throw new Error(`Item does not have the correct key types. Expected [${keyTypes.join(', ')}], but got [${keyTypeArray.join(', ')}]`);\n }\n return item;\n};\n\nexport const isPriItem = <\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 item: Item<S, L1, L2, L3, L4, L5>,\n): item is Item<S> & { key: PriKey<S> } => {\n return !!(item && item.key && isPriKey(item.key));\n};\n\nexport const isComItem = <\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 item: Item<S, L1, L2, L3, L4, L5>,\n): item is Item<S, L1, L2, L3, L4, L5> & { key: ComKey<S, L1, L2, L3, L4, L5> } => {\n return !!(item && item.key && isComKey(item.key));\n};"],"names":["logger","LibLogger","get","validatePKForItem","item","pkType","error","Error","key","keyTypeArray","toKeyTypeArray","validatePK","input","trace","Array","isArray","map","validateKeys","keyTypes","JSON","stringify","length","match","thisKeyTypes","join","isPriItem","isPriKey","isComItem","isComKey"],"mappings":";;;;;;;AAQA,MAAMA,MAAAA,GAASC,gBAAAA,CAAUC,GAAG,CAAC,QAAA,CAAA;AAE7B,MAAMC,iBAAAA,GAAoB,CAOxBC,IAAAA,EAAmCC,MAAAA,GAAAA;AACnC,IAAA,IAAI,CAACD,IAAAA,EAAM;QACTJ,MAAAA,CAAOM,KAAK,CAAC,kCAAA,EAAoC;AAAEF,YAAAA;AAAK,SAAA,CAAA;AACxD,QAAA,MAAM,IAAIG,KAAAA,CAAM,kCAAA,CAAA;AAClB,IAAA;IACA,IAAI,CAACH,IAAAA,CAAKI,GAAG,EAAE;QACbR,MAAAA,CAAOM,KAAK,CAAC,yCAAA,EAA2C;AAAEF,YAAAA;AAAK,SAAA,CAAA;AAC/D,QAAA,MAAM,IAAIG,KAAAA,CAAM,yCAAA,CAAA;AAClB,IAAA;IAEA,MAAME,YAAAA,GAAeC,qBAAAA,CAAeN,IAAAA,CAAKI,GAAG,CAAA;AAC5C,IAAA,IAAIC,YAAY,CAAC,CAAA,CAAE,KAAKJ,MAAAA,EAAQ;QAC9BL,MAAAA,CAAOM,KAAK,CAAC,yBAAA,EAA2B;AAAEG,YAAAA,YAAAA;AAAcJ,YAAAA;AAAO,SAAA,CAAA;QAC/D,MAAM,IAAIE,KAAAA,CAAM,C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,QAAiBH,IAAAA,CAAKC,SAAS,CAACX,YAAAA,CAAAA,KAAkBU,IAAAA,CAAKC,SAAS,CAACF,QAAAA,CAAAA;AACvE,IAAA,IAAI,CAACI,KAAAA,EAAO;QACVtB,MAAAA,CAAOM,KAAK,CAAC,yBAAA,EAA2B;AAAEG,YAAAA,YAAAA;YAAcc,YAAAA,EAAcL;AAAS,SAAA,CAAA;AAC/E,QAAA,MAAM,IAAIX,KAAAA,CAAM,CAAC,oDAAoD,EAAEW,SAASM,IAAI,CAAC,IAAA,CAAA,CAAM,YAAY,EAAEf,YAAAA,CAAae,IAAI,CAAC,IAAA,CAAA,CAAM,CAAC,CAAC,CAAA;AACrI,IAAA;IACA,OAAOpB,IAAAA;AACT;AAEO,MAAMqB,YAAY,CAQvBrB,IAAAA,GAAAA;IAEA,OAAO,CAAC,EAAEA,IAAAA,IAAQA,IAAAA,CAAKI,GAAG,IAAIkB,eAAAA,CAAStB,IAAAA,CAAKI,GAAG,CAAA,CAAA;AACjD;AAEO,MAAMmB,YAAY,CAQvBvB,IAAAA,GAAAA;IAEA,OAAO,CAAC,EAAEA,IAAAA,IAAQA,IAAAA,CAAKI,GAAG,IAAIoB,eAAAA,CAASxB,IAAAA,CAAKI,GAAG,CAAA,CAAA;AACjD;;;;;;;"}
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const isCondition = (condition)=>{
6
- return (typeof condition.column === 'string' && Array.isArray(condition.value) && condition.value.every((item)=>typeof item === 'string') || Array.isArray(condition.value) && condition.value.every((item)=>typeof item === 'number') || typeof condition.value === 'string' || typeof condition.value === 'number' || typeof condition.value === 'boolean' || condition.value instanceof Date) && (condition.operator ? typeof condition.operator === 'string' : true);
7
- };
8
-
9
- exports.isCondition = isCondition;
10
- //# sourceMappingURL=ItemQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ItemQuery.js","sources":["../../../src/item/ItemQuery.ts"],"sourcesContent":["import { References } from '@/items';\n\nexport type QueryParams = Record<string, string | number | boolean | Date>;\n\n/**\n * The operator for a condition. This is the same as the operators used in the Firestore query language.\n */\nexport type ConditionOperator =\n '==' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any';\n\n/**\n * A single property condition is defined with a column, value, and operator.\n * This is a condition that is used in a query.\n */\nexport type Condition = {\n column: string,\n value: string[] | string | number[] | number | boolean | Date,\n operator: ConditionOperator,\n};\n\n/**\n * When applying a compound condition, the CompoundType defines the type of compound condition.\n */\nexport type CompoundType = 'AND' | 'OR';\n\n/**\n * When configuring a CompoundCondition this can contain a collection of conditions\n * that will be applied to the query. By default, this is an AND conditiion that is associated\n * with an array of Condition objects OR an array of CompoundCondition objects.\n *\n * For example, I could have { compoundType: 'AND', conditions: [{column: 'name', value: 'test', operator: '=='},\n * {column: 'age', value: 21, operator: '>='}]} which would filter the query to only include items\n * where the name is 'test' and the age is greater than or equal to 21.\n *\n * Or, I could have a { compoundType: 'OR', conditions: [{column: 'name', value: 'test', operator: '=='},\n * {column: 'age', value: 21, operator: '>='}]} which would filter the query to only include items\n * where the name is 'test' OR the age is greater than or equal to 21.\n *\n * I could also nest an OR within an AND, like this:\n * ['AND', [{column: 'name', value: 'test', operator: '=='},\n * { compoundType: 'OR', conditions: [{column: 'age', value: 21, operator: '<='},\n * {column: 'age', value: 52, operator: '>='}]}]] which would filter the query to only include items where the\n * name is 'test' and the age is less than or equal to 21 or greater than or equal to 52.\n */\nexport type CompoundCondition = {\n compoundType: CompoundType,\n conditions: Array<Condition | CompoundCondition>\n};\n\nexport const isCondition = (condition: any): condition is Condition => {\n return (\n typeof condition.column === 'string' &&\n (Array.isArray(condition.value) && condition.value.every((item: any) => typeof item === 'string')) ||\n (Array.isArray(condition.value) && condition.value.every((item: any) => typeof item === 'number')) ||\n typeof condition.value === 'string' ||\n typeof condition.value === 'number' ||\n typeof condition.value === 'boolean' ||\n condition.value instanceof Date\n ) && (condition.operator ? typeof condition.operator === 'string' : true);\n}\n\nexport type EventQuery = {\n start?: Date,\n end?: Date,\n by?: string,\n}\n\nexport type OrderDirection = 'asc' | 'desc';\n\nexport type OrderBy = {\n field: string;\n direction: OrderDirection;\n}\n\nexport type ItemQuery = {\n refs?: References;\n compoundCondition?: CompoundCondition;\n limit?: number;\n offset?: number;\n aggs?: Record<\n string,\n ItemQuery\n >;\n events?: Record<string, EventQuery>;\n orderBy?: OrderBy[];\n};\n\n"],"names":["isCondition","condition","column","Array","isArray","value","every","item","Date","operator"],"mappings":";;;;AAiDO,MAAMA,cAAc,CAACC,SAAAA,GAAAA;AAC1B,IAAA,OAAO,CACL,OAAOA,SAAAA,CAAUC,MAAM,KAAK,QAAA,IAC3BC,KAAAA,CAAMC,OAAO,CAACH,SAAAA,CAAUI,KAAK,CAAA,IAAKJ,UAAUI,KAAK,CAACC,KAAK,CAAC,CAACC,IAAAA,GAAc,OAAOA,IAAAA,KAAS,aACvFJ,KAAAA,CAAMC,OAAO,CAACH,SAAAA,CAAUI,KAAK,CAAA,IAAKJ,SAAAA,CAAUI,KAAK,CAACC,KAAK,CAAC,CAACC,IAAAA,GAAc,OAAOA,IAAAA,KAAS,QAAA,CAAA,IACxF,OAAON,UAAUI,KAAK,KAAK,QAAA,IAC3B,OAAOJ,SAAAA,CAAUI,KAAK,KAAK,QAAA,IAC3B,OAAOJ,SAAAA,CAAUI,KAAK,KAAK,SAAA,IAC3BJ,SAAAA,CAAUI,KAAK,YAAYG,IAAG,MAC1BP,SAAAA,CAAUQ,QAAQ,GAAG,OAAOR,SAAAA,CAAUQ,QAAQ,KAAK,WAAW,IAAG,CAAA;AACzE;;;;"}