@tstdl/base 0.93.21 → 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.
- package/application/application.js +1 -1
- package/authentication/server/module.d.ts +1 -1
- package/authentication/server/module.js +1 -6
- package/document-management/api/document-management.api.d.ts +0 -4
- package/document-management/service-models/document.service-model.d.ts +0 -2
- package/injector/injector.js +9 -9
- package/logger/manager.js +3 -3
- package/orm/data-types/bytea.d.ts +4 -14
- package/orm/data-types/bytea.js +2 -2
- package/orm/data-types/common.d.ts +18 -0
- package/orm/data-types/common.js +11 -0
- package/orm/data-types/index.d.ts +1 -0
- package/orm/data-types/index.js +1 -0
- package/orm/data-types/numeric-date.d.ts +4 -15
- package/orm/data-types/numeric-date.js +2 -2
- package/orm/data-types/timestamp.d.ts +4 -15
- package/orm/data-types/timestamp.js +2 -2
- package/orm/data-types/tsvector.d.ts +3 -13
- package/orm/data-types/tsvector.js +2 -2
- package/orm/decorators.d.ts +16 -54
- package/orm/decorators.js +24 -37
- package/orm/entity.d.ts +6 -9
- package/orm/entity.js +1 -2
- package/orm/query.d.ts +199 -61
- package/orm/query.js +2 -2
- package/orm/repository.types.d.ts +38 -9
- package/orm/server/drizzle/schema-converter.js +40 -118
- package/orm/server/query-converter.d.ts +21 -7
- package/orm/server/query-converter.js +194 -38
- package/orm/server/repository.d.ts +39 -22
- package/orm/server/repository.js +141 -71
- package/orm/server/types.d.ts +10 -2
- package/orm/sqls.d.ts +14 -16
- package/orm/sqls.js +34 -17
- package/package.json +2 -2
- package/test/drizzle/0000_nervous_iron_monger.sql +9 -0
- package/test/drizzle/meta/0000_snapshot.json +27 -7
- package/test/drizzle/meta/_journal.json +2 -44
- package/test/test.model.js +2 -6
- package/test1.js +18 -5
- package/test6.js +21 -35
- package/types/types.d.ts +8 -5
- package/utils/equals.js +2 -2
- package/utils/format-error.js +2 -2
- package/utils/helpers.js +3 -2
- package/utils/object/object.d.ts +4 -4
- package/test/drizzle/0000_sudden_sphinx.sql +0 -9
- package/test/drizzle/0001_organic_rhodey.sql +0 -2
- package/test/drizzle/0002_nice_squadron_supreme.sql +0 -1
- package/test/drizzle/0003_serious_mockingbird.sql +0 -1
- package/test/drizzle/0004_complete_pixie.sql +0 -1
- package/test/drizzle/0005_bumpy_sabra.sql +0 -1
- package/test/drizzle/0006_overrated_post.sql +0 -6
- package/test/drizzle/meta/0001_snapshot.json +0 -79
- package/test/drizzle/meta/0002_snapshot.json +0 -63
- package/test/drizzle/meta/0003_snapshot.json +0 -73
- package/test/drizzle/meta/0004_snapshot.json +0 -89
- package/test/drizzle/meta/0005_snapshot.json +0 -104
- package/test/drizzle/meta/0006_snapshot.json +0 -104
|
@@ -29,7 +29,7 @@ let Application = Application_1 = class Application {
|
|
|
29
29
|
#shutdownPromise = new DeferredPromise();
|
|
30
30
|
#shutdownToken = inject(CancellationSignal, undefined, { optional: true })?.createChild() ?? new CancellationToken();
|
|
31
31
|
static create(name, providers = []) {
|
|
32
|
-
const injector = new Injector(`${name}
|
|
32
|
+
const injector = new Injector(`${name}ApplicationInjector`);
|
|
33
33
|
injector.register(APPLICATION_INSTANCE_ID, { useValue: crypto.randomUUID() });
|
|
34
34
|
injector.register(APPLICATION_NAME, { useValue: name });
|
|
35
35
|
for (const providersItem of providers.flat()) {
|
|
@@ -15,7 +15,7 @@ export declare class AuthenticationModuleConfig {
|
|
|
15
15
|
/**
|
|
16
16
|
* Options for {@link AuthenticationService}.
|
|
17
17
|
*/
|
|
18
|
-
serviceOptions
|
|
18
|
+
serviceOptions: AuthenticationServiceOptions | Provider<AuthenticationServiceOptions>;
|
|
19
19
|
/**
|
|
20
20
|
* Override default {@link AuthenticationService}.
|
|
21
21
|
*/
|
|
@@ -33,12 +33,7 @@ export class AuthenticationModuleConfig {
|
|
|
33
33
|
*/
|
|
34
34
|
export function configureAuthenticationServer(config) {
|
|
35
35
|
Injector.register(AuthenticationModuleConfig, { useValue: config });
|
|
36
|
-
|
|
37
|
-
Injector.register(AuthenticationServiceOptions, isProvider(config.serviceOptions) ? config.serviceOptions : { useValue: config.serviceOptions });
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw new Error('Either serviceOptions or serviceOptionsToken must be provided.');
|
|
41
|
-
}
|
|
36
|
+
Injector.register(AuthenticationServiceOptions, isProvider(config.serviceOptions) ? config.serviceOptions : { useValue: config.serviceOptions });
|
|
42
37
|
if (isDefined(config.authenticationService)) {
|
|
43
38
|
Injector.registerSingleton(AuthenticationService, { useToken: config.authenticationService });
|
|
44
39
|
}
|
|
@@ -179,7 +179,6 @@ 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;
|
|
183
182
|
tenantId?: string | null | undefined;
|
|
184
183
|
label?: string | undefined;
|
|
185
184
|
metadata?: Partial<{
|
|
@@ -233,7 +232,6 @@ export declare const documentManagementApiDefinition: {
|
|
|
233
232
|
method: "PATCH";
|
|
234
233
|
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
235
234
|
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;
|
|
237
235
|
tenantId?: string | null | undefined;
|
|
238
236
|
typeId?: import("../../orm/types.js").Uuid | undefined;
|
|
239
237
|
comment?: string | null | undefined;
|
|
@@ -581,7 +579,6 @@ declare const _DocumentManagementApi: import("../../api/client/index.js").ApiCli
|
|
|
581
579
|
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
582
580
|
id: import("../../orm/types.js").IsPrimaryKey<import("../../orm/types.js").HasDefault<import("../../orm/types.js").Uuid>>;
|
|
583
581
|
description?: string | null | undefined;
|
|
584
|
-
readonly __entityMeta__?: import("../../orm/entity.js").EntityMeta | undefined;
|
|
585
582
|
tenantId?: string | null | undefined;
|
|
586
583
|
label?: string | undefined;
|
|
587
584
|
metadata?: Partial<{
|
|
@@ -635,7 +632,6 @@ declare const _DocumentManagementApi: import("../../api/client/index.js").ApiCli
|
|
|
635
632
|
method: "PATCH";
|
|
636
633
|
parameters: import("../../schema/index.js").ObjectSchema<{
|
|
637
634
|
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;
|
|
639
635
|
tenantId?: string | null | undefined;
|
|
640
636
|
typeId?: import("../../orm/types.js").Uuid | undefined;
|
|
641
637
|
comment?: string | null | undefined;
|
|
@@ -97,7 +97,6 @@ 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;
|
|
101
100
|
tenantId?: string | null | undefined;
|
|
102
101
|
label?: string | undefined;
|
|
103
102
|
metadata?: Partial<{
|
|
@@ -127,7 +126,6 @@ export declare const createDocumentRequestTemplateParametersSchema: import("../.
|
|
|
127
126
|
}>;
|
|
128
127
|
export declare const updateDocumentRequestTemplateParametersSchema: import("../../schema/index.js").ObjectSchema<{
|
|
129
128
|
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;
|
|
131
129
|
tenantId?: string | null | undefined;
|
|
132
130
|
typeId?: import("../../orm/index.js").Uuid | undefined;
|
|
133
131
|
comment?: string | null | undefined;
|
package/injector/injector.js
CHANGED
|
@@ -287,13 +287,13 @@ export class Injector {
|
|
|
287
287
|
if (isUndefined(token)) {
|
|
288
288
|
throw new ResolveError('Token is undefined. This might be due to a circular dependency. Consider using an alias or forwardRef.', chain);
|
|
289
289
|
}
|
|
290
|
-
const
|
|
291
|
-
if (isDefined(
|
|
292
|
-
const singleRegistration = isArray(
|
|
290
|
+
const registration = this.tryGetRegistration(token, options);
|
|
291
|
+
if (isDefined(registration)) {
|
|
292
|
+
const singleRegistration = isArray(registration) ? registration[0] : registration;
|
|
293
293
|
return this._resolveRegistration(singleRegistration, argument, options, context, chain);
|
|
294
294
|
}
|
|
295
295
|
if ((options.onlySelf != true) && isNotNull(this.#parent)) {
|
|
296
|
-
return this.#parent._resolve(token, argument,
|
|
296
|
+
return this.#parent._resolve(token, argument, options, context, chain);
|
|
297
297
|
}
|
|
298
298
|
if (options.optional == true) {
|
|
299
299
|
return undefined;
|
|
@@ -320,14 +320,14 @@ export class Injector {
|
|
|
320
320
|
}
|
|
321
321
|
const ownValues = [];
|
|
322
322
|
const parentValues = [];
|
|
323
|
-
const
|
|
324
|
-
if (isDefined(
|
|
325
|
-
const registrations = isArray(
|
|
323
|
+
const registration = this.tryGetRegistration(token, options);
|
|
324
|
+
if (isDefined(registration)) {
|
|
325
|
+
const registrations = isArray(registration) ? registration : [registration];
|
|
326
326
|
const resolved = registrations.map((reg) => this._resolveRegistration(reg, argument, options, context, chain));
|
|
327
327
|
ownValues.push(...resolved);
|
|
328
328
|
}
|
|
329
329
|
if ((options.onlySelf != true) && isNotNull(this.#parent)) {
|
|
330
|
-
parentValues.push(...this.#parent._resolveAll(token, argument,
|
|
330
|
+
parentValues.push(...this.#parent._resolveAll(token, argument, options, context, chain));
|
|
331
331
|
}
|
|
332
332
|
const allValues = [...ownValues, ...parentValues];
|
|
333
333
|
if ((allValues.length == 0) && (options.optional != true)) {
|
|
@@ -358,7 +358,7 @@ export class Injector {
|
|
|
358
358
|
}
|
|
359
359
|
// A new scope is only needed if we are instantiating a class, running a factory, or if the registration explicitly defines scoped providers.
|
|
360
360
|
const needsNewScope = isClassProvider(provider) || isFactoryProvider(provider) || (providers.length > 0);
|
|
361
|
-
const injector = needsNewScope ? this.fork(
|
|
361
|
+
const injector = needsNewScope ? this.fork(`[${getTokenName(token)}]ResolutionInjector`) : this;
|
|
362
362
|
for (const nestedProvider of providers) {
|
|
363
363
|
injector.registerSingleton(nestedProvider.provide, nestedProvider, { multi: nestedProvider.multi });
|
|
364
364
|
}
|
package/logger/manager.js
CHANGED
|
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { Singleton } from '../injector/decorators.js';
|
|
8
8
|
import { inject, injectAll } from '../injector/inject.js';
|
|
9
|
-
import { isDefined } from '../utils/type-guards.js';
|
|
9
|
+
import { isArray, isDefined } from '../utils/type-guards.js';
|
|
10
10
|
import { LogLevel } from './level.js';
|
|
11
11
|
import { DEFAULT_LOG_LEVEL } from './tokens.js';
|
|
12
12
|
import { LogTransport } from './transport.js';
|
|
@@ -41,7 +41,7 @@ let LogManager = class LogManager {
|
|
|
41
41
|
* @param level The log level to set
|
|
42
42
|
*/
|
|
43
43
|
setModuleLevel(module, level) {
|
|
44
|
-
const moduleString =
|
|
44
|
+
const moduleString = isArray(module) ? module.join('.') : module;
|
|
45
45
|
if (this.#moduleLevelRules.get(moduleString) === level) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
@@ -58,7 +58,7 @@ let LogManager = class LogManager {
|
|
|
58
58
|
if (!isDefined(module) || (module.length == 0)) {
|
|
59
59
|
return this.#defaultLevel;
|
|
60
60
|
}
|
|
61
|
-
const path =
|
|
61
|
+
const path = isArray(module) ? module.join('.') : module;
|
|
62
62
|
const cachedLevel = this.#moduleLevelCache.get(path);
|
|
63
63
|
if (isDefined(cachedLevel)) {
|
|
64
64
|
return cachedLevel;
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module
|
|
3
|
-
* Defines a custom Drizzle type for handling PostgreSQL `bytea` columns.
|
|
4
|
-
*/
|
|
5
|
-
import { type ConvertCustomConfig, type PgCustomColumnBuilder } from 'drizzle-orm/pg-core';
|
|
6
|
-
type Config = {
|
|
7
|
-
data: Uint8Array;
|
|
8
|
-
driverData: Uint8Array;
|
|
9
|
-
};
|
|
10
1
|
/**
|
|
11
2
|
* Custom Drizzle type for PostgreSQL `bytea` columns.
|
|
12
3
|
* Maps between `Uint8Array` in JavaScript and `bytea` in the database.
|
|
13
4
|
*/
|
|
14
|
-
export declare const bytea: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
export {};
|
|
5
|
+
export declare const bytea: import("./common.js").CustomTypeBuilder<{
|
|
6
|
+
data: Uint8Array;
|
|
7
|
+
driverData: Uint8Array;
|
|
8
|
+
}>;
|
package/orm/data-types/bytea.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* @module
|
|
3
3
|
* Defines a custom Drizzle type for handling PostgreSQL `bytea` columns.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { createCustomType } from './common.js';
|
|
6
6
|
/**
|
|
7
7
|
* Custom Drizzle type for PostgreSQL `bytea` columns.
|
|
8
8
|
* Maps between `Uint8Array` in JavaScript and `bytea` in the database.
|
|
9
9
|
*/
|
|
10
|
-
export const bytea =
|
|
10
|
+
export const bytea = createCustomType({
|
|
11
11
|
dataType() {
|
|
12
12
|
return 'bytea';
|
|
13
13
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ConvertCustomConfig, type CustomTypeParams, type CustomTypeValues, type PgCustomColumnBuilder } from 'drizzle-orm/pg-core';
|
|
2
|
+
/**
|
|
3
|
+
* A generic type for a custom Drizzle column builder function.
|
|
4
|
+
* This provides the overloads for creating a column with or without a specific database name.
|
|
5
|
+
* @template TConfig The configuration object for the custom type, containing `data` and `driverData` types.
|
|
6
|
+
*/
|
|
7
|
+
export type CustomTypeBuilder<TConfig extends Partial<CustomTypeValues>> = {
|
|
8
|
+
(): PgCustomColumnBuilder<ConvertCustomConfig<'', TConfig>>;
|
|
9
|
+
<TName extends string>(dbName: TName): PgCustomColumnBuilder<ConvertCustomConfig<TName, TConfig>>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Factory function to create a custom Drizzle type with the standard builder overloads.
|
|
13
|
+
* This reduces boilerplate by wrapping `drizzle-orm/pg-core#customType` and applying a common type cast.
|
|
14
|
+
* @template TConfig The configuration object for the custom type.
|
|
15
|
+
* @param params The parameters for the custom type, including `dataType`, `toDriver`, and `fromDriver`.
|
|
16
|
+
* @returns A custom type builder function.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createCustomType<TConfig extends CustomTypeValues>(params: CustomTypeParams<TConfig>): CustomTypeBuilder<TConfig>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { customType, } from 'drizzle-orm/pg-core';
|
|
2
|
+
/**
|
|
3
|
+
* Factory function to create a custom Drizzle type with the standard builder overloads.
|
|
4
|
+
* This reduces boilerplate by wrapping `drizzle-orm/pg-core#customType` and applying a common type cast.
|
|
5
|
+
* @template TConfig The configuration object for the custom type.
|
|
6
|
+
* @param params The parameters for the custom type, including `dataType`, `toDriver`, and `fromDriver`.
|
|
7
|
+
* @returns A custom type builder function.
|
|
8
|
+
*/
|
|
9
|
+
export function createCustomType(params) {
|
|
10
|
+
return customType(params);
|
|
11
|
+
}
|
package/orm/data-types/index.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module
|
|
3
|
-
* Defines a custom Drizzle type for handling PostgreSQL `date` columns
|
|
4
|
-
* using numeric representation (YYYYMMDD).
|
|
5
|
-
*/
|
|
6
|
-
import { type ConvertCustomConfig, type PgCustomColumnBuilder } from 'drizzle-orm/pg-core';
|
|
7
|
-
type Config = {
|
|
8
|
-
data: number;
|
|
9
|
-
driverData: string;
|
|
10
|
-
};
|
|
11
1
|
/**
|
|
12
2
|
* Custom Drizzle type for PostgreSQL `date` columns, storing dates as numeric values (YYYYMMDD).
|
|
13
3
|
* Converts between JavaScript `number` (YYYYMMDD) and database `date` (ISO string).
|
|
14
4
|
*/
|
|
15
|
-
export declare const numericDate: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
5
|
+
export declare const numericDate: import("./common.js").CustomTypeBuilder<{
|
|
6
|
+
data: number;
|
|
7
|
+
driverData: string;
|
|
8
|
+
}>;
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Defines a custom Drizzle type for handling PostgreSQL `date` columns
|
|
4
4
|
* using numeric representation (YYYYMMDD).
|
|
5
5
|
*/
|
|
6
|
-
import { customType } from 'drizzle-orm/pg-core';
|
|
7
6
|
import { dateToNumericDate, numericDateToDateObject } from '../../utils/date-time.js';
|
|
7
|
+
import { createCustomType } from './common.js';
|
|
8
8
|
/**
|
|
9
9
|
* Custom Drizzle type for PostgreSQL `date` columns, storing dates as numeric values (YYYYMMDD).
|
|
10
10
|
* Converts between JavaScript `number` (YYYYMMDD) and database `date` (ISO string).
|
|
11
11
|
*/
|
|
12
|
-
export const numericDate =
|
|
12
|
+
export const numericDate = createCustomType({
|
|
13
13
|
dataType() {
|
|
14
14
|
return 'date';
|
|
15
15
|
},
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module
|
|
3
|
-
* Defines a custom Drizzle type for handling PostgreSQL `timestamp with time zone` columns
|
|
4
|
-
* using numeric representation (Unix timestamp in milliseconds).
|
|
5
|
-
*/
|
|
6
|
-
import { type ConvertCustomConfig, type PgCustomColumnBuilder } from 'drizzle-orm/pg-core';
|
|
7
|
-
type Config = {
|
|
8
|
-
data: number;
|
|
9
|
-
driverData: string;
|
|
10
|
-
};
|
|
11
1
|
/**
|
|
12
2
|
* Custom Drizzle type for PostgreSQL `timestamp with time zone` columns, storing timestamps as numeric values (Unix timestamp in milliseconds).
|
|
13
3
|
* Converts between JavaScript `number` (milliseconds since epoch) and database `timestamp with time zone` (ISO string).
|
|
14
4
|
*/
|
|
15
|
-
export declare const timestamp: {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
5
|
+
export declare const timestamp: import("./common.js").CustomTypeBuilder<{
|
|
6
|
+
data: number;
|
|
7
|
+
driverData: string;
|
|
8
|
+
}>;
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
* Defines a custom Drizzle type for handling PostgreSQL `timestamp with time zone` columns
|
|
4
4
|
* using numeric representation (Unix timestamp in milliseconds).
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { createCustomType } from './common.js';
|
|
7
7
|
/**
|
|
8
8
|
* Custom Drizzle type for PostgreSQL `timestamp with time zone` columns, storing timestamps as numeric values (Unix timestamp in milliseconds).
|
|
9
9
|
* Converts between JavaScript `number` (milliseconds since epoch) and database `timestamp with time zone` (ISO string).
|
|
10
10
|
*/
|
|
11
|
-
export const timestamp =
|
|
11
|
+
export const timestamp = createCustomType({
|
|
12
12
|
dataType() {
|
|
13
13
|
return 'timestamp with time zone';
|
|
14
14
|
},
|
|
@@ -1,16 +1,6 @@
|
|
|
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
1
|
/**
|
|
10
2
|
* Custom Drizzle type for PostgreSQL `tsvector` columns.
|
|
11
3
|
*/
|
|
12
|
-
export declare const tsvector: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
export {};
|
|
4
|
+
export declare const tsvector: import("./common.js").CustomTypeBuilder<{
|
|
5
|
+
data: unknown;
|
|
6
|
+
}>;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @module
|
|
3
3
|
* Defines a custom Drizzle type for handling PostgreSQL `tsvector` columns.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { createCustomType } from './common.js';
|
|
6
6
|
/**
|
|
7
7
|
* Custom Drizzle type for PostgreSQL `tsvector` columns.
|
|
8
8
|
*/
|
|
9
|
-
export const tsvector =
|
|
9
|
+
export const tsvector = createCustomType({
|
|
10
10
|
dataType() {
|
|
11
11
|
return 'tsvector';
|
|
12
12
|
},
|
package/orm/decorators.d.ts
CHANGED
|
@@ -3,29 +3,30 @@
|
|
|
3
3
|
* Defines decorators for ORM entities and columns, used to configure database schema mapping.
|
|
4
4
|
*/
|
|
5
5
|
import type { SQL } from 'drizzle-orm';
|
|
6
|
+
import type { ExtraConfigColumn } from 'drizzle-orm/pg-core';
|
|
6
7
|
import type { LiteralUnion } from 'type-fest';
|
|
7
8
|
import { type SpecificCreateDecoratorOptions } from '../reflection/index.js';
|
|
8
9
|
import type { AbstractConstructor, Record, TypedOmit } from '../types/index.js';
|
|
9
10
|
import type { ValueOrProvider } from '../utils/value-or-provider.js';
|
|
10
11
|
import type { AnyEntity, BaseEntity, Entity, EntityType } from './entity.js';
|
|
11
12
|
import type { Query } from './query.js';
|
|
12
|
-
import type {
|
|
13
|
-
import type {
|
|
14
|
-
type IndexMethod = LiteralUnion<'hash' | 'btree' | 'gist' | 'spgist' | 'gin' | 'brin' | 'hnsw' | 'ivfflat', string>;
|
|
13
|
+
import type { TargetColumnPath } from './repository.types.js';
|
|
14
|
+
import type { ExtraConfigColumnsFromType } from './server/types.js';
|
|
15
|
+
type IndexMethod = LiteralUnion<'hash' | 'btree' | 'gist' | 'spgist' | 'gin' | 'brin' | 'hnsw' | 'ivfflat' | 'bm25', string>;
|
|
15
16
|
type NamingStrategy = 'abbreviated-table';
|
|
16
|
-
type Column<T> =
|
|
17
|
-
type Columns<T> = [Column<T>, ...Column<T>[]];
|
|
18
|
-
export type SqlBuilder<T extends BaseEntity = any, R = SQL> = (table:
|
|
17
|
+
type Column<T extends BaseEntity> = TargetColumnPath<T>;
|
|
18
|
+
type Columns<T extends BaseEntity> = [Column<T>, ...Column<T>[]];
|
|
19
|
+
export type SqlBuilder<T extends BaseEntity = any, R = SQL> = (table: ExtraConfigColumnsFromType<EntityType<T>>) => R;
|
|
19
20
|
/**
|
|
20
21
|
* Builder function type for creating SQL check constraints.
|
|
21
22
|
* @param table The Drizzle table object.
|
|
22
23
|
*/
|
|
23
|
-
export type CheckBuilder<T extends BaseEntity =
|
|
24
|
+
export type CheckBuilder<T extends BaseEntity = BaseEntity> = SqlBuilder<T>;
|
|
24
25
|
/**
|
|
25
26
|
* Builder function type for creating partial index WHERE clauses.
|
|
26
27
|
* @param table The Drizzle table object.
|
|
27
28
|
*/
|
|
28
|
-
export type WhereBuilder<T extends BaseEntity =
|
|
29
|
+
export type WhereBuilder<T extends BaseEntity = BaseEntity> = SqlBuilder<T, Query<T>>;
|
|
29
30
|
/**
|
|
30
31
|
* Reflection data stored for ORM table decorators.
|
|
31
32
|
*/
|
|
@@ -36,7 +37,6 @@ export type OrmTableReflectionData = {
|
|
|
36
37
|
compundPrimaryKeyNaming?: NamingStrategy;
|
|
37
38
|
unique?: UniqueReflectionData[];
|
|
38
39
|
index?: IndexReflectionData[];
|
|
39
|
-
fullTextSearch?: FullTextSearchReflectionData[];
|
|
40
40
|
checks?: CheckReflectionData[];
|
|
41
41
|
foreignKeys?: ForeignKeyReflectionData[];
|
|
42
42
|
};
|
|
@@ -57,7 +57,7 @@ export type OrmColumnReflectionData = {
|
|
|
57
57
|
};
|
|
58
58
|
references?: {
|
|
59
59
|
target: () => EntityType;
|
|
60
|
-
targetColumn?:
|
|
60
|
+
targetColumn?: TargetColumnPath<any>;
|
|
61
61
|
}[];
|
|
62
62
|
encrypted?: boolean;
|
|
63
63
|
expirationField?: {
|
|
@@ -81,7 +81,7 @@ export type UniqueReflectionData = {
|
|
|
81
81
|
* @template T The entity type.
|
|
82
82
|
*/
|
|
83
83
|
export type IndexReflectionData<T extends BaseEntity = any> = {
|
|
84
|
-
columns?: (
|
|
84
|
+
columns?: ValueOrProvider<(TargetColumnPath<T> | [TargetColumnPath<T>, 'asc' | 'desc'] | SQL | ExtraConfigColumn)[], ExtraConfigColumnsFromType<EntityType<T>>>;
|
|
85
85
|
order?: 'asc' | 'desc';
|
|
86
86
|
options?: {
|
|
87
87
|
name?: string;
|
|
@@ -89,48 +89,11 @@ export type IndexReflectionData<T extends BaseEntity = any> = {
|
|
|
89
89
|
using?: IndexMethod;
|
|
90
90
|
unique?: boolean;
|
|
91
91
|
where?: WhereBuilder<T>;
|
|
92
|
+
with?: Record<string, number | string | boolean | SQL>;
|
|
93
|
+
concurrently?: boolean;
|
|
92
94
|
nulls?: 'first' | 'last';
|
|
93
95
|
};
|
|
94
96
|
};
|
|
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?: {
|
|
107
|
-
/**
|
|
108
|
-
* Raw SQL or builder function for generating the tsvector source.
|
|
109
|
-
*/
|
|
110
|
-
rawVectorSource?: ValueOrProvider<SQL, PgTableFromType<EntityType<T>>>;
|
|
111
|
-
/**
|
|
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.
|
|
115
|
-
*/
|
|
116
|
-
language?: string | SQL | SqlBuilder<T>;
|
|
117
|
-
/**
|
|
118
|
-
* Weights for columns in source.
|
|
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.
|
|
130
|
-
*/
|
|
131
|
-
threshold?: number;
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
97
|
type CheckReflectionData = {
|
|
135
98
|
name: string;
|
|
136
99
|
builder: CheckBuilder;
|
|
@@ -140,8 +103,8 @@ type CheckReflectionData = {
|
|
|
140
103
|
};
|
|
141
104
|
export type ForeignKeyReflectionData = {
|
|
142
105
|
target: () => EntityType;
|
|
143
|
-
columns:
|
|
144
|
-
foreignColumns:
|
|
106
|
+
columns: TargetColumnPath<any>[];
|
|
107
|
+
foreignColumns: TargetColumnPath<any>[];
|
|
145
108
|
options?: {
|
|
146
109
|
name?: string;
|
|
147
110
|
naming?: NamingStrategy;
|
|
@@ -179,7 +142,7 @@ export declare function PrimaryKeyProperty(): PropertyDecorator;
|
|
|
179
142
|
* @param type A function returning the referenced entity type.
|
|
180
143
|
*/
|
|
181
144
|
export declare function References(target: () => EntityType): PropertyDecorator;
|
|
182
|
-
export declare function References<T extends AnyEntity>(target: () => EntityType<T>, targetColumn?:
|
|
145
|
+
export declare function References<T extends AnyEntity>(target: () => EntityType<T>, targetColumn?: TargetColumnPath<T>): PropertyDecorator;
|
|
183
146
|
/**
|
|
184
147
|
* Define a table check constraint.
|
|
185
148
|
* @template T The entity type.
|
|
@@ -247,7 +210,6 @@ export declare function Index<T extends BaseEntity = any>(options?: IndexReflect
|
|
|
247
210
|
* @param options Additional index options.
|
|
248
211
|
*/
|
|
249
212
|
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;
|
|
251
213
|
/**
|
|
252
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}.
|
|
253
215
|
* @param ttl Time To Live in milliseconds.
|
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 {
|
|
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
|
|
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
|
|
39
|
+
export declare abstract class Entity extends BaseEntity {
|
|
43
40
|
metadata: Embedded<EntityMetadata>;
|
|
44
41
|
}
|
|
45
|
-
export declare abstract class TenantEntity
|
|
42
|
+
export declare abstract class TenantEntity extends Entity {
|
|
46
43
|
tenantId: Uuid;
|
|
47
44
|
}
|
|
48
|
-
export declare abstract class TenantBaseEntity
|
|
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 };
|