@tstdl/base 0.93.26 → 0.93.28

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.
@@ -202,14 +202,14 @@ export declare function Unique<T extends AnyEntity>(columns: Columns<T>, options
202
202
  * @param name Optional name for the index.
203
203
  * @param options Additional index options (e.g., method, uniqueness, conditions).
204
204
  */
205
- export declare function Index<T extends BaseEntity = any>(options?: IndexReflectionData<T>['options']): PropertyDecorator;
205
+ export declare function Index<T extends BaseEntity = BaseEntity>(options?: IndexReflectionData<T>['options']): PropertyDecorator;
206
206
  /**
207
207
  * Define a composite index on multiple columns.
208
208
  * @template T The entity type.
209
209
  * @param columns An array of property names (or tuples with direction) included in the index.
210
210
  * @param options Additional index options.
211
211
  */
212
- export declare function Index<T extends BaseEntity = any>(columns: Columns<T>, options?: IndexReflectionData<T>['options']): ClassDecorator;
212
+ export declare function Index<T extends BaseEntity>(columns: NonNullable<IndexReflectionData<T>['columns']>, options?: IndexReflectionData<T>['options']): ClassDecorator;
213
213
  /**
214
214
  * Automatically expire records after a certain time to live (TTL) based on the createTimestamp metadata. Requires extension of {@link Entity} instead of {@link BaseEntity}.
215
215
  * @param ttl Time To Live in milliseconds.
package/orm/decorators.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createClassDecorator, createDecorator, createPropertyDecorator } from '../reflection/index.js';
2
2
  import { Property } from '../schema/index.js';
3
3
  import { filterUndefinedObjectProperties, objectEntries, propertyNameOf } from '../utils/object/index.js';
4
- import { isArray, isString, isUndefined } from '../utils/type-guards.js';
4
+ import { isArray, isFunction, isString, isUndefined } from '../utils/type-guards.js';
5
5
  /**
6
6
  * Merges ORM reflection data into the target's metadata.
7
7
  * @param metadata The metadata object for the class or property.
@@ -122,7 +122,7 @@ export function Unique(columnsOrOptions, options) {
122
122
  return createColumnDecorator({ unique: { options: columnsOrOptions } });
123
123
  }
124
124
  export function Index(columnsOrOptions, options) {
125
- if (isArray(columnsOrOptions)) {
125
+ if (isArray(columnsOrOptions) || isFunction(columnsOrOptions)) {
126
126
  return createTableDecorator({ index: [{ columns: columnsOrOptions, options }] });
127
127
  }
128
128
  return createColumnDecorator({ index: { options: columnsOrOptions } });
@@ -73,7 +73,6 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
73
73
  return column;
74
74
  });
75
75
  const indexFn = (data.options?.unique == true) ? uniqueIndex : index;
76
- console.log({ name: data.options?.name ?? getIndexName(tableName, columns, { naming: data.options?.naming }) });
77
76
  let builder = indexFn(data.options?.name ?? getIndexName(tableName, columns, { naming: data.options?.naming })).using(data.options?.using ?? 'btree', ...columns);
78
77
  if (isDefined(data.options?.where)) {
79
78
  const query = convertQuery(data.options.where(table), table, columnDefinitionsMap);
@@ -173,8 +173,10 @@ let EntityRepository = class EntityRepository extends Transactional {
173
173
  .exhaustive()
174
174
  : isSimilar(query, searchExpression);
175
175
  const distanceColumn = distance(query, searchExpression).as(searchDistanceColumn);
176
+ const score = sql `1 - ${distance(query, searchExpression)}`.as(searchScoreColumn);
176
177
  const selection = fromEntries(this.#columnDefinitions.map((column) => [column.name, this.resolveTargetColumn(column)]));
177
178
  selection[searchDistanceColumn] = distanceColumn;
179
+ selection[searchScoreColumn] = score;
178
180
  const whereClause = isDefined(filter)
179
181
  ? and(this.convertQuery(filter), trigramClause)
180
182
  : trigramClause;
@@ -190,7 +192,6 @@ let EntityRepository = class EntityRepository extends Transactional {
190
192
  dbQuery = dbQuery.limit(options.limit);
191
193
  }
192
194
  const orderByExpressions = [];
193
- const score = sql `1 - ${distanceColumn}`;
194
195
  if (isDefined(options.order)) {
195
196
  const order = isFunction(options.order) ? options.order({ score }) : options.order;
196
197
  orderByExpressions.push(...this.convertOrderBy(order));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.26",
3
+ "version": "0.93.28",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,5 +1,5 @@
1
1
  {
2
- "id": "e703ecc5-9f40-4ecb-848d-c1f3663d484c",
2
+ "id": "cfbaaee3-4960-412e-83b7-0f58ea61969d",
3
3
  "prevId": "00000000-0000-0000-0000-000000000000",
4
4
  "version": "7",
5
5
  "dialect": "postgresql",
@@ -5,8 +5,8 @@
5
5
  {
6
6
  "idx": 0,
7
7
  "version": "7",
8
- "when": 1761843226770,
9
- "tag": "0000_nervous_iron_monger",
8
+ "when": 1761929933695,
9
+ "tag": "0000_sturdy_patch",
10
10
  "breakpoints": true
11
11
  }
12
12
  ]
package/test1.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import './polyfills.js';
2
2
  import { Application, provideInitializer, provideModule, provideSignalHandler } from './application/index.js';
3
3
  import { migrateAuditSchema } from './audit/index.js';
4
- import { AuthenticationService } from './authentication/server/authentication.service.js';
5
4
  import { configureAuthenticationServer } from './authentication/server/module.js';
6
- import { inject, injectAsync, Injector, runInInjectionContext } from './injector/index.js';
5
+ import { inject, Injector, runInInjectionContext } from './injector/index.js';
7
6
  import { configurePostgresKeyValueStore, migratePostgresKeyValueStoreSchema } from './key-value-store/postgres/module.js';
8
7
  import { configurePostgresLock, migratePostgresLockSchema } from './lock/postgres/index.js';
9
8
  import { PrettyPrintLogFormatter, provideConsoleLogTransport } from './logger/index.js';
@@ -51,16 +50,19 @@ async function bootstrap() {
51
50
  }
52
51
  async function main(_cancellationSignal) {
53
52
  const repository = injectRepository(Test);
54
- const authService = await injectAsync(AuthenticationService);
55
53
  if (await repository.count() == 0) {
56
54
  await repository.insertMany(testData);
57
55
  }
58
56
  const result = await repository.search({
59
57
  query: {
60
- $parade: {
61
- all: null,
58
+ $trigram: {
59
+ fields: ['title'],
60
+ query: 'lorem ipsum dolor sit amet',
62
61
  },
63
62
  },
63
+ distinct: ['title'],
64
+ order: (x) => ['title', x.score],
65
+ limit: 10,
64
66
  });
65
67
  console.log(result);
66
68
  }