@tstdl/base 0.93.20 → 0.93.22

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 (68) hide show
  1. package/application/application.js +1 -1
  2. package/audit/auditor.js +1 -1
  3. package/authentication/server/authentication.service.js +1 -1
  4. package/authentication/server/module.d.ts +1 -1
  5. package/authentication/server/module.js +1 -6
  6. package/document-management/api/document-management.api.d.ts +0 -4
  7. package/document-management/server/services/singleton.js +1 -1
  8. package/document-management/service-models/document.service-model.d.ts +0 -2
  9. package/injector/injector.d.ts +1 -1
  10. package/injector/injector.js +25 -13
  11. package/injector/types.d.ts +1 -1
  12. package/key-value-store/postgres/key-value-store.service.js +1 -1
  13. package/lock/postgres/provider.js +1 -1
  14. package/logger/manager.js +3 -3
  15. package/mail/mail.service.js +1 -1
  16. package/orm/data-types/bytea.d.ts +4 -14
  17. package/orm/data-types/bytea.js +2 -2
  18. package/orm/data-types/common.d.ts +18 -0
  19. package/orm/data-types/common.js +11 -0
  20. package/orm/data-types/index.d.ts +1 -0
  21. package/orm/data-types/index.js +1 -0
  22. package/orm/data-types/numeric-date.d.ts +4 -15
  23. package/orm/data-types/numeric-date.js +2 -2
  24. package/orm/data-types/timestamp.d.ts +4 -15
  25. package/orm/data-types/timestamp.js +2 -2
  26. package/orm/data-types/tsvector.d.ts +3 -13
  27. package/orm/data-types/tsvector.js +2 -2
  28. package/orm/decorators.d.ts +16 -54
  29. package/orm/decorators.js +24 -37
  30. package/orm/entity.d.ts +6 -9
  31. package/orm/entity.js +1 -2
  32. package/orm/query.d.ts +199 -61
  33. package/orm/query.js +2 -2
  34. package/orm/repository.types.d.ts +38 -9
  35. package/orm/server/drizzle/schema-converter.js +40 -118
  36. package/orm/server/query-converter.d.ts +21 -7
  37. package/orm/server/query-converter.js +194 -38
  38. package/orm/server/repository.d.ts +39 -22
  39. package/orm/server/repository.js +141 -71
  40. package/orm/server/types.d.ts +10 -2
  41. package/orm/sqls.d.ts +14 -16
  42. package/orm/sqls.js +34 -17
  43. package/package.json +2 -2
  44. package/queue/postgres/queue.js +1 -1
  45. package/test/drizzle/0000_nervous_iron_monger.sql +9 -0
  46. package/test/drizzle/meta/0000_snapshot.json +27 -7
  47. package/test/drizzle/meta/_journal.json +2 -44
  48. package/test/test.model.js +2 -6
  49. package/test1.js +18 -5
  50. package/test6.js +21 -35
  51. package/types/types.d.ts +8 -5
  52. package/utils/equals.js +2 -2
  53. package/utils/format-error.js +2 -2
  54. package/utils/helpers.js +3 -2
  55. package/utils/object/object.d.ts +4 -4
  56. package/test/drizzle/0000_sudden_sphinx.sql +0 -9
  57. package/test/drizzle/0001_organic_rhodey.sql +0 -2
  58. package/test/drizzle/0002_nice_squadron_supreme.sql +0 -1
  59. package/test/drizzle/0003_serious_mockingbird.sql +0 -1
  60. package/test/drizzle/0004_complete_pixie.sql +0 -1
  61. package/test/drizzle/0005_bumpy_sabra.sql +0 -1
  62. package/test/drizzle/0006_overrated_post.sql +0 -6
  63. package/test/drizzle/meta/0001_snapshot.json +0 -79
  64. package/test/drizzle/meta/0002_snapshot.json +0 -63
  65. package/test/drizzle/meta/0003_snapshot.json +0 -73
  66. package/test/drizzle/meta/0004_snapshot.json +0 -89
  67. package/test/drizzle/meta/0005_snapshot.json +0 -104
  68. package/test/drizzle/meta/0006_snapshot.json +0 -104
package/orm/decorators.js CHANGED
@@ -2,6 +2,28 @@ import { createClassDecorator, createDecorator, createPropertyDecorator } from '
2
2
  import { Property } from '../schema/index.js';
3
3
  import { filterUndefinedObjectProperties, objectEntries, propertyNameOf } from '../utils/object/index.js';
