@tstdl/base 0.93.25 → 0.93.27

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/audit/auditor.js CHANGED
@@ -233,7 +233,7 @@ Auditor = Auditor_1 = __decorate([
233
233
  Injectable({
234
234
  providers: [
235
235
  provide(EntityRepositoryConfig, { useValue: { schema: 'audit' } }),
236
- { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(AuditModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) },
236
+ { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(AuditModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) },
237
237
  ],
238
238
  })
239
239
  ], Auditor);
@@ -630,7 +630,7 @@ AuthenticationService = AuthenticationService_1 = __decorate([
630
630
  Singleton({
631
631
  providers: [
632
632
  provide(EntityRepositoryConfig, { useValue: { schema: 'authentication' } }),
633
- provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(AuthenticationModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) }),
633
+ provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(AuthenticationModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) }),
634
634
  ],
635
635
  })
636
636
  ], AuthenticationService);
@@ -3,7 +3,7 @@ import { provide } from '../../../injector/injector.js';
3
3
  import { factoryProvider } from '../../../injector/provider.js';
4
4
  import { DatabaseConfig } from '../../../orm/server/index.js';
5
5
  import { DocumentManagementConfiguration } from '../module.js';
6
- export const documentManagementDatabaseConfigFactoryProvider = factoryProvider((_, context) => context.resolve(DocumentManagementConfiguration).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }));
6
+ export const documentManagementDatabaseConfigFactoryProvider = factoryProvider((_, context) => context.resolve(DocumentManagementConfiguration).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }));
7
7
  export const documentManagementDatabaseConfigProvider = provide(DatabaseConfig, documentManagementDatabaseConfigFactoryProvider);
