@opra/common 1.7.4 → 1.8.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 (33) hide show
  1. package/browser/index.cjs +5 -5
  2. package/browser/index.mjs +5 -5
  3. package/cjs/document/data-type/api-field.js +2 -0
  4. package/cjs/document/decorators/api-field-decorator.js +1 -0
  5. package/cjs/filter/antlr/OpraFilterLexer.js +212 -347
  6. package/cjs/filter/antlr/OpraFilterListener.js +1 -1
  7. package/cjs/filter/antlr/OpraFilterParser.js +198 -227
  8. package/cjs/filter/antlr/OpraFilterVisitor.js +1 -1
  9. package/cjs/filter/ast/index.js +1 -0
  10. package/cjs/filter/ast/terms/date-time-literal.js +27 -0
  11. package/cjs/filter/build.js +3 -1
  12. package/cjs/filter/filter-tree-visitor.js +1 -1
  13. package/esm/document/data-type/api-field.js +2 -0
  14. package/esm/document/decorators/api-field-decorator.js +1 -0
  15. package/esm/filter/antlr/OpraFilterLexer.js +213 -348
  16. package/esm/filter/antlr/OpraFilterListener.js +2 -2
  17. package/esm/filter/antlr/OpraFilterParser.js +198 -227
  18. package/esm/filter/antlr/OpraFilterVisitor.js +1 -1
  19. package/esm/filter/ast/index.js +1 -0
  20. package/esm/filter/ast/terms/date-time-literal.js +23 -0
  21. package/esm/filter/build.js +3 -1
  22. package/esm/filter/filter-tree-visitor.js +2 -2
  23. package/package.json +2 -2
  24. package/types/document/data-type/api-field.d.ts +2 -1
  25. package/types/document/decorators/api-field-decorator.d.ts +2 -2
  26. package/types/filter/antlr/OpraFilterLexer.d.ts +1 -1
  27. package/types/filter/antlr/OpraFilterListener.d.ts +36 -10
  28. package/types/filter/antlr/OpraFilterParser.d.ts +1 -1
  29. package/types/filter/antlr/OpraFilterVisitor.d.ts +31 -5
  30. package/types/filter/ast/index.d.ts +1 -0
  31. package/types/filter/ast/terms/date-time-literal.d.ts +6 -0
  32. package/types/filter/filter-tree-visitor.d.ts +2 -2
  33. package/types/schema/data-type/field.interface.d.ts +16 -1
@@ -1,4 +1,4 @@
1
- // Generated from ./src/filter/antlr/OpraFilter.g4 by ANTLR 4.12.0
1
+ // Generated from ./src/filter/antlr/OpraFilter.g4 by ANTLR 4.13.2
2
2
  import { ParseTreeVisitor } from '@browsery/antlr4';
