@aikotools/datafilter 1.0.0 → 1.0.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.
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { DateTime as
|
|
2
|
-
function
|
|
1
|
+
import { DateTime as $ } from "luxon";
|
|
2
|
+
function x(i) {
|
|
3
3
|
return "matchAny" in i;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function b(i) {
|
|
6
6
|
return "match" in i && "expected" in i;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function g(i, s) {
|
|
9
9
|
const t = [];
|
|
10
10
|
if (s.length === 0)
|
|
11
11
|
return {
|
|
@@ -67,15 +67,15 @@ function k(i, s) {
|
|
|
67
67
|
validPath: t
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
const t =
|
|
70
|
+
function V(i, s) {
|
|
71
|
+
const t = g(i, s);
|
|
72
72
|
return t.found && t.value !== void 0;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
const e =
|
|
74
|
+
function I(i, s, t) {
|
|
75
|
+
const e = g(i, s);
|
|
76
76
|
return e.found && e.value !== void 0 ? e.value : t;
|
|
77
77
|
}
|
|
78
|
-
class
|
|
78
|
+
class w {
|
|
79
79
|
constructor(s) {
|
|
80
80
|
this.context = s;
|
|
81
81
|
}
|
|
@@ -104,7 +104,7 @@ class M {
|
|
|
104
104
|
* @returns FilterCheckResult
|
|
105
105
|
*/
|
|
106
106
|
checkValue(s, t, e) {
|
|
107
|
-
const n =
|
|
107
|
+
const n = g(s, t);
|
|
108
108
|
if (!n.found)
|
|
109
109
|
return {
|
|
110
110
|
status: !1,
|
|
@@ -138,7 +138,7 @@ class M {
|
|
|
138
138
|
* @returns FilterCheckResult
|
|
139
139
|
*/
|
|
140
140
|
checkExists(s, t, e) {
|
|
141
|
-
const n =
|
|
141
|
+
const n = g(s, t), r = n.found && n.value !== void 0;
|
|
142
142
|
return e.exists === r ? {
|
|
143
143
|
status: !0,
|
|
144
144
|
checkType: "checkExists"
|
|
@@ -160,7 +160,7 @@ class M {
|
|
|
160
160
|
* @returns FilterCheckResult
|
|
161
161
|
*/
|
|
162
162
|
checkArrayElement(s, t, e) {
|
|
163
|
-
const n =
|
|
163
|
+
const n = g(s, t);
|
|
164
164
|
if (!n.found)
|
|
165
165
|
return {
|
|
166
166
|
status: !1,
|
|
@@ -204,7 +204,7 @@ class M {
|
|
|
204
204
|
* @returns FilterCheckResult
|
|
205
205
|
*/
|
|
206
206
|
checkArraySize(s, t, e) {
|
|
207
|
-
const n =
|
|
207
|
+
const n = g(s, t);
|
|
208
208
|
if (!n.found)
|
|
209
209
|
return {
|
|
210
210
|
status: !1,
|
|
@@ -261,7 +261,7 @@ class M {
|
|
|
261
261
|
* @returns FilterCheckResult
|
|
262
262
|
*/
|
|
263
263
|
checkTimeRange(s, t, e) {
|
|
264
|
-
const n =
|
|
264
|
+
const n = g(s, t);
|
|
265
265
|
if (!n.found)
|
|
266
266
|
return {
|
|
267
267
|
status: !1,
|
|
@@ -298,7 +298,7 @@ class M {
|
|
|
298
298
|
};
|
|
299
299
|
}
|
|
300
300
|
if (typeof r == "string") {
|
|
301
|
-
const a =
|
|
301
|
+
const a = $.fromISO(r), u = $.fromISO(e.min), c = $.fromISO(e.max);
|
|
302
302
|
return a.isValid ? !u.isValid || !c.isValid ? {
|
|
303
303
|
status: !1,
|
|
304
304
|
checkType: "checkTimeRange",
|
|
@@ -347,7 +347,7 @@ class M {
|
|
|
347
347
|
* @returns FilterCheckResult
|
|
348
348
|
*/
|
|
349
349
|
checkNumericRange(s, t, e) {
|
|
350
|
-
const n =
|
|
350
|
+
const n = g(s, t);
|
|
351
351
|
if (!n.found)
|
|
352
352
|
return {
|
|
353
353
|
status: !1,
|
|
@@ -401,9 +401,9 @@ class M {
|
|
|
401
401
|
return s === t;
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
|
-
class
|
|
404
|
+
class S {
|
|
405
405
|
constructor(s) {
|
|
406
|
-
this.engine = new
|
|
406
|
+
this.engine = new w(s);
|
|
407
407
|
}
|
|
408
408
|
/**
|
|
409
409
|
* Matches a single file against a rule.
|
|
@@ -413,7 +413,7 @@ class P {
|
|
|
413
413
|
* @returns MatchResult indicating if all criteria matched
|
|
414
414
|
*/
|
|
415
415
|
matchFile(s, t) {
|
|
416
|
-
const n = (
|
|
416
|
+
const n = (x(t) ? t.matchAny : t.match).map((a) => this.engine.evaluateCriterion(s.data, a));
|
|
417
417
|
return {
|
|
418
418
|
matched: n.every((a) => a.status),
|
|
419
419
|
checks: n,
|
|
@@ -440,54 +440,53 @@ class P {
|
|
|
440
440
|
* @returns FilterResult with mapped, wildcardMatched, and unmapped files
|
|
441
441
|
*/
|
|
442
442
|
filterFiles(s, t, e, n) {
|
|
443
|
-
|
|
444
|
-
const r = n ? this.applyPreFilter(s, n) : s, a = e ? [...r].sort(e) : [...r], u = [], c = [], f = [], p = /* @__PURE__ */ new Set(), x = /* @__PURE__ */ new Map();
|
|
443
|
+
const r = n ? this.applyPreFilter(s, n) : s, a = e ? [...r].sort(e) : [...r], u = [], c = [], f = [], y = /* @__PURE__ */ new Set(), k = /* @__PURE__ */ new Map();
|
|
445
444
|
let o = 0, l = 0;
|
|
446
445
|
for (; o < a.length; ) {
|
|
447
|
-
const
|
|
446
|
+
const h = a[o];
|
|
448
447
|
if (l >= t.length) {
|
|
449
|
-
|
|
450
|
-
file:
|
|
448
|
+
y.has(o) || f.push({
|
|
449
|
+
file: h,
|
|
451
450
|
attemptedRules: []
|
|
452
451
|
}), o++;
|
|
453
452
|
continue;
|
|
454
453
|
}
|
|
455
|
-
const
|
|
456
|
-
let
|
|
457
|
-
if (Array.isArray(
|
|
458
|
-
for (let
|
|
459
|
-
if (
|
|
454
|
+
const m = t[l], v = [];
|
|
455
|
+
let R = !1;
|
|
456
|
+
if (Array.isArray(m)) {
|
|
457
|
+
for (let p = 0; p < m.length; p++) {
|
|
458
|
+
if (k.get(l)?.has(p))
|
|
460
459
|
continue;
|
|
461
|
-
const
|
|
462
|
-
if (
|
|
463
|
-
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
expected:
|
|
467
|
-
file:
|
|
468
|
-
matchResult:
|
|
469
|
-
optional:
|
|
470
|
-
info:
|
|
471
|
-
}),
|
|
460
|
+
const T = m[p], F = this.matchFile(h, T);
|
|
461
|
+
if (v.push(F), F.matched && b(T)) {
|
|
462
|
+
k.has(l) || k.set(l, /* @__PURE__ */ new Set());
|
|
463
|
+
const E = k.get(l);
|
|
464
|
+
E && E.add(p), u.push({
|
|
465
|
+
expected: T.expected,
|
|
466
|
+
file: h,
|
|
467
|
+
matchResult: F,
|
|
468
|
+
optional: T.optional || !1,
|
|
469
|
+
info: T.info
|
|
470
|
+
}), y.add(o), R = !0;
|
|
472
471
|
break;
|
|
473
472
|
}
|
|
474
473
|
}
|
|
475
|
-
|
|
474
|
+
k.get(l)?.size === m.length && l++, o++;
|
|
476
475
|
} else {
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
expected:
|
|
480
|
-
file:
|
|
481
|
-
matchResult:
|
|
482
|
-
optional:
|
|
483
|
-
info:
|
|
484
|
-
}),
|
|
485
|
-
file:
|
|
486
|
-
matchResult:
|
|
487
|
-
info:
|
|
488
|
-
}),
|
|
489
|
-
file:
|
|
490
|
-
attemptedRules:
|
|
476
|
+
const d = m, p = this.matchFile(h, d);
|
|
477
|
+
v.push(p), p.matched ? b(d) ? (u.push({
|
|
478
|
+
expected: d.expected,
|
|
479
|
+
file: h,
|
|
480
|
+
matchResult: p,
|
|
481
|
+
optional: d.optional || !1,
|
|
482
|
+
info: d.info
|
|
483
|
+
}), y.add(o), l++, o++) : x(d) && (c.push({
|
|
484
|
+
file: h,
|
|
485
|
+
matchResult: p,
|
|
486
|
+
info: d.info
|
|
487
|
+
}), y.add(o), d.greedy || l++, o++) : d.optional || x(d) ? l++ : (f.push({
|
|
488
|
+
file: h,
|
|
489
|
+
attemptedRules: v
|
|
491
490
|
}), o++);
|
|
492
491
|
}
|
|
493
492
|
}
|
|
@@ -517,13 +516,13 @@ class P {
|
|
|
517
516
|
* Counts mandatory rules
|
|
518
517
|
*/
|
|
519
518
|
countMandatoryRules(s) {
|
|
520
|
-
return s.reduce((t, e) => Array.isArray(e) ? t + e.filter((n) => !n.optional && !
|
|
519
|
+
return s.reduce((t, e) => Array.isArray(e) ? t + e.filter((n) => !n.optional && !x(n)).length : t + (e.optional || x(e) ? 0 : 1), 0);
|
|
521
520
|
}
|
|
522
521
|
/**
|
|
523
522
|
* Counts optional rules
|
|
524
523
|
*/
|
|
525
524
|
countOptionalRules(s) {
|
|
526
|
-
return s.reduce((t, e) => Array.isArray(e) ? t + e.filter((n) => n.optional ||
|
|
525
|
+
return s.reduce((t, e) => Array.isArray(e) ? t + e.filter((n) => n.optional || x(n)).length : t + (e.optional || x(e) ? 1 : 0), 0);
|
|
527
526
|
}
|
|
528
527
|
/**
|
|
529
528
|
* Filtering function for grouped rules with common filter criteria.
|
|
@@ -539,31 +538,31 @@ class P {
|
|
|
539
538
|
filterFilesWithGroups(s, t, e, n) {
|
|
540
539
|
const r = n ? this.applyPreFilter(s, n) : s, a = e ? [...r].sort(e) : [...r], u = [], c = [], f = [];
|
|
541
540
|
for (const o of t) {
|
|
542
|
-
const l = a.filter((
|
|
541
|
+
const l = a.filter((m) => o.groupFilter.map((R) => this.engine.evaluateCriterion(m.data, R)).every((R) => R.status));
|
|
543
542
|
if (l.length === 0)
|
|
544
543
|
continue;
|
|
545
|
-
const A = o.rules.map((
|
|
546
|
-
u.push(...
|
|
544
|
+
const A = o.rules.map((m) => (Array.isArray(m), m)), h = this.filterFiles(l, A);
|
|
545
|
+
u.push(...h.mapped), c.push(...h.wildcardMatched), f.push(...h.unmapped);
|
|
547
546
|
}
|
|
548
|
-
const
|
|
547
|
+
const y = t.flatMap((o) => o.rules), k = {
|
|
549
548
|
totalFiles: s.length,
|
|
550
549
|
mappedFiles: u.length,
|
|
551
550
|
wildcardMatchedFiles: c.length,
|
|
552
551
|
unmappedFiles: f.length,
|
|
553
|
-
totalRules: this.countRules(
|
|
554
|
-
mandatoryRules: this.countMandatoryRules(
|
|
555
|
-
optionalRules: this.countOptionalRules(
|
|
552
|
+
totalRules: this.countRules(y),
|
|
553
|
+
mandatoryRules: this.countMandatoryRules(y),
|
|
554
|
+
optionalRules: this.countOptionalRules(y)
|
|
556
555
|
};
|
|
557
556
|
return {
|
|
558
557
|
mapped: u,
|
|
559
558
|
wildcardMatched: c,
|
|
560
559
|
unmapped: f,
|
|
561
|
-
stats:
|
|
560
|
+
stats: k
|
|
562
561
|
};
|
|
563
562
|
}
|
|
564
563
|
}
|
|
565
|
-
function
|
|
566
|
-
const s = new
|
|
564
|
+
function N(i) {
|
|
565
|
+
const s = new S(i.context);
|
|
567
566
|
if (i.rules && i.groups)
|
|
568
567
|
throw new Error('FilterRequest: Provide either "rules" or "groups", not both');
|
|
569
568
|
if (!i.rules && !i.groups)
|
|
@@ -580,12 +579,12 @@ function O(i) {
|
|
|
580
579
|
return s.filterFiles(i.files, i.rules, i.sortFn, i.preFilter);
|
|
581
580
|
}
|
|
582
581
|
export {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
582
|
+
w as FilterEngine,
|
|
583
|
+
S as Matcher,
|
|
584
|
+
N as filterFiles,
|
|
585
|
+
g as getValueFromPath,
|
|
586
|
+
I as getValueOr,
|
|
587
|
+
b as isSingleMatchRule,
|
|
588
|
+
x as isWildcardRule,
|
|
589
|
+
V as pathExists
|
|
591
590
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterEngine.d.ts","sourceRoot":"","sources":["../../../src/engine/FilterEngine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAOlB,MAAM,eAAe,CAAA;AAGtB;;;GAGG;AACH,qBAAa,YAAY;IACvB;;OAEG;
|
|
1
|
+
{"version":3,"file":"FilterEngine.d.ts","sourceRoot":"","sources":["../../../src/engine/FilterEngine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAOlB,MAAM,eAAe,CAAA;AAGtB;;;GAGG;AACH,qBAAa,YAAY;IACvB;;OAEG;IACH,OAAO,CAAC,OAAO,CAAC,CAGf;gBAEW,OAAO,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE;IAI1E;;;;;;OAMG;IAEH,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,eAAe,GAAG,iBAAiB;IAoC3E;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU;IAyClB;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;IA4BnB;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;IAwDzB;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAyEtB;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAqHtB;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;IAqDzB;;;OAGG;IAEH,OAAO,CAAC,SAAS;CAmClB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aikotools/datafilter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Advanced data filtering engine for JSON file matching in E2E testing",
|
|
5
5
|
"main": "dist/aikotools-datafilter.js",
|
|
6
6
|
"module": "dist/aikotools-datafilter.js",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/luxon": "^3.7.1",
|
|
41
|
-
"@types/node": "^
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
43
|
-
"@typescript-eslint/parser": "^
|
|
44
|
-
"@vitest/coverage-v8": "^
|
|
45
|
-
"eslint": "^
|
|
46
|
-
"prettier": "^3.
|
|
47
|
-
"typescript": "^5.
|
|
48
|
-
"vite": "^
|
|
49
|
-
"vite-plugin-dts": "^
|
|
50
|
-
"vitest": "^
|
|
41
|
+
"@types/node": "^24.9.1",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
43
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
44
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
45
|
+
"eslint": "^9.38.0",
|
|
46
|
+
"prettier": "^3.6.2",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vite": "^7.1.11",
|
|
49
|
+
"vite-plugin-dts": "^4.5.4",
|
|
50
|
+
"vitest": "^3.2.4"
|
|
51
51
|
}
|
|
52
52
|
}
|