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

realm / realm-js / 4957253461

12 May 2023 09:22AM UTC coverage: 85.493%. First build
4957253461

push

github

Kenneth Geisshirt
Add more testing of IN operator

821 of 1026 branches covered (80.02%)

Branch coverage included in aggregate %.

2208 of 2517 relevant lines covered (87.72%)

740.5 hits per line

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

53.33
/packages/realm/src/binding.ts
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2022 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 { IndexSet, Int64, ObjKey, Timestamp } from "../generated/ts/native.mjs";
20

21
/** @internal */
22
export * from "../generated/ts/native.mjs"; // core types are transitively exported.
23

24
/** @internal */
25
declare module "../generated/ts/native.mjs" {
26
  interface IndexSet {
27
    asIndexes(): Iterator<number>;
28
  }
29
  interface Timestamp {
30
    toDate(): Date;
31
  }
32
  // eslint-disable-next-line @typescript-eslint/no-namespace
33
  namespace Timestamp {
34
    export function fromDate(d: Date): Timestamp;
35
  }
36
}
37

38
IndexSet.prototype.asIndexes = function* (this: IndexSet) {
1✔
39
  for (const [from, to] of this) {
×
40
    let i = from;
×
41
    while (i < to) {
×
42
      yield i;
×
43
      i++;
×
44
    }
45
  }
46
};
47

48
Timestamp.fromDate = (d: Date) =>
1✔
49
  Timestamp.make(Int64.numToInt(Math.floor(d.valueOf() / 1000)), (d.valueOf() % 1000) * 1000_000);
318✔
50

51
Timestamp.prototype.toDate = function () {
1✔
52
  return new Date(Number(this.seconds) * 1000 + this.nanoseconds / 1000_000);
63✔
53
};
54

55
/** @internal */
56
export class InvalidObjKey extends TypeError {
57
  constructor(input: string) {
58
    super(`Cannot convert '${input}' to an ObjKey`);
×
59
  }
60
}
61

62
/** @internal */
63
export function stringToObjKey(input: string): ObjKey {
64
  try {
3✔
65
    return Int64.strToInt(input) as unknown as ObjKey;
3✔
66
  } catch {
67
    throw new InvalidObjKey(input);
×
68
  }
69
}
70

71
/** @internal */
72
export function isEmptyObjKey(objKey: ObjKey) {
73
  // This relies on the JS representation of an ObjKey being a bigint
74
  return Int64.equals(objKey as unknown as Int64, -1);
37✔
75
}
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