8
8
  export function DocumentManagementSingleton() {
9
9
  return Singleton({ providers: [documentManagementDatabaseConfigProvider] });
@@ -22,7 +22,7 @@ export type Registration<T = any, A = any> = GlobalRegistration<T, A> & {
22
22
  resolutions: Map<any, T>;
23
23
  };
24
24
  export type GetRegistrationOptions = {
25
- skipSelf?: boolean;
25
+ skipSelf?: boolean | number;
26
26
  onlySelf?: boolean;
27
27
  };
28
28
  export type ResolveManyArrayItem<T, A> = [token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>];
@@ -38,6 +38,7 @@ export declare class Injector implements AsyncDisposable {
38
38
  #private;
39
39
  readonly id: number;
40
40
  readonly name: string;
41
+ get parent(): Injector | null;
41
42
  get disposed(): boolean;
42
43
  constructor(name: string, parent?: Injector | null);
43
44
  /**
@@ -31,6 +31,9 @@ export class Injector {
31
31
  #addDisposeHandler;
32
32
  id = _id++;
33
33
  name;
34
+ get parent() {
35
+ return this.#parent;
36
+ }
34
37
  get disposed() {
35
38
  return this.#disposableStack.disposed;
36
39
  }
@@ -147,8 +150,9 @@ export class Injector {
147
150
  this.register(globalRegistration.token, globalRegistration.provider, globalRegistration.options);
148
151
  }
149
152
  }
150
- if (options?.skipSelf == true) {
151
- return this.#parent?.tryGetRegistration(token, { ...options, skipSelf: false });
153
+ const skipSelf = Number(options?.skipSelf ?? 0);
154
+ if (skipSelf > 0) {
155
+ return this.#parent?.tryGetRegistration(token, { ...options, skipSelf: skipSelf - 1 });
152
156
  }
153
157
  const ownRegistration = this.#registrations.get(token);
154
158
  if (isDefined(ownRegistration)) {
@@ -272,11 +276,12 @@ export class Injector {
272
276
  }
273
277
  _resolve(token, argument, options, context, chain) {
274
278
  this.assertNotDisposed();
275
- if (options.skipSelf == true) {
279
+ const skipSelf = Number(options.skipSelf ?? 0);
280
+ if (skipSelf > 0) {
276
281
  if (isNull(this.#parent) && (options.optional != true)) {
277
282
  throw new ResolveError(`No parent injector available.`, chain);
278
283
  }
279
- return this.#parent?._resolve(token, argument, { ...options, skipSelf: false }, context, chain);
284
+ return this.#parent?._resolve(token, argument, { ...options, skipSelf: skipSelf - 1 }, context, chain);
280
285
  }
281
286
  if (isDefined(options.forwardRef) && (options.forwardRef != false)) {
282
287
  assert(options.optional != true, 'ForwardRef does not support optional without resolveAll/injectAll as undefined is not forwardable.');
@@ -304,11 +309,12 @@ export class Injector {
304
309
  }
305
310
  _resolveAll(token, argument, options, context, chain) {
306
311
  this.assertNotDisposed();
307
- if (options.skipSelf == true) {
312
+ const skipSelf = Number(options.skipSelf ?? 0);
313
+ if (skipSelf > 0) {
308
314
  if (isNull(this.#parent) && (options.optional != true)) {
309
315
  throw new ResolveError(`No parent injector available.`, chain);
310
316
  }
311
- return this.#parent?._resolveAll(token, argument, { ...options, skipSelf: false }, context, chain) ?? [];
317
+ return this.#parent?._resolveAll(token, argument, { ...options, skipSelf: skipSelf - 1 }, context, chain) ?? [];
312
318
  }
313
319
  if (isDefined(options.forwardRef) && (options.forwardRef != false)) {
314
320
  const forwardToken = isFunction(options.forwardRef) ? options.forwardRef() : token;
@@ -26,7 +26,7 @@ export type ArgumentProvider<T = unknown, D extends Record = Record> = (context:
26
26
  export type ForwardRefInjectionToken<T = any, A = any> = Exclude<InjectionToken<T, A>, Function> | (() => InjectionToken<T, A>);
27
27
  export type ResolveOptions<T, A> = {
28
28
  optional?: boolean;
29
- skipSelf?: boolean;
29
+ skipSelf?: boolean | number;
30
30
  onlySelf?: boolean;
31
31
  /** If defined, resolve the token using ForwardRef strategy instead of resolving the token directly can be used to circumvent circular dependency problems */
32
32
  forwardRef?: boolean | ForwardRefInjectionToken<T, A>;
@@ -57,7 +57,7 @@ PostgresKeyValueStore = __decorate([
57
57
  Singleton({
58
58
  providers: [
59
59
  provide(EntityRepositoryConfig, { useValue: { schema: 'key_value_store' } }),
60
- { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(PostgresKeyValueStoreModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) },
60
+ { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(PostgresKeyValueStoreModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) },
61
61
  ],
62
62
  })
63
63
  ], PostgresKeyValueStore);
@@ -21,7 +21,7 @@ PostgresLockProvider = __decorate([
21
21
  Singleton({
22
22
  providers: [
23
23
  provide(EntityRepositoryConfig, { useValue: { schema: 'lock' } }),
24
- { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(PostgresLockModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) },
24
+ { provide: DatabaseConfig, useFactory: (_, context) => context.resolve(PostgresLockModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) },
25
25
  ],
26
26
  })
27
27
  ], PostgresLockProvider);
@@ -60,7 +60,7 @@ MailService = __decorate([
60
60
  Singleton({
61
61
  providers: [
62
62
  provide(EntityRepositoryConfig, { useValue: { schema: 'mail' } }),
63
- provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(MailModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) }),
63
+ provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(MailModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) }),
64
64
  ],
65
65
  })
66
66
  ], MailService);
@@ -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.25",
3
+ "version": "0.93.27",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -157,7 +157,7 @@ PostgresQueue = __decorate([
157
157
  argumentIdentityProvider: JSON.stringify,
158
158
  providers: [
159
159
  provide(EntityRepositoryConfig, { useValue: { schema: 'queue' } }),
160
- provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(PostgresQueueModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) }),
160
+ provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(PostgresQueueModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: 2 }) }),
161
161
  ],
162
162
  })
163
163
  ], PostgresQueue);
@@ -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
  }