realm
Version:
Realm is a mobile database: an alternative to SQLite and key-value stores
1,541 lines (1,394 loc) • 437 kB
JavaScript
'use strict';
var createDebug = require('debug');
var reactNative = require('react-native');
var bson = require('bson');
var realmConstants_json = require('realm/realm-constants.json');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var bson__namespace = /*#__PURE__*/_interopNamespaceDefault(bson);
function assertPath(path) {
if (typeof path !== 'string') {
throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
}
}
// Resolves . and .. elements in a path with directory names
function normalizeStringPosix(path, allowAboveRoot) {
var res = '';
var lastSegmentLength = 0;
var lastSlash = -1;
var dots = 0;
var code;
for (var i = 0; i <= path.length; ++i) {
if (i < path.length)
code = path.charCodeAt(i);
else if (code === 47 /*/*/)
break;
else
code = 47 /*/*/;
if (code === 47 /*/*/) {
if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
if (res.length > 2) {
var lastSlashIndex = res.lastIndexOf('/');
if (lastSlashIndex !== res.length - 1) {
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
} else {
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
}
lastSlash = i;
dots = 0;
continue;
}
} else if (res.length === 2 || res.length === 1) {
res = '';
lastSegmentLength = 0;
lastSlash = i;
dots = 0;
continue;
}
}
if (allowAboveRoot) {
if (res.length > 0)
res += '/..';
else
res = '..';
lastSegmentLength = 2;
}
} else {
if (res.length > 0)
res += '/' + path.slice(lastSlash + 1, i);
else
res = path.slice(lastSlash + 1, i);
lastSegmentLength = i - lastSlash - 1;
}
lastSlash = i;
dots = 0;
} else if (code === 46 /*.*/ && dots !== -1) {
++dots;
} else {
dots = -1;
}
}
return res;
}
function _format(sep, pathObject) {
var dir = pathObject.dir || pathObject.root;
var base = pathObject.base || (pathObject.name || '') + (pathObject.ext || '');
if (!dir) {
return base;
}
if (dir === pathObject.root) {
return dir + base;
}
return dir + sep + base;
}
var posix = {
// path.resolve([from ...], to)
resolve: function resolve() {
var resolvedPath = '';
var resolvedAbsolute = false;
var cwd;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path;
if (i >= 0)
path = arguments[i];
else {
if (cwd === undefined)
cwd = process.cwd();
path = cwd;
}
assertPath(path);
// Skip empty entries
if (path.length === 0) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
if (resolvedAbsolute) {
if (resolvedPath.length > 0)
return '/' + resolvedPath;
else
return '/';
} else if (resolvedPath.length > 0) {
return resolvedPath;
} else {
return '.';
}
},
normalize: function normalize(path) {
assertPath(path);
if (path.length === 0) return '.';
var isAbsolute = path.charCodeAt(0) === 47 /*/*/;
var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/;
// Normalize the path
path = normalizeStringPosix(path, !isAbsolute);
if (path.length === 0 && !isAbsolute) path = '.';
if (path.length > 0 && trailingSeparator) path += '/';
if (isAbsolute) return '/' + path;
return path;
},
isAbsolute: function isAbsolute(path) {
assertPath(path);
return path.length > 0 && path.charCodeAt(0) === 47 /*/*/;
},
join: function join() {
if (arguments.length === 0)
return '.';
var joined;
for (var i = 0; i < arguments.length; ++i) {
var arg = arguments[i];
assertPath(arg);
if (arg.length > 0) {
if (joined === undefined)
joined = arg;
else
joined += '/' + arg;
}
}
if (joined === undefined)
return '.';
return posix.normalize(joined);
},
relative: function relative(from, to) {
assertPath(from);
assertPath(to);
if (from === to) return '';
from = posix.resolve(from);
to = posix.resolve(to);
if (from === to) return '';
// Trim any leading backslashes
var fromStart = 1;
for (; fromStart < from.length; ++fromStart) {
if (from.charCodeAt(fromStart) !== 47 /*/*/)
break;
}
var fromEnd = from.length;
var fromLen = fromEnd - fromStart;
// Trim any leading backslashes
var toStart = 1;
for (; toStart < to.length; ++toStart) {
if (to.charCodeAt(toStart) !== 47 /*/*/)
break;
}
var toEnd = to.length;
var toLen = toEnd - toStart;
// Compare paths to find the longest common path from root
var length = fromLen < toLen ? fromLen : toLen;
var lastCommonSep = -1;
var i = 0;
for (; i <= length; ++i) {
if (i === length) {
if (toLen > length) {
if (to.charCodeAt(toStart + i) === 47 /*/*/) {
// We get here if `from` is the exact base path for `to`.
// For example: from='/foo/bar'; to='/foo/bar/baz'
return to.slice(toStart + i + 1);
} else if (i === 0) {
// We get here if `from` is the root
// For example: from='/'; to='/foo'
return to.slice(toStart + i);
}
} else if (fromLen > length) {
if (from.charCodeAt(fromStart + i) === 47 /*/*/) {
// We get here if `to` is the exact base path for `from`.
// For example: from='/foo/bar/baz'; to='/foo/bar'
lastCommonSep = i;
} else if (i === 0) {
// We get here if `to` is the root.
// For example: from='/foo'; to='/'
lastCommonSep = 0;
}
}
break;
}
var fromCode = from.charCodeAt(fromStart + i);
var toCode = to.charCodeAt(toStart + i);
if (fromCode !== toCode)
break;
else if (fromCode === 47 /*/*/)
lastCommonSep = i;
}
var out = '';
// Generate the relative path based on the path difference between `to`
// and `from`
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) {
if (out.length === 0)
out += '..';
else
out += '/..';
}
}
// Lastly, append the rest of the destination (`to`) path that comes after
// the common path parts
if (out.length > 0)
return out + to.slice(toStart + lastCommonSep);
else {
toStart += lastCommonSep;
if (to.charCodeAt(toStart) === 47 /*/*/)
++toStart;
return to.slice(toStart);
}
},
_makeLong: function _makeLong(path) {
return path;
},
dirname: function dirname(path) {
assertPath(path);
if (path.length === 0) return '.';
var code = path.charCodeAt(0);
var hasRoot = code === 47 /*/*/;
var end = -1;
var matchedSlash = true;
for (var i = path.length - 1; i >= 1; --i) {
code = path.charCodeAt(i);
if (code === 47 /*/*/) {
if (!matchedSlash) {
end = i;
break;
}
} else {
// We saw the first non-path separator
matchedSlash = false;
}
}
if (end === -1) return hasRoot ? '/' : '.';
if (hasRoot && end === 1) return '//';
return path.slice(0, end);
},
basename: function basename(path, ext) {
if (ext !== undefined && typeof ext !== 'string') throw new TypeError('"ext" argument must be a string');
assertPath(path);
var start = 0;
var end = -1;
var matchedSlash = true;
var i;
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
if (ext.length === path.length && ext === path) return '';
var extIdx = ext.length - 1;
var firstNonSlashEnd = -1;
for (i = path.length - 1; i >= 0; --i) {
var code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
start = i + 1;
break;
}
} else {
if (firstNonSlashEnd === -1) {
// We saw the first non-path separator, remember this index in case
// we need it if the extension ends up not matching
matchedSlash = false;
firstNonSlashEnd = i + 1;
}
if (extIdx >= 0) {
// Try to match the explicit extension
if (code === ext.charCodeAt(extIdx)) {
if (--extIdx === -1) {
// We matched the extension, so mark this as the end of our path
// component
end = i;
}
} else {
// Extension does not match, so our result is the entire path
// component
extIdx = -1;
end = firstNonSlashEnd;
}
}
}
}
if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length;
return path.slice(start, end);
} else {
for (i = path.length - 1; i >= 0; --i) {
if (path.charCodeAt(i) === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
start = i + 1;
break;
}
} else if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// path component
matchedSlash = false;
end = i + 1;
}
}
if (end === -1) return '';
return path.slice(start, end);
}
},
extname: function extname(path) {
assertPath(path);
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
for (var i = path.length - 1; i >= 0; --i) {
var code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
startPart = i + 1;
break;
}
continue;
}
if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// extension
matchedSlash = false;
end = i + 1;
}
if (code === 46 /*.*/) {
// If this is our first dot, mark it as the start of our extension
if (startDot === -1)
startDot = i;
else if (preDotState !== 1)
preDotState = 1;
} else if (startDot !== -1) {
// We saw a non-dot and non-path separator before our dot, so we should
// have a good chance at having a non-empty extension
preDotState = -1;
}
}
if (startDot === -1 || end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
return '';
}
return path.slice(startDot, end);
},
format: function format(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
}
return _format('/', pathObject);
},
parse: function parse(path) {
assertPath(path);
var ret = { root: '', dir: '', base: '', ext: '', name: '' };
if (path.length === 0) return ret;
var code = path.charCodeAt(0);
var isAbsolute = code === 47 /*/*/;
var start;
if (isAbsolute) {
ret.root = '/';
start = 1;
} else {
start = 0;
}
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
var i = path.length - 1;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
// Get non-dir info
for (; i >= start; --i) {
code = path.charCodeAt(i);
if (code === 47 /*/*/) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
if (!matchedSlash) {
startPart = i + 1;
break;
}
continue;
}
if (end === -1) {
// We saw the first non-path separator, mark this as the end of our
// extension
matchedSlash = false;
end = i + 1;
}
if (code === 46 /*.*/) {
// If this is our first dot, mark it as the start of our extension
if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1;
} else if (startDot !== -1) {
// We saw a non-dot and non-path separator before our dot, so we should
// have a good chance at having a non-empty extension
preDotState = -1;
}
}
if (startDot === -1 || end === -1 ||
// We saw a non-dot character immediately before the dot
preDotState === 0 ||
// The (right-most) trimmed path component is exactly '..'
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
if (end !== -1) {
if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end);
}
} else {
if (startPart === 0 && isAbsolute) {
ret.name = path.slice(1, startDot);
ret.base = path.slice(1, end);
} else {
ret.name = path.slice(startPart, startDot);
ret.base = path.slice(startPart, end);
}
ret.ext = path.slice(startDot, end);
}
if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = '/';
return ret;
},
sep: '/',
delimiter: ':',
win32: null,
posix: null
};
posix.posix = posix;
var pathBrowserify = posix;
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2022 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 fs = {
isAbsolutePath() {
throw new Error("Not supported on this platform");
},
joinPaths() {
throw new Error("Not supported on this platform");
},
removeFile() {
throw new Error("Not supported on this platform");
},
setDefaultDirectoryPath() {
throw new Error("Not supported on this platform");
},
getDefaultDirectoryPath() {
throw new Error("Not supported on this platform");
},
exists() {
throw new Error("Not supported on this platform");
},
copyBundledRealmFiles() {
throw new Error("Not supported on this platform");
},
removeDirectory() {
throw new Error("Not supported on this platform");
},
ensureDirectoryForFile() {
throw new Error("Not supported on this platform");
},
/*
readDirectory() {
throw new Error("Not supported on this platform");
},
*/
removeRealmFilesFromDirectory() {
throw new Error("Not supported on this platform");
},
};
function inject$2(injected) {
Object.freeze(Object.assign(fs, injected));
}
////////////////////////////////////////////////////////////////////////////
const debug$3 = createDebug("realm");
function extendDebug(namespace) {
return debug$3.extend(namespace);
}
// Wrapped types
class Float {
value;
constructor(value) {
this.value = value;
}
valueOf() {
return this.value;
}
}
class Status {
isOk;
code;
reason;
constructor(isOk) {
this.isOk = isOk;
}
}
////////////////////////////////////////////////////////////////////////////
if (reactNative.Platform.OS === "android") {
// Getting the native module on Android will inject the Realm global
// eslint-disable-next-line @typescript-eslint/no-unused-vars
reactNative.NativeModules.Realm;
}
// TODO: Remove the need to store Realm as a global
// @see https://github.com/realm/realm-js/issues/2126
const nativeModule = global.__RealmFuncs;
if (!nativeModule) {
throw new Error(
"Could not find the Realm binary. Please consult our troubleshooting guide: https://www.mongodb.com/docs/realm-sdks/js/latest/#md:troubleshooting-missing-binary",
);
}
const WeakRef =
global.WeakRef ??
class WeakRef {
constructor(obj) {
this.native = nativeModule.createWeakRef(obj);
}
deref() {
return nativeModule.lockWeakRef(this.native);
}
};
const NativeBigIntSupport = Object.freeze({
add(a, b) {
return a + b;
},
equals(a, b) {
return a == b;
}, // using == rather than === to support number and string RHS!
isInt(a) {
return typeof a === "bigint";
},
numToInt(a) {
return BigInt(a);
},
strToInt(a) {
return BigInt(a);
},
intToNum(a) {
return Number(a);
},
});
// Hermes supports BigInt, but JSC doesn't.
const Int64 = global.HermesInternal
? NativeBigIntSupport
: {
add(a, b) {
return a.add(b);
},
equals(a, b) {
return a.equals(b);
},
isInt(a) {
return a instanceof bson.Long;
},
numToInt(a) {
return bson.Long.fromNumber(a);
},
strToInt(a) {
return bson.Long.fromString(a);
},
intToNum(a) {
return a.toNumber();
},
};
// Copied from lib/utils.js.
// TODO consider importing instead.
// Might be slightly faster to make dedicated wrapper for 1 and 2 argument forms, but unlikely to be worth it.
function _promisify(nullAllowed, func) {
return new Promise((resolve, reject) => {
func((...cbargs) => {
// Any errors in this function should flow into the Promise chain, rather than out to the caller,
// since callers of async callbacks aren't expecting exceptions.
try {
if (cbargs.length < 1 || cbargs.length > 2) throw Error("invalid cbargs length " + cbargs.length);
let error = cbargs[cbargs.length - 1];
if (error) {
reject(error);
} else if (cbargs.length == 2) {
const result = cbargs[0];
if (!nullAllowed && (result === null || result === undefined)) {
throw new Error("Unexpected null or undefined successful result");
}
resolve(result);
} else {
resolve();
}
} catch (err) {
reject(err);
}
});
});
}
const _Helpers_Symbol = Symbol("Realm.Helpers.external_pointer");
const _native_Helpers_get_table = nativeModule.Helpers_get_table;
const _native_Helpers_get_keypath_mapping = nativeModule.Helpers_get_keypath_mapping;
const _native_Helpers_results_append_query = nativeModule.Helpers_results_append_query;
const _native_Helpers_make_object_notifier = nativeModule.Helpers_make_object_notifier;
const _native_Helpers_set_binding_context = nativeModule.Helpers_set_binding_context;
const _native_Helpers_get_or_create_object_with_primary_key =
nativeModule.Helpers_get_or_create_object_with_primary_key;
const _native_Helpers_make_network_transport = nativeModule.Helpers_make_network_transport;
const _native_Helpers_delete_data_for_object = nativeModule.Helpers_delete_data_for_object;
const _native_Helpers_is_empty_realm = nativeModule.Helpers_is_empty_realm;
const _native_Helpers_base64_decode = nativeModule.Helpers_base64_decode;
const _native_Helpers_make_logger_factory = nativeModule.Helpers_make_logger_factory;
const _native_Helpers_make_logger = nativeModule.Helpers_make_logger;
const _native_Helpers_simulate_sync_error = nativeModule.Helpers_simulate_sync_error;
const _native_Helpers_consume_thread_safe_reference_to_shared_realm =
nativeModule.Helpers_consume_thread_safe_reference_to_shared_realm;
const _native_Helpers_file_exists = nativeModule.Helpers_file_exists;
const _native_Helpers_erase_subscription = nativeModule.Helpers_erase_subscription;
const _native_Helpers_get_results_description = nativeModule.Helpers_get_results_description;
const _native_Helpers_feed_buffer = nativeModule.Helpers_feed_buffer;
const _native_Helpers_make_ssl_verify_callback = nativeModule.Helpers_make_ssl_verify_callback;
class Helpers {
constructor(ptr) {
this[_Helpers_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Helpers)) throw new TypeError("Expected a Helpers");
const out = self[_Helpers_Symbol];
if (!out) throw new TypeError("received an improperly constructed Helpers");
return out;
}
static getTable(r, key) {
return _native_Helpers_get_table(r, key);
}
static getKeypathMapping(r) {
return _native_Helpers_get_keypath_mapping(r);
}
static resultsAppendQuery(results, query) {
return _native_Helpers_results_append_query(results, query);
}
static makeObjectNotifier(r, o) {
return _native_Helpers_make_object_notifier(r, o);
}
static setBindingContext(r, methods) {
return _native_Helpers_set_binding_context(r, methods);
}
static getOrCreateObjectWithPrimaryKey(t, pk) {
return _native_Helpers_get_or_create_object_with_primary_key(t, pk);
}
static makeNetworkTransport(runRequest) {
return _native_Helpers_make_network_transport(runRequest);
}
static deleteDataForObject(realm, object_type) {
return _native_Helpers_delete_data_for_object(realm, object_type);
}
static isEmptyRealm(realm) {
return _native_Helpers_is_empty_realm(realm);
}
static base64Decode(input) {
return _native_Helpers_base64_decode(input);
}
static makeLoggerFactory(log) {
return _native_Helpers_make_logger_factory(log);
}
static makeLogger(log) {
return _native_Helpers_make_logger(log);
}
static simulateSyncError(session, code, message, type, is_fatal) {
return _native_Helpers_simulate_sync_error(session, code, message, type, is_fatal);
}
static consumeThreadSafeReferenceToSharedRealm(tsr) {
return _native_Helpers_consume_thread_safe_reference_to_shared_realm(tsr);
}
static fileExists(path) {
return _native_Helpers_file_exists(path);
}
static eraseSubscription(subs, sub_to_remove) {
return _native_Helpers_erase_subscription(subs, sub_to_remove);
}
static getResultsDescription(results) {
return _native_Helpers_get_results_description(results);
}
static feedBuffer(ws, buffer) {
return _native_Helpers_feed_buffer(ws, buffer);
}
static makeSslVerifyCallback(callback) {
return _native_Helpers_make_ssl_verify_callback(callback);
}
}
const _Logger_Symbol = Symbol("Realm.Logger.external_pointer");
const _native_Logger_set_default_logger = nativeModule.Logger_set_default_logger;
const _native_Logger_set_default_level_threshold = nativeModule.Logger_set_default_level_threshold;
class Logger {
constructor(ptr) {
this[_Logger_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Logger)) throw new TypeError("Expected a Logger");
const out = self[_Logger_Symbol];
if (!out) throw new TypeError("received an improperly constructed Logger");
return out;
}
static setDefaultLogger(logger) {
return _native_Logger_set_default_logger(logger);
}
static setDefaultLevelThreshold(level) {
return _native_Logger_set_default_level_threshold(level);
}
}
const _ConstTableRef_Symbol = Symbol("Realm.ConstTableRef.external_pointer");
const _native_ConstTableRef_get_column_type = nativeModule.ConstTableRef_get_column_type;
const _native_ConstTableRef_get_link_target = nativeModule.ConstTableRef_get_link_target;
const _native_ConstTableRef_get_object = nativeModule.ConstTableRef_get_object;
const _native_ConstTableRef_try_get_object = nativeModule.ConstTableRef_try_get_object;
const _native_ConstTableRef_query = nativeModule.ConstTableRef_query;
const _native_ConstTableRef_find_primary_key = nativeModule.ConstTableRef_find_primary_key;
const _native_ConstTableRef_get_key = nativeModule.ConstTableRef_get_key;
const _native_ConstTableRef_Symbol_iterator = nativeModule.ConstTableRef_Symbol_iterator;
class ConstTableRef {
constructor(ptr) {
this[_ConstTableRef_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof ConstTableRef)) throw new TypeError("Expected a ConstTableRef");
const out = self[_ConstTableRef_Symbol];
if (!out) throw new TypeError("received an improperly constructed ConstTableRef");
return out;
}
getColumnType(column) {
return _native_ConstTableRef_get_column_type(this[_ConstTableRef_Symbol], column);
}
getLinkTarget(column) {
return _native_ConstTableRef_get_link_target(this[_ConstTableRef_Symbol], column);
}
getObject(key) {
return _native_ConstTableRef_get_object(this[_ConstTableRef_Symbol], key);
}
tryGetObject(key) {
return _native_ConstTableRef_try_get_object(this[_ConstTableRef_Symbol], key);
}
query(query_string, args, mapping) {
return _native_ConstTableRef_query(this[_ConstTableRef_Symbol], query_string, args, mapping);
}
findPrimaryKey(pk) {
return _native_ConstTableRef_find_primary_key(this[_ConstTableRef_Symbol], pk);
}
get key() {
return _native_ConstTableRef_get_key(this[_ConstTableRef_Symbol]);
}
[Symbol.iterator]() {
return _native_ConstTableRef_Symbol_iterator(this[_ConstTableRef_Symbol]);
}
}
const _native_TableRef_create_object = nativeModule.TableRef_create_object;
const _native_TableRef_remove_object = nativeModule.TableRef_remove_object;
const _native_TableRef_get_link_target = nativeModule.TableRef_get_link_target;
const _native_TableRef_clear = nativeModule.TableRef_clear;
class TableRef extends ConstTableRef {
static _extract(self) {
if (!(self instanceof TableRef)) throw new TypeError("Expected a TableRef");
const out = self[_ConstTableRef_Symbol];
if (!out) throw new TypeError("received an improperly constructed TableRef");
return out;
}
createObject() {
return _native_TableRef_create_object(this[_ConstTableRef_Symbol]);
}
removeObject(key) {
return _native_TableRef_remove_object(this[_ConstTableRef_Symbol], key);
}
getLinkTarget(column) {
return _native_TableRef_get_link_target(this[_ConstTableRef_Symbol], column);
}
clear() {
return _native_TableRef_clear(this[_ConstTableRef_Symbol]);
}
}
const _Obj_Symbol = Symbol("Realm.Obj.external_pointer");
const _native_Obj_get_any = nativeModule.Obj_get_any;
const _native_Obj_set_any = nativeModule.Obj_set_any;
const _native_Obj_get_linked_object = nativeModule.Obj_get_linked_object;
const _native_Obj_get_backlink_count = nativeModule.Obj_get_backlink_count;
const _native_Obj_get_backlink_view = nativeModule.Obj_get_backlink_view;
const _native_Obj_create_and_set_linked_object = nativeModule.Obj_create_and_set_linked_object;
const _native_Obj_is_valid = nativeModule.Obj_is_valid;
const _native_Obj_get_table = nativeModule.Obj_get_table;
const _native_Obj_get_key = nativeModule.Obj_get_key;
class Obj {
constructor(ptr) {
this[_Obj_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Obj)) throw new TypeError("Expected a Obj");
const out = self[_Obj_Symbol];
if (!out) throw new TypeError("received an improperly constructed Obj");
return out;
}
getAny(column) {
return _native_Obj_get_any(this[_Obj_Symbol], column);
}
setAny(column, value) {
return _native_Obj_set_any(this[_Obj_Symbol], column, value);
}
getLinkedObject(column) {
return _native_Obj_get_linked_object(this[_Obj_Symbol], column);
}
getBacklinkCount() {
return _native_Obj_get_backlink_count(this[_Obj_Symbol]);
}
getBacklinkView(src_table, src_col_key) {
return _native_Obj_get_backlink_view(this[_Obj_Symbol], src_table, src_col_key);
}
createAndSetLinkedObject(column) {
return _native_Obj_create_and_set_linked_object(this[_Obj_Symbol], column);
}
get isValid() {
return _native_Obj_is_valid(this[_Obj_Symbol]);
}
get table() {
return _native_Obj_get_table(this[_Obj_Symbol]);
}
get key() {
return _native_Obj_get_key(this[_Obj_Symbol]);
}
}
const _Transaction_Symbol = Symbol("Realm.Transaction.external_pointer");
class Transaction {
constructor(ptr) {
this[_Transaction_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Transaction)) throw new TypeError("Expected a Transaction");
const out = self[_Transaction_Symbol];
if (!out) throw new TypeError("received an improperly constructed Transaction");
return out;
}
}
const _ObjectStore_Symbol = Symbol("Realm.ObjectStore.external_pointer");
class ObjectStore {
constructor(ptr) {
this[_ObjectStore_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof ObjectStore)) throw new TypeError("Expected a ObjectStore");
const out = self[_ObjectStore_Symbol];
if (!out) throw new TypeError("received an improperly constructed ObjectStore");
return out;
}
}
const _Timestamp_Symbol = Symbol("Realm.Timestamp.external_pointer");
const _native_Timestamp_make = nativeModule.Timestamp_make;
const _native_Timestamp_get_seconds = nativeModule.Timestamp_get_seconds;
const _native_Timestamp_get_nanoseconds = nativeModule.Timestamp_get_nanoseconds;
class Timestamp {
constructor(ptr) {
this[_Timestamp_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Timestamp)) throw new TypeError("Expected a Timestamp");
const out = self[_Timestamp_Symbol];
if (!out) throw new TypeError("received an improperly constructed Timestamp");
return out;
}
static make(seconds, nanoseconds) {
return _native_Timestamp_make(seconds, nanoseconds);
}
get seconds() {
return _native_Timestamp_get_seconds(this[_Timestamp_Symbol]);
}
get nanoseconds() {
return _native_Timestamp_get_nanoseconds(this[_Timestamp_Symbol]);
}
}
const _Geospatial_Symbol = Symbol("Realm.Geospatial.external_pointer");
const _native_Geospatial_make_from_circle = nativeModule.Geospatial_make_from_circle;
const _native_Geospatial_make_from_box = nativeModule.Geospatial_make_from_box;
const _native_Geospatial_make_from_polygon = nativeModule.Geospatial_make_from_polygon;
class Geospatial {
constructor(ptr) {
this[_Geospatial_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Geospatial)) throw new TypeError("Expected a Geospatial");
const out = self[_Geospatial_Symbol];
if (!out) throw new TypeError("received an improperly constructed Geospatial");
return out;
}
static makeFromCircle(circle) {
return _native_Geospatial_make_from_circle(circle);
}
static makeFromBox(box) {
return _native_Geospatial_make_from_box(box);
}
static makeFromPolygon(polygon) {
return _native_Geospatial_make_from_polygon(polygon);
}
}
const _ObjLink_Symbol = Symbol("Realm.ObjLink.external_pointer");
const _native_ObjLink_get_table_key = nativeModule.ObjLink_get_table_key;
const _native_ObjLink_get_obj_key = nativeModule.ObjLink_get_obj_key;
class ObjLink {
constructor(ptr) {
this[_ObjLink_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof ObjLink)) throw new TypeError("Expected a ObjLink");
const out = self[_ObjLink_Symbol];
if (!out) throw new TypeError("received an improperly constructed ObjLink");
return out;
}
get tableKey() {
return _native_ObjLink_get_table_key(this[_ObjLink_Symbol]);
}
get objKey() {
return _native_ObjLink_get_obj_key(this[_ObjLink_Symbol]);
}
}
const _KeyPathMapping_Symbol = Symbol("Realm.KeyPathMapping.external_pointer");
class KeyPathMapping {
constructor(ptr) {
this[_KeyPathMapping_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof KeyPathMapping)) throw new TypeError("Expected a KeyPathMapping");
const out = self[_KeyPathMapping_Symbol];
if (!out) throw new TypeError("received an improperly constructed KeyPathMapping");
return out;
}
}
const _Query_Symbol = Symbol("Realm.Query.external_pointer");
const _native_Query_get_table = nativeModule.Query_get_table;
const _native_Query_get_description = nativeModule.Query_get_description;
class Query {
constructor(ptr) {
this[_Query_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Query)) throw new TypeError("Expected a Query");
const out = self[_Query_Symbol];
if (!out) throw new TypeError("received an improperly constructed Query");
return out;
}
get table() {
return _native_Query_get_table(this[_Query_Symbol]);
}
get description() {
return _native_Query_get_description(this[_Query_Symbol]);
}
}
const _SortDescriptor_Symbol = Symbol("Realm.SortDescriptor.external_pointer");
class SortDescriptor {
constructor(ptr) {
this[_SortDescriptor_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof SortDescriptor)) throw new TypeError("Expected a SortDescriptor");
const out = self[_SortDescriptor_Symbol];
if (!out) throw new TypeError("received an improperly constructed SortDescriptor");
return out;
}
}
const _TableView_Symbol = Symbol("Realm.TableView.external_pointer");
class TableView {
constructor(ptr) {
this[_TableView_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof TableView)) throw new TypeError("Expected a TableView");
const out = self[_TableView_Symbol];
if (!out) throw new TypeError("received an improperly constructed TableView");
return out;
}
}
const _Results_Symbol = Symbol("Realm.Results.external_pointer");
const _native_Results_size = nativeModule.Results_size;
const _native_Results_index_of = nativeModule.Results_index_of;
const _native_Results_index_of_obj = nativeModule.Results_index_of_obj;
const _native_Results_get_obj = nativeModule.Results_get_obj;
const _native_Results_get_any = nativeModule.Results_get_any;
const _native_Results_sort_by_names = nativeModule.Results_sort_by_names;
const _native_Results_snapshot = nativeModule.Results_snapshot;
const _native_Results_max = nativeModule.Results_max;
const _native_Results_min = nativeModule.Results_min;
const _native_Results_average = nativeModule.Results_average;
const _native_Results_sum = nativeModule.Results_sum;
const _native_Results_clear = nativeModule.Results_clear;
const _native_Results_add_notification_callback = nativeModule.Results_add_notification_callback;
const _native_Results_from_table = nativeModule.Results_from_table;
const _native_Results_from_table_view = nativeModule.Results_from_table_view;
const _native_Results_is_valid = nativeModule.Results_is_valid;
const _native_Results_get_query = nativeModule.Results_get_query;
const _native_Results_get_object_type = nativeModule.Results_get_object_type;
const _native_Results_get_type = nativeModule.Results_get_type;
let Results$1 = class Results {
constructor(ptr) {
this[_Results_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Results)) throw new TypeError("Expected a Results");
const out = self[_Results_Symbol];
if (!out) throw new TypeError("received an improperly constructed Results");
return out;
}
size() {
return _native_Results_size(this[_Results_Symbol]);
}
indexOf(value) {
return _native_Results_index_of(this[_Results_Symbol], value);
}
indexOfObj(obj) {
return _native_Results_index_of_obj(this[_Results_Symbol], obj);
}
getObj(index) {
return _native_Results_get_obj(this[_Results_Symbol], index);
}
getAny(index) {
return _native_Results_get_any(this[_Results_Symbol], index);
}
sortByNames(order) {
return _native_Results_sort_by_names(this[_Results_Symbol], order);
}
snapshot() {
return _native_Results_snapshot(this[_Results_Symbol]);
}
max(column) {
return _native_Results_max(this[_Results_Symbol], column);
}
min(column) {
return _native_Results_min(this[_Results_Symbol], column);
}
average(column) {
return _native_Results_average(this[_Results_Symbol], column);
}
sum(column) {
return _native_Results_sum(this[_Results_Symbol], column);
}
clear() {
return _native_Results_clear(this[_Results_Symbol]);
}
addNotificationCallback(cb, keyPaths) {
return _native_Results_add_notification_callback(this[_Results_Symbol], cb, keyPaths);
}
static fromTable(r, table) {
return _native_Results_from_table(r, table);
}
static fromTableView(r, table) {
return _native_Results_from_table_view(r, table);
}
get isValid() {
return _native_Results_is_valid(this[_Results_Symbol]);
}
get query() {
return _native_Results_get_query(this[_Results_Symbol]);
}
get objectType() {
return _native_Results_get_object_type(this[_Results_Symbol]);
}
get type() {
return _native_Results_get_type(this[_Results_Symbol]);
}
};
const _Realm_Symbol = Symbol("Realm.Realm.external_pointer");
const _native_Realm_begin_transaction = nativeModule.Realm_begin_transaction;
const _native_Realm_commit_transaction = nativeModule.Realm_commit_transaction;
const _native_Realm_cancel_transaction = nativeModule.Realm_cancel_transaction;
const _native_Realm_update_schema = nativeModule.Realm_update_schema;
const _native_Realm_compact = nativeModule.Realm_compact;
const _native_Realm_convert = nativeModule.Realm_convert;
const _native_Realm_verify_open = nativeModule.Realm_verify_open;
const _native_Realm_close = nativeModule.Realm_close;
const _native_Realm_get_shared_realm = nativeModule.Realm_get_shared_realm;
const _native_Realm_get_synchronized_realm = nativeModule.Realm_get_synchronized_realm;
const _native_Realm_get_schema_version = nativeModule.Realm_get_schema_version;
const _native_Realm_config = nativeModule.Realm_config;
const _native_Realm_schema = nativeModule.Realm_schema;
const _native_Realm_schema_version = nativeModule.Realm_schema_version;
const _native_Realm_is_in_transaction = nativeModule.Realm_is_in_transaction;
const _native_Realm_is_in_migration = nativeModule.Realm_is_in_migration;
const _native_Realm_is_closed = nativeModule.Realm_is_closed;
const _native_Realm_sync_session = nativeModule.Realm_sync_session;
const _native_Realm_get_latest_subscription_set = nativeModule.Realm_get_latest_subscription_set;
const _native_Realm_DOLLAR_addr = nativeModule.Realm_DOLLAR_addr;
const _native_Realm_DOLLAR_resetSharedPtr = nativeModule.Realm_DOLLAR_resetSharedPtr;
let Realm$1 = class Realm {
constructor(ptr) {
this[_Realm_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Realm)) throw new TypeError("Expected a Realm");
const out = self[_Realm_Symbol];
if (!out) throw new TypeError("received an improperly constructed Realm");
return out;
}
beginTransaction() {
return _native_Realm_begin_transaction(this[_Realm_Symbol]);
}
commitTransaction() {
return _native_Realm_commit_transaction(this[_Realm_Symbol]);
}
cancelTransaction() {
return _native_Realm_cancel_transaction(this[_Realm_Symbol]);
}
updateSchema(schema, version, migration_function, initialization_function, in_transaction) {
return _native_Realm_update_schema(
this[_Realm_Symbol],
schema,
version,
migration_function,
initialization_function,
in_transaction,
);
}
compact() {
return _native_Realm_compact(this[_Realm_Symbol]);
}
convert(config) {
return _native_Realm_convert(this[_Realm_Symbol], config);
}
verifyOpen() {
return _native_Realm_verify_open(this[_Realm_Symbol]);
}
close() {
return _native_Realm_close(this[_Realm_Symbol]);
}
static getSharedRealm(config) {
return _native_Realm_get_shared_realm(config);
}
static getSynchronizedRealm(config) {
return _native_Realm_get_synchronized_realm(config);
}
static getSchemaVersion(config) {
return _native_Realm_get_schema_version(config);
}
get config() {
return _native_Realm_config(this[_Realm_Symbol]);
}
get schema() {
return _native_Realm_schema(this[_Realm_Symbol]);
}
get schemaVersion() {
return _native_Realm_schema_version(this[_Realm_Symbol]);
}
get isInTransaction() {
return _native_Realm_is_in_transaction(this[_Realm_Symbol]);
}
get isInMigration() {
return _native_Realm_is_in_migration(this[_Realm_Symbol]);
}
get isClosed() {
return _native_Realm_is_closed(this[_Realm_Symbol]);
}
get syncSession() {
return _native_Realm_sync_session(this[_Realm_Symbol]);
}
get latestSubscriptionSet() {
return _native_Realm_get_latest_subscription_set(this[_Realm_Symbol]);
}
get $addr() {
return _native_Realm_DOLLAR_addr(this[_Realm_Symbol]);
}
$resetSharedPtr() {
return _native_Realm_DOLLAR_resetSharedPtr(this[_Realm_Symbol]);
}
};
const _RealmCoordinator_Symbol = Symbol("Realm.RealmCoordinator.external_pointer");
const _native_RealmCoordinator_clear_all_caches = nativeModule.RealmCoordinator_clear_all_caches;
class RealmCoordinator {
constructor(ptr) {
this[_RealmCoordinator_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof RealmCoordinator)) throw new TypeError("Expected a RealmCoordinator");
const out = self[_RealmCoordinator_Symbol];
if (!out) throw new TypeError("received an improperly constructed RealmCoordinator");
return out;
}
static clearAllCaches() {
return _native_RealmCoordinator_clear_all_caches();
}
}
const _ObjectNotifier_Symbol = Symbol("Realm.ObjectNotifier.external_pointer");
const _native_ObjectNotifier_add_callback = nativeModule.ObjectNotifier_add_callback;
class ObjectNotifier {
constructor(ptr) {
this[_ObjectNotifier_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof ObjectNotifier)) throw new TypeError("Expected a ObjectNotifier");
const out = self[_ObjectNotifier_Symbol];
if (!out) throw new TypeError("received an improperly constructed ObjectNotifier");
return out;
}
addCallback(cb, keyPaths) {
return _native_ObjectNotifier_add_callback(this[_ObjectNotifier_Symbol], cb, keyPaths);
}
}
const _NotificationToken_Symbol = Symbol("Realm.NotificationToken.external_pointer");
const _native_NotificationToken_unregister = nativeModule.NotificationToken_unregister;
const _native_NotificationToken_for_object = nativeModule.NotificationToken_for_object;
class NotificationToken {
constructor(ptr) {
this[_NotificationToken_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof NotificationToken)) throw new TypeError("Expected a NotificationToken");
const out = self[_NotificationToken_Symbol];
if (!out) throw new TypeError("received an improperly constructed NotificationToken");
return out;
}
unregister() {
return _native_NotificationToken_unregister(this[_NotificationToken_Symbol]);
}
static forObject(notifier, token) {
return _native_NotificationToken_for_object(notifier, token);
}
}
const _IndexSet_Symbol = Symbol("Realm.IndexSet.external_pointer");
const _native_IndexSet_Symbol_iterator = nativeModule.IndexSet_Symbol_iterator;
class IndexSet {
constructor(ptr) {
this[_IndexSet_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof IndexSet)) throw new TypeError("Expected a IndexSet");
const out = self[_IndexSet_Symbol];
if (!out) throw new TypeError("received an improperly constructed IndexSet");
return out;
}
[Symbol.iterator]() {
return _native_IndexSet_Symbol_iterator(this[_IndexSet_Symbol]);
}
}
const _Collection_Symbol = Symbol("Realm.Collection.external_pointer");
const _native_Collection_get_any = nativeModule.Collection_get_any;
const _native_Collection_as_results = nativeModule.Collection_as_results;
const _native_Collection_get_object_schema = nativeModule.Collection_get_object_schema;
const _native_Collection_size = nativeModule.Collection_size;
const _native_Collection_is_valid = nativeModule.Collection_is_valid;
let Collection$1 = class Collection {
constructor(ptr) {
this[_Collection_Symbol] = ptr;
}
static _extract(self) {
if (!(self instanceof Collection)) throw new TypeError("Expected a Collection");
const out = self[_Collection_Symbol];
if (!out) throw new TypeError("received an improperly constructed Collection");
return out;
}
getAny(ndx) {
return _native_Collection_get_any(this[_Collection_Symbol], ndx);
}
asResults() {
return _native_Collection_as_results(this[_Collection_Symbol]);
}
get objectSchema() {
return _native_Collection_get_object_schema(this[_Collection_Symbol]);
}
get size() {
return _native_Collection_size(this[_Collection_Symbol]);
}
get isValid() {
return _native_Collection_is_valid(this[_Collection_Symbol]);
}
};
const _native_List_move = nativeModule.List_move;
const _native_List_remove = nativeModule.List_remove;
const _native_List_remove_all = nativeModule.List_remove_all;
const _native_List_swap = nativeModule.List_swap;
const _native_List_delete_all = nativeModule.List_delete_all;
const _native_List_insert_any = nativeModule.List_insert_any;
const _native_List_insert_embedded = nativeModule.List_insert_embedded;
const _native_List_set_any = nativeModule.List_set_any;
const _native_List_make = nativeModule.List_make;
let List$1 = class List extends Collection$1 {
static _extract(self) {
if (!(self instanceof List)) throw new TypeError("Expected a List");
const out = self[_Collection_Symbol];
if (!out) throw new TypeError("received an improperly constructed List");
return out;
}
move(source_ndx, dest_ndx) {
return _native_List_move(this[_Collection_Symbol], source_ndx, dest_ndx);
}
remove(ndx) {
return _native_List_remove(this[_Collection_Symbol], ndx);
}
removeAll() {
return _native_List_remove_all(this[_Collection_Symbol]);
}
swap(ndx1, ndx2) {
return _native_List_swap(this[_Collection_Symbol], ndx1, ndx2);
}
deleteAll() {
return _native_List_delete_all(this[_Collection_Symbol]);
}
insertAny(list_ndx, value) {
return _native_List_insert_any(this[_Collection_Symbol], list_ndx, value);
}
insertEmbedded(ndx) {
return _native_List_insert_embedded(this[_Collection_Symbol], ndx);
}
setAny(list_ndx, value) {
return _native_List_set_any(this[_Collection_Symbol], list_ndx, value);
}
static make(r, parent, col) {
return _native_List_make(r, parent, col);
}
};
const _native_Set_insert_any = nativeModule.Set_insert_any;
const _native_Set_remove_any = nativeModule.Set_remove_any;
const _native_Set_remove_all = nativeModule.Set_remove_all;
const _native_Set_delete_all = nativeModule.Set_delete_all;
const _native_Set_make = nativeModule.Set_make;
let Set$1 = class Set extends Collection$1 {
static _extract(self) {
if (!(self instanceof Set)) throw new TypeError("Expected a Set");
const out = self[_Collection_Symbol];
if (!out) throw new TypeError("received an improperly constructed Set");
return out;
}
insertAny(val) {
return _native_Set_insert_any(this[_Collection_Symbol], val);
}
removeAny(val) {
return _native_Set_remove_any(this[_Collection_Symbol], val);
}
removeAll() {
return _native_Set_remove_all(this[_Collection_Symbol]);
}
deleteAll() {
return _native_Set_delete_all(this[_Collection_Symbol]);
}
static make(r, parent, col) {
return _native_Set_make(r, parent, col);
}
};
const _native_Dictionary_contains = nativeModule.Dictionary_contains;
const _native_Dictionary_add_key_based_notification_callback =
nativeModule.Dictionary_add_key_based_notification_callback;
const _native_Dictionary_insert_any = nativeModule.Dictionary_insert_any;
const _native_Dictionary_insert_embedded = nativeModule.Dictionary_insert_embedded;
const _native_Dictionary_try_get_any = nativeModule.Dictionary_try_get_any;
const _native_Dictionary_remo