@aikotools/datafilter 1.0.0
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/README.md +396 -0
- package/dist/aikotools-datafilter.mjs +591 -0
- package/dist/src/core/index.d.ts +5 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/types.d.ts +321 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/engine/FilterEngine.d.ts +84 -0
- package/dist/src/engine/FilterEngine.d.ts.map +1 -0
- package/dist/src/engine/index.d.ts +5 -0
- package/dist/src/engine/index.d.ts.map +1 -0
- package/dist/src/index.d.ts +48 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/matcher/Matcher.d.ts +64 -0
- package/dist/src/matcher/Matcher.d.ts.map +1 -0
- package/dist/src/matcher/index.d.ts +5 -0
- package/dist/src/matcher/index.d.ts.map +1 -0
- package/dist/src/utils/ObjectAccess.d.ts +72 -0
- package/dist/src/utils/ObjectAccess.d.ts.map +1 -0
- package/dist/src/utils/index.d.ts +5 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/license +9 -0
- package/package.json +52 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for the datafilter engine
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A single element in a path through a JSON structure.
|
|
6
|
+
* Can be a string for object properties or a number for array indices.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ['data', 'stations', 0, 'name'] → data.stations[0].name
|
|
10
|
+
*/
|
|
11
|
+
export type PathElement = string | number;
|
|
12
|
+
/**
|
|
13
|
+
* Time unit for time-based comparisons
|
|
14
|
+
*/
|
|
15
|
+
export type TimeUnit = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months' | 'years';
|
|
16
|
+
/**
|
|
17
|
+
* Check if a value matches an expected value (deep equality)
|
|
18
|
+
*/
|
|
19
|
+
export interface CheckValue {
|
|
20
|
+
value: any;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if a path exists in the object
|
|
24
|
+
*/
|
|
25
|
+
export interface CheckExists {
|
|
26
|
+
exists: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if an array contains (or doesn't contain) a specific item
|
|
30
|
+
*/
|
|
31
|
+
export interface CheckArrayElement {
|
|
32
|
+
itemExists: boolean;
|
|
33
|
+
item: any;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if an array has a specific size
|
|
37
|
+
*/
|
|
38
|
+
export interface CheckArraySize {
|
|
39
|
+
type: 'equal' | 'lessThan' | 'greaterThan';
|
|
40
|
+
size: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if a timestamp is within a time range
|
|
44
|
+
*/
|
|
45
|
+
export interface CheckTimeRange {
|
|
46
|
+
min: string;
|
|
47
|
+
max: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if a numeric value is within a numeric range
|
|
51
|
+
*/
|
|
52
|
+
export interface CheckNumericRange {
|
|
53
|
+
min: number;
|
|
54
|
+
max: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A single filter criterion that checks one aspect of the data
|
|
58
|
+
*/
|
|
59
|
+
export interface FilterCriterion {
|
|
60
|
+
/**
|
|
61
|
+
* Path to the value to check
|
|
62
|
+
*/
|
|
63
|
+
path: PathElement[];
|
|
64
|
+
/**
|
|
65
|
+
* The check to perform on the value
|
|
66
|
+
*/
|
|
67
|
+
check: CheckValue | CheckExists | CheckArrayElement | CheckArraySize | CheckTimeRange | CheckNumericRange;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A single match rule that defines how to match a file
|
|
71
|
+
*/
|
|
72
|
+
export interface SingleMatchRule {
|
|
73
|
+
/**
|
|
74
|
+
* Filter criteria - all must match (AND logic)
|
|
75
|
+
*/
|
|
76
|
+
match: FilterCriterion[];
|
|
77
|
+
/**
|
|
78
|
+
* Expected file name/identifier
|
|
79
|
+
*/
|
|
80
|
+
expected: string;
|
|
81
|
+
/**
|
|
82
|
+
* Whether this match is optional
|
|
83
|
+
*/
|
|
84
|
+
optional?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Additional metadata for reporting
|
|
87
|
+
*/
|
|
88
|
+
info?: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A wildcard match rule that can match multiple files
|
|
92
|
+
* NEW: Allows matching arbitrary number of optional files without explicit specification
|
|
93
|
+
*/
|
|
94
|
+
export interface WildcardMatchRule {
|
|
95
|
+
/**
|
|
96
|
+
* Filter criteria for wildcard matching
|
|
97
|
+
*/
|
|
98
|
+
matchAny: FilterCriterion[];
|
|
99
|
+
/**
|
|
100
|
+
* Whether to match greedily (as many as possible) or stop after first match
|
|
101
|
+
* Default: false (stop after first match)
|
|
102
|
+
*/
|
|
103
|
+
greedy?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Wildcard matches are always optional
|
|
106
|
+
*/
|
|
107
|
+
optional: true;
|
|
108
|
+
/**
|
|
109
|
+
* Additional metadata for reporting
|
|
110
|
+
*/
|
|
111
|
+
info?: Record<string, unknown>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A match rule can be either a single match or a wildcard match
|
|
115
|
+
*/
|
|
116
|
+
export type MatchRule = SingleMatchRule | WildcardMatchRule;
|
|
117
|
+
/**
|
|
118
|
+
* Type guard to check if a rule is a wildcard rule
|
|
119
|
+
*/
|
|
120
|
+
export declare function isWildcardRule(rule: MatchRule): rule is WildcardMatchRule;
|
|
121
|
+
/**
|
|
122
|
+
* Type guard to check if a rule is a single match rule
|
|
123
|
+
*/
|
|
124
|
+
export declare function isSingleMatchRule(rule: MatchRule): rule is SingleMatchRule;
|
|
125
|
+
/**
|
|
126
|
+
* A group of rules with common filter criteria
|
|
127
|
+
* NEW: Allows hierarchical filtering where a group of files shares common properties
|
|
128
|
+
*/
|
|
129
|
+
export interface FilterGroup {
|
|
130
|
+
/**
|
|
131
|
+
* Common filter criteria that all files in this group must match
|
|
132
|
+
* These are checked before evaluating individual rules
|
|
133
|
+
*/
|
|
134
|
+
groupFilter: FilterCriterion[];
|
|
135
|
+
/**
|
|
136
|
+
* Rules to apply to files that match the group filter
|
|
137
|
+
*/
|
|
138
|
+
rules: MatchRule[];
|
|
139
|
+
/**
|
|
140
|
+
* Additional metadata for reporting
|
|
141
|
+
*/
|
|
142
|
+
info?: Record<string, unknown>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* A file to be filtered
|
|
146
|
+
*/
|
|
147
|
+
export interface JsonFile {
|
|
148
|
+
/**
|
|
149
|
+
* File name or identifier
|
|
150
|
+
*/
|
|
151
|
+
fileName: string;
|
|
152
|
+
/**
|
|
153
|
+
* The JSON data
|
|
154
|
+
*/
|
|
155
|
+
data: any;
|
|
156
|
+
/**
|
|
157
|
+
* Optional metadata
|
|
158
|
+
*/
|
|
159
|
+
metadata?: Record<string, unknown>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Result of filtering a single file against a criterion
|
|
163
|
+
*/
|
|
164
|
+
export interface FilterCheckResult {
|
|
165
|
+
/**
|
|
166
|
+
* Whether the check passed
|
|
167
|
+
*/
|
|
168
|
+
status: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* The check that was performed
|
|
171
|
+
*/
|
|
172
|
+
checkType: string;
|
|
173
|
+
/**
|
|
174
|
+
* Reason for failure (if status is false)
|
|
175
|
+
*/
|
|
176
|
+
reason?: string | Record<string, unknown>;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Result of matching a file against a rule
|
|
180
|
+
*/
|
|
181
|
+
export interface MatchResult {
|
|
182
|
+
/**
|
|
183
|
+
* Whether all criteria matched
|
|
184
|
+
*/
|
|
185
|
+
matched: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Individual check results
|
|
188
|
+
*/
|
|
189
|
+
checks: FilterCheckResult[];
|
|
190
|
+
/**
|
|
191
|
+
* The rule that was tested
|
|
192
|
+
*/
|
|
193
|
+
rule: MatchRule;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* A mapped file with its expected identifier
|
|
197
|
+
*/
|
|
198
|
+
export interface MappedFile {
|
|
199
|
+
/**
|
|
200
|
+
* Expected identifier
|
|
201
|
+
*/
|
|
202
|
+
expected: string;
|
|
203
|
+
/**
|
|
204
|
+
* The actual file that was matched
|
|
205
|
+
*/
|
|
206
|
+
file: JsonFile;
|
|
207
|
+
/**
|
|
208
|
+
* Match result details
|
|
209
|
+
*/
|
|
210
|
+
matchResult: MatchResult;
|
|
211
|
+
/**
|
|
212
|
+
* Optional flag from the rule
|
|
213
|
+
*/
|
|
214
|
+
optional: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Additional info from the rule
|
|
217
|
+
*/
|
|
218
|
+
info?: Record<string, unknown>;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* A wildcard-matched file (matched via matchAny)
|
|
222
|
+
*/
|
|
223
|
+
export interface WildcardMappedFile {
|
|
224
|
+
/**
|
|
225
|
+
* The file that was matched
|
|
226
|
+
*/
|
|
227
|
+
file: JsonFile;
|
|
228
|
+
/**
|
|
229
|
+
* Match result details
|
|
230
|
+
*/
|
|
231
|
+
matchResult: MatchResult;
|
|
232
|
+
/**
|
|
233
|
+
* Additional info from the rule
|
|
234
|
+
*/
|
|
235
|
+
info?: Record<string, unknown>;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* An unmapped file that didn't match any rule
|
|
239
|
+
*/
|
|
240
|
+
export interface UnmappedFile {
|
|
241
|
+
/**
|
|
242
|
+
* The file that couldn't be matched
|
|
243
|
+
*/
|
|
244
|
+
file: JsonFile;
|
|
245
|
+
/**
|
|
246
|
+
* All rules that were tried
|
|
247
|
+
*/
|
|
248
|
+
attemptedRules: MatchResult[];
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Result of the entire filtering operation
|
|
252
|
+
*/
|
|
253
|
+
export interface FilterResult {
|
|
254
|
+
/**
|
|
255
|
+
* Successfully mapped files (expected identifier → actual file)
|
|
256
|
+
*/
|
|
257
|
+
mapped: MappedFile[];
|
|
258
|
+
/**
|
|
259
|
+
* Files matched by wildcard rules
|
|
260
|
+
*/
|
|
261
|
+
wildcardMatched: WildcardMappedFile[];
|
|
262
|
+
/**
|
|
263
|
+
* Files that couldn't be matched to any rule
|
|
264
|
+
*/
|
|
265
|
+
unmapped: UnmappedFile[];
|
|
266
|
+
/**
|
|
267
|
+
* Statistics
|
|
268
|
+
*/
|
|
269
|
+
stats: {
|
|
270
|
+
totalFiles: number;
|
|
271
|
+
mappedFiles: number;
|
|
272
|
+
wildcardMatchedFiles: number;
|
|
273
|
+
unmappedFiles: number;
|
|
274
|
+
totalRules: number;
|
|
275
|
+
mandatoryRules: number;
|
|
276
|
+
optionalRules: number;
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Request for filtering files
|
|
281
|
+
*/
|
|
282
|
+
export interface FilterRequest {
|
|
283
|
+
/**
|
|
284
|
+
* Files to be filtered
|
|
285
|
+
*/
|
|
286
|
+
files: JsonFile[];
|
|
287
|
+
/**
|
|
288
|
+
* Matching rules in order (flat structure)
|
|
289
|
+
* Can be a single rule or an array of rules (for flexible ordering)
|
|
290
|
+
* Either 'rules' or 'groups' should be provided, not both
|
|
291
|
+
*/
|
|
292
|
+
rules?: (MatchRule | MatchRule[])[];
|
|
293
|
+
/**
|
|
294
|
+
* Grouped rules with common filter criteria (hierarchical structure)
|
|
295
|
+
* Either 'rules' or 'groups' should be provided, not both
|
|
296
|
+
* NEW: Allows organizing rules by common criteria (e.g., by line number, event type)
|
|
297
|
+
*/
|
|
298
|
+
groups?: FilterGroup[];
|
|
299
|
+
/**
|
|
300
|
+
* Sort function for ordering files before matching
|
|
301
|
+
* @param a - First file
|
|
302
|
+
* @param b - Second file
|
|
303
|
+
* @returns Negative if a < b, positive if a > b, zero if equal
|
|
304
|
+
*/
|
|
305
|
+
sortFn?: (a: JsonFile, b: JsonFile) => number;
|
|
306
|
+
/**
|
|
307
|
+
* Optional pre-filter criteria that all files must match before rule/group matching
|
|
308
|
+
* Files that don't match the pre-filter are excluded entirely (not added to unmapped)
|
|
309
|
+
* Applied before group filters
|
|
310
|
+
*/
|
|
311
|
+
preFilter?: FilterCriterion[];
|
|
312
|
+
/**
|
|
313
|
+
* Optional context for time-based filtering
|
|
314
|
+
*/
|
|
315
|
+
context?: {
|
|
316
|
+
startTimeScript?: string;
|
|
317
|
+
startTimeTest?: string;
|
|
318
|
+
pathTime?: PathElement[];
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAA;AAEzC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,cAAc,GACd,SAAS,GACT,SAAS,GACT,OAAO,GACP,MAAM,GACN,OAAO,GACP,QAAQ,GACR,OAAO,CAAA;AAEX;;GAEG;AACH,MAAM,WAAW,UAAU;IAEzB,KAAK,EAAE,GAAG,CAAA;CACX;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,OAAO,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,OAAO,CAAA;IAEnB,IAAI,EAAE,GAAG,CAAA;CACV;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,aAAa,CAAA;IAC1C,IAAI,EAAE,MAAM,CAAA;CACb;AAED;;GAEG;AACH,M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Result } from '../core/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Filter engine that evaluates filter criteria against data objects.
|
|
5
|
+
* Provides various check methods for different types of comparisons.
|
|
6
|
+
*/
|
|
7
|
+
export declare class FilterEngine {
|
|
8
|
+
/**
|
|
9
|
+
* Context for time-based filtering
|
|
10
|
+
*/
|
|
11
|
+
private context?;
|
|
12
|
+
constructor(context?: {
|
|
13
|
+
startTimeScript?: string;
|
|
14
|
+
startTimeTest?: string;
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Evaluates a single filter criterion against a data object.
|
|
18
|
+
*
|
|
19
|
+
* @param data - The data object to check
|
|
20
|
+
* @param criterion - The filter criterion to evaluate
|
|
21
|
+
* @returns FilterCheckResult indicating success or failure
|
|
22
|
+
*/
|
|
23
|
+
evaluateCriterion(data: any, criterion: FilterCriterion): FilterCheckResult;
|
|
24
|
+
/**
|
|
25
|
+
* Checks if a value matches an expected value using deep equality.
|
|
26
|
+
*
|
|
27
|
+
* @param data - The data object
|
|
28
|
+
* @param path - Path to the value
|
|
29
|
+
* @param check - The value check specification
|
|
30
|
+
* @returns FilterCheckResult
|
|
31
|
+
*/
|
|
32
|
+
private checkValue;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a path exists in the data object.
|
|
35
|
+
*
|
|
36
|
+
* @param data - The data object
|
|
37
|
+
* @param path - Path to check
|
|
38
|
+
* @param check - The exists check specification
|
|
39
|
+
* @returns FilterCheckResult
|
|
40
|
+
*/
|
|
41
|
+
private checkExists;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if an array contains (or doesn't contain) a specific element.
|
|
44
|
+
*
|
|
45
|
+
* @param data - The data object
|
|
46
|
+
* @param path - Path to the array
|
|
47
|
+
* @param check - The array element check specification
|
|
48
|
+
* @returns FilterCheckResult
|
|
49
|
+
*/
|
|
50
|
+
private checkArrayElement;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if an array has the expected size.
|
|
53
|
+
*
|
|
54
|
+
* @param data - The data object
|
|
55
|
+
* @param path - Path to the array
|
|
56
|
+
* @param check - The array size check specification
|
|
57
|
+
* @returns FilterCheckResult
|
|
58
|
+
*/
|
|
59
|
+
private checkArraySize;
|
|
60
|
+
/**
|
|
61
|
+
* Checks if a timestamp is within the expected time range.
|
|
62
|
+
*
|
|
63
|
+
* @param data - The data object
|
|
64
|
+
* @param path - Path to the timestamp
|
|
65
|
+
* @param check - The time range check specification
|
|
66
|
+
* @returns FilterCheckResult
|
|
67
|
+
*/
|
|
68
|
+
private checkTimeRange;
|
|
69
|
+
/**
|
|
70
|
+
* Checks if a numeric value is within the expected range.
|
|
71
|
+
*
|
|
72
|
+
* @param data - The data object
|
|
73
|
+
* @param path - Path to the numeric value
|
|
74
|
+
* @param check - The numeric range check specification
|
|
75
|
+
* @returns FilterCheckResult
|
|
76
|
+
*/
|
|
77
|
+
private checkNumericRange;
|
|
78
|
+
/**
|
|
79
|
+
* Deep equality comparison.
|
|
80
|
+
* Compares two values recursively for equality.
|
|
81
|
+
*/
|
|
82
|
+
private deepEqual;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=FilterEngine.d.ts.map
|
|
@@ -0,0 +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;IAEH,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/engine/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { FilterRequest, FilterResult } from './core/types';
|
|
2
|
+
/**
|
|
3
|
+
* @aikotools/datafilter
|
|
4
|
+
*
|
|
5
|
+
* Advanced data filtering engine for JSON file matching in E2E testing
|
|
6
|
+
*/
|
|
7
|
+
export type { PathElement, TimeUnit, CheckValue, CheckExists, CheckArrayElement, CheckArraySize, CheckTimeRange, CheckNumericRange, FilterCriterion, SingleMatchRule, WildcardMatchRule, MatchRule, FilterGroup, JsonFile, FilterCheckResult, MatchResult, MappedFile, WildcardMappedFile, UnmappedFile, FilterResult, FilterRequest, } from './core/types';
|
|
8
|
+
export { isWildcardRule, isSingleMatchRule } from './core/types';
|
|
9
|
+
export { FilterEngine } from './engine';
|
|
10
|
+
export { Matcher } from './matcher';
|
|
11
|
+
export { getValueFromPath, pathExists, getValueOr } from './utils';
|
|
12
|
+
export type { AccessResult } from './utils';
|
|
13
|
+
/**
|
|
14
|
+
* Convenience function for filtering files with a single call.
|
|
15
|
+
* Creates a Matcher instance and performs the filtering operation.
|
|
16
|
+
*
|
|
17
|
+
* @param request - Filter request containing files, rules/groups, sort function, and context
|
|
18
|
+
* @returns FilterResult with mapped, wildcardMatched, and unmapped files
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Using flat rules structure
|
|
23
|
+
* const result = filterFiles({
|
|
24
|
+
* files: jsonFiles,
|
|
25
|
+
* rules: [
|
|
26
|
+
* { match: [{path: ['type'], check: {value: 'event1'}}], expected: 'event1.json' },
|
|
27
|
+
* { matchAny: [{path: ['optional'], check: {exists: true}}], optional: true, greedy: true },
|
|
28
|
+
* { match: [{path: ['type'], check: {value: 'event2'}}], expected: 'event2.json' }
|
|
29
|
+
* ],
|
|
30
|
+
* sortFn: (a, b) => a.data.timestamp - b.data.timestamp
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Using grouped structure
|
|
34
|
+
* const result = filterFiles({
|
|
35
|
+
* files: jsonFiles,
|
|
36
|
+
* preFilter: [{path: ['eventType'], check: {value: 'RiFahrt'}}],
|
|
37
|
+
* groups: [
|
|
38
|
+
* {
|
|
39
|
+
* groupFilter: [{path: ['linie'], check: {value: '88888'}}],
|
|
40
|
+
* rules: [...]
|
|
41
|
+
* }
|
|
42
|
+
* ],
|
|
43
|
+
* sortFn: (a, b) => a.data.timestamp - b.data.timestamp
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function filterFiles(request: FilterRequest): FilterResult;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,WAAW,EACX,QAAQ,EACR,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,aAAa,GACd,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAGvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAClE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAI3C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CA4BhE"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { JsonFile, MatchRule, FilterResult, MatchResult, FilterCriterion, FilterGroup } from '../core/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Matcher system that matches files against rules.
|
|
5
|
+
* Supports single matches, flexible ordering, and wildcard matches.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Matcher {
|
|
8
|
+
private engine;
|
|
9
|
+
constructor(context?: {
|
|
10
|
+
startTimeScript?: string;
|
|
11
|
+
startTimeTest?: string;
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Matches a single file against a rule.
|
|
15
|
+
*
|
|
16
|
+
* @param file - The file to match
|
|
17
|
+
* @param rule - The rule to match against
|
|
18
|
+
* @returns MatchResult indicating if all criteria matched
|
|
19
|
+
*/
|
|
20
|
+
matchFile(file: JsonFile, rule: MatchRule): MatchResult;
|
|
21
|
+
/**
|
|
22
|
+
* Applies pre-filter criteria to files, returning only files that match all criteria.
|
|
23
|
+
*
|
|
24
|
+
* @param files - Files to filter
|
|
25
|
+
* @param preFilter - Filter criteria that all files must match
|
|
26
|
+
* @returns Filtered files that match all preFilter criteria
|
|
27
|
+
*/
|
|
28
|
+
private applyPreFilter;
|
|
29
|
+
/**
|
|
30
|
+
* Main filtering function that processes files according to rules.
|
|
31
|
+
*
|
|
32
|
+
* @param files - Files to filter
|
|
33
|
+
* @param rules - Matching rules (can include arrays for flexible ordering)
|
|
34
|
+
* @param sortFn - Optional sort function for file ordering
|
|
35
|
+
* @param preFilter - Optional pre-filter criteria (files not matching are excluded)
|
|
36
|
+
* @returns FilterResult with mapped, wildcardMatched, and unmapped files
|
|
37
|
+
*/
|
|
38
|
+
filterFiles(files: JsonFile[], rules: (MatchRule | MatchRule[])[], sortFn?: (a: JsonFile, b: JsonFile) => number, preFilter?: FilterCriterion[]): FilterResult;
|
|
39
|
+
/**
|
|
40
|
+
* Counts total number of rules (flattening arrays)
|
|
41
|
+
*/
|
|
42
|
+
private countRules;
|
|
43
|
+
/**
|
|
44
|
+
* Counts mandatory rules
|
|
45
|
+
*/
|
|
46
|
+
private countMandatoryRules;
|
|
47
|
+
/**
|
|
48
|
+
* Counts optional rules
|
|
49
|
+
*/
|
|
50
|
+
private countOptionalRules;
|
|
51
|
+
/**
|
|
52
|
+
* Filtering function for grouped rules with common filter criteria.
|
|
53
|
+
* Files are first filtered by preFilter (if provided), then matched against
|
|
54
|
+
* group filters, and finally processed by the group's rules.
|
|
55
|
+
*
|
|
56
|
+
* @param files - Files to filter
|
|
57
|
+
* @param groups - Filter groups with common criteria and rules
|
|
58
|
+
* @param sortFn - Optional sort function for file ordering
|
|
59
|
+
* @param preFilter - Optional pre-filter criteria (files not matching are excluded)
|
|
60
|
+
* @returns FilterResult with mapped, wildcardMatched, and unmapped files
|
|
61
|
+
*/
|
|
62
|
+
filterFilesWithGroups(files: JsonFile[], groups: FilterGroup[], sortFn?: (a: JsonFile, b: JsonFile) => number, preFilter?: FilterCriterion[]): FilterResult;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=Matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Matcher.d.ts","sourceRoot":"","sources":["../../../src/matcher/Matcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,YAAY,EAIZ,WAAW,EACX,eAAe,EACf,WAAW,EACZ,MAAM,eAAe,CAAA;AAItB;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,MAAM,CAAc;gBAEhB,OAAO,CAAC,EAAE;QAAE,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE;IAI1E;;;;;;OAMG;IACH,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,WAAW;IAgBvD;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IAStB;;;;;;;;OAQG;IACH,WAAW,CACT,KAAK,EAAE,QAAQ,EAAE,EACjB,KAAK,EAAE,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC,EAAE,EAClC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,KAAK,MAAM,EAC7C,SAAS,CAAC,EAAE,eAAe,EAAE,GAC5B,YAAY;IAuKf;;OAEG;IACH,OAAO,CAAC,UAAU;IASlB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAS1B;;;;;;;;;;OAUG;IACH,qBAAqB,CACnB,KAAK,EAAE,QAAQ,EAAE,EACjB,MAAM,EAAE,WAAW,EAAE,EACrB,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,KAAK,MAAM,EAC7C,SAAS,CAAC,EAAE,eAAe,EAAE,GAC5B,YAAY;CA+DhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/matcher/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { PathElement } from '../core/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result of accessing a value from an object
|
|
5
|
+
*/
|
|
6
|
+
export interface AccessResult {
|
|
7
|
+
/**
|
|
8
|
+
* The value found at the path (undefined if not found)
|
|
9
|
+
*/
|
|
10
|
+
value: any;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the path was successfully resolved
|
|
13
|
+
*/
|
|
14
|
+
found: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Error message if path couldn't be resolved
|
|
17
|
+
*/
|
|
18
|
+
error?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The portion of the path that was successfully resolved
|
|
21
|
+
*/
|
|
22
|
+
validPath: PathElement[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves a value from an object following the specified path.
|
|
26
|
+
* Supports nested objects and arrays.
|
|
27
|
+
*
|
|
28
|
+
* @param object - The object to access
|
|
29
|
+
* @param path - Array of property names and array indices
|
|
30
|
+
* @returns AccessResult containing the value and status
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const obj = { data: { stations: [{ name: 'Berlin' }, { name: 'Munich' }] } };
|
|
35
|
+
* const result = getValueFromPath(obj, ['data', 'stations', 1, 'name']);
|
|
36
|
+
* // result.value === 'Munich'
|
|
37
|
+
* // result.found === true
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function getValueFromPath(object: any, path: PathElement[]): AccessResult;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a path exists in an object.
|
|
43
|
+
*
|
|
44
|
+
* @param object - The object to check
|
|
45
|
+
* @param path - Array of property names and array indices
|
|
46
|
+
* @returns true if the path exists and has a defined value
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const obj = { data: { value: 42 } };
|
|
51
|
+
* pathExists(obj, ['data', 'value']); // true
|
|
52
|
+
* pathExists(obj, ['data', 'missing']); // false
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function pathExists(object: any, path: PathElement[]): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Gets a value from an object with a default fallback.
|
|
58
|
+
*
|
|
59
|
+
* @param object - The object to access
|
|
60
|
+
* @param path - Array of property names and array indices
|
|
61
|
+
* @param defaultValue - Value to return if path doesn't exist
|
|
62
|
+
* @returns The value at the path, or defaultValue if not found
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const obj = { data: { value: 42 } };
|
|
67
|
+
* getValueOr(obj, ['data', 'value'], 0); // 42
|
|
68
|
+
* getValueOr(obj, ['data', 'missing'], 0); // 0
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function getValueOr<T>(object: any, path: PathElement[], defaultValue: T): T;
|
|
72
|
+
//# sourceMappingURL=ObjectAccess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectAccess.d.ts","sourceRoot":"","sources":["../../../src/utils/ObjectAccess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IAEH,KAAK,EAAE,GAAG,CAAA;IAEV;;OAEG;IACH,KAAK,EAAE,OAAO,CAAA;IAEd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,SAAS,EAAE,WAAW,EAAE,CAAA;CACzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAE9B,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,WAAW,EAAE,GAClB,YAAY,CAwFd;AAED;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,OAAO,CAGpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAE1B,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,WAAW,EAAE,EACnB,YAAY,EAAE,CAAC,GACd,CAAC,CAGH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAA"}
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Torsten Link <torstenlink@gmx.de> (https://nanook.io)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|