@markupai/api 0.0.6
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 +40 -0
- package/Client.js +32 -0
- package/LICENSE +201 -0
- package/README.md +165 -0
- package/api/errors/ContentTooLargeError.d.ts +8 -0
- package/api/errors/ContentTooLargeError.js +52 -0
- package/api/errors/ForbiddenError.d.ts +9 -0
- package/api/errors/ForbiddenError.js +52 -0
- package/api/errors/InternalServerError.d.ts +9 -0
- package/api/errors/InternalServerError.js +52 -0
- package/api/errors/NotFoundError.d.ts +9 -0
- package/api/errors/NotFoundError.js +52 -0
- package/api/errors/UnprocessableEntityError.d.ts +8 -0
- package/api/errors/UnprocessableEntityError.js +52 -0
- package/api/errors/index.d.ts +5 -0
- package/api/errors/index.js +21 -0
- package/api/index.d.ts +3 -0
- package/api/index.js +19 -0
- package/api/resources/index.d.ts +8 -0
- package/api/resources/index.js +47 -0
- package/api/resources/styleChecks/client/Client.d.ts +70 -0
- package/api/resources/styleChecks/client/Client.js +215 -0
- package/api/resources/styleChecks/client/index.d.ts +1 -0
- package/api/resources/styleChecks/client/index.js +17 -0
- package/api/resources/styleChecks/client/requests/StyleChecksCreateStyleCheckRequest.d.ts +22 -0
- package/api/resources/styleChecks/client/requests/StyleChecksCreateStyleCheckRequest.js +5 -0
- package/api/resources/styleChecks/client/requests/index.d.ts +1 -0
- package/api/resources/styleChecks/client/requests/index.js +2 -0
- package/api/resources/styleChecks/index.d.ts +1 -0
- package/api/resources/styleChecks/index.js +17 -0
- package/api/resources/styleGuides/client/Client.d.ts +109 -0
- package/api/resources/styleGuides/client/Client.js +394 -0
- package/api/resources/styleGuides/client/index.d.ts +1 -0
- package/api/resources/styleGuides/client/index.js +17 -0
- package/api/resources/styleGuides/client/requests/BodyStyleGuidesUpdateStyleGuide.d.ts +13 -0
- package/api/resources/styleGuides/client/requests/BodyStyleGuidesUpdateStyleGuide.js +5 -0
- package/api/resources/styleGuides/client/requests/StyleGuideRequestBody.d.ts +11 -0
- package/api/resources/styleGuides/client/requests/StyleGuideRequestBody.js +5 -0
- package/api/resources/styleGuides/client/requests/index.d.ts +2 -0
- package/api/resources/styleGuides/client/requests/index.js +2 -0
- package/api/resources/styleGuides/index.d.ts +1 -0
- package/api/resources/styleGuides/index.js +17 -0
- package/api/resources/styleRewrites/client/Client.d.ts +70 -0
- package/api/resources/styleRewrites/client/Client.js +215 -0
- package/api/resources/styleRewrites/client/index.d.ts +1 -0
- package/api/resources/styleRewrites/client/index.js +17 -0
- package/api/resources/styleRewrites/client/requests/StyleRewritesCreateStyleRewriteRequest.d.ts +22 -0
- package/api/resources/styleRewrites/client/requests/StyleRewritesCreateStyleRewriteRequest.js +5 -0
- package/api/resources/styleRewrites/client/requests/index.d.ts +1 -0
- package/api/resources/styleRewrites/client/requests/index.js +2 -0
- package/api/resources/styleRewrites/index.d.ts +1 -0
- package/api/resources/styleRewrites/index.js +17 -0
- package/api/resources/styleSuggestions/client/Client.d.ts +70 -0
- package/api/resources/styleSuggestions/client/Client.js +215 -0
- package/api/resources/styleSuggestions/client/index.d.ts +1 -0
- package/api/resources/styleSuggestions/client/index.js +17 -0
- package/api/resources/styleSuggestions/client/requests/StyleSuggestionsCreateStyleSuggestionRequest.d.ts +22 -0
- package/api/resources/styleSuggestions/client/requests/StyleSuggestionsCreateStyleSuggestionRequest.js +5 -0
- package/api/resources/styleSuggestions/client/requests/index.d.ts +1 -0
- package/api/resources/styleSuggestions/client/requests/index.js +2 -0
- package/api/resources/styleSuggestions/index.d.ts +1 -0
- package/api/resources/styleSuggestions/index.js +17 -0
- package/api/types/CheckOptions.d.ts +9 -0
- package/api/types/CheckOptions.js +5 -0
- package/api/types/ClarityScore.d.ts +14 -0
- package/api/types/ClarityScore.js +5 -0
- package/api/types/Dialects.d.ts +9 -0
- package/api/types/Dialects.js +11 -0
- package/api/types/ErrorResponse.d.ts +11 -0
- package/api/types/ErrorResponse.js +5 -0
- package/api/types/GrammarCategory.d.ts +13 -0
- package/api/types/GrammarCategory.js +15 -0
- package/api/types/GrammarScore.d.ts +7 -0
- package/api/types/GrammarScore.js +5 -0
- package/api/types/Issue.d.ts +13 -0
- package/api/types/Issue.js +5 -0
- package/api/types/IssueCategory.d.ts +13 -0
- package/api/types/IssueCategory.js +15 -0
- package/api/types/QualityScore.d.ts +6 -0
- package/api/types/QualityScore.js +5 -0
- package/api/types/RewriteResponse.d.ts +15 -0
- package/api/types/RewriteResponse.js +5 -0
- package/api/types/ScoreOutput.d.ts +12 -0
- package/api/types/ScoreOutput.js +5 -0
- package/api/types/SentenceLengthCategory.d.ts +13 -0
- package/api/types/SentenceLengthCategory.js +15 -0
- package/api/types/SentenceStructureCategory.d.ts +14 -0
- package/api/types/SentenceStructureCategory.js +16 -0
- package/api/types/SimpleVocabCategory.d.ts +8 -0
- package/api/types/SimpleVocabCategory.js +10 -0
- package/api/types/StyleCheckResponse.d.ts +13 -0
- package/api/types/StyleCheckResponse.js +5 -0
- package/api/types/StyleGuide.d.ts +10 -0
- package/api/types/StyleGuide.js +5 -0
- package/api/types/StyleGuideCategory.d.ts +15 -0
- package/api/types/StyleGuideCategory.js +17 -0
- package/api/types/StyleGuideResponse.d.ts +19 -0
- package/api/types/StyleGuideResponse.js +5 -0
- package/api/types/StyleGuideScore.d.ts +7 -0
- package/api/types/StyleGuideScore.js +5 -0
- package/api/types/StyleGuideStatus.d.ts +10 -0
- package/api/types/StyleGuideStatus.js +12 -0
- package/api/types/StyleGuides.d.ts +11 -0
- package/api/types/StyleGuides.js +13 -0
- package/api/types/Subcategory.d.ts +8 -0
- package/api/types/Subcategory.js +5 -0
- package/api/types/Suggestion.d.ts +14 -0
- package/api/types/Suggestion.js +5 -0
- package/api/types/SuggestionResponse.d.ts +13 -0
- package/api/types/SuggestionResponse.js +5 -0
- package/api/types/TermReplaceCategory.d.ts +8 -0
- package/api/types/TermReplaceCategory.js +10 -0
- package/api/types/TerminologyScore.d.ts +7 -0
- package/api/types/TerminologyScore.js +5 -0
- package/api/types/ToneCategory.d.ts +12 -0
- package/api/types/ToneCategory.js +14 -0
- package/api/types/ToneScore.d.ts +12 -0
- package/api/types/ToneScore.js +5 -0
- package/api/types/Tones.d.ts +12 -0
- package/api/types/Tones.js +14 -0
- package/api/types/WebhookResponse.d.ts +7 -0
- package/api/types/WebhookResponse.js +5 -0
- package/api/types/WorkflowResponse.d.ts +8 -0
- package/api/types/WorkflowResponse.js +5 -0
- package/api/types/WorkflowStatus.d.ts +10 -0
- package/api/types/WorkflowStatus.js +12 -0
- package/api/types/index.d.ts +32 -0
- package/api/types/index.js +48 -0
- package/core/auth/BasicAuth.d.ts +8 -0
- package/core/auth/BasicAuth.js +26 -0
- package/core/auth/BearerToken.d.ts +5 -0
- package/core/auth/BearerToken.js +15 -0
- package/core/auth/index.d.ts +2 -0
- package/core/auth/index.js +7 -0
- package/core/fetcher/APIResponse.d.ts +20 -0
- package/core/fetcher/APIResponse.js +2 -0
- package/core/fetcher/Fetcher.d.ts +39 -0
- package/core/fetcher/Fetcher.js +107 -0
- package/core/fetcher/Headers.d.ts +2 -0
- package/core/fetcher/Headers.js +84 -0
- package/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/core/fetcher/HttpResponsePromise.js +103 -0
- package/core/fetcher/RawResponse.d.ts +29 -0
- package/core/fetcher/RawResponse.js +44 -0
- package/core/fetcher/Supplier.d.ts +4 -0
- package/core/fetcher/Supplier.js +22 -0
- package/core/fetcher/createRequestUrl.d.ts +1 -0
- package/core/fetcher/createRequestUrl.js +12 -0
- package/core/fetcher/getFetchFn.d.ts +4 -0
- package/core/fetcher/getFetchFn.js +68 -0
- package/core/fetcher/getHeader.d.ts +1 -0
- package/core/fetcher/getHeader.js +11 -0
- package/core/fetcher/getRequestBody.d.ts +7 -0
- package/core/fetcher/getRequestBody.js +23 -0
- package/core/fetcher/getResponseBody.d.ts +1 -0
- package/core/fetcher/getResponseBody.js +54 -0
- package/core/fetcher/index.d.ts +8 -0
- package/core/fetcher/index.js +15 -0
- package/core/fetcher/makeRequest.d.ts +1 -0
- package/core/fetcher/makeRequest.js +42 -0
- package/core/fetcher/requestWithRetries.d.ts +1 -0
- package/core/fetcher/requestWithRetries.js +40 -0
- package/core/fetcher/signals.d.ts +11 -0
- package/core/fetcher/signals.js +36 -0
- package/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.d.ts +30 -0
- package/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.js +247 -0
- package/core/fetcher/stream-wrappers/NodePre18StreamWrapper.d.ts +21 -0
- package/core/fetcher/stream-wrappers/NodePre18StreamWrapper.js +126 -0
- package/core/fetcher/stream-wrappers/UndiciStreamWrapper.d.ts +31 -0
- package/core/fetcher/stream-wrappers/UndiciStreamWrapper.js +229 -0
- package/core/fetcher/stream-wrappers/chooseStreamWrapper.d.ts +18 -0
- package/core/fetcher/stream-wrappers/chooseStreamWrapper.js +59 -0
- package/core/form-data-utils/FormDataWrapper.d.ts +63 -0
- package/core/form-data-utils/FormDataWrapper.js +227 -0
- package/core/form-data-utils/encodeAsFormParameter.d.ts +4 -0
- package/core/form-data-utils/encodeAsFormParameter.js +18 -0
- package/core/form-data-utils/index.d.ts +2 -0
- package/core/form-data-utils/index.js +20 -0
- package/core/index.d.ts +4 -0
- package/core/index.js +20 -0
- package/core/json.d.ts +15 -0
- package/core/json.js +24 -0
- package/core/runtime/index.d.ts +1 -0
- package/core/runtime/index.js +5 -0
- package/core/runtime/runtime.d.ts +9 -0
- package/core/runtime/runtime.js +103 -0
- package/dist/Client.d.ts +40 -0
- package/dist/Client.js +32 -0
- package/dist/api/errors/ContentTooLargeError.d.ts +8 -0
- package/dist/api/errors/ContentTooLargeError.js +52 -0
- package/dist/api/errors/ForbiddenError.d.ts +9 -0
- package/dist/api/errors/ForbiddenError.js +52 -0
- package/dist/api/errors/InternalServerError.d.ts +9 -0
- package/dist/api/errors/InternalServerError.js +52 -0
- package/dist/api/errors/NotFoundError.d.ts +9 -0
- package/dist/api/errors/NotFoundError.js +52 -0
- package/dist/api/errors/UnprocessableEntityError.d.ts +8 -0
- package/dist/api/errors/UnprocessableEntityError.js +52 -0
- package/dist/api/errors/index.d.ts +5 -0
- package/dist/api/errors/index.js +21 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +19 -0
- package/dist/api/resources/index.d.ts +8 -0
- package/dist/api/resources/index.js +47 -0
- package/dist/api/resources/styleChecks/client/Client.d.ts +70 -0
- package/dist/api/resources/styleChecks/client/Client.js +215 -0
- package/dist/api/resources/styleChecks/client/index.d.ts +1 -0
- package/dist/api/resources/styleChecks/client/index.js +17 -0
- package/dist/api/resources/styleChecks/client/requests/StyleChecksCreateStyleCheckRequest.d.ts +22 -0
- package/dist/api/resources/styleChecks/client/requests/StyleChecksCreateStyleCheckRequest.js +5 -0
- package/dist/api/resources/styleChecks/client/requests/index.d.ts +1 -0
- package/dist/api/resources/styleChecks/client/requests/index.js +2 -0
- package/dist/api/resources/styleChecks/index.d.ts +1 -0
- package/dist/api/resources/styleChecks/index.js +17 -0
- package/dist/api/resources/styleGuides/client/Client.d.ts +109 -0
- package/dist/api/resources/styleGuides/client/Client.js +394 -0
- package/dist/api/resources/styleGuides/client/index.d.ts +1 -0
- package/dist/api/resources/styleGuides/client/index.js +17 -0
- package/dist/api/resources/styleGuides/client/requests/BodyStyleGuidesUpdateStyleGuide.d.ts +13 -0
- package/dist/api/resources/styleGuides/client/requests/BodyStyleGuidesUpdateStyleGuide.js +5 -0
- package/dist/api/resources/styleGuides/client/requests/StyleGuideRequestBody.d.ts +11 -0
- package/dist/api/resources/styleGuides/client/requests/StyleGuideRequestBody.js +5 -0
- package/dist/api/resources/styleGuides/client/requests/index.d.ts +2 -0
- package/dist/api/resources/styleGuides/client/requests/index.js +2 -0
- package/dist/api/resources/styleGuides/index.d.ts +1 -0
- package/dist/api/resources/styleGuides/index.js +17 -0
- package/dist/api/resources/styleRewrites/client/Client.d.ts +70 -0
- package/dist/api/resources/styleRewrites/client/Client.js +215 -0
- package/dist/api/resources/styleRewrites/client/index.d.ts +1 -0
- package/dist/api/resources/styleRewrites/client/index.js +17 -0
- package/dist/api/resources/styleRewrites/client/requests/StyleRewritesCreateStyleRewriteRequest.d.ts +22 -0
- package/dist/api/resources/styleRewrites/client/requests/StyleRewritesCreateStyleRewriteRequest.js +5 -0
- package/dist/api/resources/styleRewrites/client/requests/index.d.ts +1 -0
- package/dist/api/resources/styleRewrites/client/requests/index.js +2 -0
- package/dist/api/resources/styleRewrites/index.d.ts +1 -0
- package/dist/api/resources/styleRewrites/index.js +17 -0
- package/dist/api/resources/styleSuggestions/client/Client.d.ts +70 -0
- package/dist/api/resources/styleSuggestions/client/Client.js +215 -0
- package/dist/api/resources/styleSuggestions/client/index.d.ts +1 -0
- package/dist/api/resources/styleSuggestions/client/index.js +17 -0
- package/dist/api/resources/styleSuggestions/client/requests/StyleSuggestionsCreateStyleSuggestionRequest.d.ts +22 -0
- package/dist/api/resources/styleSuggestions/client/requests/StyleSuggestionsCreateStyleSuggestionRequest.js +5 -0
- package/dist/api/resources/styleSuggestions/client/requests/index.d.ts +1 -0
- package/dist/api/resources/styleSuggestions/client/requests/index.js +2 -0
- package/dist/api/resources/styleSuggestions/index.d.ts +1 -0
- package/dist/api/resources/styleSuggestions/index.js +17 -0
- package/dist/api/types/CheckOptions.d.ts +9 -0
- package/dist/api/types/CheckOptions.js +5 -0
- package/dist/api/types/ClarityScore.d.ts +14 -0
- package/dist/api/types/ClarityScore.js +5 -0
- package/dist/api/types/Dialects.d.ts +9 -0
- package/dist/api/types/Dialects.js +11 -0
- package/dist/api/types/ErrorResponse.d.ts +11 -0
- package/dist/api/types/ErrorResponse.js +5 -0
- package/dist/api/types/GrammarCategory.d.ts +13 -0
- package/dist/api/types/GrammarCategory.js +15 -0
- package/dist/api/types/GrammarScore.d.ts +7 -0
- package/dist/api/types/GrammarScore.js +5 -0
- package/dist/api/types/Issue.d.ts +13 -0
- package/dist/api/types/Issue.js +5 -0
- package/dist/api/types/IssueCategory.d.ts +13 -0
- package/dist/api/types/IssueCategory.js +15 -0
- package/dist/api/types/QualityScore.d.ts +6 -0
- package/dist/api/types/QualityScore.js +5 -0
- package/dist/api/types/RewriteResponse.d.ts +15 -0
- package/dist/api/types/RewriteResponse.js +5 -0
- package/dist/api/types/ScoreOutput.d.ts +12 -0
- package/dist/api/types/ScoreOutput.js +5 -0
- package/dist/api/types/SentenceLengthCategory.d.ts +13 -0
- package/dist/api/types/SentenceLengthCategory.js +15 -0
- package/dist/api/types/SentenceStructureCategory.d.ts +14 -0
- package/dist/api/types/SentenceStructureCategory.js +16 -0
- package/dist/api/types/SimpleVocabCategory.d.ts +8 -0
- package/dist/api/types/SimpleVocabCategory.js +10 -0
- package/dist/api/types/StyleCheckResponse.d.ts +13 -0
- package/dist/api/types/StyleCheckResponse.js +5 -0
- package/dist/api/types/StyleGuide.d.ts +10 -0
- package/dist/api/types/StyleGuide.js +5 -0
- package/dist/api/types/StyleGuideCategory.d.ts +15 -0
- package/dist/api/types/StyleGuideCategory.js +17 -0
- package/dist/api/types/StyleGuideResponse.d.ts +19 -0
- package/dist/api/types/StyleGuideResponse.js +5 -0
- package/dist/api/types/StyleGuideScore.d.ts +7 -0
- package/dist/api/types/StyleGuideScore.js +5 -0
- package/dist/api/types/StyleGuideStatus.d.ts +10 -0
- package/dist/api/types/StyleGuideStatus.js +12 -0
- package/dist/api/types/StyleGuides.d.ts +11 -0
- package/dist/api/types/StyleGuides.js +13 -0
- package/dist/api/types/Subcategory.d.ts +8 -0
- package/dist/api/types/Subcategory.js +5 -0
- package/dist/api/types/Suggestion.d.ts +14 -0
- package/dist/api/types/Suggestion.js +5 -0
- package/dist/api/types/SuggestionResponse.d.ts +13 -0
- package/dist/api/types/SuggestionResponse.js +5 -0
- package/dist/api/types/TermReplaceCategory.d.ts +8 -0
- package/dist/api/types/TermReplaceCategory.js +10 -0
- package/dist/api/types/TerminologyScore.d.ts +7 -0
- package/dist/api/types/TerminologyScore.js +5 -0
- package/dist/api/types/ToneCategory.d.ts +12 -0
- package/dist/api/types/ToneCategory.js +14 -0
- package/dist/api/types/ToneScore.d.ts +12 -0
- package/dist/api/types/ToneScore.js +5 -0
- package/dist/api/types/Tones.d.ts +12 -0
- package/dist/api/types/Tones.js +14 -0
- package/dist/api/types/WebhookResponse.d.ts +7 -0
- package/dist/api/types/WebhookResponse.js +5 -0
- package/dist/api/types/WorkflowResponse.d.ts +8 -0
- package/dist/api/types/WorkflowResponse.js +5 -0
- package/dist/api/types/WorkflowStatus.d.ts +10 -0
- package/dist/api/types/WorkflowStatus.js +12 -0
- package/dist/api/types/index.d.ts +32 -0
- package/dist/api/types/index.js +48 -0
- package/dist/core/auth/BasicAuth.d.ts +8 -0
- package/dist/core/auth/BasicAuth.js +26 -0
- package/dist/core/auth/BearerToken.d.ts +5 -0
- package/dist/core/auth/BearerToken.js +15 -0
- package/dist/core/auth/index.d.ts +2 -0
- package/dist/core/auth/index.js +7 -0
- package/dist/core/fetcher/APIResponse.d.ts +20 -0
- package/dist/core/fetcher/APIResponse.js +2 -0
- package/dist/core/fetcher/Fetcher.d.ts +39 -0
- package/dist/core/fetcher/Fetcher.js +107 -0
- package/dist/core/fetcher/Headers.d.ts +2 -0
- package/dist/core/fetcher/Headers.js +84 -0
- package/dist/core/fetcher/HttpResponsePromise.d.ts +58 -0
- package/dist/core/fetcher/HttpResponsePromise.js +103 -0
- package/dist/core/fetcher/RawResponse.d.ts +29 -0
- package/dist/core/fetcher/RawResponse.js +44 -0
- package/dist/core/fetcher/Supplier.d.ts +4 -0
- package/dist/core/fetcher/Supplier.js +22 -0
- package/dist/core/fetcher/createRequestUrl.d.ts +1 -0
- package/dist/core/fetcher/createRequestUrl.js +12 -0
- package/dist/core/fetcher/getFetchFn.d.ts +4 -0
- package/dist/core/fetcher/getFetchFn.js +68 -0
- package/dist/core/fetcher/getHeader.d.ts +1 -0
- package/dist/core/fetcher/getHeader.js +11 -0
- package/dist/core/fetcher/getRequestBody.d.ts +7 -0
- package/dist/core/fetcher/getRequestBody.js +23 -0
- package/dist/core/fetcher/getResponseBody.d.ts +1 -0
- package/dist/core/fetcher/getResponseBody.js +54 -0
- package/dist/core/fetcher/index.d.ts +8 -0
- package/dist/core/fetcher/index.js +15 -0
- package/dist/core/fetcher/makeRequest.d.ts +1 -0
- package/dist/core/fetcher/makeRequest.js +42 -0
- package/dist/core/fetcher/requestWithRetries.d.ts +1 -0
- package/dist/core/fetcher/requestWithRetries.js +40 -0
- package/dist/core/fetcher/signals.d.ts +11 -0
- package/dist/core/fetcher/signals.js +36 -0
- package/dist/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.d.ts +30 -0
- package/dist/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.js +247 -0
- package/dist/core/fetcher/stream-wrappers/NodePre18StreamWrapper.d.ts +21 -0
- package/dist/core/fetcher/stream-wrappers/NodePre18StreamWrapper.js +126 -0
- package/dist/core/fetcher/stream-wrappers/UndiciStreamWrapper.d.ts +31 -0
- package/dist/core/fetcher/stream-wrappers/UndiciStreamWrapper.js +229 -0
- package/dist/core/fetcher/stream-wrappers/chooseStreamWrapper.d.ts +18 -0
- package/dist/core/fetcher/stream-wrappers/chooseStreamWrapper.js +59 -0
- package/dist/core/form-data-utils/FormDataWrapper.d.ts +63 -0
- package/dist/core/form-data-utils/FormDataWrapper.js +227 -0
- package/dist/core/form-data-utils/encodeAsFormParameter.d.ts +4 -0
- package/dist/core/form-data-utils/encodeAsFormParameter.js +18 -0
- package/dist/core/form-data-utils/index.d.ts +2 -0
- package/dist/core/form-data-utils/index.js +20 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +20 -0
- package/dist/core/json.d.ts +15 -0
- package/dist/core/json.js +24 -0
- package/dist/core/runtime/index.d.ts +1 -0
- package/dist/core/runtime/index.js +5 -0
- package/dist/core/runtime/runtime.d.ts +9 -0
- package/dist/core/runtime/runtime.js +103 -0
- package/dist/environments.d.ts +7 -0
- package/dist/environments.js +9 -0
- package/dist/errors/MarkupAIError.d.ts +15 -0
- package/dist/errors/MarkupAIError.js +30 -0
- package/dist/errors/MarkupAITimeoutError.d.ts +6 -0
- package/dist/errors/MarkupAITimeoutError.js +13 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +44 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/environments.d.ts +7 -0
- package/environments.js +9 -0
- package/errors/MarkupAIError.d.ts +15 -0
- package/errors/MarkupAIError.js +30 -0
- package/errors/MarkupAITimeoutError.d.ts +6 -0
- package/errors/MarkupAITimeoutError.js +13 -0
- package/errors/index.d.ts +2 -0
- package/errors/index.js +7 -0
- package/index.d.ts +4 -0
- package/index.js +44 -0
- package/jest.config.mjs +8 -0
- package/package.json +46 -0
- package/reference.md +748 -0
- package/scripts/rename-to-esm-files.js +115 -0
- package/version.d.ts +1 -0
- package/version.js +4 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Node18UniversalStreamWrapper = void 0;
|
|
13
|
+
class Node18UniversalStreamWrapper {
|
|
14
|
+
constructor(readableStream) {
|
|
15
|
+
this.readableStream = readableStream;
|
|
16
|
+
this.reader = this.readableStream.getReader();
|
|
17
|
+
this.events = {
|
|
18
|
+
data: [],
|
|
19
|
+
end: [],
|
|
20
|
+
error: [],
|
|
21
|
+
readable: [],
|
|
22
|
+
close: [],
|
|
23
|
+
pause: [],
|
|
24
|
+
resume: [],
|
|
25
|
+
};
|
|
26
|
+
this.paused = false;
|
|
27
|
+
this.resumeCallback = null;
|
|
28
|
+
this.encoding = null;
|
|
29
|
+
}
|
|
30
|
+
on(event, callback) {
|
|
31
|
+
var _a;
|
|
32
|
+
(_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.push(callback);
|
|
33
|
+
}
|
|
34
|
+
off(event, callback) {
|
|
35
|
+
var _a;
|
|
36
|
+
this.events[event] = (_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.filter((cb) => cb !== callback);
|
|
37
|
+
}
|
|
38
|
+
pipe(dest) {
|
|
39
|
+
this.on("data", (chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
41
|
+
dest._write(chunk);
|
|
42
|
+
}
|
|
43
|
+
else if (dest instanceof WritableStream) {
|
|
44
|
+
const writer = dest.getWriter();
|
|
45
|
+
writer.write(chunk).then(() => writer.releaseLock());
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
dest.write(chunk);
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
this.on("end", () => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
53
|
+
dest._end();
|
|
54
|
+
}
|
|
55
|
+
else if (dest instanceof WritableStream) {
|
|
56
|
+
const writer = dest.getWriter();
|
|
57
|
+
writer.close();
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
dest.end();
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
this.on("error", (error) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
65
|
+
dest._error(error);
|
|
66
|
+
}
|
|
67
|
+
else if (dest instanceof WritableStream) {
|
|
68
|
+
const writer = dest.getWriter();
|
|
69
|
+
writer.abort(error);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
dest.destroy(error);
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
this._startReading();
|
|
76
|
+
return dest;
|
|
77
|
+
}
|
|
78
|
+
pipeTo(dest) {
|
|
79
|
+
return this.pipe(dest);
|
|
80
|
+
}
|
|
81
|
+
unpipe(dest) {
|
|
82
|
+
this.off("data", (chunk) => __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
84
|
+
dest._write(chunk);
|
|
85
|
+
}
|
|
86
|
+
else if (dest instanceof WritableStream) {
|
|
87
|
+
const writer = dest.getWriter();
|
|
88
|
+
writer.write(chunk).then(() => writer.releaseLock());
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
dest.write(chunk);
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
this.off("end", () => __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
96
|
+
dest._end();
|
|
97
|
+
}
|
|
98
|
+
else if (dest instanceof WritableStream) {
|
|
99
|
+
const writer = dest.getWriter();
|
|
100
|
+
writer.close();
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
dest.end();
|
|
104
|
+
}
|
|
105
|
+
}));
|
|
106
|
+
this.off("error", (error) => __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
if (dest instanceof Node18UniversalStreamWrapper) {
|
|
108
|
+
dest._error(error);
|
|
109
|
+
}
|
|
110
|
+
else if (dest instanceof WritableStream) {
|
|
111
|
+
const writer = dest.getWriter();
|
|
112
|
+
writer.abort(error);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
dest.destroy(error);
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
destroy(error) {
|
|
120
|
+
this.reader
|
|
121
|
+
.cancel(error)
|
|
122
|
+
.then(() => {
|
|
123
|
+
this._emit("close");
|
|
124
|
+
})
|
|
125
|
+
.catch((err) => {
|
|
126
|
+
this._emit("error", err);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
pause() {
|
|
130
|
+
this.paused = true;
|
|
131
|
+
this._emit("pause");
|
|
132
|
+
}
|
|
133
|
+
resume() {
|
|
134
|
+
if (this.paused) {
|
|
135
|
+
this.paused = false;
|
|
136
|
+
this._emit("resume");
|
|
137
|
+
if (this.resumeCallback) {
|
|
138
|
+
this.resumeCallback();
|
|
139
|
+
this.resumeCallback = null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
get isPaused() {
|
|
144
|
+
return this.paused;
|
|
145
|
+
}
|
|
146
|
+
read() {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
if (this.paused) {
|
|
149
|
+
yield new Promise((resolve) => {
|
|
150
|
+
this.resumeCallback = resolve;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const { done, value } = yield this.reader.read();
|
|
154
|
+
if (done) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
return value;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
setEncoding(encoding) {
|
|
161
|
+
this.encoding = encoding;
|
|
162
|
+
}
|
|
163
|
+
text() {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
const chunks = [];
|
|
166
|
+
while (true) {
|
|
167
|
+
const { done, value } = yield this.reader.read();
|
|
168
|
+
if (done) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
if (value) {
|
|
172
|
+
chunks.push(value);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const decoder = new TextDecoder(this.encoding || "utf-8");
|
|
176
|
+
return decoder.decode(yield new Blob(chunks).arrayBuffer());
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
json() {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const text = yield this.text();
|
|
182
|
+
return JSON.parse(text);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
_write(chunk) {
|
|
186
|
+
this._emit("data", chunk);
|
|
187
|
+
}
|
|
188
|
+
_end() {
|
|
189
|
+
this._emit("end");
|
|
190
|
+
}
|
|
191
|
+
_error(error) {
|
|
192
|
+
this._emit("error", error);
|
|
193
|
+
}
|
|
194
|
+
_emit(event, data) {
|
|
195
|
+
if (this.events[event]) {
|
|
196
|
+
for (const callback of this.events[event] || []) {
|
|
197
|
+
callback(data);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
_startReading() {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
try {
|
|
204
|
+
this._emit("readable");
|
|
205
|
+
while (true) {
|
|
206
|
+
if (this.paused) {
|
|
207
|
+
yield new Promise((resolve) => {
|
|
208
|
+
this.resumeCallback = resolve;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const { done, value } = yield this.reader.read();
|
|
212
|
+
if (done) {
|
|
213
|
+
this._emit("end");
|
|
214
|
+
this._emit("close");
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
if (value) {
|
|
218
|
+
this._emit("data", value);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
this._emit("error", error);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
[Symbol.asyncIterator]() {
|
|
228
|
+
return {
|
|
229
|
+
next: () => __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
if (this.paused) {
|
|
231
|
+
yield new Promise((resolve) => {
|
|
232
|
+
this.resumeCallback = resolve;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
const { done, value } = yield this.reader.read();
|
|
236
|
+
if (done) {
|
|
237
|
+
return { done: true, value: undefined };
|
|
238
|
+
}
|
|
239
|
+
return { done: false, value };
|
|
240
|
+
}),
|
|
241
|
+
[Symbol.asyncIterator]() {
|
|
242
|
+
return this;
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.Node18UniversalStreamWrapper = Node18UniversalStreamWrapper;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Readable, Writable } from "readable-stream";
|
|
2
|
+
import { EventCallback, StreamWrapper } from "./chooseStreamWrapper";
|
|
3
|
+
export declare class NodePre18StreamWrapper implements StreamWrapper<Writable, Buffer> {
|
|
4
|
+
private readableStream;
|
|
5
|
+
private encoding;
|
|
6
|
+
constructor(readableStream: Readable);
|
|
7
|
+
on(event: string, callback: EventCallback): void;
|
|
8
|
+
off(event: string, callback: EventCallback): void;
|
|
9
|
+
pipe(dest: Writable): Writable;
|
|
10
|
+
pipeTo(dest: Writable): Writable;
|
|
11
|
+
unpipe(dest?: Writable): void;
|
|
12
|
+
destroy(error?: Error): void;
|
|
13
|
+
pause(): void;
|
|
14
|
+
resume(): void;
|
|
15
|
+
get isPaused(): boolean;
|
|
16
|
+
read(): Promise<Buffer | undefined>;
|
|
17
|
+
setEncoding(encoding?: string): void;
|
|
18
|
+
text(): Promise<string>;
|
|
19
|
+
json<T>(): Promise<T>;
|
|
20
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Buffer>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
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);
|
|
15
|
+
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); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.NodePre18StreamWrapper = void 0;
|
|
20
|
+
class NodePre18StreamWrapper {
|
|
21
|
+
constructor(readableStream) {
|
|
22
|
+
this.readableStream = readableStream;
|
|
23
|
+
}
|
|
24
|
+
on(event, callback) {
|
|
25
|
+
this.readableStream.on(event, callback);
|
|
26
|
+
}
|
|
27
|
+
off(event, callback) {
|
|
28
|
+
this.readableStream.off(event, callback);
|
|
29
|
+
}
|
|
30
|
+
pipe(dest) {
|
|
31
|
+
this.readableStream.pipe(dest);
|
|
32
|
+
return dest;
|
|
33
|
+
}
|
|
34
|
+
pipeTo(dest) {
|
|
35
|
+
return this.pipe(dest);
|
|
36
|
+
}
|
|
37
|
+
unpipe(dest) {
|
|
38
|
+
if (dest) {
|
|
39
|
+
this.readableStream.unpipe(dest);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.readableStream.unpipe();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
destroy(error) {
|
|
46
|
+
this.readableStream.destroy(error);
|
|
47
|
+
}
|
|
48
|
+
pause() {
|
|
49
|
+
this.readableStream.pause();
|
|
50
|
+
}
|
|
51
|
+
resume() {
|
|
52
|
+
this.readableStream.resume();
|
|
53
|
+
}
|
|
54
|
+
get isPaused() {
|
|
55
|
+
return this.readableStream.isPaused();
|
|
56
|
+
}
|
|
57
|
+
read() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const chunk = this.readableStream.read();
|
|
61
|
+
if (chunk) {
|
|
62
|
+
resolve(chunk);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.readableStream.once("readable", () => {
|
|
66
|
+
const chunk = this.readableStream.read();
|
|
67
|
+
resolve(chunk);
|
|
68
|
+
});
|
|
69
|
+
this.readableStream.once("error", reject);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
setEncoding(encoding) {
|
|
75
|
+
this.readableStream.setEncoding(encoding);
|
|
76
|
+
this.encoding = encoding;
|
|
77
|
+
}
|
|
78
|
+
text() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
var _a, e_1, _b, _c;
|
|
81
|
+
const chunks = [];
|
|
82
|
+
const encoder = new TextEncoder();
|
|
83
|
+
this.readableStream.setEncoding((this.encoding || "utf-8"));
|
|
84
|
+
try {
|
|
85
|
+
for (var _d = true, _e = __asyncValues(this.readableStream), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
86
|
+
_c = _f.value;
|
|
87
|
+
_d = false;
|
|
88
|
+
const chunk = _c;
|
|
89
|
+
chunks.push(encoder.encode(chunk));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
93
|
+
finally {
|
|
94
|
+
try {
|
|
95
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
96
|
+
}
|
|
97
|
+
finally { if (e_1) throw e_1.error; }
|
|
98
|
+
}
|
|
99
|
+
const decoder = new TextDecoder(this.encoding || "utf-8");
|
|
100
|
+
return decoder.decode(Buffer.concat(chunks));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
json() {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const text = yield this.text();
|
|
106
|
+
return JSON.parse(text);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
[Symbol.asyncIterator]() {
|
|
110
|
+
const readableStream = this.readableStream;
|
|
111
|
+
const iterator = readableStream[Symbol.asyncIterator]();
|
|
112
|
+
// Create and return an async iterator that yields buffers
|
|
113
|
+
return {
|
|
114
|
+
next() {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
const { value, done } = yield iterator.next();
|
|
117
|
+
return { value: value, done };
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
[Symbol.asyncIterator]() {
|
|
121
|
+
return this;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.NodePre18StreamWrapper = NodePre18StreamWrapper;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StreamWrapper } from "./chooseStreamWrapper";
|
|
2
|
+
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): 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
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<ReadFormat>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UndiciStreamWrapper = void 0;
|
|
13
|
+
class UndiciStreamWrapper {
|
|
14
|
+
constructor(readableStream) {
|
|
15
|
+
this.readableStream = readableStream;
|
|
16
|
+
this.reader = this.readableStream.getReader();
|
|
17
|
+
this.events = {
|
|
18
|
+
data: [],
|
|
19
|
+
end: [],
|
|
20
|
+
error: [],
|
|
21
|
+
readable: [],
|
|
22
|
+
close: [],
|
|
23
|
+
pause: [],
|
|
24
|
+
resume: [],
|
|
25
|
+
};
|
|
26
|
+
this.paused = false;
|
|
27
|
+
this.resumeCallback = null;
|
|
28
|
+
this.encoding = null;
|
|
29
|
+
}
|
|
30
|
+
on(event, callback) {
|
|
31
|
+
var _a;
|
|
32
|
+
(_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.push(callback);
|
|
33
|
+
}
|
|
34
|
+
off(event, callback) {
|
|
35
|
+
var _a;
|
|
36
|
+
this.events[event] = (_a = this.events[event]) === null || _a === void 0 ? void 0 : _a.filter((cb) => cb !== callback);
|
|
37
|
+
}
|
|
38
|
+
pipe(dest) {
|
|
39
|
+
this.on("data", (chunk) => {
|
|
40
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
41
|
+
dest._write(chunk);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const writer = dest.getWriter();
|
|
45
|
+
writer.write(chunk).then(() => writer.releaseLock());
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
this.on("end", () => {
|
|
49
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
50
|
+
dest._end();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const writer = dest.getWriter();
|
|
54
|
+
writer.close();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.on("error", (error) => {
|
|
58
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
59
|
+
dest._error(error);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const writer = dest.getWriter();
|
|
63
|
+
writer.abort(error);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
this._startReading();
|
|
67
|
+
return dest;
|
|
68
|
+
}
|
|
69
|
+
pipeTo(dest) {
|
|
70
|
+
return this.pipe(dest);
|
|
71
|
+
}
|
|
72
|
+
unpipe(dest) {
|
|
73
|
+
this.off("data", (chunk) => {
|
|
74
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
75
|
+
dest._write(chunk);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const writer = dest.getWriter();
|
|
79
|
+
writer.write(chunk).then(() => writer.releaseLock());
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this.off("end", () => {
|
|
83
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
84
|
+
dest._end();
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const writer = dest.getWriter();
|
|
88
|
+
writer.close();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
this.off("error", (error) => {
|
|
92
|
+
if (dest instanceof UndiciStreamWrapper) {
|
|
93
|
+
dest._error(error);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const writer = dest.getWriter();
|
|
97
|
+
writer.abort(error);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
destroy(error) {
|
|
102
|
+
this.reader
|
|
103
|
+
.cancel(error)
|
|
104
|
+
.then(() => {
|
|
105
|
+
this._emit("close");
|
|
106
|
+
})
|
|
107
|
+
.catch((err) => {
|
|
108
|
+
this._emit("error", err);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
pause() {
|
|
112
|
+
this.paused = true;
|
|
113
|
+
this._emit("pause");
|
|
114
|
+
}
|
|
115
|
+
resume() {
|
|
116
|
+
if (this.paused) {
|
|
117
|
+
this.paused = false;
|
|
118
|
+
this._emit("resume");
|
|
119
|
+
if (this.resumeCallback) {
|
|
120
|
+
this.resumeCallback();
|
|
121
|
+
this.resumeCallback = null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
get isPaused() {
|
|
126
|
+
return this.paused;
|
|
127
|
+
}
|
|
128
|
+
read() {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
if (this.paused) {
|
|
131
|
+
yield new Promise((resolve) => {
|
|
132
|
+
this.resumeCallback = resolve;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const { done, value } = yield this.reader.read();
|
|
136
|
+
if (done) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
return value;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
setEncoding(encoding) {
|
|
143
|
+
this.encoding = encoding;
|
|
144
|
+
}
|
|
145
|
+
text() {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const chunks = [];
|
|
148
|
+
while (true) {
|
|
149
|
+
const { done, value } = yield this.reader.read();
|
|
150
|
+
if (done) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
if (value) {
|
|
154
|
+
chunks.push(value);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const decoder = new TextDecoder(this.encoding || "utf-8");
|
|
158
|
+
return decoder.decode(yield new Blob(chunks).arrayBuffer());
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
json() {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
const text = yield this.text();
|
|
164
|
+
return JSON.parse(text);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
_write(chunk) {
|
|
168
|
+
this._emit("data", chunk);
|
|
169
|
+
}
|
|
170
|
+
_end() {
|
|
171
|
+
this._emit("end");
|
|
172
|
+
}
|
|
173
|
+
_error(error) {
|
|
174
|
+
this._emit("error", error);
|
|
175
|
+
}
|
|
176
|
+
_emit(event, data) {
|
|
177
|
+
if (this.events[event]) {
|
|
178
|
+
for (const callback of this.events[event] || []) {
|
|
179
|
+
callback(data);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
_startReading() {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
try {
|
|
186
|
+
this._emit("readable");
|
|
187
|
+
while (true) {
|
|
188
|
+
if (this.paused) {
|
|
189
|
+
yield new Promise((resolve) => {
|
|
190
|
+
this.resumeCallback = resolve;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
const { done, value } = yield this.reader.read();
|
|
194
|
+
if (done) {
|
|
195
|
+
this._emit("end");
|
|
196
|
+
this._emit("close");
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
if (value) {
|
|
200
|
+
this._emit("data", value);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
this._emit("error", error);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
[Symbol.asyncIterator]() {
|
|
210
|
+
return {
|
|
211
|
+
next: () => __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
if (this.paused) {
|
|
213
|
+
yield new Promise((resolve) => {
|
|
214
|
+
this.resumeCallback = resolve;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
const { done, value } = yield this.reader.read();
|
|
218
|
+
if (done) {
|
|
219
|
+
return { done: true, value: undefined };
|
|
220
|
+
}
|
|
221
|
+
return { done: false, value };
|
|
222
|
+
}),
|
|
223
|
+
[Symbol.asyncIterator]() {
|
|
224
|
+
return this;
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.UndiciStreamWrapper = UndiciStreamWrapper;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export 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
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<ReadFormat>;
|
|
17
|
+
}
|
|
18
|
+
export declare function chooseStreamWrapper(responseBody: any): Promise<Promise<StreamWrapper<any, any>>>;
|