@tstdl/base 0.92.99 → 0.92.101
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/middlewares/cors.middleware.js +7 -8
- package/document-management/api/document-management.api.d.ts +4 -0
- package/document-management/models/document.model.d.ts +1 -0
- package/document-management/models/document.model.js +6 -1
- package/document-management/models/service-models/document.service-model.d.ts +2 -0
- package/document-management/models/service-models/document.service-model.js +1 -1
- package/document-management/models/service-models/document.view-model.d.ts +8 -0
- package/document-management/models/service-models/document.view-model.js +12 -1
- package/document-management/server/drizzle/0001_concerned_quentin_quire.sql +1 -0
- package/document-management/server/drizzle/meta/0001_snapshot.json +1932 -0
- package/document-management/server/drizzle/meta/_journal.json +7 -0
- package/document-management/server/services/document-management.service.d.ts +12 -1
- package/document-management/server/services/document-management.service.js +114 -24
- package/message-bus/message-bus-base.d.ts +0 -1
- package/message-bus/message-bus-base.js +2 -9
- package/orm/decorators.d.ts +5 -4
- package/package.json +1 -1
- package/queue/mongo/queue.d.ts +3 -2
- package/queue/mongo/queue.js +8 -2
- package/queue/postgres/drizzle/0001_certain_wild_pack.sql +2 -0
- package/queue/postgres/drizzle/meta/0001_snapshot.json +103 -0
- package/queue/postgres/drizzle/meta/_journal.json +7 -0
- package/queue/postgres/job.model.js +3 -3
- package/queue/postgres/queue.d.ts +3 -0
- package/queue/postgres/queue.js +13 -6
- package/queue/queue.d.ts +6 -0
- package/utils/try-ignore.d.ts +4 -4
- package/utils/try-ignore.js +2 -2
|
@@ -7,9 +7,9 @@ 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 { Table } from '../../orm/decorators.js';
|
|
10
|
+
import { Index, Table } from '../../orm/decorators.js';
|
|
11
11
|
import { EntityWithoutMetadata } from '../../orm/entity.js';
|
|
12
|
-
import { Integer, Json, Timestamp
|
|
12
|
+
import { Integer, Json, Timestamp } from '../../orm/index.js';
|
|
13
13
|
import { StringProperty } from '../../schema/index.js';
|
|
14
14
|
let PostgresJob = class PostgresJob extends EntityWithoutMetadata {
|
|
15
15
|
queue;
|
|
@@ -50,6 +50,6 @@ __decorate([
|
|
|
50
50
|
], PostgresJob.prototype, "data", void 0);
|
|
51
51
|
PostgresJob = __decorate([
|
|
52
52
|
Table('job'),
|
|
53
|
-
|
|
53
|
+
Index(['queue', 'tag'])
|
|
54
54
|
], PostgresJob);
|
|
55
55
|
export { PostgresJob };
|
|
@@ -3,6 +3,8 @@ import type { ObjectLiteral } from '../../types.js';
|
|
|
3
3
|
import { Queue, type EnqueueManyItem, type EnqueueManyOptions, type EnqueueOneOptions, type Job, type JobTag } from '../queue.js';
|
|
4
4
|
export declare class PostgresQueue<T extends ObjectLiteral> extends Queue<T> {
|
|
5
5
|
#private;
|
|
6
|
+
readonly processTimeout: number;
|
|
7
|
+
readonly maxTries: number;
|
|
6
8
|
enqueue(data: T, options?: EnqueueOneOptions): Promise<Job<T>>;
|
|
7
9
|
enqueueMany(items: EnqueueManyItem<T>[], options?: EnqueueManyOptions & {
|
|
8
10
|
returnJobs?: false;
|
|
@@ -15,6 +17,7 @@ export declare class PostgresQueue<T extends ObjectLiteral> extends Queue<T> {
|
|
|
15
17
|
countByTag(tag: JobTag): Promise<number>;
|
|
16
18
|
get(id: string): Promise<Job<T> | undefined>;
|
|
17
19
|
getByTag(tag: JobTag): Promise<Job<T>[]>;
|
|
20
|
+
getByTags(tags: JobTag[]): Promise<Job<T>[]>;
|
|
18
21
|
cancel(id: string): Promise<void>;
|
|
19
22
|
cancelMany(ids: string[]): Promise<void>;
|
|
20
23
|
cancelByTag(tag: JobTag): Promise<void>;
|
package/queue/postgres/queue.js
CHANGED
|
@@ -12,7 +12,7 @@ import { MessageBus } from '../../message-bus/index.js';
|
|
|
12
12
|
import { interval, RANDOM_UUID, 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
|
-
import { isDefined, isString } from '../../utils/type-guards.js';
|
|
15
|
+
import { isDefined, isString, isUndefined } from '../../utils/type-guards.js';
|
|
16
16
|
import { millisecondsPerSecond } from '../../utils/units.js';
|
|
17
17
|
import { defaultQueueConfig, Queue, UniqueTagStrategy } from '../queue.js';
|
|
18
18
|
import { PostgresJob } from './job.model.js';
|
|
@@ -21,11 +21,11 @@ import { job } from './schemas.js';
|
|
|
21
21
|
let PostgresQueue = class PostgresQueue extends Queue {
|
|
22
22
|
#repository = injectRepository(PostgresJob);
|
|
23
23
|
#config = injectArgument(this);
|
|
24
|
-
#processTimeout = (isString(this.#config) ? undefined : this.#config.processTimeout) ?? defaultQueueConfig.processTimeout;
|
|
25
|
-
#maxTries = (isString(this.#config) ? undefined : this.#config.maxTries) ?? defaultQueueConfig.maxTries;
|
|
26
24
|
#queueName = isString(this.#config) ? this.#config : this.#config.name;
|
|
27
25
|
#messageBus = inject((MessageBus), `PostgresQueue:${this.#queueName}`);
|
|
28
26
|
#keepOldUpdate = { id: sql `${job.id}` };
|
|
27
|
+
processTimeout = (isString(this.#config) ? undefined : this.#config.processTimeout) ?? defaultQueueConfig.processTimeout;
|
|
28
|
+
maxTries = (isString(this.#config) ? undefined : this.#config.maxTries) ?? defaultQueueConfig.maxTries;
|
|
29
29
|
#takeNewUpdate = {
|
|
30
30
|
id: RANDOM_UUID,
|
|
31
31
|
queue: this.#queueName,
|
|
@@ -36,7 +36,7 @@ let PostgresQueue = class PostgresQueue extends Queue {
|
|
|
36
36
|
lastDequeueTimestamp: null,
|
|
37
37
|
data: sql `excluded.data`
|
|
38
38
|
};
|
|
39
|
-
#dequeueQuery = and(eq(job.queue, this.#queueName), lt(job.tries, this
|
|
39
|
+
#dequeueQuery = and(eq(job.queue, this.#queueName), lt(job.tries, this.maxTries), or(isSqlNull(job.lastDequeueTimestamp), lte(sql `${job.lastDequeueTimestamp} + ${interval(this.processTimeout, 'milliseconds')}`, TRANSACTION_TIMESTAMP)));
|
|
40
40
|
#dequeueUpdate = {
|
|
41
41
|
tries: sql `${job.tries} + 1`,
|
|
42
42
|
lastDequeueTimestamp: TRANSACTION_TIMESTAMP
|
|
@@ -57,8 +57,12 @@ let PostgresQueue = class PostgresQueue extends Queue {
|
|
|
57
57
|
}));
|
|
58
58
|
const update = (options?.uniqueTag == UniqueTagStrategy.TakeNew)
|
|
59
59
|
? this.#takeNewUpdate
|
|
60
|
-
:
|
|
61
|
-
|
|
60
|
+
: (options?.uniqueTag == UniqueTagStrategy.KeepOld)
|
|
61
|
+
? this.#keepOldUpdate
|
|
62
|
+
: undefined;
|
|
63
|
+
const jobs = isUndefined(update)
|
|
64
|
+
? await this.#repository.insertMany(newEntities)
|
|
65
|
+
: await this.#repository.upsertMany(['queue', 'tag'], newEntities, update);
|
|
62
66
|
this.#messageBus.publishAndForget();
|
|
63
67
|
return jobs;
|
|
64
68
|
}
|
|
@@ -74,6 +78,9 @@ let PostgresQueue = class PostgresQueue extends Queue {
|
|
|
74
78
|
async getByTag(tag) {
|
|
75
79
|
return this.#repository.loadManyByQuery({ queue: this.#queueName, tag });
|
|
76
80
|
}
|
|
81
|
+
async getByTags(tags) {
|
|
82
|
+
return this.#repository.loadManyByQuery({ queue: this.#queueName, tag: { $in: tags } });
|
|
83
|
+
}
|
|
77
84
|
async cancel(id) {
|
|
78
85
|
await this.#repository.hardDeleteByQuery({ queue: this.#queueName, id });
|
|
79
86
|
}
|
package/queue/queue.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ export type Job<T> = {
|
|
|
14
14
|
priority: number;
|
|
15
15
|
tag: JobTag;
|
|
16
16
|
data: T;
|
|
17
|
+
enqueueTimestamp: number;
|
|
18
|
+
lastDequeueTimestamp: number | null;
|
|
19
|
+
tries: number;
|
|
17
20
|
};
|
|
18
21
|
export declare const defaultJobPriority = 1000;
|
|
19
22
|
export declare enum UniqueTagStrategy {
|
|
@@ -46,6 +49,8 @@ export type QueueArgument = string | (QueueConfig & {
|
|
|
46
49
|
export declare const defaultQueueConfig: Required<QueueConfig>;
|
|
47
50
|
export declare abstract class Queue<T> implements Resolvable<QueueArgument> {
|
|
48
51
|
readonly [resolveArgumentType]: QueueArgument;
|
|
52
|
+
abstract readonly processTimeout: number;
|
|
53
|
+
abstract readonly maxTries: number;
|
|
49
54
|
batch(): QueueEnqueueBatch<T>;
|
|
50
55
|
abstract enqueue(data: T, options?: EnqueueOneOptions): Promise<Job<T>>;
|
|
51
56
|
abstract enqueueMany(items: EnqueueManyItem<T>[], options?: EnqueueManyOptions & {
|
|
@@ -59,6 +64,7 @@ export declare abstract class Queue<T> implements Resolvable<QueueArgument> {
|
|
|
59
64
|
abstract countByTag(tag: JobTag): Promise<number>;
|
|
60
65
|
abstract get(id: string): Promise<Job<T> | undefined>;
|
|
61
66
|
abstract getByTag(tag: JobTag): Promise<Job<T>[]>;
|
|
67
|
+
abstract getByTags(tags: JobTag[]): Promise<Job<T>[]>;
|
|
62
68
|
abstract cancel(id: string): Promise<void>;
|
|
63
69
|
abstract cancelMany(ids: string[]): Promise<void>;
|
|
64
70
|
abstract cancelByTag(tag: JobTag): Promise<void>;
|
package/utils/try-ignore.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare function tryIgnore<R>(fn: () => R): R;
|
|
|
3
3
|
export declare function tryIgnore<R, F>(fn: () => R, fallback: F): R | F;
|
|
4
4
|
export declare function tryIgnoreAsync<R>(fn: () => Promise<R>): Promise<R>;
|
|
5
5
|
export declare function tryIgnoreAsync<R, F>(fn: () => Promise<R>, fallback: F): Promise<F>;
|
|
6
|
-
export declare function tryIgnoreLog<R>(fn: () => R
|
|
7
|
-
export declare function tryIgnoreLog<R, F>(fn: () => R,
|
|
8
|
-
export declare function tryIgnoreLogAsync<R>(fn: () => Promise<R
|
|
9
|
-
export declare function tryIgnoreLogAsync<R, F>(fn: () => Promise<R>,
|
|
6
|
+
export declare function tryIgnoreLog<R>(logger: Logger, fn: () => R): R;
|
|
7
|
+
export declare function tryIgnoreLog<R, F>(logger: Logger, fn: () => R, fallback: F): R | F;
|
|
8
|
+
export declare function tryIgnoreLogAsync<R>(logger: Logger, fn: () => Promise<R>): Promise<R>;
|
|
9
|
+
export declare function tryIgnoreLogAsync<R, F>(logger: Logger, fn: () => Promise<R>, fallback: F): Promise<F>;
|
package/utils/try-ignore.js
CHANGED
|
@@ -15,7 +15,7 @@ export async function tryIgnoreAsync(fn, fallback) {
|
|
|
15
15
|
return fallback;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
export function tryIgnoreLog(
|
|
18
|
+
export function tryIgnoreLog(logger, fn, fallback) {
|
|
19
19
|
try {
|
|
20
20
|
return fn();
|
|
21
21
|
}
|
|
@@ -24,7 +24,7 @@ export function tryIgnoreLog(fn, logger, fallback) {
|
|
|
24
24
|
return fallback;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
export async function tryIgnoreLogAsync(
|
|
27
|
+
export async function tryIgnoreLogAsync(logger, fn, fallback) {
|
|
28
28
|
try {
|
|
29
29
|
const value = await fn();
|
|
30
30
|
return value;
|