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

realm / realm-js / 5133612036

31 May 2023 01:41PM UTC coverage: 85.686%. First build
5133612036

push

github

takameyer
Fix warning for deprecated namespace setting method in Android

* Fixes #5646

829 of 1032 branches covered (80.33%)

Branch coverage included in aggregate %.

2218 of 2524 relevant lines covered (87.88%)

744.03 hits per line

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

70.83
/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, SyncSession, Timestamp, WeakSyncSession } from "realm/binding";
20

21
/** @internal */
22
export * from "realm/binding";
23

24
/** @internal */
25
declare module "realm/binding" {
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
  interface SyncSession {
38
    /** Returns a WeakSyncSession and releases the strong reference held by this SyncSession */
39
    weaken(): WeakSyncSession;
40
  }
41

42
  interface WeakSyncSession {
43
    /**
44
     * Similar to WeakRef.deref(), but takes a callback so that the strong reference can be
45
     * automatically released when the callback exists (either by returning or throwing).
46
     * It is not legal to hold on to the SyncSession after this returns because its
47
     * strong reference will have been deleted.
48
     */
49
    withDeref<Ret = void>(callback: (shared: SyncSession | null) => Ret): Ret;
50
  }
51
}
52

53
IndexSet.prototype.asIndexes = function* (this: IndexSet) {
1✔
54
  for (const [from, to] of this) {
×
55
    let i = from;
×
56
    while (i < to) {
×
57
      yield i;
×
58
      i++;
×
59
    }
60
  }
61
};
62

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

66
Timestamp.prototype.toDate = function () {
1✔
67
  return new Date(Number(this.seconds) * 1000 + this.nanoseconds / 1000_000);
63✔
68
};
69

70
SyncSession.prototype.weaken = function () {
1✔
71
  try {
265✔
72
    return WeakSyncSession.weakCopyOf(this);
265✔
73
  } finally {
74
    this.$resetSharedPtr();
265✔
75
  }
76
};
77

78
WeakSyncSession.prototype.withDeref = function <Ret = void>(callback: (shared: SyncSession | null) => Ret) {
1✔
79
  const shared = this.rawDereference();
185✔
80
  try {
185✔
81
    return callback(shared);
185✔
82
  } finally {
83
    shared?.$resetSharedPtr();
185✔
84
  }
85
};
86

87
/** @internal */
88
export class InvalidObjKey extends TypeError {
89
  constructor(input: string) {
90
    super(`Cannot convert '${input}' to an ObjKey`);
×
91
  }
92
}
93

94
/** @internal */
95
export function stringToObjKey(input: string): ObjKey {
96
  try {
3✔
97
    return Int64.strToInt(input) as unknown as ObjKey;
3✔
98
  } catch {
99
    throw new InvalidObjKey(input);
×
100
  }
101
}
102

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