• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-js / 7681391482

27 Jan 2024 10:00PM CUT coverage: 85.346%. Remained the same
7681391482

Pull #6431

github

web-flow
Update source-map-loader to version 5.0.0
Pull Request #6431: Update source-map-loader 4.0.2 → 5.0.0 (major)

942 of 1164 branches covered (0.0%)

Branch coverage included in aggregate %.

2372 of 2719 relevant lines covered (87.24%)

1015.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.13
/packages/realm/src/async-iterator-from-response.ts
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2024 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
import { Response } from "@realm/fetch";
20

21
// Falling back on a known string used in code transpiled by Babel
22
const asyncIteratorSymbol: typeof Symbol.asyncIterator = Symbol.asyncIterator || "@@asyncIterator";
1!
23

24
/** @internal */
25
export function asyncIteratorFromResponse({ body }: Response): AsyncIterable<Uint8Array> {
26
  if (typeof body !== "object" || body === null) {
3!
27
    throw new Error("Expected a non-null object");
×
28
  } else if (Symbol.asyncIterator in body) {
3!
29
    return body as AsyncIterable<Uint8Array>;
3✔
30
  } else if ("getReader" in body) {
×
31
    return {
×
32
      [asyncIteratorSymbol]() {
33
        const reader = body.getReader();
×
34
        return {
×
35
          async next() {
36
            const { done, value } = await reader.read();
×
37
            if (done) {
×
38
              // TODO: Simply return the result once https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1676 is merged and released
39
              return { done, value: undefined };
×
40
            } else if (value instanceof Uint8Array) {
×
41
              return { done, value };
×
42
            } else {
43
              throw new Error("Expected value to be Uint8Array");
×
44
            }
45
          },
46
          async return() {
47
            await reader.cancel();
×
48
            return { done: true, value: null };
×
49
          },
50
        };
51
      },
52
    };
53
  } else {
54
    throw new Error("Expected an AsyncIterable or a ReadableStream");
×
55
  }
56
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc