@tstdl/base 0.88.7 → 0.89.0
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/index.d.ts +7 -3
- package/api/index.js +7 -3
- package/application/index.d.ts +5 -0
- package/application/index.js +5 -0
- package/authentication/client/authentication.service.d.ts +1 -1
- package/authentication/client/authentication.service.js +4 -4
- package/authentication/client/http-client.middleware.d.ts +2 -2
- package/authentication/client/module.d.ts +2 -2
- package/authentication/client/module.js +2 -2
- package/authentication/index.d.ts +7 -0
- package/authentication/index.js +7 -0
- package/browser/index.d.ts +5 -0
- package/browser/index.js +5 -0
- package/cancellation/index.d.ts +4 -0
- package/cancellation/index.js +4 -0
- package/collections/index.d.ts +5 -0
- package/collections/index.js +5 -0
- package/cookie/index.d.ts +5 -0
- package/cookie/index.js +5 -0
- package/data-structures/index.d.ts +5 -0
- package/data-structures/index.js +5 -0
- package/database/index.d.ts +5 -0
- package/database/index.js +5 -0
- package/database/mongo/index.d.ts +5 -0
- package/database/mongo/index.js +5 -0
- package/database/mongo/module.js +1 -1
- package/decorators/index.d.ts +5 -0
- package/decorators/index.js +5 -0
- package/disposable/index.d.ts +5 -0
- package/disposable/index.js +5 -0
- package/distributed-loop/index.d.ts +5 -0
- package/distributed-loop/index.js +5 -0
- package/enumerable/index.d.ts +5 -0
- package/enumerable/index.js +5 -0
- package/error/index.d.ts +5 -0
- package/error/index.js +5 -0
- package/examples/api/authentication.js +1 -1
- package/examples/api/custom-authentication.js +1 -1
- package/function/index.d.ts +5 -0
- package/function/index.js +5 -0
- package/http/client/index.d.ts +1 -0
- package/http/client/index.js +1 -0
- package/http/index.d.ts +6 -0
- package/http/index.js +6 -0
- package/http/server/index.d.ts +2 -1
- package/http/server/index.js +2 -1
- package/image-service/index.d.ts +6 -0
- package/image-service/index.js +6 -0
- package/index.d.ts +5 -0
- package/index.js +5 -0
- package/injector/index.d.ts +5 -0
- package/injector/index.js +5 -0
- package/json-path/index.d.ts +5 -0
- package/json-path/index.js +5 -0
- package/key-value-store/index.d.ts +6 -0
- package/key-value-store/index.js +6 -0
- package/lock/index.d.ts +7 -0
- package/lock/index.js +7 -0
- package/lock/mongo/lock.d.ts +1 -2
- package/lock/mongo/lock.js +9 -9
- package/lock/mongo/provider.d.ts +3 -7
- package/lock/mongo/provider.js +14 -24
- package/logger/index.d.ts +7 -0
- package/logger/index.js +7 -0
- package/mail/index.d.ts +6 -1
- package/mail/index.js +6 -1
- package/mail/repositories/index.d.ts +2 -1
- package/mail/repositories/index.js +2 -1
- package/memory/index.d.ts +5 -0
- package/memory/index.js +5 -0
- package/message-bus/index.d.ts +7 -0
- package/message-bus/index.js +7 -0
- package/migration/index.d.ts +6 -0
- package/migration/index.js +6 -0
- package/module/index.d.ts +6 -0
- package/module/index.js +6 -0
- package/object-storage/index.d.ts +8 -2
- package/object-storage/index.js +8 -2
- package/openid-connect/index.d.ts +5 -0
- package/openid-connect/index.js +5 -0
- package/package.json +6 -24
- package/password/index.d.ts +5 -0
- package/password/index.js +5 -0
- package/pdf/pdf.service.d.ts +5 -0
- package/pdf/pdf.service.js +5 -0
- package/pool/index.d.ts +5 -0
- package/pool/index.js +5 -0
- package/promise/cancelable-promise.d.ts +10 -2
- package/promise/cancelable-promise.js +23 -19
- package/promise/custom-promise.d.ts +6 -0
- package/promise/custom-promise.js +14 -0
- package/promise/deferred-promise.d.ts +3 -3
- package/promise/deferred-promise.js +5 -8
- package/promise/index.d.ts +6 -0
- package/promise/index.js +6 -0
- package/promise/lazy-promise.d.ts +6 -6
- package/promise/lazy-promise.js +23 -15
- package/promise/types.d.ts +3 -0
- package/promise/types.js +1 -0
- package/utils/type-guards.d.ts +6 -0
- package/utils/type-guards.js +7 -0
- package/container/decorators.d.ts +0 -2
- package/container/decorators.js +0 -1
- package/container/index.d.ts +0 -3
- package/container/index.js +0 -3
- package/container/interfaces.d.ts +0 -2
- package/container/interfaces.js +0 -1
- package/container/token.d.ts +0 -2
- package/container/token.js +0 -1
package/lock/mongo/lock.js
CHANGED
|
@@ -22,12 +22,12 @@ import { MongoLockProvider } from './provider.js';
|
|
|
22
22
|
const expirationTime = 10000;
|
|
23
23
|
const renewBuffer = expirationTime / 2;
|
|
24
24
|
let MongoLock = class MongoLock extends Lock {
|
|
25
|
-
lockRepository;
|
|
26
|
-
logger;
|
|
25
|
+
#lockRepository;
|
|
26
|
+
#logger;
|
|
27
27
|
constructor(lockRepository, resource, logger) {
|
|
28
28
|
super(resource);
|
|
29
|
-
this
|
|
30
|
-
this
|
|
29
|
+
this.#lockRepository = lockRepository;
|
|
30
|
+
this.#logger = logger;
|
|
31
31
|
}
|
|
32
32
|
async acquire(timeout, throwOnFail) {
|
|
33
33
|
const key = getRandomString(15, Alphabet.LowerUpperCaseNumbers);
|
|
@@ -69,7 +69,7 @@ let MongoLock = class MongoLock extends Lock {
|
|
|
69
69
|
expiration = (refreshResult == false) ? new Date(0) : refreshResult; // eslint-disable-line require-atomic-updates
|
|
70
70
|
}
|
|
71
71
|
catch (error) {
|
|
72
|
-
this
|
|
72
|
+
this.#logger.error(error);
|
|
73
73
|
}
|
|
74
74
|
finally {
|
|
75
75
|
await cancelableTimeoutUntil(Math.max(currentTimestamp() + 1000, expiration.valueOf() - renewBuffer), releaseToken);
|
|
@@ -92,18 +92,18 @@ let MongoLock = class MongoLock extends Lock {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
async exists() {
|
|
95
|
-
return this
|
|
95
|
+
return this.#lockRepository.exists(this.resource);
|
|
96
96
|
}
|
|
97
97
|
async tryAcquireOrRefresh(resource, key) {
|
|
98
98
|
const expirationDate = getExpirationDate();
|
|
99
|
-
return this
|
|
99
|
+
return this.#lockRepository.tryInsertOrRefresh(resource, key, expirationDate);
|
|
100
100
|
}
|
|
101
101
|
async tryRefresh(resource, key) {
|
|
102
102
|
const expiration = getExpirationDate();
|
|
103
|
-
return this
|
|
103
|
+
return this.#lockRepository.tryUpdateExpiration(resource, key, expiration);
|
|
104
104
|
}
|
|
105
105
|
async release(resource, key) {
|
|
106
|
-
return this
|
|
106
|
+
return this.#lockRepository.deleteByResource(resource, key);
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
109
|
MongoLock = __decorate([
|
package/lock/mongo/provider.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { Lock } from '../../lock/index.js';
|
|
2
2
|
import { LockProvider } from '../../lock/index.js';
|
|
3
|
-
import { Logger } from '../../logger/index.js';
|
|
4
|
-
import { MongoLockRepository } from './mongo-lock-repository.js';
|
|
5
3
|
export declare class MongoLockProvider extends LockProvider {
|
|
6
|
-
private
|
|
7
|
-
|
|
8
|
-
private readonly _prefix;
|
|
9
|
-
constructor(lockRepository: MongoLockRepository, logger: Logger, prefix?: string);
|
|
10
|
-
prefix(prefix: string): LockProvider;
|
|
4
|
+
#private;
|
|
5
|
+
prefix(prefix: string): MongoLockProvider;
|
|
11
6
|
get(resource: string): Lock;
|
|
7
|
+
private getResourceString;
|
|
12
8
|
}
|
package/lock/mongo/provider.js
CHANGED
|
@@ -4,43 +4,33 @@ 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
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
7
|
var MongoLockProvider_1;
|
|
14
|
-
import {
|
|
8
|
+
import { Singleton } from '../../injector/decorators.js';
|
|
9
|
+
import { inject, injectArgument } from '../../injector/inject.js';
|
|
10
|
+
import { Injector } from '../../injector/injector.js';
|
|
15
11
|
import { LockProvider } from '../../lock/index.js';
|
|
16
12
|
import { Logger } from '../../logger/index.js';
|
|
17
13
|
import { assertDefinedPass } from '../../utils/type-guards.js';
|
|
18
14
|
import { MongoLock } from './lock.js';
|
|
19
15
|
import { mongoLockModuleConfig } from './module.js';
|
|
20
16
|
import { MongoLockRepository } from './mongo-lock-repository.js';
|
|
21
|
-
const collectionArgumentProvider = () => assertDefinedPass(mongoLockModuleConfig.lockEntityRepositoryConfig, 'mongo lock module not configured');
|
|
22
17
|
let MongoLockProvider = MongoLockProvider_1 = class MongoLockProvider extends LockProvider {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
super();
|
|
28
|
-
this.lockRepository = lockRepository;
|
|
29
|
-
this.logger = logger;
|
|
30
|
-
this._prefix = prefix;
|
|
31
|
-
}
|
|
18
|
+
#injector = inject(Injector);
|
|
19
|
+
#lockRepository = inject(MongoLockRepository, assertDefinedPass(mongoLockModuleConfig.lockEntityRepositoryConfig, 'mongo lock module not configured'));
|
|
20
|
+
#logger = inject(Logger, 'MongoLock');
|
|
21
|
+
#prefix = injectArgument(this);
|
|
32
22
|
prefix(prefix) {
|
|
33
|
-
return
|
|
23
|
+
return this.#injector.resolve(MongoLockProvider_1, this.getResourceString(prefix));
|
|
34
24
|
}
|
|
35
25
|
get(resource) {
|
|
36
|
-
return new MongoLock(this
|
|
26
|
+
return new MongoLock(this.#lockRepository, this.getResourceString(resource), this.#logger);
|
|
27
|
+
}
|
|
28
|
+
getResourceString(resource) {
|
|
29
|
+
const prefixDivider = (this.#prefix.length > 0) ? ':' : '';
|
|
30
|
+
return `${this.#prefix}${prefixDivider}${resource}`;
|
|
37
31
|
}
|
|
38
32
|
};
|
|
39
33
|
MongoLockProvider = MongoLockProvider_1 = __decorate([
|
|
40
|
-
Singleton()
|
|
41
|
-
__param(0, ResolveArgProvider(collectionArgumentProvider)),
|
|
42
|
-
__param(1, ResolveArg('MongoLock')),
|
|
43
|
-
__param(2, InjectArg()),
|
|
44
|
-
__metadata("design:paramtypes", [MongoLockRepository, Logger, String])
|
|
34
|
+
Singleton()
|
|
45
35
|
], MongoLockProvider);
|
|
46
36
|
export { MongoLockProvider };
|
package/logger/index.d.ts
CHANGED
package/logger/index.js
CHANGED
package/mail/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send mails with template support
|
|
3
|
+
*
|
|
4
|
+
* @module Mail
|
|
5
|
+
*/
|
|
6
|
+
export * from './clients/index.js';
|
|
1
7
|
export * from './mail.client.js';
|
|
2
8
|
export * from './mail.service.js';
|
|
3
9
|
export * from './models/index.js';
|
|
4
10
|
export * from './module.js';
|
|
5
11
|
export * from './repositories/index.js';
|
|
6
|
-
export * from './repositories/mail-log.repository.js';
|
|
7
12
|
export * from './tokens.js';
|
package/mail/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send mails with template support
|
|
3
|
+
*
|
|
4
|
+
* @module Mail
|
|
5
|
+
*/
|
|
6
|
+
export * from './clients/index.js';
|
|
1
7
|
export * from './mail.client.js';
|
|
2
8
|
export * from './mail.service.js';
|
|
3
9
|
export * from './models/index.js';
|
|
4
10
|
export * from './module.js';
|
|
5
11
|
export * from './repositories/index.js';
|
|
6
|
-
export * from './repositories/mail-log.repository.js';
|
|
7
12
|
export * from './tokens.js';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './mail-log.repository.js';
|
|
2
|
+
export * from './mongo/index.js';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './mail-log.repository.js';
|
|
2
|
+
export * from './mongo/index.js';
|
package/memory/index.d.ts
CHANGED
package/memory/index.js
CHANGED
package/message-bus/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message broadcasting
|
|
3
|
+
*
|
|
4
|
+
* @module Message Bus
|
|
5
|
+
*/
|
|
6
|
+
export * from './broadcast-channel/index.js';
|
|
7
|
+
export * from './local/index.js';
|
|
1
8
|
export * from './message-bus-base.js';
|
|
2
9
|
export * from './message-bus-provider.js';
|
|
3
10
|
export * from './message-bus.js';
|
package/message-bus/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message broadcasting
|
|
3
|
+
*
|
|
4
|
+
* @module Message Bus
|
|
5
|
+
*/
|
|
6
|
+
export * from './broadcast-channel/index.js';
|
|
7
|
+
export * from './local/index.js';
|
|
1
8
|
export * from './message-bus-base.js';
|
|
2
9
|
export * from './message-bus-provider.js';
|
|
3
10
|
export * from './message-bus.js';
|
package/migration/index.d.ts
CHANGED
package/migration/index.js
CHANGED
package/module/index.d.ts
CHANGED
package/module/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Storage for objects/files
|
|
3
|
+
*
|
|
4
|
+
* @module Object Storage
|
|
5
|
+
*/
|
|
3
6
|
export * from './object-storage-provider.js';
|
|
7
|
+
export * from './object-storage.js';
|
|
8
|
+
export * from './object.js';
|
|
9
|
+
export * from './s3/index.js';
|
package/object-storage/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Storage for objects/files
|
|
3
|
+
*
|
|
4
|
+
* @module Object Storage
|
|
5
|
+
*/
|
|
3
6
|
export * from './object-storage-provider.js';
|
|
7
|
+
export * from './object-storage.js';
|
|
8
|
+
export * from './object.js';
|
|
9
|
+
export * from './s3/index.js';
|
package/openid-connect/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OIDC (OAuth 2.0) client implementation
|
|
3
|
+
*
|
|
4
|
+
* @module OpenID Connect
|
|
5
|
+
*/
|
|
1
6
|
import { Injector } from '../injector/injector.js';
|
|
2
7
|
import { CachedOidcConfigurationService } from './cached-oidc-configuration.service.js';
|
|
3
8
|
import { OidcConfigurationService } from './oidc-configuration.service.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.89.0",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"build:production": "rm -rf dist && npm run build && npm run build:production:copy-files",
|
|
13
13
|
"build:production:copy-files": "cp package.json .eslintrc.json tsconfig.server.json dist/ && cp tsconfig.base.json dist/tsconfig.json",
|
|
14
14
|
"build:docs": "typedoc",
|
|
15
|
-
"build:docs
|
|
15
|
+
"build:docs:watch": "typedoc --watch",
|
|
16
16
|
"lint": "eslint -c .eslintrc.json --ext .ts .",
|
|
17
17
|
"pub": "npm run build:production && rm -vf dist/test* && npm publish dist/",
|
|
18
18
|
"tsc:watch": "tsc --watch",
|
|
@@ -32,12 +32,8 @@
|
|
|
32
32
|
"./web-types": "./web-types.js",
|
|
33
33
|
|
|
34
34
|
"./api": "./api/index.js",
|
|
35
|
-
"./api/client": "./api/client/index.js",
|
|
36
|
-
"./api/server": "./api/server/index.js",
|
|
37
35
|
"./application": "./application/index.js",
|
|
38
36
|
"./authentication": "./authentication/index.js",
|
|
39
|
-
"./authentication/client": "./authentication/client/index.js",
|
|
40
|
-
"./authentication/server": "./authentication/server/index.js",
|
|
41
37
|
"./browser": "./browser/index.js",
|
|
42
38
|
"./cancellation": "./cancellation/index.js",
|
|
43
39
|
"./cookie": "./cookie/index.js",
|
|
@@ -51,34 +47,18 @@
|
|
|
51
47
|
"./error": "./error/index.js",
|
|
52
48
|
"./function": "./function/index.js",
|
|
53
49
|
"./http": "./http/index.js",
|
|
54
|
-
"./http/client/adapters": "./http/client/adapters/index.js",
|
|
55
|
-
"./http/server": "./http/server/index.js",
|
|
56
|
-
"./http/server/node": "./http/server/node/index.js",
|
|
57
50
|
"./image-service": "./image-service/index.js",
|
|
58
|
-
"./image-service/imgproxy": "./image-service/imgproxy/index.js",
|
|
59
51
|
"./injector": "./injector/index.js",
|
|
60
52
|
"./json-path": "./json-path/index.js",
|
|
61
53
|
"./key-value-store": "./key-value-store/index.js",
|
|
62
|
-
"./key-value-store/mongo": "./key-value-store/mongo/index.js",
|
|
63
54
|
"./lock": "./lock/index.js",
|
|
64
|
-
"./lock/mongo": "./lock/mongo/index.js",
|
|
65
|
-
"./lock/web": "./lock/web/index.js",
|
|
66
55
|
"./logger": "./logger/index.js",
|
|
67
|
-
"./logger/console": "./logger/console/index.js",
|
|
68
|
-
"./logger/noop": "./logger/noop/index.js",
|
|
69
56
|
"./mail": "./mail/index.js",
|
|
70
|
-
"./mail/clients": "./mail/clients/index.js",
|
|
71
|
-
"./mail/repositories/mongo": "./mail/repositories/mongo/index.js",
|
|
72
57
|
"./memory": "./memory/index.js",
|
|
73
58
|
"./message-bus": "./message-bus/index.js",
|
|
74
|
-
"./message-bus/broadcast-channel": "./message-bus/broadcast-channel/index.js",
|
|
75
|
-
"./message-bus/local": "./message-bus/local/index.js",
|
|
76
59
|
"./migration": "./migration/index.js",
|
|
77
|
-
"./migration/mongo": "./migration/mongo/index.js",
|
|
78
60
|
"./module": "./module/index.js",
|
|
79
|
-
"./module/modules": "./module/modules/index.js",
|
|
80
61
|
"./object-storage": "./object-storage/index.js",
|
|
81
|
-
"./object-storage/s3": "./object-storage/s3/index.js",
|
|
82
62
|
"./openid-connect": "./openid-connect/index.js",
|
|
83
63
|
"./password": "./password/index.js",
|
|
84
64
|
"./pdf": "./pdf/index.js",
|
|
@@ -127,6 +107,7 @@
|
|
|
127
107
|
"type-fest": "^4.3"
|
|
128
108
|
},
|
|
129
109
|
"devDependencies": {
|
|
110
|
+
"@mxssfd/typedoc-theme": "1.1",
|
|
130
111
|
"@types/chroma-js": "2.4",
|
|
131
112
|
"@types/koa__router": "12.0",
|
|
132
113
|
"@types/luxon": "3.3",
|
|
@@ -143,12 +124,13 @@
|
|
|
143
124
|
"eslint-plugin-import": "2.28",
|
|
144
125
|
"tsc-alias": "1.8",
|
|
145
126
|
"typedoc": "0.25",
|
|
127
|
+
"typedoc-plugin-missing-exports": "2.1",
|
|
146
128
|
"typescript": "5.2"
|
|
147
129
|
},
|
|
148
130
|
"peerDependencies": {
|
|
149
131
|
"@elastic/elasticsearch": "^8.9",
|
|
150
132
|
"@koa/router": "^12.0",
|
|
151
|
-
"@tstdl/angular": "^0.
|
|
133
|
+
"@tstdl/angular": "^0.89",
|
|
152
134
|
"@zxcvbn-ts/core": "^3.0",
|
|
153
135
|
"@zxcvbn-ts/language-common": "^3.0",
|
|
154
136
|
"@zxcvbn-ts/language-de": "^3.0",
|
|
@@ -164,7 +146,7 @@
|
|
|
164
146
|
"playwright": "^1.38",
|
|
165
147
|
"preact": "^10.17",
|
|
166
148
|
"preact-render-to-string": "^6.2",
|
|
167
|
-
"undici": "^5.
|
|
149
|
+
"undici": "^5.25",
|
|
168
150
|
"urlpattern-polyfill": "^9.0"
|
|
169
151
|
},
|
|
170
152
|
"peerDependenciesMeta": {
|
package/password/index.d.ts
CHANGED
package/password/index.js
CHANGED
package/pdf/pdf.service.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF generation
|
|
3
|
+
*
|
|
4
|
+
* @module PDF
|
|
5
|
+
*/
|
|
1
6
|
import { BrowserContextController } from '../browser/browser-context-controller.js';
|
|
2
7
|
import type { BrowserControllerArgument } from '../browser/browser-controller.js';
|
|
3
8
|
import { BrowserController } from '../browser/browser-controller.js';
|
package/pdf/pdf.service.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF generation
|
|
3
|
+
*
|
|
4
|
+
* @module PDF
|
|
5
|
+
*/
|
|
1
6
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
7
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
8
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
package/pool/index.d.ts
CHANGED
package/pool/index.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { type CancellationSignal } from '../cancellation/token.js';
|
|
2
|
+
import { CustomPromise } from './custom-promise.js';
|
|
3
|
+
export type CancelablePromiseExecutor<T> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void, cancellationSignal: CancellationSignal) => void;
|
|
4
|
+
export type CancelablePromiseResult<T, R> = {
|
|
2
5
|
canceled: true;
|
|
6
|
+
reason: R;
|
|
3
7
|
} | {
|
|
4
8
|
canceled: false;
|
|
5
9
|
value: T;
|
|
6
10
|
};
|
|
7
|
-
export declare
|
|
11
|
+
export declare class CancelablePromise<T, R = void> extends CustomPromise<CancelablePromiseResult<T, R>> {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(executor: CancelablePromiseExecutor<T>);
|
|
14
|
+
cancel(reason: R): void;
|
|
15
|
+
}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { CancellationToken } from '../cancellation/token.js';
|
|
2
|
+
import { CustomPromise } from './custom-promise.js';
|
|
3
|
+
export class CancelablePromise extends CustomPromise {
|
|
4
|
+
#cancellationToken = new CancellationToken();
|
|
5
|
+
#resolve;
|
|
6
|
+
#reject;
|
|
7
|
+
#pending = true;
|
|
8
|
+
constructor(executor) {
|
|
9
|
+
super();
|
|
10
|
+
this.#resolve = (value) => {
|
|
11
|
+
if (this.#pending) {
|
|
12
|
+
this.resolve(value);
|
|
13
|
+
this.#pending = false;
|
|
9
14
|
}
|
|
10
15
|
};
|
|
11
|
-
|
|
12
|
-
if (pending) {
|
|
13
|
-
reject(reason);
|
|
14
|
-
pending = false;
|
|
16
|
+
this.#reject = (reason) => {
|
|
17
|
+
if (this.#pending) {
|
|
18
|
+
this.reject(reason);
|
|
19
|
+
this.#pending = false;
|
|
15
20
|
}
|
|
16
21
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
22
|
+
executor((value) => this.#resolve(Promise.resolve(value).then((result) => ({ canceled: false, value: result }))), this.#reject, this.#cancellationToken.signal);
|
|
23
|
+
}
|
|
24
|
+
cancel(reason) {
|
|
25
|
+
this.#cancellationToken.set();
|
|
26
|
+
this.#resolve({ canceled: true, reason });
|
|
27
|
+
}
|
|
24
28
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PromiseRejectFunction, PromiseResolveFunction } from './types.js';
|
|
2
|
+
export declare class CustomPromise<T> extends Promise<T> {
|
|
3
|
+
protected readonly resolve: PromiseResolveFunction<T>;
|
|
4
|
+
protected readonly reject: PromiseRejectFunction;
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class CustomPromise extends Promise {
|
|
2
|
+
resolve;
|
|
3
|
+
reject;
|
|
4
|
+
constructor() {
|
|
5
|
+
let _resolve;
|
|
6
|
+
let _reject;
|
|
7
|
+
super((resolve, reject) => {
|
|
8
|
+
_resolve = resolve;
|
|
9
|
+
_reject = reject;
|
|
10
|
+
});
|
|
11
|
+
this.resolve = _resolve;
|
|
12
|
+
this.reject = _reject;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { PromiseExecutor } from './types.js';
|
|
1
2
|
export declare const enum PromiseState {
|
|
2
3
|
Pending = 0,
|
|
3
4
|
Resolved = 1,
|
|
4
5
|
Rejected = 2
|
|
5
6
|
}
|
|
6
|
-
export declare class DeferredPromise<T = void>
|
|
7
|
-
static readonly [Symbol.species]: PromiseConstructor;
|
|
7
|
+
export declare class DeferredPromise<T = void> extends Promise<T> {
|
|
8
8
|
private backingPromise;
|
|
9
9
|
private resolvePromise;
|
|
10
10
|
private rejectPromise;
|
|
@@ -14,7 +14,7 @@ export declare class DeferredPromise<T = void> implements Promise<T> {
|
|
|
14
14
|
get rejected(): boolean;
|
|
15
15
|
get pending(): boolean;
|
|
16
16
|
get settled(): boolean;
|
|
17
|
-
constructor(executor?:
|
|
17
|
+
constructor(executor?: PromiseExecutor<T>);
|
|
18
18
|
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
|
19
19
|
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
|
|
20
20
|
finally(onfinally?: (() => void) | null | undefined): Promise<T>;
|
|
@@ -4,8 +4,7 @@ export var PromiseState;
|
|
|
4
4
|
PromiseState[PromiseState["Resolved"] = 1] = "Resolved";
|
|
5
5
|
PromiseState[PromiseState["Rejected"] = 2] = "Rejected";
|
|
6
6
|
})(PromiseState || (PromiseState = {}));
|
|
7
|
-
export class DeferredPromise {
|
|
8
|
-
static [Symbol.species] = Promise;
|
|
7
|
+
export class DeferredPromise extends Promise {
|
|
9
8
|
backingPromise;
|
|
10
9
|
resolvePromise;
|
|
11
10
|
rejectPromise;
|
|
@@ -24,21 +23,19 @@ export class DeferredPromise {
|
|
|
24
23
|
return this.state != PromiseState.Pending;
|
|
25
24
|
}
|
|
26
25
|
constructor(executor) {
|
|
26
|
+
super(() => { });
|
|
27
27
|
this.reset();
|
|
28
28
|
if (executor != undefined) {
|
|
29
29
|
executor((value) => this.resolve(value), (reason) => this.reject(reason));
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
then(onfulfilled, onrejected) {
|
|
32
|
+
async then(onfulfilled, onrejected) {
|
|
34
33
|
return this.backingPromise.then(onfulfilled, onrejected);
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
catch(onrejected) {
|
|
35
|
+
async catch(onrejected) {
|
|
38
36
|
return this.backingPromise.catch(onrejected);
|
|
39
37
|
}
|
|
40
|
-
|
|
41
|
-
finally(onfinally) {
|
|
38
|
+
async finally(onfinally) {
|
|
42
39
|
return this.backingPromise.finally(onfinally);
|
|
43
40
|
}
|
|
44
41
|
resolve(value) {
|
package/promise/index.d.ts
CHANGED