@tstdl/base 0.92.132 → 0.92.134
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/api-request-token.provider.d.ts +3 -0
- package/api/server/api-request-token.provider.js +9 -0
- package/api/server/module.js +1 -1
- package/database/mongo/module.js +6 -6
- package/document-management/api/document-management.api.d.ts +20 -4
- package/document-management/api/document-management.api.js +9 -3
- package/document-management/server/api/document-management.api.d.ts +1 -0
- package/document-management/server/api/document-management.api.js +9 -2
- package/document-management/server/module.d.ts +1 -0
- package/document-management/server/module.js +1 -0
- package/document-management/server/services/document-file.service.d.ts +16 -0
- package/document-management/server/services/document-file.service.js +54 -24
- package/document-management/server/services/document-management-ancillary.service.d.ts +2 -2
- package/document-management/server/services/document.service.d.ts +5 -1
- package/document-management/server/services/document.service.js +12 -9
- package/document-management/service-models/document.service-model.d.ts +1 -0
- package/document-management/service-models/document.service-model.js +1 -0
- package/examples/document-management/main.d.ts +1 -1
- package/examples/document-management/main.js +17 -8
- package/http/client/adapters/undici.adapter.js +3 -3
- package/http/client/http-client.js +29 -30
- package/http/http-body.js +4 -4
- package/http/http.error.d.ts +5 -1
- package/http/http.error.js +6 -6
- package/http/utils.js +4 -4
- package/injector/decorators.d.ts +1 -1
- package/injector/injector.d.ts +1 -1
- package/injector/interfaces.d.ts +1 -1
- package/injector/provider.d.ts +4 -4
- package/object-storage/object-storage.d.ts +37 -2
- package/object-storage/s3/s3.object-storage-provider.js +1 -1
- package/object-storage/s3/s3.object-storage.d.ts +6 -3
- package/object-storage/s3/s3.object-storage.js +86 -14
- package/object-storage/s3/s3.object.js +2 -3
- package/package.json +1 -1
- package/search-index/elastic/module.js +5 -5
- package/utils/cryptography.js +18 -18
- package/utils/object/object.d.ts +3 -2
- package/utils/object/object.js +5 -2
- package/utils/stream/size-limited-stream.js +1 -1
- package/utils/type-guards.d.ts +7 -1
- package/utils/type-guards.js +13 -1
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ import { Client } from '@elastic/elasticsearch';
|
|
|
8
8
|
import { ElasticSearchIndexConfig } from './config.js';
|
|
9
9
|
export const elasticsearchModuleConfig = {
|
|
10
10
|
defaultOptions: { node: 'http://localhost:9200' },
|
|
11
|
-
logPrefix: 'ELASTIC'
|
|
11
|
+
logPrefix: 'ELASTIC',
|
|
12
12
|
};
|
|
13
13
|
export const ELASTIC_SEARCH_INDEX_CONFIG = injectionToken('ElasticSearchIndexConfig');
|
|
14
14
|
export function configureElasticsearch(config = {}) {
|
|
@@ -20,19 +20,19 @@ Injector.registerSingleton(Client, {
|
|
|
20
20
|
assertDefined(argument, 'missing elasticsearch client options');
|
|
21
21
|
context.data.logger = inject(Logger, elasticsearchModuleConfig.logPrefix);
|
|
22
22
|
const client = new Client(argument);
|
|
23
|
-
context.addDisposeHandler(async () => client.close().then(() => context.data.logger.info('closed connection')));
|
|
23
|
+
context.addDisposeHandler(async () => await client.close().then(() => context.data.logger.info('closed connection')));
|
|
24
24
|
return client;
|
|
25
25
|
},
|
|
26
26
|
async afterResolve(client, options, { cancellationSignal, data: { logger } }) {
|
|
27
27
|
const url = getUrl(options.node ?? options.nodes);
|
|
28
|
-
await connect(`elasticsearch (${url})`, async () => client.ping().then((alive) => assert(alive, 'failed to connect')), logger, cancellationSignal);
|
|
28
|
+
await connect(`elasticsearch (${url})`, async () => await client.ping().then((alive) => assert(alive, 'failed to connect')), logger, cancellationSignal);
|
|
29
29
|
},
|
|
30
30
|
defaultArgumentProvider() {
|
|
31
31
|
return elasticsearchModuleConfig.defaultOptions;
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
33
|
});
|
|
34
34
|
Injector.registerSingleton(ELASTIC_SEARCH_INDEX_CONFIG, {
|
|
35
|
-
useFactory: (argument, context) => context.resolve(ElasticSearchIndexConfig, argument)
|
|
35
|
+
useFactory: (argument, context) => context.resolve(ElasticSearchIndexConfig, argument),
|
|
36
36
|
});
|
|
37
37
|
function getUrl(node) {
|
|
38
38
|
if (isString(node)) {
|
package/utils/cryptography.js
CHANGED
|
@@ -14,11 +14,11 @@ export function encrypt(algorithm, key, data) {
|
|
|
14
14
|
const bytes = isString(data) ? encodeUtf8(data) : data;
|
|
15
15
|
const encryptedBuffer = globalThis.crypto.subtle.encrypt(algorithm, key, bytes);
|
|
16
16
|
return {
|
|
17
|
-
toBuffer: async () => encryptedBuffer,
|
|
17
|
+
toBuffer: async () => await encryptedBuffer,
|
|
18
18
|
toHex: async () => encodeHex(await encryptedBuffer),
|
|
19
19
|
toBase64: async () => encodeBase64(await encryptedBuffer),
|
|
20
20
|
toBase64Url: async () => encodeBase64Url(await encryptedBuffer),
|
|
21
|
-
toZBase32: async () => zBase32Encode(await encryptedBuffer)
|
|
21
|
+
toZBase32: async () => zBase32Encode(await encryptedBuffer),
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -30,12 +30,12 @@ export function encrypt(algorithm, key, data) {
|
|
|
30
30
|
export function decrypt(algorithm, key, bytes) {
|
|
31
31
|
const decryptedBuffer = globalThis.crypto.subtle.decrypt(algorithm, key, bytes);
|
|
32
32
|
return {
|
|
33
|
-
toBuffer: async () => decryptedBuffer,
|
|
33
|
+
toBuffer: async () => await decryptedBuffer,
|
|
34
34
|
toHex: async () => encodeHex(await decryptedBuffer),
|
|
35
35
|
toBase64: async () => encodeBase64(await decryptedBuffer),
|
|
36
36
|
toBase64Url: async () => encodeBase64Url(await decryptedBuffer),
|
|
37
37
|
toZBase32: async () => zBase32Encode(await decryptedBuffer),
|
|
38
|
-
toUtf8: async () => decodeText(await decryptedBuffer)
|
|
38
|
+
toUtf8: async () => decodeText(await decryptedBuffer),
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
@@ -47,11 +47,11 @@ export function digest(algorithm, data) {
|
|
|
47
47
|
const bytes = isString(data) ? encodeUtf8(data) : data;
|
|
48
48
|
const arrayBufferPromise = globalThis.crypto.subtle.digest(algorithm, bytes);
|
|
49
49
|
const result = {
|
|
50
|
-
toBuffer: async () => arrayBufferPromise,
|
|
50
|
+
toBuffer: async () => await arrayBufferPromise,
|
|
51
51
|
toHex: async () => encodeHex(await arrayBufferPromise),
|
|
52
52
|
toBase64: async () => encodeBase64(await arrayBufferPromise),
|
|
53
53
|
toBase64Url: async () => encodeBase64Url(await arrayBufferPromise),
|
|
54
|
-
toZBase32: async () => zBase32Encode(await arrayBufferPromise)
|
|
54
|
+
toZBase32: async () => zBase32Encode(await arrayBufferPromise),
|
|
55
55
|
};
|
|
56
56
|
return result;
|
|
57
57
|
}
|
|
@@ -65,11 +65,11 @@ export function sign(algorithm, key, data) {
|
|
|
65
65
|
const bytes = isString(data) ? encodeUtf8(data) : data;
|
|
66
66
|
const arrayBufferPromise = globalThis.crypto.subtle.sign(algorithm, key, bytes);
|
|
67
67
|
const result = {
|
|
68
|
-
toBuffer: async () => arrayBufferPromise,
|
|
68
|
+
toBuffer: async () => await arrayBufferPromise,
|
|
69
69
|
toHex: async () => encodeHex(await arrayBufferPromise),
|
|
70
70
|
toBase64: async () => encodeBase64(await arrayBufferPromise),
|
|
71
71
|
toBase64Url: async () => encodeBase64Url(await arrayBufferPromise),
|
|
72
|
-
toZBase32: async () => zBase32Encode(await arrayBufferPromise)
|
|
72
|
+
toZBase32: async () => zBase32Encode(await arrayBufferPromise),
|
|
73
73
|
};
|
|
74
74
|
return result;
|
|
75
75
|
}
|
|
@@ -83,7 +83,7 @@ export function sign(algorithm, key, data) {
|
|
|
83
83
|
export async function verify(algorithm, key, signature, data) {
|
|
84
84
|
const signatureBytes = isString(signature) ? encodeUtf8(signature) : signature;
|
|
85
85
|
const dataBytes = isString(data) ? encodeUtf8(data) : data;
|
|
86
|
-
return globalThis.crypto.subtle.verify(algorithm, key, signatureBytes, dataBytes);
|
|
86
|
+
return await globalThis.crypto.subtle.verify(algorithm, key, signatureBytes, dataBytes);
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Imports a HMAC CryptoKey
|
|
@@ -94,9 +94,9 @@ export async function verify(algorithm, key, signature, data) {
|
|
|
94
94
|
export async function importHmacKey(algorithm, key, extractable = false) {
|
|
95
95
|
const binaryKey = isString(key) ? encodeUtf8(key) : key;
|
|
96
96
|
if (isBinaryKey(binaryKey)) {
|
|
97
|
-
return globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
|
|
97
|
+
return await globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
|
|
98
98
|
}
|
|
99
|
-
return globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
|
|
99
|
+
return await globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'HMAC', hash: algorithm }, extractable, ['sign', 'verify']);
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Imports a CryptoKey for symmetric encryption
|
|
@@ -108,9 +108,9 @@ export async function importHmacKey(algorithm, key, extractable = false) {
|
|
|
108
108
|
export async function importSymmetricKey(algorithm, length, key, extractable = false) {
|
|
109
109
|
const binaryKey = isString(key) ? encodeUtf8(key) : key;
|
|
110
110
|
if (isBinaryKey(binaryKey)) {
|
|
111
|
-
return globalThis.crypto.subtle.importKey('raw', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
|
|
111
|
+
return await globalThis.crypto.subtle.importKey('raw', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
|
|
112
112
|
}
|
|
113
|
-
return globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
|
|
113
|
+
return await globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: algorithm, length }, extractable, ['encrypt', 'decrypt']);
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
116
|
* Imports an ECDSA CryptoKey
|
|
@@ -121,9 +121,9 @@ export async function importSymmetricKey(algorithm, length, key, extractable = f
|
|
|
121
121
|
export async function importEcdsaKey(curve, key, extractable = false) {
|
|
122
122
|
const binaryKey = isString(key) ? encodeUtf8(key) : key;
|
|
123
123
|
if (isBinaryKey(binaryKey)) {
|
|
124
|
-
return globalThis.crypto.subtle.importKey('spki', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
|
|
124
|
+
return await globalThis.crypto.subtle.importKey('spki', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
|
|
125
125
|
}
|
|
126
|
-
return globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
|
|
126
|
+
return await globalThis.crypto.subtle.importKey('jwk', binaryKey, { name: 'ECDSA', namedCurve: curve }, extractable, ['verify']);
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
129
|
* Import a pbkdf2 CryptoKey
|
|
@@ -132,7 +132,7 @@ export async function importEcdsaKey(curve, key, extractable = false) {
|
|
|
132
132
|
*/
|
|
133
133
|
export async function importPbkdf2Key(key, extractable = false) {
|
|
134
134
|
const binaryKey = isString(key) ? encodeUtf8(key) : key;
|
|
135
|
-
return globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'PBKDF2' }, extractable, ['deriveKey', 'deriveBits']);
|
|
135
|
+
return await globalThis.crypto.subtle.importKey('raw', binaryKey, { name: 'PBKDF2' }, extractable, ['deriveKey', 'deriveBits']);
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* Generates a new ECDSA CryptoKeyPair
|
|
@@ -141,7 +141,7 @@ export async function importPbkdf2Key(key, extractable = false) {
|
|
|
141
141
|
* @param usages whether to generate a key for signing, verifiying or both. Defaults to both
|
|
142
142
|
*/
|
|
143
143
|
export async function generateEcdsaKey(curve, extractable = false, usages = ['sign', 'verify']) {
|
|
144
|
-
return globalThis.crypto.subtle.generateKey({ name: 'ECDSA', namedCurve: curve }, extractable, usages);
|
|
144
|
+
return await globalThis.crypto.subtle.generateKey({ name: 'ECDSA', namedCurve: curve }, extractable, usages);
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
147
|
* Generates a pbkdf2 CryptoKey
|
|
@@ -149,7 +149,7 @@ export async function generateEcdsaKey(curve, extractable = false, usages = ['si
|
|
|
149
149
|
*/
|
|
150
150
|
export async function generatePbkdf2Key(extractable = false) {
|
|
151
151
|
const key = getRandomBytes(16);
|
|
152
|
-
return importPbkdf2Key(key, extractable);
|
|
152
|
+
return await importPbkdf2Key(key, extractable);
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
155
|
* Derive byte array from key
|
package/utils/object/object.d.ts
CHANGED
|
@@ -13,9 +13,10 @@ export declare function objectKeys<T extends ObjectLiteral>(object: T): (keyof T
|
|
|
13
13
|
export declare function objectValues<T extends ObjectLiteral>(object: T): (T[keyof T])[];
|
|
14
14
|
export declare function fromEntries<A>(entries: A): FromEntries<A>;
|
|
15
15
|
export declare function fromEntries<K extends PropertyKey, T>(entries: Iterable<readonly [K, T]>): Record<K, T>;
|
|
16
|
-
export declare function mapObject<T extends ObjectLiteral, K extends
|
|
17
|
-
export declare function mapObjectAsync<T extends ObjectLiteral, K extends
|
|
16
|
+
export declare function mapObject<T extends ObjectLiteral, K extends PropertyKey, V>(object: T, mapper: (value: T[keyof T], key: keyof T) => [key: K, value: V]): Record<K, V>;
|
|
17
|
+
export declare function mapObjectAsync<T extends ObjectLiteral, K extends PropertyKey, V>(object: T, mapper: (value: T[keyof T], key: keyof T) => Promise<[key: K, value: V]>): Promise<Record<K, V>>;
|
|
18
18
|
export declare function mapObjectValues<T extends ObjectLiteral, V>(object: T, mapper: (value: T[keyof T], key: keyof T) => V): Record<keyof T, V>;
|
|
19
|
+
export declare function mapObjectKeys<T extends ObjectLiteral, K extends PropertyKey>(object: T, mapper: (key: keyof T, value: T[keyof T]) => K): Record<K, T[keyof T]>;
|
|
19
20
|
export declare function mapObjectValuesAsync<T extends ObjectLiteral, V>(object: T, mapper: (value: T[keyof T], key: keyof T) => Promise<V>): Promise<Record<keyof T, V>>;
|
|
20
21
|
export declare function filterObject<T extends ObjectLiteral, U extends T[keyof T]>(object: T, predicate: (value: T[keyof T], key: keyof T) => value is U): PickBy<T, U>;
|
|
21
22
|
export declare function filterObject<T extends ObjectLiteral>(object: T, predicate: (value: T[keyof T], key: keyof T) => boolean): Partial<T>;
|
package/utils/object/object.js
CHANGED
|
@@ -31,14 +31,17 @@ export function mapObject(object, mapper) {
|
|
|
31
31
|
}
|
|
32
32
|
export async function mapObjectAsync(object, mapper) {
|
|
33
33
|
const entries = objectKeys(object);
|
|
34
|
-
const mappedEntries = await toArrayAsync(mapAsync(entries, async (key) => mapper(object[key], key)));
|
|
34
|
+
const mappedEntries = await toArrayAsync(mapAsync(entries, async (key) => await mapper(object[key], key)));
|
|
35
35
|
return Object.fromEntries(mappedEntries);
|
|
36
36
|
}
|
|
37
37
|
export function mapObjectValues(object, mapper) {
|
|
38
38
|
return mapObject(object, (value, key) => [key, mapper(value, key)]);
|
|
39
39
|
}
|
|
40
|
+
export function mapObjectKeys(object, mapper) {
|
|
41
|
+
return mapObject(object, (value, key) => [mapper(key, value), value]);
|
|
42
|
+
}
|
|
40
43
|
export async function mapObjectValuesAsync(object, mapper) {
|
|
41
|
-
return mapObjectAsync(object, async (value, key) => [key, await mapper(value, key)]);
|
|
44
|
+
return await mapObjectAsync(object, async (value, key) => [key, await mapper(value, key)]);
|
|
42
45
|
}
|
|
43
46
|
export function filterObject(object, predicate) {
|
|
44
47
|
const mappedEntries = objectEntries(object).filter(([key, value]) => predicate(value, key));
|
package/utils/type-guards.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AbstractConstructor, BinaryData, JsonPrimitive, PascalCase, Primitive, TypedArray } from '../types.js';
|
|
1
|
+
import type { AbstractConstructor, BinaryData, JsonPrimitive, PascalCase, Primitive, Type, TypedArray } from '../types.js';
|
|
2
2
|
export type AssertionMessage = string | (() => string);
|
|
3
3
|
export type IsFunction<T> = <U extends T = T>(value: any) => value is U;
|
|
4
4
|
export type IsNotFunction<T> = <V>(value: V) => value is Exclude<V, T>;
|
|
@@ -257,3 +257,9 @@ export declare const assertReadableStream: <T = any>(value: any, message?: Asser
|
|
|
257
257
|
export declare const assertNotReadableStream: AssertNotFunction<ReadableStream>;
|
|
258
258
|
export declare const assertReadableStreamPass: <T = any>(value: any, message?: AssertionMessage) => ReadableStream<T>;
|
|
259
259
|
export declare const assertNotReadableStreamPass: AssertNotPassFunction<ReadableStream>;
|
|
260
|
+
export declare const isInstanceOf: <T>(value: any, type: Type<T>) => value is T;
|
|
261
|
+
export declare const isNotInstanceOf: <V, T>(value: V, type: Type<T>) => value is Exclude<V, T>;
|
|
262
|
+
export declare const assertInstanceOf: <T>(value: any, type: Type<T>, message?: AssertionMessage) => asserts value is T;
|
|
263
|
+
export declare const assertNotInstanceOf: <V, T>(value: V, type: Type<T>, message?: AssertionMessage) => asserts value is Exclude<V, T>;
|
|
264
|
+
export declare const assertInstanceOfPass: <T>(value: any, type: Type<T>, message?: AssertionMessage) => T;
|
|
265
|
+
export declare const assertNotInstanceOfPass: <V, T>(value: V, type: Type<T>, message?: AssertionMessage) => Exclude<V, T>;
|
package/utils/type-guards.js
CHANGED
|
@@ -36,7 +36,7 @@ export function createGuards(name, testFn) {
|
|
|
36
36
|
[`assertNot${normalizedName}Pass`](value, message = defaultNotMessage) {
|
|
37
37
|
assertNot(testFn(value), message);
|
|
38
38
|
return value;
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
export function createInstanceGuards(name, type) {
|
|
@@ -335,3 +335,15 @@ export const assertReadableStream = readableStreamGuards.assertReadableStream;
|
|
|
335
335
|
export const assertNotReadableStream = readableStreamGuards.assertNotReadableStream;
|
|
336
336
|
export const assertReadableStreamPass = readableStreamGuards.assertReadableStreamPass;
|
|
337
337
|
export const assertNotReadableStreamPass = readableStreamGuards.assertNotReadableStreamPass;
|
|
338
|
+
export const isInstanceOf = (value, type) => value instanceof type;
|
|
339
|
+
export const isNotInstanceOf = (value, type) => !isInstanceOf(value, type);
|
|
340
|
+
export const assertInstanceOf = (value, type, message) => assert(isInstanceOf(value, type), message);
|
|
341
|
+
export const assertNotInstanceOf = (value, type, message) => assertNot(isInstanceOf(value, type), message);
|
|
342
|
+
export const assertInstanceOfPass = (value, type, message) => {
|
|
343
|
+
assert(isInstanceOf(value, type), message);
|
|
344
|
+
return value;
|
|
345
|
+
};
|
|
346
|
+
export const assertNotInstanceOfPass = (value, type, message) => {
|
|
347
|
+
assertNot(isInstanceOf(value, type), message);
|
|
348
|
+
return value;
|
|
349
|
+
};
|