@nulledexp/translatable-criteria 1.2.0 → 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.
- package/README.md +91 -86
- package/dist/criteria/criteria-factory.d.ts +6 -5
- package/dist/criteria/criteria-factory.d.ts.map +1 -1
- package/dist/criteria/criteria-factory.js +8 -8
- package/dist/criteria/criteria-factory.js.map +1 -1
- package/dist/criteria/criteria-filter-manager.d.ts.map +1 -1
- package/dist/criteria/criteria-join-manager.d.ts +2 -2
- package/dist/criteria/criteria-join-manager.d.ts.map +1 -1
- package/dist/criteria/criteria-join-manager.js.map +1 -1
- package/dist/criteria/criteria.d.ts +45 -35
- package/dist/criteria/criteria.d.ts.map +1 -1
- package/dist/criteria/criteria.js +82 -69
- package/dist/criteria/criteria.js.map +1 -1
- package/dist/criteria/cursor.d.ts +15 -0
- package/dist/criteria/cursor.d.ts.map +1 -1
- package/dist/criteria/cursor.js +22 -0
- package/dist/criteria/cursor.js.map +1 -1
- package/dist/criteria/filter/filter-group.d.ts +7 -1
- package/dist/criteria/filter/filter-group.d.ts.map +1 -1
- package/dist/criteria/filter/filter-group.js +12 -3
- package/dist/criteria/filter/filter-group.js.map +1 -1
- package/dist/criteria/filter/filter.d.ts +3 -3
- package/dist/criteria/filter/filter.d.ts.map +1 -1
- package/dist/criteria/filter/filter.js +37 -14
- package/dist/criteria/filter/filter.js.map +1 -1
- package/dist/criteria/filter/types/filter-primitive.types.d.ts +21 -11
- package/dist/criteria/filter/types/filter-primitive.types.d.ts.map +1 -1
- package/dist/criteria/index.d.ts +2 -2
- package/dist/criteria/index.d.ts.map +1 -1
- package/dist/criteria/index.js.map +1 -1
- package/dist/criteria/join/inner.join-criteria.d.ts +10 -17
- package/dist/criteria/join/inner.join-criteria.d.ts.map +1 -1
- package/dist/criteria/join/inner.join-criteria.js +11 -18
- package/dist/criteria/join/inner.join-criteria.js.map +1 -1
- package/dist/criteria/join/left.join-criteria.d.ts +4 -4
- package/dist/criteria/join/left.join-criteria.d.ts.map +1 -1
- package/dist/criteria/join/left.join-criteria.js +5 -5
- package/dist/criteria/join/left.join-criteria.js.map +1 -1
- package/dist/criteria/join/outer.join-criteria.d.ts +13 -16
- package/dist/criteria/join/outer.join-criteria.d.ts.map +1 -1
- package/dist/criteria/join/outer.join-criteria.js +14 -17
- package/dist/criteria/join/outer.join-criteria.js.map +1 -1
- package/dist/criteria/order/order.d.ts +18 -1
- package/dist/criteria/order/order.d.ts.map +1 -1
- package/dist/criteria/order/order.js +21 -1
- package/dist/criteria/order/order.js.map +1 -1
- package/dist/criteria/root.criteria.d.ts +6 -16
- package/dist/criteria/root.criteria.d.ts.map +1 -1
- package/dist/criteria/root.criteria.js +4 -14
- package/dist/criteria/root.criteria.js.map +1 -1
- package/dist/criteria/translator/criteria-translator.d.ts +23 -32
- package/dist/criteria/translator/criteria-translator.d.ts.map +1 -1
- package/dist/criteria/translator/criteria-translator.js +5 -24
- package/dist/criteria/translator/criteria-translator.js.map +1 -1
- package/dist/criteria/types/criteria.interface.d.ts +35 -22
- package/dist/criteria/types/criteria.interface.d.ts.map +1 -1
- package/dist/criteria/types/criteria.interface.js.map +1 -1
- package/dist/criteria/types/join-parameter.types.d.ts +27 -9
- package/dist/criteria/types/join-parameter.types.d.ts.map +1 -1
- package/dist/criteria/types/join-utility.types.d.ts +26 -32
- package/dist/criteria/types/join-utility.types.d.ts.map +1 -1
- package/dist/criteria/types/manager.interface.d.ts +3 -3
- package/dist/criteria/types/manager.interface.d.ts.map +1 -1
- package/dist/criteria/types/operator.types.d.ts +92 -86
- package/dist/criteria/types/operator.types.d.ts.map +1 -1
- package/dist/criteria/types/operator.types.js +91 -85
- package/dist/criteria/types/operator.types.js.map +1 -1
- package/dist/criteria/types/schema.types.d.ts +109 -41
- package/dist/criteria/types/schema.types.d.ts.map +1 -1
- package/dist/criteria/types/schema.types.js +38 -11
- package/dist/criteria/types/schema.types.js.map +1 -1
- package/dist/criteria/types/visitor-interface.types.d.ts +33 -12
- package/dist/criteria/types/visitor-interface.types.d.ts.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@nulledexp/translatable-criteria)
|
|
4
4
|

