@tstdl/base 0.93.28 → 0.93.29

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 (40) hide show
  1. package/orm/data-types/tsvector.d.ts +3 -1
  2. package/orm/data-types/tsvector.js +2 -0
  3. package/orm/decorators.d.ts +166 -16
  4. package/orm/decorators.js +46 -0
  5. package/orm/index.d.ts +1 -1
  6. package/orm/index.js +1 -1
  7. package/orm/{query.d.ts → query/base.d.ts} +14 -166
  8. package/orm/{query.js → query/base.js} +3 -2
  9. package/orm/query/index.d.ts +2 -0
  10. package/orm/query/index.js +2 -0
  11. package/orm/query/parade.d.ts +172 -0
  12. package/orm/query/parade.js +4 -0
  13. package/orm/repository.types.d.ts +27 -6
  14. package/orm/schemas/index.d.ts +1 -0
  15. package/orm/schemas/index.js +1 -0
  16. package/orm/schemas/tsvector.d.ts +12 -0
  17. package/orm/schemas/tsvector.js +20 -0
  18. package/orm/server/drizzle/schema-converter.js +100 -19
  19. package/orm/server/query-converter.d.ts +2 -2
  20. package/orm/server/query-converter.js +138 -91
  21. package/orm/server/repository.d.ts +6 -6
  22. package/orm/server/repository.js +34 -23
  23. package/orm/sqls.d.ts +19 -16
  24. package/orm/sqls.js +28 -38
  25. package/package.json +6 -6
  26. package/test/drizzle/0000_natural_cannonball.sql +9 -0
  27. package/test/drizzle/meta/0000_snapshot.json +29 -10
  28. package/test/drizzle/meta/_journal.json +2 -2
  29. package/test/test.model.js +8 -2
  30. package/test1.js +9 -9
  31. package/utils/enum.js +1 -1
  32. package/utils/object/object.d.ts +5 -3
  33. package/utils/object/object.js +17 -7
  34. package/utils/string/casing.d.ts +3 -0
  35. package/utils/string/casing.js +15 -0
  36. package/utils/string/index.d.ts +1 -1
  37. package/utils/string/index.js +1 -1
  38. package/test/drizzle/0000_sturdy_patch.sql +0 -9
  39. package/utils/string/snake-case.d.ts +0 -1
  40. package/utils/string/snake-case.js +0 -4
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Custom Drizzle type for PostgreSQL `tsvector` columns.
3
+ * This type is a placeholder for the column type and does not perform
4
+ * any data transformation, as `tsvector` columns are typically not directly mapped to application data.
3
5
  */
4
6
  export declare const tsvector: import("./common.js").CustomTypeBuilder<{
5
- data: unknown;
7
+ data: string;
6
8
  }>;
@@ -5,6 +5,8 @@
5
5
  import { createCustomType } from './common.js';
6
6
  /**
7
7
  * Custom Drizzle type for PostgreSQL `tsvector` columns.
8
+ * This type is a placeholder for the column type and does not perform
9
+ * any data transformation, as `tsvector` columns are typically not directly mapped to application data.
8
10
  */
