@nulledexp/translatable-criteria 1.0.4 → 1.2.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 +3 -3
- package/dist/criteria/criteria.d.ts +182 -10
- package/dist/criteria/criteria.d.ts.map +1 -1
- package/dist/criteria/criteria.js +182 -8
- package/dist/criteria/criteria.js.map +1 -1
- package/dist/criteria/cursor.d.ts +31 -0
- package/dist/criteria/cursor.d.ts.map +1 -1
- package/dist/criteria/cursor.js +34 -6
- package/dist/criteria/cursor.js.map +1 -1
- package/dist/criteria/filter/filter-utils.d.ts +6 -0
- package/dist/criteria/filter/filter-utils.d.ts.map +1 -1
- package/dist/criteria/filter/filter-utils.js +29 -9
- package/dist/criteria/filter/filter-utils.js.map +1 -1
- package/dist/criteria/filter/filter.d.ts +3 -0
- package/dist/criteria/filter/filter.d.ts.map +1 -1
- package/dist/criteria/filter/filter.js +62 -35
- package/dist/criteria/filter/filter.js.map +1 -1
- package/dist/criteria/filter/types/filter-primitive.types.d.ts +8 -11
- package/dist/criteria/filter/types/filter-primitive.types.d.ts.map +1 -1
- package/dist/criteria/join/inner.join-criteria.d.ts +5 -0
- package/dist/criteria/join/inner.join-criteria.d.ts.map +1 -1
- package/dist/criteria/join/inner.join-criteria.js +5 -0
- package/dist/criteria/join/inner.join-criteria.js.map +1 -1
- package/dist/criteria/join/left.join-criteria.d.ts +5 -0
- package/dist/criteria/join/left.join-criteria.d.ts.map +1 -1
- package/dist/criteria/join/left.join-criteria.js +5 -0
- package/dist/criteria/join/left.join-criteria.js.map +1 -1
- package/dist/criteria/join/outer.join-criteria.d.ts +5 -0
- package/dist/criteria/join/outer.join-criteria.d.ts.map +1 -1
- package/dist/criteria/join/outer.join-criteria.js +5 -0
- package/dist/criteria/join/outer.join-criteria.js.map +1 -1
- package/dist/criteria/order/order.d.ts +49 -0
- package/dist/criteria/order/order.d.ts.map +1 -1
- package/dist/criteria/order/order.js +39 -0
- package/dist/criteria/order/order.js.map +1 -1
- package/dist/criteria/root.criteria.d.ts +5 -0
- package/dist/criteria/root.criteria.d.ts.map +1 -1
- package/dist/criteria/root.criteria.js +5 -0
- package/dist/criteria/root.criteria.js.map +1 -1
- package/dist/criteria/types/criteria.interface.d.ts +32 -27
- package/dist/criteria/types/criteria.interface.d.ts.map +1 -1
- package/dist/criteria/types/filter-expression.interface.d.ts +12 -0
- package/dist/criteria/types/filter-expression.interface.d.ts.map +1 -1
- package/dist/criteria/types/join-parameter.types.d.ts +36 -2
- package/dist/criteria/types/join-parameter.types.d.ts.map +1 -1
- package/dist/criteria/types/join-utility.types.d.ts +5 -5
- package/dist/criteria/types/join-utility.types.d.ts.map +1 -1
- package/dist/criteria/types/operator.types.d.ts +44 -7
- package/dist/criteria/types/operator.types.d.ts.map +1 -1
- package/dist/criteria/types/operator.types.js +44 -8
- package/dist/criteria/types/operator.types.js.map +1 -1
- package/dist/criteria/types/schema.types.d.ts +26 -2
- package/dist/criteria/types/schema.types.d.ts.map +1 -1
- package/dist/criteria/types/schema.types.js +1 -1
- package/dist/criteria/types/schema.types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ export const UserSchema = GetTypedCriteriaSchema({
|
|
|
54
54
|
alias: ['users', 'user', 'publisher'],
|
|
55
55
|
fields: ['uuid', 'email', 'username', 'created_at'],
|
|
56
56
|
joins: [
|
|
57
|
-
{ alias: 'posts',
|
|
57
|
+
{ alias: 'posts', relation_type: 'one_to_many' },
|
|
58
58
|
// other joins like 'permissions', 'addresses' can be defined here
|
|
59
59
|
],
|
|
60
60
|
});
|
|
@@ -73,8 +73,8 @@ export const PostSchema = GetTypedCriteriaSchema({
|
|
|
73
73
|
'metadata', // Example: for JSON filters
|
|
74
74
|
],
|
|
75
75
|
joins: [
|
|
76
|
-
{ alias: 'comments',
|
|
77
|
-
{ alias: 'publisher',
|
|
76
|
+
{ alias: 'comments', relation_type: 'one_to_many' },
|
|
77
|
+
{ alias: 'publisher', relation_type: 'many_to_one' },
|
|
78
78
|
],
|
|
79
79
|
});
|
|
80
80
|
export type PostSchema = typeof PostSchema;
|
|
@@ -3,8 +3,17 @@ 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 { JoinCriteriaParameterType, JoinParameterType, SpecificMatchingJoinConfig } from './types/join-utility.types.js';
|
|
6
|
+
import type { JoinCriteriaParameterType, JoinParameterType, SpecificMatchingJoinConfig, StoredJoinDetails } from './types/join-utility.types.js';
|
|
7
7
|
import { FilterOperator } from './types/operator.types.js';
|
|
8
|
+
import type { FilterGroup } from './filter/filter-group.js';
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base class for constructing query criteria.
|
|
11
|
+
* It provides a fluent API for defining filters, joins, selections, ordering, and pagination.
|
|
12
|
+
* Concrete criteria types (e.g., RootCriteria, JoinCriteria) will extend this class.
|
|
13
|
+
*
|
|
14
|
+
* @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
|
+
*/
|
|
8
17
|
export declare abstract class Criteria<TSchema extends CriteriaSchema, CurrentAlias extends SelectedAliasOf<TSchema> = SelectedAliasOf<TSchema>> implements ICriteriaBase<TSchema, CurrentAlias> {
|
|
9
18
|
protected readonly schema: TSchema;
|
|
10
19
|
protected _alias: CurrentAlias;
|
|
@@ -12,37 +21,200 @@ export declare abstract class Criteria<TSchema extends CriteriaSchema, CurrentAl
|
|
|
12
21
|
private readonly _joinManager;
|
|
13
22
|
private readonly _source_name;
|
|
14
23
|
private _take;
|
|
24
|
+
/**
|
|
25
|
+
* Stores the set of fields explicitly selected by the user.
|
|
26
|
+
* This is used when `_selectAll` is false.
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
15
29
|
protected _select: Set<FieldOfSchema<TSchema>>;
|
|
16
30
|
private _selectAll;
|
|
31
|
+
/**
|
|
32
|
+
* Stores the cursor configuration for pagination, if set.
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
17
35
|
protected _cursor: Cursor<FieldOfSchema<TSchema>, FilterOperator.GREATER_THAN | FilterOperator.LESS_THAN> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Initializes a new instance of the Criteria class.
|
|
38
|
+
* @param {TSchema} schema - The schema definition for the entity.
|
|
39
|
+
* @param {CurrentAlias} _alias - The alias to use for this entity in the query.
|
|
40
|
+
* @throws {Error} If the provided alias is not supported by the schema.
|
|
41
|
+
* @protected
|
|
42
|
+
*/
|
|
18
43
|
constructor(schema: TSchema, _alias: CurrentAlias);
|
|
19
|
-
|
|
20
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Gets the currently selected fields.
|
|
46
|
+
* If `_selectAll` is true, it returns all fields from the schema.
|
|
47
|
+
* Otherwise, it returns the fields explicitly set via `setSelect`.
|
|
48
|
+
* @returns {Array<FieldOfSchema<TSchema>>} An array of selected field names.
|
|
49
|
+
*/
|
|
50
|
+
get select(): Array<FieldOfSchema<TSchema>>;
|
|
51
|
+
/**
|
|
52
|
+
* Resets the selection to include all fields from the schema.
|
|
53
|
+
* Subsequent calls to `get select()` will return all schema fields
|
|
54
|
+
* until `setSelect()` is called again.
|
|
55
|
+
* @returns {this} The current criteria instance for chaining.
|
|
56
|
+
*/
|
|
21
57
|
resetSelect(): this;
|
|
58
|
+
/**
|
|
59
|
+
* Indicates whether all fields are currently configured to be selected.
|
|
60
|
+
* @returns {boolean} True if all fields are selected, false if specific fields are selected.
|
|
61
|
+
*/
|
|
22
62
|
get selectAll(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Specifies which fields to select for the entity.
|
|
65
|
+
* Calling this method sets `selectAll` to false.
|
|
66
|
+
* @param {Array<FieldOfSchema<TSchema>>} selectFields - An array of field names to select.
|
|
67
|
+
* @returns {this} The current criteria instance for chaining.
|
|
68
|
+
* @throws {Error} If any of the specified fields are not defined in the schema.
|
|
69
|
+
*/
|
|
23
70
|
setSelect(selectFields: Array<FieldOfSchema<TSchema>>): this;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the maximum number of records to return (LIMIT).
|
|
73
|
+
* @returns {number} The take value.
|
|
74
|
+
*/
|
|
24
75
|
get take(): number;
|
|
25
76
|
private _skip;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the number of records to skip (OFFSET).
|
|
79
|
+
* @returns {number} The skip value.
|
|
80
|
+
*/
|
|
26
81
|
get skip(): number;
|
|
27
82
|
private _orders;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the current ordering rules applied to this criteria.
|
|
85
|
+
* @returns {ReadonlyArray<Order<FieldOfSchema<TSchema>>>} A readonly array of order objects.
|
|
86
|
+
*/
|
|
28
87
|
get orders(): ReadonlyArray<Order<FieldOfSchema<TSchema>>>;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Gets the configured join details for this criteria.
|
|
90
|
+
* @returns {ReadonlyArray<StoredJoinDetails<TSchema>>} A readonly array of join configurations.
|
|
91
|
+
*/
|
|
92
|
+
get joins(): ReadonlyArray<StoredJoinDetails<TSchema>>;
|
|
93
|
+
/**
|
|
94
|
+
* Gets the root filter group for this criteria, which holds all filter conditions.
|
|
95
|
+
* @returns {FilterGroup} The root filter group.
|
|
96
|
+
*/
|
|
97
|
+
get rootFilterGroup(): FilterGroup;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the source name (e.g., table name) for the entity of this criteria.
|
|
100
|
+
* @returns {TSchema['source_name']} The source name string.
|
|
101
|
+
*/
|
|
102
|
+
get sourceName(): TSchema['source_name'];
|
|
103
|
+
/**
|
|
104
|
+
* Gets the alias used for the entity of this criteria.
|
|
105
|
+
* @returns {CurrentAlias} The alias string.
|
|
106
|
+
*/
|
|
32
107
|
get alias(): CurrentAlias;
|
|
108
|
+
/**
|
|
109
|
+
* Sets the maximum number of records to return (LIMIT).
|
|
110
|
+
* @param {number} amount - The number of records to take. Must be non-negative.
|
|
111
|
+
* @returns {this} The current criteria instance for chaining.
|
|
112
|
+
* @throws {Error} If the amount is negative.
|
|
113
|
+
*/
|
|
33
114
|
setTake(amount: number): this;
|
|
115
|
+
/**
|
|
116
|
+
* Sets the number of records to skip before starting to return records (OFFSET).
|
|
117
|
+
* @param {number} amount - The number of records to skip. Must be non-negative.
|
|
118
|
+
* @returns {this} The current criteria instance for chaining.
|
|
119
|
+
* @throws {Error} If the amount is negative.
|
|
120
|
+
*/
|
|
34
121
|
setSkip(amount: number): this;
|
|
122
|
+
/**
|
|
123
|
+
* Asserts that a given field name is defined within the current criteria's schema.
|
|
124
|
+
* This is a protected utility method used internally to validate field names
|
|
125
|
+
* before they are used in filters, ordering, or selections.
|
|
126
|
+
*
|
|
127
|
+
* @protected
|
|
128
|
+
* @param {FieldOfSchema<TSchema>} field - The field name to validate.
|
|
129
|
+
* @throws {Error} If the field is not defined in the schema.
|
|
130
|
+
*/
|
|
35
131
|
protected assetFieldOnSchema(field: FieldOfSchema<TSchema>): void;
|
|
132
|
+
/**
|
|
133
|
+
* Adds an ordering rule to the criteria.
|
|
134
|
+
* Multiple calls will append new ordering rules.
|
|
135
|
+
* @param {FieldOfSchema<TSchema>} field - The field to order by.
|
|
136
|
+
* @param {OrderDirection} direction - The direction of the ordering (ASC or DESC).
|
|
137
|
+
* @returns {this} The current criteria instance for chaining.
|
|
138
|
+
* @throws {Error} If the specified field is not defined in the schema.
|
|
139
|
+
*/
|
|
36
140
|
orderBy(field: FieldOfSchema<TSchema>, direction: OrderDirection): this;
|
|
141
|
+
/**
|
|
142
|
+
* Initializes the filter criteria with a single filter primitive.
|
|
143
|
+
* This replaces any existing filters in the root filter group.
|
|
144
|
+
* @template Operator - The specific filter operator type.
|
|
145
|
+
* @param {FilterPrimitive<FieldOfSchema<TSchema>, Operator>} filterPrimitive - The filter to apply.
|
|
146
|
+
* @returns {this} The current criteria instance for chaining.
|
|
147
|
+
* @throws {Error} If the specified field in filterPrimitive is not defined in the schema.
|
|
148
|
+
*/
|
|
37
149
|
where<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): this;
|
|
150
|
+
/**
|
|
151
|
+
* Adds a filter primitive to the current filter group using an AND logical operator.
|
|
152
|
+
* Requires `where()` to have been called first to initialize the filter group.
|
|
153
|
+
* @template Operator - The specific filter operator type.
|
|
154
|
+
* @param {FilterPrimitive<FieldOfSchema<TSchema>, Operator>} filterPrimitive - The filter to add.
|
|
155
|
+
* @returns {this} The current criteria instance for chaining.
|
|
156
|
+
* @throws {Error} If the specified field in filterPrimitive is not defined in the schema.
|
|
157
|
+
* @throws {Error} If `where()` has not been called first.
|
|
158
|
+
*/
|
|
38
159
|
andWhere<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): this;
|
|
160
|
+
/**
|
|
161
|
+
* Adds a filter primitive to the current filter group using an OR logical operator.
|
|
162
|
+
* Requires `where()` to have been called first to initialize the filter group.
|
|
163
|
+
* @template Operator - The specific filter operator type.
|
|
164
|
+
* @param {FilterPrimitive<FieldOfSchema<TSchema>, Operator>} filterPrimitive - The filter to add.
|
|
165
|
+
* @returns {this} The current criteria instance for chaining.
|
|
166
|
+
* @throws {Error} If the specified field in filterPrimitive is not defined in the schema.
|
|
167
|
+
* @throws {Error} If `where()` has not been called first.
|
|
168
|
+
*/
|
|
39
169
|
orWhere<Operator extends FilterOperator>(filterPrimitive: FilterPrimitive<FieldOfSchema<TSchema>, Operator>): this;
|
|
170
|
+
/**
|
|
171
|
+
* Adds a join to another criteria.
|
|
172
|
+
* @template TJoinSchema - The schema of the entity to join.
|
|
173
|
+
* @template TJoinedCriteriaAlias - The alias for the joined entity.
|
|
174
|
+
* @template TMatchingJoinConfig - The specific join configuration from the parent schema that matches the joined
|
|
175
|
+
* alias.
|
|
176
|
+
* @param {JoinCriteriaParameterType<TSchema, TJoinSchema, TJoinedCriteriaAlias, TMatchingJoinConfig>} criteriaToJoin
|
|
177
|
+
* The criteria instance representing the entity to join (e.g., `InnerJoinCriteria`, `LeftJoinCriteria`).
|
|
178
|
+
* @param {JoinParameterType<TSchema, TJoinSchema, TMatchingJoinConfig>} joinParameter
|
|
179
|
+
* The parameters defining how the join should be performed (e.g., fields for simple join, pivot table details for
|
|
180
|
+
* many-to-many).
|
|
181
|
+
* @returns {this} The current criteria instance for chaining.
|
|
182
|
+
* @throws {Error} If `criteriaToJoin` is a string (which is invalid).
|
|
183
|
+
* @throws {Error} If `parent_field` in `joinParameter` (or `parent_field.reference` for pivot joins) is not defined
|
|
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
|
+
*/
|
|
40
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;
|
|
41
191
|
private assertIsValidJoinOptions;
|
|
192
|
+
/**
|
|
193
|
+
* Gets the current cursor configuration, if set.
|
|
194
|
+
* @returns {Cursor<FieldOfSchema<TSchema>, FilterOperator.GREATER_THAN | FilterOperator.LESS_THAN> | undefined}
|
|
195
|
+
* The cursor object or undefined.
|
|
196
|
+
*/
|
|
42
197
|
get cursor(): Cursor<FieldOfSchema<TSchema>, FilterOperator.GREATER_THAN | FilterOperator.LESS_THAN> | undefined;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Sets the cursor for pagination.
|
|
200
|
+
* @template Operator - The specific comparison operator for the cursor.
|
|
201
|
+
* @param {readonly [Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>] | readonly
|
|
202
|
+
* [Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>,
|
|
203
|
+
* Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>]} filterPrimitives - An array of one or two
|
|
204
|
+
* filter primitives defining the cursor's fields and values.
|
|
205
|
+
* @param {Operator} operator - The comparison operator (GREATER_THAN or LESS_THAN).
|
|
206
|
+
* @param {OrderDirection} order - The primary order direction for pagination.
|
|
207
|
+
* @returns {this} The current criteria instance for chaining.
|
|
208
|
+
* @throws {Error} If filterPrimitives does not contain exactly 1 or 2 elements.
|
|
209
|
+
* @throws {Error} If any cursor field is not defined in the schema.
|
|
210
|
+
* @throws {Error} If any cursor value is undefined (null is allowed, per Cursor constructor).
|
|
211
|
+
* @throws {Error} If two cursor fields are provided and they are identical (per Cursor constructor).
|
|
212
|
+
*/
|
|
213
|
+
setCursor<Operator extends FilterOperator.GREATER_THAN | FilterOperator.LESS_THAN>(filterPrimitives: readonly [
|
|
214
|
+
Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>
|
|
215
|
+
] | readonly [
|
|
216
|
+
Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>,
|
|
217
|
+
Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>
|
|
218
|
+
], operator: Operator, order: OrderDirection): this;
|
|
47
219
|
}
|
|
48
220
|
//# sourceMappingURL=criteria.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteria.d.ts","sourceRoot":"","sources":["../../src/criteria/criteria.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EAEb,eAAe,EAChB,MA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,cAAc,CAAC,SAAS,CACvD,GACD,SAAS,CAEZ;IACD;;;;;;;;;;;;;;OAcG;IACH,SAAS,CACP,QAAQ,SAAS,cAAc,CAAC,YAAY,GAAG,cAAc,CAAC,SAAS,EAEvE,gBAAgB,EACZ,SAAS;QACP,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC;KACpE,GACD,SAAS;QACP,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC;QACnE,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC;KACpE,EACL,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,cAAc,GACpB,IAAI;CAWR"}
|
|
@@ -3,6 +3,14 @@ import { CriteriaJoinManager } from './criteria-join-manager.js';
|
|
|
3
3
|
import { Cursor } from './cursor.js';
|
|
4
4
|
import { Order, OrderDirection } from './order/order.js';
|
|
5
5
|
import { FilterOperator } from './types/operator.types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base class for constructing query criteria.
|
|
8
|
+
* It provides a fluent API for defining filters, joins, selections, ordering, and pagination.
|
|
9
|
+
* Concrete criteria types (e.g., RootCriteria, JoinCriteria) will extend this class.
|
|
10
|
+
*
|
|
11
|
+
* @template TSchema - The schema definition for the entity this criteria operates on.
|
|
12
|
+
* @template CurrentAlias - The selected alias for the entity from its schema.
|
|
13
|
+
*/
|
|
6
14
|
export class Criteria {
|
|
7
15
|
schema;
|
|
8
16
|
_alias;
|
|
@@ -10,9 +18,25 @@ export class Criteria {
|
|
|
10
18
|
_joinManager = new CriteriaJoinManager();
|
|
11
19
|
_source_name;
|
|
12
20
|
_take = 0; // 0 = no limit
|
|
21
|
+
/**
|
|
22
|
+
* Stores the set of fields explicitly selected by the user.
|
|
23
|
+
* This is used when `_selectAll` is false.
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
13
26
|
_select = new Set([]);
|
|
14
27
|
_selectAll = true;
|
|
28
|
+
/**
|
|
29
|
+
* Stores the cursor configuration for pagination, if set.
|
|
30
|
+
* @protected
|
|
31
|
+
*/
|
|
15
32
|
_cursor;
|
|
33
|
+
/**
|
|
34
|
+
* Initializes a new instance of the Criteria class.
|
|
35
|
+
* @param {TSchema} schema - The schema definition for the entity.
|
|
36
|
+
* @param {CurrentAlias} _alias - The alias to use for this entity in the query.
|
|
37
|
+
* @throws {Error} If the provided alias is not supported by the schema.
|
|
38
|
+
* @protected
|
|
39
|
+
*/
|
|
16
40
|
constructor(schema, _alias) {
|
|
17
41
|
this.schema = schema;
|
|
18
42
|
this._alias = _alias;
|
|
@@ -20,20 +44,43 @@ export class Criteria {
|
|
|
20
44
|
throw new Error(`Unsupported alia ${this._alias} for schema ${schema.source_name}`);
|
|
21
45
|
this._source_name = schema.source_name;
|
|
22
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Gets the currently selected fields.
|
|
49
|
+
* If `_selectAll` is true, it returns all fields from the schema.
|
|
50
|
+
* Otherwise, it returns the fields explicitly set via `setSelect`.
|
|
51
|
+
* @returns {Array<FieldOfSchema<TSchema>>} An array of selected field names.
|
|
52
|
+
*/
|
|
23
53
|
get select() {
|
|
24
54
|
if (this._selectAll) {
|
|
25
55
|
return [...this.schema.fields];
|
|
26
56
|
}
|
|
27
57
|
return Array.from(this._select);
|
|
28
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Resets the selection to include all fields from the schema.
|
|
61
|
+
* Subsequent calls to `get select()` will return all schema fields
|
|
62
|
+
* until `setSelect()` is called again.
|
|
63
|
+
* @returns {this} The current criteria instance for chaining.
|
|
64
|
+
*/
|
|
29
65
|
resetSelect() {
|
|
30
66
|
this._selectAll = true;
|
|
31
67
|
this._select.clear();
|
|
32
68
|
return this;
|
|
33
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Indicates whether all fields are currently configured to be selected.
|
|
72
|
+
* @returns {boolean} True if all fields are selected, false if specific fields are selected.
|
|
73
|
+
*/
|
|
34
74
|
get selectAll() {
|
|
35
75
|
return this._selectAll;
|
|
36
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Specifies which fields to select for the entity.
|
|
79
|
+
* Calling this method sets `selectAll` to false.
|
|
80
|
+
* @param {Array<FieldOfSchema<TSchema>>} selectFields - An array of field names to select.
|
|
81
|
+
* @returns {this} The current criteria instance for chaining.
|
|
82
|
+
* @throws {Error} If any of the specified fields are not defined in the schema.
|
|
83
|
+
*/
|
|
37
84
|
setSelect(selectFields) {
|
|
38
85
|
for (const field of selectFields) {
|
|
39
86
|
this.assetFieldOnSchema(field);
|
|
@@ -44,29 +91,63 @@ export class Criteria {
|
|
|
44
91
|
}
|
|
45
92
|
return this;
|
|
46
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets the maximum number of records to return (LIMIT).
|
|
96
|
+
* @returns {number} The take value.
|
|
97
|
+
*/
|
|
47
98
|
get take() {
|
|
48
99
|
return this._take;
|
|
49
100
|
}
|
|
50
101
|
_skip = 0;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the number of records to skip (OFFSET).
|
|
104
|
+
* @returns {number} The skip value.
|
|
105
|
+
*/
|
|
51
106
|
get skip() {
|
|
52
107
|
return this._skip;
|
|
53
108
|
}
|
|
54
109
|
_orders = [];
|
|
110
|
+
/**
|
|
111
|
+
* Gets the current ordering rules applied to this criteria.
|
|
112
|
+
* @returns {ReadonlyArray<Order<FieldOfSchema<TSchema>>>} A readonly array of order objects.
|
|
113
|
+
*/
|
|
55
114
|
get orders() {
|
|
56
115
|
return [...this._orders];
|
|
57
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets the configured join details for this criteria.
|
|
119
|
+
* @returns {ReadonlyArray<StoredJoinDetails<TSchema>>} A readonly array of join configurations.
|
|
120
|
+
*/
|
|
58
121
|
get joins() {
|
|
59
122
|
return [...this._joinManager.getJoins()];
|
|
60
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Gets the root filter group for this criteria, which holds all filter conditions.
|
|
126
|
+
* @returns {FilterGroup} The root filter group.
|
|
127
|
+
*/
|
|
61
128
|
get rootFilterGroup() {
|
|
62
129
|
return this._filterManager.getRootFilterGroup();
|
|
63
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets the source name (e.g., table name) for the entity of this criteria.
|
|
133
|
+
* @returns {TSchema['source_name']} The source name string.
|
|
134
|
+
*/
|
|
64
135
|
get sourceName() {
|
|
65
136
|
return this._source_name;
|
|
66
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Gets the alias used for the entity of this criteria.
|
|
140
|
+
* @returns {CurrentAlias} The alias string.
|
|
141
|
+
*/
|
|
67
142
|
get alias() {
|
|
68
143
|
return this._alias;
|
|
69
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Sets the maximum number of records to return (LIMIT).
|
|
147
|
+
* @param {number} amount - The number of records to take. Must be non-negative.
|
|
148
|
+
* @returns {this} The current criteria instance for chaining.
|
|
149
|
+
* @throws {Error} If the amount is negative.
|
|
150
|
+
*/
|
|
70
151
|
setTake(amount) {
|
|
71
152
|
if (amount < 0) {
|
|
72
153
|
throw new Error(`Take value cant be negative`);
|
|
@@ -74,6 +155,12 @@ export class Criteria {
|
|
|
74
155
|
this._take = amount;
|
|
75
156
|
return this;
|
|
76
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Sets the number of records to skip before starting to return records (OFFSET).
|
|
160
|
+
* @param {number} amount - The number of records to skip. Must be non-negative.
|
|
161
|
+
* @returns {this} The current criteria instance for chaining.
|
|
162
|
+
* @throws {Error} If the amount is negative.
|
|
163
|
+
*/
|
|
77
164
|
setSkip(amount) {
|
|
78
165
|
if (amount < 0) {
|
|
79
166
|
throw new Error(`Skip value cant be negative`);
|
|
@@ -81,30 +168,93 @@ export class Criteria {
|
|
|
81
168
|
this._skip = amount;
|
|
82
169
|
return this;
|
|
83
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Asserts that a given field name is defined within the current criteria's schema.
|
|
173
|
+
* This is a protected utility method used internally to validate field names
|
|
174
|
+
* before they are used in filters, ordering, or selections.
|
|
175
|
+
*
|
|
176
|
+
* @protected
|
|
177
|
+
* @param {FieldOfSchema<TSchema>} field - The field name to validate.
|
|
178
|
+
* @throws {Error} If the field is not defined in the schema.
|
|
179
|
+
*/
|
|
84
180
|
assetFieldOnSchema(field) {
|
|
85
181
|
if (!this.schema.fields.includes(field))
|
|
86
182
|
throw new Error(`The field '${String(field)}' is not defined in the schema '${this.schema.source_name}'.`);
|
|
87
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Adds an ordering rule to the criteria.
|
|
186
|
+
* Multiple calls will append new ordering rules.
|
|
187
|
+
* @param {FieldOfSchema<TSchema>} field - The field to order by.
|
|
188
|
+
* @param {OrderDirection} direction - The direction of the ordering (ASC or DESC).
|
|
189
|
+
* @returns {this} The current criteria instance for chaining.
|
|
190
|
+
* @throws {Error} If the specified field is not defined in the schema.
|
|
191
|
+
*/
|
|
88
192
|
orderBy(field, direction) {
|
|
89
193
|
this.assetFieldOnSchema(field);
|
|
90
194
|
this._orders.push(new Order(direction, field));
|
|
91
195
|
return this;
|
|
92
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Initializes the filter criteria with a single filter primitive.
|
|
199
|
+
* This replaces any existing filters in the root filter group.
|
|
200
|
+
* @template Operator - The specific filter operator type.
|
|
201
|
+
* @param {FilterPrimitive<FieldOfSchema<TSchema>, Operator>} filterPrimitive - The filter to apply.
|
|
202
|
+
* @returns {this} The current criteria instance for chaining.
|
|
203
|
+
* @throws {Error} If the specified field in filterPrimitive is not defined in the schema.
|
|
204
|
+
*/
|
|
93
205
|
where(filterPrimitive) {
|
|
94
206
|
this.assetFieldOnSchema(filterPrimitive.field);
|
|
95
207
|
this._filterManager.where(filterPrimitive);
|
|
96
208
|
return this;
|
|
97
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Adds a filter primitive to the current filter group using an AND logical operator.
|
|
212
|
+
* Requires `where()` to have been called first to initialize the filter group.
|
|
213
|
+
* @template Operator - The specific filter operator type.
|
|
214
|
+
* @param {FilterPrimitive<FieldOfSchema<TSchema>, Operator>} filterPrimitive - The filter to add.
|
|
215
|
+
* @returns {this} The current criteria instance for chaining.
|
|
216
|
+
* @throws {Error} If the specified field in filterPrimitive is not defined in the schema.
|
|
217
|
+
* @throws {Error} If `where()` has not been called first.
|
|
218
|
+
*/
|
|
98
219
|
andWhere(filterPrimitive) {
|
|
99
220
|
this.assetFieldOnSchema(filterPrimitive.field);
|
|
100
221
|
this._filterManager.andWhere(filterPrimitive);
|
|
101
222
|
return this;
|
|
102
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Adds a filter primitive to the current filter group using an OR logical operator.
|
|
226
|
+
* Requires `where()` to have been called first to initialize the filter group.
|
|
227
|
+
* @template Operator - The specific filter operator type.
|
|
228
|
+
* @param {FilterPrimitive<FieldOfSchema<TSchema>, Operator>} filterPrimitive - The filter to add.
|
|
229
|
+
* @returns {this} The current criteria instance for chaining.
|
|
230
|
+
* @throws {Error} If the specified field in filterPrimitive is not defined in the schema.
|
|
231
|
+
* @throws {Error} If `where()` has not been called first.
|
|
232
|
+
*/
|
|
103
233
|
orWhere(filterPrimitive) {
|
|
104
234
|
this.assetFieldOnSchema(filterPrimitive.field);
|
|
105
235
|
this._filterManager.orWhere(filterPrimitive);
|
|
106
236
|
return this;
|
|
107
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Adds a join to another criteria.
|
|
240
|
+
* @template TJoinSchema - The schema of the entity to join.
|
|
241
|
+
* @template TJoinedCriteriaAlias - The alias for the joined entity.
|
|
242
|
+
* @template TMatchingJoinConfig - The specific join configuration from the parent schema that matches the joined
|
|
243
|
+
* alias.
|
|
244
|
+
* @param {JoinCriteriaParameterType<TSchema, TJoinSchema, TJoinedCriteriaAlias, TMatchingJoinConfig>} criteriaToJoin
|
|
245
|
+
* The criteria instance representing the entity to join (e.g., `InnerJoinCriteria`, `LeftJoinCriteria`).
|
|
246
|
+
* @param {JoinParameterType<TSchema, TJoinSchema, TMatchingJoinConfig>} joinParameter
|
|
247
|
+
* The parameters defining how the join should be performed (e.g., fields for simple join, pivot table details for
|
|
248
|
+
* many-to-many).
|
|
249
|
+
* @returns {this} The current criteria instance for chaining.
|
|
250
|
+
* @throws {Error} If `criteriaToJoin` is a string (which is invalid).
|
|
251
|
+
* @throws {Error} If `parent_field` in `joinParameter` (or `parent_field.reference` for pivot joins) is not defined
|
|
252
|
+
* in the parent schema.
|
|
253
|
+
* @throws {Error} If the join configuration for the given `criteriaToJoin.alias` is not found in the parent schema's
|
|
254
|
+
* `joins` array.
|
|
255
|
+
* @throws {Error} If `joinParameter` is invalid for the `relation_type` defined in the schema (e.g., using
|
|
256
|
+
* simple join input for many-to-many or vice-versa).
|
|
257
|
+
*/
|
|
108
258
|
join(criteriaToJoin, joinParameter) {
|
|
109
259
|
if (typeof criteriaToJoin === 'string') {
|
|
110
260
|
throw new Error(`Invalid criteriaToJoin: ${criteriaToJoin}`);
|
|
@@ -121,7 +271,10 @@ export class Criteria {
|
|
|
121
271
|
...joinParameter,
|
|
122
272
|
parent_alias: this.alias,
|
|
123
273
|
parent_source_name: this.sourceName,
|
|
124
|
-
|
|
274
|
+
relation_type: joinConfig.relation_type,
|
|
275
|
+
join_metadata: this.schema.joins.find((join) => join.alias === criteriaToJoin.alias)
|
|
276
|
+
?.metadata ?? {},
|
|
277
|
+
parent_schema_metadata: this.schema.metadata ?? {},
|
|
125
278
|
};
|
|
126
279
|
this._joinManager.addJoin(criteriaToJoin, fullJoinParameters);
|
|
127
280
|
return this;
|
|
@@ -133,7 +286,7 @@ export class Criteria {
|
|
|
133
286
|
'pivot_field' in field &&
|
|
134
287
|
'reference' in field);
|
|
135
288
|
};
|
|
136
|
-
if (joinConfig.
|
|
289
|
+
if (joinConfig.relation_type === 'many_to_many') {
|
|
137
290
|
if (!isPivotFieldObject(joinParameter.parent_field) ||
|
|
138
291
|
!isPivotFieldObject(joinParameter.join_field)) {
|
|
139
292
|
throw new Error(`Invalid JoinOptions for 'many_to_many' join. Expected parent_field and join_field to be objects with 'pivot_field' and 'reference' properties. Alias: '${String(joinConfig.alias)}'`);
|
|
@@ -142,20 +295,41 @@ export class Criteria {
|
|
|
142
295
|
else {
|
|
143
296
|
if (typeof joinParameter.parent_field !== 'string' ||
|
|
144
297
|
typeof joinParameter.join_field !== 'string') {
|
|
145
|
-
throw new Error(`Invalid JoinOptions for '${joinConfig.
|
|
298
|
+
throw new Error(`Invalid JoinOptions for '${joinConfig.relation_type}' join. Expected parent_field and join_field to be strings. Alias: '${String(joinConfig.alias)}'`);
|
|
146
299
|
}
|
|
147
300
|
}
|
|
148
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Gets the current cursor configuration, if set.
|
|
304
|
+
* @returns {Cursor<FieldOfSchema<TSchema>, FilterOperator.GREATER_THAN | FilterOperator.LESS_THAN> | undefined}
|
|
305
|
+
* The cursor object or undefined.
|
|
306
|
+
*/
|
|
149
307
|
get cursor() {
|
|
150
308
|
return this._cursor;
|
|
151
309
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Sets the cursor for pagination.
|
|
312
|
+
* @template Operator - The specific comparison operator for the cursor.
|
|
313
|
+
* @param {readonly [Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>] | readonly
|
|
314
|
+
* [Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>,
|
|
315
|
+
* Omit<FilterPrimitive<FieldOfSchema<TSchema>, Operator>, 'operator'>]} filterPrimitives - An array of one or two
|
|
316
|
+
* filter primitives defining the cursor's fields and values.
|
|
317
|
+
* @param {Operator} operator - The comparison operator (GREATER_THAN or LESS_THAN).
|
|
318
|
+
* @param {OrderDirection} order - The primary order direction for pagination.
|
|
319
|
+
* @returns {this} The current criteria instance for chaining.
|
|
320
|
+
* @throws {Error} If filterPrimitives does not contain exactly 1 or 2 elements.
|
|
321
|
+
* @throws {Error} If any cursor field is not defined in the schema.
|
|
322
|
+
* @throws {Error} If any cursor value is undefined (null is allowed, per Cursor constructor).
|
|
323
|
+
* @throws {Error} If two cursor fields are provided and they are identical (per Cursor constructor).
|
|
324
|
+
*/
|
|
325
|
+
setCursor(filterPrimitives, operator, order) {
|
|
326
|
+
if (filterPrimitives.length !== 1 && filterPrimitives.length !== 2) {
|
|
327
|
+
throw new Error('The cursor must have exactly 1 or 2 elements');
|
|
328
|
+
}
|
|
329
|
+
for (const filterPrimitive of filterPrimitives) {
|
|
156
330
|
this.assetFieldOnSchema(filterPrimitive.field);
|
|
157
331
|
}
|
|
158
|
-
this._cursor = new Cursor(
|
|
332
|
+
this._cursor = new Cursor(filterPrimitives, operator, order);
|
|
159
333
|
return this;
|
|
160
334
|
}
|
|
161
335
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteria.js","sourceRoot":"","sources":["../../src/criteria/criteria.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"criteria.js","sourceRoot":"","sources":["../../src/criteria/criteria.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AASzD,OAAO,EAAE,cAAc,EAAE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