|
|
5
5
|
[]()
|
|
6
|
-
[](./src/docs/introduction/en.md)
|
|
7
|
+
[](./src/docs/introduction/es.md)
|
|
7
8
|
[](https://github.com/Techscq/translatable-criteria/actions/workflows/ci.yml)
|
|
8
9
|
|
|
9
10
|
A TypeScript library for building data-source agnostic, translatable query criteria. Define complex filtering, ordering, and join logic in a structured, type-safe way, then translate it to your specific data source using custom translators.
|
|
@@ -16,84 +17,90 @@ npm install @nulledexp/translatable-criteria
|
|
|
16
17
|
|
|
17
18
|
## Overview
|
|
18
19
|
|
|
19
|
-
This library simplifies the construction of complex data queries by providing a consistent and abstract way to define filtering, ordering, field selection, pagination (offset and cursor-based), and relationship (joins) configurations. The core concept revolves around the `Criteria` object hierarchy, which allows developers to define sophisticated query specifications in a data source-agnostic manner. These `Criteria` objects can then be processed by a `CriteriaTranslator`
|
|
20
|
+
This library simplifies the construction of complex data queries by providing a consistent and abstract way to define filtering, ordering, field selection, pagination (offset and cursor-based), and relationship (joins) configurations. The core concept revolves around the `Criteria` object hierarchy, which allows developers to define sophisticated query specifications in a data source-agnostic manner, now with enhanced schema validation (including `identifier_field`) and richer context for translators (like `parent_identifier`). These `Criteria` objects can then be processed by a `CriteriaTranslator` to generate queries for various data sources.
|
|
20
21
|
|
|
21
22
|
## Key Features
|
|
22
23
|
|
|
23
|
-
- **Enhanced Type-Safety:** Construct queries with a fluent, strongly-typed interface, benefiting from compile-time and runtime validation of field names, aliases, and join parameters based on your schemas.
|
|
24
|
-
- **Powerful Filtering:** Define intricate filtering logic with multiple operators (including for JSON and
|
|
25
|
-
- **Flexible Join System:** Support for various join types (inner, left, full outer) and pivot table configurations
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
24
|
+
- **Enhanced Type-Safety:** Construct queries with a fluent, strongly-typed interface, benefiting from compile-time and runtime validation of field names (including `identifier_field`), aliases, and join parameters based on your schemas.
|
|
25
|
+
- **Powerful Filtering:** Define intricate filtering logic with multiple operators (including for JSON, arrays, sets, ranges, and regex) and grouping. Filter groups are automatically normalized for consistency.
|
|
26
|
+
- **Flexible Join System:** Support for various join types (inner, left, full outer) and pivot table configurations. Join parameters now include `parent_identifier` to provide richer context to translators for relationship inference (e.g., for `one_to_one`).
|
|
27
|
+
- **Granular Null-Value Sorting:** Explicitly control whether `NULL` values appear first or last in your ordered results.
|
|
28
|
+
- **Filter-Only Joins:** Improve query performance by creating joins solely for filtering, without including their fields in the final `SELECT` statement.
|
|
29
|
+
- **Field Selection & `identifier_field`:** Specify exactly which fields to retrieve using `setSelect()`. The `identifier_field` of an entity is automatically included when `setSelect()` is used. Use `resetSelect()` to select all fields (default behavior).
|
|
28
30
|
- **Pagination:** Supports both offset-based (`setTake()`, `setSkip()`) and cursor-based (`setCursor()`) pagination.
|
|
29
|
-
- **Visitor Pattern for Translation:** Criteria objects implement an `accept` method, allowing for clean and extensible translation logic via the Visitor pattern.
|
|
30
31
|
- **Data Source Agnostic:** Design criteria independently of the underlying data source.
|
|
31
32
|
- **Translator-Based Architecture:** The core library defines criteria; actual translation is handled by separate translator packages that implement the `CriteriaTranslator` interface.
|
|
32
33
|
- **Full TypeScript Support:** Benefit from compile-time validation and autocompletion.
|
|
33
34
|
|
|
34
35
|
## Core Concepts
|
|
35
36
|
|
|
36
|
-
The library is built upon a few fundamental concepts. For detailed explanations, please refer to our
|
|
37
|
+
The library is built upon a few fundamental concepts. For detailed explanations, please refer to our documentation guides.
|
|
37
38
|
|
|
38
|
-
- **`Criteria` Hierarchy:** Abstract base for query specifications (`RootCriteria`, `InnerJoinCriteria`, etc.).
|
|
39
|
-
- **`CriteriaFactory`:** Recommended utility for creating `Criteria` instances
|
|
40
|
-
- **Schemas (`CriteriaSchema` & `GetTypedCriteriaSchema`):** Define your data entities' structure for type-safe criteria construction.
|
|
41
|
-
- **`CriteriaTranslator`:** Abstract class for converting `Criteria` objects into specific data source queries
|
|
39
|
+
- [**`Criteria` Hierarchy:**](./src/docs/core-concepts/en.md#criteria-hierarchy) Abstract base for query specifications (`RootCriteria`, `InnerJoinCriteria`, etc.).
|
|
40
|
+
- [**`CriteriaFactory`:**](./src/docs/core-concepts/en.md#criteriafactory) Recommended utility for creating `Criteria` instances.
|
|
41
|
+
- [**Schemas (`CriteriaSchema` & `GetTypedCriteriaSchema`):**](./src/docs/guides/schema-definitions/en.md) Define your data entities' structure for type-safe criteria construction.
|
|
42
|
+
- [**`CriteriaTranslator`:**](./src/docs/guides/developing-translators/en.md) Abstract class responsible for converting `Criteria` objects into specific data source queries.
|
|
42
43
|
|
|
43
44
|
## Usage Example (Core Library)
|
|
44
45
|
|
|
45
|
-
This package provides the tools to define your query criteria.
|
|
46
|
+
This package provides the tools to define your query criteria. The core philosophy is to define relationship logic **once** in the schema, and then simply reference it when building criteria.
|
|
46
47
|
|
|
47
48
|
### 1. Define Schemas
|
|
48
49
|
|
|
50
|
+
First, define your entity schemas using `GetTypedCriteriaSchema`. This is where you declare how entities are related by defining `local_field`, `relation_field`, etc.
|
|
51
|
+
|
|
49
52
|
```typescript
|
|
50
53
|
import { GetTypedCriteriaSchema } from '@nulledexp/translatable-criteria';
|
|
51
54
|
|
|
52
55
|
export const UserSchema = GetTypedCriteriaSchema({
|
|
53
|
-
source_name: '
|
|
54
|
-
alias:
|
|
55
|
-
fields: ['
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
source_name: 'users',
|
|
57
|
+
alias: 'u',
|
|
58
|
+
fields: ['id', 'username', 'email', 'age', 'isActive', 'createdAt'],
|
|
59
|
+
identifier_field: 'id',
|
|
60
|
+
relations: [
|
|
61
|
+
{
|
|
62
|
+
is_relation_id: false,
|
|
63
|
+
relation_alias: 'posts',
|
|
64
|
+
target_source_name: 'posts',
|
|
65
|
+
relation_type: 'one_to_many',
|
|
66
|
+
local_field: 'id',
|
|
67
|
+
relation_field: 'userId',
|
|
68
|
+
},
|
|
59
69
|
],
|
|
60
70
|
});
|
|
61
|
-
export type UserSchema = typeof UserSchema;
|
|
62
71
|
|
|
63
72
|
export const PostSchema = GetTypedCriteriaSchema({
|
|
64
|
-
source_name: '
|
|
65
|
-
alias:
|
|
66
|
-
fields: [
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
{ alias: 'publisher', relation_type: 'many_to_one' },
|
|
73
|
+
source_name: 'posts',
|
|
74
|
+
alias: 'p',
|
|
75
|
+
fields: ['id', 'title', 'content', 'userId', 'createdAt'],
|
|
76
|
+
identifier_field: 'id',
|
|
77
|
+
relations: [
|
|
78
|
+
{
|
|
79
|
+
is_relation_id: false,
|
|
80
|
+
relation_alias: 'user',
|
|
81
|
+
target_source_name: 'users',
|
|
82
|
+
relation_type: 'many_to_one',
|
|
83
|
+
local_field: 'userId',
|
|
84
|
+
relation_field: 'id',
|
|
85
|
+
},
|
|
78
86
|
],
|
|
79
87
|
});
|
|
80
|
-
export type PostSchema = typeof PostSchema;
|
|
81
|
-
|
|
82
|
-
// Define other schemas (PermissionSchema, PostCommentSchema, AddressSchema) as needed for your application.
|
|
83
|
-
// See the full documentation for more examples.
|
|
84
88
|
```
|
|
85
89
|
|
|
86
|
-
### 2. Create Criteria
|
|
90
|
+
### 2. Create a Simple Criteria
|
|
91
|
+
|
|
92
|
+
Use `CriteriaFactory` to create a `Criteria` object and apply filters or ordering.
|
|
87
93
|
|
|
88
94
|
```typescript
|
|
89
95
|
import {
|
|
90
96
|
CriteriaFactory,
|
|
91
97
|
FilterOperator,
|
|
98
|
+
OrderDirection,
|
|
92
99
|
} from '@nulledexp/translatable-criteria';
|
|
93
|
-
import { UserSchema } from './path/to/your/
|
|
100
|
+
import { UserSchema } from './path/to/your/schemas'; // Adjust path
|
|
94
101
|
|
|
95
102
|
// Create Criteria for the User entity
|
|
96
|
-
const userCriteria = CriteriaFactory.GetCriteria(UserSchema
|
|
103
|
+
const userCriteria = CriteriaFactory.GetCriteria(UserSchema);
|
|
97
104
|
|
|
98
105
|
// Example: Add a simple filter
|
|
99
106
|
userCriteria.where({
|
|
@@ -103,17 +110,45 @@ userCriteria.where({
|
|
|
103
110
|
});
|
|
104
111
|
|
|
105
112
|
// Example: Add ordering
|
|
106
|
-
userCriteria.orderBy('
|
|
113
|
+
userCriteria.orderBy('createdAt', OrderDirection.DESC);
|
|
107
114
|
|
|
108
115
|
// The 'userCriteria' object is now ready to be passed to a translator.
|
|
109
116
|
```
|
|
110
117
|
|
|
118
|
+
### 3. Create Criteria with a Join
|
|
119
|
+
|
|
120
|
+
To add a join, simply call the `.join()` method with the `relation_alias` you defined in the schema. The library automatically uses the configuration you provided, eliminating the need for manual join parameters.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import {
|
|
124
|
+
CriteriaFactory,
|
|
125
|
+
FilterOperator,
|
|
126
|
+
} from '@nulledexp/translatable-criteria';
|
|
127
|
+
import { PostSchema, UserSchema } from './path/to/your/schemas'; // Adjust path
|
|
128
|
+
|
|
129
|
+
// Find posts from active users
|
|
130
|
+
const postCriteria = CriteriaFactory.GetCriteria(PostSchema);
|
|
131
|
+
|
|
132
|
+
const activeUserJoin = CriteriaFactory.GetInnerJoinCriteria(UserSchema).where({
|
|
133
|
+
field: 'isActive',
|
|
134
|
+
operator: FilterOperator.EQUALS,
|
|
135
|
+
value: true,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// The join is now declarative. Just provide the relation alias.
|
|
139
|
+
postCriteria.join('user', activeUserJoin);
|
|
140
|
+
|
|
141
|
+
// The 'postCriteria' object is now ready to be passed to a translator.
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
111
146
|
## Available Translators
|
|
112
147
|
|
|
113
|
-
To interact with a database, you'll need a translator package.
|
|
148
|
+
To interact with a database, you'll need a translator package. You can either build your own following our Criteria Translator Development Guide or use one from the community.
|
|
114
149
|
|
|
115
150
|
- **`@nulledexp/typeorm-mysql-criteria-translator`**:
|
|
116
|
-
A translator for generating TypeORM `SelectQueryBuilder` instances for MySQL.
|
|
151
|
+
- A translator for generating TypeORM `SelectQueryBuilder` instances for MySQL.
|
|
117
152
|
- **Author:** Nelson Cabrera
|
|
118
153
|
- **Installation**:
|
|
119
154
|
|
|
@@ -121,58 +156,24 @@ To interact with a database, you'll need a translator package.
|
|
|
121
156
|
npm install @nulledexp/typeorm-mysql-criteria-translator
|
|
122
157
|
```
|
|
123
158
|
|
|
124
|
-
- **Usage
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
import {
|
|
128
|
-
CriteriaFactory,
|
|
129
|
-
FilterOperator,
|
|
130
|
-
} from '@nulledexp/translatable-criteria';
|
|
131
|
-
import { TypeOrmMysqlTranslator } from '@nulledexp/typeorm-mysql-criteria-translator'; // Using new suggested name
|
|
132
|
-
import { UserSchema } from './path/to/your/criteria/schemas'; // Your Criteria Schema
|
|
133
|
-
// import { YourTypeOrmUserEntity } from './path/to/your/typeorm/entities'; // Your actual TypeORM entity
|
|
134
|
-
// import { DbDatasource } from './path-to-your-datasource-config'; // Your initialized TypeORM DataSource instance
|
|
135
|
-
|
|
136
|
-
// 1. Define your Criteria using @nulledexp/translatable-criteria
|
|
137
|
-
const criteria = CriteriaFactory.GetCriteria(UserSchema, 'users') // 'users' is an alias from UserSchema
|
|
138
|
-
.where({
|
|
139
|
-
field: 'username', // Field from UserSchema
|
|
140
|
-
operator: FilterOperator.EQUALS,
|
|
141
|
-
value: 'testuser',
|
|
142
|
-
})
|
|
143
|
-
.setTake(10);
|
|
144
|
-
|
|
145
|
-
// 2. Use the translator with your TypeORM QueryBuilder
|
|
146
|
-
// (Conceptual - assuming DbDatasource and YourTypeOrmUserEntity are set up)
|
|
147
|
-
|
|
148
|
-
// const queryBuilder = DbDatasource.getRepository(YourTypeOrmUserEntity)
|
|
149
|
-
// .createQueryBuilder(criteria.alias); // Alias must match root criteria alias
|
|
150
|
-
|
|
151
|
-
// const translator = new TypeOrmMysqlTranslator<YourTypeOrmUserEntity>();
|
|
152
|
-
// translator.translate(criteria, queryBuilder);
|
|
153
|
-
|
|
154
|
-
// Now queryBuilder is populated with the translated criteria
|
|
155
|
-
// console.log(queryBuilder.getSql(), queryBuilder.getParameters());
|
|
156
|
-
// const results = await queryBuilder.getMany();
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
- **Note:** This translator has been tested with integration tests. Please review its implementation at its repository (replace with actual repo link if different) to ensure it meets your specific project needs and production requirements. Contributions and bug reports are welcome!
|
|
159
|
+
- **Usage:**
|
|
160
|
+
- See the TypeORM Translator Usage Guide for detailed instructions.
|
|
160
161
|
|
|
161
162
|
- **(More translators coming soon or can be created by the community)**
|
|
162
163
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
You can create your own translators by extending the abstract `CriteriaTranslator` class. See the Developing Custom Translators Guide for details.
|
|
164
|
+
**Important Note for Translator Developers:** Translators should be updated to handle the new `parent_identifier` in join parameters (especially for inferring `one_to_one` relationships) and to support the new filter operators. Refer to the Developing Custom Translators Guide for details.
|
|
166
165
|
|
|
167
166
|
## Type Safety Features
|
|
168
167
|
|
|
169
168
|
- Compile-time validation of field names within criteria based on schemas.
|
|
169
|
+
- Validation of `identifier_field` definition within schemas.
|
|
170
170
|
- Type-checked join configurations ensuring compatibility between schemas.
|
|
171
171
|
- Autocomplete support for schema fields and defined join aliases.
|
|
172
172
|
- Validation of alias usage in `Criteria` constructors.
|
|
173
173
|
- Robust validation of join parameters based on `join_relation_type`.
|
|
174
174
|
- Validation for selected fields, cursor fields, take/skip values.
|
|
175
175
|
- Strictly typed filter values based on the `FilterOperator` used.
|
|
176
|
+
- Inclusion of `parent_identifier` in resolved join parameters for translator use.
|
|
176
177
|
|
|
177
178
|
## Roadmap (Core Library)
|
|
178
179
|
|
|
@@ -182,9 +183,13 @@ You can create your own translators by extending the abstract `CriteriaTranslato
|
|
|
182
183
|
- [x] Implement `LIMIT` and `OFFSET` (take/skip) for pagination.
|
|
183
184
|
- [x] Implement `PivotJoin` for many-to-many relationships.
|
|
184
185
|
- [x] Strictly typed filter values based on operator.
|
|
185
|
-
- [x] New filter operators (JSON, Array, Set).
|
|
186
|
-
- [x] Enhanced documentation with detailed examples for translator development.
|
|
186
|
+
- [x] New filter operators (JSON, Array, Set, Range, Regex, ILIKE).
|
|
187
187
|
- [x] `OuterJoinCriteria` support in the core logic.
|
|
188
|
+
- [x] Introduce `identifier_field` in schemas and `parent_identifier` in join parameters.
|
|
189
|
+
- [x] Enforce stricter schema validation at type level.
|
|
190
|
+
- [x] Implement `NULLS FIRST/LAST` ordering.
|
|
191
|
+
- [x] Implement filter-only joins (`withSelect`).
|
|
192
|
+
- [x] Enhanced documentation with detailed examples for translator development.
|
|
188
193
|
- [ ] Explore utility functions to simplify translator development.
|
|
189
194
|
- [ ] Explore utility functions to simplify schema development.
|
|
190
195
|
- [ ] Add more comprehensive unit test coverage for criteria construction and edge cases.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { RootCriteria } from './root.criteria.js';
|
|
2
|
-
import type { CriteriaSchema
|
|
2
|
+
import type { CriteriaSchema } from './types/schema.types.js';
|
|
3
3
|
import { InnerJoinCriteria } from './join/inner.join-criteria.js';
|
|
4
4
|
import { LeftJoinCriteria } from './join/left.join-criteria.js';
|
|
5
5
|
import { OuterJoinCriteria } from './join/outer.join-criteria.js';
|
|
6
|
+
import type { ValidSchema } from './criteria.js';
|
|
6
7
|
/**
|
|
7
8
|
* Provides static methods for creating instances of different types of `Criteria`.
|
|
8
9
|
* This simplifies the creation of `Criteria` objects and ensures they are instantiated
|
|
@@ -22,7 +23,7 @@ export declare class CriteriaFactory {
|
|
|
22
23
|
*
|
|
23
24
|
* const userCriteria = CriteriaFactory.GetCriteria(UserSchema, 'users');
|
|
24
25
|
*/
|
|
25
|
-
static GetCriteria<CSchema extends CriteriaSchema
|
|
26
|
+
static GetCriteria<CSchema extends CriteriaSchema>(schema: ValidSchema<CSchema>): RootCriteria<CSchema>;
|
|
26
27
|
/**
|
|
27
28
|
* Creates an instance of `InnerJoinCriteria`. Used to define an `INNER JOIN` in a query.
|
|
28
29
|
* @template CSchema - The type of the `CriteriaSchema` for the entity to be joined.
|
|
@@ -37,7 +38,7 @@ export declare class CriteriaFactory {
|
|
|
37
38
|
* const postJoinCriteria = CriteriaFactory.GetInnerJoinCriteria(PostSchema, 'posts');
|
|
38
39
|
* // postJoinCriteria can then be used in the .join() method of another Criteria
|
|
39
40
|
*/
|
|
40
|
-
static GetInnerJoinCriteria<CSchema extends CriteriaSchema
|
|
41
|
+
static GetInnerJoinCriteria<CSchema extends CriteriaSchema>(schema: ValidSchema<CSchema>): InnerJoinCriteria<CSchema>;
|
|
41
42
|
/**
|
|
42
43
|
* Creates an instance of `LeftJoinCriteria`. Used to define a `LEFT JOIN` in a query.
|
|
43
44
|
* @template CSchema - The type of the `CriteriaSchema` for the entity to be joined.
|
|
@@ -51,7 +52,7 @@ export declare class CriteriaFactory {
|
|
|
51
52
|
*
|
|
52
53
|
* const commentJoinCriteria = CriteriaFactory.GetLeftJoinCriteria(CommentSchema, 'comments');
|
|
53
54
|
*/
|
|
54
|
-
static GetLeftJoinCriteria<CSchema extends CriteriaSchema
|
|
55
|
+
static GetLeftJoinCriteria<CSchema extends CriteriaSchema>(schema: ValidSchema<CSchema>): LeftJoinCriteria<CSchema>;
|
|
55
56
|
/**
|
|
56
57
|
* Creates an instance of `OuterJoinCriteria`. Used to define a `FULL OUTER JOIN` in a query.
|
|
57
58
|
* @template CSchema - The type of the `CriteriaSchema` for the entity to be joined.
|
|
@@ -65,6 +66,6 @@ export declare class CriteriaFactory {
|
|
|
65
66
|
*
|
|
66
67
|
* const profileJoinCriteria = CriteriaFactory.GetOuterJoinCriteria(ProfileSchema, 'profiles');
|
|
67
68
|
*/
|
|
68
|
-
static GetOuterJoinCriteria<CSchema extends CriteriaSchema
|
|
69
|
+
static GetOuterJoinCriteria<CSchema extends CriteriaSchema>(schema: ValidSchema<CSchema>): OuterJoinCriteria<CSchema>;
|
|
69
70
|
}
|
|
70
71
|
//# sourceMappingURL=criteria-factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteria-factory.d.ts","sourceRoot":"","sources":["../../src/criteria/criteria-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"criteria-factory.d.ts","sourceRoot":"","sources":["../../src/criteria/criteria-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD;;;;GAIG;AACH,qBAAa,eAAe;IAC1B;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,SAAS,cAAc,EAC/C,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,YAAY,CAAC,OAAO,CAAC;IAIxB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,oBAAoB,CAAC,OAAO,SAAS,cAAc,EACxD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,iBAAiB,CAAC,OAAO,CAAC;IAI7B;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,mBAAmB,CAAC,OAAO,SAAS,cAAc,EACvD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,gBAAgB,CAAC,OAAO,CAAC;IAI5B;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,oBAAoB,CAAC,OAAO,SAAS,cAAc,EACxD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,iBAAiB,CAAC,OAAO,CAAC;CAG9B"}
|
|
@@ -21,8 +21,8 @@ export class CriteriaFactory {
|
|
|
21
21
|
*
|
|
22
22
|
* const userCriteria = CriteriaFactory.GetCriteria(UserSchema, 'users');
|
|
23
23
|
*/
|
|
24
|
-
static GetCriteria(schema
|
|
25
|
-
return new RootCriteria(schema
|
|
24
|
+
static GetCriteria(schema) {
|
|
25
|
+
return new RootCriteria(schema);
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Creates an instance of `InnerJoinCriteria`. Used to define an `INNER JOIN` in a query.
|
|
@@ -38,8 +38,8 @@ export class CriteriaFactory {
|
|
|
38
38
|
* const postJoinCriteria = CriteriaFactory.GetInnerJoinCriteria(PostSchema, 'posts');
|
|
39
39
|
* // postJoinCriteria can then be used in the .join() method of another Criteria
|
|
40
40
|
*/
|
|
41
|
-
static GetInnerJoinCriteria(schema
|
|
42
|
-
return new InnerJoinCriteria(schema
|
|
41
|
+
static GetInnerJoinCriteria(schema) {
|
|
42
|
+
return new InnerJoinCriteria(schema);
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* Creates an instance of `LeftJoinCriteria`. Used to define a `LEFT JOIN` in a query.
|
|
@@ -54,8 +54,8 @@ export class CriteriaFactory {
|
|
|
54
54
|
*
|
|
55
55
|
* const commentJoinCriteria = CriteriaFactory.GetLeftJoinCriteria(CommentSchema, 'comments');
|
|
56
56
|
*/
|
|
57
|
-
static GetLeftJoinCriteria(schema
|
|
58
|
-
return new LeftJoinCriteria(schema
|
|
57
|
+
static GetLeftJoinCriteria(schema) {
|
|
58
|
+
return new LeftJoinCriteria(schema);
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Creates an instance of `OuterJoinCriteria`. Used to define a `FULL OUTER JOIN` in a query.
|
|
@@ -70,8 +70,8 @@ export class CriteriaFactory {
|
|
|
70
70
|
*
|
|
71
71
|
* const profileJoinCriteria = CriteriaFactory.GetOuterJoinCriteria(ProfileSchema, 'profiles');
|
|
72
72
|
*/
|
|
73
|
-
static GetOuterJoinCriteria(schema
|
|
74
|
-
return new OuterJoinCriteria(schema
|
|
73
|
+
static GetOuterJoinCriteria(schema) {
|
|
74
|
+
return new OuterJoinCriteria(schema);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
//# sourceMappingURL=criteria-factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteria-factory.js","sourceRoot":"","sources":["../../src/criteria/criteria-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"criteria-factory.js","sourceRoot":"","sources":["../../src/criteria/criteria-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAGlE;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAC1B;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,WAAW,CAChB,MAA4B;QAE5B,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,oBAAoB,CACzB,MAA4B;QAE5B,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,mBAAmB,CACxB,MAA4B;QAE5B,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,oBAAoB,CACzB,MAA4B;QAE5B,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteria-filter-manager.d.ts","sourceRoot":"","sources":["../../src/criteria/criteria-filter-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEhF,qBAAa,qBAAqB,
|
|
1
|
+
{"version":3,"file":"criteria-filter-manager.d.ts","sourceRoot":"","sources":["../../src/criteria/criteria-filter-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEhF,qBAAa,qBAAqB,CAChC,OAAO,SAAS,cAAc,CAC9B,YAAW,cAAc,CAAC,OAAO,CAAC;IAClC,OAAO,CAAC,gBAAgB,CAGrB;IAEH,KAAK,CAAC,QAAQ,SAAS,cAAc,EACnC,eAAe,EAAE,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,GACjE,IAAI;IAIP,QAAQ,CAAC,QAAQ,SAAS,cAAc,EACtC,eAAe,EAAE,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,GACjE,IAAI;IAIP,OAAO,CAAC,QAAQ,SAAS,cAAc,EACrC,eAAe,EAAE,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,GACjE,IAAI;IAIP,kBAAkB,IAAI,WAAW;CAGlC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { CriteriaSchema
|
|
1
|
+
import type { CriteriaSchema } from './types/schema.types.js';
|
|
2
2
|
import type { IJoinManager } from './types/manager.interface.js';
|
|
3
3
|
import type { PivotJoin, SimpleJoin } from './types/join-parameter.types.js';
|
|
4
4
|
import type { AnyJoinCriteria, StoredJoinDetails } from './types/join-utility.types.js';
|
|
5
5
|
export declare class CriteriaJoinManager<CSchema extends CriteriaSchema> implements IJoinManager<CSchema> {
|
|
6
6
|
private _joins;
|
|
7
|
-
addJoin<JoinSchema extends CriteriaSchema>(criteriaToJoin: AnyJoinCriteria<JoinSchema>, joinParameter: PivotJoin<CSchema, JoinSchema
|
|
7
|
+
addJoin<JoinSchema extends CriteriaSchema>(criteriaToJoin: AnyJoinCriteria<JoinSchema>, joinParameter: PivotJoin<CSchema, JoinSchema> | SimpleJoin<CSchema, JoinSchema>): void;
|
|
8
8
|
getJoins(): Array<StoredJoinDetails<CSchema>>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=criteria-join-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteria-join-manager.d.ts","sourceRoot":"","sources":["../../src/criteria/criteria-join-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"criteria-join-manager.d.ts","sourceRoot":"","sources":["../../src/criteria/criteria-join-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AAEvC,qBAAa,mBAAmB,CAC9B,OAAO,SAAS,cAAc,CAC9B,YAAW,YAAY,CAAC,OAAO,CAAC;IAChC,OAAO,CAAC,MAAM,CAAsD;IAEpE,OAAO,CAAC,UAAU,SAAS,cAAc,EACvC,cAAc,EAAE,eAAe,CAAC,UAAU,CAAC,EAC3C,aAAa,EACT,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,GAC9B,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,GAClC,IAAI;IASP,QAAQ,IAAI,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;CAG9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteria-join-manager.js","sourceRoot":"","sources":["../../src/criteria/criteria-join-manager.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,mBAAmB;IAGtB,MAAM,GAA4C,IAAI,GAAG,EAAE,CAAC;IAEpE,OAAO,CACL,cAA2C,EAC3C,
|
|
1
|
+
{"version":3,"file":"criteria-join-manager.js","sourceRoot":"","sources":["../../src/criteria/criteria-join-manager.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,mBAAmB;IAGtB,MAAM,GAA4C,IAAI,GAAG,EAAE,CAAC;IAEpE,OAAO,CACL,cAA2C,EAC3C,aAEmC;QAEnC,MAAM,WAAW,GAA+B;YAC9C,UAAU,EAAE,aAAa;YACzB,QAAQ,EAAE,cAAiD;SAC5D,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IACrD,CAAC;IAED,QAAQ;QACN,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import type { CriteriaSchema, FieldOfSchema
|
|
1
|
+
import type { CriteriaSchema, FieldOfSchema } from './types/schema.types.js';
|
|
2
2
|
import { Cursor } from './cursor.js';
|
|
3
3
|
import { Order, OrderDirection } from './order/order.js';
|
|
4
4
|
import type { FilterPrimitive } from './filter/types/filter-primitive.types.js';
|
|
5
5
|
import type { ICriteriaBase } from './types/criteria.interface.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { JoinCriteriaType, StoredJoinDetails } from './types/join-utility.types.js';
|
|
7
7
|
import { FilterOperator } from './types/operator.types.js';
|
|
8
8
|
import type { FilterGroup } from './filter/filter-group.js';
|
|
9
|
+
export type ValidSchema<CSchema extends CriteriaSchema> = CSchema['identifier_field'] extends CSchema['fields'][number] ? CSchema : `Schema identifier_field '${CSchema['identifier_field']}' must be one of the schema's defined fields. Schema: ${CSchema['source_name']}`;
|
|
9
10
|
/**
|
|
10
11
|
* Abstract base class for constructing query criteria.
|
|
11
12
|
* It provides a fluent API for defining filters, joins, selections, ordering, and pagination.
|
|
12
13
|
* Concrete criteria types (e.g., RootCriteria, JoinCriteria) will extend this class.
|
|
13
14
|
*
|
|
14
15
|
* @template TSchema - The schema definition for the entity this criteria operates on.
|
|
15
|
-
* @template CurrentAlias - The selected alias for the entity from its schema.
|
|
16
16
|
*/
|
|
17
|
-
export declare abstract class Criteria<TSchema extends CriteriaSchema
|
|
18
|
-
protected readonly schema: TSchema;
|
|
19
|
-
protected _alias: CurrentAlias;
|
|
17
|
+
export declare abstract class Criteria<const TSchema extends CriteriaSchema> implements ICriteriaBase<TSchema> {
|
|
20
18
|
private readonly _filterManager;
|
|
21
19
|
private readonly _joinManager;
|
|
22
20
|
private readonly _source_name;
|
|
@@ -33,24 +31,37 @@ export declare abstract class Criteria<TSchema extends CriteriaSchema, CurrentAl
|
|
|
33
31
|
* @protected
|
|
34
32
|
*/
|
|
35
33
|
protected _cursor: Cursor<FieldOfSchema<TSchema>, FilterOperator.GREATER_THAN | FilterOperator.LESS_THAN> | undefined;
|
|
34
|
+
protected readonly _schema: TSchema;
|
|
36
35
|
/**
|
|
37
36
|
* Initializes a new instance of the Criteria class.
|
|
38
|
-
* @param {TSchema} schema - The schema definition for the entity.
|
|
39
|
-
* @
|
|
40
|
-
* @throws {Error} If the provided alias is not supported by the schema.
|
|
37
|
+
* @param {ValidSchema<TSchema>} schema - The schema definition for the entity.
|
|
38
|
+
* @throws {Error} If the schema's identifier_field is not one of its defined fields.
|
|
41
39
|
* @protected
|
|
42
40
|
*/
|
|
43
|
-
constructor(schema: TSchema
|
|
41
|
+
constructor(schema: ValidSchema<TSchema>);
|
|
42
|
+
get schema(): TSchema;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the metadata associated with the root schema of this criteria.
|
|
45
|
+
* @returns {TSchema['metadata']} The metadata object from the schema, which can be undefined.
|
|
46
|
+
* @remarks This is intended primarily for use by translators.
|
|
47
|
+
*/
|
|
48
|
+
get schemaMetadata(): TSchema['metadata'];
|
|
49
|
+
/**
|
|
50
|
+
* Gets the name of the identifier field for the current schema.
|
|
51
|
+
* @returns {FieldOfSchema<TSchema>} The name of the identifier field.
|
|
52
|
+
*/
|
|
53
|
+
get identifierField(): FieldOfSchema<TSchema>;
|
|
44
54
|
/**
|
|
45
55
|
* Gets the currently selected fields.
|
|
46
|
-
* If `_selectAll` is true, it returns all fields from the schema.
|
|
47
|
-
*
|
|
56
|
+
* If `_selectAll` is true (default or after `resetSelect()`), it returns all fields from the schema.
|
|
57
|
+
* If `_selectAll` is false (after `setSelect()`), it returns the fields explicitly set by the user,
|
|
58
|
+
* plus the schema's `identifier_field` (which is added implicitly by `setSelect`).
|
|
48
59
|
* @returns {Array<FieldOfSchema<TSchema>>} An array of selected field names.
|
|
49
60
|
*/
|
|
50
61
|
get select(): Array<FieldOfSchema<TSchema>>;
|
|
51
62
|
/**
|
|
52
63
|
* Resets the selection to include all fields from the schema.
|
|
53
|
-
*
|
|
64
|
+
* Later calls to `get select()` will return all schema fields
|
|
54
65
|
* until `setSelect()` is called again.
|
|
55
66
|
* @returns {this} The current criteria instance for chaining.
|
|
56
67
|
*/
|
|
@@ -63,6 +74,9 @@ export declare abstract class Criteria<TSchema extends CriteriaSchema, CurrentAl
|
|
|
63
74
|
/**
|
|
64
75
|
* Specifies which fields to select for the entity.
|
|
65
76
|
* Calling this method sets `selectAll` to false.
|
|
77
|
+
* The schema's `identifier_field` will always be included in the selection
|
|
78
|
+
* if it's not already present in `selectFields`.
|
|
79
|
+
* If `selectFields` is empty, only the `identifier_field` will be selected.
|
|
66
80
|
* @param {Array<FieldOfSchema<TSchema>>} selectFields - An array of field names to select.
|
|
67
81
|
* @returns {this} The current criteria instance for chaining.
|
|
68
82
|
* @throws {Error} If any of the specified fields are not defined in the schema.
|
|
@@ -104,7 +118,7 @@ export declare abstract class Criteria<TSchema extends CriteriaSchema, CurrentAl
|
|
|
104
118
|
* Gets the alias used for the entity of this criteria.
|
|
105
119
|
* @returns {CurrentAlias} The alias string.
|
|
106
120
|
*/
|
|
107
|
-
get alias():
|
|
121
|
+
get alias(): TSchema['alias'];
|
|
108
122
|
/**
|
|
109
123
|
* Sets the maximum number of records to return (LIMIT).
|
|
110
124
|
* @param {number} amount - The number of records to take. Must be non-negative.
|
|
@@ -128,16 +142,17 @@ export declare abstract class Criteria<TSchema extends CriteriaSchema, CurrentAl
|
|
|
128
142
|
* @param {FieldOfSchema<TSchema>} field - The field name to validate.
|
|
129
143
|
* @throws {Error} If the field is not defined in the schema.
|
|
130
144
|
*/
|
|
131
|
-
protected assetFieldOnSchema(field:
|
|
145
|
+
protected assetFieldOnSchema(field: TSchema['fields'][number]): void;
|
|
132
146
|
/**
|
|
133
147
|
* Adds an ordering rule to the criteria.
|
|
134
148
|
* Multiple calls will append new ordering rules.
|
|
135
149
|
* @param {FieldOfSchema<TSchema>} field - The field to order by.
|
|
136
150
|
* @param {OrderDirection} direction - The direction of the ordering (ASC or DESC).
|
|
151
|
+
* @param {boolean} [nullFirst=false] - If true, null values will be ordered first.
|
|
137
152
|
* @returns {this} The current criteria instance for chaining.
|
|
138
153
|
* @throws {Error} If the specified field is not defined in the schema.
|
|
139
154
|
*/
|
|
140
|
-
orderBy(field: FieldOfSchema<TSchema>, direction: OrderDirection): this;
|
|
155
|
+
orderBy(field: FieldOfSchema<TSchema>, direction: OrderDirection, nullFirst?: boolean): this;
|
|
141
156
|
/**
|
|
142
157
|
* Initializes the filter criteria with a single filter primitive.
|
|
143
158
|
* This replaces any existing filters in the root filter group.
|
|
@@ -168,27 +183,22 @@ export declare abstract class Criteria<TSchema extends CriteriaSchema, CurrentAl
|
|
|
168
183
|
*/
|
|
169
184
|
orWhere<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): this;
|
|
170
185
|
/**
|
|
171
|
-
* Adds a join to another criteria.
|
|
186
|
+
* Adds a join to another criteria. This method is fully type-safe.
|
|
187
|
+
* The `joinAlias` argument provides autocompletion for all valid relation aliases defined in the schema.
|
|
188
|
+
* The `criteriaToJoin` argument is then validated to ensure its `source_name` matches the one
|
|
189
|
+
* configured for the chosen `joinAlias`, providing clear, compile-time error messages if they mismatch.
|
|
190
|
+
*
|
|
172
191
|
* @template TJoinSchema - The schema of the entity to join.
|
|
173
|
-
* @template
|
|
174
|
-
* @
|
|
175
|
-
*
|
|
176
|
-
* @param {
|
|
177
|
-
*
|
|
178
|
-
* @param {
|
|
179
|
-
*
|
|
180
|
-
* many-to-many).
|
|
192
|
+
* @template SpecificRelationAlias - The literal type of the relation alias being used for the join.
|
|
193
|
+
* @param {SpecificRelationAlias} joinAlias - The specific alias defined in the parent schema's `relations` array for
|
|
194
|
+
* this relation.
|
|
195
|
+
* @param {JoinCriteriaType<TSchema, TJoinSchema, SpecificRelationAlias>} criteriaToJoin - The criteria instance
|
|
196
|
+
* representing the entity to join (e.g., `InnerJoinCriteria`).
|
|
197
|
+
* @param {boolean} [withSelect=true] - If true (default), the joined entity's fields will be included in the final
|
|
198
|
+
* selection. If false, the join will only be used for filtering and its fields will not be selected.
|
|
181
199
|
* @returns {this} The current criteria instance for chaining.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
* in the parent schema.
|
|
185
|
-
* @throws {Error} If the join configuration for the given `criteriaToJoin.alias` is not found in the parent schema's
|
|
186
|
-
* `joins` array.
|
|
187
|
-
* @throws {Error} If `joinParameter` is invalid for the `relation_type` defined in the schema (e.g., using
|
|
188
|
-
* simple join input for many-to-many or vice-versa).
|
|
189
|
-
*/
|
|
190
|
-
join<TJoinSchema extends CriteriaSchema, TJoinedCriteriaAlias extends SelectedAliasOf<TJoinSchema>, TMatchingJoinConfig extends SpecificMatchingJoinConfig<TSchema, TJoinedCriteriaAlias>>(criteriaToJoin: JoinCriteriaParameterType<TSchema, TJoinSchema, TJoinedCriteriaAlias, TMatchingJoinConfig>, joinParameter: JoinParameterType<TSchema, TJoinSchema, TMatchingJoinConfig>): this;
|
|
191
|
-
private assertIsValidJoinOptions;
|
|
200
|
+
*/
|
|
201
|
+
join<const TJoinSchema extends CriteriaSchema, const SpecificRelationAlias extends TSchema['relations'][number]['relation_alias']>(joinAlias: SpecificRelationAlias, criteriaToJoin: JoinCriteriaType<TSchema, TJoinSchema, SpecificRelationAlias>, withSelect?: boolean): this;
|
|
192
202
|
/**
|
|
193
203
|
* Gets the current cursor configuration, if set.
|
|
194
204
|
* @returns {Cursor<FieldOfSchema<TSchema>, FilterOperator.GREATER_THAN | FilterOperator.LESS_THAN> | undefined}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteria.d.ts","sourceRoot":"","sources":["../../src/criteria/criteria.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"criteria.d.ts","sourceRoot":"","sources":["../../src/criteria/criteria.ts"],"names":[],"mappings":"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"}
|