9
11
  export const tsvector = createCustomType({
10
12
  dataType() {
@@ -4,19 +4,26 @@
4
4
  */
5
5
  import type { SQL } from 'drizzle-orm';
6
6
  import type { ExtraConfigColumn } from 'drizzle-orm/pg-core';
7
- import type { LiteralUnion } from 'type-fest';
7
+ import type { LiteralUnion, SetRequired } from 'type-fest';
8
8
  import { type SpecificCreateDecoratorOptions } from '../reflection/index.js';
9
9
  import type { AbstractConstructor, Record, TypedOmit } from '../types/index.js';
10
10
  import type { ValueOrProvider } from '../utils/value-or-provider.js';
11
11
  import type { AnyEntity, BaseEntity, Entity, EntityType } from './entity.js';
12
- import type { Query } from './query.js';
12
+ import type { Query } from './query/index.js';
13
13
  import type { TargetColumnPath } from './repository.types.js';
14
14
  import type { ExtraConfigColumnsFromType } from './server/types.js';
15
15
  type IndexMethod = LiteralUnion<'hash' | 'btree' | 'gist' | 'spgist' | 'gin' | 'brin' | 'hnsw' | 'ivfflat' | 'bm25', string>;
16
16
  type NamingStrategy = 'abbreviated-table';
17
17
  type Column<T extends BaseEntity> = TargetColumnPath<T>;
18
18
  type Columns<T extends BaseEntity> = [Column<T>, ...Column<T>[]];
19
+ export type ParadeIndexColumn<T extends BaseEntity> = TargetColumnPath<T> | SQL | ExtraConfigColumn;
20
+ export type ParadeIndexColumnConfig<T extends BaseEntity> = ValueOrProvider<ParadeIndexColumn<T> | readonly [ParadeIndexColumn<T>, ParadeFieldOptions], ExtraConfigColumnsFromType<EntityType<T>>>;
21
+ export type ParadeIndexCompoundColumnColumnsProvider<T extends BaseEntity> = ValueOrProvider<readonly ParadeIndexColumn<T>[], ExtraConfigColumnsFromType<EntityType<T>>>;
22
+ export type ParadeIndexCompoundColumnConfig<T extends BaseEntity> = readonly [ParadeIndexCompoundColumnColumnsProvider<T>, SetRequired<ParadeFieldOptions, 'alias' | 'tokenizer'>];
23
+ export type ParadeIndexExpressionProvider<T extends BaseEntity> = SqlOrBuilder<T, string>;
24
+ export type ParadeIndexExpressionConfig<T extends BaseEntity> = readonly [ParadeIndexExpressionProvider<T>, SetRequired<ParadeFieldOptions, 'alias' | 'tokenizer'>];
19
25
  export type SqlBuilder<T extends BaseEntity = any, R = SQL> = (table: ExtraConfigColumnsFromType<EntityType<T>>) => R;
26
+ export type SqlOrBuilder<T extends BaseEntity = any, V = unknown> = SQL<V> | SqlBuilder<T, SQL<V>>;
20
27
  /**
21
28
  * Builder function type for creating SQL check constraints.
22
29
  * @param table The Drizzle table object.
@@ -30,13 +37,14 @@ export type WhereBuilder<T extends BaseEntity = BaseEntity> = SqlBuilder<T, Quer
30
37
  /**
31
38
  * Reflection data stored for ORM table decorators.
32
39
  */
33
- export type OrmTableReflectionData = {
40
+ export type OrmTableReflectionData<T extends BaseEntity = BaseEntity> = {
34
41
  name?: string;
35
42
  schema?: string;
36
- compundPrimaryKeyName?: string;
37
- compundPrimaryKeyNaming?: NamingStrategy;
43
+ compoundPrimaryKeyName?: string;
44
+ compoundPrimaryKeyNaming?: NamingStrategy;
38
45
  unique?: UniqueReflectionData[];
39
46
  index?: IndexReflectionData[];
47
+ paradeIndex?: ParadeIndexReflectionData<T>;
40
48
  checks?: CheckReflectionData[];
41
49
  foreignKeys?: ForeignKeyReflectionData[];
42
50
  };
@@ -59,6 +67,8 @@ export type OrmColumnReflectionData = {
59
67
  target: () => EntityType;
60
68
  targetColumn?: TargetColumnPath<any>;
61
69
  }[];
70
+ paradeField?: ParadeFieldOptions;
71
+ tsVector?: TsVectorOptions<any>;
62
72
  encrypted?: boolean;
63
73
  expirationField?: {
64
74
  after: number;
@@ -83,16 +93,7 @@ export type UniqueReflectionData = {
83
93
  export type IndexReflectionData<T extends BaseEntity = any> = {
84
94
  columns?: ValueOrProvider<(TargetColumnPath<T> | [TargetColumnPath<T>, 'asc' | 'desc'] | SQL | ExtraConfigColumn)[], ExtraConfigColumnsFromType<EntityType<T>>>;
85
95
  order?: 'asc' | 'desc';
86
- options?: {
87
- name?: string;
88
- naming?: NamingStrategy;
89
- using?: IndexMethod;
90
- unique?: boolean;
91
- where?: WhereBuilder<T>;
92
- with?: Record<string, number | string | boolean | SQL>;
93
- concurrently?: boolean;
94
- nulls?: 'first' | 'last';
95
- };
96
+ options?: IndexOptions<T>;
96
97
  };
97
98
  type CheckReflectionData = {
98
99
  name: string;
@@ -110,12 +111,106 @@ export type ForeignKeyReflectionData = {
110
111
  naming?: NamingStrategy;
111
112
  };
112
113
  };
114
+ export type IndexOptions<T extends BaseEntity> = {
115
+ name?: string;
116
+ naming?: NamingStrategy;
117
+ using?: IndexMethod;
118
+ unique?: boolean;
119
+ where?: WhereBuilder<T>;
120
+ with?: Record<string, number | string | boolean | SQL>;
121
+ concurrently?: boolean;
122
+ nulls?: 'first' | 'last';
123
+ opclass?: string;
124
+ };
125
+ export type ParadeIndexReflectionData<T extends BaseEntity> = Pick<IndexOptions<T>, 'naming' | 'where' | 'concurrently'> & {
126
+ /**
127
+ * Columns to include in the Parade index.
128
+ */
129
+ columns?: readonly ParadeIndexColumnConfig<T>[];
130
+ /**
131
+ * Columns to include in the Parade index.
132
+ */
133
+ compoundColumns?: readonly ParadeIndexCompoundColumnConfig<T>[];
134
+ /**
135
+ * Expressions to include in the Parade index based on combined.
136
+ */
137
+ expressions?: readonly ParadeIndexExpressionConfig<T>[];
138
+ targetSegmentCount?: number;
139
+ layerSizes?: string;
140
+ backgroundLayerSizes?: string;
141
+ mutableSegmentRows?: number;
142
+ };
143
+ export type ParadeTokenizer = 'simple' | 'whitespace' | 'literal' | 'literal_normalized' | 'ngram' | 'regex_pattern' | 'source_code' | 'chinese_compatible' | 'lindera' | 'jieba' | 'icu';
144
+ /**
145
+ * A type-safe object for configuring ParadeDB token filters.
146
+ */
147
+ export type ParadeTokenizerFilters = {
148
+ /**
149
+ * Reduces words to their root form for a given language.
150
+ * Corresponds to the `stemmer` parameter.
151
+ */
152
+ stemmer?: 'arabic' | 'danish' | 'dutch' | 'english' | 'finnish' | 'french' | 'german' | 'greek' | 'hungarian' | 'italian' | 'norwegian' | 'portuguese' | 'romanian' | 'russian' | 'spanish' | 'swedish' | 'tamil' | 'turkish';
153
+ /**
154
+ * Removes language-specific stopwords from the index.
155
+ * Corresponds to the `stopwords_language` parameter.
156
+ */
157
+ stopwordsLanguage?: 'danish' | 'dutch' | 'english' | 'finnish' | 'french' | 'german' | 'hungarian' | 'italian' | 'norwegian' | 'portuguese' | 'russian' | 'spanish' | 'swedish';
158
+ /**
159
+ * Strips away diacritical marks (accents, umlauts, etc.).
160
+ * Corresponds to the `ascii_folding` parameter.
161
+ */
162
+ asciiFolding?: boolean;
163
+ /**
164
+ * Removes any tokens that contain characters that are not ASCII letters or digits.
165
+ * Corresponds to the `alpha_num_only` parameter.
166
+ */
167
+ alphaNumOnly?: boolean;
168
+ /**
169
+ * Converts all characters to lowercase. Enabled by default. Set to `false` to disable.
170
+ * Corresponds to the `lowercase` parameter.
171
+ */
172
+ lowercase?: boolean;
173
+ /**
174
+ * Removes tokens that are longer than a certain byte length.
175
+ * Corresponds to the `remove_long` parameter.
176
+ */
177
+ removeLong?: number;
178
+ /**
179
+ * Removes tokens that are shorter than a certain byte length.
180
+ * Corresponds to the `remove_short` parameter.
181
+ */
182
+ removeShort?: number;
183
+ };
184
+ export type ParadeTokenizerConfig = ParadeTokenizer | {
185
+ /** The type of tokenizer to use. */
186
+ type: ParadeTokenizer;
187
+ /**
188
+ * Raw parameters for the tokenizer (e.g., for ngram min/max length).
189
+ * For common token filters, prefer using the structured `filters` property.
190
+ */
191
+ parameters?: (string | number)[];
192
+ /** Type-safe configuration for common token filters. */
193
+ filters?: ParadeTokenizerFilters;
194
+ };
195
+ export type ParadeFieldOptions = {
196
+ /**
197
+ * The tokenizer configuration for this field. Can be a simple string (e.g., 'literal')
198
+ * or a configuration object for advanced settings.
199
+ */
200
+ tokenizer?: ParadeTokenizerConfig;
201
+ /**
202
+ * Provides an alias for this field configuration, allowing the same source column
203
+ * to be indexed in multiple ways. The aliased field can be queried using
204
+ * a `$parade` query on the original field, specifying the alias.
205
+ */
206
+ alias?: string;
207
+ };
113
208
  /**
114
209
  * Factory function to create a class decorator for ORM table configuration.
115
210
  * Merges provided data with existing ORM reflection data on the class metadata.
116
211
  * @param data The ORM table reflection data to add.
117
212
  */
118
- export declare function createTableDecorator(data?: OrmTableReflectionData): ClassDecorator;
213
+ export declare function createTableDecorator<T extends BaseEntity = BaseEntity>(data?: OrmTableReflectionData<T>): ClassDecorator;
119
214
  /**
120
215
  * Factory function to create a property decorator for ORM column configuration.
121
216
  * Merges provided data with existing ORM reflection data on the property metadata.
@@ -225,4 +320,59 @@ export declare function Expires(options?: {
225
320
  after?: number;
226
321
  mode?: 'soft' | 'hard';
227
322
  }): PropertyDecorator;
323
+ /**
324
+ * Define a trigram index on a text column for similarity searches.
325
+ * @param options Index options, like the method to use ('gin' or 'gist').
326
+ */
327
+ export declare function TrigramIndex(options?: {
328
+ method?: 'gin' | 'gist';
329
+ name?: string;
330
+ }): PropertyDecorator;
331
+ export type TsVectorOptions<T extends BaseEntity> = {
332
+ /** The source columns to generate the tsvector from. */
333
+ sources: (TargetColumnPath<T>)[];
334
+ /** The text search configuration language. Defaults to 'simple'. */
335
+ language?: string | SQL;
336
+ /** Weights for different source columns. */
337
+ weights?: Partial<Record<TargetColumnPath<T>, 'A' | 'B' | 'C' | 'D'>>;
338
+ /** The index method to use on the generated column. Defaults to 'gin'. */
339
+ indexMethod?: 'gin' | 'gist';
340
+ };
341
+ /**
342
+ * Defines a `tsvector` column that is automatically generated from other columns.
343
+ * Also creates a GIN or GiST index on the column for efficient full-text search.
344
+ * @param options Configuration for the generated tsvector column.
345
+ */
346
+ export declare function GeneratedTsVector<T extends BaseEntity>(options: TsVectorOptions<T>): PropertyDecorator;
347
+ /**
348
+ * Defines a Parade BM25 full-text search index on the entity.
349
+ * Can be used on a class to define the index and its columns, or on a property to configure a specific field's tokenization.
350
+ *
351
+ * @example
352
+ * // On a class, defining index expressions
353
+ * @ParadeIndex({
354
+ * columns: [
355
+ * 'description', // simple column
356
+ * ['category', { tokenizer: 'literal' }], // column with options
357
+ * [sql`(data->>'name')::text`, { tokenizer: 'simple' }] // expression with options
358
+ * ]
359
+ * })
360
+ *
361
+ * @example
362
+ * // On a property, defining field-specific options with type-safe filters
363
+ * @ParadeIndex({
364
+ * tokenizer: {
365
+ * type: 'simple',
366
+ * filters: {
367
+ * stemmer: 'english',
368
+ * stopwordsLanguage: 'english'
369
+ * }
370
+ * }
371
+ * })
372
+ * description: string;
373
+ */
374
+ export declare function ParadeIndex<T extends BaseEntity>(options: ParadeIndexReflectionData<T>): ClassDecorator;
375
+ export declare function ParadeIndex(options?: ParadeFieldOptions): PropertyDecorator;
376
+ export declare function ParadeCompoundIndex<T extends BaseEntity>(alias: string, compoundColumns: ParadeIndexCompoundColumnColumnsProvider<T>, options?: TypedOmit<ParadeFieldOptions, 'alias'>): ClassDecorator;
377
+ export declare function ParadeExpressionIndex<T extends BaseEntity>(alias: string, expression: ParadeIndexExpressionProvider<T>, options?: TypedOmit<ParadeFieldOptions, 'alias'>): ClassDecorator;
228
378
  export {};
package/orm/decorators.js CHANGED
@@ -1,5 +1,7 @@
1
+ import { match } from 'ts-pattern';
1
2
  import { createClassDecorator, createDecorator, createPropertyDecorator } from '../reflection/index.js';
2
3
  import { Property } from '../schema/index.js';
4
+ import { merge } from '../utils/merge.js';
3
5
  import { filterUndefinedObjectProperties, objectEntries, propertyNameOf } from '../utils/object/index.js';
4
6
  import { isArray, isFunction, isString, isUndefined } from '../utils/type-guards.js';
5
7
  /**
@@ -145,3 +147,47 @@ export function TimeToLive(ttl, mode) {
145
147
  export function Expires(options) {
146
148
  return createColumnDecorator({ expirationField: { after: options?.after ?? 0, mode: options?.mode ?? 'soft' } });
147
149
  }
150
+ /**
151
+ * Define a trigram index on a text column for similarity searches.
152
+ * @param options Index options, like the method to use ('gin' or 'gist').
153
+ */
154
+ export function TrigramIndex(options) {
155
+ const method = options?.method ?? 'gin';
156
+ return Index({
157
+ name: options?.name,
158
+ using: method,
159
+ opclass: `${method}_trgm_ops`,
160
+ });
161
+ }
162
+ /**
163
+ * Defines a `tsvector` column that is automatically generated from other columns.
164
+ * Also creates a GIN or GiST index on the column for efficient full-text search.
165
+ * @param options Configuration for the generated tsvector column.
166
+ */
167
+ export function GeneratedTsVector(options) {
168
+ const { indexMethod = 'gin' } = options;
169
+ return createPropertyDecorator({
170
+ include: [
171
+ createColumnDecorator({ tsVector: options }),
172
+ Index({ using: indexMethod }),
173
+ ],
174
+ });
175
+ }
176
+ export function ParadeIndex(options) {
177
+ return createDecorator({ class: true, property: true }, (data, metadata) => {
178
+ match(metadata.metadataType)
179
+ .with('type', () => {
180
+ const existing = (metadata.data.tryGet('orm') ?? {}).paradeIndex;
181
+ const merged = merge(existing, options);
182
+ return createTableDecorator({ paradeIndex: merged })(data.constructor);
183
+ })
184
+ .with('property', () => createColumnDecorator({ paradeField: options ?? {} })(data.prototype, data.propertyKey))
185
+ .exhaustive();
186
+ });
187
+ }
188
+ export function ParadeCompoundIndex(alias, compoundColumns, options) {
189
+ return ParadeIndex({ compoundColumns: [[compoundColumns, { alias, tokenizer: 'simple', ...options }]] });
190
+ }
191
+ export function ParadeExpressionIndex(alias, expression, options) {
192
+ return ParadeIndex({ expressions: [[expression, { alias, tokenizer: 'simple', ...options }]] });
193
+ }
package/orm/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export * from './decorators.js';
7
7
  export * from './entity.js';
8
- export * from './query.js';
8
+ export * from './query/index.js';
9
9
  export * from './repository.types.js';
10
10
  export * from './schemas/index.js';
11
11
  export * from './sqls.js';
package/orm/index.js CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export * from './decorators.js';
7
7
  export * from './entity.js';
8
- export * from './query.js';
8
+ export * from './query/index.js';
9
9
  export * from './repository.types.js';
10
10
  export * from './schemas/index.js';
11
11
  export * from './sqls.js';
@@ -1,10 +1,11 @@
1
1
  import type { SQL, SQLWrapper } from 'drizzle-orm';
2
- import type { LiteralUnion, UnionToIntersection } from 'type-fest';
3
- import type { Geometry } from '../types/geo-json.js';
4
- import type { Flatten, Record } from '../types/index.js';
5
- import type { UntaggedDeep } from '../types/tagged.js';
6
- import type { BaseEntity } from './entity.js';
7
- import type { TargetColumn } from './repository.types.js';
2
+ import type { UnionToIntersection } from 'type-fest';
3
+ import type { Geometry } from '../../types/geo-json.js';
4
+ import type { Flatten, Record } from '../../types/index.js';
5
+ import type { UntaggedDeep } from '../../types/tagged.js';
6
+ import type { BaseEntity } from '../entity.js';
7
+ import type { TargetColumnPath } from '../repository.types.js';
8
+ import { type ParadeComparisonQuery, type ParadeSearchQuery, type ParadeSpecialQuery } from './parade.js';
8
9
  /** Represents a logical query combining multiple sub-queries (e.g., $and, $or, $nor). */
9
10
  export type LogicalQuery<T = any> = LogicalAndQuery<T> | LogicalOrQuery<T> | LogicalNorQuery<T>;
10
11
  /** Union of keys representing logical query operators ('$and', '$or', '$nor'). */
@@ -18,7 +19,7 @@ export type ComparisonQueryBody<T = any> = {
18
19
  /** Represents either a full comparison query object or a direct value for equality comparison. */
19
20
  export type ComparisonQueryOrValue<T = any> = ComparisonQuery<T> | ComparisonValue<T>;
20
21
  /** Represents a comparison query using various operators like $eq, $ne, $gt, $in, etc. */
21
- export type ComparisonQuery<T = any> = Partial<ComparisonAndQuery<T> & ComparisonOrQuery<T> & ComparisonNotQuery<T> & ComparisonEqualsQuery<T> & ComparisonNotEqualsQuery<T> & ComparisonExistsQuery & ComparisonItemQuery<T> & ComparisonInQuery<T> & ComparisonNotInQuery<T> & ComparisonAllQuery<T> & ComparisonGreaterThanQuery<T> & ComparisonGreaterThanOrEqualsQuery<T> & ComparisonLessThanQuery<T> & ComparisonLessThanOrEqualsQuery<T> & ComparisonRegexQuery & ComparisonTsVectorQuery & ComparisonTrigramQuery & ComparisonParadeMatchQuery & ComparisonParadeTantivyQuery & ComparisonGeoShapeQuery & ComparisonGeoDistanceQuery>;
22
+ export type ComparisonQuery<T = any> = Partial<ComparisonAndQuery<T> & ComparisonOrQuery<T> & ComparisonNotQuery<T> & ComparisonEqualsQuery<T> & ComparisonNotEqualsQuery<T> & ComparisonExistsQuery & ComparisonItemQuery<T> & ComparisonInQuery<T> & ComparisonNotInQuery<T> & ComparisonAllQuery<T> & ComparisonGreaterThanQuery<T> & ComparisonGreaterThanOrEqualsQuery<T> & ComparisonLessThanQuery<T> & ComparisonLessThanOrEqualsQuery<T> & ComparisonRegexQuery & ComparisonTsVectorQuery & ComparisonTrigramQuery & ParadeComparisonQuery & ComparisonGeoShapeQuery & ComparisonGeoDistanceQuery>;
22
23
  export type TsVectorParser = 'raw' | 'plain' | 'phrase' | 'websearch';
23
24
  export type TsVectorWeight = 'A' | 'B' | 'C' | 'D';
24
25
  export type TrigramSimilarityType = 'phrase' | 'word' | 'strict-word';
@@ -27,8 +28,8 @@ export type ComparisonQueryTypes = keyof ComparisonQuery;
27
28
  /** Array containing all valid comparison query operator keys. */
28
29
  export declare const allComparisonQueryTypes: ComparisonQueryTypes[];
29
30
  /** Represents specialized query types beyond simple comparisons. */
30
- export type SpecialQuery<T extends BaseEntity = BaseEntity> = FullTextSearchQuery<T>;
31
- export type FullTextSearchQuery<T extends BaseEntity = BaseEntity> = TsVectorSearchQuery<T> | TrigramSearchQuery<T> | ParadeDbSearchQuery<T>;
31
+ export type SpecialQuery<T extends BaseEntity = BaseEntity> = FullTextSearchQuery<T> | ParadeSpecialQuery<T>;
32
+ export type FullTextSearchQuery<T extends BaseEntity = BaseEntity> = TsVectorSearchQuery<T> | TrigramSearchQuery<T> | ParadeSearchQuery<T>;
32
33
  /** Union of keys representing special query operators. */
33
34
  export type SpecialQueryTypes = keyof UnionToIntersection<SpecialQuery>;
34
35
  /** Array containing all valid special query operator keys. */
@@ -40,11 +41,11 @@ export declare const allSpecialQueryTypes: SpecialQueryTypes[];
40
41
  */
41
42
  export type Query<T = any> = SQLWrapper | QueryObject<Extract<UntaggedDeep<T>, BaseEntity>>;
42
43
  /** Represents a structured query object, combining logical, comparison, and special queries. */
43
- export type QueryObject<T extends BaseEntity> = LogicalQuery<T> | (ComparisonQueryBody<T> & Partial<SpecialQuery<T>>);
44
+ export type QueryObject<T extends BaseEntity> = LogicalQuery<T> | Partial<SpecialQuery<T>> | ComparisonQueryBody<T>;
44
45
  /** Union of all possible query operator keys (logical, comparison, special). */
45
46
  export type QueryTypes = LogicalQueryTypes | ComparisonQueryTypes | SpecialQueryTypes;
46
47
  /** Array containing all valid query operator keys. */
47
- export declare const allQueryTypes: ("$and" | "$or" | "$nor" | "$not" | "$eq" | "$neq" | "$exists" | "$item" | "$in" | "$nin" | "$all" | "$gt" | "$gte" | "$lt" | "$lte" | "$regex" | "$tsvector" | "$trigram" | "$match" | "$tantivy" | "$geoShape" | "$geoDistance" | "$parade")[];
48
+ export declare const allQueryTypes: ("$parade" | "$and" | "$or" | "$nor" | "$not" | "$eq" | "$neq" | "$exists" | "$item" | "$in" | "$nin" | "$all" | "$gt" | "$gte" | "$lt" | "$lte" | "$regex" | "$tsvector" | "$trigram" | "$geoShape" | "$geoDistance")[];
48
49
  /** Represents an AND logical query. All sub-queries must be true. */
49
50
  export type LogicalAndQuery<T = any> = {
50
51
  $and: readonly Query<T>[];
@@ -148,23 +149,6 @@ export type ComparisonTrigramQuery = {
148
149
  threshold?: number;
149
150
  };
150
151
  };
151
- /** Represents a ParadeDB match query. */
152
- export type ComparisonParadeMatchQuery = {
153
- $match: string | {
154
- query: string;
155
- distance?: number;
156
- prefix?: boolean;
157
- conjunctionMode?: boolean;
158
- };
159
- };
160
- /** Represents a ParadeDB parse query (Tantivy syntax). */
161
- export type ComparisonParadeTantivyQuery = {
162
- $tantivy: string | {
163
- query: string;
164
- conjunctionMode?: boolean;
165
- lenient?: boolean;
166
- };
167
- };
168
152
  /** Defines the possible spatial relationships for geospatial shape queries. */
169
153
  export type GeoShapeRelation = 'intersects' | 'within' | 'disjoint' | 'contains';
170
154
  /** Represents a geospatial query based on shape relationships ($geoShape). */
@@ -192,7 +176,7 @@ export type ComparisonGeoDistanceQuery = {
192
176
  /** Represents a multi-field tsvector search. */
193
177
  export type TsVectorSearchQuery<T extends BaseEntity = BaseEntity> = {
194
178
  $tsvector: {
195
- fields: readonly (TargetColumn<T> | readonly [TargetColumn<T>, TsVectorWeight])[];
179
+ fields: readonly (TargetColumnPath<T> | readonly [TargetColumnPath<T>, TsVectorWeight])[];
196
180
  query: string | SQL<string>;
197
181
  parser?: TsVectorParser;
198
182
  language?: string | SQL<string>;
@@ -201,145 +185,9 @@ export type TsVectorSearchQuery<T extends BaseEntity = BaseEntity> = {
201
185
  /** Represents a multi-field trigram search. */
202
186
  export type TrigramSearchQuery<T extends BaseEntity = BaseEntity> = {
203
187
  $trigram: {
204
- fields: readonly TargetColumn<T>[];
188
+ fields: readonly TargetColumnPath<T>[];
205
189
  query: string | SQL<string>;
206
190
  type?: TrigramSimilarityType;
207
191
  threshold?: number;
208
192
  };
209
193
  };
210
- /**
211
- * Represents a ParadeDB tokenizer configuration object for a `match` query.
212
- */
213
- export type ParadeDbTokenizerObject = {
214
- type: LiteralUnion<'default' | 'whitespace' | 'raw' | 'keyword' | 'regex' | 'ngram' | 'source_code' | 'chinese_compatible' | 'chinese_lindera' | 'korean_lindera' | 'japanese_lindera' | 'jieba' | 'icu', string>;
215
- [key: string]: any;
216
- };
217
- /**
218
- * Represents a bound for a ParadeDB range query.
219
- */
220
- type ParadeDbRangeBound<V> = {
221
- included: V;
222
- } | {
223
- excluded: V;
224
- };
225
- /** A recursive type representing the rich ParadeDB / Tantivy query DSL. */
226
- export type ParadeDbQueryObject<T extends BaseEntity = BaseEntity> = {
227
- all?: null;
228
- empty?: null;
229
- term?: {
230
- field: TargetColumn<T>;
231
- value: any;
232
- };
233
- fuzzy_term?: {
234
- field: TargetColumn<T>;
235
- value: string;
236
- distance?: number;
237
- transposition_cost_one?: boolean;
238
- prefix?: boolean;
239
- };
240
- regex?: {
241
- field: TargetColumn<T>;
242
- pattern: string;
243
- };
244
- phrase?: {
245
- field: TargetColumn<T>;
246
- phrases: readonly string[];
247
- slop?: number;
248
- };
249
- match?: {
250
- field: TargetColumn<T>;
251
- value: string;
252
- distance?: number;
253
- prefix?: boolean;
254
- conjunction_mode?: boolean;
255
- tokenizer?: ParadeDbTokenizerObject;
256
- transposition_cost_one?: boolean;
257
- };
258
- boolean?: {
259
- must?: ParadeDbQueryObject<T> | readonly ParadeDbQueryObject<T>[];
260
- should?: ParadeDbQueryObject<T> | readonly ParadeDbQueryObject<T>[];
261
- must_not?: ParadeDbQueryObject<T> | readonly ParadeDbQueryObject<T>[];
262
- };
263
- boost?: {
264
- query: ParadeDbQueryObject<T>;
265
- factor: number;
266
- };
267
- const_score?: {
268
- query: ParadeDbQueryObject<T>;
269
- score: number;
270
- };
271
- disjunction_max?: {
272
- disjuncts: readonly ParadeDbQueryObject<T>[];
273
- tie_breaker?: number;
274
- };
275
- parse?: {
276
- query_string: string | SQL<string>;
277
- lenient?: boolean;
278
- conjunction_mode?: boolean;
279
- };
280
- parse_with_field?: {
281
- field: TargetColumn<T>;
282
- query_string: string | SQL<string>;
283
- lenient?: boolean;
284
- conjunction_mode?: boolean;
285
- };
286
- exists?: {
287
- field: TargetColumn<T>;
288
- };
289
- range?: {
290
- field: TargetColumn<T>;
291
- lower_bound?: ParadeDbRangeBound<any> | null;
292
- upper_bound?: ParadeDbRangeBound<any> | null;
293
- is_datetime?: boolean;
294
- };
295
- term_set?: {
296
- terms: readonly ParadeDbQueryObject<T>[];
297
- };
298
- phrase_prefix?: {
299
- field: TargetColumn<T>;
300
- phrases: readonly string[];
301
- max_expansions?: number;
302
- };
303
- regex_phrase?: {
304
- field: TargetColumn<T>;
305
- regexes: readonly string[];
306
- slop?: number;
307
- max_expansions?: number;
308
- };
309
- more_like_this?: {
310
- key_value?: any;
311
- document?: readonly [string, any][];
312
- min_doc_frequency?: number;
313
- max_doc_frequency?: number;
314
- min_term_frequency?: number;
315
- max_query_terms?: number;
316
- min_word_length?: number;
317
- max_word_length?: number;
318
- boost_factor?: number;
319
- stop_words?: readonly string[];
320
- };
321
- range_term?: {
322
- field: TargetColumn<T>;
323
- value: any;
324
- };
325
- range_intersects?: {
326
- field: TargetColumn<T>;
327
- lower_bound: ParadeDbRangeBound<any>;
328
- upper_bound: ParadeDbRangeBound<any>;
329
- };
330
- range_contains?: {
331
- field: TargetColumn<T>;
332
- lower_bound: ParadeDbRangeBound<any>;
333
- upper_bound: ParadeDbRangeBound<any>;
334
- };
335
- range_within?: {
336
- field: TargetColumn<T>;
337
- lower_bound: ParadeDbRangeBound<any>;
338
- upper_bound: ParadeDbRangeBound<any>;
339
- };
340
- };
341
- /** Represents a ParadeDB search using its native JSON-based query language. */
342
- export type ParadeDbSearchQuery<T extends BaseEntity = BaseEntity> = {
343
- $parade: ParadeDbQueryObject<T>;
344
- };
345
- export {};
@@ -1,8 +1,9 @@
1
+ import { paradeComparisonQueryTypes, paradeSpecialQueryTypes } from './parade.js';
1
2
  /** Array containing all valid logical query operator keys. */
2
3
  export const allLogicalQueryTypes = ['$and', '$or', '$nor'];
3
4
  /** Array containing all valid comparison query operator keys. */
4
- export const allComparisonQueryTypes = ['$all', '$not', '$eq', '$exists', '$gt', '$gte', '$in', '$item', '$lt', '$lte', '$neq', '$nin', '$regex', '$tsvector', '$trigram', '$match', '$tantivy', '$geoDistance', '$geoShape'];
5
+ export const allComparisonQueryTypes = ['$all', '$not', '$eq', '$exists', '$gt', '$gte', '$in', '$item', '$lt', '$lte', '$neq', '$nin', '$regex', '$tsvector', '$trigram', '$geoDistance', '$geoShape', ...paradeComparisonQueryTypes];
5
6
  /** Array containing all valid special query operator keys. */
6
- export const allSpecialQueryTypes = ['$tsvector', '$trigram', '$parade'];
7
+ export const allSpecialQueryTypes = ['$tsvector', '$trigram', ...paradeSpecialQueryTypes];
7
8
  /** Array containing all valid query operator keys. */
8
9
  export const allQueryTypes = [...allLogicalQueryTypes, ...allComparisonQueryTypes, ...allSpecialQueryTypes];
@@ -0,0 +1,2 @@
1
+ export * from './base.js';
2
+ export * from './parade.js';
@@ -0,0 +1,2 @@
1
+ export * from './base.js';
2
+ export * from './parade.js';