3
3
  /**
4
4
  * This interface defines a complete generic visitor for a parse tree produced
@@ -10,6 +10,7 @@ export * from './expressions/negative-expression.js';
10
10
  export * from './expressions/parenthesized-expression.js';
11
11
  export * from './terms/boolean-literal.js';
12
12
  export * from './terms/date-literal.js';
13
+ export * from './terms/date-time-literal.js';
13
14
  export * from './terms/null-literal.js';
14
15
  export * from './terms/number-literal.js';
15
16
  export * from './terms/qualified-identifier.js';
@@ -0,0 +1,23 @@
1
+ import { toDateDef } from 'putil-varhelpers';
2
+ import { FilterValidationError } from '../../errors.js';
3
+ import { quoteFilterString } from '../../utils.js';
4
+ import { Literal } from '../abstract/literal.js';
5
+ const NullDate = new Date(0);
6
+ export class DateTimeLiteral extends Literal {
7
+ constructor(value) {
8
+ super('');
9
+ if (value instanceof Date) {
10
+ this.value = value.toISOString();
11
+ return;
12
+ }
13
+ // noinspection SuspiciousTypeOfGuard
14
+ if (typeof value === 'string' && toDateDef(value, NullDate) !== NullDate) {
15
+ this.value = value;
16
+ return;
17
+ }
18
+ throw new FilterValidationError(`Invalid date-time value "${value}"`);
19
+ }
20
+ toString() {
21
+ return quoteFilterString(this.value);
22
+ }
23
+ }
@@ -81,7 +81,9 @@ export function $arithmetic(n) {
81
81
  return exp;
82
82
  }
83
83
  function comparisonExpression(op, left, right) {
84
- const lex = wrapEntryValue(left);
84
+ const lex = typeof left === 'string'
85
+ ? new QualifiedIdentifier(left)
86
+ : wrapEntryValue(left);
85
87
  const rex = wrapEntryValue(right);
86
88
  return new ComparisonExpression({ op, left: lex, right: rex });
87
89
  }
@@ -1,6 +1,6 @@
1
1
  import { ParseTreeVisitor } from '@browsery/antlr4';
2
2
  import { LogicalExpressionContext, } from './antlr/OpraFilterParser.js';
3
- import { ArrayExpression, BooleanLiteral, ComparisonExpression, DateLiteral, LogicalExpression, NegativeExpression, NullLiteral, NumberLiteral, ParenthesizedExpression, QualifiedIdentifier, StringLiteral, TimeLiteral, } from './ast/index.js';
3
+ import { ArrayExpression, BooleanLiteral, ComparisonExpression, DateLiteral, DateTimeLiteral, LogicalExpression, NegativeExpression, NullLiteral, NumberLiteral, ParenthesizedExpression, QualifiedIdentifier, StringLiteral, TimeLiteral, } from './ast/index.js';
4
4
  import { ExternalConstant } from './ast/terms/external-constant.js';
5
5
  import { unquoteFilterString } from './utils.js';
6
6
  export class FilterTreeVisitor extends ParseTreeVisitor {
@@ -82,7 +82,7 @@ export class FilterTreeVisitor extends ParseTreeVisitor {
82
82
  return new DateLiteral(unquoteFilterString(ctx.getText()));
83
83
  }
84
84
  visitDateTimeLiteral(ctx) {
85
- return new DateLiteral(unquoteFilterString(ctx.getText()));
85
+ return new DateTimeLiteral(unquoteFilterString(ctx.getText()));
86
86
  }
87
87
  visitTimeLiteral(ctx) {
88
88
  return new TimeLiteral(unquoteFilterString(ctx.getText()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "1.7.4",
3
+ "version": "1.8.0",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -8,7 +8,7 @@
8
8
  "@browsery/antlr4": "^4.13.3-r4",
9
9
  "@browsery/highland": "^2.13.6-r4",
10
10
  "@browsery/http-parser": "^0.5.9-r4",
11
- "@browsery/i18next": "^23.12.3-r2",
11
+ "@browsery/i18next": "^24.2.1-r1",
12
12
  "@browsery/type-is": "^1.6.18-r8",
13
13
  "@jsopen/objects": "^1.5.0",
14
14
  "fast-tokenizer": "^1.7.0",
@@ -43,6 +43,7 @@ declare class ApiFieldClass extends DocumentElement {
43
43
  readonly type: DataType;
44
44
  readonly description?: string;
45
45
  readonly isArray?: boolean;
46
+ readonly isNestedEntity?: boolean;
46
47
  readonly default?: any;
47
48
  readonly fixed?: any;
48
49
  readonly required?: boolean;
@@ -66,7 +67,7 @@ export declare namespace ApiField {
66
67
  type?: string | OpraSchema.DataType | TypeThunkAsync | EnumType.EnumObject | EnumType.EnumArray | object;
67
68
  }, OpraSchema.Field> {
68
69
  scopePattern?: (string | RegExp) | (string | RegExp)[];
69
- override?: StrictOmit<Metadata, 'override' | 'type' | 'isArray'>[];
70
+ override?: StrictOmit<Metadata, 'override' | 'type' | 'isArray' | 'isNestedEntity'>[];
70
71
  }
71
72
  interface Options extends Partial<StrictOmit<Metadata, 'override' | 'scopePattern'>> {
72
73
  /**
@@ -6,11 +6,11 @@ export interface ApiFieldDecorator extends PropertyDecorator {
6
6
  *
7
7
  * @param {string | RegExp | (string | RegExp)[]} scopePattern - A pattern or array of patterns that defines the scope
8
8
  * within which the override applies. Patterns can be strings or regular expressions.
9
- * @param {StrictOmit<ApiField.Options, 'isArray' | 'type' | 'scopePattern'>} options - Configuration options to override
9
+ * @param {StrictOmit<ApiField.Options, 'isArray' | 'isNestedEntity' | 'type' | 'scopePattern'>} options - Configuration options to override
10
10
  * the default API field behavior, excluding the properties 'isArray', 'type', and 'scopePattern'.
11
11
  * @return {ApiFieldDecorator} The decorated API field after applying the override configuration.
12
12
  */
