@tstdl/base 0.90.62 → 0.90.63
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-controller.d.ts +1 -1
- package/api/server/api-controller.js +1 -0
- package/object-storage/object-storage.d.ts +18 -17
- package/object-storage/object-storage.js +1 -1
- package/object-storage/s3/s3.object-storage.d.ts +4 -6
- package/object-storage/s3/s3.object-storage.js +16 -13
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type InjectableOptionsWithoutLifecycle } from '../../injector/decorators.js';
|
|
2
2
|
import type { Constructor, Type } from '../../types.js';
|
|
3
3
|
import type { ApiController, ApiDefinition } from '../types.js';
|
|
4
4
|
type ApiDefinitionProvider = () => ApiDefinition;
|
|
@@ -1,74 +1,75 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { resolveArgumentType } from '../injector/interfaces.js';
|
|
1
|
+
import { resolveArgumentType, type Resolvable } from '../injector/interfaces.js';
|
|
3
2
|
import type { ObjectMetadata, ObjectStorageObject } from './object.js';
|
|
4
3
|
export type UploadObjectOptions = {
|
|
5
4
|
metadata?: ObjectMetadata;
|
|
6
5
|
};
|
|
7
6
|
export type ObjectStorageArgument = string;
|
|
8
7
|
export declare abstract class ObjectStorage implements Resolvable<ObjectStorageArgument> {
|
|
9
|
-
/**
|
|
8
|
+
/** Object storage module */
|
|
10
9
|
readonly module: string;
|
|
11
10
|
readonly [resolveArgumentType]: ObjectStorageArgument;
|
|
12
11
|
constructor(module: string);
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* Checks if an object exists
|
|
15
14
|
* @param key object key
|
|
16
15
|
*/
|
|
17
16
|
abstract exists(key: string): Promise<boolean>;
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
18
|
+
* Uploads an object
|
|
20
19
|
* @param key object key
|
|
21
20
|
* @param content content of object
|
|
22
21
|
*/
|
|
23
|
-
abstract uploadObject(key: string, content: Uint8Array
|
|
22
|
+
abstract uploadObject(key: string, content: Uint8Array | ReadableStream<Uint8Array>, options?: UploadObjectOptions): Promise<void>;
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
24
|
+
* Uploads an object stream
|
|
26
25
|
* @param key object key
|
|
27
26
|
* @param stream stream of object
|
|
27
|
+
* @deprecated use {@link uploadObject} instead
|
|
28
28
|
*/
|
|
29
29
|
abstract uploadObjectStream(key: string, stream: ReadableStream<Uint8Array>, options?: UploadObjectOptions): Promise<void>;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Get an url which can be used to upload the object without further authorization
|
|
32
32
|
* @param key object key
|
|
33
33
|
* @param expirationTimestamp timestamp when the url expires and can no longer be used
|
|
34
34
|
*/
|
|
35
35
|
abstract getUploadUrl(key: string, expirationTimestamp: number): Promise<string>;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Get all objects
|
|
38
38
|
*/
|
|
39
39
|
abstract getObjects(): Promise<ObjectStorageObject[]>;
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
41
|
+
* Get all objects
|
|
42
42
|
*/
|
|
43
43
|
abstract getObjectsCursor(): AsyncIterable<ObjectStorageObject>;
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Get object
|
|
46
46
|
* @param key object key
|
|
47
47
|
*/
|
|
48
48
|
abstract getObject(key: string): Promise<ObjectStorageObject>;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Get object resource uri
|
|
51
51
|
* @param key object key
|
|
52
52
|
*/
|
|
53
53
|
abstract getResourceUri(key: string): Promise<string>;
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Get stream of object content
|
|
56
56
|
* @param key object key
|
|
57
57
|
*/
|
|
58
58
|
abstract getContentStream(key: string): ReadableStream<Uint8Array>;
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* Get an url which can be used to download the object without further authorization
|
|
61
61
|
* @param key object key
|
|
62
62
|
* @param expirationTimestamp timestamp when the url expires and can no longer be used
|
|
63
|
+
* @param responseHeaders headers used for download response
|
|
63
64
|
*/
|
|
64
|
-
abstract getDownloadUrl(key: string, expirationTimestamp: number): Promise<string>;
|
|
65
|
+
abstract getDownloadUrl(key: string, expirationTimestamp: number, responseHeaders?: Record<string, string>): Promise<string>;
|
|
65
66
|
/**
|
|
66
|
-
*
|
|
67
|
+
* Deletes an object
|
|
67
68
|
* @param key object key
|
|
68
69
|
*/
|
|
69
70
|
abstract deleteObject(key: string): Promise<void>;
|
|
70
71
|
/**
|
|
71
|
-
*
|
|
72
|
+
* Deletes objects
|
|
72
73
|
* @param keys object key
|
|
73
74
|
*/
|
|
74
75
|
abstract deleteObjects(keys: string[]): Promise<void>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { BucketItemStat } from 'minio';
|
|
2
|
-
import {
|
|
3
|
-
import type { UploadObjectOptions } from '../../object-storage/index.js';
|
|
4
|
-
import { ObjectStorage } from '../../object-storage/index.js';
|
|
1
|
+
import type { BucketItemStat, Client } from 'minio';
|
|
2
|
+
import { ObjectStorage, type UploadObjectOptions } from '../../object-storage/index.js';
|
|
5
3
|
import { S3Object } from './s3.object.js';
|
|
6
4
|
export declare class S3ObjectStorage extends ObjectStorage {
|
|
7
5
|
private readonly client;
|
|
@@ -13,7 +11,7 @@ export declare class S3ObjectStorage extends ObjectStorage {
|
|
|
13
11
|
}): Promise<void>;
|
|
14
12
|
exists(key: string): Promise<boolean>;
|
|
15
13
|
statObject(key: string): Promise<BucketItemStat>;
|
|
16
|
-
uploadObject(key: string, content: Uint8Array
|
|
14
|
+
uploadObject(key: string, content: Uint8Array | ReadableStream<Uint8Array>, options?: UploadObjectOptions): Promise<void>;
|
|
17
15
|
uploadObjectStream(key: string, stream: ReadableStream<Uint8Array>, options?: UploadObjectOptions): Promise<void>;
|
|
18
16
|
getContent(key: string): Promise<Uint8Array>;
|
|
19
17
|
getContentStream(key: string): ReadableStream<Uint8Array>;
|
|
@@ -21,7 +19,7 @@ export declare class S3ObjectStorage extends ObjectStorage {
|
|
|
21
19
|
getObjectsCursor(): AsyncIterable<S3Object>;
|
|
22
20
|
getObject(key: string): Promise<S3Object>;
|
|
23
21
|
getResourceUri(key: string): Promise<string>;
|
|
24
|
-
getDownloadUrl(key: string, expirationTimestamp: number): Promise<string>;
|
|
22
|
+
getDownloadUrl(key: string, expirationTimestamp: number, responseHeaders?: Record<string, string>): Promise<string>;
|
|
25
23
|
getUploadUrl(key: string, expirationTimestamp: number): Promise<string>;
|
|
26
24
|
deleteObject(key: string): Promise<void>;
|
|
27
25
|
deleteObjects(keys: string[]): Promise<void>;
|
|
@@ -8,7 +8,6 @@ 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
10
|
import { Readable } from 'node:stream';
|
|
11
|
-
import { Client } from 'minio';
|
|
12
11
|
import { Singleton } from '../../injector/decorators.js';
|
|
13
12
|
import { ObjectStorage } from '../../object-storage/index.js';
|
|
14
13
|
import { mapAsync } from '../../utils/async-iterable-helpers/map.js';
|
|
@@ -16,7 +15,7 @@ import { toArrayAsync } from '../../utils/async-iterable-helpers/to-array.js';
|
|
|
16
15
|
import { now } from '../../utils/date-time.js';
|
|
17
16
|
import { readableStreamFromPromise } from '../../utils/stream/index.js';
|
|
18
17
|
import { readBinaryStream } from '../../utils/stream/stream-reader.js';
|
|
19
|
-
import { assertStringPass, isObject } from '../../utils/type-guards.js';
|
|
18
|
+
import { assertStringPass, isObject, isUint8Array } from '../../utils/type-guards.js';
|
|
20
19
|
import { S3ObjectStorageProvider } from './s3.object-storage-provider.js';
|
|
21
20
|
import { S3Object } from './s3.object.js';
|
|
22
21
|
let S3ObjectStorage = class S3ObjectStorage extends ObjectStorage {
|
|
@@ -55,16 +54,20 @@ let S3ObjectStorage = class S3ObjectStorage extends ObjectStorage {
|
|
|
55
54
|
}
|
|
56
55
|
async uploadObject(key, content, options) {
|
|
57
56
|
const bucketKey = this.getBucketKey(key);
|
|
58
|
-
|
|
57
|
+
if (isUint8Array(content)) {
|
|
58
|
+
await this.client.putObject(this.bucket, bucketKey, Buffer.from(content), options?.metadata);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const readable = Readable.fromWeb(content);
|
|
62
|
+
const errorPromise = new Promise((_, reject) => readable.on('error', reject));
|
|
63
|
+
await Promise.race([
|
|
64
|
+
this.client.putObject(this.bucket, bucketKey, readable, options?.metadata),
|
|
65
|
+
errorPromise
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
async uploadObjectStream(key, stream, options) {
|
|
61
|
-
|
|
62
|
-
const readable = Readable.fromWeb(stream);
|
|
63
|
-
const errorPromise = new Promise((_, reject) => readable.on('error', reject));
|
|
64
|
-
await Promise.race([
|
|
65
|
-
this.client.putObject(this.bucket, bucketKey, readable, options?.metadata),
|
|
66
|
-
errorPromise
|
|
67
|
-
]);
|
|
70
|
+
return this.uploadObject(key, stream, options);
|
|
68
71
|
}
|
|
69
72
|
async getContent(key) {
|
|
70
73
|
const bucketKey = this.getBucketKey(key);
|
|
@@ -93,10 +96,10 @@ let S3ObjectStorage = class S3ObjectStorage extends ObjectStorage {
|
|
|
93
96
|
async getResourceUri(key) {
|
|
94
97
|
return this.getResourceUriSync(key);
|
|
95
98
|
}
|
|
96
|
-
async getDownloadUrl(key, expirationTimestamp) {
|
|
99
|
+
async getDownloadUrl(key, expirationTimestamp, responseHeaders) {
|
|
97
100
|
const bucketKey = this.getBucketKey(key);
|
|
98
101
|
const { date, expiration } = getDateAndExpiration(expirationTimestamp);
|
|
99
|
-
return this.client.presignedGetObject(this.bucket, bucketKey, expiration,
|
|
102
|
+
return this.client.presignedGetObject(this.bucket, bucketKey, expiration, responseHeaders, date);
|
|
100
103
|
}
|
|
101
104
|
async getUploadUrl(key, expirationTimestamp) {
|
|
102
105
|
const bucketKey = this.getBucketKey(key);
|
|
@@ -131,7 +134,7 @@ S3ObjectStorage = __decorate([
|
|
|
131
134
|
}
|
|
132
135
|
}
|
|
133
136
|
}),
|
|
134
|
-
__metadata("design:paramtypes", [
|
|
137
|
+
__metadata("design:paramtypes", [Function, String, String, String])
|
|
135
138
|
], S3ObjectStorage);
|
|
136
139
|
export { S3ObjectStorage };
|
|
137
140
|
function getDateAndExpiration(expirationTimestamp) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.90.
|
|
3
|
+
"version": "0.90.63",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"typedoc": "0.25",
|
|
131
131
|
"typedoc-plugin-missing-exports": "2.2",
|
|
132
132
|
"typescript": "5.4",
|
|
133
|
-
"typescript-eslint": "7.
|
|
133
|
+
"typescript-eslint": "7.7"
|
|
134
134
|
},
|
|
135
135
|
"peerDependencies": {
|
|
136
136
|
"@elastic/elasticsearch": "^8.13",
|
|
@@ -147,10 +147,10 @@
|
|
|
147
147
|
"mjml": "^4.15",
|
|
148
148
|
"mongodb": "^6.5",
|
|
149
149
|
"nodemailer": "^6.9",
|
|
150
|
-
"playwright": "^1.
|
|
150
|
+
"playwright": "^1.43",
|
|
151
151
|
"preact": "^10.20",
|
|
152
152
|
"preact-render-to-string": "^6.4",
|
|
153
|
-
"undici": "^6.
|
|
153
|
+
"undici": "^6.13",
|
|
154
154
|
"urlpattern-polyfill": "^10.0"
|
|
155
155
|
},
|
|
156
156
|
"peerDependenciesMeta": {
|