@opra/common 1.9.0 → 1.9.2

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.
@@ -120,8 +120,16 @@ function createFilterDecorator(decorator, decoratorChain, dataType) {
120
120
  const filterOptions = (Array.isArray(arg0)
121
121
  ? { operators: arg0 }
122
122
  : typeof arg0 === 'string'
123
- ? { operators: [arg0] }
123
+ ? {
124
+ operators: arg0.split(/\s*,\s*/),
125
+ }
124
126
  : arg0) || {};
127
+ filterOptions.operators = filterOptions.operators || ['=', '!='];
128
+ if (field.includes(':')) {
129
+ const a = field.split(':');
130
+ field = a[0];
131
+ filterOptions.mappedField = a[1];
132
+ }
125
133
  decoratorChain.push(() => {
126
134
  filterRules.set(field, filterOptions);
127
135
  filterType.rules = filterRules.toJSON();
@@ -69,6 +69,8 @@ class FilterRules {
69
69
  },
70
70
  });
71
71
  }
72
+ if (rule.mappedField)
73
+ ast.left.value = rule.mappedField;
72
74
  if (rule.prepare)
73
75
  ast.prepare = rule.prepare;
74
76
  this.normalizeFilterAst(ast.right, stack, currentType);
@@ -114,8 +114,16 @@ export function createFilterDecorator(decorator, decoratorChain, dataType) {
114
114
  const filterOptions = (Array.isArray(arg0)
115
115
  ? { operators: arg0 }
116
116
  : typeof arg0 === 'string'
117
- ? { operators: [arg0] }
117
+ ? {
118
+ operators: arg0.split(/\s*,\s*/),
119
+ }
118
120
  : arg0) || {};
121
+ filterOptions.operators = filterOptions.operators || ['=', '!='];
122
+ if (field.includes(':')) {
123
+ const a = field.split(':');
124
+ field = a[0];
125
+ filterOptions.mappedField = a[1];
126
+ }
119
127
  decoratorChain.push(() => {
120
128
  filterRules.set(field, filterOptions);
121
129
  filterType.rules = filterRules.toJSON();
@@ -66,6 +66,8 @@ export class FilterRules {
66
66
  },
67
67
  });
68
68
  }
69
+ if (rule.mappedField)
70
+ ast.left.value = rule.mappedField;
69
71
  if (rule.prepare)
70
72
  ast.prepare = rule.prepare;
