@tstdl/base 0.93.15 → 0.93.17
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/document-management/api/document-management.api.d.ts +4 -0
- package/document-management/service-models/document.service-model.d.ts +2 -0
- package/injector/injector.js +13 -10
- package/mail/mail.service.js +1 -1
- package/orm/data-types/index.d.ts +1 -0
- package/orm/data-types/index.js +1 -0
- package/orm/data-types/tsvector.d.ts +16 -0
- package/orm/data-types/tsvector.js +13 -0
- package/orm/decorators.d.ts +44 -32
- package/orm/decorators.js +3 -6
- package/orm/entity.d.ts +20 -13
- package/orm/entity.js +18 -18
- package/orm/repository.types.d.ts +13 -13
- package/orm/server/drizzle/schema-converter.js +115 -63
- package/orm/server/types.d.ts +2 -3
- package/package.json +4 -4
- package/test/drizzle/0002_nice_squadron_supreme.sql +1 -0
- package/test/drizzle/0003_serious_mockingbird.sql +1 -0
- package/test/drizzle/0004_complete_pixie.sql +1 -0
- package/test/drizzle/0005_bumpy_sabra.sql +1 -0
- package/test/drizzle/0006_overrated_post.sql +6 -0
- package/test/drizzle/meta/0002_snapshot.json +63 -0
- package/test/drizzle/meta/0003_snapshot.json +73 -0
- package/test/drizzle/meta/0004_snapshot.json +89 -0
- package/test/drizzle/meta/0005_snapshot.json +104 -0
- package/test/drizzle/meta/0006_snapshot.json +104 -0
- package/test/drizzle/meta/_journal.json +35 -0
- package/test/test.model.d.ts +2 -2
- package/test/test.model.js +6 -4
- package/utils/value-or-provider.d.ts +7 -4
- 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;
|
package/injector/injector.js
CHANGED
|
@@ -320,8 +320,10 @@ export class Injector {
|
|
|
320
320
|
}
|
|
321
321
|
_resolveRegistration(registration, argument, options, context, chain) {
|
|
322
322
|
checkOverflow(chain, context);
|
|
323
|
-
const { token, providers } = registration;
|
|
324
|
-
|
|
323
|
+
const { token, provider, providers } = registration;
|
|
324
|
+
// A new scope is only needed if we are instantiating a class, running a factory, or if the registration explicitly defines scoped providers.
|
|
325
|
+
const needsNewScope = isClassProvider(provider) || isFactoryProvider(provider) || (providers.length > 0);
|
|
326
|
+
const injector = needsNewScope ? this.fork('ResolutionInjector') : this;
|
|
325
327
|
for (const nestedProvider of providers) {
|
|
326
328
|
injector.registerSingleton(nestedProvider.provide, nestedProvider, { multi: nestedProvider.multi });
|
|
327
329
|
}
|
|
@@ -375,7 +377,7 @@ export class Injector {
|
|
|
375
377
|
}
|
|
376
378
|
_resolveProvider(resolutionTag, registration, resolveArgument, options, context, resolutionContext, injectionContext, chain) {
|
|
377
379
|
try {
|
|
378
|
-
setResolving(registration.token, context, chain);
|
|
380
|
+
setResolving(this, registration.token, context, chain);
|
|
379
381
|
const { provider } = registration;
|
|
380
382
|
let result;
|
|
381
383
|
if (isClassProvider(provider)) {
|
|
@@ -417,7 +419,7 @@ export class Injector {
|
|
|
417
419
|
return result.value;
|
|
418
420
|
}
|
|
419
421
|
finally {
|
|
420
|
-
deleteResolving(registration.token, context);
|
|
422
|
+
deleteResolving(this, registration.token, context);
|
|
421
423
|
}
|
|
422
424
|
}
|
|
423
425
|
resolveClassInjection(resolutionTag, context, constructor, metadata, resolveArgument, chain) {
|
|
@@ -523,7 +525,7 @@ function addRegistration(registrations, registration) {
|
|
|
523
525
|
function newInternalResolveContext() {
|
|
524
526
|
return {
|
|
525
527
|
resolves: 0,
|
|
526
|
-
resolving: new Set(),
|
|
528
|
+
resolving: new FactoryMap(() => new Set()),
|
|
527
529
|
resolutionScopedResolutions: new MultiKeyMap(),
|
|
528
530
|
resolutions: [],
|
|
529
531
|
resolutionContextData: new FactoryMap(() => ({})),
|
|
@@ -594,14 +596,15 @@ function resolveArgumentIdentity(registration, resolveArgument, chain) {
|
|
|
594
596
|
}
|
|
595
597
|
return resolveArgument;
|
|
596
598
|
}
|
|
597
|
-
function setResolving(token, context, chain) {
|
|
598
|
-
|
|
599
|
+
function setResolving(injector, token, context, chain) {
|
|
600
|
+
const resolvingSet = context.resolving.get(injector);
|
|
601
|
+
if (resolvingSet.has(token)) {
|
|
599
602
|
throw new ResolveError('Circular dependency detected. Use forwardRef for circular dependencies between classes.', chain);
|
|
600
603
|
}
|
|
601
|
-
|
|
604
|
+
resolvingSet.add(token);
|
|
602
605
|
}
|
|
603
|
-
function deleteResolving(token, context) {
|
|
604
|
-
context.resolving.delete(token);
|
|
606
|
+
function deleteResolving(injector, token, context) {
|
|
607
|
+
context.resolving.get(injector).delete(token);
|
|
605
608
|
}
|
|
606
609
|
function throwOnPromise(value, type, chain) {
|
|
607
610
|
if (isPromise(value)) {
|
package/mail/mail.service.js
CHANGED
|
@@ -61,7 +61,7 @@ MailService = __decorate([
|
|
|
61
61
|
providers: [
|
|
62
62
|
provide(EntityRepositoryConfig, { useValue: { schema: 'mail' } }),
|
|
63
63
|
provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(MailModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) }),
|
|
64
|
-
]
|
|
64
|
+
],
|
|
65
65
|
})
|
|
66
66
|
], MailService);
|
|
67
67
|
export { MailService };
|
package/orm/data-types/index.js
CHANGED
|
@@ -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
|
+
});
|
package/orm/decorators.d.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
|
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
|
|
81
|
-
columns?: (string | [string, 'asc' | 'desc']
|
|
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
|
-
*
|
|
92
|
-
* Can also be a SQL object for dynamic configuration.
|
|
108
|
+
* Raw SQL or builder function for generating the tsvector source.
|
|
93
109
|
*/
|
|
94
|
-
|
|
110
|
+
rawVectorSource?: ValueOrProvider<SQL, PgTableFromType<EntityType<T>>>;
|
|
95
111
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
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
|
-
|
|
116
|
+
language?: string | SQL | SqlBuilder<T>;
|
|
101
117
|
/**
|
|
102
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
141
|
-
|
|
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
|
|
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
|
|
7
|
+
export interface EntityType<T extends BaseEntity = BaseEntity | Entity> extends Type<T> {
|
|
8
8
|
readonly entityName?: string;
|
|
9
9
|
}
|
|
10
|
-
export type AnyEntity =
|
|
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)
|
|
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
|
|
34
|
+
export declare abstract class BaseEntity<TMeta extends EntityMeta = EntityMeta> {
|
|
33
35
|
id: IsPrimaryKey<HasDefault<Uuid>>;
|
|
34
|
-
|
|
36
|
+
readonly [entityMeta]?: TMeta;
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
|
-
* Abstract base class for entities that
|
|
38
|
-
* Provides
|
|
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
|
|
41
|
-
|
|
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
|
|
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)
|
|
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
|
|
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
|
-
],
|
|
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
|
|
76
|
-
* Provides
|
|
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
|
|
79
|
-
|
|
74
|
+
export class Entity extends BaseEntity {
|
|
75
|
+
metadata;
|
|
80
76
|
}
|
|
81
77
|
__decorate([
|
|
82
|
-
|
|
83
|
-
UuidProperty({ defaultRandom: true }),
|
|
78
|
+
EmbeddedProperty(EntityMetadata, { prefix: null }),
|
|
84
79
|
__metadata("design:type", Object)
|
|
85
|
-
],
|
|
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
|
|
88
|
+
export class TenantBaseEntity extends BaseEntity {
|
|
94
89
|
tenantId;
|
|
95
90
|
}
|
|
96
91
|
__decorate([
|
|
97
92
|
UuidProperty(),
|
|
98
93
|
__metadata("design:type", String)
|
|
99
|
-
],
|
|
94
|
+
], TenantBaseEntity.prototype, "tenantId", void 0);
|
|
95
|
+
export {
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use BaseEntity instead.
|
|
98
|
+
*/
|
|
99
|
+
BaseEntity as EntityWithoutMetadata, };
|
|
@@ -7,7 +7,7 @@ import type { Paths, Record, SimplifyObject, TypedOmit } from '../types/index.js
|
|
|
7
7
|
import type { UntaggedDeep } from '../types/tagged.js';
|
|
8
8
|
import type { SQL, SQLWrapper } from 'drizzle-orm';
|
|
9
9
|
import type { PartialDeep } from 'type-fest';
|
|
10
|
-
import type { Entity, EntityMetadata
|
|
10
|
+
import type { BaseEntity, Entity, EntityMetadata } from './entity.js';
|
|
11
11
|
import type { FullTextSearchQuery, Query } from './query.js';
|
|
12
12
|
import type { TsHeadlineOptions } from './sqls.js';
|
|
13
13
|
type WithSql<T> = {
|
|
@@ -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
|
|
21
|
+
export type TargetColumnPaths<T extends BaseEntity> = Paths<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
|
|
27
|
+
export type TargetColumn<T extends BaseEntity> = TargetColumnPaths<T> | SQLWrapper;
|
|
28
28
|
/** Specifies the direction for ordering results ('asc' or 'desc'). */
|
|
29
29
|
export type OrderDirection = 'asc' | 'desc';
|
|
30
30
|
/**
|
|
@@ -32,26 +32,26 @@ export type OrderDirection = 'asc' | 'desc';
|
|
|
32
32
|
* (optionally with direction), or an object mapping property paths to directions.
|
|
33
33
|
* @template T - The entity type.
|
|
34
34
|
*/
|
|
35
|
-
export type Order<T extends
|
|
35
|
+
export type Order<T extends BaseEntity> = TargetColumn<T> | (TargetColumn<T> | [TargetColumn<T>, OrderDirection])[] | Partial<Record<Exclude<TargetColumn<T>, SQLWrapper>, OrderDirection>>;
|
|
36
36
|
/**
|
|
37
37
|
* Options object containing ordering configuration.
|
|
38
38
|
* @template T - The entity type.
|
|
39
39
|
*/
|
|
40
|
-
export type OrderOptions<T extends
|
|
40
|
+
export type OrderOptions<T extends BaseEntity> = {
|
|
41
41
|
order?: Order<T>;
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
44
|
* Options for loading a single entity, including ordering and offset.
|
|
45
45
|
* @template T - The entity type.
|
|
46
46
|
*/
|
|
47
|
-
export type LoadOptions<T extends
|
|
47
|
+
export type LoadOptions<T extends BaseEntity> = OrderOptions<T> & {
|
|
48
48
|
offset?: number;
|
|
49
49
|
};
|
|
50
50
|
/**
|
|
51
51
|
* Options for loading multiple entities, including ordering, offset, and limit.
|
|
52
52
|
* @template T - The entity type.
|
|
53
53
|
*/
|
|
54
|
-
export type LoadManyOptions<T extends
|
|
54
|
+
export type LoadManyOptions<T extends BaseEntity> = LoadOptions<T> & {
|
|
55
55
|
limit?: number;
|
|
56
56
|
distinct?: boolean | TargetColumn<T>[];
|
|
57
57
|
};
|
|
@@ -74,7 +74,7 @@ export type RankOptions = {
|
|
|
74
74
|
/**
|
|
75
75
|
* Options for highlighting search results.
|
|
76
76
|
*/
|
|
77
|
-
export type HighlightOptions<T extends
|
|
77
|
+
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
|
*/
|
|
@@ -84,7 +84,7 @@ export type HighlightOptions<T extends EntityWithoutMetadata> = {
|
|
|
84
84
|
* Options for the `search` method.
|
|
85
85
|
* @template T - The entity type.
|
|
86
86
|
*/
|
|
87
|
-
export type SearchOptions<T extends
|
|
87
|
+
export type SearchOptions<T extends BaseEntity> = SimplifyObject<FullTextSearchQuery<T>['$fts'] & TypedOmit<LoadManyOptions<T>, 'order'> & {
|
|
88
88
|
/**
|
|
89
89
|
* An additional filter to apply to the search query.
|
|
90
90
|
*/
|
|
@@ -119,7 +119,7 @@ export type SearchOptions<T extends EntityWithoutMetadata> = SimplifyObject<Full
|
|
|
119
119
|
* Represents a single result from a full-text search operation.
|
|
120
120
|
* @template T - The entity type.
|
|
121
121
|
*/
|
|
122
|
-
export type SearchResult<T extends
|
|
122
|
+
export type SearchResult<T extends BaseEntity> = {
|
|
123
123
|
entity: T;
|
|
124
124
|
score?: number;
|
|
125
125
|
highlight?: string;
|
|
@@ -128,7 +128,7 @@ export type SearchResult<T extends EntityWithoutMetadata> = {
|
|
|
128
128
|
* Options for update operations (currently inherits from LoadOptions, primarily for ordering).
|
|
129
129
|
* @template T - The entity type.
|
|
130
130
|
*/
|
|
131
|
-
export type UpdateOptions<T extends
|
|
131
|
+
export type UpdateOptions<T extends BaseEntity> = LoadOptions<T>;
|
|
132
132
|
/** Type definition for updating entity metadata attributes, allowing partial updates and SQL expressions. */
|
|
133
133
|
export type EntityMetadataUpdate = WithSql<Partial<UntaggedDeep<Pick<EntityMetadata, 'attributes'>>>>;
|
|
134
134
|
export type EntityMetadataInsert = Partial<Pick<EntityMetadata, 'attributes'>>;
|
|
@@ -138,7 +138,7 @@ export type EntityMetadataInsert = Partial<Pick<EntityMetadata, 'attributes'>>;
|
|
|
138
138
|
* Allows SQL expressions for values.
|
|
139
139
|
* @template T - The entity type.
|
|
140
140
|
*/
|
|
141
|
-
export type NewEntity<T extends Entity |
|
|
141
|
+
export type NewEntity<T extends Entity | BaseEntity> = T extends Entity ? WithSql<UntaggedDeep<TypedOmit<T, 'id' | 'metadata'> & {
|
|
142
142
|
id?: string;
|
|
143
143
|
metadata?: EntityMetadataInsert;
|
|
144
144
|
}>> : WithSql<UntaggedDeep<TypedOmit<T, 'id'> & {
|
|
@@ -150,7 +150,7 @@ export type NewEntity<T extends Entity | EntityWithoutMetadata> = T extends Enti
|
|
|
150
150
|
* Allows SQL expressions for values.
|
|
151
151
|
* @template T - The entity type.
|
|
152
152
|
*/
|
|
153
|
-
export type EntityUpdate<T extends
|
|
153
|
+
export type EntityUpdate<T extends BaseEntity> = T extends Entity ? WithSql<PartialDeep<UntaggedDeep<TypedOmit<T, 'metadata'>>>> & {
|
|
154
154
|
metadata?: EntityMetadataUpdate;
|
|
155
155
|
} : WithSql<PartialDeep<UntaggedDeep<T>>>;
|
|
156
156
|
export {};
|