4
4
  import { isArray, isString, isUndefined } from '../utils/type-guards.js';
5
+ /**
6
+ * Merges ORM reflection data into the target's metadata.
7
+ * @param metadata The metadata object for the class or property.
8
+ * @param data The ORM reflection data to merge.
9
+ */
10
+ function mergeOrmReflectionData(metadata, data) {
11
+ const reflectionData = metadata.data.tryGet('orm') ?? {};
12
+ const dataEntries = objectEntries(data);
13
+ if (dataEntries.length == 0) {
14
+ return;
15
+ }
16
+ for (const [key, value] of dataEntries) {
17
+ const existingValue = reflectionData[key];
18
+ if (isArray(existingValue)) {
19
+ reflectionData[key] = [...existingValue, ...value];
20
+ }
21
+ else {
22
+ reflectionData[key] = value;
23
+ }
24
+ }
25
+ metadata.data.set('orm', reflectionData, true);
26
+ }
5
27
  /**
6
28
  * Factory function to create a class decorator for ORM table configuration.
7
29
  * Merges provided data with existing ORM reflection data on the class metadata.
@@ -9,23 +31,7 @@ import { isArray, isString, isUndefined } from '../utils/type-guards.js';
9
31
  */
10
32
  export function createTableDecorator(data = {}) {
11
33
  return createClassDecorator({
12
- handler: (_, metadata) => {
13
- const reflectionData = metadata.data.tryGet('orm') ?? {};
14
- const dataEntries = objectEntries(data);
15
- if (dataEntries.length == 0) {
16
- return;
17
- }
18
- for (const [key, value] of dataEntries) {
19
- const existingValue = reflectionData[key];
20
- if (isArray(existingValue)) {
21
- reflectionData[key] = [...existingValue, ...value];
22
- }
23
- else {
24
- reflectionData[key] = value;
25
- }
26
- }
27
- metadata.data.set('orm', reflectionData, true);
28
- },
34
+ handler: (_, metadata) => mergeOrmReflectionData(metadata, data),
29
35
  });
30
36
  }
31
37
  /**
@@ -35,23 +41,7 @@ export function createTableDecorator(data = {}) {
35
41
  */
36
42
  export function createColumnDecorator(data = {}, decoratorOptions) {
37
43
  return createPropertyDecorator({
38
- handler: (_, metadata) => {
39
- const reflectionData = metadata.data.tryGet('orm') ?? {};
40
- const dataEntries = objectEntries(data);
41
- if (dataEntries.length == 0) {
42
- return;
43
- }
44
- for (const [key, value] of dataEntries) {
45
- const existingValue = reflectionData[key];
46
- if (isArray(existingValue)) {
47
- reflectionData[key] = [...existingValue, ...value];
48
- }
49
- else {
50
- reflectionData[key] = value;
51
- }
52
- }
53
- metadata.data.set('orm', reflectionData, true);
54
- },
44
+ handler: (_, metadata) => mergeOrmReflectionData(metadata, data),
55
45
  ...decoratorOptions,
56
46
  });
57
47
  }
@@ -137,9 +127,6 @@ export function Index(columnsOrOptions, options) {
137
127
  }
138
128
  return createColumnDecorator({ index: { options: columnsOrOptions } });
139
129
  }
140
- export function FullTextSearch(name, options) {
141
- return createTableDecorator({ fullTextSearch: [{ name, ...options }] });
142
- }
143
130
  /**
144
131
  * Automatically expire records after a certain time to live (TTL) based on the createTimestamp metadata. Requires extension of {@link Entity} instead of {@link BaseEntity}.
145
132
  * @param ttl Time To Live in milliseconds.
package/orm/entity.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Record, Type } from '../types/index.js';
1
+ import type { Type } from '../types/index.js';
2
2
  import type { Embedded, HasDefault, IsPrimaryKey, Json, Timestamp, Uuid } from './types.js';
3
3
  /**
4
4
  * Represents the type (constructor) of an entity, potentially holding an entity name.
@@ -8,8 +8,6 @@ export interface EntityType<T extends BaseEntity = BaseEntity | Entity> extends
8
8
  readonly entityName?: string;
9
9
  }
10
10
  export type AnyEntity = BaseEntity | Entity;
11
- export type EntityMeta = Record<string>;
12
- export declare const entityMeta: "__entityMeta__";
13
11
  /**
14
12
  * Base class for extensible metadata attributes associated with an entity.
15
13
  * Allows storing arbitrary key-value pairs.
@@ -31,25 +29,24 @@ export declare abstract class EntityMetadata {
31
29
  * Abstract base class for entities that do *not* include the standard metadata fields.
32
30
  * Provides only a default `id` (UUID primary key). Useful for simpler tables or join tables.
33
31
  */
