@tstdl/base 0.92.166 → 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/api/server/middlewares/content-type.middleware.js +1 -1
- 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
|
@@ -8,8 +8,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
10
|
import { Index, Table } from '../../orm/decorators.js';
|
|
11
|
-
import { EntityWithoutMetadata } from '../../orm/
|
|
12
|
-
import { Integer, Json, Timestamp } from '../../orm/index.js';
|
|
11
|
+
import { EntityWithoutMetadata, Integer, Json, Timestamp } from '../../orm/index.js';
|
|
13
12
|
import { StringProperty } from '../../schema/index.js';
|
|
14
13
|
let PostgresJob = class PostgresJob extends EntityWithoutMetadata {
|
|
15
14
|
queue;
|
package/queue/postgres/module.js
CHANGED
|
@@ -24,6 +24,6 @@ export async function migratePostgresQueueSchema() {
|
|
|
24
24
|
await migrate(database, {
|
|
25
25
|
migrationsSchema: 'queue',
|
|
26
26
|
migrationsTable: '_migrations',
|
|
27
|
-
migrationsFolder: import.meta.resolve('./drizzle').replace('file://', '')
|
|
27
|
+
migrationsFolder: import.meta.resolve('./drizzle').replace('file://', ''),
|
|
28
28
|
});
|
|
29
29
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type * as NodeWorkerThreads from 'node:worker_threads';
|
|
2
2
|
import type { LiteralUnion } from 'type-fest';
|
|
3
|
-
import type { AsyncDisposable } from '../disposable/index.js';
|
|
4
|
-
import { disposeAsync } from '../disposable/index.js';
|
|
5
3
|
import type { Logger } from '../logger/index.js';
|
|
6
4
|
import type { ThreadWorker } from './thread-worker.js';
|
|
7
5
|
export type ThreadOptions = (WorkerOptions | NodeWorkerThreads.WorkerOptions) & {
|
|
@@ -13,7 +11,7 @@ export declare class ThreadPool implements AsyncDisposable {
|
|
|
13
11
|
readonly options: ThreadOptions | undefined;
|
|
14
12
|
constructor(url: string | URL, logger: Logger, options?: ThreadOptions);
|
|
15
13
|
dispose(): Promise<void>;
|
|
16
|
-
[
|
|
14
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
17
15
|
getProcessor<T extends ThreadWorker>(name?: string): (...args: Parameters<T>) => Promise<ReturnType<T>>;
|
|
18
16
|
process<T extends ThreadWorker>(name: LiteralUnion<'default', string>, ...args: Parameters<T>): Promise<ReturnType<T>>;
|
|
19
17
|
private spawn;
|
package/threading/thread-pool.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { disposeAsync } from '../disposable/index.js';
|
|
2
1
|
import { isNode } from '../environment.js';
|
|
3
2
|
import { dynamicImport } from '../import.js';
|
|
4
3
|
import { Pool } from '../pool/index.js';
|
|
@@ -9,7 +8,7 @@ if (isNode) {
|
|
|
9
8
|
spawnWorker = async (url, options) => {
|
|
10
9
|
const workerThreads = await dynamicImport('node:worker_threads');
|
|
11
10
|
spawnWorker = () => new workerThreads.Worker(url, options);
|
|
12
|
-
return spawnWorker(url, options);
|
|
11
|
+
return await spawnWorker(url, options);
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
14
|
else {
|
|
@@ -22,26 +21,26 @@ export class ThreadPool {
|
|
|
22
21
|
constructor(url, logger, options) {
|
|
23
22
|
this.url = url;
|
|
24
23
|
this.options = options;
|
|
25
|
-
this.pool = new Pool(async () => this.spawn(), async ({ worker }) => worker.terminate(), logger, { size: options?.threadCount });
|
|
24
|
+
this.pool = new Pool(async () => await this.spawn(), async ({ worker }) => await worker.terminate(), logger, { size: options?.threadCount });
|
|
26
25
|
}
|
|
27
26
|
async dispose() {
|
|
28
|
-
|
|
27
|
+
await this[Symbol.asyncDispose]();
|
|
29
28
|
}
|
|
30
|
-
async [
|
|
29
|
+
async [Symbol.asyncDispose]() {
|
|
31
30
|
await this.pool.dispose();
|
|
32
31
|
}
|
|
33
32
|
getProcessor(name = 'default') {
|
|
34
|
-
const processor = async (...args) => this.process(name, ...args);
|
|
33
|
+
const processor = async (...args) => await this.process(name, ...args);
|
|
35
34
|
return processor;
|
|
36
35
|
}
|
|
37
36
|
async process(name, ...args) {
|
|
38
|
-
return this.pool.use(async (entry) => {
|
|
37
|
+
return await this.pool.use(async (entry) => {
|
|
39
38
|
if (!entry.remotes.has(name)) {
|
|
40
39
|
const rpcEndpoint = MessagePortRpcEndpoint.from(entry.worker);
|
|
41
40
|
const remote = await Rpc.connect(rpcEndpoint, `thread-worker:${name}`);
|
|
42
41
|
entry.remotes.set(name, remote);
|
|
43
42
|
}
|
|
44
|
-
return entry.remotes.get(name)(...args);
|
|
43
|
+
return await entry.remotes.get(name)(...args);
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
async spawn() {
|
package/utils/format-error.d.ts
CHANGED
|
@@ -16,9 +16,16 @@ export type FormatErrorOptions = {
|
|
|
16
16
|
* Include stack trace
|
|
17
17
|
*/
|
|
18
18
|
includeStack?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum recursion depth for nested causes and aggregate errors (default: 5)
|
|
21
|
+
*/
|
|
22
|
+
depth?: number;
|
|
19
23
|
};
|
|
20
24
|
export interface ErrorExtraInfo {
|
|
21
25
|
/** Format extra data (without message and stack) as JSON */
|
|
22
26
|
getExtraInfo(): UndefinableJson | undefined;
|
|
23
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Enhanced error formatting
|
|
30
|
+
*/
|
|
24
31
|
export declare function formatError(error: any, options?: FormatErrorOptions): string;
|
package/utils/format-error.js
CHANGED
|
@@ -1,35 +1,77 @@
|
|
|
1
1
|
import { unwrapError } from '../errors/utils.js';
|
|
2
2
|
import { decycle } from './object/decycle.js';
|
|
3
3
|
import { objectKeys } from './object/object.js';
|
|
4
|
-
import {
|
|
4
|
+
import { tryChain } from './try-chain.js';
|
|
5
|
+
import { isDefined, isFunction, isObject, isUndefined } from './type-guards.js';
|
|
6
|
+
/**
|
|
7
|
+
* Enhanced error formatting
|
|
8
|
+
*/
|
|
5
9
|
export function formatError(error, options = {}) {
|
|
6
|
-
const { includeRest = 'if-no-extra-info', includeExtraInfo = true, includeStack = true } = options;
|
|
10
|
+
const { includeName = true, includeRest = 'if-no-extra-info', includeExtraInfo = true, includeStack = true, depth = 5, } = options;
|
|
11
|
+
if (depth <= 0) {
|
|
12
|
+
return '[Max recursion depth reached]';
|
|
13
|
+
}
|
|
14
|
+
const actualError = unwrapError(error);
|
|
7
15
|
let name;
|
|
8
16
|
let message;
|
|
9
17
|
let stack;
|
|
10
18
|
let rest;
|
|
11
19
|
let extraInfo;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
let cause;
|
|
21
|
+
let aggregateErrors;
|
|
22
|
+
if (isObject(actualError)) {
|
|
23
|
+
if (actualError instanceof Error) {
|
|
24
|
+
({ name, message, stack, cause, ...rest } = actualError);
|
|
25
|
+
if (actualError instanceof AggregateError) {
|
|
26
|
+
aggregateErrors = actualError.errors;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Handle plain objects that might have error-like properties
|
|
31
|
+
({ name, message, stack, cause, ...rest } = actualError);
|
|
32
|
+
}
|
|
33
|
+
// Check for extra info (duck-typing)
|
|
34
|
+
if (includeExtraInfo && isFunction(actualError.getExtraInfo)) { // eslint-disable-line @typescript-eslint/unbound-method
|
|
17
35
|
extraInfo = actualError.getExtraInfo();
|
|
18
36
|
}
|
|
19
37
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
// If no message, serialize the whole object as a fallback
|
|
39
|
+
if (isUndefined(message) || String(message).trim().length === 0) { // eslint-disable-line @typescript-eslint/no-unnecessary-type-conversion
|
|
40
|
+
// Handle primitives directly
|
|
41
|
+
if (!isObject(actualError)) {
|
|
42
|
+
message = String(actualError);
|
|
24
43
|
}
|
|
25
|
-
|
|
26
|
-
|
|
44
|
+
else {
|
|
45
|
+
message = tryChain([
|
|
46
|
+
() => JSON.stringify(actualError, null, 2), // Try normal serialization first
|
|
47
|
+
() => {
|
|
48
|
+
// Fallback with decycle for objects with circular references
|
|
49
|
+
const decycledError = decycle(actualError);
|
|
50
|
+
return JSON.stringify(decycledError, null, 2);
|
|
51
|
+
},
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
53
|
+
() => `[Unstringifiable object: ${String(actualError)}]`, // Safe fallback if JSON.stringify still fails
|
|
54
|
+
]);
|
|
27
55
|
}
|
|
28
56
|
}
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
57
|
+
// --- String Assembly ---
|
|
58
|
+
const nameString = includeName ? `${name ?? 'Error'}: ` : '';
|
|
59
|
+
let restString = '';
|
|
60
|
+
const shouldIncludeRest = (includeRest == true) || (includeRest == 'if-no-extra-info' && isUndefined(extraInfo));
|
|
61
|
+
if (shouldIncludeRest && isDefined(rest) && objectKeys(rest).length > 0) {
|
|
62
|
+
restString = `\n${JSON.stringify(decycle(rest), null, 2)}`;
|
|
63
|
+
}
|
|
32
64
|
const extraInfoString = isDefined(extraInfo) ? `\n${JSON.stringify(extraInfo, null, 2)}` : '';
|
|
33
65
|
const stackString = (includeStack && isDefined(stack)) ? `\n${stack}` : '';
|
|
34
|
-
|
|
66
|
+
const causeString = includeStack && cause
|
|
67
|
+
? formatNestedError('Caused by:', cause, { ...options, depth: depth - 1 })
|
|
68
|
+
: '';
|
|
69
|
+
const aggregateErrorsString = Array.isArray(aggregateErrors)
|
|
70
|
+
? aggregateErrors.map((err, i) => formatNestedError(`Sub-error #${i + 1}:`, err, { ...options, depth: depth - 1 })).join('')
|
|
71
|
+
: '';
|
|
72
|
+
return `${nameString}${message}${restString}${extraInfoString}${stackString}${causeString}${aggregateErrorsString}`;
|
|
73
|
+
}
|
|
74
|
+
function formatNestedError(prefix, error, options) {
|
|
75
|
+
const formatted = formatError(error, options).replace(/\n/g, '\n ');
|
|
76
|
+
return `\n\n${prefix}\n ${formatted}`;
|
|
35
77
|
}
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -1,34 +1,66 @@
|
|
|
1
1
|
import { type JsonPathInput } from '../../json-path/index.js';
|
|
2
|
+
type CachedDereferencer<TOptional extends boolean | undefined> = TOptional extends true ? (<T = unknown>(object: object, reference: JsonPathInput) => T | undefined) : (<T = unknown>(object: object, reference: JsonPathInput) => T);
|
|
2
3
|
export type DereferenceOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* If true, the dereferencer will not throw an error if an intermediate
|
|
6
|
+
* property is null or undefined, and will return `undefined` instead.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
3
9
|
optional?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Method to use for dereferencing.
|
|
12
|
+
* - 'loop': Uses a simple loop to traverse the object. More robust, works in all environments.
|
|
13
|
+
* - 'function': Dynamically generates a function for dereferencing. Slow to compile, but faster at runtime - may not work in all environments. Automatically falls back to 'loop' if generation fails.
|
|
14
|
+
*
|
|
15
|
+
* @default 'loop' for `dereference`; 'function' for `compileDereferencer` and `getCachedDereference`
|
|
16
|
+
*/
|
|
17
|
+
method?: 'loop' | 'function';
|
|
4
18
|
};
|
|
5
19
|
/**
|
|
6
|
-
* Compiles a dereferencer for a specific reference
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
20
|
+
* Compiles a dereferencer for a specific reference path.
|
|
21
|
+
* This is the most performant option if you need to access the same path on many different objects.
|
|
22
|
+
*
|
|
23
|
+
* @param reference - Path to a property, e.g., 'a.b.c' or ['a', 'b', 'c'].
|
|
24
|
+
* @param options - Dereferencing options.
|
|
25
|
+
* @returns A specialized function to retrieve a value from an object.
|
|
10
26
|
*/
|
|
11
|
-
export declare function compileDereferencer(reference: JsonPathInput, options
|
|
27
|
+
export declare function compileDereferencer<T = unknown>(reference: JsonPathInput, options: DereferenceOptions & {
|
|
28
|
+
optional: true;
|
|
29
|
+
}): (object: object) => T | undefined;
|
|
30
|
+
export declare function compileDereferencer<T = unknown>(reference: JsonPathInput, options?: DereferenceOptions): (object: object) => T;
|
|
12
31
|
/**
|
|
13
|
-
*
|
|
32
|
+
* Dereferences a value from an object using a reference path.
|
|
14
33
|
*
|
|
15
|
-
* @description
|
|
34
|
+
* @description
|
|
35
|
+
* Best for one-off use. For repeated access, use `compileDereferencer` or `getCachedDereference`.
|
|
16
36
|
*
|
|
17
|
-
*
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @returns referenced value
|
|
37
|
+
* @param object - The object to access.
|
|
38
|
+
* @param reference - Path to a property, e.g., 'a.b.c' or ['a', 'b', 'c'].
|
|
39
|
+
* @param options - Dereferencing options.
|
|
40
|
+
* @returns The referenced value.
|
|
21
41
|
*/
|
|
22
|
-
export declare function dereference(object: object, reference: JsonPathInput, options
|
|
42
|
+
export declare function dereference<T = unknown>(object: object, reference: JsonPathInput, options: DereferenceOptions & {
|
|
43
|
+
optional: true;
|
|
44
|
+
}): T | undefined;
|
|
45
|
+
export declare function dereference<T = unknown>(object: object, reference: JsonPathInput, options?: DereferenceOptions): T;
|
|
23
46
|
/**
|
|
24
|
-
*
|
|
47
|
+
* Returns a cached dereferencing function.
|
|
48
|
+
* The function caches the compiled dereferencer for each path, but not the resulting values.
|
|
25
49
|
*
|
|
26
50
|
* @description
|
|
27
|
-
*
|
|
51
|
+
* Ideal for applications that frequently access various, but repeating, paths on different objects.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const optionalDeref = getCachedDereference({ optional: true });
|
|
55
|
+
* const value = optionalDeref(myObj, 'a.b.c'); // value is T | undefined
|
|
56
|
+
*
|
|
57
|
+
* const requiredDeref = getCachedDereference();
|
|
58
|
+
* const value2 = requiredDeref(myObj, 'a.b.c'); // value2 is T
|
|
28
59
|
*
|
|
29
|
-
*
|
|
30
|
-
* @
|
|
31
|
-
* @param reference path to property in dot notation or {@link JsonPath}
|
|
32
|
-
* @returns referenced value
|
|
60
|
+
* @param options - Dereferencing options. These options are fixed for the lifetime of the returned function.
|
|
61
|
+
* @returns A function that takes an object and a reference and returns the value.
|
|
33
62
|
*/
|
|
34
|
-
export declare function getCachedDereference(options?: DereferenceOptions
|
|
63
|
+
export declare function getCachedDereference<TOptional extends boolean | undefined>(options?: DereferenceOptions & {
|
|
64
|
+
optional: TOptional;
|
|
65
|
+
}): CachedDereferencer<TOptional>;
|
|
66
|
+
export {};
|
|
@@ -1,62 +1,71 @@
|
|
|
1
1
|
import { JsonPath } from '../../json-path/index.js';
|
|
2
2
|
import { memoizeSingle } from '../function/memoize.js';
|
|
3
|
-
import { isNullOrUndefined } from '../type-guards.js';
|
|
4
|
-
|
|
5
|
-
* Compiles a dereferencer for a specific reference
|
|
6
|
-
* @param object object to dereference
|
|
7
|
-
* @param reference path to property in dot notation or {@link JsonPath}
|
|
8
|
-
* @returns referenced value
|
|
9
|
-
*/
|
|
10
|
-
export function compileDereferencer(reference, options) {
|
|
11
|
-
const nodes = JsonPath.from(reference).nodes;
|
|
12
|
-
if (options?.optional == true) {
|
|
13
|
-
return function optionalDereferencer(object) {
|
|
14
|
-
let target = object;
|
|
15
|
-
for (let i = 0; i < nodes.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
|
|
16
|
-
if (isNullOrUndefined(target)) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
target = target[nodes[i]];
|
|
20
|
-
}
|
|
21
|
-
return target;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
3
|
+
import { isNullOrUndefined, isSymbol } from '../type-guards.js';
|
|
4
|
+
function compileLoopDereferencer(nodes, isOptional) {
|
|
24
5
|
return function dereferencer(object) {
|
|
25
6
|
let target = object;
|
|
26
7
|
for (let i = 0; i < nodes.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
|
|
8
|
+
if (isOptional && isNullOrUndefined(target)) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
27
11
|
target = target[nodes[i]];
|
|
28
12
|
}
|
|
29
13
|
return target;
|
|
30
14
|
};
|
|
31
15
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
function compileFunctionDereferencer(nodes, isOptional) {
|
|
17
|
+
const accessor = isOptional
|
|
18
|
+
// Generates code like: obj?.['prop1']?.['prop2']
|
|
19
|
+
? nodes.map((node) => `?.['${node.replace(/'/g, '\\\'')}']`).join('')
|
|
20
|
+
// Generates code like: obj['prop1']['prop2']
|
|
21
|
+
: nodes.map((node) => `['${node.replace(/'/g, '\\\'')}']`).join('');
|
|
22
|
+
const body = `
|
|
23
|
+
"use strict";
|
|
24
|
+
return object${accessor};
|
|
25
|
+
`;
|
|
26
|
+
return new Function('object', body);
|
|
27
|
+
}
|
|
28
|
+
export function compileDereferencer(reference, options) {
|
|
29
|
+
const nodes = JsonPath.from(reference).nodes;
|
|
30
|
+
const isOptional = options?.optional ?? false;
|
|
31
|
+
if (options?.method === 'loop') {
|
|
32
|
+
return compileLoopDereferencer(nodes, isOptional);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
for (const node of nodes) {
|
|
36
|
+
if (isSymbol(node)) {
|
|
37
|
+
throw new Error('Cannot compile function dereferencer for paths containing symbols');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return compileFunctionDereferencer(nodes, isOptional);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return compileLoopDereferencer(nodes, isOptional);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
42
46
|
export function dereference(object, reference, options) {
|
|
43
|
-
return compileDereferencer(reference, options)(object);
|
|
47
|
+
return compileDereferencer(reference, { method: 'loop', ...options })(object);
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
46
|
-
*
|
|
50
|
+
* Returns a cached dereferencing function.
|
|
51
|
+
* The function caches the compiled dereferencer for each path, but not the resulting values.
|
|
47
52
|
*
|
|
48
53
|
* @description
|
|
49
|
-
*
|
|
54
|
+
* Ideal for applications that frequently access various, but repeating, paths on different objects.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const optionalDeref = getCachedDereference({ optional: true });
|
|
58
|
+
* const value = optionalDeref(myObj, 'a.b.c'); // value is T | undefined
|
|
50
59
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
60
|
+
* const requiredDeref = getCachedDereference();
|
|
61
|
+
* const value2 = requiredDeref(myObj, 'a.b.c'); // value2 is T
|
|
62
|
+
*
|
|
63
|
+
* @param options - Dereferencing options. These options are fixed for the lifetime of the returned function.
|
|
64
|
+
* @returns A function that takes an object and a reference and returns the value.
|
|
55
65
|
*/
|
|
56
66
|
export function getCachedDereference(options) {
|
|
57
|
-
const
|
|
58
|
-
function cachedDereference(object, reference) {
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
return cachedDereference;
|
|
67
|
+
const memoizedCompiler = memoizeSingle((reference) => compileDereferencer(reference, options));
|
|
68
|
+
return function cachedDereference(object, reference) {
|
|
69
|
+
return memoizedCompiler(reference)(object);
|
|
70
|
+
};
|
|
62
71
|
}
|
package/utils/timing.js
CHANGED
|
@@ -29,8 +29,8 @@ export async function cancelableTimeout(milliseconds, cancelSignal) {
|
|
|
29
29
|
}
|
|
30
30
|
/** Timeout until specified time */
|
|
31
31
|
export async function cancelableTimeoutUntil(timestamp, cancelSignal) {
|
|
32
|
-
const
|
|
33
|
-
return await cancelableTimeout(
|
|
32
|
+
const millisecondsLeft = timestamp.valueOf() - Date.now();
|
|
33
|
+
return await cancelableTimeout(millisecondsLeft, cancelSignal);
|
|
34
34
|
}
|
|
35
35
|
export async function withTimeout(milliseconds, promiseOrProvider, options) {
|
|
36
36
|
const abortController = new AbortController();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes a series of functions (strategies) in order until one succeeds.
|
|
3
|
+
* If all strategies fail by throwing an error, the fallback function is executed.
|
|
4
|
+
*
|
|
5
|
+
* @template T The expected return type.
|
|
6
|
+
* @param strategies An array of functions to attempt, in order.
|
|
7
|
+
* @param fallback Optional function to execute if all strategies fail.
|
|
8
|
+
* @param onError Optional callback to handle/log errors from failing strategies.
|
|
9
|
+
* @returns The result of the first successful strategy or the fallback.
|
|
10
|
+
*/
|
|
11
|
+
export declare function tryChain<T>(strategies: (() => T)[], onError?: (error: unknown, index: number) => void): T;
|
|
12
|
+
/**
|
|
13
|
+
* Executes a series of functions (strategies) in order until one succeeds.
|
|
14
|
+
* If all strategies fail by throwing an error, the fallback function is executed.
|
|
15
|
+
*
|
|
16
|
+
* @template T The expected return type.
|
|
17
|
+
* @param strategies An array of functions to attempt, in order.
|
|
18
|
+
* @param fallback Optional function to execute if all strategies fail.
|
|
19
|
+
* @param onError Optional callback to handle/log errors from failing strategies.
|
|
20
|
+
* @returns The result of the first successful strategy or the fallback.
|
|
21
|
+
*/
|
|
22
|
+
export declare function tryChainAsync<T>(strategies: (() => T | Promise<T>)[], onError?: (error: unknown, index: number) => void): Promise<T>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes a series of functions (strategies) in order until one succeeds.
|
|
3
|
+
* If all strategies fail by throwing an error, the fallback function is executed.
|
|
4
|
+
*
|
|
5
|
+
* @template T The expected return type.
|
|
6
|
+
* @param strategies An array of functions to attempt, in order.
|
|
7
|
+
* @param fallback Optional function to execute if all strategies fail.
|
|
8
|
+
* @param onError Optional callback to handle/log errors from failing strategies.
|
|
9
|
+
* @returns The result of the first successful strategy or the fallback.
|
|
10
|
+
*/
|
|
11
|
+
export function tryChain(strategies, onError) {
|
|
12
|
+
const errors = [];
|
|
13
|
+
for (const [index, strategy] of strategies.entries()) {
|
|
14
|
+
try {
|
|
15
|
+
return strategy();
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
errors.push(error);
|
|
19
|
+
onError?.(error, index);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
throw new AggregateError(errors, 'All strategies failed and no fallback provided');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Executes a series of functions (strategies) in order until one succeeds.
|
|
26
|
+
* If all strategies fail by throwing an error, the fallback function is executed.
|
|
27
|
+
*
|
|
28
|
+
* @template T The expected return type.
|
|
29
|
+
* @param strategies An array of functions to attempt, in order.
|
|
30
|
+
* @param fallback Optional function to execute if all strategies fail.
|
|
31
|
+
* @param onError Optional callback to handle/log errors from failing strategies.
|
|
32
|
+
* @returns The result of the first successful strategy or the fallback.
|
|
33
|
+
*/
|
|
34
|
+
export async function tryChainAsync(strategies, onError) {
|
|
35
|
+
const errors = [];
|
|
36
|
+
for (const [index, strategy] of strategies.entries()) {
|
|
37
|
+
try {
|
|
38
|
+
return await strategy();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
errors.push(error);
|
|
42
|
+
onError?.(error, index);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new AggregateError(errors, 'All strategies failed and no fallback provided');
|
|
46
|
+
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Entity, MaybeNewEntity } from './entity.js';
|
|
2
|
-
import type { Query, QueryOptions } from './query.js';
|
|
3
|
-
export declare const repositoryType: unique symbol;
|
|
4
|
-
export type UpdateOptions = {
|
|
5
|
-
upsert?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export type EntityPatch<T extends Entity = Entity> = Partial<Omit<T, 'id'>>;
|
|
8
|
-
export declare abstract class EntityRepository<T extends Entity = Entity> {
|
|
9
|
-
readonly [repositoryType]: T;
|
|
10
|
-
abstract load<U extends T = T>(id: string): Promise<U>;
|
|
11
|
-
abstract tryLoad<U extends T = T>(id: string): Promise<U | undefined>;
|
|
12
|
-
abstract loadByFilter<U extends T = T>(query: Query<U>, options?: QueryOptions<U>): Promise<U>;
|
|
13
|
-
abstract tryLoadByFilter<U extends T = T>(query: Query<U>, options?: QueryOptions<U>): Promise<U | undefined>;
|
|
14
|
-
abstract loadMany<U extends T = T>(ids: string[], options?: QueryOptions<U>): Promise<U[]>;
|
|
15
|
-
abstract loadManyCursor<U extends T = T>(ids: string[], options?: QueryOptions<U>): AsyncIterableIterator<U>;
|
|
16
|
-
abstract loadManyByFilter<U extends T = T>(query: Query<U>, options?: QueryOptions<U>): Promise<U[]>;
|
|
17
|
-
abstract loadManyByFilterCursor<U extends T = T>(query: Query<U>, options?: QueryOptions<U>): AsyncIterableIterator<U>;
|
|
18
|
-
abstract loadAll<U extends T = T>(options?: QueryOptions<U>): Promise<U[]>;
|
|
19
|
-
abstract loadAllCursor<U extends T = T>(options?: QueryOptions<U>): AsyncIterableIterator<U>;
|
|
20
|
-
abstract loadAndDelete<U extends T = T>(id: string): Promise<U>;
|
|
21
|
-
abstract tryLoadAndDelete<U extends T = T>(id: string): Promise<U | undefined>;
|
|
22
|
-
abstract loadByFilterAndDelete<U extends T = T>(query: Query<U>, options?: QueryOptions<U>): Promise<U>;
|
|
23
|
-
abstract tryLoadByFilterAndDelete<U extends T = T>(query: Query<U>, options?: QueryOptions<U>): Promise<U | undefined>;
|
|
24
|
-
abstract loadAndPatch<U extends T = T>(id: string, patch: EntityPatch<U>, includePatch: boolean): Promise<U>;
|
|
25
|
-
abstract tryLoadAndPatch<U extends T = T>(id: string, patch: EntityPatch<U>, includePatch: boolean): Promise<U | undefined>;
|
|
26
|
-
abstract loadByFilterAndPatch<U extends T = T>(query: Query<U>, patch: EntityPatch<U>, includePatch: boolean, options?: QueryOptions<U>): Promise<U>;
|
|
27
|
-
abstract tryLoadByFilterAndPatch<U extends T = T>(query: Query<U>, patch: EntityPatch<U>, includePatch: boolean, options?: QueryOptions<U>): Promise<U | undefined>;
|
|
28
|
-
abstract count(allowEstimation?: boolean): Promise<number>;
|
|
29
|
-
abstract countByFilter<U extends T>(query: Query<U>, allowEstimation?: boolean): Promise<number>;
|
|
30
|
-
abstract has(id: string): Promise<boolean>;
|
|
31
|
-
abstract hasByFilter<U extends T>(query: Query<U>): Promise<boolean>;
|
|
32
|
-
abstract hasMany(ids: string[]): Promise<string[]>;
|
|
33
|
-
abstract hasAll(ids: string[]): Promise<boolean>;
|
|
34
|
-
abstract insert<U extends T>(entity: MaybeNewEntity<U>): Promise<U>;
|
|
35
|
-
abstract insertMany<U extends T>(entities: MaybeNewEntity<U>[]): Promise<U[]>;
|
|
36
|
-
abstract insertIfNotExists<U extends T>(entity: MaybeNewEntity<U>): Promise<U | undefined>;
|
|
37
|
-
abstract insertIfNotExistsByFilter<U extends T>(query: Query<U>, entity: MaybeNewEntity<U>): Promise<U | undefined>;
|
|
38
|
-
abstract update<U extends T>(entity: U, options?: UpdateOptions): Promise<boolean>;
|
|
39
|
-
abstract updateMany<U extends T>(entities: U[], options?: UpdateOptions): Promise<number>;
|
|
40
|
-
abstract patch<U extends T = T>(entity: U, patch: EntityPatch<U>): Promise<boolean>;
|
|
41
|
-
abstract patchMany<U extends T = T>(entities: U[], patch: EntityPatch<U>): Promise<number>;
|
|
42
|
-
abstract patchByFilter<U extends T = T>(query: Query<U>, patch: EntityPatch<U>): Promise<boolean>;
|
|
43
|
-
abstract patchManyByFilter<U extends T = T>(query: Query<U>, patch: EntityPatch<U>): Promise<number>;
|
|
44
|
-
abstract delete<U extends T>(entity: U): Promise<boolean>;
|
|
45
|
-
abstract deleteMany<U extends T>(entities: U[]): Promise<number>;
|
|
46
|
-
abstract deleteById(id: string): Promise<boolean>;
|
|
47
|
-
abstract deleteManyById(ids: string[]): Promise<number>;
|
|
48
|
-
abstract deleteByFilter<U extends T = T>(query: Query<U>): Promise<boolean>;
|
|
49
|
-
abstract deleteManyByFilter<U extends T = T>(query: Query<U>): Promise<number>;
|
|
50
|
-
}
|
package/database/entity.d.ts
DELETED
package/database/entity.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/database/id.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getNewId(): string;
|
package/database/id.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Alphabet } from '../utils/alphabet.js';
|
|
2
|
-
import { getRandomString } from '../utils/random.js';
|
|
3
|
-
import { isDefined } from '../utils/type-guards.js';
|
|
4
|
-
import { databaseModuleConfig } from './module.js';
|
|
5
|
-
export function getNewId() {
|
|
6
|
-
return isDefined(databaseModuleConfig.idGenerator)
|
|
7
|
-
? databaseModuleConfig.idGenerator()
|
|
8
|
-
: getRandomString(databaseModuleConfig.idLength ?? 15, databaseModuleConfig.idAlphabet ?? Alphabet.LowerUpperCaseNumbers);
|
|
9
|
-
}
|
package/database/index.d.ts
DELETED
package/database/index.js
DELETED
package/database/module.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Alphabet } from '../utils/alphabet.js';
|
|
2
|
-
export type DatabaseModuleConfig = {
|
|
3
|
-
idLength?: number;
|
|
4
|
-
idAlphabet?: Alphabet;
|
|
5
|
-
idGenerator?: () => string;
|
|
6
|
-
};
|
|
7
|
-
export declare const databaseModuleConfig: DatabaseModuleConfig;
|
|
8
|
-
export declare function configureDatabase(config: DatabaseModuleConfig): void;
|
package/database/module.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Alphabet } from '../utils/alphabet.js';
|
|
2
|
-
export const databaseModuleConfig = {
|
|
3
|
-
idLength: 15,
|
|
4
|
-
idAlphabet: Alphabet.LowerUpperCaseNumbers,
|
|
5
|
-
idGenerator: undefined
|
|
6
|
-
};
|
|
7
|
-
export function configureDatabase(config) {
|
|
8
|
-
databaseModuleConfig.idLength = config.idLength;
|
|
9
|
-
databaseModuleConfig.idAlphabet = config.idAlphabet;
|
|
10
|
-
databaseModuleConfig.idGenerator = config.idGenerator;
|
|
11
|
-
}
|