@tstdl/base 0.92.123 → 0.92.125
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/ai/ai-file.service.js +23 -18
- package/ai/ai.service.d.ts +4 -12
- package/ai/ai.service.js +79 -147
- package/ai/functions.d.ts +1 -1
- package/ai/types.d.ts +3 -1
- package/api/server/gateway.js +6 -6
- package/authentication/authentication.api.js +24 -24
- package/authentication/server/authentication.service.js +20 -20
- package/browser/page-controller.js +1 -1
- package/context/context.js +5 -5
- package/document-management/api/document-management.api.d.ts +60 -215
- package/document-management/api/document-management.api.js +32 -68
- package/document-management/models/document-assignment-scope.model.d.ts +11 -0
- package/document-management/models/{document-request-assignment-task-collection.model.js → document-assignment-scope.model.js} +14 -10
- package/document-management/models/document-assignment-task.model.d.ts +13 -0
- package/document-management/models/document-assignment-task.model.js +38 -0
- package/document-management/models/document-category.model.d.ts +2 -0
- package/document-management/models/document-category.model.js +7 -1
- package/document-management/models/{document-collection-document.model.d.ts → document-collection-assignment.model.d.ts} +1 -1
- package/document-management/models/{document-collection-document.model.js → document-collection-assignment.model.js} +7 -7
- package/document-management/models/document-collection.model.d.ts +2 -0
- package/document-management/models/document-collection.model.js +10 -0
- package/document-management/models/document-property-value.model.d.ts +3 -11
- package/document-management/models/document-property-value.model.js +15 -46
- package/document-management/models/document-property.model.d.ts +2 -1
- package/document-management/models/document-property.model.js +2 -2
- package/document-management/models/document-request-submission.model.d.ts +7 -0
- package/document-management/models/document-request-submission.model.js +34 -0
- package/document-management/models/document-request-template.d.ts +2 -4
- package/document-management/models/document-request-template.js +3 -8
- package/document-management/models/document-request.model.d.ts +14 -6
- package/document-management/models/document-request.model.js +22 -12
- package/document-management/models/document-type-validation.model.d.ts +6 -0
- package/document-management/models/document-type-validation.model.js +34 -0
- package/document-management/models/document-type.model.d.ts +0 -1
- package/document-management/models/document-type.model.js +0 -5
- package/document-management/models/document-validation-definition.model.d.ts +10 -0
- package/document-management/models/document-validation-definition.model.js +39 -0
- package/document-management/models/document-validation-execution-related-document.model.d.ts +7 -0
- package/document-management/models/document-validation-execution-related-document.model.js +34 -0
- package/document-management/models/document-validation-execution.model.d.ts +26 -0
- package/document-management/models/document-validation-execution.model.js +72 -0
- package/document-management/models/document-workflow.model.d.ts +35 -0
- package/document-management/models/document-workflow.model.js +70 -0
- package/document-management/models/document.model.d.ts +12 -1
- package/document-management/models/document.model.js +21 -5
- package/document-management/models/index.d.ts +10 -5
- package/document-management/models/index.js +10 -5
- package/document-management/models/service-models/categories-and-types.view-model.d.ts +3 -3
- package/document-management/models/service-models/categories-and-types.view-model.js +2 -21
- package/document-management/models/service-models/document-folders.view-model.d.ts +7 -14
- package/document-management/models/service-models/document-folders.view-model.js +20 -44
- package/document-management/models/service-models/document-management.view-model.d.ts +41 -0
- package/document-management/models/service-models/{document.view-model.js → document-management.view-model.js} +43 -26
- package/document-management/models/service-models/document.service-model.d.ts +51 -81
- package/document-management/models/service-models/document.service-model.js +30 -28
- package/document-management/models/service-models/enriched/enriched-document-assignment.view.d.ts +11 -0
- package/document-management/models/service-models/enriched/enriched-document-assignment.view.js +12 -0
- package/document-management/models/service-models/enriched/enriched-document-category.view.d.ts +13 -0
- package/document-management/models/service-models/enriched/enriched-document-category.view.js +47 -0
- package/document-management/models/service-models/enriched/enriched-document-collection.view.d.ts +22 -0
- package/document-management/models/service-models/enriched/enriched-document-collection.view.js +89 -0
- package/document-management/models/service-models/enriched/enriched-document-file.view.d.ts +12 -0
- package/document-management/models/service-models/enriched/enriched-document-file.view.js +16 -0
- package/document-management/models/service-models/enriched/enriched-document-management-data.view.d.ts +41 -0
- package/document-management/models/service-models/enriched/enriched-document-management-data.view.js +130 -0
- package/document-management/models/service-models/enriched/enriched-document-request.view.d.ts +17 -0
- package/document-management/models/service-models/enriched/enriched-document-request.view.js +52 -0
- package/document-management/models/service-models/enriched/enriched-document-type.view.d.ts +9 -0
- package/document-management/models/service-models/enriched/enriched-document-type.view.js +10 -0
- package/document-management/models/service-models/enriched/enriched-document.view.d.ts +28 -0
- package/document-management/models/service-models/enriched/enriched-document.view.js +77 -0
- package/document-management/models/service-models/enriched/enriched.d.ts +18 -0
- package/document-management/models/service-models/enriched/enriched.js +39 -0
- package/document-management/models/service-models/enriched/index.d.ts +9 -0
- package/document-management/models/service-models/enriched/index.js +9 -0
- package/document-management/models/service-models/index.d.ts +2 -2
- package/document-management/models/service-models/index.js +2 -2
- package/document-management/models/service-models/normalized-requests-template-data.model.d.ts +12 -10
- package/document-management/models/service-models/normalized-requests-template-data.model.js +5 -4
- package/document-management/models/service-models/stats.view-model.d.ts +7 -5
- package/document-management/models/service-models/stats.view-model.js +19 -9
- package/document-management/server/module.d.ts +2 -2
- package/document-management/server/module.js +3 -7
- package/document-management/server/schemas.d.ts +18 -23
- package/document-management/server/schemas.js +18 -23
- package/document-management/server/services/document-category-type.service.d.ts +25 -0
- package/document-management/server/services/document-category-type.service.js +66 -0
- package/document-management/server/services/document-collection.service.d.ts +13 -0
- package/document-management/server/services/document-collection.service.js +41 -0
- package/document-management/server/services/document-file.service.d.ts +17 -0
- package/document-management/server/services/document-file.service.js +204 -0
- package/document-management/server/services/document-management-ai.service.d.ts +22 -0
- package/document-management/server/services/document-management-ai.service.js +340 -0
- package/document-management/server/services/document-management-ancillary.service.d.ts +127 -3
- package/document-management/server/services/document-management-ancillary.service.js +24 -0
- package/document-management/server/services/document-management.service.d.ts +10 -122
- package/document-management/server/services/document-management.service.js +106 -888
- package/document-management/server/services/document-property.service.d.ts +84 -0
- package/document-management/server/services/document-property.service.js +87 -0
- package/document-management/server/services/document-request.service.d.ts +30 -0
- package/document-management/server/services/document-request.service.js +138 -0
- package/document-management/server/services/document-validation.service.d.ts +20 -0
- package/document-management/server/services/document-validation.service.js +145 -0
- package/document-management/server/services/document-workflow.service.d.ts +20 -0
- package/document-management/server/services/document-workflow.service.js +132 -0
- package/document-management/server/services/document.service.d.ts +16 -0
- package/document-management/server/services/document.service.js +81 -0
- package/document-management/server/services/index.d.ts +9 -0
- package/document-management/server/services/index.js +9 -0
- package/document-management/server/validators/ai-validation-executor.d.ts +19 -0
- package/document-management/server/validators/ai-validation-executor.js +51 -0
- package/document-management/server/validators/index.d.ts +2 -0
- package/document-management/server/validators/index.js +2 -0
- package/document-management/server/validators/single-document-validation-executor.d.ts +16 -0
- package/document-management/server/validators/single-document-validation-executor.js +20 -0
- package/document-management/server/validators/validator.d.ts +21 -0
- package/document-management/server/validators/validator.js +2 -0
- package/eslint.config.js +31 -17
- package/examples/document-management/main.d.ts +18 -3
- package/examples/document-management/main.js +28 -12
- package/file/mime-type.js +2 -9
- package/formats.d.ts +5 -2
- package/formats.js +32 -23
- package/http/client/http-client.js +1 -1
- package/injector/injector.js +2 -2
- package/object-storage/s3/s3.object-storage.js +1 -1
- package/orm/data-types/bytea.d.ts +8 -0
- package/orm/data-types/bytea.js +8 -0
- package/orm/data-types/index.d.ts +4 -0
- package/orm/data-types/index.js +4 -0
- package/orm/data-types/numeric-date.d.ts +9 -0
- package/orm/data-types/numeric-date.js +9 -0
- package/orm/data-types/timestamp.d.ts +9 -0
- package/orm/data-types/timestamp.js +9 -0
- package/orm/decorators.d.ts +139 -5
- package/orm/decorators.js +50 -0
- package/orm/entity.d.ts +19 -0
- package/orm/entity.js +19 -0
- package/orm/index.d.ts +5 -0
- package/orm/index.js +5 -0
- package/orm/query.d.ts +51 -0
- package/orm/query.js +6 -0
- package/orm/repository.types.d.ts +54 -2
- package/orm/server/database-schema.d.ts +34 -0
- package/orm/server/database-schema.js +29 -0
- package/orm/server/database.d.ts +19 -1
- package/orm/server/database.js +17 -3
- package/orm/server/drizzle/schema-converter.d.ts +2 -1
- package/orm/server/drizzle/schema-converter.js +12 -1
- package/orm/server/encryption.d.ts +16 -0
- package/orm/server/encryption.js +29 -4
- package/orm/server/index.d.ts +7 -0
- package/orm/server/index.js +7 -0
- package/orm/server/module.d.ts +20 -0
- package/orm/server/module.js +9 -0
- package/orm/server/query-converter.d.ts +17 -0
- package/orm/server/query-converter.js +66 -11
- package/orm/server/repository.d.ts +324 -18
- package/orm/server/repository.js +344 -73
- package/orm/server/transaction.d.ts +5 -5
- package/orm/server/transaction.js +5 -5
- package/orm/server/transactional.d.ts +75 -0
- package/orm/server/transactional.js +134 -0
- package/orm/server/types.d.ts +1 -0
- package/orm/sqls.d.ts +55 -0
- package/orm/sqls.js +60 -0
- package/orm/types.d.ts +67 -4
- package/orm/utils.d.ts +19 -3
- package/orm/utils.js +12 -0
- package/package.json +32 -31
- package/password/password-check-result.model.d.ts +9 -7
- package/password/password-check-result.model.js +8 -8
- package/password/password-check.js +5 -7
- package/password/password-check.localization.js +12 -12
- package/pdf/pdf.service.js +1 -1
- package/pdf/utils.d.ts +9 -0
- package/pdf/utils.js +19 -2
- package/process/spawn.d.ts +11 -4
- package/process/spawn.js +42 -5
- package/queue/postgres/queue.js +5 -5
- package/queue/queue.d.ts +6 -4
- package/queue/queue.js +6 -6
- package/schema/schemas/one-or-many.d.ts +2 -1
- package/schema/schemas/one-or-many.js +1 -1
- package/search-index/elastic/model/index-mapping.d.ts +1 -1
- package/search-index/elastic/model/index-mapping.js +0 -1
- package/search-index/elastic/search-index.d.ts +1 -2
- package/search-index/elastic/search-index.js +3 -3
- package/types.d.ts +1 -0
- package/utils/async-hook/async-hook.d.ts +9 -0
- package/utils/async-hook/async-hook.js +21 -0
- package/utils/async-hook/index.d.ts +1 -0
- package/utils/async-hook/index.js +1 -0
- package/utils/compression.js +1 -1
- package/utils/function/class.d.ts +6 -0
- package/utils/function/class.js +9 -0
- package/utils/function/index.d.ts +1 -0
- package/utils/function/index.js +1 -0
- package/utils/function/memoize.d.ts +18 -0
- package/utils/function/memoize.js +41 -2
- package/utils/jwt.d.ts +1 -1
- package/utils/jwt.js +5 -5
- package/utils/object/forward-ref.d.ts +3 -2
- package/utils/object/forward-ref.js +12 -12
- package/utils/object/lazy-property.js +2 -2
- package/utils/proxy.js +1 -1
- package/utils/stream/{readable-stream-from-promise.d.ts → from-promise.d.ts} +1 -0
- package/utils/stream/from-promise.js +27 -0
- package/utils/stream/index.d.ts +1 -1
- package/utils/stream/index.js +1 -1
- package/utils/stream/stream-reader.js +71 -31
- package/document-management/models/document-request-assignment-task-collection.model.d.ts +0 -7
- package/document-management/models/document-request-assignment-task.model.d.ts +0 -14
- package/document-management/models/document-request-assignment-task.model.js +0 -77
- package/document-management/models/document-request-file.model.d.ts +0 -16
- package/document-management/models/document-request-file.model.js +0 -86
- package/document-management/models/service-models/document.view-model.d.ts +0 -41
- package/document-management/models/service-models/normalized-document-collection-view.model.d.ts +0 -73
- package/document-management/models/service-models/normalized-document-collection-view.model.js +0 -110
- package/utils/stream/readable-stream-from-promise.js +0 -8
package/orm/entity.js
CHANGED
|
@@ -7,15 +7,26 @@ 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
|
+
/**
|
|
11
|
+
* @module
|
|
12
|
+
* Defines base entity classes and related types for the ORM.
|
|
13
|
+
*/
|
|
10
14
|
import { Defaulted, Integer } from '../schema/index.js';
|
|
11
15
|
import { PrimaryKey } from './decorators.js';
|
|
12
16
|
import { Embedded, Json, Timestamp, Uuid } from './types.js';
|
|
17
|
+
/**
|
|
18
|
+
* Base class for extensible metadata attributes associated with an entity.
|
|
19
|
+
* Allows storing arbitrary key-value pairs.
|
|
20
|
+
*/
|
|
13
21
|
let EntityMetadataAttributes = class EntityMetadataAttributes {
|
|
14
22
|
};
|
|
15
23
|
EntityMetadataAttributes = __decorate([
|
|
16
24
|
Json()
|
|
17
25
|
], EntityMetadataAttributes);
|
|
18
26
|
export { EntityMetadataAttributes };
|
|
27
|
+
/**
|
|
28
|
+
* Base class defining common metadata fields for entities, such as revision tracking and timestamps.
|
|
29
|
+
*/
|
|
19
30
|
export class EntityMetadata {
|
|
20
31
|
revision;
|
|
21
32
|
revisionTimestamp;
|
|
@@ -43,6 +54,10 @@ __decorate([
|
|
|
43
54
|
Defaulted(EntityMetadataAttributes, {}),
|
|
44
55
|
__metadata("design:type", Object)
|
|
45
56
|
], EntityMetadata.prototype, "attributes", void 0);
|
|
57
|
+
/**
|
|
58
|
+
* Abstract base class for entities that include standard metadata.
|
|
59
|
+
* Provides a default `id` (UUID primary key) and an `metadata` field.
|
|
60
|
+
*/
|
|
46
61
|
export class Entity {
|
|
47
62
|
id;
|
|
48
63
|
metadata;
|
|
@@ -56,6 +71,10 @@ __decorate([
|
|
|
56
71
|
Embedded(EntityMetadata, { prefix: null }),
|
|
57
72
|
__metadata("design:type", Object)
|
|
58
73
|
], Entity.prototype, "metadata", void 0);
|
|
74
|
+
/**
|
|
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.
|
|
77
|
+
*/
|
|
59
78
|
export class EntityWithoutMetadata {
|
|
60
79
|
id;
|
|
61
80
|
}
|
package/orm/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Barrel file exporting core ORM functionalities including data types,
|
|
4
|
+
* base entities, query types, repository types, SQL helpers, and utility types.
|
|
5
|
+
*/
|
|
1
6
|
export * from './data-types/index.js';
|
|
2
7
|
export * from './entity.js';
|
|
3
8
|
export * from './query.js';
|
package/orm/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Barrel file exporting core ORM functionalities including data types,
|
|
4
|
+
* base entities, query types, repository types, SQL helpers, and utility types.
|
|
5
|
+
*/
|
|
1
6
|
export * from './data-types/index.js';
|
|
2
7
|
export * from './entity.js';
|
|
3
8
|
export * from './query.js';
|
package/orm/query.d.ts
CHANGED
|
@@ -1,92 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Defines types for constructing database queries using a MongoDB-like syntax.
|
|
4
|
+
* Supports logical operators, comparison operators, and specialized queries like text search and geospatial queries.
|
|
5
|
+
*/
|
|
1
6
|
import type { SQLWrapper } from 'drizzle-orm';
|
|
2
7
|
import type { Flatten, Record } from '../types.js';
|
|
3
8
|
import type { Geometry } from '../types/geo-json.js';
|
|
4
9
|
import type { UntaggedDeep } from '../types/tagged.js';
|
|
10
|
+
/** Represents a logical query combining multiple sub-queries (e.g., $and, $or, $nor). */
|
|
5
11
|
export type LogicalQuery<T = any> = LogicalAndQuery<T> | LogicalOrQuery<T> | LogicalNorQuery<T>;
|
|
12
|
+
/** Union of keys representing logical query operators ('$and', '$or', '$nor'). */
|
|
6
13
|
export type LogicalQueryTypes = keyof (LogicalAndQuery & LogicalOrQuery & LogicalNorQuery);
|
|
14
|
+
/** Array containing all valid logical query operator keys. */
|
|
7
15
|
export declare const allLogicalQueryTypes: LogicalQueryTypes[];
|
|
16
|
+
/** Represents the body of a comparison query, mapping field paths to comparison operators or values. Allows nested structures. */
|
|
8
17
|
export type ComparisonQueryBody<T = any> = {
|
|
9
18
|
[P in keyof T]?: T[P] extends Record ? ComparisonQueryBody<T[P]> : ComparisonQueryOrValue<T[P]>;
|
|
10
19
|
} & Record<ComparisonQueryOrValue>;
|
|
20
|
+
/** Represents either a full comparison query object or a direct value for equality comparison. */
|
|
11
21
|
export type ComparisonQueryOrValue<T = any> = ComparisonQuery<T> | ComparisonValue<T>;
|
|
22
|
+
/** Represents a comparison query using various operators like $eq, $ne, $gt, $in, etc. */
|
|
12
23
|
export type ComparisonQuery<T = any> = Partial<ComparisonNotQuery<T> & ComparisonEqualsQuery<T> & ComparisonNotEqualsQuery<T> & ComparisonExistsQuery & ComparisonItemQuery<T> & ComparisonInQuery<T> & ComparisonNotInQuery<T> & ComparisonAllQuery<T> & ComparisonGreaterThanQuery<T> & ComparisonGreaterThanOrEqualsQuery<T> & ComparisonLessThanQuery<T> & ComparisonLessThanOrEqualsQuery<T> & ComparisonRegexQuery & ComparisonTextQuery & ComparisonGeoShapeQuery & ComparisonGeoDistanceQuery>;
|
|
24
|
+
/** Union of keys representing comparison query operators. */
|
|
13
25
|
export type ComparisonQueryTypes = keyof ComparisonQuery;
|
|
26
|
+
/** Array containing all valid comparison query operator keys. */
|
|
14
27
|
export declare const allComparisonQueryTypes: ComparisonQueryTypes[];
|
|
28
|
+
/** Represents specialized query types beyond simple comparisons (e.g., $textSpan). */
|
|
15
29
|
export type SpecialQuery<T = any> = Partial<TextSpanQuery<T>>;
|
|
30
|
+
/** Union of keys representing special query operators. */
|
|
16
31
|
export type SpecialQueryTypes = keyof SpecialQuery;
|
|
32
|
+
/** Array containing all valid special query operator keys. */
|
|
17
33
|
export declare const allSpecialQueryTypes: SpecialQueryTypes[];
|
|
34
|
+
/**
|
|
35
|
+
* Represents a complete query, which can be either a raw Drizzle SQLWrapper
|
|
36
|
+
* or a structured query object using logical and comparison operators.
|
|
37
|
+
* @template T - The type of the entity being queried.
|
|
38
|
+
*/
|
|
18
39
|
export type Query<T = any> = SQLWrapper | QueryObject<UntaggedDeep<T>>;
|
|
40
|
+
/** Represents a structured query object, combining logical, comparison, and special queries. */
|
|
19
41
|
export type QueryObject<T> = LogicalQuery<T> | (ComparisonQueryBody<T> & SpecialQuery<T>);
|
|
42
|
+
/** Union of all possible query operator keys (logical, comparison, special). */
|
|
20
43
|
export type QueryTypes = LogicalQueryTypes | ComparisonQueryTypes | SpecialQueryTypes;
|
|
44
|
+
/** Array containing all valid query operator keys. */
|
|
21
45
|
export declare const allQueryTypes: ("$and" | "$or" | "$nor" | "$not" | "$eq" | "$neq" | "$exists" | "$item" | "$in" | "$nin" | "$all" | "$gt" | "$gte" | "$lt" | "$lte" | "$regex" | "$text" | "$geoShape" | "$geoDistance" | "$textSpan")[];
|
|
46
|
+
/** Logical operators used within certain query types like $text. */
|
|
22
47
|
export type Operator = 'and' | 'or';
|
|
48
|
+
/** Array containing all valid logical operators ('and', 'or'). */
|
|
23
49
|
export declare const allOperators: Operator[];
|
|
50
|
+
/** Represents an AND logical query. All sub-queries must be true. */
|
|
24
51
|
export type LogicalAndQuery<T = any> = {
|
|
25
52
|
$and: readonly Query<T>[];
|
|
26
53
|
};
|
|
54
|
+
/** Represents an OR logical query. At least one sub-query must be true. */
|
|
27
55
|
export type LogicalOrQuery<T = any> = {
|
|
28
56
|
$or: readonly Query<T>[];
|
|
29
57
|
};
|
|
58
|
+
/** Represents a NOR logical query. All sub-queries must be false. */
|
|
30
59
|
export type LogicalNorQuery<T = any> = {
|
|
31
60
|
$nor: readonly Query<T>[];
|
|
32
61
|
};
|
|
62
|
+
/** Represents a value used in comparisons, can be a direct value, a flattened value, or a Drizzle SQLWrapper. */
|
|
33
63
|
export type ComparisonValue<T> = T | Flatten<T> | SQLWrapper;
|
|
64
|
+
/** Represents a comparison value that can also include a RegExp for string comparisons. */
|
|
34
65
|
export type ComparisonValueWithRegex<T> = T extends string ? ComparisonValue<T | RegExp> : T extends readonly string[] ? ComparisonValue<readonly (Flatten<T> | RegExp)[]> : (T | Flatten<T>);
|
|
66
|
+
/** Represents a NOT comparison query. Inverts the result of the nested comparison. */
|
|
35
67
|
export type ComparisonNotQuery<T = any> = {
|
|
36
68
|
$not: ComparisonQuery<T>;
|
|
37
69
|
};
|
|
70
|
+
/** Represents an equality comparison query ($eq). */
|
|
38
71
|
export type ComparisonEqualsQuery<T = any> = {
|
|
39
72
|
$eq: ComparisonValueWithRegex<T>;
|
|
40
73
|
};
|
|
74
|
+
/** Represents a non-equality comparison query ($neq). */
|
|
41
75
|
export type ComparisonNotEqualsQuery<T = any> = {
|
|
42
76
|
$neq: ComparisonValueWithRegex<T>;
|
|
43
77
|
};
|
|
78
|
+
/** Represents an existence check query ($exists). Checks if a field exists (or not). */
|
|
44
79
|
export type ComparisonExistsQuery = {
|
|
45
80
|
$exists: ComparisonValue<boolean>;
|
|
46
81
|
};
|
|
82
|
+
/** Represents a query targeting elements within an array field ($item). */
|
|
47
83
|
export type ComparisonItemQuery<T = any> = {
|
|
48
84
|
$item: T extends readonly (infer U)[] ? U extends Record ? Query<U> : ComparisonQuery<U> : never;
|
|
49
85
|
};
|
|
86
|
+
/** Represents an "in list" comparison query ($in). Checks if a field value is within a specified array. */
|
|
50
87
|
export type ComparisonInQuery<T = any> = {
|
|
51
88
|
$in: readonly ComparisonValueWithRegex<T>[];
|
|
52
89
|
};
|
|
90
|
+
/** Represents a "not in list" comparison query ($nin). Checks if a field value is not within a specified array. */
|
|
53
91
|
export type ComparisonNotInQuery<T = any> = {
|
|
54
92
|
$nin: readonly ComparisonValueWithRegex<T>[];
|
|
55
93
|
};
|
|
94
|
+
/** Represents an "all elements match" query ($all). Checks if an array field contains all specified values. */
|
|
56
95
|
export type ComparisonAllQuery<T = any> = {
|
|
57
96
|
$all: readonly ComparisonValueWithRegex<T>[];
|
|
58
97
|
};
|
|
98
|
+
/** Represents a "greater than" comparison query ($gt). */
|
|
59
99
|
export type ComparisonGreaterThanQuery<T = any> = {
|
|
60
100
|
$gt: ComparisonValue<T>;
|
|
61
101
|
};
|
|
102
|
+
/** Represents a "greater than or equals" comparison query ($gte). */
|
|
62
103
|
export type ComparisonGreaterThanOrEqualsQuery<T = any> = {
|
|
63
104
|
$gte: ComparisonValue<T>;
|
|
64
105
|
};
|
|
106
|
+
/** Represents a "less than" comparison query ($lt). */
|
|
65
107
|
export type ComparisonLessThanQuery<T = any> = {
|
|
66
108
|
$lt: ComparisonValue<T>;
|
|
67
109
|
};
|
|
110
|
+
/** Represents a "less than or equals" comparison query ($lte). */
|
|
68
111
|
export type ComparisonLessThanOrEqualsQuery<T = any> = {
|
|
69
112
|
$lte: ComparisonValue<T>;
|
|
70
113
|
};
|
|
114
|
+
/** Represents a regular expression comparison query ($regex). */
|
|
71
115
|
export type ComparisonRegexQuery = {
|
|
72
116
|
$regex: string | RegExp | {
|
|
73
117
|
pattern: string;
|
|
74
118
|
flags: string;
|
|
75
119
|
};
|
|
76
120
|
};
|
|
121
|
+
/** Represents a full-text search query ($text). */
|
|
77
122
|
export type ComparisonTextQuery = {
|
|
78
123
|
$text: string | {
|
|
79
124
|
text: string;
|
|
80
125
|
operator?: Operator;
|
|
81
126
|
};
|
|
82
127
|
};
|
|
128
|
+
/** Defines the possible spatial relationships for geospatial shape queries. */
|
|
83
129
|
export type GeoShapeRelation = 'intersects' | 'within' | 'disjoint' | 'contains';
|
|
130
|
+
/** Represents a geospatial query based on shape relationships ($geoShape). */
|
|
84
131
|
export type ComparisonGeoShapeQuery = {
|
|
85
132
|
$geoShape: {
|
|
86
133
|
geometry: Geometry;
|
|
87
134
|
relation: GeoShapeRelation;
|
|
88
135
|
};
|
|
89
136
|
};
|
|
137
|
+
/** Represents a geospatial query based on distance from a point ($geoDistance). */
|
|
90
138
|
export type ComparisonGeoDistanceQuery = {
|
|
91
139
|
$geoDistance: {
|
|
92
140
|
longitude: number;
|
|
@@ -101,8 +149,11 @@ export type ComparisonGeoDistanceQuery = {
|
|
|
101
149
|
minDistance?: number;
|
|
102
150
|
};
|
|
103
151
|
};
|
|
152
|
+
/** Defines the modes for text span queries, affecting how multiple field matches are handled. */
|
|
104
153
|
export type TextSpanQueryMode = 'best' | 'most' | 'cross';
|
|
154
|
+
/** Array containing all valid text span query modes. */
|
|
105
155
|
export declare const allTextSpanQueryModes: TextSpanQueryMode[];
|
|
156
|
+
/** Represents a text span query ($textSpan), searching for text across multiple fields. */
|
|
106
157
|
export type TextSpanQuery<T = any> = {
|
|
107
158
|
$textSpan: {
|
|
108
159
|
fields: readonly (Extract<keyof T, string>)[];
|
package/orm/query.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
/** Array containing all valid logical query operator keys. */
|
|
1
2
|
export const allLogicalQueryTypes = ['$and', '$or', '$nor'];
|
|
3
|
+
/** Array containing all valid comparison query operator keys. */
|
|
2
4
|
export const allComparisonQueryTypes = ['$all', '$not', '$eq', '$exists', '$gt', '$gte', '$in', '$item', '$lt', '$lte', '$neq', '$nin', '$regex', '$text', '$geoDistance', '$geoShape'];
|
|
5
|
+
/** Array containing all valid special query operator keys. */
|
|
3
6
|
export const allSpecialQueryTypes = ['$textSpan'];
|
|
7
|
+
/** Array containing all valid query operator keys. */
|
|
4
8
|
export const allQueryTypes = [...allLogicalQueryTypes, ...allComparisonQueryTypes, ...allSpecialQueryTypes];
|
|
9
|
+
/** Array containing all valid logical operators ('and', 'or'). */
|
|
5
10
|
export const allOperators = ['and', 'or'];
|
|
11
|
+
/** Array containing all valid text span query modes. */
|
|
6
12
|
export const allTextSpanQueryModes = ['best', 'most', 'cross'];
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Defines types used by ORM repositories for operations like loading, updating, and creating entities.
|
|
4
|
+
* Includes types for ordering, loading options, and entity data structures for create/update operations.
|
|
5
|
+
*/
|
|
1
6
|
import type { Paths, Record, TypedOmit } from '../types.js';
|
|
2
7
|
import type { UntaggedDeep } from '../types/tagged.js';
|
|
3
8
|
import type { SQL, SQLWrapper } from 'drizzle-orm';
|
|
@@ -6,26 +11,73 @@ import type { Entity, EntityMetadata, EntityWithoutMetadata } from './entity.js'
|
|
|
6
11
|
type WithSql<T> = {
|
|
7
12
|
[P in keyof T]: T[P] extends Record ? WithSql<T[P]> : (T[P] | SQL);
|
|
8
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Specifies the target column (e.g. for ordering, distinct on), which can be a property path within the entity
|
|
16
|
+
* or a raw Drizzle SQLWrapper for a complex target.
|
|
17
|
+
* @template T - The entity type.
|
|
18
|
+
*/
|
|
19
|
+
export type TargetColumnPaths<T extends EntityWithoutMetadata> = Paths<UntaggedDeep<T>>;
|
|
20
|
+
/**
|
|
21
|
+
* Specifies the target column (e.g. for ordering, distinct on), which can be a property path within the entity
|
|
22
|
+
* or a raw Drizzle SQLWrapper for a complex target.
|
|
23
|
+
* @template T - The entity type.
|
|
24
|
+
*/
|
|
25
|
+
export type TargetColumn<T extends EntityWithoutMetadata> = TargetColumnPaths<T> | SQLWrapper;
|
|
26
|
+
/** Specifies the direction for ordering results ('asc' or 'desc'). */
|
|
9
27
|
export type OrderDirection = 'asc' | 'desc';
|
|
10
|
-
|
|
11
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Defines how results should be ordered. Can be a single target, an array of targets
|
|
30
|
+
* (optionally with direction), or an object mapping property paths to directions.
|
|
31
|
+
* @template T - The entity type.
|
|
32
|
+
*/
|
|
33
|
+
export type Order<T extends EntityWithoutMetadata> = TargetColumn<T> | (TargetColumn<T> | [TargetColumn<T>, OrderDirection])[] | Partial<Record<Exclude<TargetColumn<T>, SQLWrapper>, OrderDirection>>;
|
|
34
|
+
/**
|
|
35
|
+
* Options object containing ordering configuration.
|
|
36
|
+
* @template T - The entity type.
|
|
37
|
+
*/
|
|
12
38
|
export type OrderOptions<T extends EntityWithoutMetadata> = {
|
|
13
39
|
order?: Order<T>;
|
|
14
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Options for loading a single entity, including ordering and offset.
|
|
43
|
+
* @template T - The entity type.
|
|
44
|
+
*/
|
|
15
45
|
export type LoadOptions<T extends EntityWithoutMetadata> = OrderOptions<T> & {
|
|
16
46
|
offset?: number;
|
|
17
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Options for loading multiple entities, including ordering, offset, and limit.
|
|
50
|
+
* @template T - The entity type.
|
|
51
|
+
*/
|
|
18
52
|
export type LoadManyOptions<T extends EntityWithoutMetadata> = LoadOptions<T> & {
|
|
19
53
|
limit?: number;
|
|
54
|
+
distinct?: boolean | TargetColumn<T>[];
|
|
20
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Options for update operations (currently inherits from LoadOptions, primarily for ordering).
|
|
58
|
+
* @template T - The entity type.
|
|
59
|
+
*/
|
|
21
60
|
export type UpdateOptions<T extends EntityWithoutMetadata> = LoadOptions<T>;
|
|
61
|
+
/** Type definition for updating entity metadata attributes, allowing partial updates and SQL expressions. */
|
|
22
62
|
export type EntityMetadataUpdate = WithSql<Partial<UntaggedDeep<Pick<EntityMetadata, 'attributes'>>>>;
|
|
63
|
+
/**
|
|
64
|
+
* Represents the data structure for creating a new entity.
|
|
65
|
+
* Excludes 'id' and 'metadata' by default, but allows providing an optional 'id' and partial 'metadata.attributes'.
|
|
66
|
+
* Allows SQL expressions for values.
|
|
67
|
+
* @template T - The entity type.
|
|
68
|
+
*/
|
|
23
69
|
export type NewEntity<T extends Entity | EntityWithoutMetadata> = T extends Entity ? WithSql<UntaggedDeep<TypedOmit<T, 'id' | 'metadata'> & {
|
|
24
70
|
id?: string;
|
|
25
71
|
metadata?: Partial<Pick<EntityMetadata, 'attributes'>>;
|
|
26
72
|
}>> : WithSql<UntaggedDeep<TypedOmit<T, 'id'> & {
|
|
27
73
|
id?: string;
|
|
28
74
|
}>>;
|
|
75
|
+
/**
|
|
76
|
+
* Represents the data structure for updating an existing entity.
|
|
77
|
+
* Allows partial updates for all properties (using PartialDeep) and specific updates for 'metadata.attributes'.
|
|
78
|
+
* Allows SQL expressions for values.
|
|
79
|
+
* @template T - The entity type.
|
|
80
|
+
*/
|
|
29
81
|
export type EntityUpdate<T extends EntityWithoutMetadata> = T extends Entity ? WithSql<PartialDeep<UntaggedDeep<TypedOmit<T, 'metadata'>>>> & {
|
|
30
82
|
metadata?: EntityMetadataUpdate;
|
|
31
83
|
} : WithSql<PartialDeep<UntaggedDeep<T>>>;
|
|
@@ -1,11 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Provides utilities for defining and accessing database schemas, tables, and enums
|
|
4
|
+
* within a specific PostgreSQL schema.
|
|
5
|
+
*/
|
|
1
6
|
import type { PgEnum } from 'drizzle-orm/pg-core';
|
|
2
7
|
import type { Enumeration, EnumerationValue, UnionToTuple } from '../../types.js';
|
|
3
8
|
import type { EntityType } from '../entity.js';
|
|
4
9
|
import type { PgTableFromType } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Represents a database schema, providing methods to access tables and enums within that schema.
|
|
12
|
+
* @template SchemaName The name of the PostgreSQL schema.
|
|
13
|
+
*/
|
|
5
14
|
export declare class DatabaseSchema<SchemaName extends string> {
|
|
15
|
+
/** The name of the PostgreSQL schema. */
|
|
6
16
|
readonly name: SchemaName;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of DatabaseSchema.
|
|
19
|
+
* @param name The name of the PostgreSQL schema.
|
|
20
|
+
*/
|
|
7
21
|
constructor(name: SchemaName);
|
|
22
|
+
/**
|
|
23
|
+
* Gets the Drizzle table object corresponding to the given entity type within this schema.
|
|
24
|
+
* @template T The entity type.
|
|
25
|
+
* @param type The entity class.
|
|
26
|
+
* @returns The Drizzle table object.
|
|
27
|
+
*/
|
|
8
28
|
getTable<T extends EntityType>(type: T): PgTableFromType<T, SchemaName>;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the Drizzle enum object corresponding to the given enumeration within this schema.
|
|
31
|
+
* If a name is provided, it registers the enum with that name first.
|
|
32
|
+
* @template T The enumeration type.
|
|
33
|
+
* @param enumeration The enumeration object.
|
|
34
|
+
* @param name Optional name to register the enum with.
|
|
35
|
+
* @returns The Drizzle enum object.
|
|
36
|
+
*/
|
|
9
37
|
getEnum<T extends Enumeration>(enumeration: T, name?: string): PgEnum<UnionToTuple<`${EnumerationValue<T>}`> extends [string, ...string[]] ? UnionToTuple<`${EnumerationValue<T>}`> : never>;
|
|
10
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Factory function to create a DatabaseSchema instance.
|
|
41
|
+
* @template Name The name of the PostgreSQL schema.
|
|
42
|
+
* @param name The name of the PostgreSQL schema.
|
|
43
|
+
* @returns A new DatabaseSchema instance.
|
|
44
|
+
*/
|
|
11
45
|
export declare function databaseSchema<Name extends string>(name: Name): DatabaseSchema<Name>;
|
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import { isDefined } from '../../utils/type-guards.js';
|
|
2
2
|
import { getDrizzleTableFromType, getPgEnum, registerEnum } from './drizzle/schema-converter.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a database schema, providing methods to access tables and enums within that schema.
|
|
5
|
+
* @template SchemaName The name of the PostgreSQL schema.
|
|
6
|
+
*/
|
|
3
7
|
export class DatabaseSchema {
|
|
8
|
+
/** The name of the PostgreSQL schema. */
|
|
4
9
|
name;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of DatabaseSchema.
|
|
12
|
+
* @param name The name of the PostgreSQL schema.
|
|
13
|
+
*/
|
|
5
14
|
constructor(name) {
|
|
6
15
|
this.name = name;
|
|
7
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Gets the Drizzle table object corresponding to the given entity type within this schema.
|
|
19
|
+
* @template T The entity type.
|
|
20
|
+
* @param type The entity class.
|
|
21
|
+
* @returns The Drizzle table object.
|
|
22
|
+
*/
|
|
8
23
|
getTable(type) {
|
|
9
24
|
return getDrizzleTableFromType(type, this.name);
|
|
10
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets the Drizzle enum object corresponding to the given enumeration within this schema.
|
|
28
|
+
* If a name is provided, it registers the enum with that name first.
|
|
29
|
+
* @template T The enumeration type.
|
|
30
|
+
* @param enumeration The enumeration object.
|
|
31
|
+
* @param name Optional name to register the enum with.
|
|
32
|
+
* @returns The Drizzle enum object.
|
|
33
|
+
*/
|
|
11
34
|
getEnum(enumeration, name) {
|
|
12
35
|
if (isDefined(name)) {
|
|
13
36
|
registerEnum(enumeration, name);
|
|
@@ -15,6 +38,12 @@ export class DatabaseSchema {
|
|
|
15
38
|
return getPgEnum(this.name, enumeration); // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
16
39
|
}
|
|
17
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Factory function to create a DatabaseSchema instance.
|
|
43
|
+
* @template Name The name of the PostgreSQL schema.
|
|
44
|
+
* @param name The name of the PostgreSQL schema.
|
|
45
|
+
* @returns A new DatabaseSchema instance.
|
|
46
|
+
*/
|
|
18
47
|
export function databaseSchema(name) {
|
|
19
48
|
return new DatabaseSchema(name);
|
|
20
49
|
}
|
package/orm/server/database.d.ts
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Provides the core database connection and migration functionality using Drizzle ORM and node-postgres.
|
|
4
|
+
* It sets up the dependency injection for the database instance.
|
|
5
|
+
*/
|
|
1
6
|
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
7
|
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
3
|
-
import type
|
|
8
|
+
import { type PoolConfig } from 'pg';
|
|
4
9
|
import type { Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
|
|
10
|
+
/**
|
|
11
|
+
* Type alias for the argument required to resolve a Database instance via the injector.
|
|
12
|
+
* Represents the PostgreSQL pool configuration.
|
|
13
|
+
*/
|
|
5
14
|
export type DatabaseArgument = PoolConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Represents the application's database connection.
|
|
17
|
+
* Extends Drizzle's `NodePgDatabase` and integrates with the dependency injection system.
|
|
18
|
+
* Can be resolved using a `PoolConfig` argument.
|
|
19
|
+
*/
|
|
6
20
|
export declare class Database extends NodePgDatabase<any> implements Resolvable<DatabaseArgument> {
|
|
7
21
|
readonly [resolveArgumentType]?: DatabaseArgument;
|
|
8
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Re-exports the `migrate` function from `drizzle-orm/node-postgres/migrator`
|
|
25
|
+
* for running database migrations.
|
|
26
|
+
*/
|
|
9
27
|
export { migrate };
|
package/orm/server/database.js
CHANGED
|
@@ -4,12 +4,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* @module
|
|
9
|
+
* Provides the core database connection and migration functionality using Drizzle ORM and node-postgres.
|
|
10
|
+
* It sets up the dependency injection for the database instance.
|
|
11
|
+
*/
|
|
7
12
|
import { drizzle, NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
8
13
|
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
9
|
-
import
|
|
14
|
+
import { Pool } from 'pg';
|
|
10
15
|
import { inject, Injector, ReplaceClass } from '../../injector/index.js';
|
|
11
16
|
import { isUndefined } from '../../utils/type-guards.js';
|
|
12
17
|
import { DatabaseConfig } from './module.js';
|
|
18
|
+
/**
|
|
19
|
+
* Represents the application's database connection.
|
|
20
|
+
* Extends Drizzle's `NodePgDatabase` and integrates with the dependency injection system.
|
|
21
|
+
* Can be resolved using a `PoolConfig` argument.
|
|
22
|
+
*/
|
|
13
23
|
let Database = class Database extends NodePgDatabase {
|
|
14
24
|
};
|
|
15
25
|
Database = __decorate([
|
|
@@ -22,9 +32,13 @@ Injector.registerSingleton(Database, {
|
|
|
22
32
|
if (isUndefined(connection)) {
|
|
23
33
|
throw new Error('Missing postgres connection. Provide it either via injection argument or a provider for DatabaseConfig.');
|
|
24
34
|
}
|
|
25
|
-
const pool = new
|
|
35
|
+
const pool = new Pool(connection);
|
|
26
36
|
context.addDisposeHandler(async () => pool.end());
|
|
27
37
|
return drizzle(pool);
|
|
28
|
-
}
|
|
38
|
+
},
|
|
29
39
|
});
|
|
40
|
+
/**
|
|
41
|
+
* Re-exports the `migrate` function from `drizzle-orm/node-postgres/migrator`
|
|
42
|
+
* for running database migrations.
|
|
43
|
+
*/
|
|
30
44
|
export { migrate };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type PgEnum, type PgSchema, type PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
2
2
|
import type { AbstractConstructor, Enumeration } from '../../../types.js';
|
|
3
3
|
import type { EntityType } from '../../entity.js';
|
|
4
|
-
import type { ColumnDefinition, PgTableFromType } from '../types.js';
|
|
4
|
+
import type { ColumnDefinition, ColumnDefinitionsMap, PgTableFromType } from '../types.js';
|
|
5
5
|
type ConverterContext = {
|
|
6
6
|
type: AbstractConstructor;
|
|
7
7
|
property: string;
|
|
8
8
|
};
|
|
9
9
|
export declare const getDrizzleTableFromType: typeof _getDrizzleTableFromType;
|
|
10
10
|
export declare function getColumnDefinitions(table: PgTableWithColumns<any>): ColumnDefinition[];
|
|
11
|
+
export declare function getColumnDefinitionsMap(table: PgTableWithColumns<any>): ColumnDefinitionsMap;
|
|
11
12
|
export declare function _getDrizzleTableFromType<T extends EntityType, S extends string>(type: T, fallbackSchemaName?: S): PgTableFromType<T, S>;
|
|
12
13
|
export declare function registerEnum(enumeration: Enumeration, name: string): void;
|
|
13
14
|
export declare function getPgEnum(schema: string | PgSchema, enumeration: Enumeration, context?: ConverterContext): PgEnum<[string, ...string[]]>;
|
|
@@ -19,12 +19,17 @@ import { NumericDateSchema } from '../../schemas/numeric-date.js';
|
|
|
19
19
|
import { TimestampSchema } from '../../schemas/timestamp.js';
|
|
20
20
|
import { UuidSchema } from '../../schemas/uuid.js';
|
|
21
21
|
import { decryptBytes, encryptBytes } from '../encryption.js';
|
|
22
|
+
import { convertQuery } from '../query-converter.js';
|
|
22
23
|
const getDbSchema = memoizeSingle(pgSchema);
|
|
23
24
|
export const getDrizzleTableFromType = memoize(_getDrizzleTableFromType);
|
|
24
25
|
const columnDefinitionsSymbol = Symbol('columnDefinitions');
|
|
26
|
+
const columnDefinitionsMapSymbol = Symbol('columnDefinitionsMap');
|
|
25
27
|
export function getColumnDefinitions(table) {
|
|
26
28
|
return table[columnDefinitionsSymbol];
|
|
27
29
|
}
|
|
30
|
+
export function getColumnDefinitionsMap(table) {
|
|
31
|
+
return table[columnDefinitionsMapSymbol];
|
|
32
|
+
}
|
|
28
33
|
export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
29
34
|
const metadata = reflectionRegistry.getMetadata(type);
|
|
30
35
|
assertDefined(metadata, `Type ${type.name} does not have reflection metadata.`);
|
|
@@ -41,6 +46,7 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
41
46
|
const tableName = tableReflectionData?.name ?? getDefaultTableName(type);
|
|
42
47
|
const dbSchema = getDbSchema(schema);
|
|
43
48
|
const columnDefinitions = getPostgresColumnEntries(type, dbSchema, tableName);
|
|
49
|
+
const columnDefinitionsMap = new Map(columnDefinitions.map((column) => [column.objectPath.path, column]));
|
|
44
50
|
function getColumn(table, propertyName) {
|
|
45
51
|
return assertDefinedPass(table[propertyName], `Property "${propertyName}" does not exist on ${type.name}`);
|
|
46
52
|
}
|
|
@@ -60,7 +66,11 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
60
66
|
return column;
|
|
61
67
|
});
|
|
62
68
|
const indexFn = (data.options?.unique == true) ? uniqueIndex : index;
|
|
63
|
-
|
|
69
|
+
let builder = indexFn(data.name ?? getIndexName(tableName, columns, { naming: data.options?.naming })).using(data.options?.using ?? 'btree', ...columns);
|
|
70
|
+
if (isDefined(data.options?.where)) {
|
|
71
|
+
builder = builder.where(convertQuery(data.options.where(table), table, columnDefinitionsMap));
|
|
72
|
+
}
|
|
73
|
+
return builder;
|
|
64
74
|
}
|
|
65
75
|
function buildPrimaryKey(table) {
|
|
66
76
|
const columns = primaryKeyColumnDefinitions.map((columnDefinition) => getColumn(table, columnDefinition.name));
|
|
@@ -95,6 +105,7 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
95
105
|
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.checks).filter(isDefined).map((data) => check(data.name, data.builder(table)))
|
|
96
106
|
]);
|
|
97
107
|
drizzleSchema[columnDefinitionsSymbol] = columnDefinitions;
|
|
108
|
+
drizzleSchema[columnDefinitionsMapSymbol] = columnDefinitionsMap;
|
|
98
109
|
return drizzleSchema;
|
|
99
110
|
}
|
|
100
111
|
function getPostgresColumnEntries(type, dbSchema, tableName, path = new JsonPath({ dollar: false }), prefix = '') {
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypts a byte array using AES-GCM with the provided key.
|
|
3
|
+
* Prepends the encryption version and IV to the resulting ciphertext.
|
|
4
|
+
* @param bytes The byte array to encrypt.
|
|
5
|
+
* @param key The CryptoKey to use for encryption.
|
|
6
|
+
* @returns A promise that resolves to the encrypted byte array (version + IV + ciphertext).
|
|
7
|
+
*/
|
|
1
8
|
export declare function encryptBytes(bytes: Uint8Array, key: CryptoKey): Promise<Uint8Array>;
|
|
9
|
+
/**
|
|
10
|
+
* Decrypts a byte array encrypted with `encryptBytes`.
|
|
11
|
+
* Reads the version and IV from the beginning of the array.
|
|
12
|
+
* @param bytes The byte array to decrypt (must include version and IV).
|
|
13
|
+
* @param key The CryptoKey to use for decryption.
|
|
14
|
+
* @returns A promise that resolves to the original decrypted byte array.
|
|
15
|
+
* @throws {DetailsError} If decryption fails (e.g., wrong key, corrupted data).
|
|
16
|
+
* @throws {Error} If the encryption version is invalid.
|
|
17
|
+
*/
|
|
2
18
|
export declare function decryptBytes(bytes: Uint8Array, key: CryptoKey): Promise<Uint8Array>;
|
package/orm/server/encryption.js
CHANGED
|
@@ -1,30 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Provides utility functions for encrypting and decrypting byte arrays using AES-GCM.
|
|
4
|
+
* It includes versioning to handle potential future changes in the encryption format.
|
|
5
|
+
*/
|
|
1
6
|
import { DetailsError } from '../../errors/index.js';
|
|
2
7
|
import { decrypt, encrypt } from '../../utils/cryptography.js';
|
|
3
8
|
import { getRandomBytes } from '../../utils/random.js';
|
|
4
9
|
import { assert } from '../../utils/type-guards.js';
|
|
10
|
+
/** Current version of the encryption format. */
|
|
5
11
|
const encryptionVersion = 1;
|
|
12
|
+
/** Number of bytes used to store the encryption version. */
|
|
6
13
|
const encryptionVersionBytes = 2;
|
|
14
|
+
/** Number of bytes used for the Initialization Vector (IV). */
|
|
7
15
|
const ivBytes = 12;
|
|
16
|
+
/**
|
|
17
|
+
* Encrypts a byte array using AES-GCM with the provided key.
|
|
18
|
+
* Prepends the encryption version and IV to the resulting ciphertext.
|
|
19
|
+
* @param bytes The byte array to encrypt.
|
|
20
|
+
* @param key The CryptoKey to use for encryption.
|
|
21
|
+
* @returns A promise that resolves to the encrypted byte array (version + IV + ciphertext).
|
|
22
|
+
*/
|
|
8
23
|
export async function encryptBytes(bytes, key) {
|
|
9
24
|
const iv = getRandomBytes(ivBytes);
|
|
10
25
|
const encrypted = await encrypt({ name: 'AES-GCM', iv }, key, bytes).toBuffer();
|
|
11
26
|
const result = new Uint8Array(encryptionVersionBytes + ivBytes + encrypted.byteLength);
|
|
12
27
|
const resultView = new DataView(result.buffer);
|
|
13
|
-
resultView.setUint16(0, encryptionVersion);
|
|
14
|
-
result.set(iv, encryptionVersionBytes);
|
|
15
|
-
result.set(new Uint8Array(encrypted), encryptionVersionBytes + ivBytes);
|
|
28
|
+
resultView.setUint16(0, encryptionVersion); // Prepend version
|
|
29
|
+
result.set(iv, encryptionVersionBytes); // Prepend IV
|
|
30
|
+
result.set(new Uint8Array(encrypted), encryptionVersionBytes + ivBytes); // Append ciphertext
|
|
16
31
|
return result;
|
|
17
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Decrypts a byte array encrypted with `encryptBytes`.
|
|
35
|
+
* Reads the version and IV from the beginning of the array.
|
|
36
|
+
* @param bytes The byte array to decrypt (must include version and IV).
|
|
37
|
+
* @param key The CryptoKey to use for decryption.
|
|
38
|
+
* @returns A promise that resolves to the original decrypted byte array.
|
|
39
|
+
* @throws {DetailsError} If decryption fails (e.g., wrong key, corrupted data).
|
|
40
|
+
* @throws {Error} If the encryption version is invalid.
|
|
41
|
+
*/
|
|
18
42
|
export async function decryptBytes(bytes, key) {
|
|
19
43
|
const bytesView = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
|
|
20
44
|
const version = bytesView.getUint16(0);
|
|
21
45
|
const iv = bytes.slice(encryptionVersionBytes, encryptionVersionBytes + ivBytes);
|
|
22
|
-
assert(version == encryptionVersion, 'Invalid encryption version.');
|
|
46
|
+
assert(version == encryptionVersion, 'Invalid encryption version.'); // Check version
|
|
23
47
|
try {
|
|
24
48
|
const decrypted = await decrypt({ name: 'AES-GCM', iv }, key, bytes.slice(encryptionVersionBytes + ivBytes)).toBuffer();
|
|
25
49
|
return new Uint8Array(decrypted);
|
|
26
50
|
}
|
|
27
51
|
catch (error) {
|
|
52
|
+
// Wrap decryption errors for better context
|
|
28
53
|
throw new DetailsError('Decrypt error', error);
|
|
29
54
|
}
|
|
30
55
|
}
|
package/orm/server/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Barrel file exporting core server-side ORM functionalities.
|
|
4
|
+
* Includes database connection, schema management, repositories, transactions,
|
|
5
|
+
* and query conversion utilities.
|
|
6
|
+
*/
|
|
1
7
|
export * from './database-schema.js';
|
|
2
8
|
export * from './database.js';
|
|
3
9
|
export * from './module.js';
|
|
4
10
|
export * from './query-converter.js';
|
|
5
11
|
export * from './repository.js';
|
|
6
12
|
export * from './transaction.js';
|
|
13
|
+
export * from './transactional.js';
|