realm
Version:
Realm by MongoDB is an offline-first mobile database: an alternative to SQLite and key-value stores
72 lines • 2.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
////////////////////////////////////////////////////////////////////////////
//
// 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.
//
////////////////////////////////////////////////////////////////////////////
const node_util_1 = require("node:util");
const internal_1 = require("../../internal");
function injectInspect(constructor, customInspect) {
Object.assign(constructor.prototype, { [node_util_1.inspect.custom]: customInspect });
}
function constructorName(value) {
if (value instanceof internal_1.RealmObject) {
return value.objectSchema().name;
}
else if (value instanceof internal_1.RealmSet) {
return "Realm.Set";
}
else if (value instanceof internal_1.List) {
return "Realm.List";
}
else if (value instanceof internal_1.Dictionary) {
return "Realm.Dictionary";
}
else if (value instanceof internal_1.Results) {
return "Realm.Results";
}
else {
return value.constructor.name;
}
}
function isIterable(value) {
if (value instanceof internal_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(internal_1.RealmObject, defaultInspector);
injectInspect(internal_1.Collection, defaultInspector);
//# sourceMappingURL=custom-inspect.js.map