mavenagi 0.0.0-alpha.11 → 0.0.0-alpha.14
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/Client.d.ts +9 -0
- package/README.md +49 -5
- package/api/resources/actions/client/Client.d.ts +9 -0
- package/api/resources/actions/client/Client.js +18 -15
- package/api/resources/commons/types/AppUser.d.ts +3 -2
- package/api/resources/commons/types/AppUserIdentifier.d.ts +1 -1
- package/api/resources/commons/types/AppUserRequest.d.ts +19 -1
- package/api/resources/commons/types/AppUserResponse.d.ts +34 -2
- package/api/resources/commons/types/EntityType.d.ts +2 -1
- package/api/resources/commons/types/EntityType.js +1 -0
- package/api/resources/commons/types/Feedback.d.ts +4 -8
- package/api/resources/commons/types/FeedbackBase.d.ts +10 -0
- package/api/resources/commons/types/UserData.d.ts +1 -1
- package/api/resources/commons/types/index.d.ts +4 -2
- package/api/resources/commons/types/index.js +4 -2
- package/api/resources/conversation/client/Client.d.ts +39 -22
- package/api/resources/conversation/client/Client.js +97 -77
- package/api/resources/conversation/types/AskRequest.d.ts +2 -4
- package/api/resources/conversation/types/ConversationBase.d.ts +12 -0
- package/api/resources/conversation/types/ConversationMessageBase.d.ts +4 -3
- package/api/resources/conversation/types/ConversationRequest.d.ts +0 -2
- package/api/resources/conversation/types/ConversationResponse.d.ts +0 -2
- package/api/resources/conversation/types/FeedbackRequest.d.ts +8 -1
- package/api/resources/conversation/types/SubmitActionFormRequest.d.ts +1 -3
- package/api/resources/conversation/types/UserMessageBase.d.ts +2 -0
- package/api/resources/conversation/types/index.d.ts +0 -2
- package/api/resources/conversation/types/index.js +0 -2
- package/api/resources/knowledge/client/Client.d.ts +9 -0
- package/api/resources/knowledge/client/Client.js +44 -37
- package/api/resources/triggers/client/Client.d.ts +9 -0
- package/api/resources/triggers/client/Client.js +18 -15
- package/api/resources/triggers/types/index.d.ts +0 -3
- package/api/resources/triggers/types/index.js +0 -3
- package/api/resources/users/client/Client.d.ts +27 -14
- package/api/resources/users/client/Client.js +32 -26
- package/core/fetcher/Fetcher.d.ts +4 -1
- package/core/fetcher/Fetcher.js +18 -159
- package/core/fetcher/createRequestUrl.d.ts +1 -0
- package/core/fetcher/createRequestUrl.js +6 -0
- package/core/fetcher/getFetchFn.d.ts +4 -0
- package/core/fetcher/getFetchFn.js +32 -0
- package/core/fetcher/getRequestBody.d.ts +7 -0
- package/core/fetcher/getRequestBody.js +19 -0
- package/core/fetcher/getResponseBody.d.ts +1 -0
- package/core/fetcher/getResponseBody.js +48 -0
- package/core/fetcher/makeRequest.d.ts +1 -0
- package/core/fetcher/makeRequest.js +38 -0
- package/core/fetcher/requestWithRetries.d.ts +1 -0
- package/core/fetcher/requestWithRetries.js +28 -0
- package/core/fetcher/signals.d.ts +12 -0
- package/core/fetcher/signals.js +32 -0
- package/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.d.ts +30 -0
- package/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.js +222 -0
- package/core/fetcher/stream-wrappers/NodePre18StreamWrapper.d.ts +21 -0
- package/core/fetcher/stream-wrappers/NodePre18StreamWrapper.js +104 -0
- package/core/fetcher/stream-wrappers/UndiciStreamWrapper.d.ts +30 -0
- package/core/fetcher/stream-wrappers/UndiciStreamWrapper.js +204 -0
- package/core/fetcher/stream-wrappers/chooseStreamWrapper.d.ts +17 -0
- package/core/fetcher/stream-wrappers/chooseStreamWrapper.js +23 -0
- package/core/runtime/runtime.d.ts +1 -0
- package/core/runtime/runtime.js +1 -0
- package/core/schemas/Schema.d.ts +7 -4
- package/core/schemas/builders/lazy/lazy.d.ts +2 -2
- package/core/schemas/builders/lazy/lazy.js +8 -19
- package/core/schemas/builders/lazy/lazyObject.js +1 -10
- package/core/schemas/builders/list/list.js +31 -44
- package/core/schemas/builders/object/object.js +90 -111
- package/core/schemas/builders/object/types.d.ts +2 -2
- package/core/schemas/builders/object-like/getObjectLikeUtils.js +3 -12
- package/core/schemas/builders/record/record.js +49 -60
- package/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +2 -2
- package/core/schemas/builders/schema-utils/getSchemaUtils.js +18 -21
- package/core/schemas/builders/set/set.js +6 -15
- package/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +21 -32
- package/core/schemas/builders/union/union.js +51 -62
- package/core/schemas/utils/maybeSkipValidation.js +3 -12
- package/dist/Client.d.ts +9 -0
- package/dist/api/resources/actions/client/Client.d.ts +9 -0
- package/dist/api/resources/actions/client/Client.js +18 -15
- package/dist/api/resources/commons/types/AppUser.d.ts +3 -2
- package/dist/api/resources/commons/types/AppUserIdentifier.d.ts +1 -1
- package/dist/api/resources/commons/types/AppUserRequest.d.ts +19 -1
- package/dist/api/resources/commons/types/AppUserResponse.d.ts +34 -2
- package/dist/api/resources/commons/types/EntityType.d.ts +2 -1
- package/dist/api/resources/commons/types/EntityType.js +1 -0
- package/dist/api/resources/commons/types/Feedback.d.ts +4 -8
- package/dist/api/resources/commons/types/FeedbackBase.d.ts +10 -0
- package/dist/api/resources/commons/types/UserData.d.ts +1 -1
- package/dist/api/resources/commons/types/index.d.ts +4 -2
- package/dist/api/resources/commons/types/index.js +4 -2
- package/dist/api/resources/conversation/client/Client.d.ts +39 -22
- package/dist/api/resources/conversation/client/Client.js +97 -77
- package/dist/api/resources/conversation/types/AskRequest.d.ts +2 -4
- package/dist/api/resources/conversation/types/ConversationBase.d.ts +12 -0
- package/dist/api/resources/conversation/types/ConversationMessageBase.d.ts +4 -3
- package/dist/api/resources/conversation/types/ConversationRequest.d.ts +0 -2
- package/dist/api/resources/conversation/types/ConversationResponse.d.ts +0 -2
- package/dist/api/resources/conversation/types/FeedbackRequest.d.ts +8 -1
- package/dist/api/resources/conversation/types/SubmitActionFormRequest.d.ts +1 -3
- package/dist/api/resources/conversation/types/UserMessageBase.d.ts +2 -0
- package/dist/api/resources/conversation/types/index.d.ts +0 -2
- package/dist/api/resources/conversation/types/index.js +0 -2
- package/dist/api/resources/knowledge/client/Client.d.ts +9 -0
- package/dist/api/resources/knowledge/client/Client.js +44 -37
- package/dist/api/resources/triggers/client/Client.d.ts +9 -0
- package/dist/api/resources/triggers/client/Client.js +18 -15
- package/dist/api/resources/triggers/types/index.d.ts +0 -3
- package/dist/api/resources/triggers/types/index.js +0 -3
- package/dist/api/resources/users/client/Client.d.ts +27 -14
- package/dist/api/resources/users/client/Client.js +32 -26
- package/dist/core/fetcher/Fetcher.d.ts +4 -1
- package/dist/core/fetcher/Fetcher.js +18 -159
- package/dist/core/fetcher/createRequestUrl.d.ts +1 -0
- package/dist/core/fetcher/createRequestUrl.js +6 -0
- package/dist/core/fetcher/getFetchFn.d.ts +4 -0
- package/dist/core/fetcher/getFetchFn.js +32 -0
- package/dist/core/fetcher/getRequestBody.d.ts +7 -0
- package/dist/core/fetcher/getRequestBody.js +19 -0
- package/dist/core/fetcher/getResponseBody.d.ts +1 -0
- package/dist/core/fetcher/getResponseBody.js +48 -0
- package/dist/core/fetcher/makeRequest.d.ts +1 -0
- package/dist/core/fetcher/makeRequest.js +38 -0
- package/dist/core/fetcher/requestWithRetries.d.ts +1 -0
- package/dist/core/fetcher/requestWithRetries.js +28 -0
- package/dist/core/fetcher/signals.d.ts +12 -0
- package/dist/core/fetcher/signals.js +32 -0
- package/dist/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.d.ts +30 -0
- package/dist/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.js +222 -0
- package/dist/core/fetcher/stream-wrappers/NodePre18StreamWrapper.d.ts +21 -0
- package/dist/core/fetcher/stream-wrappers/NodePre18StreamWrapper.js +104 -0
- package/dist/core/fetcher/stream-wrappers/UndiciStreamWrapper.d.ts +30 -0
- package/dist/core/fetcher/stream-wrappers/UndiciStreamWrapper.js +204 -0
- package/dist/core/fetcher/stream-wrappers/chooseStreamWrapper.d.ts +17 -0
- package/dist/core/fetcher/stream-wrappers/chooseStreamWrapper.js +23 -0
- package/dist/core/runtime/runtime.d.ts +1 -0
- package/dist/core/runtime/runtime.js +1 -0
- package/dist/core/schemas/Schema.d.ts +7 -4
- package/dist/core/schemas/builders/lazy/lazy.d.ts +2 -2
- package/dist/core/schemas/builders/lazy/lazy.js +8 -19
- package/dist/core/schemas/builders/lazy/lazyObject.js +1 -10
- package/dist/core/schemas/builders/list/list.js +31 -44
- package/dist/core/schemas/builders/object/object.js +90 -111
- package/dist/core/schemas/builders/object/types.d.ts +2 -2
- package/dist/core/schemas/builders/object-like/getObjectLikeUtils.js +3 -12
- package/dist/core/schemas/builders/record/record.js +49 -60
- package/dist/core/schemas/builders/schema-utils/getSchemaUtils.d.ts +2 -2
- package/dist/core/schemas/builders/schema-utils/getSchemaUtils.js +18 -21
- package/dist/core/schemas/builders/set/set.js +6 -15
- package/dist/core/schemas/builders/undiscriminated-union/undiscriminatedUnion.js +21 -32
- package/dist/core/schemas/builders/union/union.js +51 -62
- package/dist/core/schemas/utils/maybeSkipValidation.js +3 -12
- package/dist/serialization/resources/commons/types/AppUser.d.ts +3 -3
- package/dist/serialization/resources/commons/types/AppUser.js +3 -3
- package/dist/serialization/resources/commons/types/AppUserIdentifier.d.ts +1 -1
- package/dist/serialization/resources/commons/types/AppUserIdentifier.js +1 -1
- package/dist/serialization/resources/commons/types/AppUserRequest.d.ts +1 -1
- package/dist/serialization/resources/commons/types/AppUserRequest.js +1 -1
- package/dist/serialization/resources/commons/types/AppUserResponse.d.ts +2 -1
- package/dist/serialization/resources/commons/types/AppUserResponse.js +2 -1
- package/dist/serialization/resources/commons/types/EntityType.d.ts +1 -1
- package/dist/serialization/resources/commons/types/EntityType.js +1 -0
- package/{serialization/resources/triggers → dist/serialization/resources/commons}/types/EventTriggerResponse.d.ts +1 -1
- package/{serialization/resources/triggers → dist/serialization/resources/commons}/types/EventTriggerResponse.js +1 -1
- package/dist/serialization/resources/commons/types/Feedback.d.ts +6 -7
- package/dist/serialization/resources/commons/types/Feedback.js +9 -8
- package/dist/serialization/resources/commons/types/FeedbackBase.d.ts +14 -0
- package/dist/serialization/resources/commons/types/FeedbackBase.js +9 -0
- package/dist/serialization/resources/commons/types/UserData.d.ts +1 -1
- package/dist/serialization/resources/commons/types/UserData.js +1 -1
- package/dist/serialization/resources/commons/types/index.d.ts +4 -2
- package/dist/serialization/resources/commons/types/index.js +4 -2
- package/dist/serialization/resources/conversation/types/AskRequest.d.ts +1 -4
- package/dist/serialization/resources/conversation/types/AskRequest.js +1 -4
- package/dist/serialization/resources/conversation/types/ConversationBase.d.ts +6 -0
- package/dist/serialization/resources/conversation/types/ConversationBase.js +6 -0
- package/dist/serialization/resources/conversation/types/ConversationMessageBase.d.ts +2 -2
- package/dist/serialization/resources/conversation/types/ConversationMessageBase.js +2 -2
- package/dist/serialization/resources/conversation/types/ConversationRequest.d.ts +0 -2
- package/dist/serialization/resources/conversation/types/ConversationRequest.js +0 -2
- package/dist/serialization/resources/conversation/types/ConversationResponse.d.ts +0 -2
- package/dist/serialization/resources/conversation/types/ConversationResponse.js +0 -2
- package/dist/serialization/resources/conversation/types/FeedbackRequest.d.ts +7 -2
- package/dist/serialization/resources/conversation/types/FeedbackRequest.js +10 -2
- package/dist/serialization/resources/conversation/types/SubmitActionFormRequest.d.ts +0 -2
- package/dist/serialization/resources/conversation/types/SubmitActionFormRequest.js +0 -2
- package/dist/serialization/resources/conversation/types/UserMessageBase.d.ts +2 -0
- package/dist/serialization/resources/conversation/types/UserMessageBase.js +2 -0
- package/dist/serialization/resources/conversation/types/index.d.ts +0 -2
- package/dist/serialization/resources/conversation/types/index.js +0 -2
- package/dist/serialization/resources/triggers/types/EventTriggerRequest.d.ts +1 -1
- package/dist/serialization/resources/triggers/types/EventTriggerRequest.js +1 -1
- package/dist/serialization/resources/triggers/types/index.d.ts +0 -3
- package/dist/serialization/resources/triggers/types/index.js +0 -3
- package/package.json +7 -2
- package/reference.md +1732 -0
- package/serialization/resources/commons/types/AppUser.d.ts +3 -3
- package/serialization/resources/commons/types/AppUser.js +3 -3
- package/serialization/resources/commons/types/AppUserIdentifier.d.ts +1 -1
- package/serialization/resources/commons/types/AppUserIdentifier.js +1 -1
- package/serialization/resources/commons/types/AppUserRequest.d.ts +1 -1
- package/serialization/resources/commons/types/AppUserRequest.js +1 -1
- package/serialization/resources/commons/types/AppUserResponse.d.ts +2 -1
- package/serialization/resources/commons/types/AppUserResponse.js +2 -1
- package/serialization/resources/commons/types/EntityType.d.ts +1 -1
- package/serialization/resources/commons/types/EntityType.js +1 -0
- package/{dist/serialization/resources/triggers → serialization/resources/commons}/types/EventTriggerResponse.d.ts +1 -1
- package/{dist/serialization/resources/triggers → serialization/resources/commons}/types/EventTriggerResponse.js +1 -1
- package/serialization/resources/commons/types/Feedback.d.ts +6 -7
- package/serialization/resources/commons/types/Feedback.js +9 -8
- package/serialization/resources/commons/types/FeedbackBase.d.ts +14 -0
- package/serialization/resources/commons/types/FeedbackBase.js +9 -0
- package/serialization/resources/commons/types/UserData.d.ts +1 -1
- package/serialization/resources/commons/types/UserData.js +1 -1
- package/serialization/resources/commons/types/index.d.ts +4 -2
- package/serialization/resources/commons/types/index.js +4 -2
- package/serialization/resources/conversation/types/AskRequest.d.ts +1 -4
- package/serialization/resources/conversation/types/AskRequest.js +1 -4
- package/serialization/resources/conversation/types/ConversationBase.d.ts +6 -0
- package/serialization/resources/conversation/types/ConversationBase.js +6 -0
- package/serialization/resources/conversation/types/ConversationMessageBase.d.ts +2 -2
- package/serialization/resources/conversation/types/ConversationMessageBase.js +2 -2
- package/serialization/resources/conversation/types/ConversationRequest.d.ts +0 -2
- package/serialization/resources/conversation/types/ConversationRequest.js +0 -2
- package/serialization/resources/conversation/types/ConversationResponse.d.ts +0 -2
- package/serialization/resources/conversation/types/ConversationResponse.js +0 -2
- package/serialization/resources/conversation/types/FeedbackRequest.d.ts +7 -2
- package/serialization/resources/conversation/types/FeedbackRequest.js +10 -2
- package/serialization/resources/conversation/types/SubmitActionFormRequest.d.ts +0 -2
- package/serialization/resources/conversation/types/SubmitActionFormRequest.js +0 -2
- package/serialization/resources/conversation/types/UserMessageBase.d.ts +2 -0
- package/serialization/resources/conversation/types/UserMessageBase.js +2 -0
- package/serialization/resources/conversation/types/index.d.ts +0 -2
- package/serialization/resources/conversation/types/index.js +0 -2
- package/serialization/resources/triggers/types/EventTriggerRequest.d.ts +1 -1
- package/serialization/resources/triggers/types/EventTriggerRequest.js +1 -1
- package/serialization/resources/triggers/types/index.d.ts +0 -3
- package/serialization/resources/triggers/types/index.js +0 -3
- package/api/resources/commons/types/AppUserIdentification.d.ts +0 -8
- package/api/resources/commons/types/User.d.ts +0 -10
- package/api/resources/conversation/types/ConversationContext.d.ts +0 -20
- package/api/resources/conversation/types/ConversationContext.js +0 -4
- package/api/resources/conversation/types/ConversationMessageContext.d.ts +0 -12
- package/api/resources/conversation/types/ConversationMessageContext.js +0 -4
- package/dist/api/resources/commons/types/AppUserIdentification.d.ts +0 -8
- package/dist/api/resources/commons/types/AppUserIdentification.js +0 -4
- package/dist/api/resources/commons/types/User.d.ts +0 -10
- package/dist/api/resources/commons/types/User.js +0 -4
- package/dist/api/resources/conversation/types/ConversationContext.d.ts +0 -20
- package/dist/api/resources/conversation/types/ConversationContext.js +0 -4
- package/dist/api/resources/conversation/types/ConversationMessageContext.d.ts +0 -12
- package/dist/api/resources/conversation/types/ConversationMessageContext.js +0 -4
- package/dist/serialization/resources/commons/types/AppUserIdentification.d.ts +0 -13
- package/dist/serialization/resources/commons/types/AppUserIdentification.js +0 -8
- package/dist/serialization/resources/commons/types/User.d.ts +0 -15
- package/dist/serialization/resources/commons/types/User.js +0 -10
- package/dist/serialization/resources/conversation/types/ConversationContext.d.ts +0 -20
- package/dist/serialization/resources/conversation/types/ConversationContext.js +0 -15
- package/dist/serialization/resources/conversation/types/ConversationMessageContext.d.ts +0 -16
- package/dist/serialization/resources/conversation/types/ConversationMessageContext.js +0 -11
- package/serialization/resources/commons/types/AppUserIdentification.d.ts +0 -13
- package/serialization/resources/commons/types/AppUserIdentification.js +0 -8
- package/serialization/resources/commons/types/User.d.ts +0 -15
- package/serialization/resources/commons/types/User.js +0 -10
- package/serialization/resources/conversation/types/ConversationContext.d.ts +0 -20
- package/serialization/resources/conversation/types/ConversationContext.js +0 -15
- package/serialization/resources/conversation/types/ConversationMessageContext.d.ts +0 -16
- package/serialization/resources/conversation/types/ConversationMessageContext.js +0 -11
- /package/api/resources/{triggers → commons}/types/EventTriggerBase.d.ts +0 -0
- /package/api/resources/{triggers → commons}/types/EventTriggerBase.js +0 -0
- /package/api/resources/{triggers → commons}/types/EventTriggerResponse.d.ts +0 -0
- /package/api/resources/{triggers → commons}/types/EventTriggerResponse.js +0 -0
- /package/api/resources/{triggers → commons}/types/EventTriggerType.d.ts +0 -0
- /package/api/resources/{triggers → commons}/types/EventTriggerType.js +0 -0
- /package/api/resources/commons/types/{AppUserIdentification.js → FeedbackBase.js} +0 -0
- /package/dist/api/resources/{triggers → commons}/types/EventTriggerBase.d.ts +0 -0
- /package/dist/api/resources/{triggers → commons}/types/EventTriggerBase.js +0 -0
- /package/dist/api/resources/{triggers → commons}/types/EventTriggerResponse.d.ts +0 -0
- /package/dist/api/resources/{triggers → commons}/types/EventTriggerResponse.js +0 -0
- /package/dist/api/resources/{triggers → commons}/types/EventTriggerType.d.ts +0 -0
- /package/dist/api/resources/{triggers → commons}/types/EventTriggerType.js +0 -0
- /package/{api/resources/commons/types/User.js → dist/api/resources/commons/types/FeedbackBase.js} +0 -0
- /package/dist/serialization/resources/{triggers → commons}/types/EventTriggerBase.d.ts +0 -0
- /package/dist/serialization/resources/{triggers → commons}/types/EventTriggerBase.js +0 -0
- /package/dist/serialization/resources/{triggers → commons}/types/EventTriggerType.d.ts +0 -0
- /package/dist/serialization/resources/{triggers → commons}/types/EventTriggerType.js +0 -0
- /package/serialization/resources/{triggers → commons}/types/EventTriggerBase.d.ts +0 -0
- /package/serialization/resources/{triggers → commons}/types/EventTriggerBase.js +0 -0
- /package/serialization/resources/{triggers → commons}/types/EventTriggerType.d.ts +0 -0
- /package/serialization/resources/{triggers → commons}/types/EventTriggerType.js +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Writable } from "stream";
|
|
3
|
+
import { EventCallback, StreamWrapper } from "./chooseStreamWrapper";
|
|
4
|
+
export declare class Node18UniversalStreamWrapper implements StreamWrapper<Node18UniversalStreamWrapper | Writable | WritableStream<Uint8Array>, Uint8Array> {
|
|
5
|
+
private readableStream;
|
|
6
|
+
private reader;
|
|
7
|
+
private events;
|
|
8
|
+
private paused;
|
|
9
|
+
private resumeCallback;
|
|
10
|
+
private encoding;
|
|
11
|
+
constructor(readableStream: ReadableStream<Uint8Array>);
|
|
12
|
+
on(event: string, callback: EventCallback): void;
|
|
13
|
+
off(event: string, callback: EventCallback): void;
|
|
14
|
+
pipe(dest: Node18UniversalStreamWrapper | Writable | WritableStream<Uint8Array>): Node18UniversalStreamWrapper | Writable | WritableStream<Uint8Array>;
|
|
15
|
+
pipeTo(dest: Node18UniversalStreamWrapper | Writable | WritableStream<Uint8Array>): Node18UniversalStreamWrapper | Writable | WritableStream<Uint8Array>;
|
|
16
|
+
unpipe(dest: Node18UniversalStreamWrapper | Writable | WritableStream<Uint8Array>): void;
|
|
17
|
+
destroy(error?: Error): void;
|
|
18
|
+
pause(): void;
|
|
19
|
+
resume(): void;
|
|
20
|
+
get isPaused(): boolean;
|
|
21
|
+
read(): Promise<Uint8Array | undefined>;
|
|
22
|
+
setEncoding(encoding: string): void;
|
|
23
|
+
text(): Promise<string>;
|
|
24
|
+
json<T>(): Promise<T>;
|
|
25
|
+
private _write;
|
|
26
|
+
private _end;
|
|
27
|
+
private _error;
|
|
28
|
+
private _emit;
|
|
29
|
+
private _startReading;
|
|
30
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export class Node18UniversalStreamWrapper {
|
|
11
|
+
constructor(readableStream) {
|
|
12
|
+
this.readableStream = readableStream;
|
|
13
|
+
this.reader = this.readableStream.getReader();
|
|
14
|
+
this.events = {
|
|
15
|
+
data: [],
|
|
16
|
+
end: [],
|
|
17
|
+
error: [],
|
|
18
|
+
readable: [],
|
|
19
|
+
close: [],
|
|
20
|
+
pause: [],
|
|
21
|
+
resume: [],
|
|
22
|
+
};
|
|
23
|
+
this.paused = false;
|
|
24
|
+
this.resumeCallback = null;
|
|
25
|
+
this.encoding = null;
|
|
26
|
+
}
|
|
27
|
+
on(event, callback) {
|
|
28
|
+
var _a;
|
|
29
|
+
(_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.push(callback);
|
|
30
|
+
}
|
|
31
|
+
off(event, callback) {
|
|
32
|
+
var _a;
|
|
33
|
+
this.events[event] = (_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.filter((cb) => cb !== callback);
|
|
34
|
+
}
|
|
35
|
+
pipe(dest) {
|
|
36
|
+
this.on("data", (chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
38
|
+
dest._write(chunk);
|
|
39
|
+
}
|
|
40
|
+
else if (dest instanceof WritableStream) {
|
|
41
|
+
const writer = dest.getWriter();
|
|
42
|
+
writer.write(chunk).then(() => writer.releaseLock());
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
dest.write(chunk);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
this.on("end", () => __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
50
|
+
dest._end();
|
|
51
|
+
}
|
|
52
|
+
else if (dest instanceof WritableStream) {
|
|
53
|
+
const writer = dest.getWriter();
|
|
54
|
+
writer.close();
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
dest.end();
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
this.on("error", (error) => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
62
|
+
dest._error(error);
|
|
63
|
+
}
|
|
64
|
+
else if (dest instanceof WritableStream) {
|
|
65
|
+
const writer = dest.getWriter();
|
|
66
|
+
writer.abort(error);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
dest.destroy(error);
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
this._startReading();
|
|
73
|
+
return dest;
|
|
74
|
+
}
|
|
75
|
+
pipeTo(dest) {
|
|
76
|
+
return this.pipe(dest);
|
|
77
|
+
}
|
|
78
|
+
unpipe(dest) {
|
|
79
|
+
this.off("data", (chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
81
|
+
dest._write(chunk);
|
|
82
|
+
}
|
|
83
|
+
else if (dest instanceof WritableStream) {
|
|
84
|
+
const writer = dest.getWriter();
|
|
85
|
+
writer.write(chunk).then(() => writer.releaseLock());
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
dest.write(chunk);
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
91
|
+
this.off("end", () => __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
93
|
+
dest._end();
|
|
94
|
+
}
|
|
95
|
+
else if (dest instanceof WritableStream) {
|
|
96
|
+
const writer = dest.getWriter();
|
|
97
|
+
writer.close();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
dest.end();
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
this.off("error", (error) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
105
|
+
dest._error(error);
|
|
106
|
+
}
|
|
107
|
+
else if (dest instanceof WritableStream) {
|
|
108
|
+
const writer = dest.getWriter();
|
|
109
|
+
writer.abort(error);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
dest.destroy(error);
|
|
113
|
+
}
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
destroy(error) {
|
|
117
|
+
this.reader
|
|
118
|
+
.cancel(error)
|
|
119
|
+
.then(() => {
|
|
120
|
+
this._emit("close");
|
|
121
|
+
})
|
|
122
|
+
.catch((err) => {
|
|
123
|
+
this._emit("error", err);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
pause() {
|
|
127
|
+
this.paused = true;
|
|
128
|
+
this._emit("pause");
|
|
129
|
+
}
|
|
130
|
+
resume() {
|
|
131
|
+
if (this.paused) {
|
|
132
|
+
this.paused = false;
|
|
133
|
+
this._emit("resume");
|
|
134
|
+
if (this.resumeCallback) {
|
|
135
|
+
this.resumeCallback();
|
|
136
|
+
this.resumeCallback = null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
get isPaused() {
|
|
141
|
+
return this.paused;
|
|
142
|
+
}
|
|
143
|
+
read() {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
if (this.paused) {
|
|
146
|
+
yield new Promise((resolve) => {
|
|
147
|
+
this.resumeCallback = resolve;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const { done, value } = yield this.reader.read();
|
|
151
|
+
if (done) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
return value;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
setEncoding(encoding) {
|
|
158
|
+
this.encoding = encoding;
|
|
159
|
+
}
|
|
160
|
+
text() {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
const chunks = [];
|
|
163
|
+
while (true) {
|
|
164
|
+
const { done, value } = yield this.reader.read();
|
|
165
|
+
if (done)
|
|
166
|
+
break;
|
|
167
|
+
if (value)
|
|
168
|
+
chunks.push(value);
|
|
169
|
+
}
|
|
170
|
+
const decoder = new TextDecoder(this.encoding || "utf-8");
|
|
171
|
+
return decoder.decode(yield new Blob(chunks).arrayBuffer());
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
json() {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const text = yield this.text();
|
|
177
|
+
return JSON.parse(text);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
_write(chunk) {
|
|
181
|
+
this._emit("data", chunk);
|
|
182
|
+
}
|
|
183
|
+
_end() {
|
|
184
|
+
this._emit("end");
|
|
185
|
+
}
|
|
186
|
+
_error(error) {
|
|
187
|
+
this._emit("error", error);
|
|
188
|
+
}
|
|
189
|
+
_emit(event, data) {
|
|
190
|
+
if (this.events[event]) {
|
|
191
|
+
for (const callback of this.events[event] || []) {
|
|
192
|
+
callback(data);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
_startReading() {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
try {
|
|
199
|
+
this._emit("readable");
|
|
200
|
+
while (true) {
|
|
201
|
+
if (this.paused) {
|
|
202
|
+
yield new Promise((resolve) => {
|
|
203
|
+
this.resumeCallback = resolve;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const { done, value } = yield this.reader.read();
|
|
207
|
+
if (done) {
|
|
208
|
+
this._emit("end");
|
|
209
|
+
this._emit("close");
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
if (value) {
|
|
213
|
+
this._emit("data", value);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
this._emit("error", error);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Readable, Writable } from "stream";
|
|
3
|
+
import { EventCallback, StreamWrapper } from "./chooseStreamWrapper";
|
|
4
|
+
export declare class NodePre18StreamWrapper implements StreamWrapper<Writable, Buffer> {
|
|
5
|
+
private readableStream;
|
|
6
|
+
private encoding;
|
|
7
|
+
constructor(readableStream: Readable);
|
|
8
|
+
on(event: string, callback: EventCallback): void;
|
|
9
|
+
off(event: string, callback: EventCallback): void;
|
|
10
|
+
pipe(dest: Writable): Writable;
|
|
11
|
+
pipeTo(dest: Writable): Writable;
|
|
12
|
+
unpipe(dest?: Writable): void;
|
|
13
|
+
destroy(error?: Error): void;
|
|
14
|
+
pause(): void;
|
|
15
|
+
resume(): void;
|
|
16
|
+
get isPaused(): boolean;
|
|
17
|
+
read(): Promise<Buffer | undefined>;
|
|
18
|
+
setEncoding(encoding?: string): void;
|
|
19
|
+
text(): Promise<string>;
|
|
20
|
+
json<T>(): Promise<T>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
11
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
+
var m = o[Symbol.asyncIterator], i;
|
|
13
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
14
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
15
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
|
+
};
|
|
17
|
+
export class NodePre18StreamWrapper {
|
|
18
|
+
constructor(readableStream) {
|
|
19
|
+
this.readableStream = readableStream;
|
|
20
|
+
}
|
|
21
|
+
on(event, callback) {
|
|
22
|
+
this.readableStream.on(event, callback);
|
|
23
|
+
}
|
|
24
|
+
off(event, callback) {
|
|
25
|
+
this.readableStream.off(event, callback);
|
|
26
|
+
}
|
|
27
|
+
pipe(dest) {
|
|
28
|
+
this.readableStream.pipe(dest);
|
|
29
|
+
return dest;
|
|
30
|
+
}
|
|
31
|
+
pipeTo(dest) {
|
|
32
|
+
return this.pipe(dest);
|
|
33
|
+
}
|
|
34
|
+
unpipe(dest) {
|
|
35
|
+
if (dest) {
|
|
36
|
+
this.readableStream.unpipe(dest);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.readableStream.unpipe();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
destroy(error) {
|
|
43
|
+
this.readableStream.destroy(error);
|
|
44
|
+
}
|
|
45
|
+
pause() {
|
|
46
|
+
this.readableStream.pause();
|
|
47
|
+
}
|
|
48
|
+
resume() {
|
|
49
|
+
this.readableStream.resume();
|
|
50
|
+
}
|
|
51
|
+
get isPaused() {
|
|
52
|
+
return this.readableStream.isPaused();
|
|
53
|
+
}
|
|
54
|
+
read() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const chunk = this.readableStream.read();
|
|
58
|
+
if (chunk) {
|
|
59
|
+
resolve(chunk);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.readableStream.once("readable", () => {
|
|
63
|
+
const chunk = this.readableStream.read();
|
|
64
|
+
resolve(chunk);
|
|
65
|
+
});
|
|
66
|
+
this.readableStream.once("error", reject);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
setEncoding(encoding) {
|
|
72
|
+
this.readableStream.setEncoding(encoding);
|
|
73
|
+
this.encoding = encoding;
|
|
74
|
+
}
|
|
75
|
+
text() {
|
|
76
|
+
var e_1, _a;
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const chunks = [];
|
|
79
|
+
const encoder = new TextEncoder();
|
|
80
|
+
this.readableStream.setEncoding((this.encoding || "utf-8"));
|
|
81
|
+
try {
|
|
82
|
+
for (var _b = __asyncValues(this.readableStream), _c; _c = yield _b.next(), !_c.done;) {
|
|
83
|
+
const chunk = _c.value;
|
|
84
|
+
chunks.push(encoder.encode(chunk));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
88
|
+
finally {
|
|
89
|
+
try {
|
|
90
|
+
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
|
|
91
|
+
}
|
|
92
|
+
finally { if (e_1) throw e_1.error; }
|
|
93
|
+
}
|
|
94
|
+
const decoder = new TextDecoder(this.encoding || "utf-8");
|
|
95
|
+
return decoder.decode(Buffer.concat(chunks));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
json() {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const text = yield this.text();
|
|
101
|
+
return JSON.parse(text);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { StreamWrapper } from "./chooseStreamWrapper";
|
|
2
|
+
declare type EventCallback = (data?: any) => void;
|
|
3
|
+
export declare class UndiciStreamWrapper<ReadFormat extends Uint8Array | Uint16Array | Uint32Array> implements StreamWrapper<UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat>, ReadFormat> {
|
|
4
|
+
private readableStream;
|
|
5
|
+
private reader;
|
|
6
|
+
private events;
|
|
7
|
+
private paused;
|
|
8
|
+
private resumeCallback;
|
|
9
|
+
private encoding;
|
|
10
|
+
constructor(readableStream: ReadableStream<ReadFormat>);
|
|
11
|
+
on(event: string, callback: EventCallback): void;
|
|
12
|
+
off(event: string, callback: EventCallback): void;
|
|
13
|
+
pipe(dest: UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat>): UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat>;
|
|
14
|
+
pipeTo(dest: UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat>): UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat>;
|
|
15
|
+
unpipe(dest: UndiciStreamWrapper<ReadFormat> | WritableStream<any>): void;
|
|
16
|
+
destroy(error?: Error): void;
|
|
17
|
+
pause(): void;
|
|
18
|
+
resume(): void;
|
|
19
|
+
get isPaused(): boolean;
|
|
20
|
+
read(): Promise<ReadFormat | undefined>;
|
|
21
|
+
setEncoding(encoding: string): void;
|
|
22
|
+
text(): Promise<string>;
|
|
23
|
+
json<T>(): Promise<T>;
|
|
24
|
+
private _write;
|
|
25
|
+
private _end;
|
|
26
|
+
private _error;
|
|
27
|
+
private _emit;
|
|
28
|
+
private _startReading;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export class UndiciStreamWrapper {
|
|
11
|
+
constructor(readableStream) {
|
|
12
|
+
this.readableStream = readableStream;
|
|
13
|
+
this.reader = this.readableStream.getReader();
|
|
14
|
+
this.events = {
|
|
15
|
+
data: [],
|
|
16
|
+
end: [],
|
|
17
|
+
error: [],
|
|
18
|
+
readable: [],
|
|
19
|
+
close: [],
|
|
20
|
+
pause: [],
|
|
21
|
+
resume: [],
|
|
22
|
+
};
|
|
23
|
+
this.paused = false;
|
|
24
|
+
this.resumeCallback = null;
|
|
25
|
+
this.encoding = null;
|
|
26
|
+
}
|
|
27
|
+
on(event, callback) {
|
|
28
|
+
var _a;
|
|
29
|
+
(_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.push(callback);
|
|
30
|
+
}
|
|
31
|
+
off(event, callback) {
|
|
32
|
+
var _a;
|
|
33
|
+
this.events[event] = (_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.filter((cb) => cb !== callback);
|
|
34
|
+
}
|
|
35
|
+
pipe(dest) {
|
|
36
|
+
this.on("data", (chunk) => {
|
|
37
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
38
|
+
dest._write(chunk);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const writer = dest.getWriter();
|
|
42
|
+
writer.write(chunk).then(() => writer.releaseLock());
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.on("end", () => {
|
|
46
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
47
|
+
dest._end();
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const writer = dest.getWriter();
|
|
51
|
+
writer.close();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
this.on("error", (error) => {
|
|
55
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
56
|
+
dest._error(error);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const writer = dest.getWriter();
|
|
60
|
+
writer.abort(error);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
this._startReading();
|
|
64
|
+
return dest;
|
|
65
|
+
}
|
|
66
|
+
pipeTo(dest) {
|
|
67
|
+
return this.pipe(dest);
|
|
68
|
+
}
|
|
69
|
+
unpipe(dest) {
|
|
70
|
+
this.off("data", (chunk) => {
|
|
71
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
72
|
+
dest._write(chunk);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const writer = dest.getWriter();
|
|
76
|
+
writer.write(chunk).then(() => writer.releaseLock());
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
this.off("end", () => {
|
|
80
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
81
|
+
dest._end();
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const writer = dest.getWriter();
|
|
85
|
+
writer.close();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
this.off("error", (error) => {
|
|
89
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
90
|
+
dest._error(error);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const writer = dest.getWriter();
|
|
94
|
+
writer.abort(error);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
destroy(error) {
|
|
99
|
+
this.reader
|
|
100
|
+
.cancel(error)
|
|
101
|
+
.then(() => {
|
|
102
|
+
this._emit("close");
|
|
103
|
+
})
|
|
104
|
+
.catch((err) => {
|
|
105
|
+
this._emit("error", err);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
pause() {
|
|
109
|
+
this.paused = true;
|
|
110
|
+
this._emit("pause");
|
|
111
|
+
}
|
|
112
|
+
resume() {
|
|
113
|
+
if (this.paused) {
|
|
114
|
+
this.paused = false;
|
|
115
|
+
this._emit("resume");
|
|
116
|
+
if (this.resumeCallback) {
|
|
117
|
+
this.resumeCallback();
|
|
118
|
+
this.resumeCallback = null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
get isPaused() {
|
|
123
|
+
return this.paused;
|
|
124
|
+
}
|
|
125
|
+
read() {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
if (this.paused) {
|
|
128
|
+
yield new Promise((resolve) => {
|
|
129
|
+
this.resumeCallback = resolve;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const { done, value } = yield this.reader.read();
|
|
133
|
+
if (done) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
return value;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
setEncoding(encoding) {
|
|
140
|
+
this.encoding = encoding;
|
|
141
|
+
}
|
|
142
|
+
text() {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
const chunks = [];
|
|
145
|
+
while (true) {
|
|
146
|
+
const { done, value } = yield this.reader.read();
|
|
147
|
+
if (done)
|
|
148
|
+
break;
|
|
149
|
+
if (value)
|
|
150
|
+
chunks.push(value);
|
|
151
|
+
}
|
|
152
|
+
const decoder = new TextDecoder(this.encoding || "utf-8");
|
|
153
|
+
return decoder.decode(yield new Blob(chunks).arrayBuffer());
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
json() {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
const text = yield this.text();
|
|
159
|
+
return JSON.parse(text);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
_write(chunk) {
|
|
163
|
+
this._emit("data", chunk);
|
|
164
|
+
}
|
|
165
|
+
_end() {
|
|
166
|
+
this._emit("end");
|
|
167
|
+
}
|
|
168
|
+
_error(error) {
|
|
169
|
+
this._emit("error", error);
|
|
170
|
+
}
|
|
171
|
+
_emit(event, data) {
|
|
172
|
+
if (this.events[event]) {
|
|
173
|
+
for (const callback of this.events[event] || []) {
|
|
174
|
+
callback(data);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
_startReading() {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
try {
|
|
181
|
+
this._emit("readable");
|
|
182
|
+
while (true) {
|
|
183
|
+
if (this.paused) {
|
|
184
|
+
yield new Promise((resolve) => {
|
|
185
|
+
this.resumeCallback = resolve;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
const { done, value } = yield this.reader.read();
|
|
189
|
+
if (done) {
|
|
190
|
+
this._emit("end");
|
|
191
|
+
this._emit("close");
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
if (value) {
|
|
195
|
+
this._emit("data", value);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
this._emit("error", error);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare type EventCallback = (data?: any) => void;
|
|
2
|
+
export interface StreamWrapper<WritableStream, ReadFormat> {
|
|
3
|
+
setEncoding(encoding?: string): void;
|
|
4
|
+
on(event: string, callback: EventCallback): void;
|
|
5
|
+
off(event: string, callback: EventCallback): void;
|
|
6
|
+
pipe(dest: WritableStream): WritableStream;
|
|
7
|
+
pipeTo(dest: WritableStream): WritableStream;
|
|
8
|
+
unpipe(dest?: WritableStream): void;
|
|
9
|
+
destroy(error?: Error): void;
|
|
10
|
+
pause(): void;
|
|
11
|
+
resume(): void;
|
|
12
|
+
get isPaused(): boolean;
|
|
13
|
+
read(): Promise<ReadFormat | undefined>;
|
|
14
|
+
text(): Promise<string>;
|
|
15
|
+
json<T>(): Promise<T>;
|
|
16
|
+
}
|
|
17
|
+
export declare function chooseStreamWrapper(responseBody: any): Promise<Promise<StreamWrapper<any, any>>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { RUNTIME } from "../../runtime";
|
|
11
|
+
export function chooseStreamWrapper(responseBody) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) {
|
|
14
|
+
return new (yield import("./Node18UniversalStreamWrapper")).Node18UniversalStreamWrapper(responseBody);
|
|
15
|
+
}
|
|
16
|
+
else if (RUNTIME.type !== "node" && typeof fetch == "function") {
|
|
17
|
+
return new (yield import("./UndiciStreamWrapper")).UndiciStreamWrapper(responseBody);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return new (yield import("./NodePre18StreamWrapper")).NodePre18StreamWrapper(responseBody);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|