@tstdl/base 0.92.167 → 0.92.168
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/application/application.d.ts +12 -18
- package/application/application.js +48 -69
- package/application/index.d.ts +1 -5
- package/application/index.js +1 -5
- package/application/providers.d.ts +10 -0
- package/application/providers.js +54 -0
- package/authentication/client/authentication.service.d.ts +1 -3
- package/authentication/client/authentication.service.js +4 -5
- package/browser/browser-context-controller.d.ts +2 -4
- package/browser/browser-context-controller.js +5 -6
- package/browser/browser-controller.d.ts +2 -4
- package/browser/browser-controller.js +3 -4
- package/browser/browser.service.d.ts +1 -3
- package/browser/browser.service.js +1 -2
- package/browser/page-controller.d.ts +2 -4
- package/browser/page-controller.js +7 -8
- package/browser/utils.js +3 -3
- package/cancellation/token.d.ts +104 -41
- package/cancellation/token.js +125 -54
- package/core.d.ts +1 -13
- package/core.js +1 -46
- package/disposable/disposable.d.ts +0 -8
- package/disposable/disposable.js +1 -3
- package/disposable/index.d.ts +0 -6
- package/disposable/index.js +0 -6
- package/disposable/using.d.ts +0 -1
- package/disposable/using.js +2 -3
- package/distributed-loop/distributed-loop.js +2 -2
- package/errors/utils.js +4 -1
- package/examples/api/authentication.js +11 -5
- package/examples/api/basic-overview.js +17 -12
- package/examples/api/custom-authentication.js +13 -7
- package/examples/api/streaming.js +15 -12
- package/examples/browser/basic.js +6 -3
- package/examples/document-management/main.js +6 -3
- package/examples/http/client.js +7 -3
- package/examples/mail/basic.js +9 -7
- package/examples/pdf/basic.js +8 -6
- package/examples/template/basic.js +7 -5
- package/http/client/http-client-request.d.ts +1 -2
- package/http/client/http-client-request.js +1 -2
- package/http/server/http-server.d.ts +1 -3
- package/http/server/http-server.js +0 -1
- package/http/server/node/node-http-server.d.ts +1 -2
- package/http/server/node/node-http-server.js +1 -2
- package/import.js +1 -1
- package/injector/injector.d.ts +1 -1
- package/injector/types.d.ts +3 -4
- package/lock/lock.d.ts +40 -21
- package/lock/lock.js +74 -1
- package/lock/postgres/drizzle/0000_busy_tattoo.sql +7 -0
- package/lock/postgres/drizzle/meta/0000_snapshot.json +65 -0
- package/lock/postgres/drizzle/meta/_journal.json +13 -0
- package/lock/postgres/drizzle.config.js +11 -0
- package/lock/postgres/index.d.ts +2 -0
- package/lock/postgres/index.js +2 -0
- package/lock/postgres/lock.d.ts +14 -0
- package/lock/postgres/lock.js +127 -0
- package/lock/postgres/models/index.d.ts +2 -0
- package/lock/postgres/models/index.js +2 -0
- package/lock/postgres/models/lock.model.d.ts +7 -0
- package/{examples/orm/user.model.js → lock/postgres/models/lock.model.js} +22 -30
- package/lock/postgres/models/schemas.d.ts +3 -0
- package/lock/postgres/models/schemas.js +4 -0
- package/lock/postgres/module.d.ts +6 -0
- package/lock/postgres/module.js +26 -0
- package/lock/postgres/provider.d.ts +6 -0
- package/lock/postgres/provider.js +29 -0
- package/lock/provider.d.ts +12 -2
- package/lock/provider.js +24 -1
- package/lock/web/web-lock.d.ts +4 -3
- package/lock/web/web-lock.js +49 -42
- package/lock/web/web-lock.provider.d.ts +0 -3
- package/lock/web/web-lock.provider.js +5 -22
- package/logger/formatter.d.ts +13 -0
- package/logger/formatter.js +3 -0
- package/logger/formatters/index.d.ts +2 -0
- package/logger/formatters/index.js +2 -0
- package/logger/formatters/json.d.ts +5 -0
- package/logger/formatters/json.js +33 -0
- package/logger/formatters/pretty-print.d.ts +5 -0
- package/logger/formatters/pretty-print.js +55 -0
- package/logger/index.d.ts +5 -2
- package/logger/index.js +5 -2
- package/logger/level.d.ts +10 -8
- package/logger/level.js +9 -9
- package/logger/logger.d.ts +21 -30
- package/logger/logger.js +98 -26
- package/logger/manager.d.ts +20 -0
- package/logger/manager.js +77 -0
- package/logger/tokens.d.ts +1 -1
- package/logger/tokens.js +1 -1
- package/logger/transport.d.ts +14 -0
- package/logger/transport.js +16 -0
- package/logger/transports/console.d.ts +14 -0
- package/logger/transports/console.js +36 -0
- package/logger/transports/index.d.ts +1 -0
- package/logger/transports/index.js +1 -0
- package/mail/clients/nodemailer.mail-client.d.ts +0 -1
- package/mail/clients/nodemailer.mail-client.js +9 -7
- package/message-bus/local/local-message-bus.js +2 -2
- package/message-bus/message-bus-base.d.ts +2 -3
- package/message-bus/message-bus-base.js +5 -6
- package/message-bus/message-bus.d.ts +1 -2
- package/message-bus/message-bus.js +1 -2
- package/module/index.d.ts +0 -2
- package/module/index.js +0 -2
- package/module/module.d.ts +17 -18
- package/module/module.js +47 -12
- package/module/modules/function.module.d.ts +6 -6
- package/module/modules/function.module.js +25 -9
- package/module/modules/web-server.module.d.ts +2 -10
- package/module/modules/web-server.module.js +3 -11
- package/openid-connect/index.d.ts +0 -2
- package/openid-connect/index.js +0 -2
- package/openid-connect/oidc-state.model.d.ts +4 -5
- package/openid-connect/oidc-state.model.js +51 -1
- package/openid-connect/oidc.service-model.d.ts +1 -1
- package/openid-connect/oidc.service.d.ts +2 -6
- package/openid-connect/oidc.service.js +24 -37
- package/orm/decorators.d.ts +10 -1
- package/orm/decorators.js +8 -0
- package/orm/server/repository.d.ts +3 -1
- package/orm/server/repository.js +32 -3
- package/package.json +17 -28
- package/pdf/pdf.service.js +9 -9
- package/pool/pool.d.ts +1 -3
- package/pool/pool.js +3 -4
- package/queue/postgres/job.model.d.ts +1 -2
- package/queue/postgres/job.model.js +1 -2
- package/queue/postgres/module.js +1 -1
- package/threading/thread-pool.d.ts +1 -3
- package/threading/thread-pool.js +7 -8
- package/utils/format-error.d.ts +7 -0
- package/utils/format-error.js +59 -17
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/object/dereference.d.ts +51 -19
- package/utils/object/dereference.js +52 -43
- package/utils/timing.js +2 -2
- package/utils/try-chain.d.ts +22 -0
- package/utils/try-chain.js +46 -0
- package/database/entity-repository.d.ts +0 -50
- package/database/entity-repository.js +0 -3
- package/database/entity.d.ts +0 -7
- package/database/entity.js +0 -1
- package/database/id.d.ts +0 -1
- package/database/id.js +0 -9
- package/database/index.d.ts +0 -11
- package/database/index.js +0 -11
- package/database/module.d.ts +0 -8
- package/database/module.js +0 -11
- package/database/mongo/classes.d.ts +0 -21
- package/database/mongo/classes.js +0 -26
- package/database/mongo/index.d.ts +0 -15
- package/database/mongo/index.js +0 -15
- package/database/mongo/model/document.d.ts +0 -29
- package/database/mongo/model/document.js +0 -63
- package/database/mongo/model/index.d.ts +0 -1
- package/database/mongo/model/index.js +0 -1
- package/database/mongo/module.d.ts +0 -8
- package/database/mongo/module.js +0 -68
- package/database/mongo/mongo-base.repository.d.ts +0 -103
- package/database/mongo/mongo-base.repository.js +0 -263
- package/database/mongo/mongo-bulk.d.ts +0 -35
- package/database/mongo/mongo-bulk.js +0 -90
- package/database/mongo/mongo-entity-repository.d.ts +0 -98
- package/database/mongo/mongo-entity-repository.js +0 -278
- package/database/mongo/operations.d.ts +0 -10
- package/database/mongo/operations.js +0 -54
- package/database/mongo/query-converter.d.ts +0 -6
- package/database/mongo/query-converter.js +0 -83
- package/database/mongo/simple-entity-repository.d.ts +0 -7
- package/database/mongo/simple-entity-repository.js +0 -6
- package/database/mongo/types.d.ts +0 -50
- package/database/mongo/types.js +0 -3
- package/database/query.d.ts +0 -121
- package/database/query.js +0 -7
- package/database/utils.d.ts +0 -2
- package/database/utils.js +0 -3
- package/disposable/async-disposer.d.ts +0 -35
- package/disposable/async-disposer.js +0 -125
- package/examples/orm/drizzle.config.js +0 -6
- package/examples/orm/schemas.d.ts +0 -3
- package/examples/orm/schemas.js +0 -4
- package/examples/orm/test.d.ts +0 -1
- package/examples/orm/test.js +0 -11
- package/examples/orm/user.model.d.ts +0 -13
- package/key-value-store/mongo/index.d.ts +0 -6
- package/key-value-store/mongo/index.js +0 -6
- package/key-value-store/mongo/module.d.ts +0 -8
- package/key-value-store/mongo/module.js +0 -18
- package/key-value-store/mongo/mongo-key-value-store.provider.d.ts +0 -8
- package/key-value-store/mongo/mongo-key-value-store.provider.js +0 -26
- package/key-value-store/mongo/mongo-key-value.model.d.ts +0 -7
- package/key-value-store/mongo/mongo-key-value.model.js +0 -1
- package/key-value-store/mongo/mongo-key-value.repository.d.ts +0 -10
- package/key-value-store/mongo/mongo-key-value.repository.js +0 -31
- package/key-value-store/mongo/mongo-key-value.store.d.ts +0 -15
- package/key-value-store/mongo/mongo-key-value.store.js +0 -82
- package/key-value-store/mongo/tokens.d.ts +0 -3
- package/key-value-store/mongo/tokens.js +0 -2
- package/lock/mongo/index.d.ts +0 -5
- package/lock/mongo/index.js +0 -5
- package/lock/mongo/lock.d.ts +0 -14
- package/lock/mongo/lock.js +0 -125
- package/lock/mongo/model.d.ts +0 -6
- package/lock/mongo/model.js +0 -1
- package/lock/mongo/module.d.ts +0 -12
- package/lock/mongo/module.js +0 -20
- package/lock/mongo/mongo-lock-repository.d.ts +0 -14
- package/lock/mongo/mongo-lock-repository.js +0 -67
- package/lock/mongo/provider.d.ts +0 -8
- package/lock/mongo/provider.js +0 -36
- package/logger/console/index.d.ts +0 -1
- package/logger/console/index.js +0 -1
- package/logger/console/logger.d.ts +0 -11
- package/logger/console/logger.js +0 -64
- package/logger/noop/index.d.ts +0 -1
- package/logger/noop/index.js +0 -1
- package/logger/noop/logger.d.ts +0 -9
- package/logger/noop/logger.js +0 -21
- package/migration/index.d.ts +0 -9
- package/migration/index.js +0 -9
- package/migration/migration-state-repository.d.ts +0 -4
- package/migration/migration-state-repository.js +0 -3
- package/migration/migration-state.d.ts +0 -6
- package/migration/migration-state.js +0 -1
- package/migration/migrator.d.ts +0 -23
- package/migration/migrator.js +0 -76
- package/migration/mongo/index.d.ts +0 -2
- package/migration/mongo/index.js +0 -2
- package/migration/mongo/migration-state-repository.d.ts +0 -11
- package/migration/mongo/migration-state-repository.js +0 -32
- package/migration/mongo/module.d.ts +0 -12
- package/migration/mongo/module.js +0 -17
- package/module/module-base.d.ts +0 -18
- package/module/module-base.js +0 -40
- package/module/module-metric-reporter.d.ts +0 -29
- package/module/module-metric-reporter.js +0 -62
- package/openid-connect/mongo-oidc-state.repository.d.ts +0 -21
- package/openid-connect/mongo-oidc-state.repository.js +0 -52
- package/openid-connect/oidc-state.repository.d.ts +0 -4
- package/openid-connect/oidc-state.repository.js +0 -3
- package/process-shutdown.d.ts +0 -9
- package/process-shutdown.js +0 -65
- package/queue/mongo/index.d.ts +0 -4
- package/queue/mongo/index.js +0 -4
- package/queue/mongo/job.d.ts +0 -12
- package/queue/mongo/job.js +0 -1
- package/queue/mongo/mongo-job.repository.d.ts +0 -13
- package/queue/mongo/mongo-job.repository.js +0 -54
- package/queue/mongo/queue.d.ts +0 -38
- package/queue/mongo/queue.js +0 -266
- package/queue/mongo/queue.provider.d.ts +0 -18
- package/queue/mongo/queue.provider.js +0 -38
- package/search-index/elastic/config.d.ts +0 -8
- package/search-index/elastic/config.js +0 -26
- package/search-index/elastic/index.d.ts +0 -8
- package/search-index/elastic/index.js +0 -8
- package/search-index/elastic/keyword-rewriter.d.ts +0 -8
- package/search-index/elastic/keyword-rewriter.js +0 -18
- package/search-index/elastic/model/elastic-query.d.ts +0 -16
- package/search-index/elastic/model/elastic-query.js +0 -1
- package/search-index/elastic/model/index-mapping.d.ts +0 -26
- package/search-index/elastic/model/index-mapping.js +0 -4
- package/search-index/elastic/model/index.d.ts +0 -3
- package/search-index/elastic/model/index.js +0 -3
- package/search-index/elastic/model/sort.d.ts +0 -8
- package/search-index/elastic/model/sort.js +0 -1
- package/search-index/elastic/module.d.ts +0 -10
- package/search-index/elastic/module.js +0 -49
- package/search-index/elastic/query-builder/boolean-query-builder.d.ts +0 -11
- package/search-index/elastic/query-builder/boolean-query-builder.js +0 -52
- package/search-index/elastic/query-builder/index.d.ts +0 -1
- package/search-index/elastic/query-builder/index.js +0 -1
- package/search-index/elastic/query-converter.d.ts +0 -9
- package/search-index/elastic/query-converter.js +0 -183
- package/search-index/elastic/search-index.d.ts +0 -30
- package/search-index/elastic/search-index.js +0 -144
- package/search-index/elastic/sort-converter.d.ts +0 -4
- package/search-index/elastic/sort-converter.js +0 -14
- package/search-index/elastic/types.d.ts +0 -5
- package/search-index/elastic/types.js +0 -1
- package/search-index/error.d.ts +0 -10
- package/search-index/error.js +0 -14
- package/search-index/index.d.ts +0 -3
- package/search-index/index.js +0 -3
- package/search-index/memory/index.d.ts +0 -1
- package/search-index/memory/index.js +0 -1
- package/search-index/memory/memory-search-index.d.ts +0 -19
- package/search-index/memory/memory-search-index.js +0 -144
- package/search-index/search-index.d.ts +0 -46
- package/search-index/search-index.js +0 -31
- package/search-index/search-result.d.ts +0 -12
- package/search-index/search-result.js +0 -1
- package/theme/adapters/css-adapter.d.ts +0 -5
- package/theme/adapters/css-adapter.js +0 -29
- package/theme/adapters/index.d.ts +0 -2
- package/theme/adapters/index.js +0 -2
- package/theme/adapters/tailwind-adapter.d.ts +0 -18
- package/theme/adapters/tailwind-adapter.js +0 -32
- package/theme/index.d.ts +0 -1
- package/theme/index.js +0 -1
- package/theme/theme-service.d.ts +0 -43
- package/theme/theme-service.js +0 -128
- /package/{examples/orm → lock/postgres}/drizzle.config.d.ts +0 -0
package/queue/mongo/queue.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
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 { CancellationToken } from '../../cancellation/index.js';
|
|
11
|
-
import { getNewId } from '../../database/id.js';
|
|
12
|
-
import { Singleton } from '../../injector/decorators.js';
|
|
13
|
-
import { Lock } from '../../lock/index.js';
|
|
14
|
-
import { MessageBusProvider } from '../../message-bus/index.js';
|
|
15
|
-
import { Queue, UniqueTagStrategy, defaultJobPriority, defaultQueueConfig } from '../../queue/index.js';
|
|
16
|
-
import { Alphabet } from '../../utils/alphabet.js';
|
|
17
|
-
import { backoffGenerator } from '../../utils/backoff.js';
|
|
18
|
-
import { currentTimestamp } from '../../utils/date-time.js';
|
|
19
|
-
import { propertyNameOf } from '../../utils/object/property-name.js';
|
|
20
|
-
import { getRandomString } from '../../utils/random.js';
|
|
21
|
-
import { assertDefined, isString, isUndefined } from '../../utils/type-guards.js';
|
|
22
|
-
import { MongoJobRepository } from './mongo-job.repository.js';
|
|
23
|
-
import { MongoQueueProvider } from './queue.provider.js';
|
|
24
|
-
const triesProperty = propertyNameOf((e) => e.tries);
|
|
25
|
-
const lastDequeueTimestampProperty = propertyNameOf((e) => e.lastDequeueTimestamp);
|
|
26
|
-
const enqueueTimestampProperty = propertyNameOf((e) => e.enqueueTimestamp);
|
|
27
|
-
const priorityProperty = propertyNameOf((e) => e.priority);
|
|
28
|
-
const batchProperty = propertyNameOf((e) => e.batch);
|
|
29
|
-
const backoffOptions = {
|
|
30
|
-
strategy: 'exponential',
|
|
31
|
-
initialDelay: 100,
|
|
32
|
-
increase: 2,
|
|
33
|
-
maximumDelay: 5000,
|
|
34
|
-
};
|
|
35
|
-
let MongoQueue = class MongoQueue extends Queue {
|
|
36
|
-
repository;
|
|
37
|
-
lock;
|
|
38
|
-
queueKey;
|
|
39
|
-
messageBus;
|
|
40
|
-
processTimeout;
|
|
41
|
-
maxTries;
|
|
42
|
-
constructor(repository, lock, messageBusProvider, key, config) {
|
|
43
|
-
super();
|
|
44
|
-
this.repository = repository;
|
|
45
|
-
this.lock = lock;
|
|
46
|
-
this.queueKey = key;
|
|
47
|
-
this.processTimeout = config?.processTimeout ?? defaultQueueConfig.processTimeout;
|
|
48
|
-
this.maxTries = config?.maxTries ?? defaultQueueConfig.maxTries;
|
|
49
|
-
this.messageBus = messageBusProvider.get(`MongoQueue:${repository.collection.collectionName}:${key}`);
|
|
50
|
-
}
|
|
51
|
-
async enqueue(data, options = {}) {
|
|
52
|
-
const { tag = null, uniqueTag, priority = defaultJobPriority } = options;
|
|
53
|
-
const newJob = {
|
|
54
|
-
queue: this.queueKey,
|
|
55
|
-
jobId: getNewId(),
|
|
56
|
-
tag,
|
|
57
|
-
priority,
|
|
58
|
-
data,
|
|
59
|
-
enqueueTimestamp: currentTimestamp(),
|
|
60
|
-
tries: 0,
|
|
61
|
-
lastDequeueTimestamp: 0,
|
|
62
|
-
batch: null,
|
|
63
|
-
};
|
|
64
|
-
const job = (uniqueTag == undefined)
|
|
65
|
-
? await this.repository.insert(newJob)
|
|
66
|
-
: await this.repository.insertWithUniqueTagStrategy(newJob, uniqueTag);
|
|
67
|
-
return toModelJob(job);
|
|
68
|
-
}
|
|
69
|
-
async enqueueMany(items, options) {
|
|
70
|
-
const now = currentTimestamp();
|
|
71
|
-
const nonUnique = [];
|
|
72
|
-
const keepOld = [];
|
|
73
|
-
const takeNew = [];
|
|
74
|
-
for (const { data, tag = null, priority = defaultJobPriority } of items) {
|
|
75
|
-
const newMongoJob = {
|
|
76
|
-
queue: this.queueKey,
|
|
77
|
-
jobId: getNewId(),
|
|
78
|
-
tag,
|
|
79
|
-
priority,
|
|
80
|
-
data,
|
|
81
|
-
enqueueTimestamp: now,
|
|
82
|
-
tries: 0,
|
|
83
|
-
lastDequeueTimestamp: 0,
|
|
84
|
-
batch: null,
|
|
85
|
-
};
|
|
86
|
-
switch (options?.uniqueTag) {
|
|
87
|
-
case undefined:
|
|
88
|
-
nonUnique.push(newMongoJob);
|
|
89
|
-
break;
|
|
90
|
-
case UniqueTagStrategy.KeepOld:
|
|
91
|
-
keepOld.push(newMongoJob);
|
|
92
|
-
break;
|
|
93
|
-
case UniqueTagStrategy.TakeNew:
|
|
94
|
-
takeNew.push(newMongoJob);
|
|
95
|
-
break;
|
|
96
|
-
default:
|
|
97
|
-
throw new Error('unsupported UniqueTagStrategy');
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const [nonUniqueJobs] = await Promise.all([
|
|
101
|
-
(nonUnique.length > 0) ? this.repository.insertMany(nonUnique) : [],
|
|
102
|
-
(keepOld.length > 0) ? this.repository.bulkInsertWithUniqueTagStrategy(keepOld, UniqueTagStrategy.KeepOld) : undefined,
|
|
103
|
-
(takeNew.length > 0) ? this.repository.bulkInsertWithUniqueTagStrategy(takeNew, UniqueTagStrategy.TakeNew) : undefined,
|
|
104
|
-
]);
|
|
105
|
-
if (options?.returnJobs == true) {
|
|
106
|
-
const keepOldTags = keepOld.map((job) => job.tag);
|
|
107
|
-
const takeNewTags = takeNew.map((job) => job.tag);
|
|
108
|
-
const uniqueTagJobs = await this.repository.loadManyByFilter({ queue: this.queueKey, tag: { $in: [...keepOldTags, ...takeNewTags] } });
|
|
109
|
-
return [...nonUniqueJobs, ...uniqueTagJobs].map(toModelJob);
|
|
110
|
-
}
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
async has(id) {
|
|
114
|
-
return await this.repository.hasByFilter({ queue: this.queueKey, jobId: id });
|
|
115
|
-
}
|
|
116
|
-
async countByTag(tag) {
|
|
117
|
-
return await this.repository.countByFilter({ queue: this.queueKey, tag });
|
|
118
|
-
}
|
|
119
|
-
async get(id) {
|
|
120
|
-
return await this.repository.tryLoadByFilter({ queue: this.queueKey, jobId: id });
|
|
121
|
-
}
|
|
122
|
-
async getByTag(tag) {
|
|
123
|
-
return await this.repository.loadManyByFilter({ queue: this.queueKey, tag });
|
|
124
|
-
}
|
|
125
|
-
async getByTags(tags) {
|
|
126
|
-
return await this.repository.loadManyByFilter({ queue: this.queueKey, tag: { $in: tags } });
|
|
127
|
-
}
|
|
128
|
-
async cancel(id) {
|
|
129
|
-
await this.repository.deleteByFilter({ queue: this.queueKey, jobId: id });
|
|
130
|
-
}
|
|
131
|
-
async cancelMany(ids) {
|
|
132
|
-
await this.repository.deleteManyByFilter({ queue: this.queueKey, jobId: { $in: ids } });
|
|
133
|
-
}
|
|
134
|
-
async cancelByTag(tag) {
|
|
135
|
-
await this.repository.deleteManyByFilter({ queue: this.queueKey, tag });
|
|
136
|
-
}
|
|
137
|
-
async cancelByTags(tags) {
|
|
138
|
-
await this.repository.deleteManyByFilter({ queue: this.queueKey, tag: { $in: tags } });
|
|
139
|
-
}
|
|
140
|
-
async dequeue() {
|
|
141
|
-
const { filter, update } = getDequeueFindParameters(this.queueKey, this.maxTries, this.processTimeout);
|
|
142
|
-
const job = await this.repository.baseRepository.tryLoadByFilterAndUpdate(filter, update, {
|
|
143
|
-
returnDocument: 'after',
|
|
144
|
-
sort: {
|
|
145
|
-
priority: 1,
|
|
146
|
-
enqueueTimestamp: 1,
|
|
147
|
-
lastDequeueTimestamp: 1,
|
|
148
|
-
tries: 1,
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
return isUndefined(job) ? undefined : toModelJob(job);
|
|
152
|
-
}
|
|
153
|
-
async dequeueMany(count) {
|
|
154
|
-
const batch = getRandomString(20, Alphabet.LowerUpperCaseNumbers);
|
|
155
|
-
await this.lock.use(10000, true, async () => {
|
|
156
|
-
const { filter } = getDequeueFindParameters(this.queueKey, this.maxTries, this.processTimeout, batch);
|
|
157
|
-
await this.repository.baseRepository.collection.aggregate([
|
|
158
|
-
{ $match: filter },
|
|
159
|
-
{
|
|
160
|
-
$sort: {
|
|
161
|
-
[priorityProperty]: 1,
|
|
162
|
-
[enqueueTimestampProperty]: 1,
|
|
163
|
-
[lastDequeueTimestampProperty]: 1,
|
|
164
|
-
[triesProperty]: 1,
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
{ $limit: count },
|
|
168
|
-
{
|
|
169
|
-
$merge: {
|
|
170
|
-
into: this.repository.baseRepository.collection.collectionName,
|
|
171
|
-
whenMatched: [
|
|
172
|
-
{
|
|
173
|
-
$set: {
|
|
174
|
-
[triesProperty]: { $add: [`$${triesProperty}`, 1] },
|
|
175
|
-
[lastDequeueTimestampProperty]: currentTimestamp(),
|
|
176
|
-
[batchProperty]: batch,
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
],
|
|
180
|
-
whenNotMatched: 'discard',
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
]).next();
|
|
184
|
-
});
|
|
185
|
-
const jobs = await this.repository.loadManyByFilter({ queue: this.queueKey, batch });
|
|
186
|
-
return jobs.map(toModelJob);
|
|
187
|
-
}
|
|
188
|
-
async acknowledge(job) {
|
|
189
|
-
return await this.cancel(job.id);
|
|
190
|
-
}
|
|
191
|
-
async acknowledgeMany(jobs) {
|
|
192
|
-
const jobIds = jobs.map((job) => job.id);
|
|
193
|
-
return await this.cancelMany(jobIds);
|
|
194
|
-
}
|
|
195
|
-
async *getConsumer(cancellationSignal) {
|
|
196
|
-
const continueToken = CancellationToken.from(this.messageBus.allMessages$);
|
|
197
|
-
for await (const backoff of backoffGenerator({ ...backoffOptions, cancellationSignal })) {
|
|
198
|
-
const job = await this.dequeue();
|
|
199
|
-
if (job != undefined) {
|
|
200
|
-
yield job;
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
backoff({ continueToken });
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
continueToken.complete();
|
|
207
|
-
}
|
|
208
|
-
async *getBatchConsumer(size, cancellationSignal) {
|
|
209
|
-
const continueToken = CancellationToken.from(this.messageBus.allMessages$);
|
|
210
|
-
for await (const backoff of backoffGenerator({ ...backoffOptions, cancellationSignal })) {
|
|
211
|
-
const jobs = await this.dequeueMany(size);
|
|
212
|
-
if (jobs.length > 0) {
|
|
213
|
-
yield jobs;
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
backoff({ continueToken });
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
continueToken.complete();
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
MongoQueue = __decorate([
|
|
223
|
-
Singleton({
|
|
224
|
-
provider: {
|
|
225
|
-
useFactory: (argument, context) => {
|
|
226
|
-
const provider = context.resolve(MongoQueueProvider);
|
|
227
|
-
assertDefined(argument, 'queue resolve argument is missing');
|
|
228
|
-
if (isString(argument)) {
|
|
229
|
-
return provider.get(argument, defaultQueueConfig);
|
|
230
|
-
}
|
|
231
|
-
return provider.get(argument.name, { ...defaultQueueConfig, ...argument });
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
}),
|
|
235
|
-
__metadata("design:paramtypes", [MongoJobRepository, Lock, MessageBusProvider, String, Object])
|
|
236
|
-
], MongoQueue);
|
|
237
|
-
export { MongoQueue };
|
|
238
|
-
function toModelJob(mongoJob) {
|
|
239
|
-
const job = {
|
|
240
|
-
id: mongoJob.jobId,
|
|
241
|
-
priority: mongoJob.priority,
|
|
242
|
-
tag: mongoJob.tag,
|
|
243
|
-
data: mongoJob.data,
|
|
244
|
-
enqueueTimestamp: mongoJob.enqueueTimestamp,
|
|
245
|
-
lastDequeueTimestamp: mongoJob.lastDequeueTimestamp,
|
|
246
|
-
tries: mongoJob.tries,
|
|
247
|
-
};
|
|
248
|
-
return job;
|
|
249
|
-
}
|
|
250
|
-
function getDequeueFindParameters(queueKey, maxTries, processTimeout, batch = null) {
|
|
251
|
-
const now = currentTimestamp();
|
|
252
|
-
const maximumLastDequeueTimestamp = now - processTimeout;
|
|
253
|
-
const filter = {
|
|
254
|
-
queue: queueKey,
|
|
255
|
-
tries: { $lt: maxTries },
|
|
256
|
-
lastDequeueTimestamp: { $lte: maximumLastDequeueTimestamp },
|
|
257
|
-
};
|
|
258
|
-
const update = {
|
|
259
|
-
$inc: { tries: 1 },
|
|
260
|
-
$set: {
|
|
261
|
-
lastDequeueTimestamp: now,
|
|
262
|
-
batch,
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
return { filter, update };
|
|
266
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { CollectionArgument, MongoRepositoryConfig } from '../../database/mongo/index.js';
|
|
2
|
-
import { resolveArgumentType, type Resolvable } from '../../injector/index.js';
|
|
3
|
-
import { QueueProvider, type QueueConfig } from '../../queue/index.js';
|
|
4
|
-
import type { MongoJob } from './job.js';
|
|
5
|
-
import { MongoQueue } from './queue.js';
|
|
6
|
-
export declare class MongoQueueProvider extends QueueProvider implements Resolvable<CollectionArgument<MongoJob>> {
|
|
7
|
-
private readonly repository;
|
|
8
|
-
private readonly lockProvider;
|
|
9
|
-
private readonly messageBusProvider;
|
|
10
|
-
readonly [resolveArgumentType]: CollectionArgument<MongoJob>;
|
|
11
|
-
get<T>(name: string, config?: QueueConfig): MongoQueue<T>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* configure mongo queue module
|
|
15
|
-
* @param jobRepositoryConfig repository configuration for jobs
|
|
16
|
-
* @param register whether to register for {@link Queue} and {@link QueueProvider}
|
|
17
|
-
*/
|
|
18
|
-
export declare function configureMongoQueue(jobRepositoryConfig: MongoRepositoryConfig<MongoJob>, register?: boolean): void;
|
|
@@ -1,38 +0,0 @@
|
|
|
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 { inject, injectArgument, Injector, resolveArgumentType, Singleton } from '../../injector/index.js';
|
|
8
|
-
import { LockProvider } from '../../lock/index.js';
|
|
9
|
-
import { MessageBusProvider } from '../../message-bus/index.js';
|
|
10
|
-
import { Queue, QueueProvider } from '../../queue/index.js';
|
|
11
|
-
import { MongoJobRepository } from './mongo-job.repository.js';
|
|
12
|
-
import { MongoQueue } from './queue.js';
|
|
13
|
-
let defaultJobRepositoryConfig;
|
|
14
|
-
let MongoQueueProvider = class MongoQueueProvider extends QueueProvider {
|
|
15
|
-
repository = inject((MongoJobRepository), injectArgument(this));
|
|
16
|
-
lockProvider = inject(LockProvider, 'queue:');
|
|
17
|
-
messageBusProvider = inject(MessageBusProvider);
|
|
18
|
-
get(name, config) {
|
|
19
|
-
const lock = this.lockProvider.get(name);
|
|
20
|
-
return new MongoQueue(this.repository, lock, this.messageBusProvider, name, config);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
MongoQueueProvider = __decorate([
|
|
24
|
-
Singleton({ defaultArgumentProvider: () => defaultJobRepositoryConfig })
|
|
25
|
-
], MongoQueueProvider);
|
|
26
|
-
export { MongoQueueProvider };
|
|
27
|
-
/**
|
|
28
|
-
* configure mongo queue module
|
|
29
|
-
* @param jobRepositoryConfig repository configuration for jobs
|
|
30
|
-
* @param register whether to register for {@link Queue} and {@link QueueProvider}
|
|
31
|
-
*/
|
|
32
|
-
export function configureMongoQueue(jobRepositoryConfig, register = true) {
|
|
33
|
-
defaultJobRepositoryConfig = jobRepositoryConfig;
|
|
34
|
-
if (register) {
|
|
35
|
-
Injector.registerSingleton(QueueProvider, { useToken: MongoQueueProvider });
|
|
36
|
-
Injector.registerSingleton(Queue, { useToken: MongoQueue });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Entity } from '../../database/index.js';
|
|
2
|
-
import type { Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
|
|
3
|
-
export type ElasticSearchIndexConfigArgument<T extends Entity = Entity> = string | ElasticSearchIndexConfig<T>;
|
|
4
|
-
export declare abstract class ElasticSearchIndexConfig<T extends Entity = Entity> implements Resolvable<ElasticSearchIndexConfigArgument> {
|
|
5
|
-
readonly indexName: string;
|
|
6
|
-
readonly [resolveArgumentType]: ElasticSearchIndexConfigArgument<T>;
|
|
7
|
-
constructor(indexNameOrConfig: string | ElasticSearchIndexConfig<T>);
|
|
8
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { InjectArg, Injectable } from '../../injector/decorators.js';
|
|
14
|
-
import { isString } from '../../utils/type-guards.js';
|
|
15
|
-
let ElasticSearchIndexConfig = class ElasticSearchIndexConfig {
|
|
16
|
-
indexName;
|
|
17
|
-
constructor(indexNameOrConfig) {
|
|
18
|
-
this.indexName = isString(indexNameOrConfig) ? indexNameOrConfig : indexNameOrConfig.indexName;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
ElasticSearchIndexConfig = __decorate([
|
|
22
|
-
Injectable(),
|
|
23
|
-
__param(0, InjectArg()),
|
|
24
|
-
__metadata("design:paramtypes", [Object])
|
|
25
|
-
], ElasticSearchIndexConfig);
|
|
26
|
-
export { ElasticSearchIndexConfig };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './config.js';
|
|
2
|
-
export * from './keyword-rewriter.js';
|
|
3
|
-
export * from './model/index.js';
|
|
4
|
-
export * from './module.js';
|
|
5
|
-
export * from './query-builder/index.js';
|
|
6
|
-
export * from './query-converter.js';
|
|
7
|
-
export * from './search-index.js';
|
|
8
|
-
export * from './types.js';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './config.js';
|
|
2
|
-
export * from './keyword-rewriter.js';
|
|
3
|
-
export * from './model/index.js';
|
|
4
|
-
export * from './module.js';
|
|
5
|
-
export * from './query-builder/index.js';
|
|
6
|
-
export * from './query-converter.js';
|
|
7
|
-
export * from './search-index.js';
|
|
8
|
-
export * from './types.js';
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export class KeywordRewriter {
|
|
2
|
-
fields;
|
|
3
|
-
constructor(fields) {
|
|
4
|
-
this.fields = new Set(fields);
|
|
5
|
-
}
|
|
6
|
-
add(field) {
|
|
7
|
-
this.fields.add(field);
|
|
8
|
-
}
|
|
9
|
-
remove(field) {
|
|
10
|
-
this.fields.delete(field);
|
|
11
|
-
}
|
|
12
|
-
requiresRewrite(field) {
|
|
13
|
-
return this.fields.has(field);
|
|
14
|
-
}
|
|
15
|
-
rewriteIfRequired(field) {
|
|
16
|
-
return this.requiresRewrite(field) ? `${field}.keyword` : field;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { estypes } from '@elastic/elasticsearch';
|
|
2
|
-
export type ElasticQuery = estypes.QueryDslQueryContainer;
|
|
3
|
-
export type ElasticBooleanQuery = Required<Pick<estypes.QueryDslQueryContainer, 'bool'>>;
|
|
4
|
-
export type ElasticIdsQuery = Required<Pick<estypes.QueryDslQueryContainer, 'ids'>>;
|
|
5
|
-
export type ElasticMatchAllQuery = Required<Pick<estypes.QueryDslQueryContainer, 'match_all'>>;
|
|
6
|
-
export type ElasticRangeQuery = Required<Pick<estypes.QueryDslQueryContainer, 'range'>>;
|
|
7
|
-
export type ElasticRegexQuery = Required<Pick<estypes.QueryDslQueryContainer, 'regexp'>>;
|
|
8
|
-
export type ElasticTermQuery = Required<Pick<estypes.QueryDslQueryContainer, 'term'>>;
|
|
9
|
-
export type ElasticTermsQuery = Required<Pick<estypes.QueryDslQueryContainer, 'terms'>>;
|
|
10
|
-
export type ElasticMatchQuery = Required<Pick<estypes.QueryDslQueryContainer, 'match'>>;
|
|
11
|
-
export type ElasticExistsQuery = Required<Pick<estypes.QueryDslQueryContainer, 'exists'>>;
|
|
12
|
-
export type ElasticMultiMatchQuery = Required<Pick<estypes.QueryDslQueryContainer, 'multi_match'>>;
|
|
13
|
-
export type ElasticGeoBoundingBoxQuery = Required<Pick<estypes.QueryDslQueryContainer, 'geo_bounding_box'>>;
|
|
14
|
-
export type ElasticGeoDistanceQuery = Required<Pick<estypes.QueryDslQueryContainer, 'geo_distance'>>;
|
|
15
|
-
export type ElasticGeoPolygonQuery = Required<Pick<estypes.QueryDslQueryContainer, 'geo_polygon'>>;
|
|
16
|
-
export type ElasticGeoShapeQuery = Required<Pick<estypes.QueryDslQueryContainer, 'geo_shape'>>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { estypes } from '@elastic/elasticsearch';
|
|
2
|
-
import type { Entity } from '../../../database/index.js';
|
|
3
|
-
import type { DeepFlatten, StringMap, TypedOmit } from '../../../types/index.js';
|
|
4
|
-
export type ElasticIndexMapping<T extends Entity = Entity> = TypedOmit<estypes.MappingTypeMapping, 'properties'> & ElasticNestedIndexMapping<TypedOmit<T, 'id'>>;
|
|
5
|
-
export type ElasticNestedIndexMapping<T> = {
|
|
6
|
-
properties: {
|
|
7
|
-
[P in keyof Required<T>]: ElasticIndexMappingItem<DeepFlatten<Required<T>[P]>>;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
type StrippedBaseType<T extends estypes.MappingPropertyBase> = TypedOmit<T, 'properties' | 'fields'>;
|
|
11
|
-
type ElasticIndexMappingItemBase = {
|
|
12
|
-
index?: boolean;
|
|
13
|
-
fields?: StringMap<ElasticIndexMappingItem>;
|
|
14
|
-
};
|
|
15
|
-
export type MappingNumberProperty = estypes.MappingByteNumberProperty | estypes.MappingDoubleNumberProperty | estypes.MappingFloatNumberProperty | estypes.MappingHalfFloatNumberProperty | estypes.MappingIntegerNumberProperty | estypes.MappingLongNumberProperty | estypes.MappingShortNumberProperty | estypes.MappingScaledFloatNumberProperty | estypes.MappingUnsignedLongNumberProperty;
|
|
16
|
-
export type ElasticKeywordIndexMappingItem = ElasticIndexMappingItemBase & StrippedBaseType<estypes.MappingKeywordProperty>;
|
|
17
|
-
export type ElasticTextIndexMappingItem = ElasticIndexMappingItemBase & StrippedBaseType<estypes.MappingTextProperty>;
|
|
18
|
-
export type ElasticNumberIndexMappingItem = ElasticIndexMappingItemBase & StrippedBaseType<MappingNumberProperty>;
|
|
19
|
-
export type ElasticBooleanIndexMappingItem = ElasticIndexMappingItemBase & StrippedBaseType<estypes.MappingBooleanProperty>;
|
|
20
|
-
export type ElasticDateIndexMappingItem = ElasticIndexMappingItemBase & StrippedBaseType<estypes.MappingDateProperty>;
|
|
21
|
-
export type ElasticGeoPointIndexMappingItem = ElasticIndexMappingItemBase & StrippedBaseType<estypes.MappingGeoPointProperty>;
|
|
22
|
-
export type ElasticObjectIndexMappingItem<T> = ElasticIndexMappingItemBase & StrippedBaseType<estypes.MappingObjectProperty> & ElasticNestedIndexMapping<T>;
|
|
23
|
-
export type ElasticNestedIndexMappingItem<T> = ElasticIndexMappingItemBase & StrippedBaseType<estypes.MappingNestedProperty> & ElasticNestedIndexMapping<T>;
|
|
24
|
-
export type ElasticIndexMappingItem<T = any> = ElasticKeywordIndexMappingItem | ElasticTextIndexMappingItem | ElasticNumberIndexMappingItem | ElasticBooleanIndexMappingItem | ElasticDateIndexMappingItem | ElasticGeoPointIndexMappingItem | ElasticObjectIndexMappingItem<T> | ElasticNestedIndexMappingItem<T>;
|
|
25
|
-
export declare function mergeElasticSearchMappings<T extends Entity>(mappings: ElasticIndexMapping<T>[]): ElasticIndexMapping<T>;
|
|
26
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Entity } from '../../../database/index.js';
|
|
2
|
-
import type { estypes } from '@elastic/elasticsearch';
|
|
3
|
-
export type SortOrder = estypes.SortOrder;
|
|
4
|
-
export type Sort<T extends Entity = Entity> = SortCombinations<T> | SortCombinations<T>[];
|
|
5
|
-
export type SortCombinations<T extends Entity = Entity> = keyof T | SortOptions<T>;
|
|
6
|
-
export type SortOptions<T extends Entity = Entity> = estypes.SortOptionsKeys & {
|
|
7
|
-
[P in keyof T]?: estypes.SortOptions[string];
|
|
8
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ClientOptions } from '@elastic/elasticsearch';
|
|
2
|
-
import type { ElasticSearchIndexConfigArgument } from './config.js';
|
|
3
|
-
import { ElasticSearchIndexConfig } from './config.js';
|
|
4
|
-
export type ElasticsearchModuleConfig = {
|
|
5
|
-
defaultOptions: ClientOptions;
|
|
6
|
-
logPrefix: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const elasticsearchModuleConfig: ElasticsearchModuleConfig;
|
|
9
|
-
export declare const ELASTIC_SEARCH_INDEX_CONFIG: import("../../injector/token.js").InjectionToken<ElasticSearchIndexConfig<import("../../database/entity.js").Entity>, ElasticSearchIndexConfigArgument>;
|
|
10
|
-
export declare function configureElasticsearch(config?: Partial<ElasticsearchModuleConfig>): void;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { connect } from '../../core.js';
|
|
2
|
-
import { inject } from '../../injector/inject.js';
|
|
3
|
-
import { Injector } from '../../injector/injector.js';
|
|
4
|
-
import { injectionToken } from '../../injector/token.js';
|
|
5
|
-
import { Logger } from '../../logger/logger.js';
|
|
6
|
-
import { assert, assertDefined, isArray, isObject, isString } from '../../utils/type-guards.js';
|
|
7
|
-
import { Client } from '@elastic/elasticsearch';
|
|
8
|
-
import { ElasticSearchIndexConfig } from './config.js';
|
|
9
|
-
export const elasticsearchModuleConfig = {
|
|
10
|
-
defaultOptions: { node: 'http://localhost:9200' },
|
|
11
|
-
logPrefix: 'ELASTIC',
|
|
12
|
-
};
|
|
13
|
-
export const ELASTIC_SEARCH_INDEX_CONFIG = injectionToken('ElasticSearchIndexConfig');
|
|
14
|
-
export function configureElasticsearch(config = {}) {
|
|
15
|
-
elasticsearchModuleConfig.defaultOptions = config.defaultOptions ?? elasticsearchModuleConfig.defaultOptions;
|
|
16
|
-
elasticsearchModuleConfig.logPrefix = config.logPrefix ?? elasticsearchModuleConfig.logPrefix;
|
|
17
|
-
}
|
|
18
|
-
Injector.registerSingleton(Client, {
|
|
19
|
-
useFactory: (argument, context) => {
|
|
20
|
-
assertDefined(argument, 'missing elasticsearch client options');
|
|
21
|
-
context.data.logger = inject(Logger, elasticsearchModuleConfig.logPrefix);
|
|
22
|
-
const client = new Client(argument);
|
|
23
|
-
context.addDisposeHandler(async () => await client.close().then(() => context.data.logger.info('closed connection')));
|
|
24
|
-
return client;
|
|
25
|
-
},
|
|
26
|
-
async afterResolve(client, options, { cancellationSignal, data: { logger } }) {
|
|
27
|
-
const url = getUrl(options.node ?? options.nodes);
|
|
28
|
-
await connect(`elasticsearch (${url})`, async () => await client.ping().then((alive) => assert(alive, 'failed to connect')), logger, cancellationSignal);
|
|
29
|
-
},
|
|
30
|
-
defaultArgumentProvider() {
|
|
31
|
-
return elasticsearchModuleConfig.defaultOptions;
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
Injector.registerSingleton(ELASTIC_SEARCH_INDEX_CONFIG, {
|
|
35
|
-
useFactory: (argument, context) => context.resolve(ElasticSearchIndexConfig, argument),
|
|
36
|
-
});
|
|
37
|
-
function getUrl(node) {
|
|
38
|
-
if (isString(node)) {
|
|
39
|
-
return node;
|
|
40
|
-
}
|
|
41
|
-
if (isArray(node)) {
|
|
42
|
-
const urls = node.map(getUrl);
|
|
43
|
-
return `[${urls.join(', ')}]`;
|
|
44
|
-
}
|
|
45
|
-
if (isObject(node)) {
|
|
46
|
-
return node.url.toString();
|
|
47
|
-
}
|
|
48
|
-
return 'undefined url';
|
|
49
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ElasticQuery } from '../model/elastic-query.js';
|
|
2
|
-
export declare class BoolQueryBuilder {
|
|
3
|
-
#private;
|
|
4
|
-
get totalQueries(): number;
|
|
5
|
-
constructor();
|
|
6
|
-
build(): ElasticQuery;
|
|
7
|
-
must(...queries: ElasticQuery[]): this;
|
|
8
|
-
should(...queries: ElasticQuery[]): this;
|
|
9
|
-
mustNot(...queries: ElasticQuery[]): this;
|
|
10
|
-
filter(...queries: ElasticQuery[]): this;
|
|
11
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export class BoolQueryBuilder {
|
|
2
|
-
#must;
|
|
3
|
-
#should;
|
|
4
|
-
#mustNot;
|
|
5
|
-
#filter;
|
|
6
|
-
get totalQueries() {
|
|
7
|
-
return this.#must.length + this.#should.length + this.#mustNot.length + this.#filter.length;
|
|
8
|
-
}
|
|
9
|
-
constructor() {
|
|
10
|
-
this.#must = [];
|
|
11
|
-
this.#should = [];
|
|
12
|
-
this.#mustNot = [];
|
|
13
|
-
this.#filter = [];
|
|
14
|
-
}
|
|
15
|
-
build() {
|
|
16
|
-
const queryObj = {
|
|
17
|
-
bool: {}
|
|
18
|
-
};
|
|
19
|
-
if (this.#must.length > 0) {
|
|
20
|
-
queryObj.bool.must = this.#must;
|
|
21
|
-
}
|
|
22
|
-
if (this.#should.length > 0) {
|
|
23
|
-
queryObj.bool.should = this.#should;
|
|
24
|
-
}
|
|
25
|
-
if (this.#mustNot.length > 0) {
|
|
26
|
-
queryObj.bool.must_not = this.#mustNot;
|
|
27
|
-
}
|
|
28
|
-
if (this.#filter.length > 0) {
|
|
29
|
-
queryObj.bool.filter = this.#filter;
|
|
30
|
-
}
|
|
31
|
-
if (this.#mustNot.length == 0 && (this.#must.length + this.#should.length + this.#filter.length) == 1) {
|
|
32
|
-
return [...this.#must, ...this.#should, ...this.#filter][0];
|
|
33
|
-
}
|
|
34
|
-
return queryObj;
|
|
35
|
-
}
|
|
36
|
-
must(...queries) {
|
|
37
|
-
this.#must.push(...queries);
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
should(...queries) {
|
|
41
|
-
this.#should.push(...queries);
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
mustNot(...queries) {
|
|
45
|
-
this.#mustNot.push(...queries);
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
filter(...queries) {
|
|
49
|
-
this.#filter.push(...queries);
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './boolean-query-builder.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './boolean-query-builder.js';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Entity } from '../../database/index.js';
|
|
2
|
-
import type { LogicalAndQuery, LogicalNorQuery, LogicalOrQuery, Query, TextSpanQueryMode } from '../../database/query.js';
|
|
3
|
-
import type { estypes } from '@elastic/elasticsearch';
|
|
4
|
-
import type { ElasticQuery } from './model/index.js';
|
|
5
|
-
export declare function convertQuery<T extends Entity>(query: Query<T>): ElasticQuery;
|
|
6
|
-
export declare function convertLogicalAndQuery<T extends Entity>(andQuery: LogicalAndQuery<T>['$and']): ElasticQuery;
|
|
7
|
-
export declare function convertLogicalOrQuery<T extends Entity>(orQuery: LogicalOrQuery<T>['$or']): ElasticQuery;
|
|
8
|
-
export declare function convertLogicalNorQuery<T extends Entity>(norQuery: LogicalNorQuery<T>['$nor']): ElasticQuery;
|
|
9
|
-
export declare function convertTextSpanQueryMode(mode: TextSpanQueryMode | undefined): estypes.QueryDslTextQueryType | undefined;
|