@tstdl/base 0.90.9 → 0.90.11
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/http/client/http-client.d.ts +2 -1
- package/http/client/http-client.js +2 -2
- package/http/utils.js +1 -0
- package/package.json +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/reactive-value-to-signal.d.ts +13 -0
- package/utils/reactive-value-to-signal.js +11 -0
- package/utils/stream/index.d.ts +1 -0
- package/utils/stream/index.js +1 -0
- package/utils/stream/slice.d.ts +2 -0
- package/utils/stream/slice.js +75 -0
- package/utils/stream/to-bytes-stream.js +2 -3
|
@@ -2,6 +2,7 @@ import { resolveArgumentType } from '../../injector/index.js';
|
|
|
2
2
|
import type { Resolvable } from '../../injector/interfaces.js';
|
|
3
3
|
import type { OneOrMany, UndefinableJson } from '../../types.js';
|
|
4
4
|
import type { HttpMethod, HttpValue } from '../types.js';
|
|
5
|
+
import type { ReadBodyOptions } from '../utils.js';
|
|
5
6
|
import { HttpClientOptions } from './http-client-options.js';
|
|
6
7
|
import type { HttpClientRequestOptions } from './http-client-request.js';
|
|
7
8
|
import { HttpClientRequest } from './http-client-request.js';
|
|
@@ -27,7 +28,7 @@ export declare class HttpClient implements Resolvable<HttpClientArgument> {
|
|
|
27
28
|
getBuffer(url: string, options?: HttpClientRequestOptions): Promise<Uint8Array>;
|
|
28
29
|
getStream(url: string, options?: HttpClientRequestOptions): ReadableStream<string> | ReadableStream<Uint8Array>;
|
|
29
30
|
getTextStream(url: string, options?: HttpClientRequestOptions): ReadableStream<string>;
|
|
30
|
-
getBinaryStream(url: string, options?: HttpClientRequestOptions): ReadableStream<Uint8Array>;
|
|
31
|
+
getBinaryStream(url: string, options?: HttpClientRequestOptions, readOptions?: ReadBodyOptions): ReadableStream<Uint8Array>;
|
|
31
32
|
post(url: string, options?: HttpClientRequestOptions): Promise<HttpClientResponse>;
|
|
32
33
|
postText(url: string, options?: HttpClientRequestOptions): Promise<string>;
|
|
33
34
|
postJson<T = UndefinableJson>(url: string, options?: HttpClientRequestOptions): Promise<T>;
|
|
@@ -79,10 +79,10 @@ let HttpClient = class HttpClient {
|
|
|
79
79
|
return response.body.readAsTextStream();
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
getBinaryStream(url, options) {
|
|
82
|
+
getBinaryStream(url, options, readOptions) {
|
|
83
83
|
return readableStreamFromPromise(async () => {
|
|
84
84
|
const response = await this.request('GET', url, { ...options });
|
|
85
|
-
return response.body.readAsBinaryStream();
|
|
85
|
+
return response.body.readAsBinaryStream(readOptions);
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
async post(url, options) {
|
package/http/utils.js
CHANGED
package/package.json
CHANGED
package/utils/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export * from './periodic-sampler.js';
|
|
|
39
39
|
export * from './provider-function-iterable.js';
|
|
40
40
|
export * from './proxy.js';
|
|
41
41
|
export * from './random.js';
|
|
42
|
+
export * from './reactive-value-to-signal.js';
|
|
42
43
|
export * from './reflection.js';
|
|
43
44
|
export * from './repl.js';
|
|
44
45
|
export * from './set.js';
|
package/utils/index.js
CHANGED
|
@@ -39,6 +39,7 @@ export * from './periodic-sampler.js';
|
|
|
39
39
|
export * from './provider-function-iterable.js';
|
|
40
40
|
export * from './proxy.js';
|
|
41
41
|
export * from './random.js';
|
|
42
|
+
export * from './reactive-value-to-signal.js';
|
|
42
43
|
export * from './reflection.js';
|
|
43
44
|
export * from './repl.js';
|
|
44
45
|
export * from './set.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Signal, ToSignalOptions } from '../signals/api.js';
|
|
2
|
+
import type { ReactiveValue } from '../types.js';
|
|
3
|
+
export type ReactiveValueToSignalOptions<T> = ToSignalOptions<T>;
|
|
4
|
+
export declare function reactiveValueToSignal<T>(source: ReactiveValue<T>, options?: ReactiveValueToSignalOptions<undefined> & {
|
|
5
|
+
requireSync?: false;
|
|
6
|
+
}): Signal<T | undefined>;
|
|
7
|
+
export declare function reactiveValueToSignal<T, I>(source: ReactiveValue<T>, options: ReactiveValueToSignalOptions<I> & {
|
|
8
|
+
initialValue: I;
|
|
9
|
+
requireSync?: false;
|
|
10
|
+
}): Signal<T | I>;
|
|
11
|
+
export declare function reactiveValueToSignal<T>(source: ReactiveValue<T>, options: ReactiveValueToSignalOptions<undefined> & {
|
|
12
|
+
requireSync: true;
|
|
13
|
+
}): Signal<T>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isObservable } from 'rxjs';
|
|
2
|
+
import { computed, isSignal, toSignal } from '../signals/api.js';
|
|
3
|
+
export function reactiveValueToSignal(source, options) {
|
|
4
|
+
if (isSignal(source)) {
|
|
5
|
+
return source;
|
|
6
|
+
}
|
|
7
|
+
if (isObservable(source)) {
|
|
8
|
+
return toSignal(source, options);
|
|
9
|
+
}
|
|
10
|
+
return computed(() => source);
|
|
11
|
+
}
|
package/utils/stream/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './finalize-stream.js';
|
|
|
2
2
|
export * from './readable-stream-adapter.js';
|
|
3
3
|
export * from './readable-stream-from-promise.js';
|
|
4
4
|
export * from './size-limited-stream.js';
|
|
5
|
+
export * from './slice.js';
|
|
5
6
|
export * from './stream-helper-types.js';
|
|
6
7
|
export * from './stream-reader.js';
|
|
7
8
|
export * from './to-bytes-stream.js';
|
package/utils/stream/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './finalize-stream.js';
|
|
|
2
2
|
export * from './readable-stream-adapter.js';
|
|
3
3
|
export * from './readable-stream-from-promise.js';
|
|
4
4
|
export * from './size-limited-stream.js';
|
|
5
|
+
export * from './slice.js';
|
|
5
6
|
export * from './stream-helper-types.js';
|
|
6
7
|
export * from './stream-reader.js';
|
|
7
8
|
export * from './to-bytes-stream.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function sliceStream(stream: ReadableStream<ArrayBufferView>, offset: number, length: number, type?: 'bytes'): ReadableStream<Uint8Array>;
|
|
2
|
+
export declare function sliceStream<T>(stream: ReadableStream<T>, offset: number, length: number, type: 'chunks'): ReadableStream<T>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { assert } from '../type-guards.js';
|
|
2
|
+
import { kibibyte, mebibyte } from '../units.js';
|
|
3
|
+
import { toBytesStream } from './to-bytes-stream.js';
|
|
4
|
+
export function sliceStream(stream, offset, length, type = 'bytes') {
|
|
5
|
+
assert(length > 0, 'Length must be positive');
|
|
6
|
+
let chunksRead = 0;
|
|
7
|
+
if (type == 'chunks') {
|
|
8
|
+
const reader = stream.getReader();
|
|
9
|
+
return new ReadableStream({
|
|
10
|
+
async pull(controller) {
|
|
11
|
+
while (chunksRead < offset) {
|
|
12
|
+
const result = await reader.read();
|
|
13
|
+
chunksRead++;
|
|
14
|
+
if (result.done) {
|
|
15
|
+
controller.close();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if ((chunksRead - offset) == length) {
|
|
20
|
+
await reader.cancel();
|
|
21
|
+
controller.close();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const result = await reader.read();
|
|
25
|
+
chunksRead++;
|
|
26
|
+
if (result.done) {
|
|
27
|
+
controller.close();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
controller.enqueue(result.value);
|
|
31
|
+
},
|
|
32
|
+
async cancel(reason) {
|
|
33
|
+
await reader.cancel(reason);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const byobReader = toBytesStream(stream).getReader({ mode: 'byob' });
|
|
38
|
+
let bytesRead = 0;
|
|
39
|
+
let offsetBuffer = new ArrayBuffer(mebibyte);
|
|
40
|
+
return new ReadableStream({
|
|
41
|
+
type: 'bytes',
|
|
42
|
+
autoAllocateChunkSize: 100 * kibibyte,
|
|
43
|
+
async pull(controller) {
|
|
44
|
+
while (bytesRead < offset) {
|
|
45
|
+
const readResult = await byobReader.read(new Uint8Array(offsetBuffer, 0, Math.min(offsetBuffer.byteLength, offset - bytesRead)));
|
|
46
|
+
if (readResult.done) {
|
|
47
|
+
controller.close();
|
|
48
|
+
controller.byobRequest.respond(0);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
bytesRead += readResult.value.byteLength;
|
|
52
|
+
if (bytesRead == offset) {
|
|
53
|
+
offsetBuffer = null; // eslint-disable-line require-atomic-updates
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if ((bytesRead - offset) == length) {
|
|
57
|
+
await byobReader.cancel();
|
|
58
|
+
controller.close();
|
|
59
|
+
controller.byobRequest.respond(0);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const view = controller.byobRequest.view;
|
|
63
|
+
const readResult = await byobReader.read(new Uint8Array(view.buffer, view.byteOffset, Math.min(view.byteLength, length - (bytesRead - offset))));
|
|
64
|
+
bytesRead += readResult.value.byteLength;
|
|
65
|
+
if (readResult.done) {
|
|
66
|
+
await byobReader.cancel();
|
|
67
|
+
controller.close();
|
|
68
|
+
}
|
|
69
|
+
controller.byobRequest.respondWithNewView(readResult.value);
|
|
70
|
+
},
|
|
71
|
+
async cancel(reason) {
|
|
72
|
+
await byobReader.cancel(reason);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { isNotNull, isNull } from '../type-guards.js';
|
|
2
|
+
import { kibibyte } from '../units.js';
|
|
2
3
|
export function toBytesStream(stream, options) {
|
|
3
4
|
try { // try to use byob mode from source
|
|
4
5
|
let byobReader;
|
|
5
6
|
return new ReadableStream({
|
|
6
7
|
type: 'bytes',
|
|
7
|
-
autoAllocateChunkSize:
|
|
8
|
+
autoAllocateChunkSize: 100 * kibibyte,
|
|
8
9
|
start() {
|
|
9
10
|
byobReader = stream.getReader({ mode: 'byob' });
|
|
10
11
|
},
|
|
@@ -12,8 +13,6 @@ export function toBytesStream(stream, options) {
|
|
|
12
13
|
const readResult = await byobReader.read(controller.byobRequest.view);
|
|
13
14
|
if (readResult.done) {
|
|
14
15
|
controller.close();
|
|
15
|
-
controller.byobRequest.respond(0);
|
|
16
|
-
return;
|
|
17
16
|
}
|
|
18
17
|
controller.byobRequest.respondWithNewView(readResult.value);
|
|
19
18
|
},
|