13
- Override(scopePattern: (string | RegExp) | (string | RegExp)[], options: StrictOmit<ApiField.Options, 'isArray' | 'type' | 'scopePattern'>): ApiFieldDecorator;
13
+ Override(scopePattern: (string | RegExp) | (string | RegExp)[], options: StrictOmit<ApiField.Options, 'isArray' | 'isNestedEntity' | 'type' | 'scopePattern'>): ApiFieldDecorator;
14
14
  }
15
15
  export interface ApiFieldDecoratorFactory {
16
16
  (options?: ApiField.Options): ApiFieldDecorator;
@@ -1,4 +1,4 @@
1
- import { ATN, CharStream, DFA, Lexer } from '@browsery/antlr4';
1
+ import { ATN, CharStream, DFA, Lexer } from "@browsery/antlr4";
2
2
  export default class OpraFilterLexer extends Lexer {
3
3
  static readonly T__0 = 1;
4
4
  static readonly T__1 = 2;
@@ -1,5 +1,31 @@
1
- import { ParseTreeListener } from '@browsery/antlr4';
2
- import { ArithmeticOperatorContext, ArrayValueContext, BooleanContext, BooleanLiteralContext, ComparisonExpressionContext, ComparisonLeftContext, ComparisonOperatorContext, ComparisonRightContext, DateLiteralContext, DateTimeLiteralContext, ExternalConstantContext, IdentifierContext, InfinityContext, InfinityLiteralContext, LogicalExpressionContext, LogicalOperatorContext, NegativeExpressionContext, NullContext, NullLiteralContext, NumberLiteralContext, ParenthesizedExpressionContext, ParenthesizedItemContext, PolarityOperatorContext, QualifiedIdentifierContext, RootContext, StringLiteralContext, TimeLiteralContext } from './OpraFilterParser.js';
1
+ import { ParseTreeListener } from "@browsery/antlr4";
2
+ import type { RootContext } from "./OpraFilterParser.js";
3
+ import type { ParenthesizedExpressionContext } from "./OpraFilterParser.js";
4
+ import type { NegativeExpressionContext } from "./OpraFilterParser.js";
5
+ import type { ComparisonExpressionContext } from "./OpraFilterParser.js";
6
+ import type { LogicalExpressionContext } from "./OpraFilterParser.js";
7
+ import type { ComparisonLeftContext } from "./OpraFilterParser.js";
8
+ import type { ComparisonRightContext } from "./OpraFilterParser.js";
9
+ import type { ParenthesizedItemContext } from "./OpraFilterParser.js";
10
+ import type { NumberLiteralContext } from "./OpraFilterParser.js";
11
+ import type { InfinityLiteralContext } from "./OpraFilterParser.js";
12
+ import type { BooleanLiteralContext } from "./OpraFilterParser.js";
13
+ import type { NullLiteralContext } from "./OpraFilterParser.js";
14
+ import type { DateTimeLiteralContext } from "./OpraFilterParser.js";
15
+ import type { DateLiteralContext } from "./OpraFilterParser.js";
16
+ import type { TimeLiteralContext } from "./OpraFilterParser.js";
17
+ import { type StringLiteralContext } from "./OpraFilterParser.js";
18
+ import type { QualifiedIdentifierContext } from "./OpraFilterParser.js";
19
+ import type { ExternalConstantContext } from "./OpraFilterParser.js";
20
+ import type { IdentifierContext } from "./OpraFilterParser.js";
21
+ import type { ArrayValueContext } from "./OpraFilterParser.js";
22
+ import type { BooleanContext } from "./OpraFilterParser.js";
23
+ import type { NullContext } from "./OpraFilterParser.js";
24
+ import type { InfinityContext } from "./OpraFilterParser.js";
25
+ import type { ArithmeticOperatorContext } from "./OpraFilterParser.js";
26
+ import type { ComparisonOperatorContext } from "./OpraFilterParser.js";
27
+ import type { LogicalOperatorContext } from "./OpraFilterParser.js";
28
+ import type { PolarityOperatorContext } from "./OpraFilterParser.js";
3
29
  /**
4
30
  * This interface defines a complete listener for a parse tree produced by
5
31
  * `OpraFilterParser`.
@@ -142,29 +168,29 @@ export default class OpraFilterListener extends ParseTreeListener {
142
168
  */
143
169
  exitNullLiteral?: (ctx: NullLiteralContext) => void;
144
170
  /**
145
- * Enter a parse tree produced by the `dateLiteral`
171
+ * Enter a parse tree produced by the `dateTimeLiteral`
146
172
  * labeled alternative in `OpraFilterParser.value`.
147
173
  * @param ctx the parse tree
148
174
  */
149
- enterDateLiteral?: (ctx: DateLiteralContext) => void;
175
+ enterDateTimeLiteral?: (ctx: DateTimeLiteralContext) => void;
150
176
  /**
151
- * Exit a parse tree produced by the `dateLiteral`
177
+ * Exit a parse tree produced by the `dateTimeLiteral`
152
178
  * labeled alternative in `OpraFilterParser.value`.
153
179
  * @param ctx the parse tree
154
180
  */
155
- exitDateLiteral?: (ctx: DateLiteralContext) => void;
181
+ exitDateTimeLiteral?: (ctx: DateTimeLiteralContext) => void;
156
182
  /**
157
- * Enter a parse tree produced by the `dateTimeLiteral`
183
+ * Enter a parse tree produced by the `dateLiteral`
158
184
  * labeled alternative in `OpraFilterParser.value`.
159
185
  * @param ctx the parse tree
160
186
  */
161
- enterDateTimeLiteral?: (ctx: DateTimeLiteralContext) => void;
187
+ enterDateLiteral?: (ctx: DateLiteralContext) => void;
162
188
  /**
163
- * Exit a parse tree produced by the `dateTimeLiteral`
189
+ * Exit a parse tree produced by the `dateLiteral`
164
190
  * labeled alternative in `OpraFilterParser.value`.
165
191
  * @param ctx the parse tree
166
192
  */
167
- exitDateTimeLiteral?: (ctx: DateTimeLiteralContext) => void;
193
+ exitDateLiteral?: (ctx: DateLiteralContext) => void;
168
194
  /**
169
195
  * Enter a parse tree produced by the `timeLiteral`
170
196
  * labeled alternative in `OpraFilterParser.value`.
@@ -1,4 +1,4 @@
1
- import { ATN, DFA, FailedPredicateException, Parser, ParserRuleContext, type RuleContext, type TerminalNode, type TokenStream } from '@browsery/antlr4';
1
+ import { ATN, DFA, FailedPredicateException, Parser, ParserRuleContext, RuleContext, TerminalNode, TokenStream } from '@browsery/antlr4';
2
2
  import type OpraFilterListener from './OpraFilterListener.js';
3
3
  import type OpraFilterVisitor from './OpraFilterVisitor.js';
4
4
  export default class OpraFilterParser extends Parser {
@@ -1,5 +1,31 @@
1
1
  import { ParseTreeVisitor } from '@browsery/antlr4';
2
- import { ArithmeticOperatorContext, ArrayValueContext, BooleanContext, BooleanLiteralContext, ComparisonExpressionContext, ComparisonLeftContext, ComparisonOperatorContext, ComparisonRightContext, DateLiteralContext, DateTimeLiteralContext, ExternalConstantContext, IdentifierContext, InfinityContext, InfinityLiteralContext, LogicalExpressionContext, LogicalOperatorContext, NegativeExpressionContext, NullContext, NullLiteralContext, NumberLiteralContext, ParenthesizedExpressionContext, ParenthesizedItemContext, PolarityOperatorContext, QualifiedIdentifierContext, RootContext, StringLiteralContext, TimeLiteralContext } from './OpraFilterParser.js';
2
+ import type { RootContext } from "./OpraFilterParser.js";
3
+ import type { ParenthesizedExpressionContext } from "./OpraFilterParser.js";
4
+ import type { NegativeExpressionContext } from "./OpraFilterParser.js";
5
+ import type { ComparisonExpressionContext } from "./OpraFilterParser.js";
6
+ import type { LogicalExpressionContext } from "./OpraFilterParser.js";
7
+ import type { ComparisonLeftContext } from "./OpraFilterParser.js";
8
+ import type { ComparisonRightContext } from "./OpraFilterParser.js";
9
+ import type { ParenthesizedItemContext } from "./OpraFilterParser.js";
10
+ import type { NumberLiteralContext } from "./OpraFilterParser.js";
11
+ import type { InfinityLiteralContext } from "./OpraFilterParser.js";
12
+ import type { BooleanLiteralContext } from "./OpraFilterParser.js";
13
+ import type { NullLiteralContext } from "./OpraFilterParser.js";
14
+ import type { DateTimeLiteralContext } from "./OpraFilterParser.js";
15
+ import type { DateLiteralContext } from "./OpraFilterParser.js";
16
+ import type { TimeLiteralContext } from "./OpraFilterParser.js";
17
+ import type { StringLiteralContext } from "./OpraFilterParser.js";
18
+ import type { QualifiedIdentifierContext } from "./OpraFilterParser.js";
19
+ import type { ExternalConstantContext } from "./OpraFilterParser.js";
20
+ import type { IdentifierContext } from "./OpraFilterParser.js";
21
+ import type { ArrayValueContext } from "./OpraFilterParser.js";
22
+ import type { BooleanContext } from "./OpraFilterParser.js";
23
+ import type { NullContext } from "./OpraFilterParser.js";
24
+ import type { InfinityContext } from "./OpraFilterParser.js";
25
+ import type { ArithmeticOperatorContext } from "./OpraFilterParser.js";
26
+ import type { ComparisonOperatorContext } from "./OpraFilterParser.js";
27
+ import type { LogicalOperatorContext } from "./OpraFilterParser.js";
28
+ import type { PolarityOperatorContext } from "./OpraFilterParser.js";
3
29
  /**
4
30
  * This interface defines a complete generic visitor for a parse tree produced
5
31
  * by `OpraFilterParser`.
@@ -89,19 +115,19 @@ export default class OpraFilterVisitor<Result> extends ParseTreeVisitor<Result>
89
115
  */
90
116
  visitNullLiteral?: (ctx: NullLiteralContext) => Result;
91
117
  /**
92
- * Visit a parse tree produced by the `dateLiteral`
118
+ * Visit a parse tree produced by the `dateTimeLiteral`
93
119
  * labeled alternative in `OpraFilterParser.value`.
94
120
  * @param ctx the parse tree
95
121
  * @return the visitor result
96
122
  */
97
- visitDateLiteral?: (ctx: DateLiteralContext) => Result;
123
+ visitDateTimeLiteral?: (ctx: DateTimeLiteralContext) => Result;
98
124
  /**
99
- * Visit a parse tree produced by the `dateTimeLiteral`
125
+ * Visit a parse tree produced by the `dateLiteral`
100
126
  * labeled alternative in `OpraFilterParser.value`.
101
127
  * @param ctx the parse tree
102
128
  * @return the visitor result
103
129
  */
104
- visitDateTimeLiteral?: (ctx: DateTimeLiteralContext) => Result;
130
+ visitDateLiteral?: (ctx: DateLiteralContext) => Result;
105
131
  /**
106
132
  * Visit a parse tree produced by the `timeLiteral`
107
133
  * labeled alternative in `OpraFilterParser.value`.
@@ -10,6 +10,7 @@ export * from './expressions/negative-expression.js';
10
10
  export * from './expressions/parenthesized-expression.js';
11
11
  export * from './terms/boolean-literal.js';
12
12
  export * from './terms/date-literal.js';
13
+ export * from './terms/date-time-literal.js';
13
14
  export * from './terms/null-literal.js';
14
15
  export * from './terms/number-literal.js';
15
16
  export * from './terms/qualified-identifier.js';
@@ -0,0 +1,6 @@
1
+ import { Literal } from '../abstract/literal.js';
2
+ export declare class DateTimeLiteral extends Literal {
3
+ value: string;
4
+ constructor(value: string | Date);
5
+ toString(): string;
6
+ }
@@ -1,7 +1,7 @@
1
1
  import { ParseTreeVisitor, type RuleNode } from '@browsery/antlr4';
2
2
  import { ArrayValueContext, BooleanLiteralContext, ComparisonExpressionContext, DateLiteralContext, DateTimeLiteralContext, ExternalConstantContext, LogicalExpressionContext, NegativeExpressionContext, NumberLiteralContext, ParenthesizedExpressionContext, ParenthesizedItemContext, QualifiedIdentifierContext, RootContext, StringLiteralContext, TimeLiteralContext } from './antlr/OpraFilterParser.js';
3
3
  import OpraFilterVisitor from './antlr/OpraFilterVisitor.js';
4
- import { ArrayExpression, BooleanLiteral, DateLiteral, LogicalExpression, NegativeExpression, NullLiteral, NumberLiteral, ParenthesizedExpression, QualifiedIdentifier, StringLiteral, TimeLiteral } from './ast/index.js';
4
+ import { ArrayExpression, BooleanLiteral, DateLiteral, DateTimeLiteral, LogicalExpression, NegativeExpression, NullLiteral, NumberLiteral, ParenthesizedExpression, QualifiedIdentifier, StringLiteral, TimeLiteral } from './ast/index.js';
5
5
  import { ExternalConstant } from './ast/terms/external-constant.js';
6
6
  export declare class FilterTreeVisitor extends ParseTreeVisitor<any> implements OpraFilterVisitor<any> {
7
7
  private _timeZone?;
@@ -24,7 +24,7 @@ export declare class FilterTreeVisitor extends ParseTreeVisitor<any> implements
24
24
  visitStringLiteral(ctx: StringLiteralContext): StringLiteral;
25
25
  visitInfinityLiteral(): NumberLiteral;
26
26
  visitDateLiteral(ctx: DateLiteralContext): DateLiteral;
27
- visitDateTimeLiteral(ctx: DateTimeLiteralContext): DateLiteral;
27
+ visitDateTimeLiteral(ctx: DateTimeLiteralContext): DateTimeLiteral;
28
28
  visitTimeLiteral(ctx: TimeLiteralContext): TimeLiteral;
29
29
  visitArrayValue(ctx: ArrayValueContext): ArrayExpression;
30
30
  }
@@ -3,6 +3,11 @@ export declare namespace Field {
3
3
  type Name = string;
4
4
  type QualifiedName = string;
5
5
  }
6
+ /**
7
+ * Represents a Field type used to define properties and behaviors of a data structure.
8
+ *
9
+ * The `Field` type allows describing the characteristics, constraints, and metadata of a field within an entity or data type.
10
+ */
6
11
  export type Field = {
7
12
  type?: DataType.Name | DataType;
8
13
  /**
@@ -35,9 +40,19 @@ export type Field = {
35
40
  */
36
41
  exclusive?: boolean;
37
42
  /**
38
- * Indicates if the field value is an array
43
+ * A boolean variable that indicates whether the value represents an array or not.
44
+ * If true, the value is recognized as an array.
45
+ * If false, the value is not an array.
46
+ * This property is optional and may be undefined.
39
47
  */
40
48
  isArray?: boolean;
49
+ /**
50
+ * Determines whether the field is a nested entity within a parent structure.
51
+ * If set to true, the field is considered to be part of a hierarchical or
52
+ * composite structure. If false or undefined, the field is considered
53
+ * standalone or root-level.
54
+ */
55
+ isNestedEntity?: boolean;
41
56
  /**
42
57
  * Indicates key field when this field is a ComplexType array
43
58
  */