@nulledexp/translatable-criteria 1.1.0 → 2.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 (71) hide show
  1. package/README.md +89 -85
  2. package/dist/criteria/criteria-factory.d.ts +6 -5
  3. package/dist/criteria/criteria-factory.d.ts.map +1 -1
  4. package/dist/criteria/criteria-factory.js +8 -8
  5. package/dist/criteria/criteria-factory.js.map +1 -1
  6. package/dist/criteria/criteria-join-manager.js.map +1 -1
  7. package/dist/criteria/criteria.d.ts +188 -17
  8. package/dist/criteria/criteria.d.ts.map +1 -1
  9. package/dist/criteria/criteria.js +219 -44
  10. package/dist/criteria/criteria.js.map +1 -1
  11. package/dist/criteria/cursor.d.ts +15 -0
  12. package/dist/criteria/cursor.d.ts.map +1 -1
  13. package/dist/criteria/cursor.js +24 -2
  14. package/dist/criteria/cursor.js.map +1 -1
  15. package/dist/criteria/filter/filter-group.d.ts +7 -1
  16. package/dist/criteria/filter/filter-group.d.ts.map +1 -1
  17. package/dist/criteria/filter/filter-group.js +12 -3
  18. package/dist/criteria/filter/filter-group.js.map +1 -1
  19. package/dist/criteria/filter/filter.d.ts +3 -3
  20. package/dist/criteria/filter/filter.d.ts.map +1 -1
  21. package/dist/criteria/filter/filter.js +37 -14
  22. package/dist/criteria/filter/filter.js.map +1 -1
  23. package/dist/criteria/filter/types/filter-primitive.types.d.ts +16 -6
  24. package/dist/criteria/filter/types/filter-primitive.types.d.ts.map +1 -1
  25. package/dist/criteria/index.d.ts +2 -2
  26. package/dist/criteria/index.d.ts.map +1 -1
  27. package/dist/criteria/index.js.map +1 -1
  28. package/dist/criteria/join/inner.join-criteria.d.ts +12 -14
  29. package/dist/criteria/join/inner.join-criteria.d.ts.map +1 -1
  30. package/dist/criteria/join/inner.join-criteria.js +13 -15
  31. package/dist/criteria/join/inner.join-criteria.js.map +1 -1
  32. package/dist/criteria/join/left.join-criteria.d.ts +9 -4
  33. package/dist/criteria/join/left.join-criteria.d.ts.map +1 -1
  34. package/dist/criteria/join/left.join-criteria.js +10 -5
  35. package/dist/criteria/join/left.join-criteria.js.map +1 -1
  36. package/dist/criteria/join/outer.join-criteria.d.ts +15 -13
  37. package/dist/criteria/join/outer.join-criteria.d.ts.map +1 -1
  38. package/dist/criteria/join/outer.join-criteria.js +16 -14
  39. package/dist/criteria/join/outer.join-criteria.js.map +1 -1
  40. package/dist/criteria/order/order.d.ts +18 -1
  41. package/dist/criteria/order/order.d.ts.map +1 -1
  42. package/dist/criteria/order/order.js +21 -1
  43. package/dist/criteria/order/order.js.map +1 -1
  44. package/dist/criteria/root.criteria.d.ts +11 -16
  45. package/dist/criteria/root.criteria.d.ts.map +1 -1
  46. package/dist/criteria/root.criteria.js +9 -14
  47. package/dist/criteria/root.criteria.js.map +1 -1
  48. package/dist/criteria/translator/criteria-translator.d.ts +23 -32
  49. package/dist/criteria/translator/criteria-translator.d.ts.map +1 -1
  50. package/dist/criteria/translator/criteria-translator.js +5 -24
  51. package/dist/criteria/translator/criteria-translator.js.map +1 -1
  52. package/dist/criteria/types/criteria.interface.d.ts +60 -44
  53. package/dist/criteria/types/criteria.interface.d.ts.map +1 -1
  54. package/dist/criteria/types/criteria.interface.js.map +1 -1
  55. package/dist/criteria/types/join-parameter.types.d.ts +56 -6
  56. package/dist/criteria/types/join-parameter.types.d.ts.map +1 -1
  57. package/dist/criteria/types/join-utility.types.d.ts +25 -31
  58. package/dist/criteria/types/join-utility.types.d.ts.map +1 -1
  59. package/dist/criteria/types/manager.interface.d.ts +3 -3
  60. package/dist/criteria/types/manager.interface.d.ts.map +1 -1
  61. package/dist/criteria/types/operator.types.d.ts +92 -86
  62. package/dist/criteria/types/operator.types.d.ts.map +1 -1
  63. package/dist/criteria/types/operator.types.js +91 -85
  64. package/dist/criteria/types/operator.types.js.map +1 -1
  65. package/dist/criteria/types/schema.types.d.ts +127 -37
  66. package/dist/criteria/types/schema.types.d.ts.map +1 -1
  67. package/dist/criteria/types/schema.types.js +38 -11
  68. package/dist/criteria/types/schema.types.js.map +1 -1
  69. package/dist/criteria/types/visitor-interface.types.d.ts +33 -12
  70. package/dist/criteria/types/visitor-interface.types.d.ts.map +1 -1
  71. package/package.json +1 -1
@@ -8,6 +8,14 @@ export const OrderDirection = {
8
8
  DESC: 'DESC',
9
9
  };
10
10
  let globalOrderSequence = 0;
