@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
package/lock/web/web-lock.js
CHANGED
|
@@ -4,61 +4,68 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { map, timer } from 'rxjs';
|
|
8
|
-
import { CancellationToken } from '../../cancellation/index.js';
|
|
9
7
|
import { Injectable } from '../../injector/index.js';
|
|
10
8
|
import { DeferredPromise } from '../../promise/deferred-promise.js';
|
|
11
|
-
import { assertStringPass,
|
|
9
|
+
import { assertStringPass, isNull, isObject, isUndefined } from '../../utils/type-guards.js';
|
|
12
10
|
import { Lock } from '../lock.js';
|
|
13
11
|
import { WebLockProvider } from './web-lock.provider.js';
|
|
14
12
|
let WebLock = class WebLock extends Lock {
|
|
15
|
-
async
|
|
16
|
-
|
|
13
|
+
async tryAcquireOnce() {
|
|
14
|
+
return await this.tryAcquire(0);
|
|
15
|
+
}
|
|
16
|
+
async tryAcquire(timeout) {
|
|
17
|
+
const controllerPromise = new DeferredPromise();
|
|
17
18
|
const releasePromise = new DeferredPromise();
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
const timeoutToken = (isDefined(timeout) && (timeout > 0)) ? CancellationToken.from(timer(timeout).pipe(map(() => true))) : undefined;
|
|
25
|
-
void navigator.locks.request(this.resource, {
|
|
26
|
-
signal: isDefined(timeoutToken) ? timeoutToken.asAbortSignal() : undefined,
|
|
27
|
-
ifAvailable: isDefined(timeout) && (timeout <= 0),
|
|
28
|
-
}, async (lock) => {
|
|
19
|
+
const ifAvailable = isUndefined(timeout) || (timeout <= 0);
|
|
20
|
+
const signal = ifAvailable ? undefined : AbortSignal.any([AbortSignal.timeout(timeout), this.cancellationSignal.asAbortSignal()]);
|
|
21
|
+
await navigator.locks
|
|
22
|
+
.request(this.resource, { signal, ifAvailable }, async (lock) => {
|
|
29
23
|
if (isNull(lock)) {
|
|
30
|
-
|
|
31
|
-
return;
|
|
24
|
+
throw new Error('Failed to acquire lock.');
|
|
32
25
|
}
|
|
33
|
-
|
|
26
|
+
let lost = false;
|
|
27
|
+
controllerPromise.resolve({
|
|
28
|
+
get lost() {
|
|
29
|
+
return lost;
|
|
30
|
+
},
|
|
31
|
+
async release() {
|
|
32
|
+
releasePromise.resolve();
|
|
33
|
+
},
|
|
34
|
+
});
|
|
34
35
|
await releasePromise;
|
|
36
|
+
lost = true;
|
|
35
37
|
})
|
|
36
|
-
.catch((
|
|
37
|
-
|
|
38
|
-
const success = await acquirePromise;
|
|
39
|
-
if (!success) {
|
|
40
|
-
throw new Error('Failed to acquire lock.');
|
|
41
|
-
}
|
|
42
|
-
return controller;
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
if (throwOnFail) {
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
38
|
+
.catch(() => controllerPromise.resolve(false));
|
|
39
|
+
return await controllerPromise;
|
|
50
40
|
}
|
|
51
|
-
async
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
41
|
+
async tryUse(timeout, func) {
|
|
42
|
+
const ifAvailable = isUndefined(timeout) || (timeout <= 0);
|
|
43
|
+
const signal = ifAvailable ? undefined : AbortSignal.any([AbortSignal.timeout(timeout), this.cancellationSignal.asAbortSignal()]);
|
|
44
|
+
let result;
|
|
56
45
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
result = await navigator.locks.request(this.resource, { signal, ifAvailable }, async (lock) => {
|
|
47
|
+
if (isNull(lock)) {
|
|
48
|
+
return { type: 'already-locked' };
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const returnValue = await func({ lost: false });
|
|
52
|
+
return { type: 'result', value: returnValue };
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return { type: 'error', error };
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return { success: false }; // navigator.locks.request throws a DOMException on timeout
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
switch (result.type) {
|
|
63
|
+
case 'result':
|
|
64
|
+
return { success: true, result: result.value };
|
|
65
|
+
case 'already-locked':
|
|
66
|
+
return { success: false };
|
|
67
|
+
case 'error':
|
|
68
|
+
throw result.error;
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
async exists() {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { Lock } from '../../lock/index.js';
|
|
2
2
|
import { LockProvider } from '../../lock/index.js';
|
|
3
3
|
export declare class WebLockProvider extends LockProvider {
|
|
4
|
-
private readonly _prefix;
|
|
5
|
-
constructor(prefix?: string);
|
|
6
|
-
prefix(prefix: string): LockProvider;
|
|
7
4
|
get(resource: string): Lock;
|
|
8
5
|
}
|
|
@@ -4,32 +4,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
var WebLockProvider_1;
|
|
14
|
-
import { InjectArg, Singleton } from '../../injector/index.js';
|
|
7
|
+
import { Singleton } from '../../injector/index.js';
|
|
15
8
|
import { LockProvider } from '../../lock/index.js';
|
|
16
9
|
import { WebLock } from './web-lock.js';
|
|
17
|
-
let WebLockProvider =
|
|
18
|
-
_prefix;
|
|
19
|
-
constructor(prefix = '') {
|
|
20
|
-
super();
|
|
21
|
-
this._prefix = prefix;
|
|
22
|
-
}
|
|
23
|
-
prefix(prefix) {
|
|
24
|
-
return new WebLockProvider_1(this._prefix + prefix);
|
|
25
|
-
}
|
|
10
|
+
let WebLockProvider = class WebLockProvider extends LockProvider {
|
|
26
11
|
get(resource) {
|
|
27
|
-
return new WebLock(this._prefix
|
|
12
|
+
return new WebLock(this.getResourceString(resource, this._prefix), this.cancellationSignal);
|
|
28
13
|
}
|
|
29
14
|
};
|
|
30
|
-
WebLockProvider =
|
|
31
|
-
Singleton()
|
|
32
|
-
__param(0, InjectArg()),
|
|
33
|
-
__metadata("design:paramtypes", [String])
|
|
15
|
+
WebLockProvider = __decorate([
|
|
16
|
+
Singleton()
|
|
34
17
|
], WebLockProvider);
|
|
35
18
|
export { WebLockProvider };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Record } from '../types/types.js';
|
|
2
|
+
import type { LogLevel } from './level.js';
|
|
3
|
+
export type LogPayload = {
|
|
4
|
+
timestamp: Date;
|
|
5
|
+
level: LogLevel;
|
|
6
|
+
module: string[];
|
|
7
|
+
message: string;
|
|
8
|
+
context: Record<string>;
|
|
9
|
+
};
|
|
10
|
+
/** Formats a log payload for a transport. */
|
|
11
|
+
export declare abstract class LogFormatter {
|
|
12
|
+
abstract format(payload: LogPayload): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Singleton } from '../../injector/decorators.js';
|
|
8
|
+
import { enumValueName } from '../../utils/enum.js';
|
|
9
|
+
import { formatError } from '../../utils/format-error.js';
|
|
10
|
+
import { isNotNullOrUndefined } from '../../utils/type-guards.js';
|
|
11
|
+
import { LogFormatter } from '../formatter.js';
|
|
12
|
+
import { LogLevel } from '../level.js';
|
|
13
|
+
/** Formats log entries as a JSON string. */
|
|
14
|
+
let JsonLogFormatter = class JsonLogFormatter extends LogFormatter {
|
|
15
|
+
format(payload) {
|
|
16
|
+
const logObject = {
|
|
17
|
+
timestamp: payload.timestamp.toISOString(),
|
|
18
|
+
level: enumValueName(LogLevel, payload.level).toLowerCase(),
|
|
19
|
+
module: (payload.module.length > 0) ? payload.module.join('.') : null,
|
|
20
|
+
message: payload.message,
|
|
21
|
+
...payload.context,
|
|
22
|
+
};
|
|
23
|
+
// Special handling for error objects to make them serializable
|
|
24
|
+
if (isNotNullOrUndefined(logObject['error'])) {
|
|
25
|
+
logObject['error'] = formatError(logObject['error'], { includeStack: true });
|
|
26
|
+
}
|
|
27
|
+
return JSON.stringify(logObject);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
JsonLogFormatter = __decorate([
|
|
31
|
+
Singleton()
|
|
32
|
+
], JsonLogFormatter);
|
|
33
|
+
export { JsonLogFormatter };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Singleton } from '../../injector/decorators.js';
|
|
8
|
+
import { enumValueName } from '../../utils/enum.js';
|
|
9
|
+
import { formatError } from '../../utils/format-error.js';
|
|
10
|
+
import { isNotNullOrUndefined } from '../../utils/type-guards.js';
|
|
11
|
+
import { LogFormatter } from '../formatter.js';
|
|
12
|
+
import { LogLevel } from '../level.js';
|
|
13
|
+
const levelColorMap = {
|
|
14
|
+
[LogLevel.Error]: '\x1b[31m', // Red
|
|
15
|
+
[LogLevel.Warn]: '\x1b[33m', // Yellow
|
|
16
|
+
[LogLevel.Info]: '\x1b[32m', // Green
|
|
17
|
+
[LogLevel.Verbose]: '\x1b[36m', // Cyan
|
|
18
|
+
[LogLevel.Debug]: '\x1b[34m', // Blue
|
|
19
|
+
[LogLevel.Trace]: '\x1b[90m', // Gray
|
|
20
|
+
};
|
|
21
|
+
const resetColor = '\x1b[0m';
|
|
22
|
+
const dimColor = '\x1b[2m';
|
|
23
|
+
/** Formats log entries in a human-readable, colorful format for development consoles. */
|
|
24
|
+
let PrettyPrintLogFormatter = class PrettyPrintLogFormatter extends LogFormatter {
|
|
25
|
+
format(payload) {
|
|
26
|
+
const color = levelColorMap[payload.level];
|
|
27
|
+
const levelName = enumValueName(LogLevel, payload.level).toUpperCase();
|
|
28
|
+
const levelString = `${levelName}:`.padEnd(8);
|
|
29
|
+
const moduleString = payload.module.map((m) => `[${m}]`).join(' ');
|
|
30
|
+
const metadata = { ...payload.context };
|
|
31
|
+
let metadataString = '';
|
|
32
|
+
let errorString = '';
|
|
33
|
+
if (Object.keys(metadata).length > 0) {
|
|
34
|
+
const displayMeta = {};
|
|
35
|
+
// Don't display metadata used in interpolation
|
|
36
|
+
const interpolationKeys = Array.from(payload.message.matchAll(/{([^{}]+)}/g)).map((match) => match[1]);
|
|
37
|
+
for (const key in metadata) {
|
|
38
|
+
if (!interpolationKeys.includes(key)) {
|
|
39
|
+
displayMeta[key] = metadata[key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (Object.keys(displayMeta).length > 0) {
|
|
43
|
+
metadataString = ` ${dimColor}${JSON.stringify(displayMeta)}${resetColor}`;
|
|
44
|
+
}
|
|
45
|
+
if (isNotNullOrUndefined(metadata['error'])) {
|
|
46
|
+
errorString += `\n${formatError(metadata['error'], { includeStack: true })}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return `${dimColor}${payload.timestamp.toISOString()}${resetColor} ${color}${levelString}${resetColor} ${moduleString}${moduleString.length > 0 ? ' ' : ''}${payload.message}${metadataString}${errorString}`;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
PrettyPrintLogFormatter = __decorate([
|
|
53
|
+
Singleton()
|
|
54
|
+
], PrettyPrintLogFormatter);
|
|
55
|
+
export { PrettyPrintLogFormatter };
|
package/logger/index.d.ts
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module Logger
|
|
5
5
|
*/
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './formatter.js';
|
|
7
|
+
export * from './formatters/index.js';
|
|
7
8
|
export * from './level.js';
|
|
8
9
|
export * from './logger.js';
|
|
9
|
-
export * from './
|
|
10
|
+
export * from './manager.js';
|
|
10
11
|
export * from './tokens.js';
|
|
12
|
+
export * from './transport.js';
|
|
13
|
+
export * from './transports/index.js';
|
package/logger/index.js
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module Logger
|
|
5
5
|
*/
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './formatter.js';
|
|
7
|
+
export * from './formatters/index.js';
|
|
7
8
|
export * from './level.js';
|
|
8
9
|
export * from './logger.js';
|
|
9
|
-
export * from './
|
|
10
|
+
export * from './manager.js';
|
|
10
11
|
export * from './tokens.js';
|
|
12
|
+
export * from './transport.js';
|
|
13
|
+
export * from './transports/index.js';
|
package/logger/level.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { type EnumType } from '../enumeration/enumeration.js';
|
|
2
|
+
export declare const LogLevel: {
|
|
3
|
+
readonly Error: 0;
|
|
4
|
+
readonly Warn: 1;
|
|
5
|
+
readonly Info: 2;
|
|
6
|
+
readonly Verbose: 3;
|
|
7
|
+
readonly Debug: 4;
|
|
8
|
+
readonly Trace: 5;
|
|
9
|
+
};
|
|
10
|
+
export type LogLevel = EnumType<typeof LogLevel>;
|
package/logger/level.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})
|
|
1
|
+
import { defineEnum } from '../enumeration/enumeration.js';
|
|
2
|
+
export const LogLevel = defineEnum('LogLevel', {
|
|
3
|
+
Error: 0,
|
|
4
|
+
Warn: 1,
|
|
5
|
+
Info: 2,
|
|
6
|
+
Verbose: 3,
|
|
7
|
+
Debug: 4,
|
|
8
|
+
Trace: 5,
|
|
9
|
+
});
|
package/logger/logger.d.ts
CHANGED
|
@@ -1,41 +1,32 @@
|
|
|
1
1
|
import type { Resolvable } from '../injector/index.js';
|
|
2
2
|
import { resolveArgumentType } from '../injector/index.js';
|
|
3
|
+
import type { Record } from '../types/types.js';
|
|
3
4
|
import { LogLevel } from './level.js';
|
|
4
|
-
export type
|
|
5
|
-
export type LogEntryProvider = () => LogEntry;
|
|
6
|
-
export type LogEntryOrProvider = LogEntry | LogEntryProvider;
|
|
7
|
-
export type LoggerStatic = new (level: LogLevel) => Logger;
|
|
8
|
-
export type LogErrorOptions = {
|
|
9
|
-
includeRest?: boolean;
|
|
10
|
-
includeStack?: boolean;
|
|
11
|
-
};
|
|
12
|
-
/** Either string as a module shorthand or object */
|
|
13
|
-
export type LoggerArgument = string | undefined | {
|
|
14
|
-
level?: LogLevel;
|
|
5
|
+
export type LoggerArgument = string | string[] | {
|
|
15
6
|
module?: string | string[];
|
|
16
|
-
|
|
7
|
+
context?: Record<string>;
|
|
8
|
+
level?: LogLevel;
|
|
17
9
|
};
|
|
18
10
|
export type LoggerForkOptions = {
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
context?: Record<string>;
|
|
12
|
+
replaceContext?: boolean;
|
|
21
13
|
level?: LogLevel;
|
|
22
14
|
};
|
|
23
|
-
export declare
|
|
24
|
-
|
|
25
|
-
readonly module
|
|
26
|
-
readonly
|
|
15
|
+
export declare class Logger implements Resolvable<LoggerArgument> {
|
|
16
|
+
#private;
|
|
17
|
+
readonly module: string[];
|
|
18
|
+
readonly context: Record<string>;
|
|
19
|
+
readonly level: LogLevel | undefined;
|
|
27
20
|
readonly [resolveArgumentType]: LoggerArgument;
|
|
28
|
-
|
|
29
|
-
error(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
error(message: string, context?: Record<string>): void;
|
|
22
|
+
error(error: unknown, context?: Record<string>): void;
|
|
23
|
+
warn(message: string, context?: Record<string>): void;
|
|
24
|
+
info(message: string, context?: Record<string>): void;
|
|
25
|
+
verbose(message: string, context?: Record<string>): void;
|
|
26
|
+
debug(message: string, context?: Record<string>): void;
|
|
27
|
+
trace(message: string, context?: Record<string>): void;
|
|
28
|
+
fork(subModule: string | string[], options?: LoggerForkOptions): Logger;
|
|
29
|
+
fork(options: LoggerForkOptions): Logger;
|
|
30
|
+
with(context: Record<string>): Logger;
|
|
36
31
|
private _log;
|
|
37
|
-
abstract fork(options: LoggerForkOptions): Logger;
|
|
38
|
-
abstract subModule(subModule: string): Logger;
|
|
39
|
-
abstract prefix(prefix: string): Logger;
|
|
40
|
-
protected abstract log(level: LogLevel, entry: LogEntry | Error, errorOptions?: LogErrorOptions): void;
|
|
41
32
|
}
|
package/logger/logger.js
CHANGED
|
@@ -1,39 +1,111 @@
|
|
|
1
|
-
|
|
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 Logger_1;
|
|
8
|
+
import { createContextProvider } from '../context/context.js';
|
|
9
|
+
import { inject, Injectable, injectArgument, isInInjectionContext, resolveArgumentType } from '../injector/index.js';
|
|
2
10
|
import { toArray } from '../utils/array/array.js';
|
|
3
|
-
import {
|
|
11
|
+
import { now } from '../utils/date-time.js';
|
|
12
|
+
import { getCachedDereference } from '../utils/object/dereference.js';
|
|
13
|
+
import { hasOwnProperty } from '../utils/object/object.js';
|
|
14
|
+
import { isArray, isNotArray, isObject, isString } from '../utils/type-guards.js';
|
|
4
15
|
import { LogLevel } from './level.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
import { LogManager } from './manager.js';
|
|
17
|
+
const { getCurrentLoggerCreationContext, runInLoggerCreationContext, isInLoggerCreationContext } = createContextProvider('LoggerCreation');
|
|
18
|
+
let Logger = Logger_1 = class Logger {
|
|
19
|
+
#manager = getCurrentLoggerCreationContext()?.manager ?? inject(LogManager);
|
|
20
|
+
#argument = isInInjectionContext() ? injectArgument(this, { optional: true }) : undefined;
|
|
21
|
+
module = getCurrentLoggerCreationContext()?.module ?? moduleFromArgument(this.#argument);
|
|
22
|
+
context = getCurrentLoggerCreationContext()?.context ?? ((isObject(this.#argument) && isNotArray(this.#argument)) ? (this.#argument.context ?? {}) : {});
|
|
23
|
+
level = isInLoggerCreationContext() ? getCurrentLoggerCreationContext().level : (isObject(this.#argument) && isNotArray(this.#argument)) ? this.#argument.level : undefined;
|
|
24
|
+
error(errorOrMessage, context) {
|
|
25
|
+
if (isString(errorOrMessage)) {
|
|
26
|
+
this._log(LogLevel.Error, errorOrMessage, context);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const message = (errorOrMessage instanceof Error) ? errorOrMessage.message : 'Error';
|
|
30
|
+
this._log(LogLevel.Error, message, { ...context, error: errorOrMessage });
|
|
31
|
+
}
|
|
13
32
|
}
|
|
14
|
-
|
|
15
|
-
this._log(LogLevel.
|
|
33
|
+
warn(message, context) {
|
|
34
|
+
this._log(LogLevel.Warn, message, context);
|
|
16
35
|
}
|
|
17
|
-
|
|
18
|
-
this._log(LogLevel.
|
|
36
|
+
info(message, context) {
|
|
37
|
+
this._log(LogLevel.Info, message, context);
|
|
19
38
|
}
|
|
20
|
-
|
|
21
|
-
this._log(LogLevel.
|
|
39
|
+
verbose(message, context) {
|
|
40
|
+
this._log(LogLevel.Verbose, message, context);
|
|
22
41
|
}
|
|
23
|
-
|
|
24
|
-
this._log(LogLevel.
|
|
42
|
+
debug(message, context) {
|
|
43
|
+
this._log(LogLevel.Debug, message, context);
|
|
25
44
|
}
|
|
26
|
-
|
|
27
|
-
this._log(LogLevel.
|
|
45
|
+
trace(message, context) {
|
|
46
|
+
this._log(LogLevel.Trace, message, context);
|
|
28
47
|
}
|
|
29
|
-
|
|
30
|
-
|
|
48
|
+
fork(subModuleOrOptions, optionsOrNothing) {
|
|
49
|
+
const subModule = (isString(subModuleOrOptions) || isArray(subModuleOrOptions)) ? subModuleOrOptions : [];
|
|
50
|
+
const options = (isString(subModuleOrOptions) || isArray(subModuleOrOptions)) ? optionsOrNothing : subModuleOrOptions;
|
|
51
|
+
const newModule = [...this.module, ...toArray(subModule)];
|
|
52
|
+
const creationContext = {
|
|
53
|
+
manager: this.#manager,
|
|
54
|
+
module: newModule,
|
|
55
|
+
context: (options?.replaceContext == true) ? (options.context ?? {}) : { ...this.context, ...options?.context },
|
|
56
|
+
level: options?.level ?? this.level,
|
|
57
|
+
};
|
|
58
|
+
return runInLoggerCreationContext(creationContext, () => new Logger_1());
|
|
31
59
|
}
|
|
32
|
-
|
|
33
|
-
|
|
60
|
+
with(context) {
|
|
61
|
+
const creationContext = {
|
|
62
|
+
manager: this.#manager,
|
|
63
|
+
module: this.module,
|
|
64
|
+
context: { ...this.context, ...context },
|
|
65
|
+
level: this.level,
|
|
66
|
+
};
|
|
67
|
+
return runInLoggerCreationContext(creationContext, () => new Logger_1());
|
|
68
|
+
}
|
|
69
|
+
_log(level, message, context = {}) {
|
|
70
|
+
const moduleLevel = this.level ?? this.#manager.getModuleLevel(this.module);
|
|
71
|
+
if (level > moduleLevel) {
|
|
34
72
|
return;
|
|
35
73
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
74
|
+
const effectiveContext = { ...this.context, ...context };
|
|
75
|
+
const finalMessage = interpolateMessage(message, effectiveContext);
|
|
76
|
+
const payload = {
|
|
77
|
+
timestamp: now(),
|
|
78
|
+
level,
|
|
79
|
+
module: this.module,
|
|
80
|
+
message: finalMessage,
|
|
81
|
+
context: effectiveContext,
|
|
82
|
+
};
|
|
83
|
+
this.#manager.log(payload);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
Logger = Logger_1 = __decorate([
|
|
87
|
+
Injectable()
|
|
88
|
+
], Logger);
|
|
89
|
+
export { Logger };
|
|
90
|
+
function moduleFromArgument(argument) {
|
|
91
|
+
if (isString(argument)) {
|
|
92
|
+
return toArray(argument);
|
|
38
93
|
}
|
|
94
|
+
if (isArray(argument)) {
|
|
95
|
+
return argument;
|
|
96
|
+
}
|
|
97
|
+
if (isObject(argument)) {
|
|
98
|
+
return moduleFromArgument(argument.module);
|
|
99
|
+
}
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
const cachedDereference = getCachedDereference({ optional: true });
|
|
103
|
+
function interpolateMessage(message, context) {
|
|
104
|
+
return message.replace(/{([^{}]+)}/g, (match, key) => {
|
|
105
|
+
if (hasOwnProperty(context, key)) {
|
|
106
|
+
const value = cachedDereference(context, key);
|
|
107
|
+
return String(value);
|
|
108
|
+
}
|
|
109
|
+
return match;
|
|
110
|
+
});
|
|
39
111
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { LogPayload } from './formatter.js';
|
|
2
|
+
import { LogLevel } from './level.js';
|
|
3
|
+
export declare class LogManager {
|
|
4
|
+
#private;
|
|
5
|
+
log(payload: LogPayload): void;
|
|
6
|
+
setDefaultLevel(level: LogLevel): void;
|
|
7
|
+
/**
|
|
8
|
+
* Sets the log level for a specific module.
|
|
9
|
+
* @param module The module (e.g., 'Api.Users' or ['Api', 'Users'])
|
|
10
|
+
* @param level The log level to set
|
|
11
|
+
*/
|
|
12
|
+
setModuleLevel(module: string | string[], level: LogLevel): void;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the effective log level for a given module path.
|
|
15
|
+
* It finds the most specific rule matching the module path.
|
|
16
|
+
* @param modulePath Array of module names, e.g., ['Api', 'Users']
|
|
17
|
+
* @returns The effective log level
|
|
18
|
+
*/
|
|
19
|
+
getModuleLevel(modulePath?: string | string[]): LogLevel;
|
|
20
|
+
}
|