@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
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CancellationSignal } from '../cancellation/token.js';
|
|
2
|
+
import { type ProvidersItem } from '../injector/injector.js';
|
|
2
3
|
import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js';
|
|
3
4
|
import type { LoggerArgument } from '../logger/index.js';
|
|
4
|
-
import
|
|
5
|
-
import type { FunctionModuleFunction } from '../module/modules/function.module.js';
|
|
5
|
+
import { Module } from '../module/index.js';
|
|
6
6
|
import type { OneOrMany, Type } from '../types/index.js';
|
|
7
|
-
export type
|
|
8
|
-
export type
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export type InitializerFn = () => void | Promise<void>;
|
|
8
|
+
export type DestructorFn = () => void | Promise<void>;
|
|
9
|
+
export declare const APPLICATION_MODULE: import("../injector/token.js").InjectionToken<Module, never>;
|
|
10
|
+
export declare const APPLICATION_INITIALIZER: import("../injector/token.js").InjectionToken<InitializerFn, never>;
|
|
11
|
+
export declare const APPLICATION_DESTRUCTOR: import("../injector/token.js").InjectionToken<DestructorFn, never>;
|
|
11
12
|
export type ApplicationArgument = LoggerArgument;
|
|
12
13
|
export declare class Application implements Resolvable<ApplicationArgument> {
|
|
13
14
|
#private;
|
|
14
|
-
static _instance: Application | undefined;
|
|
15
|
-
private static get instance();
|
|
16
15
|
readonly [resolveArgumentType]: string;
|
|
16
|
+
static create(name: string, providers?: OneOrMany<ProvidersItem>[]): Application;
|
|
17
|
+
static run(name: string, providers?: OneOrMany<ProvidersItem>[]): Application;
|
|
17
18
|
get shutdownSignal(): CancellationSignal;
|
|
18
|
-
static get shutdownSignal(): CancellationSignal;
|
|
19
|
-
static registerModule(moduleType: Type<Module>): void;
|
|
20
|
-
static registerModuleFunction(fn: FunctionModuleFunction): void;
|
|
21
|
-
static run(...functionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
|
|
22
|
-
static waitForShutdown(): Promise<void>;
|
|
23
|
-
static shutdown(): Promise<void>;
|
|
24
|
-
static requestShutdown(): void;
|
|
25
19
|
registerModule(moduleType: Module | Type<Module>): void;
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
run(): void;
|
|
21
|
+
runAndWait(): Promise<void>;
|
|
28
22
|
shutdown(): Promise<void>;
|
|
29
23
|
requestShutdown(): void;
|
|
30
24
|
waitForShutdown(): Promise<void>;
|
|
@@ -5,75 +5,54 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
var Application_1;
|
|
8
|
-
import {
|
|
8
|
+
import { CancellationSignal, CancellationToken } from '../cancellation/token.js';
|
|
9
9
|
import { Singleton } from '../injector/decorators.js';
|
|
10
|
-
import { inject, injectArgument, runInInjectionContext } from '../injector/inject.js';
|
|
10
|
+
import { inject, injectAll, injectArgument, runInInjectionContext } from '../injector/inject.js';
|
|
11
11
|
import { Injector } from '../injector/injector.js';
|
|
12
|
+
import { injectionToken } from '../injector/token.js';
|
|
12
13
|
import { Logger } from '../logger/index.js';
|
|
13
|
-
import {
|
|
14
|
-
import { ModuleState } from '../module/module.js';
|
|
15
|
-
import { FunctionModule } from '../module/modules/function.module.js';
|
|
16
|
-
import { getShutdownSignal, getShutdownToken } from '../process-shutdown.js';
|
|
14
|
+
import { Module, ModuleState } from '../module/index.js';
|
|
17
15
|
import { DeferredPromise } from '../promise/deferred-promise.js';
|
|
18
|
-
import { toArray } from '../utils/array/array.js';
|
|
19
16
|
import { mapAsync } from '../utils/async-iterable-helpers/map.js';
|
|
20
17
|
import { toArrayAsync } from '../utils/async-iterable-helpers/to-array.js';
|
|
21
|
-
import { isDefined, isFunction
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (isUndefined(this._instance)) {
|
|
27
|
-
this._instance = getGlobalInjector().resolve(Application_1, 'App');
|
|
28
|
-
// @ts-expect-error readonly
|
|
29
|
-
this._instance.#shutdownToken = getShutdownToken();
|
|
30
|
-
}
|
|
31
|
-
return this._instance;
|
|
32
|
-
}
|
|
18
|
+
import { isDefined, isFunction } from '../utils/type-guards.js';
|
|
19
|
+
export const APPLICATION_MODULE = injectionToken('ApplicationModule');
|
|
20
|
+
export const APPLICATION_INITIALIZER = injectionToken('ApplicationInitializer');
|
|
21
|
+
export const APPLICATION_DESTRUCTOR = injectionToken('ApplicationDestructor');
|
|
22
|
+
let Application = Application_1 = class Application {
|
|
33
23
|
#name = injectArgument(this);
|
|
34
|
-
#injector = inject(Injector)
|
|
35
|
-
#logger =
|
|
36
|
-
#moduleTypesAndInstances = new Set();
|
|
24
|
+
#injector = inject(Injector);
|
|
25
|
+
#logger = inject(Logger, this.#name);
|
|
26
|
+
#moduleTypesAndInstances = new Set(injectAll(APPLICATION_MODULE, undefined, { optional: true }));
|
|
37
27
|
#shutdownPromise = new DeferredPromise();
|
|
38
|
-
#shutdownToken =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
static registerModule(moduleType) {
|
|
46
|
-
Application_1.instance.registerModule(moduleType);
|
|
47
|
-
}
|
|
48
|
-
static registerModuleFunction(fn) {
|
|
49
|
-
Application_1.instance.registerModuleFunction(fn);
|
|
50
|
-
}
|
|
51
|
-
static run(...functionsAndModules) {
|
|
52
|
-
Application_1.instance.run(...functionsAndModules);
|
|
53
|
-
}
|
|
54
|
-
static async waitForShutdown() {
|
|
55
|
-
return Application_1.instance.waitForShutdown();
|
|
28
|
+
#shutdownToken = inject(CancellationSignal, undefined, { optional: true })?.createChild() ?? new CancellationToken();
|
|
29
|
+
static create(name, providers = []) {
|
|
30
|
+
const injector = new Injector(`${name}Injector`);
|
|
31
|
+
for (const providersItem of providers.flat()) {
|
|
32
|
+
injector.register(providersItem.provide, providersItem, { multi: providersItem.multi });
|
|
33
|
+
}
|
|
34
|
+
return injector.resolve(Application_1, name);
|
|
56
35
|
}
|
|
57
|
-
static
|
|
58
|
-
|
|
36
|
+
static run(name, providers = []) {
|
|
37
|
+
const app = Application_1.create(name, providers);
|
|
38
|
+
app.run();
|
|
39
|
+
return app;
|
|
59
40
|
}
|
|
60
|
-
|
|
61
|
-
|
|
41
|
+
get shutdownSignal() {
|
|
42
|
+
return this.#shutdownToken.signal;
|
|
62
43
|
}
|
|
63
44
|
registerModule(moduleType) {
|
|
64
45
|
this.#moduleTypesAndInstances.add(moduleType);
|
|
65
46
|
}
|
|
66
|
-
|
|
67
|
-
const module = new FunctionModule(fn);
|
|
68
|
-
this.registerModule(module);
|
|
69
|
-
}
|
|
70
|
-
run(...optionsFunctionsAndModules) {
|
|
47
|
+
run() {
|
|
71
48
|
if (this.#shutdownToken.isSet) {
|
|
72
49
|
throw new Error('Application was shut down.');
|
|
73
50
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
51
|
+
void this._run();
|
|
52
|
+
}
|
|
53
|
+
async runAndWait() {
|
|
54
|
+
this.run();
|
|
55
|
+
await this.waitForShutdown();
|
|
77
56
|
}
|
|
78
57
|
async shutdown() {
|
|
79
58
|
this.requestShutdown();
|
|
@@ -86,28 +65,19 @@ let Application = class Application {
|
|
|
86
65
|
this.#shutdownToken.set();
|
|
87
66
|
}
|
|
88
67
|
async waitForShutdown() {
|
|
89
|
-
|
|
68
|
+
await this.#shutdownPromise;
|
|
90
69
|
}
|
|
91
|
-
async _run(
|
|
70
|
+
async _run() {
|
|
92
71
|
let modules;
|
|
93
72
|
try {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.registerModuleFunction(fnOrModule);
|
|
100
|
-
}
|
|
73
|
+
const initializers = await this.#injector.resolveAllAsync(APPLICATION_INITIALIZER, undefined, { optional: true });
|
|
74
|
+
for (const initializer of initializers) {
|
|
75
|
+
await runInInjectionContext(this.#injector, initializer);
|
|
101
76
|
}
|
|
102
|
-
|
|
103
|
-
for (const fn of toArray(options.bootstrap)) {
|
|
104
|
-
await runInInjectionContext(this.#injector, fn);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
modules = await toArrayAsync(mapAsync(this.#moduleTypesAndInstances, async (instanceOrType) => (isFunction(instanceOrType) ? this.#injector.resolveAsync(instanceOrType) : instanceOrType)));
|
|
77
|
+
modules = await toArrayAsync(mapAsync(this.#moduleTypesAndInstances, async (instanceOrType) => (isFunction(instanceOrType) ? await this.#injector.resolveAsync(instanceOrType) : instanceOrType)));
|
|
108
78
|
await Promise.race([
|
|
109
79
|
this.runModules(modules),
|
|
110
|
-
this.shutdownSignal
|
|
80
|
+
this.shutdownSignal,
|
|
111
81
|
]);
|
|
112
82
|
}
|
|
113
83
|
catch (error) {
|
|
@@ -119,6 +89,15 @@ let Application = class Application {
|
|
|
119
89
|
if (isDefined(modules)) {
|
|
120
90
|
await this.stopModules(modules);
|
|
121
91
|
}
|
|
92
|
+
const destructors = await this.#injector.resolveAllAsync(APPLICATION_DESTRUCTOR, undefined, { optional: true });
|
|
93
|
+
for (const destructor of destructors) {
|
|
94
|
+
try {
|
|
95
|
+
await runInInjectionContext(this.#injector, destructor);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
this.#logger.error(error, { message: 'An error occurred during application destruction.' });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
122
101
|
await this.#injector.dispose();
|
|
123
102
|
this.#logger.info('Bye');
|
|
124
103
|
}
|
|
@@ -128,7 +107,7 @@ let Application = class Application {
|
|
|
128
107
|
const promises = modules.map(async (module) => {
|
|
129
108
|
try {
|
|
130
109
|
this.#logger.info(`Starting module ${module.name}`);
|
|
131
|
-
await runInInjectionContext(this.#injector, async () => module.run());
|
|
110
|
+
await runInInjectionContext(this.#injector, async () => await module.run());
|
|
132
111
|
this.#logger.info(`Module ${module.name} stopped.`);
|
|
133
112
|
}
|
|
134
113
|
catch (error) {
|
package/application/index.d.ts
CHANGED
package/application/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CancellationSignal } from '../cancellation/index.js';
|
|
2
|
+
import { type ProvidersItem } from '../injector/index.js';
|
|
3
|
+
import { Module, type FunctionModuleFunction } from '../module/index.js';
|
|
4
|
+
import type { OneOrMany, Type } from '../types/index.js';
|
|
5
|
+
import { type DestructorFn, type InitializerFn } from './application.js';
|
|
6
|
+
export declare function provideModules(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): ProvidersItem[];
|
|
7
|
+
export declare function provideInitializer(fn: InitializerFn): ProvidersItem;
|
|
8
|
+
export declare function provideDestructor(fn: DestructorFn): ProvidersItem;
|
|
9
|
+
export declare function provideShutdownSignal(signal: CancellationSignal): ProvidersItem;
|
|
10
|
+
export declare function provideSignalHandler(): ProvidersItem;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CancellationSignal } from '../cancellation/index.js';
|
|
2
|
+
import { inject } from '../injector/index.js';
|
|
3
|
+
import { Logger } from '../logger/index.js';
|
|
4
|
+
import { FunctionModule, Module } from '../module/index.js';
|
|
5
|
+
import { isFunction } from '../utils/type-guards.js';
|
|
6
|
+
import { typeExtends } from '../utils/type/index.js';
|
|
7
|
+
import { Application, APPLICATION_DESTRUCTOR, APPLICATION_INITIALIZER, APPLICATION_MODULE } from './application.js';
|
|
8
|
+
const quitSignals = ['SIGTERM', 'SIGINT', 'SIGHUP', 'SIGBREAK'];
|
|
9
|
+
const quitEvents = ['uncaughtException', 'unhandledRejection', 'rejectionHandled'];
|
|
10
|
+
export function provideModules(...functionsAndModules) {
|
|
11
|
+
return functionsAndModules.flat().map((fnOrModule) => {
|
|
12
|
+
if (typeExtends(fnOrModule, Module)) {
|
|
13
|
+
return { provide: APPLICATION_MODULE, useValue: fnOrModule, multi: true };
|
|
14
|
+
}
|
|
15
|
+
else if (isFunction(fnOrModule)) {
|
|
16
|
+
return { provide: APPLICATION_MODULE, useToken: FunctionModule, defaultArgument: fnOrModule, multi: true };
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new TypeError('Invalid module or function provided to provideModules');
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function provideInitializer(fn) {
|
|
24
|
+
return { provide: APPLICATION_INITIALIZER, useValue: fn, multi: true };
|
|
25
|
+
}
|
|
26
|
+
export function provideDestructor(fn) {
|
|
27
|
+
return { provide: APPLICATION_DESTRUCTOR, useValue: fn, multi: true };
|
|
28
|
+
}
|
|
29
|
+
export function provideShutdownSignal(signal) {
|
|
30
|
+
return { provide: CancellationSignal, useValue: signal };
|
|
31
|
+
}
|
|
32
|
+
export function provideSignalHandler() {
|
|
33
|
+
let signalCounter = 0;
|
|
34
|
+
return provideInitializer(() => {
|
|
35
|
+
const application = inject(Application);
|
|
36
|
+
const logger = inject(Logger);
|
|
37
|
+
for (const event of quitEvents) {
|
|
38
|
+
process.on(event, (...args) => {
|
|
39
|
+
logger.error(`QuitEvent occurred: ${event}`, { details: args });
|
|
40
|
+
application.requestShutdown();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
for (const quitSignal of quitSignals) {
|
|
44
|
+
process.on(quitSignal, (signal) => {
|
|
45
|
+
logger.info(`${signal} received, quitting.`);
|
|
46
|
+
application.requestShutdown();
|
|
47
|
+
if (++signalCounter > 1) {
|
|
48
|
+
logger.warn('Forcefully quitting due to multiple signals...');
|
|
49
|
+
setTimeout(() => process.exit(1), 1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { AsyncDisposable } from '../../disposable/index.js';
|
|
2
|
-
import { disposeAsync } from '../../disposable/index.js';
|
|
3
1
|
import type { AfterResolve } from '../../injector/index.js';
|
|
4
2
|
import { afterResolve } from '../../injector/index.js';
|
|
5
3
|
import type { Record } from '../../types/index.js';
|
|
@@ -95,7 +93,7 @@ export declare class AuthenticationClientService<AdditionalTokenPayload extends
|
|
|
95
93
|
*/
|
|
96
94
|
initialize(): void;
|
|
97
95
|
/** @internal */
|
|
98
|
-
[
|
|
96
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
99
97
|
/**
|
|
100
98
|
* Disposes the service.
|
|
101
99
|
* Stops refresh loop and completes subjects.
|
|
@@ -9,7 +9,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Subject, filter, firstValueFrom, race, timer } from 'rxjs';
|
|
11
11
|
import { CancellationToken } from '../../cancellation/token.js';
|
|
12
|
-
import { disposeAsync } from '../../disposable/index.js';
|
|
13
12
|
import { BadRequestError } from '../../errors/bad-request.error.js';
|
|
14
13
|
import { ForbiddenError } from '../../errors/forbidden.error.js';
|
|
15
14
|
import { InvalidTokenError } from '../../errors/invalid-token.error.js';
|
|
@@ -162,7 +161,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
162
161
|
void this.refreshLoop();
|
|
163
162
|
}
|
|
164
163
|
/** @internal */
|
|
165
|
-
async [
|
|
164
|
+
async [Symbol.asyncDispose]() {
|
|
166
165
|
await this.dispose();
|
|
167
166
|
}
|
|
168
167
|
/**
|
|
@@ -254,7 +253,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
254
253
|
if (this.impersonated()) {
|
|
255
254
|
throw new Error('Already impersonating. Please unimpersonate first.');
|
|
256
255
|
}
|
|
257
|
-
await this.lock.use(lockTimeout,
|
|
256
|
+
await this.lock.use(lockTimeout, async () => {
|
|
258
257
|
this.impersonatorAuthenticationData = this.authenticationData;
|
|
259
258
|
this.authenticationData = data;
|
|
260
259
|
try {
|
|
@@ -275,7 +274,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
275
274
|
* @param data Additional authentication data. If not provided, the data from before impersonation is used.
|
|
276
275
|
*/
|
|
277
276
|
async unimpersonate(data) {
|
|
278
|
-
await this.lock.use(lockTimeout,
|
|
277
|
+
await this.lock.use(lockTimeout, async () => {
|
|
279
278
|
const newData = data ?? this.impersonatorAuthenticationData;
|
|
280
279
|
try {
|
|
281
280
|
const token = await this.client.unimpersonate({ data: newData });
|
|
@@ -334,7 +333,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
334
333
|
while (this.disposeToken.isUnset) {
|
|
335
334
|
try {
|
|
336
335
|
// Use a non-blocking lock to ensure only one tab/instance runs the refresh logic at a time.
|
|
337
|
-
await this.lock.
|
|
336
|
+
await this.lock.tryUse(undefined, async () => await this.refreshLoopIteration());
|
|
338
337
|
// Calculate delay until the next refresh check.
|
|
339
338
|
// The buffer ensures we refresh *before* the token actually expires.
|
|
340
339
|
const delay = ((this.token()?.exp ?? 0) - this.estimatedServerTimestampSeconds() - refreshBufferSeconds) * millisecondsPerSecond;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { BrowserContext, Page } from 'playwright';
|
|
2
|
-
import type { AsyncDisposable } from '../disposable/disposable.js';
|
|
3
|
-
import { disposeAsync } from '../disposable/disposable.js';
|
|
4
2
|
import type { Resolvable } from '../injector/interfaces.js';
|
|
5
3
|
import { afterResolve, resolveArgumentType } from '../injector/interfaces.js';
|
|
6
4
|
import type { Logger } from '../logger/logger.js';
|
|
@@ -20,14 +18,14 @@ export type BrowserContextState = Tagged<Record<string | number, unknown>, 'Brow
|
|
|
20
18
|
export type BrowserContextControllerArgument = NewBrowserContextOptions;
|
|
21
19
|
export declare class BrowserContextController implements AsyncDisposable, Resolvable<BrowserContextControllerArgument> {
|
|
22
20
|
#private;
|
|
23
|
-
/** @deprecated should be avoided */
|
|
21
|
+
/** @deprecated direct usage of underlying page object should be avoided */
|
|
24
22
|
readonly context: BrowserContext;
|
|
25
23
|
readonly options: BrowserContextControllerOptions;
|
|
26
24
|
readonly [resolveArgumentType]: BrowserContextControllerArgument;
|
|
27
25
|
constructor(context: BrowserContext, options?: BrowserContextControllerOptions);
|
|
28
26
|
[afterResolve](): void;
|
|
29
27
|
initialize(): void;
|
|
30
|
-
[
|
|
28
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
31
29
|
pages(): PageController[];
|
|
32
30
|
/**
|
|
33
31
|
* Get a controller for the page.
|
|
@@ -7,7 +7,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { disposeAsync } from '../disposable/disposable.js';
|
|
11
10
|
import { Injectable } from '../injector/decorators.js';
|
|
12
11
|
import { afterResolve, resolveArgumentType } from '../injector/interfaces.js';
|
|
13
12
|
import { filterUndefinedFromRecord } from '../utils/object/object.js';
|
|
@@ -17,7 +16,7 @@ import { PageController } from './page-controller.js';
|
|
|
17
16
|
import { attachLogger } from './utils.js';
|
|
18
17
|
let BrowserContextController = class BrowserContextController {
|
|
19
18
|
#pageControllers = new WeakMap();
|
|
20
|
-
/** @deprecated should be avoided */
|
|
19
|
+
/** @deprecated direct usage of underlying page object should be avoided */
|
|
21
20
|
context;
|
|
22
21
|
options;
|
|
23
22
|
constructor(context, options = {}) {
|
|
@@ -32,7 +31,7 @@ let BrowserContextController = class BrowserContextController {
|
|
|
32
31
|
page.once('close', () => this.#pageControllers.delete(page));
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
|
-
async [
|
|
34
|
+
async [Symbol.asyncDispose]() {
|
|
36
35
|
await this.close();
|
|
37
36
|
}
|
|
38
37
|
pages() {
|
|
@@ -91,7 +90,7 @@ let BrowserContextController = class BrowserContextController {
|
|
|
91
90
|
}
|
|
92
91
|
}
|
|
93
92
|
async waitForClose() {
|
|
94
|
-
|
|
93
|
+
await new Promise((resolve) => this.context.once('close', () => resolve()));
|
|
95
94
|
}
|
|
96
95
|
attachLogger(logger) {
|
|
97
96
|
attachLogger(this.context, logger);
|
|
@@ -108,8 +107,8 @@ BrowserContextController = __decorate([
|
|
|
108
107
|
const { context: browserContext, controllerOptions } = await browserController.newRawContext(argument);
|
|
109
108
|
value.context = browserContext;
|
|
110
109
|
value.options = controllerOptions;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
110
|
+
},
|
|
111
|
+
},
|
|
113
112
|
}),
|
|
114
113
|
__metadata("design:paramtypes", [Object, Object])
|
|
115
114
|
], BrowserContextController);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Browser, BrowserContext } from 'playwright';
|
|
2
|
-
import type { AsyncDisposable } from '../disposable/disposable.js';
|
|
3
|
-
import { disposeAsync } from '../disposable/disposable.js';
|
|
4
2
|
import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js';
|
|
5
3
|
import type { Record } from '../types/index.js';
|
|
6
4
|
import type { BrowserContextControllerOptions, BrowserContextState, NewPageOptions } from './browser-context-controller.js';
|
|
@@ -29,12 +27,12 @@ export type NewBrowserContextOptions = {
|
|
|
29
27
|
};
|
|
30
28
|
export type BrowserControllerArgument = NewBrowserOptions;
|
|
31
29
|
export declare class BrowserController implements AsyncDisposable, Resolvable<BrowserControllerArgument> {
|
|
32
|
-
/** @deprecated should be avoided */
|
|
30
|
+
/** @deprecated direct usage of underlying browser object should be avoided */
|
|
33
31
|
readonly browser: Browser;
|
|
34
32
|
readonly options: BrowserControllerOptions | undefined;
|
|
35
33
|
readonly [resolveArgumentType]: BrowserControllerArgument;
|
|
36
34
|
constructor(browser: Browser, options?: BrowserControllerOptions);
|
|
37
|
-
[
|
|
35
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
38
36
|
/**
|
|
39
37
|
* @deprecated for internal use
|
|
40
38
|
*/
|
|
@@ -7,7 +7,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { disposeAsync } from '../disposable/disposable.js';
|
|
11
10
|
import { Injectable } from '../injector/decorators.js';
|
|
12
11
|
import { inject } from '../injector/inject.js';
|
|
13
12
|
import { filterUndefinedFromRecord } from '../utils/object/object.js';
|
|
@@ -16,14 +15,14 @@ import { BrowserContextController } from './browser-context-controller.js';
|
|
|
16
15
|
import { BrowserService } from './browser.service.js';
|
|
17
16
|
import { mergeNewBrowserContextOptions } from './utils.js';
|
|
18
17
|
let BrowserController = class BrowserController {
|
|
19
|
-
/** @deprecated should be avoided */
|
|
18
|
+
/** @deprecated direct usage of underlying browser object should be avoided */
|
|
20
19
|
browser;
|
|
21
20
|
options;
|
|
22
21
|
constructor(browser, options) {
|
|
23
22
|
this.browser = browser;
|
|
24
23
|
this.options = options;
|
|
25
24
|
}
|
|
26
|
-
async [
|
|
25
|
+
async [Symbol.asyncDispose]() {
|
|
27
26
|
await this.close();
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
@@ -64,7 +63,7 @@ let BrowserController = class BrowserController {
|
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
async waitForClose() {
|
|
67
|
-
|
|
66
|
+
await new Promise((resolve) => {
|
|
68
67
|
if (!this.browser.isConnected()) {
|
|
69
68
|
resolve();
|
|
70
69
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Browser, LaunchOptions } from 'playwright';
|
|
2
|
-
import type { AsyncDisposable } from '../disposable/disposable.js';
|
|
3
|
-
import { disposeAsync } from '../disposable/disposable.js';
|
|
4
2
|
import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js';
|
|
5
3
|
import { BrowserContextController } from './browser-context-controller.js';
|
|
6
4
|
import type { BrowserControllerOptions, NewBrowserContextOptions } from './browser-controller.js';
|
|
@@ -26,7 +24,7 @@ export declare class BrowserService implements AsyncDisposable, Resolvable<Brows
|
|
|
26
24
|
private readonly persistentBrowserContexts;
|
|
27
25
|
readonly options: BrowserServiceOptions | undefined;
|
|
28
26
|
readonly [resolveArgumentType]: BrowserServiceArgument;
|
|
29
|
-
[
|
|
27
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
30
28
|
/**
|
|
31
29
|
* @deprecated internal use only
|
|
32
30
|
*/
|
|
@@ -4,7 +4,6 @@ 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 { disposeAsync } from '../disposable/disposable.js';
|
|
8
7
|
import { Singleton } from '../injector/decorators.js';
|
|
9
8
|
import { injectArgument } from '../injector/inject.js';
|
|
10
9
|
import { filterUndefinedFromRecord } from '../utils/object/object.js';
|
|
@@ -20,7 +19,7 @@ let BrowserService = class BrowserService {
|
|
|
20
19
|
browsers = new Set();
|
|
21
20
|
persistentBrowserContexts = new Set();
|
|
22
21
|
options = injectArgument(this, { optional: true });
|
|
23
|
-
async [
|
|
22
|
+
async [Symbol.asyncDispose]() {
|
|
24
23
|
await this.dispose();
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Page } from 'playwright';
|
|
2
|
-
import type { AsyncDisposable } from '../disposable/disposable.js';
|
|
3
|
-
import { disposeAsync } from '../disposable/disposable.js';
|
|
4
2
|
import type { Logger } from '../logger/logger.js';
|
|
5
3
|
import type { BrowserContextController } from './browser-context-controller.js';
|
|
6
4
|
import type { DocumentControllerOptions } from './document-controller.js';
|
|
@@ -15,11 +13,11 @@ export type ScrollToCoordinates = {
|
|
|
15
13
|
y?: number;
|
|
16
14
|
};
|
|
17
15
|
export declare class PageController extends DocumentController<Page> implements AsyncDisposable {
|
|
18
|
-
/** @deprecated should be avoided */
|
|
16
|
+
/** @deprecated direct usage of underlying page object should be avoided */
|
|
19
17
|
readonly page: Page;
|
|
20
18
|
readonly options: PageControllerOptions;
|
|
21
19
|
constructor(page: Page, context: BrowserContextController, options?: PageControllerOptions);
|
|
22
|
-
[
|
|
20
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
23
21
|
close(): Promise<void>;
|
|
24
22
|
/** finds pages opened by this page (having opener set to this page) */
|
|
25
23
|
opened(): Promise<PageController[]>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { disposeAsync } from '../disposable/disposable.js';
|
|
2
1
|
import { filterUndefinedFromRecord } from '../utils/object/object.js';
|
|
3
2
|
import { readableStreamFromPromise } from '../utils/stream/from-promise.js';
|
|
4
3
|
import { toReadableStream } from '../utils/stream/to-readable-stream.js';
|
|
@@ -9,7 +8,7 @@ import { DocumentController } from './document-controller.js';
|
|
|
9
8
|
import { ElementController } from './element-controller.js';
|
|
10
9
|
import { attachLogger, delay } from './utils.js';
|
|
11
10
|
export class PageController extends DocumentController {
|
|
12
|
-
/** @deprecated should be avoided */
|
|
11
|
+
/** @deprecated direct usage of underlying page object should be avoided */
|
|
13
12
|
page;
|
|
14
13
|
options;
|
|
15
14
|
constructor(page, context, options = {}) {
|
|
@@ -17,7 +16,7 @@ export class PageController extends DocumentController {
|
|
|
17
16
|
this.page = page;
|
|
18
17
|
this.options = options;
|
|
19
18
|
}
|
|
20
|
-
async [
|
|
19
|
+
async [Symbol.asyncDispose]() {
|
|
21
20
|
await this.close();
|
|
22
21
|
}
|
|
23
22
|
async close() {
|
|
@@ -45,7 +44,7 @@ export class PageController extends DocumentController {
|
|
|
45
44
|
await this.page.setExtraHTTPHeaders(filtered);
|
|
46
45
|
}
|
|
47
46
|
async waitForClose() {
|
|
48
|
-
|
|
47
|
+
await new Promise((resolve) => {
|
|
49
48
|
if (this.page.isClosed()) {
|
|
50
49
|
resolve();
|
|
51
50
|
return;
|
|
@@ -69,7 +68,7 @@ export class PageController extends DocumentController {
|
|
|
69
68
|
}
|
|
70
69
|
async renderPdf(options = {}) {
|
|
71
70
|
const createPdfOptions = convertPdfOptions(options);
|
|
72
|
-
return withTimeout(options.timeout ?? 30 * millisecondsPerSecond, this.page.pdf(createPdfOptions), { errorMessage: 'Rendering pdf timed out.' });
|
|
71
|
+
return await withTimeout(options.timeout ?? 30 * millisecondsPerSecond, this.page.pdf(createPdfOptions), { errorMessage: 'Rendering pdf timed out.' });
|
|
73
72
|
}
|
|
74
73
|
async scroll(deltaX, deltaY) {
|
|
75
74
|
await this.page.mouse.wheel(deltaX, deltaY);
|
|
@@ -87,7 +86,7 @@ export class PageController extends DocumentController {
|
|
|
87
86
|
const offsetY = viewportSize.height / 10;
|
|
88
87
|
const isElement = coordinatesOrController instanceof ElementController;
|
|
89
88
|
while (true) {
|
|
90
|
-
const { scrollWidth, scrollHeight, scrollLeft, scrollTop, clientWidth, clientHeight } = await this.page.evaluate(
|
|
89
|
+
const { scrollWidth, scrollHeight, scrollLeft, scrollTop, clientWidth, clientHeight } = await this.page.evaluate(() => {
|
|
91
90
|
const { scrollWidth, scrollHeight, scrollLeft, scrollTop, clientWidth, clientHeight } = document.documentElement;
|
|
92
91
|
return { scrollWidth, scrollHeight, scrollLeft, scrollTop, clientWidth, clientHeight };
|
|
93
92
|
});
|
|
@@ -139,7 +138,7 @@ function convertPdfOptions(options) {
|
|
|
139
138
|
top: options.margin,
|
|
140
139
|
bottom: options.margin,
|
|
141
140
|
right: options.margin,
|
|
142
|
-
left: options.margin
|
|
141
|
+
left: options.margin,
|
|
143
142
|
};
|
|
144
143
|
return {
|
|
145
144
|
format: options.format ?? 'a4',
|
|
@@ -151,6 +150,6 @@ function convertPdfOptions(options) {
|
|
|
151
150
|
margin,
|
|
152
151
|
displayHeaderFooter: options.displayHeaderFooter ?? (isDefined(options.headerTemplate) || isDefined(options.footerTemplate)),
|
|
153
152
|
headerTemplate: options.headerTemplate,
|
|
154
|
-
footerTemplate: options.footerTemplate
|
|
153
|
+
footerTemplate: options.footerTemplate,
|
|
155
154
|
};
|
|
156
155
|
}
|
package/browser/utils.js
CHANGED
|
@@ -13,7 +13,7 @@ export function getLaunchOptions(options) {
|
|
|
13
13
|
ignoreDefaultArgs: (options.headless == 'new') ? ['--headless'] : undefined,
|
|
14
14
|
headless: headless != false,
|
|
15
15
|
args,
|
|
16
|
-
proxy: options.proxy
|
|
16
|
+
proxy: options.proxy,
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
export function mergeNewBrowserContextOptions(a, b, c) {
|
|
@@ -22,13 +22,13 @@ export function mergeNewBrowserContextOptions(a, b, c) {
|
|
|
22
22
|
...a,
|
|
23
23
|
...b,
|
|
24
24
|
...c,
|
|
25
|
-
extraHttpHeaders: (objectKeys(mergedExtraHttpHeaders).length > 0) ? mergedExtraHttpHeaders : undefined
|
|
25
|
+
extraHttpHeaders: (objectKeys(mergedExtraHttpHeaders).length > 0) ? mergedExtraHttpHeaders : undefined,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
function getPageLogger(page, baseLogger) {
|
|
29
29
|
let pageLogger = pageLoggerMap.get(page);
|
|
30
30
|
if (isUndefined(pageLogger)) {
|
|
31
|
-
pageLogger = baseLogger.
|
|
31
|
+
pageLogger = baseLogger.with({ pageSession: crypto.randomUUID().slice(-12) });
|
|
32
32
|
pageLoggerMap.set(page, pageLogger);
|
|
33
33
|
}
|
|
34
34
|
return pageLogger;
|