71
73
  this.normalizeFilterAst(ast.right, stack, currentType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/common",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "Opra common package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -52,12 +52,13 @@ declare module '../http/http-operation.js' {
52
52
  }
53
53
  /** DeleteMany */
54
54
  interface FilterOptions {
55
+ mappedField?: string;
55
56
  operators?: OpraFilter.ComparisonOperator[];
56
57
  notes?: string;
57
- prepare?: (value: any, op: OpraFilter.ComparisonOperator) => any;
58
+ prepare?: (args: OpraFilter.ComparisonExpression.PrepareArgs) => any;
58
59
  }
59
60
  interface DeleteManyDecorator extends HttpOperationDecorator {
60
- Filter(field: string, operators?: OpraFilter.ComparisonOperator[]): this;
61
+ Filter(field: string, operators?: OpraFilter.ComparisonOperator[] | string): this;
61
62
  Filter(field: string, options?: FilterOptions): this;
62
63
  }
63
64
  interface DeleteManyArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> {
@@ -68,7 +69,7 @@ declare module '../http/http-operation.js' {
68
69
  SortFields(...fields: OpraSchema.Field.QualifiedName[]): FindManyDecorator;
69
70
  SortFields(fieldsMap: Record<OpraSchema.Field.QualifiedName, OpraSchema.Field.QualifiedName>): FindManyDecorator;
70
71
  DefaultSort(...fields: OpraSchema.Field.QualifiedName[]): FindManyDecorator;
71
- Filter(field: OpraSchema.Field.QualifiedName, operators?: OpraFilter.ComparisonOperator[]): this;
72
+ Filter(field: OpraSchema.Field.QualifiedName, operators?: OpraFilter.ComparisonOperator[] | string): this;
72
73
  Filter(field: string, options?: FilterOptions): this;
73
74
  }
74
75
  interface FindManyArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> {
@@ -94,7 +95,7 @@ declare module '../http/http-operation.js' {
94
95
  /** Update */
95
96
  interface UpdateDecorator extends HttpOperationDecorator {
96
97
  KeyParam(name: string, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync): this;
97
- Filter(field: OpraSchema.Field.QualifiedName, operators?: OpraFilter.ComparisonOperator[]): this;
98
+ Filter(field: OpraSchema.Field.QualifiedName, operators?: OpraFilter.ComparisonOperator[] | string): this;
98
99
  Filter(field: string, options?: FilterOptions): this;
99
100
  }
100
101
  interface UpdateArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> {
@@ -107,7 +108,7 @@ declare module '../http/http-operation.js' {
107
108
  }
108
109
  /** UpdateMany */
109
110
  interface UpdateManyDecorator extends HttpOperationDecorator {
110
- Filter(field: OpraSchema.Field.QualifiedName, operators?: OpraFilter.ComparisonOperator[]): this;
111
+ Filter(field: OpraSchema.Field.QualifiedName, operators?: OpraFilter.ComparisonOperator[] | string): this;
111
112
  Filter(field: string, options?: FilterOptions): this;
112
113
  }
113
114
  interface UpdateManyArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> {
@@ -137,4 +138,4 @@ export declare function createSortFieldsDecorator<T extends HttpOperationDecorat
137
138
  /**
138
139
  *
139
140
  */
140
- export declare function createFilterDecorator<T extends HttpOperationDecorator>(decorator: T, decoratorChain: Function[], dataType: string | Type): (field: string, arg0?: OpraFilter.ComparisonOperator[] | HttpOperation.Entity.FilterOptions) => T;
141
+ export declare function createFilterDecorator<T extends HttpOperationDecorator>(decorator: T, decoratorChain: Function[], dataType: string | Type): (field: string, arg0?: OpraFilter.ComparisonOperator[] | string | HttpOperation.Entity.FilterOptions) => T;
@@ -5,7 +5,15 @@ export declare class ComparisonExpression extends Expression {
5
5
  op: ComparisonOperator;
6
6
  left: Expression;
7
7
  right: Expression;
8
- prepare?: (value: any, op: ComparisonOperator) => any;
8
+ prepare?: (args: ComparisonExpression.PrepareArgs) => any;
9
9
  constructor(o: StrictOmit<ComparisonExpression, 'kind'>);
10
10
  toString(): string;
11
11
  }
12
+ export declare namespace ComparisonExpression {
13
+ interface PrepareArgs {
14
+ left: string;
15
+ right: any;
16
+ op: ComparisonOperator;
17
+ adapter: string;
18
+ }
19
+ }
@@ -4,7 +4,7 @@ import { Validator } from 'valgen';
4
4
  import type { ComplexType } from '../document/index.js';
5
5
  import { ResponsiveMap } from '../helpers/index.js';
6
6
  import { OpraSchema } from '../schema/index.js';
7
- import { type ComparisonOperator, Expression } from './ast/index.js';
7
+ import { ComparisonExpression, type ComparisonOperator, Expression } from './ast/index.js';
8
8
  export declare namespace FilterRules {
9
9
  interface Options {
10
10
  caseSensitive?: boolean;
@@ -12,7 +12,8 @@ export declare namespace FilterRules {
12
12
  interface Rule {
13
13
  operators?: ComparisonOperator[];
14
14
  description?: string;
15
- prepare?: (value: any, op: ComparisonOperator) => any;
15
+ prepare?: (args: ComparisonExpression.PrepareArgs) => any;
16
+ mappedField?: string;
16
17
  }
17
18
  }
18
19
  export declare class FilterRules {