@tstdl/base 0.93.14 → 0.93.16

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/document-management/api/document-management.api.d.ts +4 -0
  2. package/document-management/service-models/document.service-model.d.ts +2 -0
  3. package/injector/injector.js +9 -8
  4. package/mail/drizzle/0001_flimsy_bloodscream.sql +5 -0
  5. package/mail/drizzle/meta/0001_snapshot.json +69 -0
  6. package/mail/drizzle/meta/_journal.json +7 -0
  7. package/mail/mail.service.js +4 -4
  8. package/mail/models/mail-log.model.d.ts +2 -2
  9. package/mail/models/mail-log.model.js +2 -2
  10. package/message-bus/local/local-message-bus-provider.d.ts +2 -1
  11. package/message-bus/local/local-message-bus-provider.js +5 -4
  12. package/message-bus/local/local-message-bus.js +1 -3
  13. package/message-bus/message-bus-base.js +2 -2
  14. package/orm/data-types/index.d.ts +1 -0
  15. package/orm/data-types/index.js +1 -0
  16. package/orm/data-types/tsvector.d.ts +16 -0
  17. package/orm/data-types/tsvector.js +13 -0
  18. package/orm/decorators.d.ts +44 -32
  19. package/orm/decorators.js +3 -6
  20. package/orm/entity.d.ts +20 -13
  21. package/orm/entity.js +18 -18
  22. package/orm/repository.types.d.ts +13 -13
  23. package/orm/server/drizzle/schema-converter.js +115 -63
  24. package/orm/server/types.d.ts +2 -3
  25. package/package.json +4 -4
  26. package/test/drizzle/0002_nice_squadron_supreme.sql +1 -0
  27. package/test/drizzle/0003_serious_mockingbird.sql +1 -0
  28. package/test/drizzle/0004_complete_pixie.sql +1 -0
  29. package/test/drizzle/0005_bumpy_sabra.sql +1 -0
  30. package/test/drizzle/0006_overrated_post.sql +6 -0
  31. package/test/drizzle/meta/0002_snapshot.json +63 -0
  32. package/test/drizzle/meta/0003_snapshot.json +73 -0
  33. package/test/drizzle/meta/0004_snapshot.json +89 -0
  34. package/test/drizzle/meta/0005_snapshot.json +104 -0
  35. package/test/drizzle/meta/0006_snapshot.json +104 -0
  36. package/test/drizzle/meta/_journal.json +35 -0
  37. package/test/test.model.d.ts +2 -2
  38. package/test/test.model.js +6 -4
  39. package/utils/value-or-provider.d.ts +7 -4
  40. package/utils/value-or-provider.js +9 -12
