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

realm / realm-js / 5354418719

23 Jun 2023 08:36AM UTC coverage: 85.663%. Remained the same
5354418719

push

github

kraenhansen
An attempt to fix async tests

845 of 1050 branches covered (80.48%)

Branch coverage included in aggregate %.

2244 of 2556 relevant lines covered (87.79%)

755.49 hits per line

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

71.43
/packages/realm/src/ClassHelpers.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 {
20
  CanonicalObjectSchema,
21
  DefaultObject,
22
  INTERNAL_HELPERS,
23
  PropertyMap,
24
  RealmObject,
25
  RealmObjectConstructor,
26
  binding,
27
} from "./internal";
28

29
type BindingObjectSchema = binding.Realm["schema"][0];
30

31
type ObjectWrapper = (obj: binding.Obj) => (RealmObject & DefaultObject) | null;
32

33
/**
34
 * @internal
35
 */
36
export type ClassHelpers = {
37
  constructor: RealmObjectConstructor;
38
  // TODO: Use a different type, once exposed by the binding
39
  objectSchema: BindingObjectSchema;
40
  properties: PropertyMap;
41
  wrapObject: ObjectWrapper;
42
  canonicalObjectSchema: CanonicalObjectSchema;
43
};
44

45
export function setClassHelpers(constructor: RealmObjectConstructor, value: ClassHelpers): void {
46
  // Store the properties map on the object class
47
  Object.defineProperty(constructor, INTERNAL_HELPERS, {
1,303✔
48
    enumerable: false,
49
    writable: false,
50
    configurable: false,
51
    value,
52
  });
53
}
54

55
/**
56
 * Get internal helpers.
57
 * NOTE: This is a free function instead of a member of RealmObject to limit conflicts with user defined properties.
58
 * @param arg The object or constructor to get a helpers for.
59
 * @returns Helpers injected onto the class by the `ClassMap`.
60
 */
61
export function getClassHelpers(arg: typeof RealmObject): ClassHelpers {
62
  const helpers = arg[INTERNAL_HELPERS];
9,321✔
63
  if (helpers) {
9,321!
64
    return helpers as ClassHelpers;
9,321✔
65
  } else {
66
    throw new Error(`Expected INTERNAL_HELPERS to be set on the '${arg.name}' class`);
×
67
  }
68
}
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