11
+ /**
12
+ * Resets the global order sequence counter.
13
+ * This function is intended for testing purposes to ensure predictable sequence IDs.
14
+ * @internal
15
+ */
16
+ export function _resetOrderSequenceForTesting() {
17
+ globalOrderSequence = 0;
18
+ }
11
19
  /**
12
20
  * Represents a single ordering rule for a query.
13
21
  * It includes the field to order by, the direction (ASC/DESC),
@@ -18,6 +26,7 @@ let globalOrderSequence = 0;
18
26
  export class Order {
19
27
  _direction;
20
28
  _field;
29
+ _nullsFirst;
21
30
  /**
22
31
  * A unique, globally incrementing ID to ensure stable sorting order
23
32
  * when multiple Order instances are created.
@@ -28,13 +37,22 @@ export class Order {
28
37
  * Creates an instance of Order.
29
38
  * @param {OrderDirection} _direction - The direction of the sort (ASC or DESC).
30
39
  * @param {T} _field - The name of the field to order by.
40
+ * @param {boolean} [_nullsFirst=false] - If true, null values will be ordered first.
31
41
  */
32
- constructor(_direction, _field) {
42
+ constructor(_direction, _field, _nullsFirst = false) {
33
43
  this._direction = _direction;
34
44
  this._field = _field;
45
+ this._nullsFirst = _nullsFirst;
35
46
  globalOrderSequence++;
36
47
  this._sequenceId = globalOrderSequence;
37
48
  }
49
+ /**
50
+ * Gets whether null values should be ordered first.
51
+ * @returns {boolean} True if nulls are first, otherwise false.
52
+ */
53
+ get nullsFirst() {
54
+ return this._nullsFirst;
55
+ }
38
56
  /**
39
57
  * Gets the unique sequence ID of this order rule.
40
58
  * Used to maintain a stable sort order when multiple orders are applied.
@@ -65,6 +83,8 @@ export class Order {
65
83
  return {
66
84
  direction: this._direction,
67
85
  field: this._field,
86
+ nulls_first: this._nullsFirst,
87
+ sequence_id: this.sequenceId,
68
88
  };
69
89
  }
70
90
  }
@@ -1 +1 @@
1
- {"version":3,"file":"order.js","sourceRoot":"","sources":["../../../src/criteria/order/order.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,wCAAwC;IACxC,GAAG,EAAE,KAAK;IACV,yCAAyC;IACzC,IAAI,EAAE,MAAM;CACJ,CAAC;AAOX,IAAI,mBAAmB,GAAW,CAAC,CAAC;AAcpC;;;;;;GAMG;AACH,MAAM,OAAO,KAAK;IAcK;IACA;IAdrB;;;;OAIG;IACO,WAAW,CAAS;IAE9B;;;;OAIG;IACH,YACqB,UAA0B,EAC1B,MAAS;QADT,eAAU,GAAV,UAAU,CAAgB;QAC1B,WAAM,GAAN,MAAM,CAAG;QAE5B,mBAAmB,EAAE,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,mBAAmB,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,KAAK,EAAE,IAAI,CAAC,MAAM;SACnB,CAAC;IACJ,CAAC;CACF"}
1
+ {"version":3,"file":"order.js","sourceRoot":"","sources":["../../../src/criteria/order/order.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,wCAAwC;IACxC,GAAG,EAAE,KAAK;IACV,yCAAyC;IACzC,IAAI,EAAE,MAAM;CACJ,CAAC;AAOX,IAAI,mBAAmB,GAAW,CAAC,CAAC;AAEpC;;;;GAIG;AACH,MAAM,UAAU,6BAA6B;IAC3C,mBAAmB,GAAG,CAAC,CAAC;AAC1B,CAAC;AAkBD;;;;;;GAMG;AACH,MAAM,OAAO,KAAK;IAeK;IACA;IACA;IAhBrB;;;;OAIG;IACO,WAAW,CAAS;IAE9B;;;;;OAKG;IACH,YACqB,UAA0B,EAC1B,MAAS,EACT,cAAuB,KAAK;QAF5B,eAAU,GAAV,UAAU,CAAgB;QAC1B,WAAM,GAAN,MAAM,CAAG;QACT,gBAAW,GAAX,WAAW,CAAiB;QAE/C,mBAAmB,EAAE,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,mBAAmB,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,UAAU;SAC7B,CAAC;IACJ,CAAC;CACF"}
@@ -1,28 +1,23 @@
1
1
  import { Criteria } from './criteria.js';
2
- import type { CriteriaSchema, SelectedAliasOf } from './types/schema.types.js';
2
+ import type { CriteriaSchema } from './types/schema.types.js';
3
3
  import type { ICriteriaVisitor } from './types/visitor-interface.types.js';
4
4
  /**
5
5
  * Represents the root criteria for a query.
6
- * This is the main entry point for building a query and defines the primary entity being queried.
7
- * It extends the base {@link Criteria} and defines how it's visited by a {@link ICriteriaVisitor}.
8
6
  * @template CSchema - The {@link CriteriaSchema} of the root entity.
9
7
  * @template Alias - The selected alias for the root entity from its schema.
10
8
  */
11
- export declare class RootCriteria<CSchema extends CriteriaSchema, Alias extends SelectedAliasOf<CSchema>> extends Criteria<CSchema, Alias> {
9
+ export declare class RootCriteria<CSchema extends CriteriaSchema> extends Criteria<CSchema> {
12
10
  /**
13
11
  * Accepts a criteria visitor to process this root criteria.
14
- * This method is the entry point for the visitor pattern to traverse the criteria tree.
15
- * @template TranslationContext - The type of the context object passed during traversal (e.g., a query builder
16
- * instance).
17
- * @template TranslationOutput - The type of the result returned by visitor methods (e.g., the modified query builder
18
- * or a query string).
19
- * @param {ICriteriaVisitor<TranslationContext, TranslationOutput>} visitor - The visitor instance responsible for
20
- * translating criteria parts.
21
- * @param {TranslationContext} context - The context object to be passed to the visitor (e.g., an initial query
22
- * builder or an empty string for SQL).
23
- * @returns {TranslationOutput} The result of the visitor processing this root criteria and its components.
12
+ * @param visitor The visitor instance responsible for translating criteria parts.
13
+ * @param context The context object to be passed to the visitor.
24
14
  */
25
- accept<TranslationContext, TranslationOutput>(visitor: ICriteriaVisitor<TranslationContext, TranslationOutput>, context: TranslationContext): TranslationOutput;
26
- resetCriteria(): RootCriteria<CSchema, Alias>;
15
+ accept<TranslationContext>(visitor: ICriteriaVisitor<TranslationContext>, context: TranslationContext): void;
16
+ /**
17
+ * Returns a new instance of `RootCriteria` with the same schema and alias configuration,
18
+ * but with all other states (filters, joins, ordering, pagination, selection) reset to their defaults.
19
+ * @returns {RootCriteria<CSchema, Alias>} A new, reset `RootCriteria` instance.
20
+ */
21
+ resetCriteria(): RootCriteria<CSchema>;
27
22
  }
28
23
  //# sourceMappingURL=root.criteria.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"root.criteria.d.ts","sourceRoot":"","sources":["../../src/criteria/root.criteria.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAE3E;;;;;;GAMG;AACH,qBAAa,YAAY,CACvB,OAAO,SAAS,cAAc,EAC9B,KAAK,SAAS,eAAe,CAAC,OAAO,CAAC,CACtC,SAAQ,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAChC;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,kBAAkB,EAAE,iBAAiB,EAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,EAChE,OAAO,EAAE,kBAAkB,GAC1B,iBAAiB;IAGpB,aAAa,IAAI,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;CAG9C"}
1
+ {"version":3,"file":"root.criteria.d.ts","sourceRoot":"","sources":["../../src/criteria/root.criteria.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAE3E;;;;GAIG;AACH,qBAAa,YAAY,CACvB,OAAO,SAAS,cAAc,CAC9B,SAAQ,QAAQ,CAAC,OAAO,CAAC;IACzB;;;;OAIG;IACI,MAAM,CAAC,kBAAkB,EAC9B,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,EAC7C,OAAO,EAAE,kBAAkB,GAC1B,IAAI;IAIP;;;;OAIG;IACI,aAAa,IAAI,YAAY,CAAC,OAAO,CAAC;CAG9C"}
@@ -1,30 +1,25 @@
1
1
  import { Criteria } from './criteria.js';
2
2
  /**
3
3
  * Represents the root criteria for a query.
4
- * This is the main entry point for building a query and defines the primary entity being queried.
5
- * It extends the base {@link Criteria} and defines how it's visited by a {@link ICriteriaVisitor}.
6
4
  * @template CSchema - The {@link CriteriaSchema} of the root entity.
7
5
  * @template Alias - The selected alias for the root entity from its schema.
8
6
  */
9
7
  export class RootCriteria extends Criteria {
10
8
  /**
11
9
  * Accepts a criteria visitor to process this root criteria.
12
- * This method is the entry point for the visitor pattern to traverse the criteria tree.
13
- * @template TranslationContext - The type of the context object passed during traversal (e.g., a query builder
14
- * instance).
15
- * @template TranslationOutput - The type of the result returned by visitor methods (e.g., the modified query builder
16
- * or a query string).
17
- * @param {ICriteriaVisitor<TranslationContext, TranslationOutput>} visitor - The visitor instance responsible for
18
- * translating criteria parts.
19
- * @param {TranslationContext} context - The context object to be passed to the visitor (e.g., an initial query
20
- * builder or an empty string for SQL).
21
- * @returns {TranslationOutput} The result of the visitor processing this root criteria and its components.
10
+ * @param visitor The visitor instance responsible for translating criteria parts.
11
+ * @param context The context object to be passed to the visitor.
22
12
  */
23
13
  accept(visitor, context) {
24
- return visitor.visitRoot(this, context);
14
+ visitor.visitRoot(this, context);
25
15
  }
16
+ /**
17
+ * Returns a new instance of `RootCriteria` with the same schema and alias configuration,
18
+ * but with all other states (filters, joins, ordering, pagination, selection) reset to their defaults.
19
+ * @returns {RootCriteria<CSchema, Alias>} A new, reset `RootCriteria` instance.
20
+ */
26
21
  resetCriteria() {
27
- return new RootCriteria(this.schema, this._alias);
22
+ return new RootCriteria(this.schema);
28
23
  }
29
24
  }
30
25
  //# sourceMappingURL=root.criteria.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"root.criteria.js","sourceRoot":"","sources":["../../src/criteria/root.criteria.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC;;;;;;GAMG;AACH,MAAM,OAAO,YAGX,SAAQ,QAAwB;IAChC;;;;;;;;;;;;OAYG;IACH,MAAM,CACJ,OAAgE,EAChE,OAA2B;QAE3B,OAAO,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IACD,aAAa;QACX,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;CACF"}
1
+ {"version":3,"file":"root.criteria.js","sourceRoot":"","sources":["../../src/criteria/root.criteria.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,eAAe,CAAC;AAI3D;;;;GAIG;AACH,MAAM,OAAO,YAEX,SAAQ,QAAiB;IACzB;;;;OAIG;IACI,MAAM,CACX,OAA6C,EAC7C,OAA2B;QAE3B,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,aAAa;QAClB,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,MAA8B,CAAC,CAAC;IAC/D,CAAC;CACF"}
@@ -1,45 +1,36 @@
1
- import type { CriteriaSchema, JoinRelationType, SelectedAliasOf } from '../types/schema.types.js';
1
+ import type { ICriteriaVisitor } from '../types/visitor-interface.types.js';
2
2
  import type { RootCriteria } from '../root.criteria.js';
3
- import type { PivotJoin, SimpleJoin } from '../types/join-parameter.types.js';
4
- import type { FilterGroup } from '../filter/filter-group.js';
3
+ import type { CriteriaSchema, JoinRelationType } from '../types/schema.types.js';
5
4
  import type { InnerJoinCriteria } from '../join/inner.join-criteria.js';
6
5
  import type { LeftJoinCriteria } from '../join/left.join-criteria.js';
7
6
  import type { OuterJoinCriteria } from '../join/outer.join-criteria.js';
7
+ import type { PivotJoin, SimpleJoin } from '../types/join-parameter.types.js';
8
8
  import type { Filter } from '../filter/filter.js';
9
- import type { ICriteriaVisitor } from '../types/visitor-interface.types.js';
9
+ import type { FilterGroup } from '../filter/filter-group.js';
10
10
  import type { FilterOperator } from '../types/operator.types.js';
11
11
  /**
12
- * Abstract Class for translating criteria into various query formats
13
- * @template TranslationContext - The target format (e.g., QueryBuilder, raw SQL string, etc.)
14
- * @template TranslationOutput - The output format by default its Source (Only specify this if
15
- * you really need something like a memory translator and the output would be different
16
- * from the TranslationContext itself)
17
- * @template RootSchema - The schema type for the root criteria
18
- * @example
19
- * // TypeORM QueryBuilder translator
20
- * class TypeORMTranslator implements CriteriaTranslator<SelectQueryBuilder<Entity>> {
21
- * ...Concrete implementation
22
- * }
12
+ * An abstract base class for creating specific criteria translators.
13
+ * It implements the ICriteriaVisitor interface and provides a structured way to handle the translation process.
23
14
  *
24
- * // Raw MySQL translator
25
- * export class MysqlTranslator extends CriteriaTranslator<string, string> { {
26
- * ...Concrete implementation
27
- * }
15
+ * @template TranslationContext The mutable context object (e.g., a query builder) passed through the traversal.
16
+ * @template TranslationOutput The final result type of the translation process. Defaults to `TranslationContext`.
17
+ * @template TFilterVisitorOutput The specific type returned by `visitFilter`.
28
18
  */
29
- export declare abstract class CriteriaTranslator<TranslationContext, TranslationOutput = TranslationContext, TFilterVisitorOutput extends any = any> implements ICriteriaVisitor<TranslationContext, TranslationOutput, TFilterVisitorOutput> {
19
+ export declare abstract class CriteriaTranslator<TranslationContext, TranslationOutput = TranslationContext, TFilterVisitorOutput = any> implements ICriteriaVisitor<TranslationContext, TFilterVisitorOutput> {
30
20
  /**
31
- * Translates a criteria into the target source format
32
- * @param criteria - The criteria to translate
33
- * @param source - The source object to translate into (e.g., QueryBuilder instance, or raw SQL string)
34
- * @returns The modified source or the output format if specified
21
+ * Translates a `RootCriteria` object into a target format.
22
+ * This is the main entry point for the translation process.
23
+ * @param criteria The `RootCriteria` to translate.
24
+ * @param source The initial context for the translation (e.g., a new query builder).
25
+ * @returns The final translated output.
35
26
  */
36
- translate<RootCriteriaSchema extends CriteriaSchema>(criteria: RootCriteria<RootCriteriaSchema, SelectedAliasOf<RootCriteriaSchema>>, source: TranslationContext): TranslationOutput;
37
- abstract visitRoot<RootCriteriaSchema extends CriteriaSchema, RootAlias extends SelectedAliasOf<RootCriteriaSchema>>(criteria: RootCriteria<RootCriteriaSchema, RootAlias>, context: TranslationContext): TranslationOutput;
38
- abstract visitInnerJoin<ParentCSchema extends CriteriaSchema, JoinCriteriaSchema extends CriteriaSchema, JoinAlias extends SelectedAliasOf<JoinCriteriaSchema>>(criteria: InnerJoinCriteria<JoinCriteriaSchema, JoinAlias>, parameters: PivotJoin<ParentCSchema, JoinCriteriaSchema, JoinRelationType> | SimpleJoin<ParentCSchema, JoinCriteriaSchema, JoinRelationType>, context: TranslationContext): TranslationOutput;
39
- abstract visitLeftJoin<ParentCSchema extends CriteriaSchema, JoinCriteriaSchema extends CriteriaSchema, JoinAlias extends SelectedAliasOf<JoinCriteriaSchema>>(criteria: LeftJoinCriteria<JoinCriteriaSchema, JoinAlias>, parameters: PivotJoin<ParentCSchema, JoinCriteriaSchema, JoinRelationType> | SimpleJoin<ParentCSchema, JoinCriteriaSchema, JoinRelationType>, context: TranslationContext): TranslationOutput;
40
- abstract visitOuterJoin<ParentCSchema extends CriteriaSchema, JoinCriteriaSchema extends CriteriaSchema, JoinAlias extends SelectedAliasOf<JoinCriteriaSchema>>(criteria: OuterJoinCriteria<JoinCriteriaSchema, JoinAlias>, parameters: PivotJoin<ParentCSchema, JoinCriteriaSchema, JoinRelationType> | SimpleJoin<ParentCSchema, JoinCriteriaSchema, JoinRelationType>, context: TranslationContext): TranslationOutput;
41
- abstract visitFilter<FieldType extends string, Operator extends FilterOperator>(filter: Filter<FieldType, Operator>, currentAlias: string): TFilterVisitorOutput;
42
- abstract visitAndGroup<FieldType extends string>(group: FilterGroup<FieldType>, currentAlias: string, context: TranslationContext): TranslationOutput;
43
- abstract visitOrGroup<FieldType extends string>(group: FilterGroup<FieldType>, currentAlias: string, context: TranslationContext): TranslationOutput;
27
+ abstract translate<RootCriteriaSchema extends CriteriaSchema>(criteria: RootCriteria<RootCriteriaSchema>, source: TranslationContext): TranslationOutput;
28
+ abstract visitRoot<RootCSchema extends CriteriaSchema>(criteria: RootCriteria<RootCSchema>, context: TranslationContext): void;
29
+ abstract visitInnerJoin<ParentCSchema extends CriteriaSchema, JoinCSchema extends CriteriaSchema>(criteria: InnerJoinCriteria<JoinCSchema>, parameters: PivotJoin<ParentCSchema, JoinCSchema, JoinRelationType> | SimpleJoin<ParentCSchema, JoinCSchema, JoinRelationType>, context: TranslationContext): void;
30
+ abstract visitLeftJoin<ParentCSchema extends CriteriaSchema, JoinCSchema extends CriteriaSchema>(criteria: LeftJoinCriteria<JoinCSchema>, parameters: PivotJoin<ParentCSchema, JoinCSchema, JoinRelationType> | SimpleJoin<ParentCSchema, JoinCSchema, JoinRelationType>, context: TranslationContext): void;
31
+ abstract visitOuterJoin<ParentCSchema extends CriteriaSchema, JoinCSchema extends CriteriaSchema>(criteria: OuterJoinCriteria<JoinCSchema>, parameters: PivotJoin<ParentCSchema, JoinCSchema, JoinRelationType> | SimpleJoin<ParentCSchema, JoinCSchema, JoinRelationType>, context: TranslationContext): void;
32
+ abstract visitFilter<FieldType extends string>(filter: Filter<FieldType, FilterOperator>, currentAlias: string, context: TranslationContext): TFilterVisitorOutput;
33
+ abstract visitAndGroup<FieldType extends string>(group: FilterGroup<FieldType>, currentAlias: string, context: TranslationContext): void;
34
+ abstract visitOrGroup<FieldType extends string>(group: FilterGroup<FieldType>, currentAlias: string, context: TranslationContext): void;
44
35
  }
45
36
  //# sourceMappingURL=criteria-translator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"criteria-translator.d.ts","sourceRoot":"","sources":["../../../src/criteria/translator/criteria-translator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAA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OAAO,EAAE,kBAAkB,GAC1B,IAAI;aAES,aAAa,CAC3B,aAAa,SAAS,cAAc,EACpC,WAAW,SAAS,cAAc,EAElC,QAAQ,EAAE,gBAAgB,CAAC,WAAW,CAAC,EACvC,UAAU,EACN,SAAS,CAAC,aAAa,EAAE,WAAW,EAAE,gBAAgB,CAAC,GACvD,UAAU,CAAC,aAAa,EAAE,WAAW,EAAE,gBAAgB,CAAC,EAC5D,OAAO,EAAE,kBAAkB,GAC1B,IAAI;aAES,cAAc,CAC5B,aAAa,SAAS,cAAc,EACpC,WAAW,SAAS,cAAc,EAElC,QAAQ,EAAE,iBAAiB,CAAC,WAAW,CAAC,EACxC,UAAU,EACN,SAAS,CAAC,aAAa,EAAE,WAAW,EAAE,gBAAgB,CAAC,GACvD,UAAU,CAAC,aAAa,EAAE,WAAW,EAAE,gBAAgB,CAAC,EAC5D,OAAO,EAAE,kBAAkB,GAC1B,IAAI;aAES,WAAW,CAAC,SAAS,SAAS,MAAM,EAClD,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,EACzC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,kBAAkB,GAC1B,oBAAoB;aAEP,aAAa,CAAC,SAAS,SAAS,MAAM,EACpD,KAAK,EAAE,WAAW,CAAC,SAAS,CAAC,EAC7B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,kBAAkB,GAC1B,IAAI;aAES,YAAY,CAAC,SAAS,SAAS,MAAM,EACnD,KAAK,EAAE,WAAW,CAAC,SAAS,CAAC,EAC7B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,kBAAkB,GAC1B,IAAI;CACR"}
@@ -1,30 +1,11 @@
1
1
  /**
2
- * Abstract Class for translating criteria into various query formats
3
- * @template TranslationContext - The target format (e.g., QueryBuilder, raw SQL string, etc.)
4
- * @template TranslationOutput - The output format by default its Source (Only specify this if
5
- * you really need something like a memory translator and the output would be different
6
- * from the TranslationContext itself)
7
- * @template RootSchema - The schema type for the root criteria
8
- * @example
9
- * // TypeORM QueryBuilder translator
10
- * class TypeORMTranslator implements CriteriaTranslator<SelectQueryBuilder<Entity>> {
11
- * ...Concrete implementation
12
- * }
2
+ * An abstract base class for creating specific criteria translators.
3
+ * It implements the ICriteriaVisitor interface and provides a structured way to handle the translation process.
13
4
  *
14
- * // Raw MySQL translator
15
- * export class MysqlTranslator extends CriteriaTranslator<string, string> { {
16
- * ...Concrete implementation
17
- * }
5
+ * @template TranslationContext The mutable context object (e.g., a query builder) passed through the traversal.
6
+ * @template TranslationOutput The final result type of the translation process. Defaults to `TranslationContext`.
7
+ * @template TFilterVisitorOutput The specific type returned by `visitFilter`.
18
8
  */
19
9
  export class CriteriaTranslator {
20
- /**
21
- * Translates a criteria into the target source format
22
- * @param criteria - The criteria to translate
23
- * @param source - The source object to translate into (e.g., QueryBuilder instance, or raw SQL string)
24
- * @returns The modified source or the output format if specified
25
- */
26
- translate(criteria, source) {
27
- return criteria.accept(this, source);
28
- }
29
10
  }
30
11
  //# sourceMappingURL=criteria-translator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"criteria-translator.js","sourceRoot":"","sources":["../../../src/criteria/translator/criteria-translator.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAgB,kBAAkB;IAWtC;;;;;OAKG;IACH,SAAS,CACP,QAGC,EACD,MAA0B;QAE1B,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;CAiEF"}
1
+ {"version":3,"file":"criteria-translator.js","sourceRoot":"","sources":["../../../src/criteria/translator/criteria-translator.ts"],"names":[],"mappings":"AAcA;;;;;;;GAOG;AACH,MAAM,OAAgB,kBAAkB;CAyEvC"}
@@ -1,24 +1,37 @@
1
- import type { CriteriaSchema, FieldOfSchema, SelectedAliasOf } from './schema.types.js';
1
+ import type { CriteriaSchema, FieldOfSchema } from './schema.types.js';
2
2
  import type { FilterGroup } from '../filter/filter-group.js';
3
3
  import type { Cursor } from '../cursor.js';
4
4
  import type { Order, OrderDirection } from '../order/order.js';
5
5
  import { FilterOperator } from './operator.types.js';
6
- import type { StoredJoinDetails, JoinCriteriaParameterType, JoinParameterType, SpecificMatchingJoinConfig } from './join-utility.types.js';
6
+ import type { StoredJoinDetails, JoinCriteriaType } from './join-utility.types.js';
7
7
  import type { FilterPrimitive } from '../filter/types/filter-primitive.types.js';
8
8
  /**
9
9
  * Base interface for defining query criteria.
10
10
  * It provides methods for filtering, joining, selecting fields, ordering, and paginating results.
11
11
  * @template TSchema - The schema definition for the primary entity.
12
- * @template CurrentAlias - The selected alias for the primary entity from its schema.
13
12
  */
14
- export interface ICriteriaBase<TSchema extends CriteriaSchema, CurrentAlias extends SelectedAliasOf<TSchema>> {
13
+ export interface ICriteriaBase<TSchema extends CriteriaSchema> {
14
+ /**
15
+ * Gets the metadata associated with the root schema of this criteria.
16
+ * @returns {TSchema['metadata']} The metadata object from the schema, which can be undefined.
17
+ */
18
+ get schemaMetadata(): TSchema['metadata'];
19
+ /**
20
+ * Gets the name of the identifier field for the current schema.
21
+ * @returns {FieldOfSchema<TSchema>} The name of the identifier field.
22
+ */
23
+ get identifierField(): FieldOfSchema<TSchema>;
15
24
  /**
16
25
  * Configures the criteria to select all available fields from the root entity
17
26
  * and any joined entities that also have `selectAll()` called or by default.
18
27
  * This overrides any previous specific selections made by `setSelect()`.
19
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
28
+ * @returns {this} The current criteria instance for chaining.
29
+ */
30
+ resetSelect(): this;
31
+ /**
32
+ * Indicates whether all fields are currently selected for the root entity.
33
+ * @returns {boolean} True if all fields are selected, false otherwise.
20
34
  */
21
- resetSelect(): ICriteriaBase<TSchema, CurrentAlias>;
22
35
  get selectAll(): boolean;
23
36
  /**
24
37
  * Sets the cursor for pagination. A cursor defines a point from which to fetch
@@ -35,10 +48,10 @@ export interface ICriteriaBase<TSchema extends CriteriaSchema, CurrentAlias exte
35
48
  * @param {OrderDirection} order - The direction of ordering that matches the cursor logic.
36
49
  * If operator is GREATER_THAN, order should typically be ASC.
37
50
  * If operator is LESS_THAN, order should typically be DESC.
38
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
51
+ * @returns {this} The current criteria instance for chaining.
39
52
  * @throws {Error} If filterPrimitive does not contain exactly 1 or 2 elements.
40
53
  * @throws {Error} If any cursor field is not defined in the schema.
41
- * @throws {Error} If any cursor value is null or undefined.
54
+ * @throws {Error} If any cursor value is undefined (null is allowed).
42
55
  * @throws {Error} If the two cursor fields are identical.
43
56
  */
44
57
  setCursor<Operator extends FilterOperator.GREATER_THAN | FilterOperator.LESS_THAN>(filterPrimitives: readonly [
@@ -46,8 +59,7 @@ export interface ICriteriaBase<TSchema extends CriteriaSchema, CurrentAlias exte
46
59
  ] | readonly [
47
60
  Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>,
48
61
  Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>
49
- ], operator: Operator, order: OrderDirection): ICriteriaBase<TSchema, CurrentAlias>;
50
- resetCriteria(): ICriteriaBase<TSchema, CurrentAlias>;
62
+ ], operator: Operator, order: OrderDirection): this;
51
63
  /**
52
64
  * Gets the current cursor configuration, if set.
53
65
  * @returns {Cursor<FieldOfSchema<TSchema>> | undefined} The cursor object or undefined.
@@ -57,10 +69,10 @@ export interface ICriteriaBase<TSchema extends CriteriaSchema, CurrentAlias exte
57
69
  * Specifies which fields to select for the root entity.
58
70
  * Calling this method disables `selectAll()` behavior.
59
71
  * @param {Array<FieldOfSchema<TSchema>>} selectFields - An array of field names to select.
60
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
72
+ * @returns {this} The current criteria instance for chaining.
61
73
  * @throws {Error} If any of the specified fields are not defined in the schema.
62
74
  */
63
- setSelect(selectFields: Array<FieldOfSchema<TSchema>>): ICriteriaBase<TSchema, CurrentAlias>;
75
+ setSelect(selectFields: Array<FieldOfSchema<TSchema>>): this;
64
76
  /**
65
77
  * Gets the currently selected fields. If `selectAll()` was last called or is default,
66
78
  * it returns all fields from the schema.
@@ -72,24 +84,24 @@ export interface ICriteriaBase<TSchema extends CriteriaSchema, CurrentAlias exte
72
84
  * Multiple calls to `orderBy` will append new ordering rules.
73
85
  * @param {FieldOfSchema<TSchema>} field - The field to order by.
74
86
  * @param {OrderDirection} direction - The direction of the ordering (ASC or DESC).
75
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
87
+ * @returns {this} The current criteria instance for chaining.
76
88
  * @throws {Error} If the specified field is not defined in the schema.
77
89
  */
78
- orderBy(field: FieldOfSchema<TSchema>, direction: OrderDirection): ICriteriaBase<TSchema, CurrentAlias>;
90
+ orderBy(field: FieldOfSchema<TSchema>, direction: OrderDirection): this;
79
91
  /**
80
92
  * Sets the maximum number of records to return (LIMIT).
81
93
  * @param {number} amount - The number of records to take. Must be non-negative.
82
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
94
+ * @returns {this} The current criteria instance for chaining.
83
95
  * @throws {Error} If the amount is negative.
84
96
  */
85
- setTake(amount: number): ICriteriaBase<TSchema, CurrentAlias>;
97
+ setTake(amount: number): this;
86
98
  /**
87
99
  * Sets the number of records to skip before starting to return records (OFFSET).
88
100
  * @param {number} amount - The number of records to skip. Must be non-negative.
89
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
101
+ * @returns {this} The current criteria instance for chaining.
90
102
  * @throws {Error} If the amount is negative.
91
103
  */
92
- setSkip(amount: number): ICriteriaBase<TSchema, CurrentAlias>;
104
+ setSkip(amount: number): this;
93
105
  /**
94
106
  * Gets the configured join details.
95
107
  * @returns {ReadonlyArray<StoredJoinDetails<TSchema>>} An array of join configurations.
@@ -102,9 +114,9 @@ export interface ICriteriaBase<TSchema extends CriteriaSchema, CurrentAlias exte
102
114
  get rootFilterGroup(): FilterGroup;
103
115
  /**
104
116
  * Gets the alias for the root entity of this criteria.
105
- * @returns {CurrentAlias} The alias string.
117
+ * @returns {TSchema['alias']} The alias string.
106
118
  */
107
- get alias(): CurrentAlias;
119
+ get alias(): TSchema['alias'];
108
120
  /**
109
121
  * Gets the source name (e.g., table name) for the root entity of this criteria.
110
122
  * @returns {TSchema['source_name']} The source name string.
@@ -127,42 +139,46 @@ export interface ICriteriaBase<TSchema extends CriteriaSchema, CurrentAlias exte
127
139
  get orders(): readonly Order[];
128
140
  /**
129
141
  * Initializes the filter criteria with a single filter primitive.
130
- * This replaces any existing filters.
131
- * @param {FilterPrimitive<FieldOfSchema<TSchema>>} filterPrimitive - The filter to apply.
132
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
142
+ * This replaces any existing filters in the root filter group.
143
+ * @template Operator - The specific filter operator type.
144
+ * @param {FilterPrimitive<FieldOfSchema<TSchema>, Operator>} filterPrimitive - The filter to apply.
145
+ * @returns {this} The current criteria instance for chaining.
133
146
  * @throws {Error} If the specified field in filterPrimitive is not defined in the schema.
134
147
  */
135
- where<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): ICriteriaBase<TSchema, CurrentAlias>;
148
+ where<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): this;
136
149
  /**
137
150
  * Adds a filter primitive to the current filter group using an AND logical operator.
138
- * @param {FilterPrimitive<FieldOfSchema<TSchema>>} filterPrimitive - The filter to add.
139
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
151
+ * Requires `where()` to have been called first to initialize the filter group.
152
+ * @template Operator - The specific filter operator type.
153
+ * @param {FilterPrimitive<FieldOfSchema<TSchema>, Operator>} filterPrimitive - The filter to add.
154
+ * @returns {this} The current criteria instance for chaining.
140
155
  * @throws {Error} If the specified field in filterPrimitive is not defined in the schema.
141
156
  * @throws {Error} If `where()` has not been called first.
142
157
  */
143
- andWhere<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): ICriteriaBase<TSchema, CurrentAlias>;
158
+ andWhere<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): this;
144
159
  /**
145
- * Adds a filter primitive, creating a new OR group with the existing filters.
146
- * @param {FilterPrimitive<FieldOfSchema<TSchema>>} filterPrimitive - The filter to add.
147
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
160
+ * Adds a filter primitive to the current filter group using an OR logical operator.
161
+ * Requires `where()` to have been called first to initialize the filter group.
162
+ * @template Operator - The specific filter operator type.
163
+ * @param {FilterPrimitive<FieldOfSchema<TSchema>, Operator>} filterPrimitive - The filter to add.
164
+ * @returns {this} The current criteria instance for chaining.
148
165
  * @throws {Error} If the specified field in filterPrimitive is not defined in the schema.
149
166
  * @throws {Error} If `where()` has not been called first.
150
167
  */
151
- orWhere<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): ICriteriaBase<TSchema, CurrentAlias>;
168
+ orWhere<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): this;
152
169
  /**
153
- * Adds a join to another criteria.
170
+ * Adds a join to another criteria. This method is fully type-safe.
171
+ * The `joinAlias` argument provides autocompletion for all valid relation aliases defined in the schema.
172
+ * The `criteriaToJoin` argument is then validated to ensure its `source_name` matches the one
173
+ * configured for the chosen `joinAlias`, providing clear, compile-time error messages if they mismatch.
174
+ *
154
175
  * @template TJoinSchema - The schema of the entity to join.
155
- * @template TJoinedCriteriaAlias - The alias for the joined entity.
156
- * @template TMatchingJoinConfig - The specific join configuration from the parent schema that matches the joined alias.
157
- * @param {JoinCriteriaParameterType<TSchema, TJoinSchema, TJoinedCriteriaAlias, TMatchingJoinConfig>} criteriaToJoin
158
- * The criteria instance representing the entity to join (e.g., `InnerJoinCriteria`, `LeftJoinCriteria`).
159
- * @param {JoinParameterType<TSchema, TJoinSchema, TMatchingJoinConfig>} joinParameter
160
- * The parameters defining how the join should be performed (e.g., fields for simple join, pivot table details for many-to-many).
161
- * @returns {ICriteriaBase<TSchema, CurrentAlias>} The current criteria instance for chaining.
162
- * @throws {Error} If the join configuration for the given alias is not found in the parent schema.
163
- * @throws {Error} If `parent_field` in `joinParameter` is not defined in the parent schema.
164
- * @throws {Error} If `joinParameter` is invalid for the `join_relation_type` defined in the schema (e.g., using simple join input for many-to-many).
165
- */
166
- join<TJoinSchema extends CriteriaSchema, TJoinedCriteriaAlias extends SelectedAliasOf<TJoinSchema>, TMatchingJoinConfig extends SpecificMatchingJoinConfig<TSchema, TJoinedCriteriaAlias>>(criteriaToJoin: JoinCriteriaParameterType<TSchema, TJoinSchema, TJoinedCriteriaAlias, TMatchingJoinConfig>, joinParameter: JoinParameterType<TSchema, TJoinSchema, TMatchingJoinConfig>): ICriteriaBase<TSchema, CurrentAlias>;
176
+ * @template SpecificRelationAlias - The literal type of the relation alias being used for the join.
177
+ * @param {SpecificRelationAlias} joinAlias - The specific alias defined in the parent schema's `relations` array for this relation.
178
+ * @param {JoinCriteriaType<TSchema, TJoinSchema, SpecificRelationAlias>} criteriaToJoin - The criteria instance representing the entity to join (e.g., `InnerJoinCriteria`).
179
+ * @param {boolean} [withSelect=true] - If true (default), the joined entity's fields will be included in the final selection. If false, the join will only be used for filtering and its fields will not be selected.
180
+ * @returns {this} The current criteria instance for chaining.
181
+ */
182
+ join<const TJoinSchema extends CriteriaSchema, const SpecificRelationAlias extends TSchema['relations'][number]['relation_alias']>(joinAlias: SpecificRelationAlias, criteriaToJoin: JoinCriteriaType<TSchema, TJoinSchema, SpecificRelationAlias>, withSelect: boolean): this;
167
183
  }
168
184
  //# sourceMappingURL=criteria.interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"criteria.interface.d.ts","sourceRoot":"","sources":["../../../src/criteria/types/criteria.interface.ts"],"names":[],"mappings":"AAAA,OAAO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,cAAc,EACxC,KAAK,CAAC,qBAAqB,SACzB,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,gBAAgB,CAAC,EAEhD,SAAS,EAAE,qBAAqB,EAChC,cAAc,EAAE,gBAAgB,CAC9B,OAAO,EACP,WAAW,EACX,qBAAqB,CACtB,EACD,UAAU,EAAE,OAAO,GAClB,IAAI,CAAC;CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"criteria.interface.js","sourceRoot":"","sources":["../../../src/criteria/types/criteria.interface.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"criteria.interface.js","sourceRoot":"","sources":["../../../src/criteria/types/criteria.interface.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}