@@ -179,6 +179,7 @@ export declare const documentManagementApiDefinition: {
179
179
  parameters: import("../../schema/index.js").ObjectSchema<{
180
180
  id: import("../../orm/types.js").IsPrimaryKey<import("../../orm/types.js").HasDefault<import("../../orm/types.js").Uuid>>;
181
181
  description?: string | null | undefined;
182
+ readonly __entityMeta__?: import("../../orm/entity.js").EntityMeta | undefined;
182
183
  tenantId?: string | null | undefined;
183
184
  label?: string | undefined;
184
185
  metadata?: Partial<{
@@ -232,6 +233,7 @@ export declare const documentManagementApiDefinition: {
232
233
  method: "PATCH";
233
234
  parameters: import("../../schema/index.js").ObjectSchema<{
234
235
  id: import("../../orm/types.js").IsPrimaryKey<import("../../orm/types.js").HasDefault<import("../../orm/types.js").Uuid>>;
236
+ readonly __entityMeta__?: import("../../orm/entity.js").EntityMeta | undefined;
235
237
  tenantId?: string | null | undefined;
236
238
  typeId?: import("../../orm/types.js").Uuid | undefined;
237
239
  comment?: string | null | undefined;
@@ -579,6 +581,7 @@ declare const _DocumentManagementApi: import("../../api/client/index.js").ApiCli
579
581
  parameters: import("../../schema/index.js").ObjectSchema<{
580
582
  id: import("../../orm/types.js").IsPrimaryKey<import("../../orm/types.js").HasDefault<import("../../orm/types.js").Uuid>>;
581
583
  description?: string | null | undefined;
584
+ readonly __entityMeta__?: import("../../orm/entity.js").EntityMeta | undefined;
582
585
  tenantId?: string | null | undefined;
583
586
  label?: string | undefined;
584
587
  metadata?: Partial<{
@@ -632,6 +635,7 @@ declare const _DocumentManagementApi: import("../../api/client/index.js").ApiCli
632
635
  method: "PATCH";
633
636
  parameters: import("../../schema/index.js").ObjectSchema<{
634
637
  id: import("../../orm/types.js").IsPrimaryKey<import("../../orm/types.js").HasDefault<import("../../orm/types.js").Uuid>>;
638
+ readonly __entityMeta__?: import("../../orm/entity.js").EntityMeta | undefined;
635
639
  tenantId?: string | null | undefined;
636
640
  typeId?: import("../../orm/types.js").Uuid | undefined;
637
641
  comment?: string | null | undefined;
@@ -97,6 +97,7 @@ export declare const createDocumentRequestsTemplateParametersSchema: import("../
97
97
  export declare const updateDocumentRequestsTemplateParametersSchema: import("../../schema/index.js").ObjectSchema<{
98
98
  id: import("../../orm/index.js").IsPrimaryKey<import("../../orm/index.js").HasDefault<import("../../orm/index.js").Uuid>>;
99
99
  description?: string | null | undefined;
100
+ readonly __entityMeta__?: import("../../orm/index.js").EntityMeta | undefined;
100
101
  tenantId?: string | null | undefined;
101
102
  label?: string | undefined;
102
103
  metadata?: Partial<{
@@ -126,6 +127,7 @@ export declare const createDocumentRequestTemplateParametersSchema: import("../.
126
127
  }>;
127
128
  export declare const updateDocumentRequestTemplateParametersSchema: import("../../schema/index.js").ObjectSchema<{
128
129
  id: import("../../orm/index.js").IsPrimaryKey<import("../../orm/index.js").HasDefault<import("../../orm/index.js").Uuid>>;
130
+ readonly __entityMeta__?: import("../../orm/index.js").EntityMeta | undefined;
129
131
  tenantId?: string | null | undefined;
130
132
  typeId?: import("../../orm/index.js").Uuid | undefined;
131
133
  comment?: string | null | undefined;
@@ -375,7 +375,7 @@ export class Injector {
375
375
  }
376
376
  _resolveProvider(resolutionTag, registration, resolveArgument, options, context, resolutionContext, injectionContext, chain) {
377
377
  try {
378
- setResolving(registration.token, context, chain);
378
+ setResolving(this, registration.token, context, chain);
379
379
  const { provider } = registration;
380
380
  let result;
381
381
  if (isClassProvider(provider)) {
@@ -417,7 +417,7 @@ export class Injector {
417
417
  return result.value;
418
418
  }
419
419
  finally {
420
- deleteResolving(registration.token, context);
420
+ deleteResolving(this, registration.token, context);
421
421
  }
422
422
  }
423
423
  resolveClassInjection(resolutionTag, context, constructor, metadata, resolveArgument, chain) {
@@ -523,7 +523,7 @@ function addRegistration(registrations, registration) {
523
523
  function newInternalResolveContext() {
524
524
  return {
525
525
  resolves: 0,
526
- resolving: new Set(),
526
+ resolving: new FactoryMap(() => new Set()),
527
527
  resolutionScopedResolutions: new MultiKeyMap(),
528
528
  resolutions: [],
529
529
  resolutionContextData: new FactoryMap(() => ({})),
@@ -594,14 +594,15 @@ function resolveArgumentIdentity(registration, resolveArgument, chain) {
594
594
  }
595
595
  return resolveArgument;
596
596
  }
597
- function setResolving(token, context, chain) {
598
- if (context.resolving.has(token)) {
597
+ function setResolving(injector, token, context, chain) {
598
+ const resolvingSet = context.resolving.get(injector);
599
+ if (resolvingSet.has(token)) {
599
600
  throw new ResolveError('Circular dependency detected. Use forwardRef for circular dependencies between classes.', chain);
600
601
  }
601
- context.resolving.add(token);
602
+ resolvingSet.add(token);
602
603
  }
603
- function deleteResolving(token, context) {
604
- context.resolving.delete(token);
604
+ function deleteResolving(injector, token, context) {
605
+ context.resolving.get(injector).delete(token);
605
606
  }
606
607
  function throwOnPromise(value, type, chain) {
607
608
  if (isPromise(value)) {
@@ -0,0 +1,5 @@
1
+ ALTER TABLE "mail"."log" DROP COLUMN "revision";--> statement-breakpoint
2
+ ALTER TABLE "mail"."log" DROP COLUMN "revision_timestamp";--> statement-breakpoint
3
+ ALTER TABLE "mail"."log" DROP COLUMN "create_timestamp";--> statement-breakpoint
4
+ ALTER TABLE "mail"."log" DROP COLUMN "delete_timestamp";--> statement-breakpoint
5
+ ALTER TABLE "mail"."log" DROP COLUMN "attributes";
@@ -0,0 +1,69 @@
1
+ {
2
+ "id": "28ddafef-64f4-437d-9406-82a02c76570e",
3
+ "prevId": "f8cdba37-11b9-477a-9f5a-5ef4b5026011",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "mail.log": {
8
+ "name": "log",
9
+ "schema": "mail",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "timestamp": {
19
+ "name": "timestamp",
20
+ "type": "timestamp with time zone",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "template": {
25
+ "name": "template",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": false
29
+ },
30
+ "data": {
31
+ "name": "data",
32
+ "type": "jsonb",
33
+ "primaryKey": false,
34
+ "notNull": true
35
+ },
36
+ "send_result": {
37
+ "name": "send_result",
38
+ "type": "jsonb",
39
+ "primaryKey": false,
40
+ "notNull": false
41
+ },
42
+ "errors": {
43
+ "name": "errors",
44
+ "type": "text[]",
45
+ "primaryKey": false,
46
+ "notNull": false
47
+ }
48
+ },
49
+ "indexes": {},
50
+ "foreignKeys": {},
51
+ "compositePrimaryKeys": {},
52
+ "uniqueConstraints": {},
53
+ "policies": {},
54
+ "checkConstraints": {},
55
+ "isRLSEnabled": false
56
+ }
57
+ },
58
+ "enums": {},
59
+ "schemas": {},
60
+ "sequences": {},
61
+ "roles": {},
62
+ "policies": {},
63
+ "views": {},
64
+ "_meta": {
65
+ "columns": {},
66
+ "schemas": {},
67
+ "tables": {}
68
+ }
69
+ }
@@ -8,6 +8,13 @@
8
8
  "when": 1740059198387,
9
9
  "tag": "0000_previous_malcolm_colcord",
10
10
  "breakpoints": true
11
+ },
12
+ {
13
+ "idx": 1,
14
+ "version": "7",
15
+ "when": 1761124592125,
16
+ "tag": "0001_flimsy_bloodscream",
17
+ "breakpoints": true
11
18
  }
12
19
  ]
13
20
  }
@@ -33,7 +33,7 @@ let MailService = class MailService {
33
33
  template: templateName ?? null,
34
34
  data,
35
35
  sendResult: null,
36
- errors: null
36
+ errors: null,
37
37
  });
38
38
  try {
39
39
  const result = await this.#mailClient.send(data, clientConfig);
@@ -53,15 +53,15 @@ let MailService = class MailService {
53
53
  async sendTemplate(keyOrTemplate, mailData, templateContext, clientConfig) {
54
54
  const { name, fields: { subject, html, text } } = await this.#templateService.render(keyOrTemplate, templateContext);
55
55
  const fullMailData = { ...mailData, subject, content: { html, text } };
56
- return this.send(fullMailData, clientConfig, name);
56
+ return await this.send(fullMailData, clientConfig, name);
57
57
  }
58
58
  };
59
59
  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 }) })
64
- ]
63
+ provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(MailModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) }),
64
+ ],
65
65
  })
66
66
  ], MailService);
67
67
  export { MailService };
@@ -1,7 +1,7 @@
1
- import { Entity, type Json, type Timestamp } from '../../orm/index.js';
1
+ import { EntityWithoutMetadata, type Json, type Timestamp } from '../../orm/index.js';
2
2
  import type { MailData } from './mail-data.model.js';
3
3
  import type { MailSendResult } from './mail-send-result.model.js';
4
- export declare class MailLog extends Entity {
4
+ export declare class MailLog extends EntityWithoutMetadata {
5
5
  timestamp: Timestamp;
6
6
  template: string | null;
7
7
  data: Json<MailData>;
@@ -7,9 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { Entity, JsonProperty, Table, TimestampProperty } from '../../orm/index.js';
10
+ import { EntityWithoutMetadata, JsonProperty, Table, TimestampProperty } from '../../orm/index.js';
11
11
  import { StringProperty } from '../../schema/index.js';
12
- let MailLog = class MailLog extends Entity {
12
+ let MailLog = class MailLog extends EntityWithoutMetadata {
13
13
  timestamp;
14
14
  template;
15
15
  data;
@@ -1,7 +1,8 @@
1
1
  import { MessageBusProvider } from '../message-bus-provider.js';
2
2
  import { LocalMessageBus } from './local-message-bus.js';
3
- export declare class LocalMessageBusProvider extends MessageBusProvider {
3
+ export declare class LocalMessageBusProvider extends MessageBusProvider implements Disposable {
4
4
  private readonly logger;
5
5
  private readonly channelSubjectsMap;
6
6
  get<T>(channel: string): LocalMessageBus<T>;
7
+ [Symbol.dispose](): void;
7
8
  }
@@ -10,7 +10,6 @@ import { WeakRefMap } from '../../data-structures/weak-ref-map.js';
10
10
  import { inject, Singleton } from '../../injector/index.js';
11
11
  import { Logger } from '../../logger/index.js';
12
12
  import { FactoryMap } from '../../utils/factory-map.js';
13
- import { isUndefined } from '../../utils/type-guards.js';
14
13
  import { MessageBusProvider } from '../message-bus-provider.js';
15
14
  import { LocalMessageBus } from './local-message-bus.js';
16
15
  let LocalMessageBusProvider = LocalMessageBusProvider_1 = class LocalMessageBusProvider extends MessageBusProvider {
@@ -18,11 +17,13 @@ let LocalMessageBusProvider = LocalMessageBusProvider_1 = class LocalMessageBusP
18
17
  channelSubjectsMap = new FactoryMap(() => new Subject(), WeakRefMap.supported ? new WeakRefMap() : undefined);
19
18
  get(channel) {
20
19
  const subject = this.channelSubjectsMap.get(channel);
21
- if (isUndefined(subject)) {
20
+ return new LocalMessageBus(subject, this.logger);
21
+ }
22
+ [Symbol.dispose]() {
23
+ for (const [channel, subject] of this.channelSubjectsMap.entries()) {
22
24
  this.channelSubjectsMap.delete(channel);
23
- return this.get(channel);
25
+ subject.complete();
24
26
  }
25
- return new LocalMessageBus(subject, this.logger);
26
27
  }
27
28
  };
28
29
  LocalMessageBusProvider = LocalMessageBusProvider_1 = __decorate([
@@ -26,9 +26,7 @@ let LocalMessageBus = class LocalMessageBus extends MessageBusBase {
26
26
  _publish(message) {
27
27
  this.subject.next({ source: this.source, message });
28
28
  }
29
- _dispose() {
30
- this.subject.complete();
31
- }
29
+ _dispose() { }
32
30
  };
33
31
  LocalMessageBus = __decorate([
34
32
  Injectable({
@@ -21,14 +21,14 @@ export class MessageBusBase extends MessageBus {
21
21
  }
22
22
  async publish(message) {
23
23
  if (this.disposeToken.isSet) {
24
- throw new Error('message-bus is disposed');
24
+ throw new Error('MessageBus is disposed.');
25
25
  }
26
26
  this.publishSubject.next(message);
27
27
  await this._publish(message);
28
28
  }
29
29
  async [Symbol.asyncDispose]() {
30
30
  if (this.disposeToken.isSet) {
31
- throw new Error('message-bus is disposed');
31
+ throw new Error('MessageBus is disposed.');
32
32
  }
33
33
  this.disposeToken.set();
34
34
  this.publishSubject.complete();
@@ -5,3 +5,4 @@
5
5
  export * from './bytea.js';
6
6
  export * from './numeric-date.js';
7
7
  export * from './timestamp.js';
8
+ export * from './tsvector.js';
@@ -5,3 +5,4 @@
5
5
  export * from './bytea.js';
6
6
  export * from './numeric-date.js';
7
7
  export * from './timestamp.js';
8
+ export * from './tsvector.js';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module
3
+ * Defines a custom Drizzle type for handling PostgreSQL `tsvector` columns.
4
+ */
5
+ import { type ConvertCustomConfig, type PgCustomColumnBuilder } from 'drizzle-orm/pg-core';
6
+ type Config = {
7
+ data: unknown;
8
+ };
9
+ /**
10
+ * Custom Drizzle type for PostgreSQL `tsvector` columns.
11
+ */
12
+ export declare const tsvector: {
13
+ (): PgCustomColumnBuilder<ConvertCustomConfig<"", Config>>;
14
+ <TName extends string>(dbName: TName): PgCustomColumnBuilder<ConvertCustomConfig<TName, Config>>;
15
+ };
16
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module
3
+ * Defines a custom Drizzle type for handling PostgreSQL `tsvector` columns.
4
+ */
5
+ import { customType } from 'drizzle-orm/pg-core';
6
+ /**
7
+ * Custom Drizzle type for PostgreSQL `tsvector` columns.
8
+ */
9
+ export const tsvector = customType({
10
+ dataType() {
11
+ return 'tsvector';
12
+ },
13
+ });
@@ -6,7 +6,8 @@ import type { SQL } from 'drizzle-orm';
6
6
  import type { LiteralUnion } from 'type-fest';
7
7
  import { type SpecificCreateDecoratorOptions } from '../reflection/index.js';
8
8
  import type { AbstractConstructor, Record, TypedOmit } from '../types/index.js';
9
- import type { AnyEntity, Entity, EntityType, EntityWithoutMetadata } from './entity.js';
9
+ import type { ValueOrProvider } from '../utils/value-or-provider.js';
10
+ import type { AnyEntity, BaseEntity, Entity, EntityType } from './entity.js';
10
11
  import type { Query } from './query.js';
11
12
  import type { TargetColumnPaths } from './repository.types.js';
12
13
  import type { PgTableFromType } from './server/types.js';
@@ -14,16 +15,17 @@ type IndexMethod = LiteralUnion<'hash' | 'btree' | 'gist' | 'spgist' | 'gin' | '
14
15
  type NamingStrategy = 'abbreviated-table';
15
16
  type Column<T> = Extract<keyof T, string>;
16
17
  type Columns<T> = [Column<T>, ...Column<T>[]];
18
+ export type SqlBuilder<T extends BaseEntity = any, R = SQL> = (table: PgTableFromType<EntityType<T>>) => R;
17
19
  /**
18
20
  * Builder function type for creating SQL check constraints.
19
21
  * @param table The Drizzle table object.
20
22
  */
21
- export type CheckBuilder<T extends Entity = any> = (table: PgTableFromType<EntityType<T>>) => SQL;
23
+ export type CheckBuilder<T extends BaseEntity = any> = SqlBuilder<T>;
22
24
  /**
23
25
  * Builder function type for creating partial index WHERE clauses.
24
26
  * @param table The Drizzle table object.
25
27
  */
26
- export type WhereBuilder<T extends Entity | EntityWithoutMetadata = any> = (table: PgTableFromType<EntityType<T>>) => Query<T>;
28
+ export type WhereBuilder<T extends BaseEntity = any> = SqlBuilder<T, Query<T>>;
27
29
  /**
28
30
  * Reflection data stored for ORM table decorators.
29
31
  */
@@ -34,6 +36,7 @@ export type OrmTableReflectionData = {
34
36
  compundPrimaryKeyNaming?: NamingStrategy;
35
37
  unique?: UniqueReflectionData[];
36
38
  index?: IndexReflectionData[];
39
+ fullTextSearch?: FullTextSearchReflectionData[];
37
40
  checks?: CheckReflectionData[];
38
41
  foreignKeys?: ForeignKeyReflectionData[];
39
42
  };
@@ -77,8 +80,8 @@ export type UniqueReflectionData = {
77
80
  * Reflection data for index definitions.
78
81
  * @template T The entity type.
79
82
  */
80
- export type IndexReflectionData<T extends Entity | EntityWithoutMetadata = any> = {
81
- columns?: (string | [string, 'asc' | 'desc'] | SQL)[];
83
+ export type IndexReflectionData<T extends BaseEntity = any> = {
84
+ columns?: (string | [string, 'asc' | 'desc'])[];
82
85
  order?: 'asc' | 'desc';
83
86
  options?: {
84
87
  name?: string;
@@ -87,22 +90,45 @@ export type IndexReflectionData<T extends Entity | EntityWithoutMetadata = any>
87
90
  unique?: boolean;
88
91
  where?: WhereBuilder<T>;
89
92
  nulls?: 'first' | 'last';
93
+ };
94
+ };
95
+ export type FullTextSearchFeature = 'vector' | 'trigram';
96
+ export type FullTextSearchReflectionData<T extends BaseEntity = BaseEntity> = {
97
+ name: string;
98
+ /**
99
+ * Columns or SQL expression to use as the text source.
100
+ */
101
+ source?: ValueOrProvider<TargetColumnPaths<T>[] | SQL<string>, PgTableFromType<EntityType<T>>>;
102
+ parade?: {};
103
+ /**
104
+ * Configuration for vector search (tsvector).
105
+ */
106
+ vector?: {
90
107
  /**
91
- * For full-text search indexes (e.g., GIN), specifies the text search configuration language (e.g., 'english').
92
- * Can also be a SQL object for dynamic configuration.
108
+ * Raw SQL or builder function for generating the tsvector source.
93
109
  */
94
- language?: string | SQL;
110
+ rawVectorSource?: ValueOrProvider<SQL, PgTableFromType<EntityType<T>>>;
95
111
  /**
96
- * For multi-column full-text search indexes, specifies how to create the tsvector.
97
- * - 'concat': (Default) Concatenate columns into a single tsvector.
98
- * - 'separate': Create a separate tsvector for each column, useful for indexing columns with different languages or weights.
112
+ * Language configuration, used for stemming, stop-words, etc.
113
+ * Can be a string (e.g., 'simple', 'english') or a SQL expression / builder.
114
+ * Not applicable if `rawVectorSource` is provided.
99
115
  */
100
- vectors?: 'concat' | 'separate';
116
+ language?: string | SQL | SqlBuilder<T>;
101
117
  /**
102
- * For multi-column full-text search indexes, specifies weights for columns.
118
+ * Weights for columns in source.
103
119
  * Keys are column names, values are 'A', 'B', 'C', or 'D'.
120
+ * Not applicable if `rawVectorSource` is provided.
121
+ */
122
+ weights?: Partial<Record<TargetColumnPaths<T>, 'A' | 'B' | 'C' | 'D'>>;
123
+ };
124
+ /**
125
+ * Configuration for trigram search (pg_trgm).
126
+ */
127
+ trigram?: {
128
+ /**
129
+ * Similarity threshold between 0 and 1 for trigram matching.
104
130
  */
105
- weights?: Partial<Record<TargetColumnPaths<any>, 'A' | 'B' | 'C' | 'D'>>;
131
+ threshold?: number;
106
132
  };
107
133
  };
108
134
  type CheckReflectionData = {
@@ -121,10 +147,6 @@ export type ForeignKeyReflectionData = {
121
147
  naming?: NamingStrategy;
122
148
  };
123
149
  };
124
- export type GinIndexOptions<T extends Entity | EntityWithoutMetadata = any> = TypedOmit<NonNullable<IndexReflectionData<T>['options']>, 'using' | 'weights'> & {
125
- weights?: Partial<Record<TargetColumnPaths<any>, 'A' | 'B' | 'C' | 'D'>>;
126
- language?: string | SQL;
127
- };
128
150
  /**
129
151
  * Factory function to create a class decorator for ORM table configuration.
130
152
  * Merges provided data with existing ORM reflection data on the class metadata.
@@ -217,27 +239,17 @@ export declare function Unique<T extends AnyEntity>(columns: Columns<T>, options
217
239
  * @param name Optional name for the index.
218
240
  * @param options Additional index options (e.g., method, uniqueness, conditions).
219
241
  */
220
- export declare function Index<T extends Entity | EntityWithoutMetadata = any>(options?: IndexReflectionData<T>['options']): PropertyDecorator;
242
+ export declare function Index<T extends BaseEntity = any>(options?: IndexReflectionData<T>['options']): PropertyDecorator;
221
243
  /**
222
244
  * Define a composite index on multiple columns.
223
245
  * @template T The entity type.
224
246
  * @param columns An array of property names (or tuples with direction) included in the index.
225
247
  * @param options Additional index options.
226
248
  */
227
- export declare function Index<T extends Entity | EntityWithoutMetadata = any>(columns: Columns<T>, options?: IndexReflectionData<T>['options']): ClassDecorator;
228
- /**
229
- * Defines a GIN index on a single column, often for full-text search.
230
- * @param options GIN index options. For full-text search, `language` is required.
231
- */
232
- export declare function GinIndex<T extends Entity | EntityWithoutMetadata = any>(options: GinIndexOptions<T>): PropertyDecorator;
233
- /**
234
- * Defines a composite GIN index on multiple columns, often for full-text search.
235
- * @param columnsOrSql The columns to include in the index.
236
- * @param options GIN index options. For full-text search, providing a `language` is highly recommended.
237
- */
238
- export declare function GinIndex<T extends Entity | EntityWithoutMetadata = any>(columnsOrSql: (Column<T> | SQL)[], options?: GinIndexOptions<T>): ClassDecorator;
249
+ export declare function Index<T extends BaseEntity = any>(columns: Columns<T>, options?: IndexReflectionData<T>['options']): ClassDecorator;
250
+ export declare function FullTextSearch<T extends BaseEntity>(name: string, options: TypedOmit<FullTextSearchReflectionData<T>, 'name'>): ClassDecorator;
239
251
  /**
240
- * Automatically expire records after a certain time to live (TTL) based on the createTimestamp metadata. Requires extension of {@link Entity} instead of {@link EntityWithoutMetadata}.
252
+ * Automatically expire records after a certain time to live (TTL) based on the createTimestamp metadata. Requires extension of {@link Entity} instead of {@link BaseEntity}.
241
253
  * @param ttl Time To Live in milliseconds.
242
254
  * @param mode Whether to delete soft or hard.
243
255
  */
package/orm/decorators.js CHANGED
@@ -137,14 +137,11 @@ export function Index(columnsOrOptions, options) {
137
137
  }
138
138
  return createColumnDecorator({ index: { options: columnsOrOptions } });
139
139
  }
140
- export function GinIndex(columnsOrSqlOrOptions, options) {
141
- if (isArray(columnsOrSqlOrOptions)) {
142
- return createTableDecorator({ index: [{ columns: columnsOrSqlOrOptions, options: { ...options, using: 'gin' } }] });
143
- }
144
- return createColumnDecorator({ index: { options: { ...columnsOrSqlOrOptions, using: 'gin' } } });
140
+ export function FullTextSearch(name, options) {
141
+ return createTableDecorator({ fullTextSearch: [{ name, ...options }] });
145
142
  }
146
143
  /**
147
- * Automatically expire records after a certain time to live (TTL) based on the createTimestamp metadata. Requires extension of {@link Entity} instead of {@link EntityWithoutMetadata}.
144
+ * Automatically expire records after a certain time to live (TTL) based on the createTimestamp metadata. Requires extension of {@link Entity} instead of {@link BaseEntity}.
148
145
  * @param ttl Time To Live in milliseconds.
149
146
  * @param mode Whether to delete soft or hard.
150
147
  */
package/orm/entity.d.ts CHANGED
@@ -1,13 +1,15 @@
1
- import type { Type } from '../types/index.js';
1
+ import type { Record, 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.
5
5
  * @template T - The entity class type.
6
6
  */
7
- export interface EntityType<T extends Entity | EntityWithoutMetadata = Entity | EntityWithoutMetadata> extends Type<T> {
7
+ export interface EntityType<T extends BaseEntity = BaseEntity | Entity> extends Type<T> {
8
8
  readonly entityName?: string;
9
9
  }
10
- export type AnyEntity = Entity | EntityWithoutMetadata;
10
+ export type AnyEntity = BaseEntity | Entity;
11
+ export type EntityMeta = Record<string>;
12
+ export declare const entityMeta: "__entityMeta__";
11
13
  /**
12
14
  * Base class for extensible metadata attributes associated with an entity.
13
15
  * Allows storing arbitrary key-value pairs.
@@ -26,23 +28,28 @@ export declare abstract class EntityMetadata {
26
28
  attributes: HasDefault<Json<EntityMetadataAttributes>>;
27
29
  }
28
30
  /**
29
- * Abstract base class for entities that include standard metadata.
30
- * Provides a default `id` (UUID primary key) and an `metadata` field.
31
+ * Abstract base class for entities that do *not* include the standard metadata fields.
32
+ * Provides only a default `id` (UUID primary key). Useful for simpler tables or join tables.
31
33
  */
32
- export declare abstract class Entity {
34
+ export declare abstract class BaseEntity<TMeta extends EntityMeta = EntityMeta> {
33
35
  id: IsPrimaryKey<HasDefault<Uuid>>;
34
- metadata: Embedded<EntityMetadata>;
36
+ readonly [entityMeta]?: TMeta;
35
37
  }
36
38
  /**
37
- * Abstract base class for entities that do *not* include the standard metadata fields.
38
- * Provides only a default `id` (UUID primary key). Useful for simpler tables or join tables.
39
+ * Abstract base class for entities that include standard metadata.
40
+ * Provides a default `id` (UUID primary key) and an `metadata` field.
39
41
  */
40
- export declare abstract class EntityWithoutMetadata {
41
- id: IsPrimaryKey<HasDefault<Uuid>>;
42
+ export declare abstract class Entity<TMeta extends EntityMeta = EntityMeta> extends BaseEntity<TMeta> {
43
+ metadata: Embedded<EntityMetadata>;
42
44
  }
43
- export declare abstract class TenantEntity extends Entity {
45
+ export declare abstract class TenantEntity<TMeta extends EntityMeta = EntityMeta> extends Entity<TMeta> {
44
46
  tenantId: Uuid;
45
47
  }
46
- export declare abstract class TenantEntityWithoutMetadata extends EntityWithoutMetadata {
48
+ export declare abstract class TenantBaseEntity<TMeta extends EntityMeta = EntityMeta> extends BaseEntity<TMeta> {
47
49
  tenantId: Uuid;
48
50
  }
51
+ export {
52
+ /**
53
+ * @deprecated Use BaseEntity instead.
54
+ */
55
+ BaseEntity as EntityWithoutMetadata, };
package/orm/entity.js CHANGED
@@ -14,6 +14,7 @@ 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__';
17
18
  /**
18
19
  * Base class for extensible metadata attributes associated with an entity.
19
20
  * Allows storing arbitrary key-value pairs.
@@ -55,34 +56,28 @@ __decorate([
55
56
  __metadata("design:type", Object)
56
57
  ], EntityMetadata.prototype, "attributes", void 0);
57
58
  /**
58
- * Abstract base class for entities that include standard metadata.
59
- * Provides a default `id` (UUID primary key) and an `metadata` field.
59
+ * Abstract base class for entities that do *not* include the standard metadata fields.
60
+ * Provides only a default `id` (UUID primary key). Useful for simpler tables or join tables.
60
61
  */
61
- export class Entity {
62
+ export class BaseEntity {
62
63
  id;
63
- metadata;
64
64
  }
65
65
  __decorate([
66
66
  PrimaryKeyProperty(),
67
67
  UuidProperty({ defaultRandom: true }),
68
68
  __metadata("design:type", Object)
69
- ], Entity.prototype, "id", void 0);
70
- __decorate([
71
- EmbeddedProperty(EntityMetadata, { prefix: null }),
72
- __metadata("design:type", Object)
73
- ], Entity.prototype, "metadata", void 0);
69
+ ], BaseEntity.prototype, "id", void 0);
74
70
  /**
75
- * Abstract base class for entities that do *not* include the standard metadata fields.
76
- * Provides only a default `id` (UUID primary key). Useful for simpler tables or join tables.
71
+ * Abstract base class for entities that include standard metadata.
72
+ * Provides a default `id` (UUID primary key) and an `metadata` field.
77
73
  */
78
- export class EntityWithoutMetadata {
79
- id;
74
+ export class Entity extends BaseEntity {
75
+ metadata;
80
76
  }
81
77
  __decorate([
82
- PrimaryKeyProperty(),
83
- UuidProperty({ defaultRandom: true }),
78
+ EmbeddedProperty(EntityMetadata, { prefix: null }),
84
79
  __metadata("design:type", Object)
85
- ], EntityWithoutMetadata.prototype, "id", void 0);
80
+ ], Entity.prototype, "metadata", void 0);
86
81
  export class TenantEntity extends Entity {
87
82
  tenantId;
88
83
  }
@@ -90,10 +85,15 @@ __decorate([
90
85
  UuidProperty(),
91
86
  __metadata("design:type", String)
92
87
  ], TenantEntity.prototype, "tenantId", void 0);
93
- export class TenantEntityWithoutMetadata extends EntityWithoutMetadata {
88
+ export class TenantBaseEntity extends BaseEntity {
94
89
  tenantId;
95
90
  }
96
91
  __decorate([
97
92
  UuidProperty(),
98
93
  __metadata("design:type", String)
99
- ], TenantEntityWithoutMetadata.prototype, "tenantId", void 0);
94
+ ], TenantBaseEntity.prototype, "tenantId", void 0);
95
+ export {
96
+ /**
97
+ * @deprecated Use BaseEntity instead.
98
+ */
99
+ BaseEntity as EntityWithoutMetadata, };