@tstdl/base 0.90.6 → 0.90.8

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.
@@ -68,7 +68,7 @@ export const germanTstdlErrorsLocalization = {
68
68
  },
69
69
  enums: [
70
70
  enumerationLocalization(HttpErrorReason, {
71
- [HttpErrorReason.Unknown]: 'Unbekannt',
71
+ [HttpErrorReason.Unknown]: 'Unerwarteter Fehler',
72
72
  [HttpErrorReason.Cancelled]: 'Anfrage abgebrochen',
73
73
  [HttpErrorReason.Network]: 'Netzwerkfehler',
74
74
  [HttpErrorReason.InvalidRequest]: 'Ungültige Anfrage',
@@ -145,7 +145,7 @@ export const englishTstdlErrorsLocalization = {
145
145
  },
146
146
  enums: [
147
147
  enumerationLocalization(HttpErrorReason, {
148
- [HttpErrorReason.Unknown]: 'Unknown',
148
+ [HttpErrorReason.Unknown]: 'Unexpected error',
149
149
  [HttpErrorReason.Cancelled]: 'Request cancelled',
150
150
  [HttpErrorReason.Network]: 'Network error',
151
151
  [HttpErrorReason.InvalidRequest]: 'Invalid request',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.90.6",
3
+ "version": "0.90.8",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -146,7 +146,7 @@
146
146
  "mjml": "^4.14",
147
147
  "mongodb": "^6.1",
148
148
  "nodemailer": "^6.9",
149
- "playwright": "^1.38",
149
+ "playwright": "^1.39",
150
150
  "preact": "^10.18",
151
151
  "preact-render-to-string": "^6.2",
152
152
  "undici": "^5.26",
@@ -11,13 +11,13 @@ export type PropertyNameProxyChild<T> = (T extends Record ? (PropertyNameProxy<T
11
11
  [cast]: <U extends T>() => PropertyNameProxyChild<U>;
12
12
  };
13
13
  export type PropertyNameOfExpressionObject<T> = {
14
- [P in keyof DeepNonNullable<T>]: PropertyNameOfExpressionObject<DeepNonNullable<T>[P]> & {
15
- [cast]: <U extends DeepNonNullable<T>[P]>() => PropertyNameOfExpressionObject<U>;
14
+ [P in keyof T]: PropertyNameOfExpressionObject<DeepNonNullable<T>[P]> & {
15
+ [cast]: <U extends T[P]>() => PropertyNameOfExpressionObject<DeepNonNullable<U>>;
16
16
  };
17
17
  };
18
18
  export type FlatPropertyNameOfExpressionObject<T> = {
19
- [P in keyof DeepFlatten<DeepNonNullable<T>>]: FlatPropertyNameOfExpressionObject<DeepFlatten<DeepNonNullable<T>>[P]> & {
20
- [cast]: <U extends DeepFlatten<DeepNonNullable<T>>[P]>() => FlatPropertyNameOfExpressionObject<U>;
19
+ [P in keyof DeepFlatten<T>]: FlatPropertyNameOfExpressionObject<DeepFlatten<DeepNonNullable<T>>[P]> & {
20
+ [cast]: <U extends DeepFlatten<T>[P]>() => FlatPropertyNameOfExpressionObject<DeepNonNullable<U>>;
21
21
  };
22
22
  };
23
23
  export declare function getPropertyName(name: string): PropertyName;
@@ -4,3 +4,4 @@ export * from './readable-stream-from-promise.js';
4
4
  export * from './size-limited-stream.js';
5
5
  export * from './stream-helper-types.js';
6
6
  export * from './stream-reader.js';
7
+ export * from './to-bytes-stream.js';
@@ -4,3 +4,4 @@ export * from './readable-stream-from-promise.js';
4
4
  export * from './size-limited-stream.js';
5
5
  export * from './stream-helper-types.js';
6
6
  export * from './stream-reader.js';
7
+ export * from './to-bytes-stream.js';
@@ -0,0 +1,4 @@
1
+ export type ToBytesStreamOptions = {
2
+ ignoreCancel?: boolean;
3
+ };
4
+ export declare function toBytesStream(stream: ReadableStream<ArrayBufferView>, options?: ToBytesStreamOptions): ReadableStream<Uint8Array>;
@@ -0,0 +1,78 @@
1
+ import { isNotNull, isNull } from '../type-guards.js';
2
+ export function toBytesStream(stream, options) {
3
+ try { // try to use byob mode from source
4
+ let byobReader;
5
+ return new ReadableStream({
6
+ type: 'bytes',
7
+ autoAllocateChunkSize: 10240,
8
+ start() {
9
+ byobReader = stream.getReader({ mode: 'byob' });
10
+ },
11
+ async pull(controller) {
12
+ const readResult = await byobReader.read(controller.byobRequest.view);
13
+ if (readResult.done) {
14
+ controller.close();
15
+ controller.byobRequest.respond(0);
16
+ return;
17
+ }
18
+ controller.byobRequest.respond(readResult.value.byteLength);
19
+ },
20
+ async cancel(reason) {
21
+ if (options?.ignoreCancel == true) {
22
+ byobReader.releaseLock();
23
+ }
24
+ else {
25
+ await byobReader.cancel(reason);
26
+ }
27
+ }
28
+ });
29
+ }
30
+ catch { /* ignore */ }
31
+ let reader;
32
+ let buffer = null;
33
+ return new ReadableStream({
34
+ type: 'bytes',
35
+ start() {
36
+ reader = stream.getReader();
37
+ },
38
+ async pull(controller) {
39
+ const isByobRequest = isNotNull(controller.byobRequest);
40
+ const bufferIsEmpty = isNull(buffer) || (buffer.byteLength == 0);
41
+ if (!isByobRequest && !bufferIsEmpty) {
42
+ // we stil have data left in buffer from previous pull which was byob
43
+ controller.enqueue(buffer);
44
+ buffer = null;
45
+ return;
46
+ }
47
+ if (bufferIsEmpty) {
48
+ const readResult = await reader.read();
49
+ if (readResult.done) {
50
+ controller.close();
51
+ controller.byobRequest?.respond(0);
52
+ return;
53
+ }
54
+ buffer = readResult.value; // eslint-disable-line require-atomic-updates
55
+ }
56
+ if (!isByobRequest) {
57
+ controller.enqueue(buffer);
58
+ buffer = null;
59
+ return;
60
+ }
61
+ const targetView = controller.byobRequest.view;
62
+ const targetArray = new Uint8Array(targetView.buffer, targetView.byteOffset, targetView.byteLength);
63
+ const setLength = Math.min(buffer.byteLength, targetArray.byteLength);
64
+ const sourceArray = new Uint8Array(buffer.buffer, buffer.byteOffset, setLength);
65
+ targetArray.set(sourceArray);
66
+ buffer = new Uint8Array(buffer.buffer, buffer.byteOffset + setLength);
67
+ controller.byobRequest.respond(setLength);
68
+ },
69
+ async cancel(reason) {
70
+ if (options?.ignoreCancel == true) {
71
+ reader.releaseLock();
72
+ }
73
+ else {
74
+ await reader.cancel(reason);
75
+ }
76
+ }
77
+ });
78
+ }