@tstdl/base 0.92.64 → 0.92.66
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/context/context.d.ts +8 -8
- package/orm/server/data-types/index.d.ts +2 -0
- package/orm/server/data-types/index.js +2 -0
- package/orm/server/data-types/numeric-date.d.ts +10 -0
- package/orm/server/data-types/numeric-date.js +15 -0
- package/orm/server/data-types/timestamp.d.ts +10 -0
- package/orm/server/data-types/timestamp.js +12 -0
- package/orm/server/drizzle/schema-converter.js +4 -4
- package/orm/server/repository.d.ts +1 -1
- package/orm/server/repository.js +14 -12
- package/package.json +1 -1
package/context/context.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { SimplifyObject } from '../types.js';
|
|
1
|
+
import type { Function, SimplifyObject } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a new context provider
|
|
4
4
|
* @param name name of of the context used for function names
|
|
5
5
|
*/
|
|
6
|
-
export declare function createContextProvider<Context, const Name extends string>(name: Name): SimplifyObject<
|
|
6
|
+
export declare function createContextProvider<Context, const Name extends string>(name: Name): SimplifyObject<Record<`getCurrent${Name}Context`, {
|
|
7
7
|
(required: true, debugFn: Function): Context;
|
|
8
|
-
(required?: false
|
|
8
|
+
(required?: false, debugFn?: Function): Context | null;
|
|
9
9
|
(required: boolean, debugFn: Function): Context | null;
|
|
10
|
-
}
|
|
10
|
+
}> & Record<`setCurrent${Name}Context`, (context: Context | null) => Context | null> & Record<`runIn${Name}Context`, <ReturnT>(context: Context, fn: () => ReturnT) => ReturnT> & Record<`isIn${Name}Context`, {
|
|
11
11
|
(required: true, debugFn: Function): Context;
|
|
12
|
-
(required?: false
|
|
12
|
+
(required?: false, debugFn?: Function): Context | null;
|
|
13
13
|
(required: boolean, debugFn: Function): Context | null;
|
|
14
|
-
}
|
|
14
|
+
}> & Record<`assertIn${Name}Context`, {
|
|
15
15
|
(required: true, debugFn: Function): Context;
|
|
16
|
-
(required?: false
|
|
16
|
+
(required?: false, debugFn?: Function): Context | null;
|
|
17
17
|
(required: boolean, debugFn: Function): Context | null;
|
|
18
|
-
}
|
|
18
|
+
}>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ConvertCustomConfig, type PgCustomColumnBuilder } from 'drizzle-orm/pg-core';
|
|
2
|
+
type Config = {
|
|
3
|
+
data: number;
|
|
4
|
+
driverData: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const numericDate: {
|
|
7
|
+
(): PgCustomColumnBuilder<ConvertCustomConfig<"", Config>>;
|
|
8
|
+
<TName extends string>(dbName: TName): PgCustomColumnBuilder<ConvertCustomConfig<TName, Config>>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { customType } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { dateToNumericDate, numericDateToDate } from '../../../utils/date-time.js';
|
|
3
|
+
export const numericDate = customType({
|
|
4
|
+
dataType() {
|
|
5
|
+
return 'date';
|
|
6
|
+
},
|
|
7
|
+
toDriver(value) {
|
|
8
|
+
const { year, month, day } = numericDateToDate(value);
|
|
9
|
+
return new Date(year, month - 1, day).toISOString();
|
|
10
|
+
},
|
|
11
|
+
fromDriver(value) {
|
|
12
|
+
const date = new Date(value);
|
|
13
|
+
return dateToNumericDate(date);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ConvertCustomConfig, type PgCustomColumnBuilder } from 'drizzle-orm/pg-core';
|
|
2
|
+
type Config = {
|
|
3
|
+
data: number;
|
|
4
|
+
driverData: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const timestamp: {
|
|
7
|
+
(): PgCustomColumnBuilder<ConvertCustomConfig<"", Config>>;
|
|
8
|
+
<TName extends string>(dbName: TName): PgCustomColumnBuilder<ConvertCustomConfig<TName, Config>>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { customType } from 'drizzle-orm/pg-core';
|
|
2
|
+
export const timestamp = customType({
|
|
3
|
+
dataType() {
|
|
4
|
+
return 'timestamp with time zone';
|
|
5
|
+
},
|
|
6
|
+
toDriver(value) {
|
|
7
|
+
return new Date(value).toISOString();
|
|
8
|
+
},
|
|
9
|
+
fromDriver(value) {
|
|
10
|
+
return new Date(value).getTime();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toCamelCase, toSnakeCase } from 'drizzle-orm/casing';
|
|
2
|
-
import { boolean,
|
|
2
|
+
import { boolean, doublePrecision, index, integer, jsonb, pgSchema, text, unique, uniqueIndex, uuid } from 'drizzle-orm/pg-core';
|
|
3
3
|
import { MultiKeyMap } from '../../../data-structures/multi-key-map.js';
|
|
4
4
|
import { tryGetEnumName } from '../../../enumeration/enumeration.js';
|
|
5
5
|
import { NotSupportedError } from '../../../errors/not-supported.error.js';
|
|
@@ -17,7 +17,7 @@ import { JsonSchema } from '../../schemas/json.js';
|
|
|
17
17
|
import { NumericDateSchema } from '../../schemas/numeric-date.js';
|
|
18
18
|
import { TimestampSchema } from '../../schemas/timestamp.js';
|
|
19
19
|
import { UuidSchema } from '../../schemas/uuid.js';
|
|
20
|
-
import { bytea } from '../data-types/
|
|
20
|
+
import { bytea, numericDate, timestamp } from '../data-types/index.js';
|
|
21
21
|
import { decryptBytes, encryptBytes } from '../encryption.js';
|
|
22
22
|
const getDbSchema = memoizeSingle(pgSchema);
|
|
23
23
|
export const getDrizzleTableFromType = memoize(_getDrizzleTableFromType);
|
|
@@ -166,10 +166,10 @@ function getPostgresBaseColumn(columnName, dbSchema, schema, context) {
|
|
|
166
166
|
return column;
|
|
167
167
|
}
|
|
168
168
|
if (schema instanceof TimestampSchema) {
|
|
169
|
-
return timestamp(columnName
|
|
169
|
+
return timestamp(columnName);
|
|
170
170
|
}
|
|
171
171
|
if (schema instanceof NumericDateSchema) {
|
|
172
|
-
return
|
|
172
|
+
return numericDate(columnName);
|
|
173
173
|
}
|
|
174
174
|
if (schema instanceof NumberSchema) {
|
|
175
175
|
return schema.integer
|
|
@@ -40,7 +40,7 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
|
|
|
40
40
|
readonly session: Database | PgTransaction;
|
|
41
41
|
readonly isInTransaction: boolean;
|
|
42
42
|
readonly [resolveArgumentType]: EntityType<T>;
|
|
43
|
-
constructor(
|
|
43
|
+
constructor();
|
|
44
44
|
withOptionalTransaction(transaction: Transaction | undefined): EntityRepository<T>;
|
|
45
45
|
withTransaction(transaction: Transaction): EntityRepository<T>;
|
|
46
46
|
startTransaction(config?: TransactionConfig): Promise<Transaction>;
|
package/orm/server/repository.js
CHANGED
|
@@ -8,13 +8,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
import { count, eq, inArray, sql } from 'drizzle-orm';
|
|
15
12
|
import { PgTransaction as DrizzlePgTransaction } from 'drizzle-orm/pg-core';
|
|
13
|
+
import { createContextProvider } from '../../context/context.js';
|
|
16
14
|
import { NotFoundError } from '../../errors/not-found.error.js';
|
|
17
|
-
import {
|
|
15
|
+
import { Singleton } from '../../injector/decorators.js';
|
|
18
16
|
import { inject, injectArgument } from '../../injector/inject.js';
|
|
19
17
|
import { resolveArgumentType } from '../../injector/interfaces.js';
|
|
20
18
|
import { injectionToken } from '../../injector/token.js';
|
|
@@ -38,6 +36,7 @@ export const ENTITY_TYPE = injectionToken('EntityType');
|
|
|
38
36
|
const entityTypeToken = Symbol('EntityType');
|
|
39
37
|
const entityRepositoryConfigToken = Symbol('EntityRepositoryConfig');
|
|
40
38
|
const TRANSACTION_TIMESTAMP = sql `transaction_timestamp()`;
|
|
39
|
+
const { getCurrentEntityRepositoryContext, runInEntityRepositoryContext } = createContextProvider('EntityRepository');
|
|
41
40
|
let EntityRepository = class EntityRepository {
|
|
42
41
|
#repositoryConstructor;
|
|
43
42
|
#withTransactionCache = new WeakMap();
|
|
@@ -49,9 +48,10 @@ let EntityRepository = class EntityRepository {
|
|
|
49
48
|
columnDefinitionsMap;
|
|
50
49
|
session;
|
|
51
50
|
isInTransaction;
|
|
52
|
-
constructor(
|
|
51
|
+
constructor() {
|
|
53
52
|
this.#repositoryConstructor = new.target;
|
|
54
53
|
const entityRepositoryConfig = new.target[entityRepositoryConfigToken] ?? inject(EntityRepositoryConfig);
|
|
54
|
+
const { type, table, columnDefinitions, columnDefinitionsMap, session } = getCurrentEntityRepositoryContext() ?? {};
|
|
55
55
|
this.type = type ?? injectArgument(this, { optional: true }) ?? assertDefinedPass(new.target[entityTypeToken], 'Missing entity type.');
|
|
56
56
|
this.table = table ?? getDrizzleTableFromType(this.type, entityRepositoryConfig.schema);
|
|
57
57
|
this.columnDefinitions = columnDefinitions ?? getColumnDefinitions(this.table);
|
|
@@ -69,7 +69,14 @@ let EntityRepository = class EntityRepository {
|
|
|
69
69
|
if (this.#withTransactionCache.has(transaction)) {
|
|
70
70
|
return this.#withTransactionCache.get(transaction);
|
|
71
71
|
}
|
|
72
|
-
const
|
|
72
|
+
const context = {
|
|
73
|
+
type: this.type,
|
|
74
|
+
table: this.table,
|
|
75
|
+
columnDefinitions: this.columnDefinitions,
|
|
76
|
+
columnDefinitionsMap: this.columnDefinitionsMap,
|
|
77
|
+
session: transaction.transaction
|
|
78
|
+
};
|
|
79
|
+
const repositoryWithTransaction = runInEntityRepositoryContext(context, () => new this.#repositoryConstructor());
|
|
73
80
|
this.#withTransactionCache.set(transaction, repositoryWithTransaction);
|
|
74
81
|
return repositoryWithTransaction;
|
|
75
82
|
}
|
|
@@ -456,12 +463,7 @@ let EntityRepository = class EntityRepository {
|
|
|
456
463
|
};
|
|
457
464
|
EntityRepository = __decorate([
|
|
458
465
|
Singleton(),
|
|
459
|
-
|
|
460
|
-
__param(1, Optional()),
|
|
461
|
-
__param(2, Optional()),
|
|
462
|
-
__param(3, Optional()),
|
|
463
|
-
__param(4, Optional()),
|
|
464
|
-
__metadata("design:paramtypes", [Object, Object, Array, Map, Object])
|
|
466
|
+
__metadata("design:paramtypes", [])
|
|
465
467
|
], EntityRepository);
|
|
466
468
|
export { EntityRepository };
|
|
467
469
|
export function injectRepository(type) {
|