@react-native-oh-tpl/realm
Version:
Realm by MongoDB is an offline-first mobile database: an alternative to SQLite and key-value stores
77 lines • 2.61 kB
JavaScript
"use strict";
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2023 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
Object.defineProperty(exports, "__esModule", { value: true });
const node_util_1 = require("node:util");
const Collection_1 = require("../../Collection");
const Dictionary_1 = require("../../Dictionary");
const List_1 = require("../../List");
const Set_1 = require("../../Set");
const Results_1 = require("../../Results");
const Object_1 = require("../../Object");
function injectInspect(constructor, customInspect) {
Object.assign(constructor.prototype, { [node_util_1.inspect.custom]: customInspect });
}
function constructorName(value) {
if (value instanceof Object_1.RealmObject) {
return value.objectSchema().name;
}
else if (value instanceof Set_1.RealmSet) {
return "Realm.Set";
}
else if (value instanceof List_1.List) {
return "Realm.List";
}
else if (value instanceof Dictionary_1.Dictionary) {
return "Realm.Dictionary";
}
else if (value instanceof Results_1.Results) {
return "Realm.Results";
}
else {
return value.constructor.name;
}
}
function isIterable(value) {
if (value instanceof Dictionary_1.Dictionary) {
return false;
}
else if (Symbol.iterator in value) {
return true;
}
else {
return false;
}
}
function defaultInspector(depth, options) {
const name = constructorName(this);
if (depth === -1) {
if (options.colors) {
return options.stylize(`[${name}]`, "special");
}
else {
return `[${name}]`;
}
}
else {
return `${name} ${(0, node_util_1.inspect)(isIterable(this) ? [...this] : { ...this }, options.showHidden, depth, options.colors)}`;
}
}
injectInspect(Object_1.RealmObject, defaultInspector);
injectInspect(Collection_1.Collection, defaultInspector);
//# sourceMappingURL=custom-inspect.js.map