@webda/cloudevents 3.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.
Files changed (35) hide show
  1. package/LICENSE +166 -0
  2. package/lib/filters/abstract.d.ts +28 -0
  3. package/lib/filters/abstract.js +17 -0
  4. package/lib/filters/abstract.js.map +1 -0
  5. package/lib/filters/index.d.ts +14 -0
  6. package/lib/filters/index.js +34 -0
  7. package/lib/filters/index.js.map +1 -0
  8. package/lib/filters/interfaces.d.ts +0 -0
  9. package/lib/filters/interfaces.js +1 -0
  10. package/lib/filters/interfaces.js.map +1 -0
  11. package/lib/filters/logical.d.ts +54 -0
  12. package/lib/filters/logical.js +49 -0
  13. package/lib/filters/logical.js.map +1 -0
  14. package/lib/filters/sql/CESQLParserLexer.d.ts +55 -0
  15. package/lib/filters/sql/CESQLParserLexer.js +293 -0
  16. package/lib/filters/sql/CESQLParserLexer.js.map +1 -0
  17. package/lib/filters/sql/CESQLParserListener.d.ts +325 -0
  18. package/lib/filters/sql/CESQLParserListener.js +3 -0
  19. package/lib/filters/sql/CESQLParserListener.js.map +1 -0
  20. package/lib/filters/sql/CESQLParserParser.d.ts +313 -0
  21. package/lib/filters/sql/CESQLParserParser.js +1825 -0
  22. package/lib/filters/sql/CESQLParserParser.js.map +1 -0
  23. package/lib/filters/sql/CESQLParserVisitor.d.ts +208 -0
  24. package/lib/filters/sql/CESQLParserVisitor.js +3 -0
  25. package/lib/filters/sql/CESQLParserVisitor.js.map +1 -0
  26. package/lib/filters/sql.d.ts +426 -0
  27. package/lib/filters/sql.js +752 -0
  28. package/lib/filters/sql.js.map +1 -0
  29. package/lib/filters/string.d.ts +105 -0
  30. package/lib/filters/string.js +79 -0
  31. package/lib/filters/string.js.map +1 -0
  32. package/lib/subscription.d.ts +228 -0
  33. package/lib/subscription.js +60 -0
  34. package/lib/subscription.js.map +1 -0
  35. package/package.json +61 -0
