@tstdl/base 0.92.142 → 0.92.143
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 +1 -1
- package/ai/ai.service.js +3 -3
- package/ai/types.d.ts +1 -1
- package/api/client/client.d.ts +1 -1
- package/api/client/client.js +10 -4
- package/api/server/middlewares/content-type.middleware.js +8 -7
- package/api/types.js +1 -1
- package/authentication/client/authentication.service.js +3 -3
- package/authentication/server/authentication-ancillary.service.d.ts +11 -1
- package/authentication/server/authentication-ancillary.service.js +1 -1
- package/authentication/server/authentication-secret-requirements.validator.js +1 -1
- package/authentication/server/authentication.api-controller.js +22 -10
- package/authentication/server/authentication.service.d.ts +11 -5
- package/authentication/server/authentication.service.js +97 -49
- package/authentication/server/drizzle.config.js +2 -2
- package/authentication/server/module.js +1 -1
- package/cancellation/token.d.ts +2 -2
- package/cancellation/token.js +4 -4
- package/cookie/cookie.js +2 -2
- package/document-management/api/document-management.api.d.ts +122 -24
- package/document-management/api/document-management.api.js +17 -0
- package/document-management/{server/services → authorization}/document-management-authorization.service.d.ts +7 -7
- package/document-management/authorization/document-management-authorization.service.js +2 -0
- package/document-management/authorization/index.d.ts +2 -0
- package/document-management/authorization/index.js +2 -0
- package/document-management/authorization/policies.d.ts +38 -0
- package/document-management/authorization/policies.js +2 -0
- package/document-management/index.d.ts +1 -0
- package/document-management/index.js +1 -0
- package/document-management/models/document-assignment-scope.model.d.ts +1 -0
- package/document-management/models/document-assignment-scope.model.js +10 -3
- package/document-management/models/document-assignment-task.model.d.ts +1 -0
- package/document-management/models/document-assignment-task.model.js +8 -2
- package/document-management/models/document-category.model.d.ts +1 -0
- package/document-management/models/document-category.model.js +7 -1
- package/document-management/models/document-collection-assignment.model.d.ts +1 -0
- package/document-management/models/document-collection-assignment.model.js +12 -4
- package/document-management/models/document-collection.model.d.ts +2 -0
- package/document-management/models/document-collection.model.js +8 -2
- package/document-management/models/document-management-table.d.ts +3 -1
- package/document-management/models/document-management-table.js +2 -2
- package/document-management/models/document-property-value.model.d.ts +1 -0
- package/document-management/models/document-property-value.model.js +9 -3
- package/document-management/models/document-property.model.d.ts +1 -0
- package/document-management/models/document-property.model.js +8 -2
- package/document-management/models/document-request-collection-assignment.model.d.ts +1 -0
- package/document-management/models/document-request-collection-assignment.model.js +12 -4
- package/document-management/models/document-request-template.d.ts +1 -0
- package/document-management/models/document-request-template.js +6 -1
- package/document-management/models/document-request.model.d.ts +1 -0
- package/document-management/models/document-request.model.js +10 -1
- package/document-management/models/document-requests-template.d.ts +1 -0
- package/document-management/models/document-requests-template.js +7 -3
- package/document-management/models/document-tag-assignment.model.d.ts +8 -0
- package/document-management/models/document-tag-assignment.model.js +40 -0
- package/document-management/models/document-tag.model.d.ts +6 -0
- package/document-management/models/{document-request-submission.model.js → document-tag.model.js} +14 -18
- package/document-management/models/document-type-property.model.d.ts +1 -0
- package/document-management/models/document-type-property.model.js +7 -2
- package/document-management/models/document-type-validation.model.d.ts +1 -0
- package/document-management/models/document-type-validation.model.js +8 -2
- package/document-management/models/document-type.model.d.ts +1 -0
- package/document-management/models/document-type.model.js +7 -2
- package/document-management/models/document-validation-definition.model.d.ts +1 -0
- package/document-management/models/document-validation-definition.model.js +7 -2
- package/document-management/models/document-validation-execution-related-document.model.d.ts +1 -0
- package/document-management/models/document-validation-execution-related-document.model.js +10 -3
- package/document-management/models/document-validation-execution.model.d.ts +1 -0
- package/document-management/models/document-validation-execution.model.js +9 -3
- package/document-management/models/document-workflow.model.d.ts +4 -1
- package/document-management/models/document-workflow.model.js +16 -4
- package/document-management/models/document.model.d.ts +2 -2
- package/document-management/models/document.model.js +9 -8
- package/document-management/models/index.d.ts +2 -1
- package/document-management/models/index.js +2 -1
- package/document-management/server/api/document-management.api.d.ts +4 -1
- package/document-management/server/api/document-management.api.js +113 -22
- package/document-management/server/configure.d.ts +2 -2
- package/document-management/server/configure.js +7 -7
- package/document-management/server/drizzle/0000_parallel_mantis.sql +359 -0
- package/document-management/server/drizzle/meta/0000_snapshot.json +784 -260
- package/document-management/server/drizzle/meta/_journal.json +2 -2
- package/document-management/server/module.d.ts +2 -2
- package/document-management/server/module.js +2 -2
- package/document-management/server/schemas.d.ts +6 -5
- package/document-management/server/schemas.js +12 -11
- package/document-management/server/services/document-category-type.service.d.ts +19 -10
- package/document-management/server/services/document-category-type.service.js +34 -27
- package/document-management/server/services/document-collection.service.d.ts +13 -6
- package/document-management/server/services/document-collection.service.js +36 -12
- package/document-management/server/services/document-file.service.d.ts +8 -7
- package/document-management/server/services/document-file.service.js +28 -33
- package/document-management/server/services/document-management-ai.service.d.ts +5 -4
- package/document-management/server/services/document-management-ai.service.js +51 -28
- package/document-management/server/services/document-management-ancillary.service.d.ts +3 -21
- package/document-management/server/services/document-management-ancillary.service.js +0 -24
- package/document-management/server/services/document-management-observation.service.d.ts +15 -0
- package/document-management/server/services/document-management-observation.service.js +160 -0
- package/document-management/server/services/document-management.service.d.ts +6 -5
- package/document-management/server/services/document-management.service.js +112 -86
- package/document-management/server/services/document-property.service.d.ts +15 -7
- package/document-management/server/services/document-property.service.js +52 -20
- package/document-management/server/services/document-request.service.d.ts +13 -24
- package/document-management/server/services/document-request.service.js +39 -62
- package/document-management/server/services/document-tag.service.d.ts +10 -0
- package/document-management/server/services/document-tag.service.js +59 -0
- package/document-management/server/services/document-validation.service.d.ts +8 -8
- package/document-management/server/services/document-validation.service.js +41 -40
- package/document-management/server/services/document-workflow.service.d.ts +6 -5
- package/document-management/server/services/document-workflow.service.js +54 -43
- package/document-management/server/services/document.service.d.ts +12 -11
- package/document-management/server/services/document.service.js +64 -40
- package/document-management/server/services/index.d.ts +2 -1
- package/document-management/server/services/index.js +2 -1
- package/document-management/server/services/singleton.js +2 -2
- package/document-management/server/validators/ai-validation-executor.js +4 -4
- package/document-management/service-models/document-collection-metadata.service-model.d.ts +14 -0
- package/document-management/service-models/document-collection-metadata.service-model.js +1 -0
- package/document-management/service-models/document-folders.view-model.d.ts +1 -7
- package/document-management/service-models/document-folders.view-model.js +3 -15
- package/document-management/service-models/document-management.view-model.d.ts +20 -6
- package/document-management/service-models/document-management.view-model.js +62 -8
- package/document-management/service-models/document.service-model.d.ts +14 -11
- package/document-management/service-models/document.service-model.js +11 -2
- package/document-management/service-models/enriched/enriched-document-assignment.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document-assignment.view.js +0 -2
- package/document-management/service-models/enriched/enriched-document-category.view.d.ts +11 -1
- package/document-management/service-models/enriched/enriched-document-category.view.js +44 -1
- package/document-management/service-models/enriched/enriched-document-collection.view.d.ts +4 -2
- package/document-management/service-models/enriched/enriched-document-collection.view.js +13 -3
- package/document-management/service-models/enriched/enriched-document-management-data.view.d.ts +2 -0
- package/document-management/service-models/enriched/enriched-document-management-data.view.js +4 -2
- package/document-management/service-models/enriched/enriched-document-request.view.d.ts +1 -0
- package/document-management/service-models/enriched/enriched-document-request.view.js +2 -0
- package/document-management/service-models/enriched/enriched-document-type.view.d.ts +9 -1
- package/document-management/service-models/enriched/enriched-document-type.view.js +28 -1
- package/document-management/service-models/enriched/enriched-document.view.d.ts +7 -6
- package/document-management/service-models/enriched/enriched-document.view.js +29 -6
- package/document-management/service-models/{normalized-requests-template-data.model.d.ts → enriched/enriched-requests-template-data.model.d.ts} +6 -6
- package/document-management/service-models/{normalized-requests-template-data.model.js → enriched/enriched-requests-template-data.model.js} +1 -1
- package/document-management/service-models/enriched/index.d.ts +1 -0
- package/document-management/service-models/enriched/index.js +1 -0
- package/document-management/service-models/index.d.ts +2 -2
- package/document-management/service-models/index.js +2 -2
- package/examples/document-management/categories-and-types.d.ts +33 -31
- package/examples/document-management/categories-and-types.js +33 -0
- package/examples/document-management/main.d.ts +5 -4
- package/examples/document-management/main.js +13 -7
- package/function/log.js +2 -2
- package/http/server/node/module.d.ts +4 -1
- package/http/server/node/module.js +10 -1
- package/http/server/node/node-http-server.d.ts +3 -6
- package/http/server/node/node-http-server.js +68 -67
- package/injector/inject.js +6 -6
- package/injector/injector.js +3 -3
- package/jsx/is-component-class.js +1 -1
- package/key-value-store/key-value.store.d.ts +38 -7
- package/key-value-store/key-value.store.js +2 -1
- package/key-value-store/mongo/mongo-key-value.store.d.ts +1 -0
- package/key-value-store/mongo/mongo-key-value.store.js +14 -5
- package/key-value-store/postgres/drizzle/0000_shocking_slipstream.sql +12 -0
- package/key-value-store/postgres/drizzle/meta/0000_snapshot.json +97 -0
- package/key-value-store/postgres/drizzle/meta/_journal.json +13 -0
- package/key-value-store/postgres/drizzle.config.d.ts +2 -0
- package/key-value-store/postgres/drizzle.config.js +11 -0
- package/key-value-store/postgres/index.d.ts +2 -0
- package/key-value-store/postgres/index.js +2 -0
- package/key-value-store/postgres/key-value-store.service.d.ts +17 -0
- package/key-value-store/postgres/key-value-store.service.js +65 -0
- package/key-value-store/postgres/models/index.d.ts +2 -0
- package/key-value-store/postgres/models/index.js +2 -0
- package/key-value-store/postgres/models/key-value.model.d.ts +7 -0
- package/key-value-store/postgres/models/key-value.model.js +35 -0
- package/key-value-store/postgres/models/schemas.d.ts +3 -0
- package/key-value-store/postgres/models/schemas.js +4 -0
- package/key-value-store/postgres/module.d.ts +6 -0
- package/key-value-store/postgres/module.js +23 -0
- package/lock/web/web-lock.d.ts +0 -1
- package/lock/web/web-lock.js +6 -13
- package/orm/data-types/timestamp.js +1 -1
- package/orm/decorators.d.ts +37 -29
- package/orm/decorators.js +44 -24
- package/orm/entity.d.ts +1 -0
- package/orm/query.d.ts +10 -2
- package/orm/repository.types.d.ts +2 -1
- package/orm/schemas/json.d.ts +12 -6
- package/orm/schemas/json.js +12 -5
- package/orm/server/database.js +5 -2
- package/orm/server/drizzle/schema-converter.js +40 -11
- package/orm/server/query-converter.d.ts +2 -1
- package/orm/server/query-converter.js +57 -34
- package/orm/server/repository.d.ts +26 -43
- package/orm/server/repository.js +106 -39
- package/orm/server/transaction.d.ts +2 -1
- package/orm/server/transaction.js +3 -0
- package/orm/server/transactional.d.ts +5 -1
- package/orm/server/transactional.js +34 -4
- package/package.json +14 -11
- package/process/spawn.js +0 -1
- package/promise/deferred-promise.d.ts +4 -3
- package/promise/deferred-promise.js +13 -5
- package/queue/postgres/queue.js +8 -8
- package/reflection/utils.js +3 -3
- package/schema/decorators/class.js +0 -1
- package/schema/decorators/schema.js +1 -1
- package/schema/schemas/boolean.d.ts +1 -1
- package/schema/schemas/boolean.js +2 -2
- package/schema/schemas/number.js +3 -3
- package/schema/schemas/object.js +5 -6
- package/sse/server-sent-events-source.js +4 -1
- package/utils/compression.js +9 -9
- package/utils/date-time.d.ts +1 -0
- package/utils/date-time.js +18 -4
- package/utils/equals.d.ts +7 -0
- package/utils/equals.js +17 -2
- package/utils/function/memoize.js +10 -2
- package/utils/jwt.js +3 -3
- package/utils/object/property-name.d.ts +2 -2
- package/utils/timing.d.ts +2 -2
- package/utils/timing.js +12 -12
- package/document-management/models/document-request-submission.model.d.ts +0 -7
- package/document-management/server/drizzle/0000_moaning_luckman.sql +0 -305
- package/document-management/server/services/document-management-authorization.service.js +0 -28
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Singleton, injectArgument, provide } from '../../injector/index.js';
|
|
8
|
+
import { DatabaseConfig, Transactional } from '../../orm/server/index.js';
|
|
9
|
+
import { EntityRepositoryConfig, injectRepository } from '../../orm/server/repository.js';
|
|
10
|
+
import { objectEntries } from '../../utils/object/object.js';
|
|
11
|
+
import { assertDefinedPass, isDefined, isUndefined } from '../../utils/type-guards.js';
|
|
12
|
+
import { KeyValueStore } from '../key-value.store.js';
|
|
13
|
+
import { KeyValue } from './models/index.js';
|
|
14
|
+
import { PostgresKeyValueStoreModuleConfig } from './module.js';
|
|
15
|
+
let PostgresKeyValueStore = class PostgresKeyValueStore extends Transactional {
|
|
16
|
+
#keyValueRepository = injectRepository(KeyValue);
|
|
17
|
+
module = assertDefinedPass(injectArgument(this), 'KeyValueStore module must be passed as argument.');
|
|
18
|
+
async get(key, defaultValue) {
|
|
19
|
+
const result = await this.#keyValueRepository.tryLoadByQuery({ module: this.module, key: key });
|
|
20
|
+
if (isUndefined(result)) {
|
|
21
|
+
return defaultValue;
|
|
22
|
+
}
|
|
23
|
+
return result.value;
|
|
24
|
+
}
|
|
25
|
+
async set(key, value) {
|
|
26
|
+
await this.#keyValueRepository.upsert(['module', 'key'], { module: this.module, key: key, value });
|
|
27
|
+
}
|
|
28
|
+
async getOrSet(key, value) {
|
|
29
|
+
const keyValue = await this.#keyValueRepository.transaction(async (tx) => {
|
|
30
|
+
const keyValue = await this.#keyValueRepository.withTransaction(tx).insertIfNotExists(['module', 'key'], { module: this.module, key: key, value });
|
|
31
|
+
if (isDefined(keyValue)) {
|
|
32
|
+
return keyValue;
|
|
33
|
+
}
|
|
34
|
+
return await this.#keyValueRepository.withTransaction(tx).loadByQuery({ module: this.module, key: key });
|
|
35
|
+
});
|
|
36
|
+
return keyValue.value;
|
|
37
|
+
}
|
|
38
|
+
async setMany(keyValues) {
|
|
39
|
+
const entries = objectEntries(keyValues).map(([key, value]) => ({
|
|
40
|
+
module: this.module,
|
|
41
|
+
key: key,
|
|
42
|
+
value,
|
|
43
|
+
}));
|
|
44
|
+
await this.#keyValueRepository.upsertMany(['module', 'key'], entries);
|
|
45
|
+
}
|
|
46
|
+
async delete(key) {
|
|
47
|
+
const result = await this.#keyValueRepository.tryDeleteByQuery({ module: this.module, key: key });
|
|
48
|
+
return isDefined(result);
|
|
49
|
+
}
|
|
50
|
+
async deleteMany(keys) {
|
|
51
|
+
await this.#keyValueRepository.deleteManyByQuery({ module: this.module, key: { $in: keys } });
|
|
52
|
+
}
|
|
53
|
+
async clear() {
|
|
54
|
+
await this.#keyValueRepository.hardDeleteManyByQuery({ module: this.module });
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
PostgresKeyValueStore = __decorate([
|
|
58
|
+
Singleton({
|
|
59
|
+
providers: [
|
|
60
|
+
provide(EntityRepositoryConfig, { useValue: { schema: 'key_value_store' } }),
|
|
61
|
+
{ provide: DatabaseConfig, useFactory: (_, context) => context.resolve(PostgresKeyValueStoreModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) },
|
|
62
|
+
],
|
|
63
|
+
})
|
|
64
|
+
], PostgresKeyValueStore);
|
|
65
|
+
export { PostgresKeyValueStore };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Table } from '../../../orm/decorators.js';
|
|
11
|
+
import { Entity } from '../../../orm/entity.js';
|
|
12
|
+
import { Json, Unique } from '../../../orm/types.js';
|
|
13
|
+
import { any, StringProperty } from '../../../schema/index.js';
|
|
14
|
+
let KeyValue = class KeyValue extends Entity {
|
|
15
|
+
module;
|
|
16
|
+
key;
|
|
17
|
+
value;
|
|
18
|
+
};
|
|
19
|
+
__decorate([
|
|
20
|
+
StringProperty(),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], KeyValue.prototype, "module", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
StringProperty(),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], KeyValue.prototype, "key", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
Json({ schema: any() }),
|
|
29
|
+
__metadata("design:type", Object)
|
|
30
|
+
], KeyValue.prototype, "value", void 0);
|
|
31
|
+
KeyValue = __decorate([
|
|
32
|
+
Table('key_value'),
|
|
33
|
+
Unique(['module', 'key'])
|
|
34
|
+
], KeyValue);
|
|
35
|
+
export { KeyValue };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { KeyValue } from './key-value.model.js';
|
|
2
|
+
export declare const keyValueSchema: import("../../../orm/server/database-schema.js").DatabaseSchema<"key_value_store">;
|
|
3
|
+
export declare const keyValue: import("../../../orm/server/types.js").PgTableFromType<typeof KeyValue, "key_value_store">;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type DatabaseConfig } from '../../orm/server/index.js';
|
|
2
|
+
export declare class PostgresKeyValueStoreModuleConfig {
|
|
3
|
+
database?: DatabaseConfig;
|
|
4
|
+
}
|
|
5
|
+
export declare function configurePostgresKeyValueStore(config?: PostgresKeyValueStoreModuleConfig): void;
|
|
6
|
+
export declare function migratePostgresKeyValueStoreSchema(): Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { inject, Injector } from '../../injector/index.js';
|
|
2
|
+
import { Database, migrate } from '../../orm/server/index.js';
|
|
3
|
+
import { isDefined } from '../../utils/type-guards.js';
|
|
4
|
+
import { KeyValueStore } from '../key-value.store.js';
|
|
5
|
+
import { PostgresKeyValueStore } from './key-value-store.service.js';
|
|
6
|
+
export class PostgresKeyValueStoreModuleConfig {
|
|
7
|
+
database;
|
|
8
|
+
}
|
|
9
|
+
export function configurePostgresKeyValueStore(config) {
|
|
10
|
+
if (isDefined(config)) {
|
|
11
|
+
Injector.register(PostgresKeyValueStoreModuleConfig, { useValue: config });
|
|
12
|
+
}
|
|
13
|
+
Injector.registerSingleton(KeyValueStore, { useToken: PostgresKeyValueStore });
|
|
14
|
+
}
|
|
15
|
+
export async function migratePostgresKeyValueStoreSchema() {
|
|
16
|
+
const connection = inject(PostgresKeyValueStoreModuleConfig, undefined, { optional: true })?.database?.connection;
|
|
17
|
+
const database = inject(Database, connection);
|
|
18
|
+
await migrate(database, {
|
|
19
|
+
migrationsSchema: 'key_value_store',
|
|
20
|
+
migrationsTable: '_migrations',
|
|
21
|
+
migrationsFolder: import.meta.resolve('./drizzle').replace('file://', ''),
|
|
22
|
+
});
|
|
23
|
+
}
|
package/lock/web/web-lock.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AcquireResult, LockedFunction, UsingResult } from '../lock.js';
|
|
2
2
|
import { Lock } from '../lock.js';
|
|
3
3
|
export declare class WebLock extends Lock {
|
|
4
|
-
constructor(resource: string);
|
|
5
4
|
acquire<Throw extends boolean>(timeout: number | undefined, throwOnFail: Throw): Promise<AcquireResult<Throw>>;
|
|
6
5
|
use<Throw extends boolean, R>(timeout: number | undefined, throwOnFail: Throw, func: LockedFunction<R>): Promise<UsingResult<Throw, R>>;
|
|
7
6
|
exists(): Promise<boolean>;
|
package/lock/web/web-lock.js
CHANGED
|
@@ -4,20 +4,14 @@ 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
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
7
|
+
import { map, timer } from 'rxjs';
|
|
10
8
|
import { CancellationToken } from '../../cancellation/index.js';
|
|
11
9
|
import { Injectable } from '../../injector/index.js';
|
|
12
10
|
import { DeferredPromise } from '../../promise/deferred-promise.js';
|
|
13
11
|
import { assertStringPass, isDefined, isNull, isObject } from '../../utils/type-guards.js';
|
|
14
|
-
import { map, timer } from 'rxjs';
|
|
15
12
|
import { Lock } from '../lock.js';
|
|
16
13
|
import { WebLockProvider } from './web-lock.provider.js';
|
|
17
14
|
let WebLock = class WebLock extends Lock {
|
|
18
|
-
constructor(resource) {
|
|
19
|
-
super(resource);
|
|
20
|
-
}
|
|
21
15
|
async acquire(timeout, throwOnFail) {
|
|
22
16
|
const acquirePromise = new DeferredPromise();
|
|
23
17
|
const releasePromise = new DeferredPromise();
|
|
@@ -25,12 +19,12 @@ let WebLock = class WebLock extends Lock {
|
|
|
25
19
|
lost: false,
|
|
26
20
|
release() {
|
|
27
21
|
releasePromise.resolve();
|
|
28
|
-
}
|
|
22
|
+
},
|
|
29
23
|
};
|
|
30
24
|
const timeoutToken = (isDefined(timeout) && (timeout > 0)) ? CancellationToken.from(timer(timeout).pipe(map(() => true))) : undefined;
|
|
31
25
|
void navigator.locks.request(this.resource, {
|
|
32
26
|
signal: isDefined(timeoutToken) ? timeoutToken.asAbortSignal() : undefined,
|
|
33
|
-
ifAvailable: isDefined(timeout) && (timeout <= 0)
|
|
27
|
+
ifAvailable: isDefined(timeout) && (timeout <= 0),
|
|
34
28
|
}, async (lock) => {
|
|
35
29
|
if (isNull(lock)) {
|
|
36
30
|
acquirePromise.resolve(false);
|
|
@@ -81,9 +75,8 @@ WebLock = __decorate([
|
|
|
81
75
|
const resource = assertStringPass(isObject(arg) ? arg.resource : arg, 'invalid lock argument');
|
|
82
76
|
const provider = context.resolve(WebLockProvider, prefix);
|
|
83
77
|
return provider.get(resource);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
__metadata("design:paramtypes", [String])
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
})
|
|
88
81
|
], WebLock);
|
|
89
82
|
export { WebLock };
|
package/orm/decorators.d.ts
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
import type { SQL } from 'drizzle-orm';
|
|
6
6
|
import type { LiteralUnion } from 'type-fest';
|
|
7
7
|
import type { AbstractConstructor, TypedOmit } from '../types.js';
|
|
8
|
-
import type { Entity, EntityType, EntityWithoutMetadata } from './entity.js';
|
|
8
|
+
import type { AnyEntity, Entity, EntityType, EntityWithoutMetadata } from './entity.js';
|
|
9
9
|
import type { Query } from './query.js';
|
|
10
|
+
import type { TargetColumnPaths } from './repository.types.js';
|
|
10
11
|
import type { PgTableFromType } from './server/types.js';
|
|
11
12
|
type IndexMethod = LiteralUnion<'hash' | 'btree' | 'gist' | 'spgist' | 'gin' | 'brin' | 'hnsw' | 'ivfflat', string>;
|
|
12
13
|
type NamingStrategy = 'abbreviated-table';
|
|
@@ -34,6 +35,7 @@ export type OrmTableReflectionData = {
|
|
|
34
35
|
unique?: UniqueReflectionData[];
|
|
35
36
|
index?: IndexReflectionData[];
|
|
36
37
|
checks?: CheckReflectionData[];
|
|
38
|
+
foreignKeys?: ForeignKeyReflectionData[];
|
|
37
39
|
};
|
|
38
40
|
/**
|
|
39
41
|
* Reflection data stored for ORM column decorators.
|
|
@@ -50,18 +52,21 @@ export type OrmColumnReflectionData = {
|
|
|
50
52
|
type: AbstractConstructor;
|
|
51
53
|
prefix?: string | null;
|
|
52
54
|
};
|
|
53
|
-
references?:
|
|
55
|
+
references?: {
|
|
56
|
+
target: () => EntityType;
|
|
57
|
+
targetColumn?: TargetColumnPaths<any>;
|
|
58
|
+
}[];
|
|
54
59
|
encrypted?: boolean;
|
|
55
60
|
};
|
|
56
61
|
/**
|
|
57
62
|
* Reflection data for unique constraints.
|
|
58
63
|
*/
|
|
59
64
|
export type UniqueReflectionData = {
|
|
60
|
-
name?: string;
|
|
61
65
|
columns?: string[];
|
|
62
66
|
options?: {
|
|
63
|
-
|
|
67
|
+
name?: string;
|
|
64
68
|
naming?: NamingStrategy;
|
|
69
|
+
nulls?: 'distinct' | 'not distinct';
|
|
65
70
|
};
|
|
66
71
|
};
|
|
67
72
|
/**
|
|
@@ -69,15 +74,15 @@ export type UniqueReflectionData = {
|
|
|
69
74
|
* @template T - The entity type.
|
|
70
75
|
*/
|
|
71
76
|
export type IndexReflectionData<T extends Entity | EntityWithoutMetadata = any> = {
|
|
72
|
-
name?: string;
|
|
73
77
|
columns?: (string | [string, 'asc' | 'desc'])[];
|
|
74
78
|
order?: 'asc' | 'desc';
|
|
75
79
|
options?: {
|
|
80
|
+
name?: string;
|
|
81
|
+
naming?: NamingStrategy;
|
|
76
82
|
using?: IndexMethod;
|
|
77
83
|
unique?: boolean;
|
|
78
84
|
where?: WhereBuilder<T>;
|
|
79
85
|
nulls?: 'first' | 'last';
|
|
80
|
-
naming?: NamingStrategy;
|
|
81
86
|
};
|
|
82
87
|
};
|
|
83
88
|
type CheckReflectionData = {
|
|
@@ -87,6 +92,15 @@ type CheckReflectionData = {
|
|
|
87
92
|
naming?: NamingStrategy;
|
|
88
93
|
};
|
|
89
94
|
};
|
|
95
|
+
export type ForeignKeyReflectionData = {
|
|
96
|
+
target: () => EntityType;
|
|
97
|
+
columns: TargetColumnPaths<any>[];
|
|
98
|
+
foreignColumns: TargetColumnPaths<any>[];
|
|
99
|
+
options?: {
|
|
100
|
+
name?: string;
|
|
101
|
+
naming?: NamingStrategy;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
90
104
|
/**
|
|
91
105
|
* Factory function to create a class decorator for ORM table configuration.
|
|
92
106
|
* Merges provided data with existing ORM reflection data on the class metadata.
|
|
@@ -124,7 +138,8 @@ export declare function PrimaryKey(): PropertyDecorator;
|
|
|
124
138
|
* @param type - A function returning the referenced entity type.
|
|
125
139
|
* @returns A property decorator.
|
|
126
140
|
*/
|
|
127
|
-
export declare function References(
|
|
141
|
+
export declare function References(target: () => EntityType): PropertyDecorator;
|
|
142
|
+
export declare function References<T extends AnyEntity>(target: () => EntityType<T>, targetColumn?: TargetColumnPaths<T>): PropertyDecorator;
|
|
128
143
|
/**
|
|
129
144
|
* Decorator to define a table check constraint.
|
|
130
145
|
* @template T - The entity type.
|
|
@@ -146,7 +161,7 @@ export declare function Encrypted(): PropertyDecorator;
|
|
|
146
161
|
* @returns A property decorator.
|
|
147
162
|
*/
|
|
148
163
|
export declare function Embedded(type: AbstractConstructor, options?: TypedOmit<NonNullable<OrmColumnReflectionData['embedded']>, 'type'>): PropertyDecorator;
|
|
149
|
-
type TableOptions = Partial<Pick<OrmTableReflectionData, 'name' | 'schema'>>;
|
|
164
|
+
export type TableOptions = Partial<Pick<OrmTableReflectionData, 'name' | 'schema'>>;
|
|
150
165
|
/**
|
|
151
166
|
* Decorator to specify the database table name and optionally the schema.
|
|
152
167
|
* @param name - The table name.
|
|
@@ -161,21 +176,23 @@ export declare function Table(name?: string, options?: TypedOmit<TableOptions, '
|
|
|
161
176
|
*/
|
|
162
177
|
export declare function Table(options?: TableOptions): ClassDecorator;
|
|
163
178
|
/**
|
|
164
|
-
* Decorator to define a
|
|
165
|
-
* @param
|
|
166
|
-
* @param
|
|
179
|
+
* Decorator to define a foreign key relationship.
|
|
180
|
+
* @param target - A function returning the referenced entity type.
|
|
181
|
+
* @param columns - The columns in the current entity that form the foreign key.
|
|
182
|
+
* @param foreignColumns - The columns in the referenced entity that the foreign key points to.
|
|
183
|
+
* @param options - Additional foreign key options (e.g., name, naming strategy).
|
|
184
|
+
* @template TThis - The entity type of the current entity.
|
|
185
|
+
* @template TTarget - The entity type of the referenced entity.
|
|
167
186
|
* @returns A property decorator.
|
|
168
187
|
*/
|
|
169
|
-
export declare function
|
|
188
|
+
export declare function ForeignKey<TThis extends AnyEntity, TTarget extends AnyEntity>(target: () => EntityType<TTarget>, columns: Columns<TThis>, foreignColumns: Columns<TTarget>, options?: ForeignKeyReflectionData['options']): ClassDecorator;
|
|
170
189
|
/**
|
|
171
|
-
* Decorator to define a
|
|
172
|
-
* @
|
|
173
|
-
* @param name - The name of the unique constraint.
|
|
174
|
-
* @param columns - An array of property names included in the constraint.
|
|
190
|
+
* Decorator to define a unique constraint on a single column.
|
|
191
|
+
* @param name - Optional name for the unique constraint.
|
|
175
192
|
* @param options - Additional unique constraint options.
|
|
176
|
-
* @returns A
|
|
193
|
+
* @returns A property decorator.
|
|
177
194
|
*/
|
|
178
|
-
export declare function Unique
|
|
195
|
+
export declare function Unique(options?: UniqueReflectionData['options']): PropertyDecorator;
|
|
179
196
|
/**
|
|
180
197
|
* Decorator to define a composite unique constraint on multiple columns.
|
|
181
198
|
* @template T - The entity type.
|
|
@@ -183,7 +200,7 @@ export declare function Unique<T>(name: string | undefined, columns: Columns<T>,
|
|
|
183
200
|
* @param options - Additional unique constraint options.
|
|
184
201
|
* @returns A class decorator.
|
|
185
202
|
*/
|
|
186
|
-
export declare function Unique<T>(columns: Columns<T>, options?: UniqueReflectionData['options']): ClassDecorator;
|
|
203
|
+
export declare function Unique<T extends AnyEntity>(columns: Columns<T>, options?: UniqueReflectionData['options']): ClassDecorator;
|
|
187
204
|
/**
|
|
188
205
|
* Decorator to define an index on a single column.
|
|
189
206
|
* @template T - The entity type.
|
|
@@ -191,16 +208,7 @@ export declare function Unique<T>(columns: Columns<T>, options?: UniqueReflectio
|
|
|
191
208
|
* @param options - Additional index options (e.g., method, uniqueness, conditions).
|
|
192
209
|
* @returns A property decorator.
|
|
193
210
|
*/
|
|
194
|
-
export declare function Index<T extends Entity | EntityWithoutMetadata = any>(
|
|
195
|
-
/**
|
|
196
|
-
* Decorator to define a composite index on multiple columns.
|
|
197
|
-
* @template T - The entity type.
|
|
198
|
-
* @param name - The name of the index.
|
|
199
|
-
* @param columns - An array of property names (or tuples with direction) included in the index.
|
|
200
|
-
* @param options - Additional index options.
|
|
201
|
-
* @returns A class decorator.
|
|
202
|
-
*/
|
|
203
|
-
export declare function Index<T extends Entity | EntityWithoutMetadata = any>(name: string, columns: Columns<T>, options?: IndexReflectionData<T>['options']): ClassDecorator;
|
|
211
|
+
export declare function Index<T extends Entity | EntityWithoutMetadata = any>(options?: IndexReflectionData<T>['options']): PropertyDecorator;
|
|
204
212
|
/**
|
|
205
213
|
* Decorator to define a composite index on multiple columns.
|
|
206
214
|
* @template T - The entity type.
|
package/orm/decorators.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createClassDecorator, createDecorator, createPropertyDecorator } from '../reflection/index.js';
|
|
2
2
|
import { Property } from '../schema/index.js';
|
|
3
3
|
import { filterUndefinedObjectProperties, objectEntries } from '../utils/object/object.js';
|
|
4
|
-
import {
|
|
4
|
+
import { isArray, isString, isUndefined } from '../utils/type-guards.js';
|
|
5
5
|
/**
|
|
6
6
|
* Factory function to create a class decorator for ORM table configuration.
|
|
7
7
|
* Merges provided data with existing ORM reflection data on the class metadata.
|
|
@@ -26,7 +26,7 @@ export function createTableDecorator(data = {}) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
metadata.data.set('orm', reflectionData, true);
|
|
29
|
-
}
|
|
29
|
+
},
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -35,8 +35,26 @@ export function createTableDecorator(data = {}) {
|
|
|
35
35
|
* @param data - The ORM column reflection data to add.
|
|
36
36
|
* @returns A property decorator.
|
|
37
37
|
*/
|
|
38
|
-
export function createColumnDecorator(data) {
|
|
39
|
-
return createPropertyDecorator({
|
|
38
|
+
export function createColumnDecorator(data = {}) {
|
|
39
|
+
return createPropertyDecorator({
|
|
40
|
+
handler: (_, metadata) => {
|
|
41
|
+
const reflectionData = metadata.data.tryGet('orm') ?? {};
|
|
42
|
+
const dataEntries = objectEntries(data);
|
|
43
|
+
if (dataEntries.length == 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
for (const [key, value] of dataEntries) {
|
|
47
|
+
const existingValue = reflectionData[key];
|
|
48
|
+
if (isArray(existingValue)) {
|
|
49
|
+
reflectionData[key] = [...existingValue, ...value];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
reflectionData[key] = value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
metadata.data.set('orm', reflectionData, true);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
40
58
|
}
|
|
41
59
|
/**
|
|
42
60
|
* Factory function to create a decorator applicable to both classes and properties for ORM configuration.
|
|
@@ -62,13 +80,8 @@ export function Column(options) {
|
|
|
62
80
|
export function PrimaryKey() {
|
|
63
81
|
return createColumnDecorator({ primaryKey: true });
|
|
64
82
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* @param type - A function returning the referenced entity type.
|
|
68
|
-
* @returns A property decorator.
|
|
69
|
-
*/
|
|
70
|
-
export function References(type) {
|
|
71
|
-
return createColumnDecorator({ references: type });
|
|
83
|
+
export function References(target, targetColumn) {
|
|
84
|
+
return createColumnDecorator({ references: [{ target, targetColumn }] });
|
|
72
85
|
}
|
|
73
86
|
/**
|
|
74
87
|
* Decorator to define a table check constraint.
|
|
@@ -96,7 +109,7 @@ export function Encrypted() {
|
|
|
96
109
|
*/
|
|
97
110
|
export function Embedded(type, options) {
|
|
98
111
|
return createPropertyDecorator({
|
|
99
|
-
include: [Property(type), createColumnDecorator({ embedded: { type, ...options } })]
|
|
112
|
+
include: [Property(type), createColumnDecorator({ embedded: { type, ...options } })],
|
|
100
113
|
});
|
|
101
114
|
}
|
|
102
115
|
export function Table(nameOrOptions, optionsOrNothing) {
|
|
@@ -107,21 +120,28 @@ export function Table(nameOrOptions, optionsOrNothing) {
|
|
|
107
120
|
: filterUndefinedObjectProperties({ name, schema });
|
|
108
121
|
return createTableDecorator(data);
|
|
109
122
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Decorator to define a foreign key relationship.
|
|
125
|
+
* @param target - A function returning the referenced entity type.
|
|
126
|
+
* @param columns - The columns in the current entity that form the foreign key.
|
|
127
|
+
* @param foreignColumns - The columns in the referenced entity that the foreign key points to.
|
|
128
|
+
* @param options - Additional foreign key options (e.g., name, naming strategy).
|
|
129
|
+
* @template TThis - The entity type of the current entity.
|
|
130
|
+
* @template TTarget - The entity type of the referenced entity.
|
|
131
|
+
* @returns A property decorator.
|
|
132
|
+
*/
|
|
133
|
+
export function ForeignKey(target, columns, foreignColumns, options) {
|
|
134
|
+
return createTableDecorator({ foreignKeys: [{ target, columns, foreignColumns, options }] });
|
|
135
|
+
}
|
|
136
|
+
export function Unique(columnsOrOptions, options) {
|
|
114
137
|
if (isArray(columnsOrOptions)) {
|
|
115
|
-
return createTableDecorator({ unique: [{
|
|
138
|
+
return createTableDecorator({ unique: [{ columns: columnsOrOptions, options }] });
|
|
116
139
|
}
|
|
117
|
-
return createColumnDecorator({ unique: {
|
|
140
|
+
return createColumnDecorator({ unique: { options: columnsOrOptions } });
|
|
118
141
|
}
|
|
119
|
-
export function Index(
|
|
120
|
-
if (isArray(nameOrColumns)) {
|
|
121
|
-
return createTableDecorator({ index: [{ columns: nameOrColumns, options: assertNotArrayPass(columnsOrOptions) }] });
|
|
122
|
-
}
|
|
142
|
+
export function Index(columnsOrOptions, options) {
|
|
123
143
|
if (isArray(columnsOrOptions)) {
|
|
124
|
-
return createTableDecorator({ index: [{
|
|
144
|
+
return createTableDecorator({ index: [{ columns: columnsOrOptions, options }] });
|
|
125
145
|
}
|
|
126
|
-
return createColumnDecorator({ index: {
|
|
146
|
+
return createColumnDecorator({ index: { options: columnsOrOptions } });
|
|
127
147
|
}
|
package/orm/entity.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Embedded, type HasDefault, type IsPrimaryKey, Json, Timestamp, Uuid } f
|
|
|
7
7
|
export interface EntityType<T extends Entity | EntityWithoutMetadata = Entity | EntityWithoutMetadata> extends Type<T> {
|
|
8
8
|
readonly entityName?: string;
|
|
9
9
|
}
|
|
10
|
+
export type AnyEntity = Entity | EntityWithoutMetadata;
|
|
10
11
|
/**
|
|
11
12
|
* Base class for extensible metadata attributes associated with an entity.
|
|
12
13
|
* Allows storing arbitrary key-value pairs.
|
package/orm/query.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type ComparisonQueryBody<T = any> = {
|
|
|
20
20
|
/** Represents either a full comparison query object or a direct value for equality comparison. */
|
|
21
21
|
export type ComparisonQueryOrValue<T = any> = ComparisonQuery<T> | ComparisonValue<T>;
|
|
22
22
|
/** Represents a comparison query using various operators like $eq, $ne, $gt, $in, etc. */
|
|
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>;
|
|
23
|
+
export type ComparisonQuery<T = any> = Partial<ComparisonAndQuery<T> & ComparisonOrQuery<T> & 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
24
|
/** Union of keys representing comparison query operators. */
|
|
25
25
|
export type ComparisonQueryTypes = keyof ComparisonQuery;
|
|
26
26
|
/** Array containing all valid comparison query operator keys. */
|
|
@@ -63,9 +63,17 @@ export type LogicalNorQuery<T = any> = {
|
|
|
63
63
|
export type ComparisonValue<T> = T | Flatten<T> | SQLWrapper;
|
|
64
64
|
/** Represents a comparison value that can also include a RegExp for string comparisons. */
|
|
65
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 logical AND query. All sub-queries must be true. */
|
|
67
|
+
export type ComparisonAndQuery<T = any> = {
|
|
68
|
+
$and: readonly ComparisonQueryOrValue<T>[];
|
|
69
|
+
};
|
|
70
|
+
/** Represents a logical OR query. At least one sub-query must be true. */
|
|
71
|
+
export type ComparisonOrQuery<T = any> = {
|
|
72
|
+
$or: readonly ComparisonQueryOrValue<T>[];
|
|
73
|
+
};
|
|
66
74
|
/** Represents a NOT comparison query. Inverts the result of the nested comparison. */
|
|
67
75
|
export type ComparisonNotQuery<T = any> = {
|
|
68
|
-
$not:
|
|
76
|
+
$not: ComparisonQueryOrValue<T>;
|
|
69
77
|
};
|
|
70
78
|
/** Represents an equality comparison query ($eq). */
|
|
71
79
|
export type ComparisonEqualsQuery<T = any> = {
|
|
@@ -60,6 +60,7 @@ export type LoadManyOptions<T extends EntityWithoutMetadata> = LoadOptions<T> &
|
|
|
60
60
|
export type UpdateOptions<T extends EntityWithoutMetadata> = LoadOptions<T>;
|
|
61
61
|
/** Type definition for updating entity metadata attributes, allowing partial updates and SQL expressions. */
|
|
62
62
|
export type EntityMetadataUpdate = WithSql<Partial<UntaggedDeep<Pick<EntityMetadata, 'attributes'>>>>;
|
|
63
|
+
export type EntityMetadataInsert = Partial<Pick<EntityMetadata, 'attributes'>>;
|
|
63
64
|
/**
|
|
64
65
|
* Represents the data structure for creating a new entity.
|
|
65
66
|
* Excludes 'id' and 'metadata' by default, but allows providing an optional 'id' and partial 'metadata.attributes'.
|
|
@@ -68,7 +69,7 @@ export type EntityMetadataUpdate = WithSql<Partial<UntaggedDeep<Pick<EntityMetad
|
|
|
68
69
|
*/
|
|
69
70
|
export type NewEntity<T extends Entity | EntityWithoutMetadata> = T extends Entity ? WithSql<UntaggedDeep<TypedOmit<T, 'id' | 'metadata'> & {
|
|
70
71
|
id?: string;
|
|
71
|
-
metadata?:
|
|
72
|
+
metadata?: EntityMetadataInsert;
|
|
72
73
|
}>> : WithSql<UntaggedDeep<TypedOmit<T, 'id'> & {
|
|
73
74
|
id?: string;
|
|
74
75
|
}>>;
|
package/orm/schemas/json.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import type { JsonPath } from '../../json-path/json-path.js';
|
|
1
2
|
import { type Decorator } from '../../reflection/index.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export
|
|
3
|
+
import { Schema, type SchemaDecoratorOptions, type SchemaTestable, type SchemaTestOptions, type SchemaTestResult } from '../../schema/index.js';
|
|
4
|
+
import type { TypedOmit } from '../../types.js';
|
|
5
|
+
export type JsonSchemaOptions<T> = {
|
|
6
|
+
schema?: SchemaTestable<T>;
|
|
7
|
+
};
|
|
8
|
+
export declare class JsonSchema<T> extends Schema<T> {
|
|
5
9
|
readonly name = "Json";
|
|
6
|
-
|
|
10
|
+
readonly innerSchema: Schema<T>;
|
|
11
|
+
constructor(options?: JsonSchemaOptions<T>);
|
|
12
|
+
_test(value: any, path: JsonPath, options: SchemaTestOptions): SchemaTestResult<T>;
|
|
7
13
|
}
|
|
8
|
-
export declare function json(options?: JsonSchemaOptions): JsonSchema
|
|
9
|
-
export declare function Json(options?: JsonSchemaOptions & SchemaDecoratorOptions): Decorator<'class' | 'property' | 'accessor'>;
|
|
14
|
+
export declare function json<T>(options?: JsonSchemaOptions<T>): JsonSchema<T>;
|
|
15
|
+
export declare function Json(options?: JsonSchemaOptions<any> & TypedOmit<SchemaDecoratorOptions, 'schema'>): Decorator<'class' | 'property' | 'accessor'>;
|
package/orm/schemas/json.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { createDecorator } from '../../reflection/index.js';
|
|
2
|
-
import { any, Class,
|
|
3
|
-
|
|
2
|
+
import { any, Class, object, Property, Schema, schemaTestableToSchema } from '../../schema/index.js';
|
|
3
|
+
import { isDefined } from '../../utils/type-guards.js';
|
|
4
|
+
export class JsonSchema extends Schema {
|
|
4
5
|
name = 'Json';
|
|
6
|
+
innerSchema;
|
|
5
7
|
constructor(options) {
|
|
6
|
-
super(
|
|
8
|
+
super();
|
|
9
|
+
this.innerSchema = isDefined(options?.schema) ? schemaTestableToSchema(options.schema) : any();
|
|
10
|
+
}
|
|
11
|
+
_test(value, path, options) {
|
|
12
|
+
return this.innerSchema._test(value, path, options);
|
|
7
13
|
}
|
|
8
14
|
}
|
|
9
15
|
export function json(options) {
|
|
10
16
|
return new JsonSchema(options);
|
|
11
17
|
}
|
|
12
18
|
export function Json(options) {
|
|
19
|
+
const { schema, ...optionsRest } = options ?? {};
|
|
13
20
|
return createDecorator({ class: true, property: true, accessor: true }, (data, metadata, args) => {
|
|
14
21
|
if (data.type == 'class') {
|
|
15
|
-
return Class({ schema: json({ factory: { type: data.constructor } }) })(args[0]);
|
|
22
|
+
return Class({ schema: json({ schema: schema ?? object({}, { unknownPropertiesKey: any(), unknownProperties: any(), factory: { type: data.constructor } }) }) })(args[0]);
|
|
16
23
|
}
|
|
17
|
-
return Property(json({ factory: { type: metadata.type } }),
|
|
24
|
+
return Property(json({ schema: schema ?? object({}, { unknownPropertiesKey: any(), unknownProperties: any(), factory: { type: metadata.type } }) }), optionsRest)(args[0], args[1], args[2]);
|
|
18
25
|
});
|
|
19
26
|
}
|
package/orm/server/database.js
CHANGED
|
@@ -32,8 +32,11 @@ Injector.registerSingleton(Database, {
|
|
|
32
32
|
if (isUndefined(connection)) {
|
|
33
33
|
throw new Error('Missing postgres connection. Provide it either via injection argument or a provider for DatabaseConfig.');
|
|
34
34
|
}
|
|
35
|
-
const pool = new Pool(
|
|
36
|
-
|
|
35
|
+
const pool = new Pool({
|
|
36
|
+
idle_in_transaction_session_timeout: 10000,
|
|
37
|
+
...connection,
|
|
38
|
+
});
|
|
39
|
+
context.addDisposeHandler(async () => await pool.end());
|
|
37
40
|
return drizzle(pool);
|
|
38
41
|
},
|
|
39
42
|
});
|