@tstdl/base 0.90.62 → 0.90.64

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,4 +1,4 @@
1
- import type { InjectableOptionsWithoutLifecycle } from '../../injector/decorators.js';
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,3 +1,4 @@
1
+ /* eslint-disable max-classes-per-file */
1
2
  import { Singleton } from '../../injector/decorators.js';
2
3
  import { objectEntries } from '../../utils/object/object.js';
3
4
  import { isFunction } from '../../utils/type-guards.js';
@@ -1,74 +1,75 @@
1
- import type { Resolvable } from '../injector/interfaces.js';
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
- /** object storage module */
8
+ /** Object storage module */
10
9
  readonly module: string;
11
10
  readonly [resolveArgumentType]: ObjectStorageArgument;
12
11
  constructor(module: string);
13
12
  /**
14
- * checks if an object exists
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
- * uploads an object
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, options?: UploadObjectOptions): Promise<void>;
22
+ abstract uploadObject(key: string, content: Uint8Array | ReadableStream<Uint8Array>, options?: UploadObjectOptions): Promise<void>;
24
23
  /**
25
- * uploads an object stream
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
- * get an url which can be used to upload the object without further authorization
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
- * get all objects
37
+ * Get all objects
38
38
  */
39
39
  abstract getObjects(): Promise<ObjectStorageObject[]>;
40
40
  /**
41
- * get all objects
41
+ * Get all objects
42
42
  */
43
43
  abstract getObjectsCursor(): AsyncIterable<ObjectStorageObject>;
44
44
  /**
45
- * get object
45
+ * Get object
46
46
  * @param key object key
47
47
  */
48
48
  abstract getObject(key: string): Promise<ObjectStorageObject>;
49
49
  /**
50
- * get object resource uri
50
+ * Get object resource uri
51
51
  * @param key object key
52
52
  */
53
53
  abstract getResourceUri(key: string): Promise<string>;
54
54
  /**
55
- * get stream of object content
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
- * get an url which can be used to download the object without further authorization
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
- * deletes an object
67
+ * Deletes an object
67
68
  * @param key object key
68
69
  */
69
70
  abstract deleteObject(key: string): Promise<void>;
70
71
  /**
71
- * deletes objects
72
+ * Deletes objects
72
73
  * @param keys object key
73
74
  */
74
75
  abstract deleteObjects(keys: string[]): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import { resolveArgumentType } from '../injector/interfaces.js';
2
2
  export class ObjectStorage {
3
- /** object storage module */
3
+ /** Object storage module */
4
4
  module;
5
5
  constructor(module) {
6
6
  this.module = module;
@@ -1,7 +1,5 @@
1
- import type { BucketItemStat } from 'minio';
2
- import { Client } from 'minio';
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, options?: UploadObjectOptions): Promise<void>;
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
- await this.client.putObject(this.bucket, bucketKey, Buffer.from(content), options?.metadata);
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
- const bucketKey = this.getBucketKey(key);
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, {}, date);
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", [Client, String, String, String])
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.62",
3
+ "version": "0.90.64",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -105,7 +105,7 @@
105
105
  "./utils/string": "./utils/object/index.js"
106
106
  },
107
107
  "dependencies": {
108
- "core-js": "3.36",
108
+ "core-js": "3.37",
109
109
  "luxon": "^3.4",
110
110
  "reflect-metadata": "^0.2",
111
111
  "rxjs": "^7.8",
@@ -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.5"
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.42",
150
+ "playwright": "^1.43",
151
151
  "preact": "^10.20",
152
152
  "preact-render-to-string": "^6.4",
153
- "undici": "^6.11",
153
+ "undici": "^6.13",
154
154
  "urlpattern-polyfill": "^10.0"
155
155
  },
156
156
  "peerDependenciesMeta": {