34
- export declare abstract class BaseEntity<TMeta extends EntityMeta = EntityMeta> {
32
+ export declare abstract class BaseEntity {
35
33
  id: IsPrimaryKey<HasDefault<Uuid>>;
36
- readonly [entityMeta]?: TMeta;
37
34
  }
38
35
  /**
39
36
  * Abstract base class for entities that include standard metadata.
40
37
  * Provides a default `id` (UUID primary key) and an `metadata` field.
41
38
  */
42
- export declare abstract class Entity<TMeta extends EntityMeta = EntityMeta> extends BaseEntity<TMeta> {
39
+ export declare abstract class Entity extends BaseEntity {
43
40
  metadata: Embedded<EntityMetadata>;
44
41
  }
45
- export declare abstract class TenantEntity<TMeta extends EntityMeta = EntityMeta> extends Entity<TMeta> {
42
+ export declare abstract class TenantEntity extends Entity {
46
43
  tenantId: Uuid;
47
44
  }
48
- export declare abstract class TenantBaseEntity<TMeta extends EntityMeta = EntityMeta> extends BaseEntity<TMeta> {
45
+ export declare abstract class TenantBaseEntity extends BaseEntity {
49
46
  tenantId: Uuid;
50
47
  }
51
48
  export {
52
49
  /**
53
50
  * @deprecated Use BaseEntity instead.
54
51
  */
55
- BaseEntity as EntityWithoutMetadata, };
52
+ BaseEntity as EntityWithoutMetadata };
package/orm/entity.js CHANGED
@@ -14,7 +14,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
14
14
  import { Defaulted, Integer } from '../schema/index.js';
15
15
  import { EmbeddedProperty, PrimaryKeyProperty } from './decorators.js';
16
16
  import { JsonProperty, TimestampProperty, UuidProperty } from './schemas/index.js';
17
- export const entityMeta = '__entityMeta__';
18
17
  /**
19
18
  * Base class for extensible metadata attributes associated with an entity.
20
19
  * Allows storing arbitrary key-value pairs.
@@ -96,4 +95,4 @@ export {
96
95
  /**
97
96
  * @deprecated Use BaseEntity instead.
98
97
  */
99
- BaseEntity as EntityWithoutMetadata, };
98
+ BaseEntity as EntityWithoutMetadata };
package/orm/query.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import type { SQL, SQLWrapper } from 'drizzle-orm';
2
+ import type { LiteralUnion, UnionToIntersection } from 'type-fest';
2
3
  import type { Geometry } from '../types/geo-json.js';
3
4
  import type { Flatten, Record } from '../types/index.js';
4
5
  import type { UntaggedDeep } from '../types/tagged.js';
6
+ import type { BaseEntity } from './entity.js';
7
+ import type { TargetColumn } from './repository.types.js';
5
8
  /** Represents a logical query combining multiple sub-queries (e.g., $and, $or, $nor). */
6
9
  export type LogicalQuery<T = any> = LogicalAndQuery<T> | LogicalOrQuery<T> | LogicalNorQuery<T>;
7
10
  /** Union of keys representing logical query operators ('$and', '$or', '$nor'). */
@@ -15,16 +18,19 @@ export type ComparisonQueryBody<T = any> = {
15
18
  /** Represents either a full comparison query object or a direct value for equality comparison. */
16
19
  export type ComparisonQueryOrValue<T = any> = ComparisonQuery<T> | ComparisonValue<T>;
17
20
  /** Represents a comparison query using various operators like $eq, $ne, $gt, $in, etc. */
18
- 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 & ComparisonFtsQuery & ComparisonGeoShapeQuery & ComparisonGeoDistanceQuery>;
19
- export type FtsParser = 'raw' | 'plain' | 'phrase' | 'websearch';
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 TsVectorParser = 'raw' | 'plain' | 'phrase' | 'websearch';
23
+ export type TsVectorWeight = 'A' | 'B' | 'C' | 'D';
24
+ export type TrigramSimilarityType = 'phrase' | 'word' | 'strict-word';
20
25
  /** Union of keys representing comparison query operators. */
21
26
  export type ComparisonQueryTypes = keyof ComparisonQuery;
22
27
  /** Array containing all valid comparison query operator keys. */
23
28
  export declare const allComparisonQueryTypes: ComparisonQueryTypes[];
24
29
  /** Represents specialized query types beyond simple comparisons. */
25
- export type SpecialQuery<T = any> = Partial<FullTextSearchQuery<T>>;
30
+ export type SpecialQuery<T extends BaseEntity = BaseEntity> = FullTextSearchQuery<T>;
31
+ export type FullTextSearchQuery<T extends BaseEntity = BaseEntity> = TsVectorSearchQuery<T> | TrigramSearchQuery<T> | ParadeDbSearchQuery<T>;
26
32
  /** Union of keys representing special query operators. */
27
- export type SpecialQueryTypes = keyof SpecialQuery;
33
+ export type SpecialQueryTypes = keyof UnionToIntersection<SpecialQuery>;
28
34
  /** Array containing all valid special query operator keys. */
29
35
  export declare const allSpecialQueryTypes: SpecialQueryTypes[];
30
36
  /**
@@ -32,13 +38,13 @@ export declare const allSpecialQueryTypes: SpecialQueryTypes[];
32
38
  * or a structured query object using logical and comparison operators.
33
39
  * @template T - The type of the entity being queried.
34
40
  */
35
- export type Query<T = any> = SQLWrapper | QueryObject<UntaggedDeep<T>>;
41
+ export type Query<T = any> = SQLWrapper | QueryObject<Extract<UntaggedDeep<T>, BaseEntity>>;
36
42
  /** Represents a structured query object, combining logical, comparison, and special queries. */
37
- export type QueryObject<T> = LogicalQuery<T> | (ComparisonQueryBody<T> & SpecialQuery<T>);
43
+ export type QueryObject<T extends BaseEntity> = LogicalQuery<T> | (ComparisonQueryBody<T> & Partial<SpecialQuery<T>>);
38
44
  /** Union of all possible query operator keys (logical, comparison, special). */
39
45
  export type QueryTypes = LogicalQueryTypes | ComparisonQueryTypes | SpecialQueryTypes;
40
46
  /** Array containing all valid query operator keys. */
41
- export declare const allQueryTypes: ("$and" | "$or" | "$nor" | "$not" | "$eq" | "$neq" | "$exists" | "$item" | "$in" | "$nin" | "$all" | "$gt" | "$gte" | "$lt" | "$lte" | "$regex" | "$fts" | "$geoShape" | "$geoDistance")[];
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")[];
42
48
  /** Represents an AND logical query. All sub-queries must be true. */
43
49
  export type LogicalAndQuery<T = any> = {
44
50
  $and: readonly Query<T>[];
@@ -118,24 +124,45 @@ export type ComparisonRegexQuery = {
118
124
  flags: string;
119
125
  };
120
126
  };
121
- /** Represents a full-text search query. */
122
- export type ComparisonFtsQuery = {
123
- $fts: string | {
127
+ /** Represents a single-field tsvector full-text search query. */
128
+ export type ComparisonTsVectorQuery = {
129
+ $tsvector: string | {
124
130
  query: string;
131
+ parser?: TsVectorParser;
125
132
  /**
126
- * The search method to use.
127
- * - 'vector': (Default) Standard full-text search using tsvector and tsquery.
128
- * - 'similarity': Trigram-based similarity search using the pg_trgm extension.
133
+ * The language to use for the full-text search (e.g., 'english', 'simple').
129
134
  */
130
- method?: 'vector' | 'similarity';
131
- /**
132
- * The parser to use for the query. Only applicable for 'vector' method.
133
- */
134
- parser?: FtsParser;
135
+ language?: string | SQL;
136
+ };
137
+ };
138
+ /** Represents a single-field trigram similarity search query. */
139
+ export type ComparisonTrigramQuery = {
140
+ $trigram: string | {
141
+ query: string;
142
+ type?: TrigramSimilarityType;
135
143
  /**
136
- * The text search configuration (e.g., 'english', 'simple'). Can also be a SQL object for dynamic configuration. Only applicable for 'vector' method.
144
+ * ### **WARNING**
145
+ * Using a threshold here impacts performance as it switches from the `%` operator to a similarity comparison requiring functions.
146
+ * Use `pg_trgm.similarity_threshold(threshold)`, `pg_trgm.word_similarity_threshold(threshold)` or `pg_trgm.-_similarity_threshold(threshold)` to set a global threshold instead and omit this option, if possible.
137
147
  */
138
- language?: string | SQL;
148
+ threshold?: number;
149
+ };
150
+ };
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;
139
166
  };
140
167
  };
141
168
  /** Defines the possible spatial relationships for geospatial shape queries. */
@@ -162,46 +189,157 @@ export type ComparisonGeoDistanceQuery = {
162
189
  minDistance?: number;
163
190
  };
164
191
  };
165
- /** Represents a full-text search query across one or more fields. Used by the `search` repository method. */
166
- export type FullTextSearchQuery<T = any> = {
167
- $fts: {
168
- fields: readonly (Extract<keyof T, string>)[];
169
- text: string | SQL<string>;
170
- /**
171
- * The search method to use.
172
- * - 'vector': (Default) Standard full-text search using tsvector and tsquery.
173
- * - 'trigram': Trigram-based similarity search using the pg_trgm extension.
174
- */
175
- method?: 'vector' | 'trigram';
176
- vector?: {
177
- /**
178
- * The parser to use for the query. Only applicable for 'vector' method.
179
- */
180
- parser?: FtsParser;
181
- /**
182
- * The text search configuration (e.g., 'english', 'simple'). Can also be a SQL object for dynamic configuration. Only applicable for 'vector' method.
183
- */
184
- language?: string | SQL<string>;
185
- /**
186
- * Assigns weights to fields for ranking.
187
- * Keys are field names from `fields`, values are 'A', 'B', 'C', or 'D'.
188
- * Fields without a specified weight will use the default. Only applicable for 'vector' method.
189
- */
190
- weights?: Partial<Record<Extract<keyof T, string>, 'A' | 'B' | 'C' | 'D'>>;
191
- };
192
- trigram?: {
193
- /**
194
- * Type of similarity to use for 'trigram' search.
195
- * - 'normal': Standard trigram similarity (default).
196
- * - 'word': Word-based similarity.
197
- * - 'strict-word': Strict word-based similarity.
198
- * @default 'normal'
199
- */
200
- type?: 'phrase' | 'word' | 'strict-word';
201
- /**
202
- * Threshold for similarity matching (0 to 1). Only applicable for 'trigram' method.
203
- */
204
- threshold?: number | SQL<number>;
205
- };
192
+ /** Represents a multi-field tsvector search. */
193
+ export type TsVectorSearchQuery<T extends BaseEntity = BaseEntity> = {
194
+ $tsvector: {
195
+ fields: readonly (TargetColumn<T> | readonly [TargetColumn<T>, TsVectorWeight])[];
196
+ query: string | SQL<string>;
197
+ parser?: TsVectorParser;
198
+ language?: string | SQL<string>;
206
199
  };
207
200
  };
201
+ /** Represents a multi-field trigram search. */
202
+ export type TrigramSearchQuery<T extends BaseEntity = BaseEntity> = {
203
+ $trigram: {
204
+ fields: readonly TargetColumn<T>[];
205
+ query: string | SQL<string>;
206
+ type?: TrigramSimilarityType;
207
+ threshold?: number;
208
+ };
209
+ };
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 {};
package/orm/query.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /** Array containing all valid logical query operator keys. */
2
2
  export const allLogicalQueryTypes = ['$and', '$or', '$nor'];
3
3
  /** 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', '$fts', '$geoDistance', '$geoShape'];
4
+ export const allComparisonQueryTypes = ['$all', '$not', '$eq', '$exists', '$gt', '$gte', '$in', '$item', '$lt', '$lte', '$neq', '$nin', '$regex', '$tsvector', '$trigram', '$match', '$tantivy', '$geoDistance', '$geoShape'];
5
5
  /** Array containing all valid special query operator keys. */
6
- export const allSpecialQueryTypes = ['$fts'];
6
+ export const allSpecialQueryTypes = ['$tsvector', '$trigram', '$parade'];
7
7
  /** Array containing all valid query operator keys. */
8
8
  export const allQueryTypes = [...allLogicalQueryTypes, ...allComparisonQueryTypes, ...allSpecialQueryTypes];
@@ -3,9 +3,9 @@
3
3
  * Defines types used by ORM repositories for operations like loading, updating, and creating entities.
4
4
  * Includes types for ordering, loading options, and entity data structures for create/update operations.
5
5
  */
6
- import type { Paths, Record, SimplifyObject, TypedOmit } from '../types/index.js';
6
+ import type { Path, Record, SimplifyObject, TypedOmit } from '../types/index.js';
7
7
  import type { UntaggedDeep } from '../types/tagged.js';
8
- import type { SQL, SQLWrapper } from 'drizzle-orm';
8
+ import type { AnyColumn, SQL, SQLWrapper } from 'drizzle-orm';
9
9
  import type { PartialDeep } from 'type-fest';
10
10
  import type { BaseEntity, Entity, EntityMetadata } from './entity.js';
11
11
  import type { FullTextSearchQuery, Query } from './query.js';
@@ -18,13 +18,13 @@ type WithSql<T> = {
18
18
  * or a raw Drizzle SQLWrapper for a complex target.
19
19
  * @template T - The entity type.
20
20
  */
21
- export type TargetColumnPaths<T extends BaseEntity> = Paths<UntaggedDeep<T>>;
21
+ export type TargetColumnPath<T extends BaseEntity = BaseEntity> = Path<UntaggedDeep<T>>;
22
22
  /**
23
23
  * Specifies the target column (e.g. for ordering, distinct on), which can be a property path within the entity
24
24
  * or a raw Drizzle SQLWrapper for a complex target.
25
25
  * @template T - The entity type.
26
26
  */
27
- export type TargetColumn<T extends BaseEntity> = TargetColumnPaths<T> | SQLWrapper;
27
+ export type TargetColumn<T extends BaseEntity = BaseEntity> = TargetColumnPath<T> | SQL | SQL.Aliased | AnyColumn;
28
28
  /** Specifies the direction for ordering results ('asc' or 'desc'). */
29
29
  export type OrderDirection = 'asc' | 'desc';
30
30
  /**
@@ -78,13 +78,42 @@ export type HighlightOptions<T extends BaseEntity> = {
78
78
  /**
79
79
  * The source to generate the highlight from. Can be one or more property paths or a raw SQL expression.
80
80
  */
81
- source: TargetColumnPaths<T> | SQL<string>;
82
- } & TsHeadlineOptions;
81
+ source: TargetColumnPath<T> | SQL<string>;
82
+ } & (TsHeadlineOptions | ParadeDbHighlightOptions);
83
+ /**
84
+ * Options for highlighting with ParadeDB (`pdb.snippet`).
85
+ */
86
+ export type ParadeDbHighlightOptions = {
87
+ /**
88
+ * Limits the number of characters in the snippet. Defaults to 150.
89
+ */
90
+ maxNumChars?: number;
91
+ /**
92
+ * The tag to use for the start of a highlighted term. Defaults to '<b>'.
93
+ */
94
+ startTag?: string;
95
+ /**
96
+ * The tag to use for the end of a highlighted term. Defaults to '</b>'.
97
+ */
98
+ endTag?: string;
99
+ /**
100
+ * Limits the number of highlighted terms returned in the snippet.
101
+ */
102
+ limit?: number;
103
+ /**
104
+ * Ignores the first N highlighted terms.
105
+ */
106
+ offset?: number;
107
+ };
83
108
  /**
84
109
  * Options for the `search` method.
85
110
  * @template T - The entity type.
86
111
  */
87
- export type SearchOptions<T extends BaseEntity> = SimplifyObject<FullTextSearchQuery<T>['$fts'] & TypedOmit<LoadManyOptions<T>, 'order'> & {
112
+ export type SearchOptions<T extends BaseEntity> = SimplifyObject<TypedOmit<LoadManyOptions<T>, 'order'> & {
113
+ /**
114
+ * The search query to execute.
115
+ */
116
+ query: FullTextSearchQuery<T>;
88
117
  /**
89
118
  * An additional filter to apply to the search query.
90
119
  */
@@ -96,7 +125,7 @@ export type SearchOptions<T extends BaseEntity> = SimplifyObject<FullTextSearchQ
96
125
  score: SQL | SQL.Aliased<number>;
97
126
  }) => Order<T>);
98
127
  /**
99
- * Whether to include a relevance score with each result. Only applicable for vector searches.
128
+ * Whether to include a relevance score with each result.
100
129
  * - If `true`, the default score is included.
101
130
  * - If a function is provided, it customizes the score calculation using the original score.
102
131
  * - If no order is specified, results are ordered by score descending, when score is enabled.
@@ -113,7 +142,7 @@ export type SearchOptions<T extends BaseEntity> = SimplifyObject<FullTextSearchQ
113
142
  /**
114
143
  * Enable and configure highlighting of search results.
115
144
  */
116
- highlight?: TargetColumnPaths<T> | SQL<string> | HighlightOptions<T>;
145
+ highlight?: TargetColumnPath<T> | SQL<string> | HighlightOptions<T>;
117
146
  }>;
118
147
  /**
119
148
  * Represents a single result from a full-text search operation.