@tstdl/base 0.93.1 → 0.93.3
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/api/server/api-request-token.provider.d.ts +5 -3
- package/api/server/api-request-token.provider.js +12 -4
- package/api/server/gateway.d.ts +1 -9
- package/api/server/gateway.js +67 -36
- package/api/types.d.ts +5 -1
- package/application/application.d.ts +2 -0
- package/application/application.js +3 -1
- package/application/providers.d.ts +1 -1
- package/application/providers.js +1 -1
- package/audit/audit.model.d.ts +106 -6
- package/audit/audit.model.js +156 -13
- package/audit/auditor.d.ts +115 -30
- package/audit/auditor.js +160 -19
- package/audit/drizzle/0000_bored_stick.sql +26 -0
- package/audit/drizzle/meta/0000_snapshot.json +195 -0
- package/audit/drizzle/meta/_journal.json +13 -0
- package/audit/drizzle.config.d.ts +2 -0
- package/audit/drizzle.config.js +11 -0
- package/audit/index.d.ts +3 -1
- package/audit/index.js +3 -1
- package/audit/module.d.ts +22 -0
- package/audit/module.js +33 -0
- package/audit/schemas.d.ts +6 -0
- package/audit/schemas.js +8 -0
- package/audit/types.d.ts +2 -1
- package/audit/types.js +2 -1
- package/authentication/models/authentication-credentials.model.js +1 -2
- package/authentication/models/authentication-session.model.d.ts +2 -2
- package/authentication/models/authentication-session.model.js +3 -5
- package/authentication/models/index.d.ts +0 -1
- package/authentication/models/index.js +0 -1
- package/authentication/server/authentication-api-request-token.provider.d.ts +2 -2
- package/authentication/server/authentication-api-request-token.provider.js +8 -5
- package/authentication/server/authentication.api-controller.d.ts +8 -8
- package/authentication/server/authentication.api-controller.js +16 -16
- package/authentication/server/authentication.audit.d.ts +34 -0
- package/authentication/server/authentication.audit.js +1 -0
- package/authentication/server/authentication.service.d.ts +19 -10
- package/authentication/server/authentication.service.js +158 -43
- package/authentication/server/drizzle.config.js +1 -1
- package/authentication/server/index.d.ts +1 -0
- package/authentication/server/index.js +1 -0
- package/authentication/server/module.d.ts +1 -1
- package/authentication/{models → server}/schemas.d.ts +2 -3
- package/authentication/{models → server}/schemas.js +2 -3
- package/constants.d.ts +1 -0
- package/constants.js +1 -0
- package/document-management/api/document-management.api.d.ts +74 -74
- package/document-management/models/document-assignment-scope.model.d.ts +1 -2
- package/document-management/models/document-assignment-scope.model.js +4 -6
- package/document-management/models/document-assignment-task.model.d.ts +1 -2
- package/document-management/models/document-assignment-task.model.js +3 -5
- package/document-management/models/document-category.model.d.ts +1 -2
- package/document-management/models/document-category.model.js +3 -4
- package/document-management/models/document-collection-assignment.model.d.ts +1 -2
- package/document-management/models/document-collection-assignment.model.js +5 -7
- package/document-management/models/document-collection.model.d.ts +1 -2
- package/document-management/models/document-collection.model.js +3 -4
- package/document-management/models/document-management-table.d.ts +1 -1
- package/document-management/models/document-management-table.js +1 -1
- package/document-management/models/document-property-value.model.d.ts +1 -2
- package/document-management/models/document-property-value.model.js +5 -8
- package/document-management/models/document-property.model.d.ts +1 -2
- package/document-management/models/document-property.model.js +2 -3
- package/document-management/models/document-request-collection-assignment.model.d.ts +1 -2
- package/document-management/models/document-request-collection-assignment.model.js +4 -6
- package/document-management/models/document-request-template.d.ts +1 -2
- package/document-management/models/document-request-template.js +4 -6
- package/document-management/models/document-request.model.d.ts +1 -1
- package/document-management/models/document-request.model.js +4 -5
- package/document-management/models/document-requests-template.d.ts +1 -1
- package/document-management/models/document-requests-template.js +2 -3
- package/document-management/models/document-tag-assignment.model.d.ts +1 -2
- package/document-management/models/document-tag-assignment.model.js +4 -6
- package/document-management/models/document-tag.model.d.ts +1 -1
- package/document-management/models/document-tag.model.js +2 -3
- package/document-management/models/document-type-property.model.d.ts +1 -2
- package/document-management/models/document-type-property.model.js +4 -6
- package/document-management/models/document-type-validation.model.d.ts +1 -2
- package/document-management/models/document-type-validation.model.js +4 -6
- package/document-management/models/document-type.model.d.ts +1 -2
- package/document-management/models/document-type.model.js +3 -5
- package/document-management/models/document-validation-definition.model.d.ts +1 -2
- package/document-management/models/document-validation-definition.model.js +3 -4
- package/document-management/models/document-validation-execution-related-document.model.d.ts +1 -2
- package/document-management/models/document-validation-execution-related-document.model.js +4 -6
- package/document-management/models/document-validation-execution.model.d.ts +1 -2
- package/document-management/models/document-validation-execution.model.js +6 -8
- package/document-management/models/document-workflow.model.d.ts +1 -2
- package/document-management/models/document-workflow.model.js +5 -7
- package/document-management/models/document.model.d.ts +1 -2
- package/document-management/models/document.model.js +5 -7
- package/document-management/server/api/document-management.api.js +1 -1
- package/document-management/server/module.d.ts +1 -1
- package/document-management/server/module.js +1 -1
- package/document-management/server/schemas.d.ts +1 -1
- package/document-management/server/schemas.js +1 -1
- package/document-management/server/services/document-category-type.service.d.ts +2 -2
- package/document-management/server/services/document-category-type.service.js +1 -2
- package/document-management/server/services/document-collection.service.d.ts +1 -1
- package/document-management/server/services/document-collection.service.js +1 -2
- package/document-management/server/services/document-management.service.js +6 -6
- package/document-management/server/services/document-property.service.d.ts +1 -1
- package/document-management/server/services/document-property.service.js +1 -2
- package/document-management/server/services/document-validation.service.js +2 -2
- package/document-management/server/services/document-workflow.service.d.ts +2 -2
- package/document-management/server/services/document-workflow.service.js +1 -2
- package/document-management/server/services/document.service.d.ts +1 -1
- package/document-management/server/services/document.service.js +1 -2
- package/document-management/server/services/singleton.js +1 -1
- package/document-management/service-models/document.service-model.d.ts +62 -62
- package/document-management/service-models/document.service-model.js +1 -1
- package/document-management/service-models/enriched/enriched-document-management-data.view.js +1 -1
- package/document-management/service-models/enriched/enriched-document.view.d.ts +1 -1
- package/examples/api/authentication.js +2 -2
- package/examples/api/basic-overview.js +2 -2
- package/examples/api/custom-authentication.js +2 -2
- package/examples/api/streaming.js +2 -2
- package/examples/browser/basic.js +2 -2
- package/examples/document-management/main.js +2 -2
- package/examples/http/client.js +2 -2
- package/examples/mail/basic.js +2 -2
- package/examples/pdf/basic.js +2 -2
- package/examples/template/basic.js +2 -2
- package/http/server/http-server-request.d.ts +3 -3
- package/key-value-store/postgres/key-value-store.service.js +1 -2
- package/key-value-store/postgres/models/key-value.model.d.ts +1 -2
- package/key-value-store/postgres/models/key-value.model.js +2 -4
- package/key-value-store/postgres/models/schemas.d.ts +1 -1
- package/key-value-store/postgres/models/schemas.js +1 -1
- package/lock/postgres/lock.js +1 -1
- package/lock/postgres/models/lock.model.d.ts +1 -2
- package/lock/postgres/models/lock.model.js +3 -5
- package/lock/postgres/models/schemas.d.ts +1 -1
- package/lock/postgres/models/schemas.js +1 -1
- package/lock/postgres/provider.js +1 -2
- package/mail/models/mail-log.model.d.ts +1 -1
- package/mail/models/mail-log.model.js +4 -5
- package/mail/models/schemas.d.ts +1 -1
- package/mail/models/schemas.js +1 -1
- package/openid-connect/oidc-state.model.d.ts +1 -1
- package/openid-connect/oidc-state.model.js +2 -3
- package/openid-connect/oidc.service.js +1 -1
- package/orm/data-types/bytea.js +1 -1
- package/orm/data-types/numeric-date.js +1 -1
- package/orm/decorators.d.ts +65 -72
- package/orm/decorators.js +42 -40
- package/orm/entity.d.ts +7 -1
- package/orm/entity.js +25 -11
- package/orm/index.d.ts +2 -1
- package/orm/index.js +2 -1
- package/orm/schemas/json.d.ts +1 -1
- package/orm/schemas/json.js +1 -1
- package/orm/schemas/numeric-date.d.ts +1 -1
- package/orm/schemas/numeric-date.js +1 -1
- package/orm/schemas/timestamp.d.ts +1 -1
- package/orm/schemas/timestamp.js +1 -1
- package/orm/schemas/uuid.d.ts +2 -2
- package/orm/schemas/uuid.js +1 -1
- package/orm/server/drizzle/schema-converter.ts +408 -0
- package/orm/server/repository.d.ts +1 -1
- package/orm/server/repository.js +12 -9
- package/orm/sqls.d.ts +1 -1
- package/orm/sqls.js +1 -1
- package/orm/types.d.ts +2 -6
- package/orm/types.js +1 -4
- package/package.json +15 -24
- package/queue/postgres/job.model.d.ts +3 -3
- package/queue/postgres/job.model.js +5 -6
- package/queue/postgres/queue.js +2 -2
- package/queue/postgres/schemas.d.ts +1 -1
- package/queue/postgres/schemas.js +1 -1
- package/supports.d.ts +1 -0
- package/supports.js +2 -1
- package/types/types.d.ts +12 -1
- package/utils/object/object.d.ts +3 -1
- package/utils/object/object.js +7 -1
- package/orm/server/drizzle/index.js +0 -1
- package/orm/server/drizzle/schema-converter.d.ts +0 -15
- package/orm/server/drizzle/schema-converter.js +0 -300
- /package/orm/server/drizzle/{index.d.ts → index.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.93.
|
|
3
|
+
"version": "0.93.3",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -19,29 +19,18 @@
|
|
|
19
19
|
"tsc:watch": "tsc --watch",
|
|
20
20
|
"tsc-alias:watch": "tsc-alias --watch",
|
|
21
21
|
"cleanup:dist": "rm -vf dist/test* && rm -vrf dist/tools/",
|
|
22
|
-
"generate:migration": "
|
|
23
|
-
"generate:migration:document-management": "drizzle-kit generate --config dist/document-management/server/drizzle.config.js",
|
|
24
|
-
"generate:migration:authentication": "drizzle-kit generate --config dist/authentication/server/drizzle.config.js",
|
|
25
|
-
"generate:migration:mail": "drizzle-kit generate --config dist/mail/drizzle.config.js",
|
|
26
|
-
"generate:migration:queue": "drizzle-kit generate --config dist/queue/postgres/drizzle.config.js",
|
|
27
|
-
"generate:migration:key-value-store": "drizzle-kit generate --config dist/key-value-store/postgres/drizzle.config.js",
|
|
28
|
-
"generate:migration:lock": "drizzle-kit generate --config dist/lock/postgres/drizzle.config.js",
|
|
22
|
+
"generate:migration": "./scripts/manage-orm.sh generate",
|
|
29
23
|
"generate:readmes": "deno run --allow-run=code2prompt --allow-read --allow-write=source --allow-net=generativelanguage.googleapis.com --allow-env=GEMINI_API_KEY generate-readmes.ts",
|
|
30
24
|
"generate:readmes:new-only": "npm run generate:readmes -- --skip-existing",
|
|
31
25
|
"generate:llms.md": "npm run build:dts && npm run cleanup:dist && ./scripts/generate-llms-docs.sh",
|
|
32
26
|
"generate:context7-docs": "npm run build:dts && npm run cleanup:dist && ./scripts/generate-context7-docs.sh",
|
|
33
|
-
"copy:orm": "
|
|
34
|
-
"copy:orm:document-management": "rm -rf ./dist/document-management/server/drizzle && cp -r ./source/document-management/server/drizzle ./dist/document-management/server/",
|
|
35
|
-
"copy:orm:authentication": "rm -rf ./dist/authentication/server/drizzle && cp -r ./source/authentication/server/drizzle ./dist/authentication/server/",
|
|
36
|
-
"copy:orm:mail": "rm -rf ./dist/mail/drizzle && cp -r ./source/mail/drizzle ./dist/mail/",
|
|
37
|
-
"copy:orm:queue": "rm -rf ./dist/queue/postgres/drizzle && cp -r ./source/queue/postgres/drizzle ./dist/queue/postgres/",
|
|
38
|
-
"copy:orm:key-value-store": "rm -rf ./dist/key-value-store/postgres/drizzle && cp -r ./source/key-value-store/postgres/drizzle ./dist/key-value-store/postgres/",
|
|
39
|
-
"copy:orm:lock": "rm -rf ./dist/lock/postgres/drizzle && cp -r ./source/lock/postgres/drizzle ./dist/lock/postgres/"
|
|
27
|
+
"copy:orm": "./scripts/manage-orm.sh copy"
|
|
40
28
|
},
|
|
41
29
|
"exports": {
|
|
42
30
|
"./tsconfig.json": "./tsconfig.json",
|
|
43
31
|
"./eslint.config.js": "./eslint.config.js",
|
|
44
32
|
".": "./index.js",
|
|
33
|
+
"./constants": "./constants.js",
|
|
45
34
|
"./environment": "./environment.js",
|
|
46
35
|
"./interfaces": "./interfaces.js",
|
|
47
36
|
"./polyfills": "./polyfills.js",
|
|
@@ -52,6 +41,7 @@
|
|
|
52
41
|
"./api/client": "./api/client/index.js",
|
|
53
42
|
"./api/server": "./api/server/index.js",
|
|
54
43
|
"./application": "./application/index.js",
|
|
44
|
+
"./audit": "./audit/index.js",
|
|
55
45
|
"./authentication": "./authentication/index.js",
|
|
56
46
|
"./authentication/server": "./authentication/server/index.js",
|
|
57
47
|
"./browser": "./browser/index.js",
|
|
@@ -94,6 +84,8 @@
|
|
|
94
84
|
"./object-storage": "./object-storage/index.js",
|
|
95
85
|
"./openid-connect": "./openid-connect/index.js",
|
|
96
86
|
"./orm": "./orm/index.js",
|
|
87
|
+
"./orm/schemas": "./orm/schemas/index.js",
|
|
88
|
+
"./orm/data-types": "./orm/data-types/index.js",
|
|
97
89
|
"./orm/server": "./orm/server/index.js",
|
|
98
90
|
"./password": "./password/index.js",
|
|
99
91
|
"./pdf": "./pdf/index.js",
|
|
@@ -140,12 +132,12 @@
|
|
|
140
132
|
"reflect-metadata": "^0.2",
|
|
141
133
|
"rxjs": "^7.8",
|
|
142
134
|
"ts-pattern": "^5.8",
|
|
143
|
-
"type-fest": "
|
|
135
|
+
"type-fest": "^5.0"
|
|
144
136
|
},
|
|
145
137
|
"peerDependencies": {
|
|
146
138
|
"@google-cloud/storage": "^7.17",
|
|
147
|
-
"@google/genai": "^1.
|
|
148
|
-
"@tstdl/angular": "^0.
|
|
139
|
+
"@google/genai": "^1.22",
|
|
140
|
+
"@tstdl/angular": "^0.93",
|
|
149
141
|
"@zxcvbn-ts/core": "^3.0",
|
|
150
142
|
"@zxcvbn-ts/language-common": "^3.0",
|
|
151
143
|
"@zxcvbn-ts/language-de": "^3.0",
|
|
@@ -154,7 +146,7 @@
|
|
|
154
146
|
"file-type": "^21.0",
|
|
155
147
|
"handlebars": "^4.7",
|
|
156
148
|
"minio": "^8.0",
|
|
157
|
-
"mjml": "^4.
|
|
149
|
+
"mjml": "^4.16",
|
|
158
150
|
"nodemailer": "^7.0",
|
|
159
151
|
"pg": "^8.16",
|
|
160
152
|
"playwright": "^1.55",
|
|
@@ -170,24 +162,23 @@
|
|
|
170
162
|
}
|
|
171
163
|
},
|
|
172
164
|
"devDependencies": {
|
|
173
|
-
"@stylistic/eslint-plugin": "5.
|
|
165
|
+
"@stylistic/eslint-plugin": "5.4",
|
|
174
166
|
"@types/koa__router": "12.0",
|
|
175
167
|
"@types/luxon": "3.7",
|
|
176
|
-
"@types/minio": "7.1",
|
|
177
168
|
"@types/mjml": "4.7",
|
|
178
169
|
"@types/node": "24",
|
|
179
170
|
"@types/nodemailer": "7.0",
|
|
180
171
|
"@types/pg": "8.15",
|
|
181
172
|
"concurrently": "9.2",
|
|
182
173
|
"drizzle-kit": "0.31",
|
|
183
|
-
"eslint": "9.
|
|
174
|
+
"eslint": "9.37",
|
|
184
175
|
"globals": "16.4",
|
|
185
176
|
"tsc-alias": "1.8",
|
|
186
177
|
"typedoc-github-wiki-theme": "2.1",
|
|
187
|
-
"typedoc-plugin-markdown": "4.
|
|
178
|
+
"typedoc-plugin-markdown": "4.9",
|
|
188
179
|
"typedoc-plugin-missing-exports": "4.1",
|
|
189
180
|
"typescript": "5.9",
|
|
190
|
-
"typescript-eslint": "8.
|
|
181
|
+
"typescript-eslint": "8.45"
|
|
191
182
|
},
|
|
192
183
|
"overrides": {
|
|
193
184
|
"drizzle-kit": {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { EntityWithoutMetadata,
|
|
1
|
+
import { EntityWithoutMetadata, type Json, type Timestamp } from '../../orm/index.js';
|
|
2
2
|
import type { ObjectLiteral } from '../../types/index.js';
|
|
3
3
|
import type { Job } from '../queue.js';
|
|
4
4
|
export declare class PostgresJob<T extends ObjectLiteral = ObjectLiteral> extends EntityWithoutMetadata implements Job<T> {
|
|
5
5
|
queue: string;
|
|
6
6
|
tag: string | null;
|
|
7
|
-
priority:
|
|
7
|
+
priority: number;
|
|
8
8
|
enqueueTimestamp: Timestamp;
|
|
9
|
-
tries:
|
|
9
|
+
tries: number;
|
|
10
10
|
lastDequeueTimestamp: Timestamp | null;
|
|
11
11
|
data: Json<T>;
|
|
12
12
|
}
|
|
@@ -7,9 +7,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { Index, Table } from '../../orm/
|
|
11
|
-
import {
|
|
12
|
-
import { StringProperty } from '../../schema/index.js';
|
|
10
|
+
import { EntityWithoutMetadata, Index, JsonProperty, Table, TimestampProperty } from '../../orm/index.js';
|
|
11
|
+
import { Integer, StringProperty } from '../../schema/index.js';
|
|
13
12
|
let PostgresJob = class PostgresJob extends EntityWithoutMetadata {
|
|
14
13
|
queue;
|
|
15
14
|
tag;
|
|
@@ -32,7 +31,7 @@ __decorate([
|
|
|
32
31
|
__metadata("design:type", Number)
|
|
33
32
|
], PostgresJob.prototype, "priority", void 0);
|
|
34
33
|
__decorate([
|
|
35
|
-
|
|
34
|
+
TimestampProperty(),
|
|
36
35
|
__metadata("design:type", Number)
|
|
37
36
|
], PostgresJob.prototype, "enqueueTimestamp", void 0);
|
|
38
37
|
__decorate([
|
|
@@ -40,11 +39,11 @@ __decorate([
|
|
|
40
39
|
__metadata("design:type", Number)
|
|
41
40
|
], PostgresJob.prototype, "tries", void 0);
|
|
42
41
|
__decorate([
|
|
43
|
-
|
|
42
|
+
TimestampProperty({ nullable: true }),
|
|
44
43
|
__metadata("design:type", Object)
|
|
45
44
|
], PostgresJob.prototype, "lastDequeueTimestamp", void 0);
|
|
46
45
|
__decorate([
|
|
47
|
-
|
|
46
|
+
JsonProperty(),
|
|
48
47
|
__metadata("design:type", Object)
|
|
49
48
|
], PostgresJob.prototype, "data", void 0);
|
|
50
49
|
PostgresJob = __decorate([
|
package/queue/postgres/queue.js
CHANGED
|
@@ -9,7 +9,7 @@ import { merge } from 'rxjs';
|
|
|
9
9
|
import { CancellationSignal } from '../../cancellation/index.js';
|
|
10
10
|
import { inject, injectArgument, provide, Singleton } from '../../injector/index.js';
|
|
11
11
|
import { MessageBus } from '../../message-bus/index.js';
|
|
12
|
-
import { interval,
|
|
12
|
+
import { interval, RANDOM_UUID_V4, TRANSACTION_TIMESTAMP } from '../../orm/index.js';
|
|
13
13
|
import { DatabaseConfig, EntityRepositoryConfig, injectRepository } from '../../orm/server/index.js';
|
|
14
14
|
import { cancelableTimeout } from '../../utils/timing.js';
|
|
15
15
|
import { isDefined, isString, isUndefined } from '../../utils/type-guards.js';
|
|
@@ -27,7 +27,7 @@ let PostgresQueue = class PostgresQueue extends Queue {
|
|
|
27
27
|
processTimeout = (isString(this.#config) ? undefined : this.#config.processTimeout) ?? defaultQueueConfig.processTimeout;
|
|
28
28
|
maxTries = (isString(this.#config) ? undefined : this.#config.maxTries) ?? defaultQueueConfig.maxTries;
|
|
29
29
|
#takeNewUpdate = {
|
|
30
|
-
id:
|
|
30
|
+
id: RANDOM_UUID_V4,
|
|
31
31
|
queue: this.#queueName,
|
|
32
32
|
priority: sql `excluded.priority`,
|
|
33
33
|
tag: sql `excluded.tag`,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { PostgresJob } from './job.model.js';
|
|
2
|
-
export declare const queueSchema: import("../../orm/server/
|
|
2
|
+
export declare const queueSchema: import("../../orm/server/index.js").DatabaseSchema<"queue">;
|
|
3
3
|
export declare const job: import("../../orm/server/types.js").PgTableFromType<typeof PostgresJob, "queue">;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { databaseSchema } from '../../orm/server/
|
|
1
|
+
import { databaseSchema } from '../../orm/server/index.js';
|
|
2
2
|
import { PostgresJob } from './job.model.js';
|
|
3
3
|
export const queueSchema = databaseSchema('queue');
|
|
4
4
|
export const job = queueSchema.getTable(PostgresJob);
|
package/supports.d.ts
CHANGED
package/supports.js
CHANGED
|
@@ -3,4 +3,5 @@ export const supportsBlob = (typeof Blob == 'function');
|
|
|
3
3
|
export const supportsBuffer = (typeof Buffer == 'function');
|
|
4
4
|
export const supportsStructuredClone = (typeof structuredClone == 'function');
|
|
5
5
|
export const supportsNotification = (typeof Notification == 'function');
|
|
6
|
-
export const supportsColoredStdout = (typeof process == 'object' && process.stdout.hasColors());
|
|
6
|
+
export const supportsColoredStdout = (typeof process == 'object' && (process.stdout.hasColors?.() ?? false));
|
|
7
|
+
export const supportsColoredStderr = (typeof process == 'object' && (process.stderr.hasColors?.() ?? false));
|
package/types/types.d.ts
CHANGED
|
@@ -117,7 +117,18 @@ export type OmitBy<T, V> = Omit<T, {
|
|
|
117
117
|
/**
|
|
118
118
|
* Normalize properties of a type that allow `undefined` to make them optional.
|
|
119
119
|
*/
|
|
120
|
-
export type Optionalize<T extends object> = OmitBy<T, undefined> & Partial<PickBy<T, undefined
|
|
120
|
+
export type Optionalize<T extends object> = SimplifyObject<OmitBy<T, undefined> & Partial<PickBy<T, undefined>>>;
|
|
121
|
+
export type OptionalizeDeep<T> = T extends BuiltIn ? T : T extends (infer U)[] ? OptionalizeDeep<U>[] : T extends readonly (infer U)[] ? readonly OptionalizeDeep<U>[] : Optionalize<{
|
|
122
|
+
[P in keyof T]: OptionalizeDeep<T[P]>;
|
|
123
|
+
}>;
|
|
124
|
+
export type OptionalizeNull<T extends object> = SimplifyObject<OmitBy<T, null> & Partial<PickBy<T, null>>>;
|
|
125
|
+
export type OptionalizeNullDeep<T> = T extends BuiltIn ? T : T extends (infer U)[] ? OptionalizeNullDeep<U>[] : T extends readonly (infer U)[] ? readonly OptionalizeNullDeep<U>[] : OptionalizeNull<{
|
|
126
|
+
[P in keyof T]: OptionalizeNullDeep<T[P]>;
|
|
127
|
+
}>;
|
|
128
|
+
export type OptionalizeNullable<T extends object> = SimplifyObject<OmitBy<T, null | undefined> & Partial<PickBy<T, null | undefined>>>;
|
|
129
|
+
export type OptionalizeNullableDeep<T> = T extends BuiltIn ? T : T extends readonly (infer U)[] ? OptionalizeNullableDeep<U>[] : T extends (infer U)[] ? OptionalizeNullableDeep<U>[] : OptionalizeNullable<{
|
|
130
|
+
[P in keyof T]: OptionalizeNullableDeep<T[P]>;
|
|
131
|
+
}>;
|
|
121
132
|
export type Unoptionalize<T extends object> = SimplifyObject<OmitBy<T, undefined> & {
|
|
122
133
|
[P in PropertiesOfType<T, undefined>]: T[P] | undefined;
|
|
123
134
|
}>;
|
package/utils/object/object.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type JsonPathInput } from '../../json-path/json-path.js';
|
|
2
|
-
import type { BaseType, FromEntries, ObjectLiteral, Optionalize, PickBy, Record, SimplifyObject, UnionToIntersection } from '../../types/index.js';
|
|
2
|
+
import type { BaseType, FromEntries, ObjectLiteral, Optionalize, OptionalizeNull, PickBy, Record, SimplifyObject, UnionToIntersection } from '../../types/index.js';
|
|
3
3
|
export declare function hasOwnProperty<T extends Record, K extends keyof UnionToIntersection<T>>(obj: T, key: K): obj is Extract<T, Partial<Record<K>>>;
|
|
4
4
|
export declare function hasOwnProperty<T extends Record>(obj: T, key: keyof T): boolean;
|
|
5
5
|
/**
|
|
@@ -22,7 +22,9 @@ export declare function filterObject<T extends ObjectLiteral, U extends T[keyof
|
|
|
22
22
|
export declare function filterObject<T extends ObjectLiteral>(object: T, predicate: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
|
|
23
23
|
export declare function filterObjectAsync<T extends ObjectLiteral>(object: T, predicate: (value: T[keyof T], key: keyof T) => Promise<boolean>): Promise<Partial<T>>;
|
|
24
24
|
export declare function filterUndefinedFromRecord<K extends PropertyKey, V>(record: Record<K, V>): Record<BaseType<K>, Exclude<V, undefined>>;
|
|
25
|
+
export declare function filterNullishFromRecord<K extends PropertyKey, V>(record: Record<K, V>): Record<BaseType<K>, Exclude<V, null | undefined>>;
|
|
25
26
|
export declare function filterUndefinedObjectProperties<T extends ObjectLiteral>(object: T): SimplifyObject<Optionalize<T>>;
|
|
27
|
+
export declare function filterNullishObjectProperties<T extends ObjectLiteral>(object: T): SimplifyObject<OptionalizeNull<Optionalize<T>>>;
|
|
26
28
|
export declare function copyObjectProperties<T extends ObjectLiteral>(source: T, target: T): void;
|
|
27
29
|
export declare function getGetter<T extends ObjectLiteral, U extends keyof T>(obj: T, property: U, bind: boolean): () => T[U];
|
|
28
30
|
export declare function deepObjectEntries(object: ObjectLiteral, keepInnerObjects?: boolean, prefix?: string): [string, any][];
|
package/utils/object/object.js
CHANGED
|
@@ -2,7 +2,7 @@ import { JsonPath } from '../../json-path/json-path.js';
|
|
|
2
2
|
import { filterAsync } from '../async-iterable-helpers/filter.js';
|
|
3
3
|
import { mapAsync } from '../async-iterable-helpers/map.js';
|
|
4
4
|
import { toArrayAsync } from '../async-iterable-helpers/to-array.js';
|
|
5
|
-
import { isArray, isDefined, isObject, isSymbol, isUndefined } from '../type-guards.js';
|
|
5
|
+
import { isArray, isDefined, isNotNullOrUndefined, isObject, isSymbol, isUndefined } from '../type-guards.js';
|
|
6
6
|
export function hasOwnProperty(obj, key) {
|
|
7
7
|
return Object.hasOwn(obj, key);
|
|
8
8
|
}
|
|
@@ -55,9 +55,15 @@ export async function filterObjectAsync(object, predicate) {
|
|
|
55
55
|
export function filterUndefinedFromRecord(record) {
|
|
56
56
|
return filterObject(record, isDefined);
|
|
57
57
|
}
|
|
58
|
+
export function filterNullishFromRecord(record) {
|
|
59
|
+
return filterObject(record, isNotNullOrUndefined);
|
|
60
|
+
}
|
|
58
61
|
export function filterUndefinedObjectProperties(object) {
|
|
59
62
|
return filterObject(object, isDefined);
|
|
60
63
|
}
|
|
64
|
+
export function filterNullishObjectProperties(object) {
|
|
65
|
+
return filterObject(object, isNotNullOrUndefined);
|
|
66
|
+
}
|
|
61
67
|
export function copyObjectProperties(source, target) {
|
|
62
68
|
for (const key of objectKeys(source)) {
|
|
63
69
|
target[key] = source[key];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './schema-converter.js';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type PgEnum, type PgSchema, type PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
2
|
-
import type { AbstractConstructor, Enumeration } from '../../../types/index.js';
|
|
3
|
-
import type { EntityType } from '../../entity.js';
|
|
4
|
-
import type { ColumnDefinition, ColumnDefinitionsMap, PgTableFromType } from '../types.js';
|
|
5
|
-
type ConverterContext = {
|
|
6
|
-
type: AbstractConstructor;
|
|
7
|
-
property: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const getDrizzleTableFromType: typeof _getDrizzleTableFromType;
|
|
10
|
-
export declare function getColumnDefinitions(table: PgTableWithColumns<any>): ColumnDefinition[];
|
|
11
|
-
export declare function getColumnDefinitionsMap(table: PgTableWithColumns<any>): ColumnDefinitionsMap;
|
|
12
|
-
export declare function _getDrizzleTableFromType<T extends EntityType, S extends string>(type: T, fallbackSchemaName?: S): PgTableFromType<T, S>;
|
|
13
|
-
export declare function registerEnum(enumeration: Enumeration, name: string): void;
|
|
14
|
-
export declare function getPgEnum(schema: string | PgSchema, enumeration: Enumeration, context?: ConverterContext): PgEnum<[string, ...string[]]>;
|
|
15
|
-
export {};
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { toCamelCase, toSnakeCase } from 'drizzle-orm/casing';
|
|
2
|
-
import { boolean, check, doublePrecision, foreignKey, index, integer, jsonb, pgSchema, primaryKey, text, unique, uniqueIndex, uuid } from 'drizzle-orm/pg-core';
|
|
3
|
-
import { MultiKeyMap } from '../../../data-structures/multi-key-map.js';
|
|
4
|
-
import { tryGetEnumName } from '../../../enumeration/enumeration.js';
|
|
5
|
-
import { NotSupportedError } from '../../../errors/not-supported.error.js';
|
|
6
|
-
import { JsonPath } from '../../../json-path/json-path.js';
|
|
7
|
-
import { reflectionRegistry } from '../../../reflection/registry.js';
|
|
8
|
-
import { ArraySchema, BooleanSchema, DefaultSchema, EnumerationSchema, getObjectSchema, NullableSchema, NumberSchema, ObjectSchema, OptionalSchema, StringSchema, Uint8ArraySchema } from '../../../schema/index.js';
|
|
9
|
-
import { compareByValueSelectionToOrder, orderRest } from '../../../utils/comparison.js';
|
|
10
|
-
import { decodeText, encodeUtf8 } from '../../../utils/encoding.js';
|
|
11
|
-
import { enumValues } from '../../../utils/enum.js';
|
|
12
|
-
import { memoize, memoizeSingle } from '../../../utils/function/memoize.js';
|
|
13
|
-
import { compileDereferencer } from '../../../utils/object/dereference.js';
|
|
14
|
-
import { fromEntries, objectEntries } from '../../../utils/object/object.js';
|
|
15
|
-
import { assertDefined, assertDefinedPass, isArray, isDefined, isNotNullOrUndefined, isNull, isString, isUndefined } from '../../../utils/type-guards.js';
|
|
16
|
-
import { bytea, numericDate, timestamp } from '../../data-types/index.js';
|
|
17
|
-
import { JsonSchema } from '../../schemas/json.js';
|
|
18
|
-
import { NumericDateSchema } from '../../schemas/numeric-date.js';
|
|
19
|
-
import { TimestampSchema } from '../../schemas/timestamp.js';
|
|
20
|
-
import { UuidSchema } from '../../schemas/uuid.js';
|
|
21
|
-
import { decryptBytes, encryptBytes } from '../encryption.js';
|
|
22
|
-
import { convertQuery } from '../query-converter.js';
|
|
23
|
-
const getDbSchema = memoizeSingle(pgSchema);
|
|
24
|
-
export const getDrizzleTableFromType = memoize(_getDrizzleTableFromType);
|
|
25
|
-
const columnDefinitionsSymbol = Symbol('columnDefinitions');
|
|
26
|
-
const columnDefinitionsMapSymbol = Symbol('columnDefinitionsMap');
|
|
27
|
-
export function getColumnDefinitions(table) {
|
|
28
|
-
return table[columnDefinitionsSymbol];
|
|
29
|
-
}
|
|
30
|
-
export function getColumnDefinitionsMap(table) {
|
|
31
|
-
return table[columnDefinitionsMapSymbol];
|
|
32
|
-
}
|
|
33
|
-
export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
34
|
-
const metadata = reflectionRegistry.getMetadata(type);
|
|
35
|
-
assertDefined(metadata, `Type ${type.name} does not have reflection metadata.`);
|
|
36
|
-
const tableReflectionDatas = [];
|
|
37
|
-
for (let currentMetadata = metadata; isNotNullOrUndefined(currentMetadata?.parent); currentMetadata = reflectionRegistry.getMetadata(currentMetadata.parent)) {
|
|
38
|
-
const tableReflectionData = currentMetadata.data.tryGet('orm');
|
|
39
|
-
if (isDefined(tableReflectionData)) {
|
|
40
|
-
tableReflectionDatas.push(tableReflectionData);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
const mergedTableReflectionData = tableReflectionDatas.reduceRight((merged, data) => ({ ...merged, ...data }), {});
|
|
44
|
-
const tableReflectionData = tableReflectionDatas[0];
|
|
45
|
-
const schema = assertDefinedPass(mergedTableReflectionData.schema ?? fallbackSchemaName, 'Table schema not provided');
|
|
46
|
-
const tableName = tableReflectionData?.name ?? getDefaultTableName(type);
|
|
47
|
-
const dbSchema = getDbSchema(schema);
|
|
48
|
-
const columnDefinitions = getPostgresColumnEntries(type, dbSchema, tableName);
|
|
49
|
-
const columnDefinitionsMap = new Map(columnDefinitions.map((column) => [column.objectPath.path, column]));
|
|
50
|
-
function getColumn(table, propertyName) {
|
|
51
|
-
return assertDefinedPass(table[propertyName], `Property "${propertyName}" does not exist on ${type.name}`);
|
|
52
|
-
}
|
|
53
|
-
function buildIndex(table, data, columnName) {
|
|
54
|
-
const columns = (data.columns ?? [columnName]).map((columnValue) => {
|
|
55
|
-
assertDefined(columnValue, 'Missing column name for index.');
|
|
56
|
-
const [columnName, columnOrder] = isString(columnValue) ? [columnValue] : columnValue;
|
|
57
|
-
const order = columnOrder ?? data.order ?? 'asc';
|
|
58
|
-
let column = getColumn(table, columnName);
|
|
59
|
-
column = column[order]();
|
|
60
|
-
if (data.options?.nulls == 'first') {
|
|
61
|
-
column = column.nullsFirst();
|
|
62
|
-
}
|
|
63
|
-
else if (data.options?.nulls == 'last') {
|
|
64
|
-
column = column.nullsLast();
|
|
65
|
-
}
|
|
66
|
-
return column;
|
|
67
|
-
});
|
|
68
|
-
const indexFn = (data.options?.unique == true) ? uniqueIndex : index;
|
|
69
|
-
let builder = indexFn(data.options?.name ?? getIndexName(tableName, columns, { naming: data.options?.naming })).using(data.options?.using ?? 'btree', ...columns);
|
|
70
|
-
if (isDefined(data.options?.where)) {
|
|
71
|
-
const query = convertQuery(data.options.where(table), table, columnDefinitionsMap);
|
|
72
|
-
builder = builder.where(query.inlineParams());
|
|
73
|
-
}
|
|
74
|
-
return builder;
|
|
75
|
-
}
|
|
76
|
-
function buildPrimaryKey(table) {
|
|
77
|
-
const columns = primaryKeyColumnDefinitions.map((columnDefinition) => getColumn(table, columnDefinition.name));
|
|
78
|
-
return primaryKey({
|
|
79
|
-
name: mergedTableReflectionData.compundPrimaryKeyName ?? getPrimaryKeyName(tableName, columns, { naming: mergedTableReflectionData.compundPrimaryKeyNaming }),
|
|
80
|
-
columns,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
const primaryKeyColumnDefinitions = columnDefinitions.filter((columnDefinition) => columnDefinition.reflectionData?.primaryKey == true);
|
|
84
|
-
const skipPrimaryKey = primaryKeyColumnDefinitions.length > 1;
|
|
85
|
-
const columnEntries = columnDefinitions.map((entry) => [entry.name, entry.buildType({ skipPrimaryKey })]);
|
|
86
|
-
const drizzleSchema = dbSchema.table(tableName, fromEntries(columnEntries), (table) => [
|
|
87
|
-
...((primaryKeyColumnDefinitions.length > 1)
|
|
88
|
-
? [buildPrimaryKey(table)]
|
|
89
|
-
: []),
|
|
90
|
-
...(columnDefinitions.map((columnDefinition) => {
|
|
91
|
-
const indexData = columnDefinition.reflectionData?.index;
|
|
92
|
-
if (isUndefined(indexData)) {
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
return buildIndex(table, indexData, columnDefinition.name);
|
|
96
|
-
}).filter(isDefined)),
|
|
97
|
-
...tableReflectionDatas.flatMap((tableReflectionData) => {
|
|
98
|
-
return tableReflectionData.foreignKeys?.map((foreignKeyData) => {
|
|
99
|
-
const foreignTable = getDrizzleTableFromType(foreignKeyData.target(), dbSchema.schemaName);
|
|
100
|
-
return foreignKey({
|
|
101
|
-
name: foreignKeyData.options?.name ?? getForeignKeyName(tableName, foreignKeyData.columns, { naming: foreignKeyData.options?.naming }),
|
|
102
|
-
columns: foreignKeyData.columns.map((column) => getColumn(table, column)),
|
|
103
|
-
foreignColumns: foreignKeyData.foreignColumns.map((column) => getColumn(foreignTable, column)),
|
|
104
|
-
});
|
|
105
|
-
}) ?? [];
|
|
106
|
-
}),
|
|
107
|
-
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.unique).filter(isDefined).map((data) => {
|
|
108
|
-
const columns = data.columns?.map((column) => getColumn(table, column));
|
|
109
|
-
let constraint = unique(data.options?.name ?? getUniqueName(tableName, columns, { naming: data.options?.naming })).on(...columns);
|
|
110
|
-
if (data.options?.nulls == 'not distinct') {
|
|
111
|
-
constraint = constraint.nullsNotDistinct();
|
|
112
|
-
}
|
|
113
|
-
return constraint;
|
|
114
|
-
}),
|
|
115
|
-
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.index).filter(isDefined).map((data) => buildIndex(table, data)),
|
|
116
|
-
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.checks).filter(isDefined).map((data) => check(data.name, data.builder(table))),
|
|
117
|
-
]);
|
|
118
|
-
drizzleSchema[columnDefinitionsSymbol] = columnDefinitions;
|
|
119
|
-
drizzleSchema[columnDefinitionsMapSymbol] = columnDefinitionsMap;
|
|
120
|
-
return drizzleSchema;
|
|
121
|
-
}
|
|
122
|
-
function getPostgresColumnEntries(type, dbSchema, tableName, path = new JsonPath({ dollar: false }), prefix = '') {
|
|
123
|
-
const metadata = reflectionRegistry.getMetadata(type);
|
|
124
|
-
assertDefined(metadata, `Type ${type.name} does not have reflection metadata (path: ${path.toString()}).`);
|
|
125
|
-
const objectSchema = getObjectSchema(type);
|
|
126
|
-
const entries = objectEntries(objectSchema.properties).toSorted(compareByValueSelectionToOrder(['id', orderRest, 'metadata'], (item) => item[0])).flatMap(([property, schema]) => {
|
|
127
|
-
const columnReflectionData = metadata.properties.get(property)?.data.tryGet('orm');
|
|
128
|
-
const columnName = columnReflectionData?.name ?? toSnakeCase(property);
|
|
129
|
-
if ((schema instanceof ObjectSchema) && !(schema instanceof JsonSchema)) {
|
|
130
|
-
const propertyMetadata = reflectionRegistry.getMetadata(type)?.properties.get(property);
|
|
131
|
-
assertDefined(propertyMetadata, `Property "${property}" of type "${type.name}" does not have reflection metadata (path: ${path.toString()}).`);
|
|
132
|
-
const propertyPrefix = columnReflectionData?.embedded?.prefix;
|
|
133
|
-
const nestedPrefix = [prefix, isNull(propertyPrefix) ? '' : propertyPrefix ?? `${columnName}_`].join('');
|
|
134
|
-
return getPostgresColumnEntries(columnReflectionData?.embedded?.type ?? propertyMetadata.type, dbSchema, tableName, path.add(property), nestedPrefix);
|
|
135
|
-
}
|
|
136
|
-
const objectPath = path.add(property);
|
|
137
|
-
const encrypted = columnReflectionData?.encrypted == true;
|
|
138
|
-
const toDatabase = encrypted
|
|
139
|
-
? async (value, context) => {
|
|
140
|
-
const bytes = encodeUtf8(value);
|
|
141
|
-
return await encryptBytes(bytes, context.encryptionKey);
|
|
142
|
-
}
|
|
143
|
-
: (value) => value;
|
|
144
|
-
const fromDatabase = encrypted
|
|
145
|
-
? async (value, context) => {
|
|
146
|
-
const decrypted = await decryptBytes(value, context.encryptionKey);
|
|
147
|
-
return decodeText(decrypted);
|
|
148
|
-
}
|
|
149
|
-
: (value) => value;
|
|
150
|
-
const prefixedColumnName = [prefix, columnName].join('');
|
|
151
|
-
return [{
|
|
152
|
-
name: toCamelCase(prefixedColumnName),
|
|
153
|
-
objectPath,
|
|
154
|
-
reflectionData: columnReflectionData,
|
|
155
|
-
buildType: (options) => getPostgresColumn(tableName, toSnakeCase(prefixedColumnName), dbSchema, schema, columnReflectionData ?? {}, options, { type, property }),
|
|
156
|
-
dereferenceObjectPath: compileDereferencer(objectPath, { optional: true }),
|
|
157
|
-
toDatabase,
|
|
158
|
-
fromDatabase,
|
|
159
|
-
}];
|
|
160
|
-
});
|
|
161
|
-
return entries;
|
|
162
|
-
}
|
|
163
|
-
function getPostgresColumn(tableName, columnName, dbSchema, propertySchema, reflectionData, options, context) {
|
|
164
|
-
let nullable = false;
|
|
165
|
-
let array = false;
|
|
166
|
-
let baseSchema = propertySchema;
|
|
167
|
-
while (true) {
|
|
168
|
-
if ((baseSchema instanceof NullableSchema) || (baseSchema instanceof OptionalSchema)) {
|
|
169
|
-
nullable = true;
|
|
170
|
-
baseSchema = baseSchema.schema;
|
|
171
|
-
}
|
|
172
|
-
else if (baseSchema instanceof ArraySchema) {
|
|
173
|
-
array = true;
|
|
174
|
-
baseSchema = baseSchema.itemSchema;
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
let column = getPostgresBaseColumn(columnName, dbSchema, baseSchema, reflectionData, context);
|
|
181
|
-
if (array) {
|
|
182
|
-
column = column.array();
|
|
183
|
-
}
|
|
184
|
-
if (!nullable) {
|
|
185
|
-
column = column.notNull();
|
|
186
|
-
}
|
|
187
|
-
if (isDefined(reflectionData.unique)) {
|
|
188
|
-
column = column.unique(reflectionData.unique.options?.name ?? getUniqueName(tableName, [columnName], { naming: reflectionData.unique.options?.naming }), isString(reflectionData.unique.options?.nulls) ? { nulls: reflectionData.unique.options.nulls } : undefined);
|
|
189
|
-
}
|
|
190
|
-
if ((reflectionData.primaryKey == true) && (options.skipPrimaryKey != true)) {
|
|
191
|
-
column = column.primaryKey();
|
|
192
|
-
}
|
|
193
|
-
for (const { target, targetColumn } of reflectionData.references ?? []) {
|
|
194
|
-
column = column.references(() => {
|
|
195
|
-
const targetTable = getDrizzleTableFromType(target(), dbSchema.schemaName);
|
|
196
|
-
return targetTable[(targetColumn ?? 'id')];
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
if (isDefined(reflectionData.references)) {
|
|
200
|
-
}
|
|
201
|
-
return column;
|
|
202
|
-
}
|
|
203
|
-
function getPostgresBaseColumn(columnName, dbSchema, schema, reflectionData, context) {
|
|
204
|
-
if (schema instanceof DefaultSchema) {
|
|
205
|
-
const column = getPostgresBaseColumn(columnName, dbSchema, schema.schema, reflectionData, context);
|
|
206
|
-
return column.default(schema.defaultValue);
|
|
207
|
-
}
|
|
208
|
-
if (reflectionData.encrypted) {
|
|
209
|
-
return bytea(columnName);
|
|
210
|
-
}
|
|
211
|
-
if (schema instanceof UuidSchema) {
|
|
212
|
-
let column = uuid(columnName);
|
|
213
|
-
if (schema.defaultRandom) {
|
|
214
|
-
column = column.defaultRandom();
|
|
215
|
-
}
|
|
216
|
-
return column;
|
|
217
|
-
}
|
|
218
|
-
if (schema instanceof TimestampSchema) {
|
|
219
|
-
return timestamp(columnName);
|
|
220
|
-
}
|
|
221
|
-
if (schema instanceof NumericDateSchema) {
|
|
222
|
-
return numericDate(columnName);
|
|
223
|
-
}
|
|
224
|
-
if (schema instanceof NumberSchema) {
|
|
225
|
-
return schema.integer
|
|
226
|
-
? integer(columnName)
|
|
227
|
-
: doublePrecision(columnName);
|
|
228
|
-
}
|
|
229
|
-
if (schema instanceof StringSchema) {
|
|
230
|
-
return text(columnName);
|
|
231
|
-
}
|
|
232
|
-
if (schema instanceof BooleanSchema) {
|
|
233
|
-
return boolean(columnName);
|
|
234
|
-
}
|
|
235
|
-
if (schema instanceof EnumerationSchema) {
|
|
236
|
-
const pgEnum = getPgEnum(dbSchema, schema.enumeration, context);
|
|
237
|
-
return pgEnum(columnName);
|
|
238
|
-
}
|
|
239
|
-
if (schema instanceof JsonSchema) {
|
|
240
|
-
return jsonb(columnName);
|
|
241
|
-
}
|
|
242
|
-
if (schema instanceof Uint8ArraySchema) {
|
|
243
|
-
return bytea(columnName);
|
|
244
|
-
}
|
|
245
|
-
throw new NotSupportedError(`Schema "${schema.constructor.name}" not supported on type "${context.type.name}" for property "${context.property}"`);
|
|
246
|
-
}
|
|
247
|
-
const enumNames = new Map();
|
|
248
|
-
const enums = new MultiKeyMap();
|
|
249
|
-
export function registerEnum(enumeration, name) {
|
|
250
|
-
enumNames.set(enumeration, toSnakeCase(name));
|
|
251
|
-
}
|
|
252
|
-
export function getPgEnum(schema, enumeration, context) {
|
|
253
|
-
const dbSchema = isString(schema) ? getDbSchema(schema) : schema;
|
|
254
|
-
const enumName = enumNames.get(enumeration) ?? tryGetEnumName(enumeration);
|
|
255
|
-
if (isUndefined(enumName)) {
|
|
256
|
-
const errorMessage = 'Enum is not registered. Please register it using `databaseSchema.getEnum(MyEnum)` before use.';
|
|
257
|
-
if (isDefined(context)) {
|
|
258
|
-
throw new Error(`${errorMessage} (type: ${context.type.name}, property: ${context.property})`);
|
|
259
|
-
}
|
|
260
|
-
throw new Error(errorMessage);
|
|
261
|
-
}
|
|
262
|
-
const values = (isArray(enumeration) ? enumeration : enumValues(enumeration))
|
|
263
|
-
.map((value) => value.toString());
|
|
264
|
-
const dbEnum = dbSchema.enum(toSnakeCase(enumName), values);
|
|
265
|
-
if (enums.has([dbSchema.schemaName, enumeration])) {
|
|
266
|
-
enums.set([dbSchema.schemaName, enumeration], dbEnum);
|
|
267
|
-
}
|
|
268
|
-
return dbEnum;
|
|
269
|
-
}
|
|
270
|
-
function getDefaultTableName(type) {
|
|
271
|
-
return toSnakeCase(isString(type.entityName) ? type.entityName : type.name.replace(/\d+$/u, ''));
|
|
272
|
-
}
|
|
273
|
-
function getPrimaryKeyName(tableName, columns, options) {
|
|
274
|
-
return getIdentifier(tableName, columns, 'pk', options);
|
|
275
|
-
}
|
|
276
|
-
function getIndexName(tableName, columns, options) {
|
|
277
|
-
return getIdentifier(tableName, columns, 'idx', options);
|
|
278
|
-
}
|
|
279
|
-
function getUniqueName(tableName, columns, options) {
|
|
280
|
-
return getIdentifier(tableName, columns, 'unique', options);
|
|
281
|
-
}
|
|
282
|
-
function getForeignKeyName(tableName, columns, options) {
|
|
283
|
-
return getIdentifier(tableName, columns, 'fkey', options);
|
|
284
|
-
}
|
|
285
|
-
function getIdentifier(tableName, columns, suffix, options) {
|
|
286
|
-
const identifier = `${getTablePrefix(tableName, options?.naming)}_${getColumnNames(columns).join('_')}_${suffix}`;
|
|
287
|
-
if (identifier.length > 63) {
|
|
288
|
-
if (options?.naming != 'abbreviated-table') {
|
|
289
|
-
return getIdentifier(tableName, columns, suffix, { naming: 'abbreviated-table' });
|
|
290
|
-
}
|
|
291
|
-
throw new Error(`Identifier "${identifier}" for table "${tableName}" is too long. Maximum length is 63 characters.`);
|
|
292
|
-
}
|
|
293
|
-
return identifier;
|
|
294
|
-
}
|
|
295
|
-
function getTablePrefix(tableName, naming) {
|
|
296
|
-
return (naming == 'abbreviated-table') ? tableName.split('_').map((part) => part[0]).join('') : tableName;
|
|
297
|
-
}
|
|
298
|
-
function getColumnNames(columns) {
|
|
299
|
-
return columns.map((column) => isString(column) ? column : column.name);
|
|
300
|
-
}
|
|
File without changes
|