@tstdl/base 0.91.25 → 0.91.27

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.
@@ -1,8 +1,8 @@
1
1
  import { firstValueFrom } from 'rxjs';
2
- import { cacheAsyncValueOrProvider } from '../../utils/value-or-provider.js';
2
+ import { cacheValueOrAsyncProvider } from '../../utils/value-or-provider.js';
3
3
  import { dontWaitForValidToken } from '../authentication.api.js';
4
4
  export function waitForAuthenticationCredentialsMiddleware(authenticationServiceOrProvider) {
5
- const getAuthenticationService = cacheAsyncValueOrProvider(authenticationServiceOrProvider);
5
+ const getAuthenticationService = cacheValueOrAsyncProvider(authenticationServiceOrProvider);
6
6
  // eslint-disable-next-line @typescript-eslint/no-shadow
7
7
  async function waitForAuthenticationCredentialsMiddleware({ request }, next) {
8
8
  const endpoint = request.context?.endpoint;
@@ -1,6 +1,5 @@
1
- import type { CancellationSignal } from '../cancellation/token.js';
2
- import { CancellationToken } from '../cancellation/token.js';
3
- import type { AsyncDisposable, Disposable } from './disposable.js';
1
+ import { type CancellationSignal, CancellationToken } from '../cancellation/token.js';
2
+ import { type AsyncDisposable, type Disposable } from './disposable.js';
4
3
  declare const deferrerToken: unique symbol;
5
4
  export type AsyncDisposeTaskFunction = () => any;
6
5
  export type AsyncDisposeHandler = AsyncDisposeTaskFunction | Disposable | AsyncDisposable;
@@ -1,5 +1,5 @@
1
- import { isDefined, isNullOrUndefined } from '../utils/type-guards.js';
2
1
  import { CancellationToken } from '../cancellation/token.js';
2
+ import { isDefined, isNullOrUndefined } from '../utils/type-guards.js';
3
3
  import { MultiError } from '../errors/multi.error.js';
4
4
  import { dispose, disposeAsync, isAsyncDisposable, isDisposable } from './disposable.js';
5
5
  const deferrerToken = Symbol('DeferrerToken');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.91.25",
3
+ "version": "0.91.27",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -152,10 +152,10 @@
152
152
  "mongodb": "^6.9",
153
153
  "nodemailer": "^6.9",
154
154
  "pg": "^8.13",
155
- "playwright": "^1.47",
155
+ "playwright": "^1.48",
156
156
  "preact": "^10.24",
157
157
  "preact-render-to-string": "^6.5",
158
- "undici": "^6.19",
158
+ "undici": "^6.20",
159
159
  "urlpattern-polyfill": "^10.0"
160
160
  },
161
161
  "peerDependenciesMeta": {
@@ -5,9 +5,9 @@ export type EcdsaCurve = 'P-256' | 'P-384' | 'P-521';
5
5
  export type HashAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
6
6
  export type SymmetricAlgorithm = `AES-${AesMode}`;
7
7
  export type AsymmetricAlgorithm = 'RSASSA-PKCS1-v1_5' | 'RSA-PSS' | 'RSA-OAEP' | 'ECDSA' | 'ECDH' | 'NODE-DSA' | 'NODE-DH' | 'NODE-ED25519' | 'NODE-ED448';
8
- export type CryptionAlgorithm = Parameters<typeof crypto.subtle.encrypt>[0];
9
- export type SignAlgorithm = Parameters<typeof crypto.subtle.sign>[0];
10
- export type KeyAlgorithm = Parameters<typeof crypto.subtle.generateKey>[0];
8
+ export type CryptionAlgorithm = Parameters<typeof globalThis.crypto.subtle.encrypt>[0];
9
+ export type SignAlgorithm = Parameters<typeof globalThis.crypto.subtle.sign>[0];
10
+ export type KeyAlgorithm = Parameters<typeof globalThis.crypto.subtle.generateKey>[0];
11
11
  export type DeriveAlgorithm = Parameters<typeof globalThis.crypto.subtle.deriveBits>['0'];
12
12
  export type KeyType = 'raw' | 'pkcs8' | 'spki' | 'jwk';
13
13
  export type Key = JsonWebKey | BinaryData;
@@ -4,7 +4,6 @@ import { decodeText, encodeHex, encodeUtf8 } from './encoding.js';
4
4
  import { getRandomBytes } from './random.js';
5
5
  import { isArray, isDefined, isString } from './type-guards.js';
6
6
  import { zBase32Encode } from './z-base32.js';
7
- const subtle = globalThis.crypto.subtle;
8
7
  /**
9
8
  * Encrypt data
10
9
  * @param algorithm algorithm as supported by Web Crypto API
@@ -13,7 +12,7 @@ const subtle = globalThis.crypto.subtle;
13
12
  */
14
13
  export function encrypt(algorithm, key, data) {
15
14
  const bytes = isString(data) ? encodeUtf8(data) : data;
16
- const encryptedBuffer = subtle.encrypt(algorithm, key, bytes);
15
+ const encryptedBuffer = globalThis.crypto.subtle.encrypt(algorithm, key, bytes);
17
16
  return {
18
17
  toBuffer: async () => encryptedBuffer,
19
18
  toHex: async () => encodeHex(await encryptedBuffer),
@@ -29,7 +28,7 @@ export function encrypt(algorithm, key, data) {
29
28
  * @param data data to decrypt
30
29
  */
31
30
  export function decrypt(algorithm, key, bytes) {
32
- const decryptedBuffer = subtle.decrypt(algorithm, key, bytes);
31
+ const decryptedBuffer = globalThis.crypto.subtle.decrypt(algorithm, key, bytes);
33
32
  return {
34
33
  toBuffer: async () => decryptedBuffer,
35
34
  toHex: async () => encodeHex(await decryptedBuffer),
@@ -46,7 +45,7 @@ export function decrypt(algorithm, key, bytes) {
46
45
  */
47
46
  export function digest(algorithm, data) {
48
47
  const bytes = isString(data) ? encodeUtf8(data) : data;
49
- const arrayBufferPromise = subtle.digest(algorithm, bytes);
48
+ const arrayBufferPromise = globalThis.crypto.subtle.digest(algorithm, bytes);
50
49
  const result = {
51
50
  toBuffer: async () => arrayBufferPromise,
52
51
  toHex: async () => encodeHex(await arrayBufferPromise),
@@ -64,7 +63,7 @@ export function digest(algorithm, data) {
64
63
  */
65
64
  export function sign(algorithm, key, data) {
66
65
  const bytes = isString(data) ? encodeUtf8(data) : data;
67
- const arrayBufferPromise = subtle.sign(algorithm, key, bytes);
66
+ const arrayBufferPromise = globalThis.crypto.subtle.sign(algorithm, key, bytes);
68
67
  const result = {
69
68
  toBuffer: async () => arrayBufferPromise,
70
69
  toHex: async () => encodeHex(await arrayBufferPromise),
@@ -84,7 +83,7 @@ export function sign(algorithm, key, data) {
84
83
  export async function verify(algorithm, key, signature, data) {
85
84
  const signatureBytes = isString(signature) ? encodeUtf8(signature) : signature;
86
85
  const dataBytes = isString(data) ? encodeUtf8(data) : data;
87
- return subtle.verify(algorithm, key, signatureBytes, dataBytes);
86
+ return globalThis.crypto.subtle.verify(algorithm, key, signatureBytes, dataBytes);
88
87
  }
89
88
  /**
90
89
  * Imports a HMAC CryptoKey
@@ -95,9 +94,9 @@ export async function verify(algorithm, key, signature, data) {
95
94
  export async function importHmacKey(algorithm, key, extractable = false) {
96
95
  const binaryKey = isString(key) ? encodeUtf8(key) : key;
97
96
  if (isBinaryKey(binaryKey)) {
98
- return subtle.importKey('raw', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
97
+ return globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
99
98
  }
100
- return subtle.importKey('jwk', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
99
+ return globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
101
100
  }
102
101
  /**
103
102
  * Imports a CryptoKey for symmetric encryption
@@ -109,9 +108,9 @@ export async function importHmacKey(algorithm, key, extractable = false) {
109
108
  export async function importSymmetricKey(algorithm, length, key, extractable = false) {
110
109
  const binaryKey = isString(key) ? encodeUtf8(key) : key;
111
110
  if (isBinaryKey(binaryKey)) {
112
- return subtle.importKey('raw', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
111
+ return globalThis.crypto.subtle.importKey('raw', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
113
112
  }
114
- return subtle.importKey('jwk', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
113
+ return globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
115
114
  }
116
115
  /**
117
116
  * Imports an ECDSA CryptoKey
@@ -122,9 +121,9 @@ export async function importSymmetricKey(algorithm, length, key, extractable = f
122
121
  export async function importEcdsaKey(curve, key, extractable = false) {
123
122
  const binaryKey = isString(key) ? encodeUtf8(key) : key;
124
123
  if (isBinaryKey(binaryKey)) {
125
- return subtle.importKey('spki', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
124
+ return globalThis.crypto.subtle.importKey('spki', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
126
125
  }
127
- return subtle.importKey('jwk', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
126
+ return globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
128
127
  }
129
128
  /**
130
129
  * Import a pbkdf2 CryptoKey
@@ -142,7 +141,7 @@ export async function importPbkdf2Key(key, extractable = false) {
142
141
  * @param usages whether to generate a key for signing, verifiying or both. Defaults to both
143
142
  */
144
143
  export async function generateEcdsaKey(curve, extractable = false, usages = ['sign', 'verify']) {
145
- return subtle.generateKey({ name: 'ECDSA', namedCurve: curve }, extractable, usages);
144
+ return globalThis.crypto.subtle.generateKey({ name: 'ECDSA', namedCurve: curve }, extractable, usages);
146
145
  }
147
146
  /**
148
147
  * Generates a pbkdf2 CryptoKey
@@ -35,12 +35,12 @@ export declare const assertNull: AssertFunction<null>;
35
35
  export declare const assertNotNull: AssertNotFunction<null>;
36
36
  export declare const assertNullPass: AssertPassFunction<null>;
37
37
  export declare const assertNotNullPass: AssertNotPassFunction<null>;
38
- export declare const isNullOrUndefined: IsFunction<null | undefined>;
39
- export declare const isNotNullOrUndefined: IsNotFunction<null | undefined>;
40
- export declare const assertNullOrUndefined: AssertFunction<null | undefined>;
41
- export declare const assertNotNullOrUndefined: AssertNotFunction<null | undefined>;
42
- export declare const assertNullOrUndefinedPass: AssertPassFunction<null | undefined>;
43
- export declare const assertNotNullOrUndefinedPass: AssertNotPassFunction<null | undefined>;
38
+ export declare const isNullOrUndefined: (value: any) => value is null | undefined;
39
+ export declare const isNotNullOrUndefined: IsNotFunction<null | undefined | void>;
40
+ export declare const assertNullOrUndefined: (value: any, message?: AssertionMessage) => asserts value is null | undefined;
41
+ export declare const assertNotNullOrUndefined: AssertNotFunction<null | undefined | void>;
42
+ export declare const assertNullOrUndefinedPass: (value: any, message?: AssertionMessage) => null | undefined;
43
+ export declare const assertNotNullOrUndefinedPass: AssertNotPassFunction<null | undefined | void>;
44
44
  export declare const isNumber: IsFunction<number>;
45
45
  export declare const isNotNumber: IsNotFunction<number>;
46
46
  export declare const assertNumber: AssertFunction<number>;
@@ -1,4 +1,7 @@
1
- /* eslint-disable max-lines, @typescript-eslint/ban-types, @typescript-eslint/no-invalid-void-type, @typescript-eslint/restrict-template-expressions, max-statements-per-line, no-eq-null */
1
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
+ /* eslint-disable @typescript-eslint/ban-types */
3
+ /* eslint-disable @typescript-eslint/no-invalid-void-type */
4
+ /* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */
2
5
  import { supportsBlob, supportsReadableStream } from '../supports.js';
3
6
  import { AssertionError } from '../errors/assertion.error.js';
4
7
  export function assert(condition, message = 'assertion failed') {
@@ -104,14 +107,14 @@ export const assertSymbol = symbolGuards.assertSymbol;
104
107
  export const assertNotSymbol = symbolGuards.assertNotSymbol;
105
108
  export const assertSymbolPass = symbolGuards.assertSymbolPass;
106
109
  export const assertNotSymbolPass = symbolGuards.assertNotSymbolPass;
107
- const literalObjectGuards = createGuards('literal object', (value) => (typeof value == 'object') && (value != null) && (Reflect.getPrototypeOf(value) == Object.prototype) && (Reflect.getPrototypeOf(value).constructor == Object));
110
+ const literalObjectGuards = createGuards('literal object', (value) => (typeof value == 'object') && (value !== null) && (Reflect.getPrototypeOf(value) == Object.prototype) && (Reflect.getPrototypeOf(value).constructor == Object));
108
111
  export const isLiteralObject = literalObjectGuards.isLiteralObject;
109
112
  export const isNotLiteralObject = literalObjectGuards.isNotLiteralObject;
110
113
  export const assertLiteralObject = literalObjectGuards.assertLiteralObject;
111
114
  export const assertNotLiteralObject = literalObjectGuards.assertNotLiteralObject;
112
115
  export const assertLiteralObjectPass = literalObjectGuards.assertLiteralObjectPass;
113
116
  export const assertNotLiteralObjectPass = literalObjectGuards.assertNotLiteralObjectPass;
114
- const objectGuards = createGuards('object', (value) => (typeof value == 'object') && (value != null));
117
+ const objectGuards = createGuards('object', (value) => (typeof value == 'object') && (value !== null));
115
118
  export const isObject = objectGuards.isObject;
116
119
  export const isNotObject = objectGuards.isNotObject;
117
120
  export const assertObject = objectGuards.assertObject;
@@ -313,7 +316,7 @@ export const assertPromise = promiseGuards.assertPromise;
313
316
  export const assertNotPromise = promiseGuards.assertNotPromise;
314
317
  export const assertPromisePass = promiseGuards.assertPromisePass;
315
318
  export const assertNotPromisePass = promiseGuards.assertNotPromisePass;
316
- const promiseLikeGuards = createGuards('PromiseLike', (value) => isPromise(value) || ((((typeof value == 'object') && (value != null)) || isFunction(value)) && ((typeof value.then) == 'function')));
319
+ const promiseLikeGuards = createGuards('PromiseLike', (value) => isPromise(value) || ((((typeof value == 'object') && (value !== null)) || isFunction(value)) && ((typeof value.then) == 'function')));
317
320
  export const isPromiseLike = promiseLikeGuards.isPromiseLike;
318
321
  export const isNotPromiseLike = promiseLikeGuards.isNotPromiseLike;
319
322
  export const assertPromiseLike = promiseLikeGuards.assertPromiseLike;
@@ -4,5 +4,5 @@ export type ValueOrProvider<T> = T extends (() => any) ? never : (T | Provider<T
4
4
  export type ValueOrAsyncProvider<T> = T extends (() => any) ? never : (T | Provider<T> | AsyncProvider<T>);
5
5
  export type ResolvedValueOrProvider<T extends ValueOrAsyncProvider<any>> = T extends ValueOrAsyncProvider<infer U> ? U : never;
6
6
  export declare function resolveValueOrProvider<T>(valueOrProvider: ValueOrProvider<T>): T;
7
- export declare function resolveAsyncValueOrProvider<T>(valueOrProvider: ValueOrAsyncProvider<T>): Promise<T>;
8
- export declare function cacheAsyncValueOrProvider<T>(provider: ValueOrAsyncProvider<T>): () => (T | Promise<T>);
7
+ export declare function resolveValueOrAsyncProvider<T>(valueOrProvider: ValueOrAsyncProvider<T>): Promise<T>;
8
+ export declare function cacheValueOrAsyncProvider<T>(provider: ValueOrAsyncProvider<T>): () => (T | Promise<T>);
@@ -5,15 +5,15 @@ export function resolveValueOrProvider(valueOrProvider) {
5
5
  }
6
6
  return valueOrProvider;
7
7
  }
8
- export async function resolveAsyncValueOrProvider(valueOrProvider) {
8
+ export async function resolveValueOrAsyncProvider(valueOrProvider) {
9
9
  if (isFunction(valueOrProvider)) {
10
10
  return valueOrProvider();
11
11
  }
12
12
  return valueOrProvider;
13
13
  }
14
- export function cacheAsyncValueOrProvider(provider) {
14
+ export function cacheValueOrAsyncProvider(provider) {
15
15
  let getValue = async () => {
16
- const valuePromise = resolveAsyncValueOrProvider(provider);
16
+ const valuePromise = resolveValueOrAsyncProvider(provider);
17
17
  getValue = async () => valuePromise;
18
18
  void valuePromise.then((resolvedValue) => (getValue = () => resolvedValue));
19
19
  return valuePromise;