@@ -0,0 +1,426 @@
1
+ import { AbstractParseTreeVisitor } from "antlr4ts/tree.js";
2
+ import { CloudEvent } from "cloudevents";
3
+ import { Filter, FilterImplementation } from "./abstract.js";
4
+ import { CESQLParserLexer } from "./sql/CESQLParserLexer.js";
5
+ import { BinaryAdditiveExpressionContext, BinaryComparisonExpressionContext, BinaryLogicExpressionContext, BinaryMultiplicativeExpressionContext, BooleanLiteralContext, CesqlContext, ExistsExpressionContext, FunctionInvocationExpressionContext, FunctionParameterListContext, IdentifierContext, InExpressionContext, IntegerLiteralContext, LikeExpressionContext, SetExpressionContext, StringLiteralContext, SubExpressionContext, UnaryLogicExpressionContext, UnaryNumericExpressionContext } from "./sql/CESQLParserParser.js";
6
+ import { CESQLParserVisitor } from "./sql/CESQLParserVisitor.js";
7
+ /**
8
+ * Use of this MUST have a string value, representing a CloudEvents SQL Expression.
9
+ * The filter result MUST be true if the result value of the expression, coerced to boolean,
10
+ * equals to the TRUE boolean value, otherwise MUST be false if an error occurred while
11
+ * evaluating the expression or if the result value, coerced to boolean, equals to the FALSE
12
+ * boolean value.
13
+ *
14
+ * Implementations SHOULD reject subscriptions with invalid CloudEvents SQL expressions.
15
+ */
16
+ export interface SqlFilter {
17
+ sql: string;
18
+ }
19
+ /**
20
+ * Function name defined by the specification
21
+ */
22
+ type FunctionName = "ABS" | "LENGTH" | "CONCAT" | "CONCAT_WS" | "LOWER" | "UPPER" | "LEFT" | "RIGHT" | "TRIM" | "BOOL" | "INT" | "SUBSTRING" | "STRING" | "IS_BOOL" | "IS_INT";
23
+ /**
24
+ * Functions implementation
25
+ */
26
+ declare const functions: {
27
+ [key in FunctionName]: (...args: any[]) => any;
28
+ };
29
+ /**
30
+ * Represent the query expression or subset
31
+ */
32
+ export declare abstract class Expression {
33
+ protected deps: Expression[];
34
+ constructor();
35
+ /**
36
+ * Evaluate the expression for the target object
37
+ * @param target to evaluate
38
+ */
39
+ abstract eval(target: any): any;
40
+ /**
41
+ * Return the representation of the expression
42
+ */
43
+ abstract toString(): string;
44
+ /**
45
+ * Resolve the expression if possible
46
+ *
47
+ * If the expression only contains static values then it can be resolved
48
+ * @returns
49
+ */
50
+ resolve(): Expression;
51
+ }
52
+ /**
53
+ * Represent an attribute expression
54
+ */
55
+ export declare class AttributeExpression extends Expression {
56
+ readonly attribute: string;
57
+ constructor(attribute: string);
58
+ /**
59
+ * @override
60
+ */
61
+ eval(target: any): any;
62
+ /**
63
+ * @override
64
+ */
65
+ toString(): string;
66
+ }
67
+ /**
68
+ * Represent a function expression
69
+ */
70
+ export declare class FunctionExpression extends Expression {
71
+ readonly functionName: keyof typeof functions;
72
+ readonly args: Expression[];
73
+ /**
74
+ *
75
+ * @param functionName to execute
76
+ * @param args to call with the function
77
+ */
78
+ constructor(functionName: keyof typeof functions, ...args: Expression[]);
79
+ /**
80
+ * @override
81
+ */
82
+ eval(target: any): any;
83
+ /**
84
+ * @override
85
+ */
86
+ toString(): string;
87
+ }
88
+ /**
89
+ * Represent a unary logic expression
90
+ */
91
+ export declare class UnaryLogicExpression extends Expression {
92
+ readonly child: Expression;
93
+ /**
94
+ * Invert the result of the child expression
95
+ * @param child
96
+ */
97
+ constructor(child: Expression);
98
+ /**
99
+ * @override
100
+ */
101
+ eval(target: any): boolean;
102
+ /**
103
+ * @override
104
+ */
105
+ toString(): string;
106
+ }
107
+ /**
108
+ * Represent a unary numeric expression
109
+ */
110
+ export declare class UnaryNumericExpression extends Expression {
111
+ readonly child: Expression;
112
+ /**
113
+ * Negative the result of the child expression
114
+ * @param child
115
+ */
116
+ constructor(child: Expression);
117
+ /**
118
+ * @override
119
+ */
120
+ eval(target: any): number;
121
+ /**
122
+ * @override
123
+ */
124
+ toString(): string;
125
+ }
126
+ /**
127
+ * Represent a LIKE expression
128
+ */
129
+ export declare class LikeExpression extends Expression {
130
+ readonly left: Expression;
131
+ readonly right: string;
132
+ readonly invert: boolean;
133
+ regexp: RegExp;
134
+ /**
135
+ *
136
+ * @param left part of the expression
137
+ * @param right part of the expression the regexp with % and _
138
+ * @param invert if NOT LIKE is used
139
+ */
140
+ constructor(left: Expression, right: string, invert: boolean);
141
+ /**
142
+ * @override
143
+ */
144
+ eval(target: any): boolean;
145
+ /**
146
+ * @override
147
+ */
148
+ toString(): string;
149
+ }
150
+ /**
151
+ * Represent a EXISTS expression
152
+ */
153
+ export declare class ExistsExpression extends Expression {
154
+ readonly property: string;
155
+ /**
156
+ *
157
+ * @param property to check
158
+ */
159
+ constructor(property: string);
160
+ /**
161
+ * @override
162
+ */
163
+ eval(target: any): boolean;
164
+ /**
165
+ * @override
166
+ */
167
+ toString(): string;
168
+ }
169
+ /**
170
+ * Represent a IN expression
171
+ */
172
+ export declare class InExpression extends Expression {
173
+ readonly left: Expression;
174
+ readonly right: Expression[];
175
+ readonly invert: boolean;
176
+ staticContent: any[];
177
+ /**
178
+ *
179
+ * @param left part of the expression
180
+ * @param right part of the expression
181
+ * @param invert if NOT IN
182
+ */
183
+ constructor(left: Expression, right: Expression[], invert?: boolean);
184
+ /**
185
+ * @override
186
+ */
187
+ eval(target: any): boolean;
188
+ /**
189
+ * @override
190
+ */
191
+ toString(): string;
192
+ }
193
+ /**
194
+ * Represent a binary multiplicative expression
195
+ */
196
+ export declare class BinaryMultiplicativeExpression extends Expression {
197
+ readonly left: Expression;
198
+ readonly right: Expression;
199
+ readonly operator: "*" | "/" | "%";
200
+ /**
201
+ *
202
+ * @param left part of the expression
203
+ * @param right part of the expression
204
+ * @param operator
205
+ */
206
+ constructor(left: Expression, right: Expression, operator: "*" | "/" | "%");
207
+ /**
208
+ * @override
209
+ */
210
+ eval(target: any): number;
211
+ /**
212
+ * @override
213
+ */
214
+ toString(): string;
215
+ }
216
+ /**
217
+ * Represent a binary additive expression
218
+ */
219
+ export declare class BinaryAdditiveExpression extends Expression {
220
+ readonly left: Expression;
221
+ readonly right: Expression;
222
+ readonly operator: "+" | "-";
223
+ /**
224
+ *
225
+ * @param left part of the expression
226
+ * @param right part of the expression
227
+ * @param operator
228
+ */
229
+ constructor(left: Expression, right: Expression, operator: "+" | "-");
230
+ /**
231
+ * @override
232
+ */
233
+ eval(target: any): any;
234
+ /**
235
+ * @override
236
+ */
237
+ toString(): string;
238
+ }
239
+ /**
240
+ * Represent a binary comparison expression
241
+ */
242
+ export declare class BinaryComparisonExpression extends Expression {
243
+ readonly left: Expression;
244
+ readonly right: Expression;
245
+ readonly operator: ">" | "<" | ">=" | "<=" | "!=" | "=";
246
+ /**
247
+ *
248
+ * @param left part of the expression
249
+ * @param right part of the expression
250
+ * @param operator to use
251
+ */
252
+ constructor(left: Expression, right: Expression, operator: ">" | "<" | ">=" | "<=" | "!=" | "=");
253
+ /**
254
+ * @override
255
+ */
256
+ eval(target: any): boolean;
257
+ /**
258
+ * @override
259
+ */
260
+ toString(): string;
261
+ }
262
+ /**
263
+ * Represent a binary logic expression
264
+ */
265
+ export declare class BinaryLogicExpression extends Expression {
266
+ readonly left: Expression;
267
+ readonly right: Expression;
268
+ readonly operator: "AND" | "OR" | "XOR";
269
+ /**
270
+ *
271
+ * @param left part of the expression
272
+ * @param right part of the expression
273
+ * @param operator to use
274
+ */
275
+ constructor(left: Expression, right: Expression, operator: "AND" | "OR" | "XOR");
276
+ /**
277
+ * @override
278
+ */
279
+ eval(target: any): any;
280
+ /**
281
+ * @override
282
+ */
283
+ toString(): string;
284
+ }
285
+ /**
286
+ * Represent a value expression
287
+ */
288
+ export declare class ValueExpression extends Expression {
289
+ readonly value: any;
290
+ /**
291
+ * Value represented by the expression
292
+ * @param value
293
+ */
294
+ constructor(value: any);
295
+ /**
296
+ * @override
297
+ */
298
+ eval(target: any): any;
299
+ /**
300
+ * @override
301
+ */
302
+ toString(): string;
303
+ }
304
+ /**
305
+ * Create Expression based on the parsed token
306
+ *
307
+ * Expression allow to optimize and split between Query and Filter
308
+ */
309
+ export declare class CESQLExpressionBuilder extends AbstractParseTreeVisitor<Expression> implements CESQLParserVisitor<any> {
310
+ /**
311
+ * By default accepting it
312
+ * @returns
313
+ */
314
+ protected defaultResult(): ValueExpression;
315
+ /**
316
+ * @override
317
+ */
318
+ visitCesql(ctx: CesqlContext): Expression;
319
+ /**
320
+ * @override
321
+ */
322
+ visitFunctionInvocationExpression(ctx: FunctionInvocationExpressionContext): Expression;
323
+ /**
324
+ * @override
325
+ */
326
+ visitUnaryLogicExpression(ctx: UnaryLogicExpressionContext): Expression;
327
+ /**
328
+ * @override
329
+ */
330
+ visitUnaryNumericExpression(ctx: UnaryNumericExpressionContext): Expression;
331
+ /**
332
+ * @override
333
+ */
334
+ visitLikeExpression(ctx: LikeExpressionContext): Expression;
335
+ /**
336
+ * @override
337
+ */
338
+ visitExistsExpression(ctx: ExistsExpressionContext): Expression;
339
+ /**
340
+ * @override
341
+ */
342
+ visitInExpression(ctx: InExpressionContext): Expression;
343
+ /**
344
+ * @override
345
+ */
346
+ visitBinaryMultiplicativeExpression(ctx: BinaryMultiplicativeExpressionContext): Expression;
347
+ /**
348
+ * @override
349
+ */
350
+ visitBinaryAdditiveExpression(ctx: BinaryAdditiveExpressionContext): Expression;
351
+ /**
352
+ * Retrieve the children results
353
+ * @param ctx
354
+ * @returns
355
+ */
356
+ getChildrenResults(ctx: any): any;
357
+ /**
358
+ *
359
+ * @param ctx
360
+ * @returns
361
+ */
362
+ visitBinaryComparisonExpression(ctx: BinaryComparisonExpressionContext): Expression;
363
+ /**
364
+ * @override
365
+ */
366
+ visitBinaryLogicExpression(ctx: BinaryLogicExpressionContext): Expression;
367
+ /**
368
+ * @override
369
+ */
370
+ visitSubExpression(ctx: SubExpressionContext): Expression;
371
+ /**
372
+ * @override
373
+ */
374
+ visitIdentifier(ctx: IdentifierContext): any;
375
+ /**
376
+ * @override
377
+ */
378
+ visitBooleanLiteral(ctx: BooleanLiteralContext): Expression;
379
+ /**
380
+ * @override
381
+ */
382
+ visitStringLiteral(ctx: StringLiteralContext): Expression;
383
+ /**
384
+ * @override
385
+ */
386
+ visitIntegerLiteral(ctx: IntegerLiteralContext): Expression;
387
+ /**
388
+ * @override
389
+ */
390
+ visitFunctionParameterList(ctx: FunctionParameterListContext): Expression[];
391
+ /**
392
+ * @override
393
+ */
394
+ visitSetExpression(ctx: SetExpressionContext): any[];
395
+ }
396
+ /**
397
+ * SQL Filter implementation
398
+ */
399
+ export declare class SqlFilterImplementation extends FilterImplementation<SqlFilter> {
400
+ lexer: CESQLParserLexer;
401
+ tree: any;
402
+ query: Expression;
403
+ /**
404
+ *
405
+ * @param definition {sql: "CESQL Expression"}
406
+ */
407
+ constructor(definition: SqlFilter);
408
+ /**
409
+ * Check if a cloudevent match the filter
410
+ * @param event
411
+ * @returns
412
+ */
413
+ match(event: CloudEvent): boolean;
414
+ /**
415
+ * Some filter can be optimized into a simpler form
416
+ *
417
+ * Samples:
418
+ * LEFT(a, 3) = "foo" => prefix: {a: "foo"}
419
+ * RIGHT(a, 3) = "foo" => suffix: {a: "foo"}
420
+ * a = "foo" => exact: {a: "foo"}
421
+ *
422
+ * @returns
423
+ */
424
+ optimize(): FilterImplementation<Filter>;
425
+ }
426
+ export {};