mongobase/dist/index.js
CounterFire2023 29a9fc2264 add base code
2024-01-19 13:54:32 +08:00

4040 lines
133 KiB
JavaScript

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __decorateClass = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result)
__defProp(target, key, result);
return result;
};
// node_modules/reflect-metadata/Reflect.js
var require_Reflect = __commonJS({
"node_modules/reflect-metadata/Reflect.js"() {
var Reflect2;
(function(Reflect3) {
(function(factory) {
var root = typeof globalThis === "object" ? globalThis : typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : sloppyModeThis();
var exporter = makeExporter(Reflect3);
if (typeof root.Reflect !== "undefined") {
exporter = makeExporter(root.Reflect, exporter);
}
factory(exporter, root);
if (typeof root.Reflect === "undefined") {
root.Reflect = Reflect3;
}
function makeExporter(target, previous) {
return function(key, value) {
Object.defineProperty(target, key, { configurable: true, writable: true, value });
if (previous)
previous(key, value);
};
}
function functionThis() {
try {
return Function("return this;")();
} catch (_) {
}
}
function indirectEvalThis() {
try {
return (void 0, eval)("(function() { return this; })()");
} catch (_) {
}
}
function sloppyModeThis() {
return functionThis() || indirectEvalThis();
}
})(function(exporter, root) {
var hasOwn = Object.prototype.hasOwnProperty;
var supportsSymbol = typeof Symbol === "function";
var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
var supportsCreate = typeof Object.create === "function";
var supportsProto = { __proto__: [] } instanceof Array;
var downLevel = !supportsCreate && !supportsProto;
var HashMap = {
// create an object in dictionary mode (a.k.a. "slow" mode in v8)
create: supportsCreate ? function() {
return MakeDictionary(/* @__PURE__ */ Object.create(null));
} : supportsProto ? function() {
return MakeDictionary({ __proto__: null });
} : function() {
return MakeDictionary({});
},
has: downLevel ? function(map, key) {
return hasOwn.call(map, key);
} : function(map, key) {
return key in map;
},
get: downLevel ? function(map, key) {
return hasOwn.call(map, key) ? map[key] : void 0;
} : function(map, key) {
return map[key];
}
};
var functionPrototype = Object.getPrototypeOf(Function);
var _Map = typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
var _Set = typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
var _WeakMap = typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
var registrySymbol = supportsSymbol ? Symbol.for("@reflect-metadata:registry") : void 0;
var metadataRegistry = GetOrCreateMetadataRegistry();
var metadataProvider = CreateMetadataProvider(metadataRegistry);
function decorate(decorators, target, propertyKey, attributes) {
if (!IsUndefined(propertyKey)) {
if (!IsArray(decorators))
throw new TypeError();
if (!IsObject(target))
throw new TypeError();
if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
throw new TypeError();
if (IsNull(attributes))
attributes = void 0;
propertyKey = ToPropertyKey(propertyKey);
return DecorateProperty(decorators, target, propertyKey, attributes);
} else {
if (!IsArray(decorators))
throw new TypeError();
if (!IsConstructor(target))
throw new TypeError();
return DecorateConstructor(decorators, target);
}
}
exporter("decorate", decorate);
function metadata(metadataKey, metadataValue) {
function decorator(target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
throw new TypeError();
OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
}
return decorator;
}
exporter("metadata", metadata);
function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
}
exporter("defineMetadata", defineMetadata);
function hasMetadata(metadataKey, target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
return OrdinaryHasMetadata(metadataKey, target, propertyKey);
}
exporter("hasMetadata", hasMetadata);
function hasOwnMetadata(metadataKey, target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
}
exporter("hasOwnMetadata", hasOwnMetadata);
function getMetadata(metadataKey, target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
return OrdinaryGetMetadata(metadataKey, target, propertyKey);
}
exporter("getMetadata", getMetadata);
function getOwnMetadata(metadataKey, target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
}
exporter("getOwnMetadata", getOwnMetadata);
function getMetadataKeys(target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
return OrdinaryMetadataKeys(target, propertyKey);
}
exporter("getMetadataKeys", getMetadataKeys);
function getOwnMetadataKeys(target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
return OrdinaryOwnMetadataKeys(target, propertyKey);
}
exporter("getOwnMetadataKeys", getOwnMetadataKeys);
function deleteMetadata(metadataKey, target, propertyKey) {
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
if (!IsObject(target))
throw new TypeError();
if (!IsUndefined(propertyKey))
propertyKey = ToPropertyKey(propertyKey);
var provider = GetMetadataProvider(
target,
propertyKey,
/*Create*/
false
);
if (IsUndefined(provider))
return false;
return provider.OrdinaryDeleteMetadata(metadataKey, target, propertyKey);
}
exporter("deleteMetadata", deleteMetadata);
function DecorateConstructor(decorators, target) {
for (var i = decorators.length - 1; i >= 0; --i) {
var decorator = decorators[i];
var decorated = decorator(target);
if (!IsUndefined(decorated) && !IsNull(decorated)) {
if (!IsConstructor(decorated))
throw new TypeError();
target = decorated;
}
}
return target;
}
function DecorateProperty(decorators, target, propertyKey, descriptor) {
for (var i = decorators.length - 1; i >= 0; --i) {
var decorator = decorators[i];
var decorated = decorator(target, propertyKey, descriptor);
if (!IsUndefined(decorated) && !IsNull(decorated)) {
if (!IsObject(decorated))
throw new TypeError();
descriptor = decorated;
}
}
return descriptor;
}
function OrdinaryHasMetadata(MetadataKey, O, P) {
var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
if (hasOwn2)
return true;
var parent = OrdinaryGetPrototypeOf(O);
if (!IsNull(parent))
return OrdinaryHasMetadata(MetadataKey, parent, P);
return false;
}
function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
var provider = GetMetadataProvider(
O,
P,
/*Create*/
false
);
if (IsUndefined(provider))
return false;
return ToBoolean(provider.OrdinaryHasOwnMetadata(MetadataKey, O, P));
}
function OrdinaryGetMetadata(MetadataKey, O, P) {
var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
if (hasOwn2)
return OrdinaryGetOwnMetadata(MetadataKey, O, P);
var parent = OrdinaryGetPrototypeOf(O);
if (!IsNull(parent))
return OrdinaryGetMetadata(MetadataKey, parent, P);
return void 0;
}
function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
var provider = GetMetadataProvider(
O,
P,
/*Create*/
false
);
if (IsUndefined(provider))
return;
return provider.OrdinaryGetOwnMetadata(MetadataKey, O, P);
}
function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
var provider = GetMetadataProvider(
O,
P,
/*Create*/
true
);
provider.OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P);
}
function OrdinaryMetadataKeys(O, P) {
var ownKeys = OrdinaryOwnMetadataKeys(O, P);
var parent = OrdinaryGetPrototypeOf(O);
if (parent === null)
return ownKeys;
var parentKeys = OrdinaryMetadataKeys(parent, P);
if (parentKeys.length <= 0)
return ownKeys;
if (ownKeys.length <= 0)
return parentKeys;
var set = new _Set();
var keys = [];
for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {
var key = ownKeys_1[_i];
var hasKey = set.has(key);
if (!hasKey) {
set.add(key);
keys.push(key);
}
}
for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {
var key = parentKeys_1[_a];
var hasKey = set.has(key);
if (!hasKey) {
set.add(key);
keys.push(key);
}
}
return keys;
}
function OrdinaryOwnMetadataKeys(O, P) {
var provider = GetMetadataProvider(
O,
P,
/*create*/
false
);
if (!provider) {
return [];
}
return provider.OrdinaryOwnMetadataKeys(O, P);
}
function Type(x) {
if (x === null)
return 1;
switch (typeof x) {
case "undefined":
return 0;
case "boolean":
return 2;
case "string":
return 3;
case "symbol":
return 4;
case "number":
return 5;
case "object":
return x === null ? 1 : 6;
default:
return 6;
}
}
function IsUndefined(x) {
return x === void 0;
}
function IsNull(x) {
return x === null;
}
function IsSymbol(x) {
return typeof x === "symbol";
}
function IsObject(x) {
return typeof x === "object" ? x !== null : typeof x === "function";
}
function ToPrimitive(input, PreferredType) {
switch (Type(input)) {
case 0:
return input;
case 1:
return input;
case 2:
return input;
case 3:
return input;
case 4:
return input;
case 5:
return input;
}
var hint = PreferredType === 3 ? "string" : PreferredType === 5 ? "number" : "default";
var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
if (exoticToPrim !== void 0) {
var result = exoticToPrim.call(input, hint);
if (IsObject(result))
throw new TypeError();
return result;
}
return OrdinaryToPrimitive(input, hint === "default" ? "number" : hint);
}
function OrdinaryToPrimitive(O, hint) {
if (hint === "string") {
var toString_1 = O.toString;
if (IsCallable(toString_1)) {
var result = toString_1.call(O);
if (!IsObject(result))
return result;
}
var valueOf = O.valueOf;
if (IsCallable(valueOf)) {
var result = valueOf.call(O);
if (!IsObject(result))
return result;
}
} else {
var valueOf = O.valueOf;
if (IsCallable(valueOf)) {
var result = valueOf.call(O);
if (!IsObject(result))
return result;
}
var toString_2 = O.toString;
if (IsCallable(toString_2)) {
var result = toString_2.call(O);
if (!IsObject(result))
return result;
}
}
throw new TypeError();
}
function ToBoolean(argument) {
return !!argument;
}
function ToString(argument) {
return "" + argument;
}
function ToPropertyKey(argument) {
var key = ToPrimitive(
argument,
3
/* String */
);
if (IsSymbol(key))
return key;
return ToString(key);
}
function IsArray(argument) {
return Array.isArray ? Array.isArray(argument) : argument instanceof Object ? argument instanceof Array : Object.prototype.toString.call(argument) === "[object Array]";
}
function IsCallable(argument) {
return typeof argument === "function";
}
function IsConstructor(argument) {
return typeof argument === "function";
}
function IsPropertyKey(argument) {
switch (Type(argument)) {
case 3:
return true;
case 4:
return true;
default:
return false;
}
}
function SameValueZero(x, y) {
return x === y || x !== x && y !== y;
}
function GetMethod(V, P) {
var func = V[P];
if (func === void 0 || func === null)
return void 0;
if (!IsCallable(func))
throw new TypeError();
return func;
}
function GetIterator(obj) {
var method = GetMethod(obj, iteratorSymbol);
if (!IsCallable(method))
throw new TypeError();
var iterator = method.call(obj);
if (!IsObject(iterator))
throw new TypeError();
return iterator;
}
function IteratorValue(iterResult) {
return iterResult.value;
}
function IteratorStep(iterator) {
var result = iterator.next();
return result.done ? false : result;
}
function IteratorClose(iterator) {
var f = iterator["return"];
if (f)
f.call(iterator);
}
function OrdinaryGetPrototypeOf(O) {
var proto = Object.getPrototypeOf(O);
if (typeof O !== "function" || O === functionPrototype)
return proto;
if (proto !== functionPrototype)
return proto;
var prototype = O.prototype;
var prototypeProto = prototype && Object.getPrototypeOf(prototype);
if (prototypeProto == null || prototypeProto === Object.prototype)
return proto;
var constructor = prototypeProto.constructor;
if (typeof constructor !== "function")
return proto;
if (constructor === O)
return proto;
return constructor;
}
function CreateMetadataRegistry() {
var fallback;
if (!IsUndefined(registrySymbol) && typeof root.Reflect !== "undefined" && !(registrySymbol in root.Reflect) && typeof root.Reflect.defineMetadata === "function") {
fallback = CreateFallbackProvider(root.Reflect);
}
var first;
var second;
var rest;
var targetProviderMap = new _WeakMap();
var registry = {
registerProvider,
getProvider,
setProvider
};
return registry;
function registerProvider(provider) {
if (!Object.isExtensible(registry)) {
throw new Error("Cannot add provider to a frozen registry.");
}
switch (true) {
case fallback === provider:
break;
case IsUndefined(first):
first = provider;
break;
case first === provider:
break;
case IsUndefined(second):
second = provider;
break;
case second === provider:
break;
default:
if (rest === void 0)
rest = new _Set();
rest.add(provider);
break;
}
}
function getProviderNoCache(O, P) {
if (!IsUndefined(first)) {
if (first.isProviderFor(O, P))
return first;
if (!IsUndefined(second)) {
if (second.isProviderFor(O, P))
return first;
if (!IsUndefined(rest)) {
var iterator = GetIterator(rest);
while (true) {
var next = IteratorStep(iterator);
if (!next) {
return void 0;
}
var provider = IteratorValue(next);
if (provider.isProviderFor(O, P)) {
IteratorClose(iterator);
return provider;
}
}
}
}
}
if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) {
return fallback;
}
return void 0;
}
function getProvider(O, P) {
var providerMap = targetProviderMap.get(O);
var provider;
if (!IsUndefined(providerMap)) {
provider = providerMap.get(P);
}
if (!IsUndefined(provider)) {
return provider;
}
provider = getProviderNoCache(O, P);
if (!IsUndefined(provider)) {
if (IsUndefined(providerMap)) {
providerMap = new _Map();
targetProviderMap.set(O, providerMap);
}
providerMap.set(P, provider);
}
return provider;
}
function hasProvider(provider) {
if (IsUndefined(provider))
throw new TypeError();
return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider);
}
function setProvider(O, P, provider) {
if (!hasProvider(provider)) {
throw new Error("Metadata provider not registered.");
}
var existingProvider = getProvider(O, P);
if (existingProvider !== provider) {
if (!IsUndefined(existingProvider)) {
return false;
}
var providerMap = targetProviderMap.get(O);
if (IsUndefined(providerMap)) {
providerMap = new _Map();
targetProviderMap.set(O, providerMap);
}
providerMap.set(P, provider);
}
return true;
}
}
function GetOrCreateMetadataRegistry() {
var metadataRegistry2;
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
metadataRegistry2 = root.Reflect[registrySymbol];
}
if (IsUndefined(metadataRegistry2)) {
metadataRegistry2 = CreateMetadataRegistry();
}
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
Object.defineProperty(root.Reflect, registrySymbol, {
enumerable: false,
configurable: false,
writable: false,
value: metadataRegistry2
});
}
return metadataRegistry2;
}
function CreateMetadataProvider(registry) {
var metadata2 = new _WeakMap();
var provider = {
isProviderFor: function(O, P) {
var targetMetadata = metadata2.get(O);
if (IsUndefined(targetMetadata))
return false;
return targetMetadata.has(P);
},
OrdinaryDefineOwnMetadata: OrdinaryDefineOwnMetadata2,
OrdinaryHasOwnMetadata: OrdinaryHasOwnMetadata2,
OrdinaryGetOwnMetadata: OrdinaryGetOwnMetadata2,
OrdinaryOwnMetadataKeys: OrdinaryOwnMetadataKeys2,
OrdinaryDeleteMetadata
};
metadataRegistry.registerProvider(provider);
return provider;
function GetOrCreateMetadataMap(O, P, Create) {
var targetMetadata = metadata2.get(O);
var createdTargetMetadata = false;
if (IsUndefined(targetMetadata)) {
if (!Create)
return void 0;
targetMetadata = new _Map();
metadata2.set(O, targetMetadata);
createdTargetMetadata = true;
}
var metadataMap = targetMetadata.get(P);
if (IsUndefined(metadataMap)) {
if (!Create)
return void 0;
metadataMap = new _Map();
targetMetadata.set(P, metadataMap);
if (!registry.setProvider(O, P, provider)) {
targetMetadata.delete(P);
if (createdTargetMetadata) {
metadata2.delete(O);
}
throw new Error("Wrong provider for target.");
}
}
return metadataMap;
}
function OrdinaryHasOwnMetadata2(MetadataKey, O, P) {
var metadataMap = GetOrCreateMetadataMap(
O,
P,
/*Create*/
false
);
if (IsUndefined(metadataMap))
return false;
return ToBoolean(metadataMap.has(MetadataKey));
}
function OrdinaryGetOwnMetadata2(MetadataKey, O, P) {
var metadataMap = GetOrCreateMetadataMap(
O,
P,
/*Create*/
false
);
if (IsUndefined(metadataMap))
return void 0;
return metadataMap.get(MetadataKey);
}
function OrdinaryDefineOwnMetadata2(MetadataKey, MetadataValue, O, P) {
var metadataMap = GetOrCreateMetadataMap(
O,
P,
/*Create*/
true
);
metadataMap.set(MetadataKey, MetadataValue);
}
function OrdinaryOwnMetadataKeys2(O, P) {
var keys = [];
var metadataMap = GetOrCreateMetadataMap(
O,
P,
/*Create*/
false
);
if (IsUndefined(metadataMap))
return keys;
var keysObj = metadataMap.keys();
var iterator = GetIterator(keysObj);
var k = 0;
while (true) {
var next = IteratorStep(iterator);
if (!next) {
keys.length = k;
return keys;
}
var nextValue = IteratorValue(next);
try {
keys[k] = nextValue;
} catch (e) {
try {
IteratorClose(iterator);
} finally {
throw e;
}
}
k++;
}
}
function OrdinaryDeleteMetadata(MetadataKey, O, P) {
var metadataMap = GetOrCreateMetadataMap(
O,
P,
/*Create*/
false
);
if (IsUndefined(metadataMap))
return false;
if (!metadataMap.delete(MetadataKey))
return false;
if (metadataMap.size === 0) {
var targetMetadata = metadata2.get(O);
if (!IsUndefined(targetMetadata)) {
targetMetadata.delete(P);
if (targetMetadata.size === 0) {
metadata2.delete(targetMetadata);
}
}
}
return true;
}
}
function CreateFallbackProvider(reflect) {
var defineMetadata2 = reflect.defineMetadata, hasOwnMetadata2 = reflect.hasOwnMetadata, getOwnMetadata2 = reflect.getOwnMetadata, getOwnMetadataKeys2 = reflect.getOwnMetadataKeys, deleteMetadata2 = reflect.deleteMetadata;
var metadataOwner = new _WeakMap();
var provider = {
isProviderFor: function(O, P) {
var metadataPropertySet = metadataOwner.get(O);
if (!IsUndefined(metadataPropertySet)) {
return metadataPropertySet.has(P);
}
if (getOwnMetadataKeys2(O, P).length) {
if (IsUndefined(metadataPropertySet)) {
metadataPropertySet = new _Set();
metadataOwner.set(O, metadataPropertySet);
}
metadataPropertySet.add(P);
return true;
}
return false;
},
OrdinaryDefineOwnMetadata: defineMetadata2,
OrdinaryHasOwnMetadata: hasOwnMetadata2,
OrdinaryGetOwnMetadata: getOwnMetadata2,
OrdinaryOwnMetadataKeys: getOwnMetadataKeys2,
OrdinaryDeleteMetadata: deleteMetadata2
};
return provider;
}
function GetMetadataProvider(O, P, Create) {
var registeredProvider = metadataRegistry.getProvider(O, P);
if (!IsUndefined(registeredProvider)) {
return registeredProvider;
}
if (Create) {
if (metadataRegistry.setProvider(O, P, metadataProvider)) {
return metadataProvider;
}
throw new Error("Illegal state.");
}
return void 0;
}
function CreateMapPolyfill() {
var cacheSentinel = {};
var arraySentinel = [];
var MapIterator = (
/** @class */
function() {
function MapIterator2(keys, values, selector) {
this._index = 0;
this._keys = keys;
this._values = values;
this._selector = selector;
}
MapIterator2.prototype["@@iterator"] = function() {
return this;
};
MapIterator2.prototype[iteratorSymbol] = function() {
return this;
};
MapIterator2.prototype.next = function() {
var index2 = this._index;
if (index2 >= 0 && index2 < this._keys.length) {
var result = this._selector(this._keys[index2], this._values[index2]);
if (index2 + 1 >= this._keys.length) {
this._index = -1;
this._keys = arraySentinel;
this._values = arraySentinel;
} else {
this._index++;
}
return { value: result, done: false };
}
return { value: void 0, done: true };
};
MapIterator2.prototype.throw = function(error) {
if (this._index >= 0) {
this._index = -1;
this._keys = arraySentinel;
this._values = arraySentinel;
}
throw error;
};
MapIterator2.prototype.return = function(value) {
if (this._index >= 0) {
this._index = -1;
this._keys = arraySentinel;
this._values = arraySentinel;
}
return { value, done: true };
};
return MapIterator2;
}()
);
var Map2 = (
/** @class */
function() {
function Map3() {
this._keys = [];
this._values = [];
this._cacheKey = cacheSentinel;
this._cacheIndex = -2;
}
Object.defineProperty(Map3.prototype, "size", {
get: function() {
return this._keys.length;
},
enumerable: true,
configurable: true
});
Map3.prototype.has = function(key) {
return this._find(
key,
/*insert*/
false
) >= 0;
};
Map3.prototype.get = function(key) {
var index2 = this._find(
key,
/*insert*/
false
);
return index2 >= 0 ? this._values[index2] : void 0;
};
Map3.prototype.set = function(key, value) {
var index2 = this._find(
key,
/*insert*/
true
);
this._values[index2] = value;
return this;
};
Map3.prototype.delete = function(key) {
var index2 = this._find(
key,
/*insert*/
false
);
if (index2 >= 0) {
var size = this._keys.length;
for (var i = index2 + 1; i < size; i++) {
this._keys[i - 1] = this._keys[i];
this._values[i - 1] = this._values[i];
}
this._keys.length--;
this._values.length--;
if (SameValueZero(key, this._cacheKey)) {
this._cacheKey = cacheSentinel;
this._cacheIndex = -2;
}
return true;
}
return false;
};
Map3.prototype.clear = function() {
this._keys.length = 0;
this._values.length = 0;
this._cacheKey = cacheSentinel;
this._cacheIndex = -2;
};
Map3.prototype.keys = function() {
return new MapIterator(this._keys, this._values, getKey);
};
Map3.prototype.values = function() {
return new MapIterator(this._keys, this._values, getValue);
};
Map3.prototype.entries = function() {
return new MapIterator(this._keys, this._values, getEntry);
};
Map3.prototype["@@iterator"] = function() {
return this.entries();
};
Map3.prototype[iteratorSymbol] = function() {
return this.entries();
};
Map3.prototype._find = function(key, insert) {
if (!SameValueZero(this._cacheKey, key)) {
this._cacheIndex = -1;
for (var i = 0; i < this._keys.length; i++) {
if (SameValueZero(this._keys[i], key)) {
this._cacheIndex = i;
break;
}
}
}
if (this._cacheIndex < 0 && insert) {
this._cacheIndex = this._keys.length;
this._keys.push(key);
this._values.push(void 0);
}
return this._cacheIndex;
};
return Map3;
}()
);
return Map2;
function getKey(key, _) {
return key;
}
function getValue(_, value) {
return value;
}
function getEntry(key, value) {
return [key, value];
}
}
function CreateSetPolyfill() {
var Set2 = (
/** @class */
function() {
function Set3() {
this._map = new _Map();
}
Object.defineProperty(Set3.prototype, "size", {
get: function() {
return this._map.size;
},
enumerable: true,
configurable: true
});
Set3.prototype.has = function(value) {
return this._map.has(value);
};
Set3.prototype.add = function(value) {
return this._map.set(value, value), this;
};
Set3.prototype.delete = function(value) {
return this._map.delete(value);
};
Set3.prototype.clear = function() {
this._map.clear();
};
Set3.prototype.keys = function() {
return this._map.keys();
};
Set3.prototype.values = function() {
return this._map.keys();
};
Set3.prototype.entries = function() {
return this._map.entries();
};
Set3.prototype["@@iterator"] = function() {
return this.keys();
};
Set3.prototype[iteratorSymbol] = function() {
return this.keys();
};
return Set3;
}()
);
return Set2;
}
function CreateWeakMapPolyfill() {
var UUID_SIZE = 16;
var keys = HashMap.create();
var rootKey = CreateUniqueKey();
return (
/** @class */
function() {
function WeakMap2() {
this._key = CreateUniqueKey();
}
WeakMap2.prototype.has = function(target) {
var table = GetOrCreateWeakMapTable(
target,
/*create*/
false
);
return table !== void 0 ? HashMap.has(table, this._key) : false;
};
WeakMap2.prototype.get = function(target) {
var table = GetOrCreateWeakMapTable(
target,
/*create*/
false
);
return table !== void 0 ? HashMap.get(table, this._key) : void 0;
};
WeakMap2.prototype.set = function(target, value) {
var table = GetOrCreateWeakMapTable(
target,
/*create*/
true
);
table[this._key] = value;
return this;
};
WeakMap2.prototype.delete = function(target) {
var table = GetOrCreateWeakMapTable(
target,
/*create*/
false
);
return table !== void 0 ? delete table[this._key] : false;
};
WeakMap2.prototype.clear = function() {
this._key = CreateUniqueKey();
};
return WeakMap2;
}()
);
function CreateUniqueKey() {
var key;
do
key = "@@WeakMap@@" + CreateUUID();
while (HashMap.has(keys, key));
keys[key] = true;
return key;
}
function GetOrCreateWeakMapTable(target, create) {
if (!hasOwn.call(target, rootKey)) {
if (!create)
return void 0;
Object.defineProperty(target, rootKey, { value: HashMap.create() });
}
return target[rootKey];
}
function FillRandomBytes(buffer2, size) {
for (var i = 0; i < size; ++i)
buffer2[i] = Math.random() * 255 | 0;
return buffer2;
}
function GenRandomBytes(size) {
if (typeof Uint8Array === "function") {
if (typeof crypto !== "undefined")
return crypto.getRandomValues(new Uint8Array(size));
if (typeof msCrypto !== "undefined")
return msCrypto.getRandomValues(new Uint8Array(size));
return FillRandomBytes(new Uint8Array(size), size);
}
return FillRandomBytes(new Array(size), size);
}
function CreateUUID() {
var data = GenRandomBytes(UUID_SIZE);
data[6] = data[6] & 79 | 64;
data[8] = data[8] & 191 | 128;
var result = "";
for (var offset = 0; offset < UUID_SIZE; ++offset) {
var byte = data[offset];
if (offset === 4 || offset === 6 || offset === 8)
result += "-";
if (byte < 16)
result += "0";
result += byte.toString(16).toLowerCase();
}
return result;
}
}
function MakeDictionary(obj) {
obj.__ = void 0;
delete obj.__;
return obj;
}
});
})(Reflect2 || (Reflect2 = {}));
}
});
// src/decorators/dbconn.ts
import { mongoose } from "@typegoose/typegoose";
function dbconn(name) {
return (target) => {
name = name || "main";
const dbName = ("db_" + name).toUpperCase();
const url = process.env[dbName];
target["db"] = mongoose.createConnection(url, {});
};
}
// src/decorators/nojson.ts
var import_reflect_metadata = __toESM(require_Reflect(), 1);
// src/decorators/singleton.ts
var SINGLETON_KEY = Symbol();
var singleton = (classTarget) => new Proxy(classTarget, {
construct(target, argumentsList, newTarget) {
if (target.prototype !== newTarget.prototype) {
return Reflect.construct(target, argumentsList, newTarget);
}
if (!target[SINGLETON_KEY]) {
target[SINGLETON_KEY] = Reflect.construct(target, argumentsList, newTarget);
}
return target[SINGLETON_KEY];
}
});
// src/decorators/nojson.ts
var NoJsonClass = class {
noJsonPropSet = /* @__PURE__ */ new Set();
addKey(className, propertyKey) {
this.noJsonPropSet.add(className + "_" + propertyKey);
}
checkExist(className, propertyKey) {
return this.noJsonPropSet.has(className + "_" + propertyKey);
}
};
NoJsonClass = __decorateClass([
singleton
], NoJsonClass);
function noJson() {
return function(target, propertyKey) {
new NoJsonClass().addKey(target.constructor.name, propertyKey);
};
}
function checkJson(target, propertyKey) {
return !new NoJsonClass().checkExist(target.constructor.modelName, propertyKey);
}
// src/common/AsyncQueue.ts
function createAsyncQueue(opts = { dedupeConcurrent: false }) {
const { dedupeConcurrent } = opts;
let queue = [];
let running;
let nextPromise = new DeferredPromise();
const push = (task) => {
let taskPromise = new DeferredPromise();
if (dedupeConcurrent) {
queue = [];
if (nextPromise.started)
nextPromise = new DeferredPromise();
taskPromise = nextPromise;
}
queue.push(() => {
taskPromise.started = true;
task().then(taskPromise.resolve).catch(taskPromise.reject);
return taskPromise.promise;
});
if (!running)
running = start();
return taskPromise.promise;
};
const start = async () => {
while (queue.length) {
const task = queue.shift();
await task().catch(() => {
});
}
running = void 0;
};
return {
push,
flush: () => running || Promise.resolve(),
get size() {
return queue.length;
}
};
}
var DeferredPromise = class {
started = false;
resolve = () => {
};
reject = () => {
};
promise;
constructor() {
this.promise = new Promise((res, rej) => {
this.resolve = res;
this.reject = rej;
});
}
};
// src/models/UserLog.ts
import { getModelForClass, index, modelOptions, mongoose as mongoose2, prop } from "@typegoose/typegoose";
import { Severity } from "@typegoose/typegoose/lib/internal/constants";
// node_modules/bson/lib/bson.mjs
function isAnyArrayBuffer(value) {
return ["[object ArrayBuffer]", "[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(value));
}
function isUint8Array(value) {
return Object.prototype.toString.call(value) === "[object Uint8Array]";
}
function isRegExp(d) {
return Object.prototype.toString.call(d) === "[object RegExp]";
}
function isMap(d) {
return Object.prototype.toString.call(d) === "[object Map]";
}
function isDate(d) {
return Object.prototype.toString.call(d) === "[object Date]";
}
function defaultInspect(x, _options) {
return JSON.stringify(x, (k, v) => {
if (typeof v === "bigint") {
return { $numberLong: `${v}` };
} else if (isMap(v)) {
return Object.fromEntries(v);
}
return v;
});
}
function getStylizeFunction(options) {
const stylizeExists = options != null && typeof options === "object" && "stylize" in options && typeof options.stylize === "function";
if (stylizeExists) {
return options.stylize;
}
}
var BSON_MAJOR_VERSION = 6;
var BSON_INT32_MAX = 2147483647;
var BSON_INT32_MIN = -2147483648;
var BSON_INT64_MAX = Math.pow(2, 63) - 1;
var BSON_INT64_MIN = -Math.pow(2, 63);
var JS_INT_MAX = Math.pow(2, 53);
var JS_INT_MIN = -Math.pow(2, 53);
var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
var BSONType = Object.freeze({
double: 1,
string: 2,
object: 3,
array: 4,
binData: 5,
undefined: 6,
objectId: 7,
bool: 8,
date: 9,
null: 10,
regex: 11,
dbPointer: 12,
javascript: 13,
symbol: 14,
javascriptWithScope: 15,
int: 16,
timestamp: 17,
long: 18,
decimal: 19,
minKey: -1,
maxKey: 127
});
var BSONError = class extends Error {
get bsonError() {
return true;
}
get name() {
return "BSONError";
}
constructor(message) {
super(message);
}
static isBSONError(value) {
return value != null && typeof value === "object" && "bsonError" in value && value.bsonError === true && "name" in value && "message" in value && "stack" in value;
}
};
var BSONVersionError = class extends BSONError {
get name() {
return "BSONVersionError";
}
constructor() {
super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.x.x`);
}
};
var BSONRuntimeError = class extends BSONError {
get name() {
return "BSONRuntimeError";
}
constructor(message) {
super(message);
}
};
function nodejsMathRandomBytes(byteLength) {
return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
}
var nodejsRandomBytes = await (async () => {
try {
return (await import("crypto")).randomBytes;
} catch {
return nodejsMathRandomBytes;
}
})();
var nodeJsByteUtils = {
toLocalBufferType(potentialBuffer) {
if (Buffer.isBuffer(potentialBuffer)) {
return potentialBuffer;
}
if (ArrayBuffer.isView(potentialBuffer)) {
return Buffer.from(potentialBuffer.buffer, potentialBuffer.byteOffset, potentialBuffer.byteLength);
}
const stringTag = potentialBuffer?.[Symbol.toStringTag] ?? Object.prototype.toString.call(potentialBuffer);
if (stringTag === "ArrayBuffer" || stringTag === "SharedArrayBuffer" || stringTag === "[object ArrayBuffer]" || stringTag === "[object SharedArrayBuffer]") {
return Buffer.from(potentialBuffer);
}
throw new BSONError(`Cannot create Buffer from ${String(potentialBuffer)}`);
},
allocate(size) {
return Buffer.alloc(size);
},
equals(a, b) {
return nodeJsByteUtils.toLocalBufferType(a).equals(b);
},
fromNumberArray(array) {
return Buffer.from(array);
},
fromBase64(base64) {
return Buffer.from(base64, "base64");
},
toBase64(buffer2) {
return nodeJsByteUtils.toLocalBufferType(buffer2).toString("base64");
},
fromISO88591(codePoints) {
return Buffer.from(codePoints, "binary");
},
toISO88591(buffer2) {
return nodeJsByteUtils.toLocalBufferType(buffer2).toString("binary");
},
fromHex(hex) {
return Buffer.from(hex, "hex");
},
toHex(buffer2) {
return nodeJsByteUtils.toLocalBufferType(buffer2).toString("hex");
},
fromUTF8(text) {
return Buffer.from(text, "utf8");
},
toUTF8(buffer2, start, end) {
return nodeJsByteUtils.toLocalBufferType(buffer2).toString("utf8", start, end);
},
utf8ByteLength(input) {
return Buffer.byteLength(input, "utf8");
},
encodeUTF8Into(buffer2, source, byteOffset) {
return nodeJsByteUtils.toLocalBufferType(buffer2).write(source, byteOffset, void 0, "utf8");
},
randomBytes: nodejsRandomBytes
};
function isReactNative() {
const { navigator } = globalThis;
return typeof navigator === "object" && navigator.product === "ReactNative";
}
function webMathRandomBytes(byteLength) {
if (byteLength < 0) {
throw new RangeError(`The argument 'byteLength' is invalid. Received ${byteLength}`);
}
return webByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
}
var webRandomBytes = (() => {
const { crypto: crypto2 } = globalThis;
if (crypto2 != null && typeof crypto2.getRandomValues === "function") {
return (byteLength) => {
return crypto2.getRandomValues(webByteUtils.allocate(byteLength));
};
} else {
if (isReactNative()) {
const { console } = globalThis;
console?.warn?.("BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.");
}
return webMathRandomBytes;
}
})();
var HEX_DIGIT = /(\d|[a-f])/i;
var webByteUtils = {
toLocalBufferType(potentialUint8array) {
const stringTag = potentialUint8array?.[Symbol.toStringTag] ?? Object.prototype.toString.call(potentialUint8array);
if (stringTag === "Uint8Array") {
return potentialUint8array;
}
if (ArrayBuffer.isView(potentialUint8array)) {
return new Uint8Array(potentialUint8array.buffer.slice(potentialUint8array.byteOffset, potentialUint8array.byteOffset + potentialUint8array.byteLength));
}
if (stringTag === "ArrayBuffer" || stringTag === "SharedArrayBuffer" || stringTag === "[object ArrayBuffer]" || stringTag === "[object SharedArrayBuffer]") {
return new Uint8Array(potentialUint8array);
}
throw new BSONError(`Cannot make a Uint8Array from ${String(potentialUint8array)}`);
},
allocate(size) {
if (typeof size !== "number") {
throw new TypeError(`The "size" argument must be of type number. Received ${String(size)}`);
}
return new Uint8Array(size);
},
equals(a, b) {
if (a.byteLength !== b.byteLength) {
return false;
}
for (let i = 0; i < a.byteLength; i++) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
},
fromNumberArray(array) {
return Uint8Array.from(array);
},
fromBase64(base64) {
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
},
toBase64(uint8array) {
return btoa(webByteUtils.toISO88591(uint8array));
},
fromISO88591(codePoints) {
return Uint8Array.from(codePoints, (c) => c.charCodeAt(0) & 255);
},
toISO88591(uint8array) {
return Array.from(Uint16Array.from(uint8array), (b) => String.fromCharCode(b)).join("");
},
fromHex(hex) {
const evenLengthHex = hex.length % 2 === 0 ? hex : hex.slice(0, hex.length - 1);
const buffer2 = [];
for (let i = 0; i < evenLengthHex.length; i += 2) {
const firstDigit = evenLengthHex[i];
const secondDigit = evenLengthHex[i + 1];
if (!HEX_DIGIT.test(firstDigit)) {
break;
}
if (!HEX_DIGIT.test(secondDigit)) {
break;
}
const hexDigit = Number.parseInt(`${firstDigit}${secondDigit}`, 16);
buffer2.push(hexDigit);
}
return Uint8Array.from(buffer2);
},
toHex(uint8array) {
return Array.from(uint8array, (byte) => byte.toString(16).padStart(2, "0")).join("");
},
fromUTF8(text) {
return new TextEncoder().encode(text);
},
toUTF8(uint8array, start, end) {
return new TextDecoder("utf8", { fatal: false }).decode(uint8array.slice(start, end));
},
utf8ByteLength(input) {
return webByteUtils.fromUTF8(input).byteLength;
},
encodeUTF8Into(buffer2, source, byteOffset) {
const bytes = webByteUtils.fromUTF8(source);
buffer2.set(bytes, byteOffset);
return bytes.byteLength;
},
randomBytes: webRandomBytes
};
var hasGlobalBuffer = typeof Buffer === "function" && Buffer.prototype?._isBuffer !== true;
var ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
var BSONDataView = class extends DataView {
static fromUint8Array(input) {
return new DataView(input.buffer, input.byteOffset, input.byteLength);
}
};
var BSONValue = class {
get [Symbol.for("@@mdb.bson.version")]() {
return BSON_MAJOR_VERSION;
}
[Symbol.for("nodejs.util.inspect.custom")](depth, options, inspect) {
return this.inspect(depth, options, inspect);
}
};
var Binary = class _Binary extends BSONValue {
get _bsontype() {
return "Binary";
}
constructor(buffer2, subType) {
super();
if (!(buffer2 == null) && typeof buffer2 === "string" && !ArrayBuffer.isView(buffer2) && !isAnyArrayBuffer(buffer2) && !Array.isArray(buffer2)) {
throw new BSONError("Binary can only be constructed from Uint8Array or number[]");
}
this.sub_type = subType ?? _Binary.BSON_BINARY_SUBTYPE_DEFAULT;
if (buffer2 == null) {
this.buffer = ByteUtils.allocate(_Binary.BUFFER_SIZE);
this.position = 0;
} else {
this.buffer = Array.isArray(buffer2) ? ByteUtils.fromNumberArray(buffer2) : ByteUtils.toLocalBufferType(buffer2);
this.position = this.buffer.byteLength;
}
}
put(byteValue) {
if (typeof byteValue === "string" && byteValue.length !== 1) {
throw new BSONError("only accepts single character String");
} else if (typeof byteValue !== "number" && byteValue.length !== 1)
throw new BSONError("only accepts single character Uint8Array or Array");
let decodedByte;
if (typeof byteValue === "string") {
decodedByte = byteValue.charCodeAt(0);
} else if (typeof byteValue === "number") {
decodedByte = byteValue;
} else {
decodedByte = byteValue[0];
}
if (decodedByte < 0 || decodedByte > 255) {
throw new BSONError("only accepts number in a valid unsigned byte range 0-255");
}
if (this.buffer.byteLength > this.position) {
this.buffer[this.position++] = decodedByte;
} else {
const newSpace = ByteUtils.allocate(_Binary.BUFFER_SIZE + this.buffer.length);
newSpace.set(this.buffer, 0);
this.buffer = newSpace;
this.buffer[this.position++] = decodedByte;
}
}
write(sequence, offset) {
offset = typeof offset === "number" ? offset : this.position;
if (this.buffer.byteLength < offset + sequence.length) {
const newSpace = ByteUtils.allocate(this.buffer.byteLength + sequence.length);
newSpace.set(this.buffer, 0);
this.buffer = newSpace;
}
if (ArrayBuffer.isView(sequence)) {
this.buffer.set(ByteUtils.toLocalBufferType(sequence), offset);
this.position = offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
} else if (typeof sequence === "string") {
throw new BSONError("input cannot be string");
}
}
read(position, length) {
length = length && length > 0 ? length : this.position;
return this.buffer.slice(position, position + length);
}
value() {
return this.buffer.length === this.position ? this.buffer : this.buffer.subarray(0, this.position);
}
length() {
return this.position;
}
toJSON() {
return ByteUtils.toBase64(this.buffer);
}
toString(encoding) {
if (encoding === "hex")
return ByteUtils.toHex(this.buffer);
if (encoding === "base64")
return ByteUtils.toBase64(this.buffer);
if (encoding === "utf8" || encoding === "utf-8")
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
}
toExtendedJSON(options) {
options = options || {};
const base64String = ByteUtils.toBase64(this.buffer);
const subType = Number(this.sub_type).toString(16);
if (options.legacy) {
return {
$binary: base64String,
$type: subType.length === 1 ? "0" + subType : subType
};
}
return {
$binary: {
base64: base64String,
subType: subType.length === 1 ? "0" + subType : subType
}
};
}
toUUID() {
if (this.sub_type === _Binary.SUBTYPE_UUID) {
return new UUID(this.buffer.slice(0, this.position));
}
throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${_Binary.SUBTYPE_UUID}" is currently supported.`);
}
static createFromHexString(hex, subType) {
return new _Binary(ByteUtils.fromHex(hex), subType);
}
static createFromBase64(base64, subType) {
return new _Binary(ByteUtils.fromBase64(base64), subType);
}
static fromExtendedJSON(doc, options) {
options = options || {};
let data;
let type;
if ("$binary" in doc) {
if (options.legacy && typeof doc.$binary === "string" && "$type" in doc) {
type = doc.$type ? parseInt(doc.$type, 16) : 0;
data = ByteUtils.fromBase64(doc.$binary);
} else {
if (typeof doc.$binary !== "string") {
type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
data = ByteUtils.fromBase64(doc.$binary.base64);
}
}
} else if ("$uuid" in doc) {
type = 4;
data = UUID.bytesFromString(doc.$uuid);
}
if (!data) {
throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`);
}
return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new _Binary(data, type);
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
const base64 = ByteUtils.toBase64(this.buffer.subarray(0, this.position));
const base64Arg = inspect(base64, options);
const subTypeArg = inspect(this.sub_type, options);
return `Binary.createFromBase64(${base64Arg}, ${subTypeArg})`;
}
};
Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
Binary.BUFFER_SIZE = 256;
Binary.SUBTYPE_DEFAULT = 0;
Binary.SUBTYPE_FUNCTION = 1;
Binary.SUBTYPE_BYTE_ARRAY = 2;
Binary.SUBTYPE_UUID_OLD = 3;
Binary.SUBTYPE_UUID = 4;
Binary.SUBTYPE_MD5 = 5;
Binary.SUBTYPE_ENCRYPTED = 6;
Binary.SUBTYPE_COLUMN = 7;
Binary.SUBTYPE_USER_DEFINED = 128;
var UUID_BYTE_LENGTH = 16;
var UUID_WITHOUT_DASHES = /^[0-9A-F]{32}$/i;
var UUID_WITH_DASHES = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
var UUID = class _UUID extends Binary {
constructor(input) {
let bytes;
if (input == null) {
bytes = _UUID.generate();
} else if (input instanceof _UUID) {
bytes = ByteUtils.toLocalBufferType(new Uint8Array(input.buffer));
} else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
bytes = ByteUtils.toLocalBufferType(input);
} else if (typeof input === "string") {
bytes = _UUID.bytesFromString(input);
} else {
throw new BSONError("Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");
}
super(bytes, BSON_BINARY_SUBTYPE_UUID_NEW);
}
get id() {
return this.buffer;
}
set id(value) {
this.buffer = value;
}
toHexString(includeDashes = true) {
if (includeDashes) {
return [
ByteUtils.toHex(this.buffer.subarray(0, 4)),
ByteUtils.toHex(this.buffer.subarray(4, 6)),
ByteUtils.toHex(this.buffer.subarray(6, 8)),
ByteUtils.toHex(this.buffer.subarray(8, 10)),
ByteUtils.toHex(this.buffer.subarray(10, 16))
].join("-");
}
return ByteUtils.toHex(this.buffer);
}
toString(encoding) {
if (encoding === "hex")
return ByteUtils.toHex(this.id);
if (encoding === "base64")
return ByteUtils.toBase64(this.id);
return this.toHexString();
}
toJSON() {
return this.toHexString();
}
equals(otherId) {
if (!otherId) {
return false;
}
if (otherId instanceof _UUID) {
return ByteUtils.equals(otherId.id, this.id);
}
try {
return ByteUtils.equals(new _UUID(otherId).id, this.id);
} catch {
return false;
}
}
toBinary() {
return new Binary(this.id, Binary.SUBTYPE_UUID);
}
static generate() {
const bytes = ByteUtils.randomBytes(UUID_BYTE_LENGTH);
bytes[6] = bytes[6] & 15 | 64;
bytes[8] = bytes[8] & 63 | 128;
return bytes;
}
static isValid(input) {
if (!input) {
return false;
}
if (typeof input === "string") {
return _UUID.isValidUUIDString(input);
}
if (isUint8Array(input)) {
return input.byteLength === UUID_BYTE_LENGTH;
}
return input._bsontype === "Binary" && input.sub_type === this.SUBTYPE_UUID && input.buffer.byteLength === 16;
}
static createFromHexString(hexString) {
const buffer2 = _UUID.bytesFromString(hexString);
return new _UUID(buffer2);
}
static createFromBase64(base64) {
return new _UUID(ByteUtils.fromBase64(base64));
}
static bytesFromString(representation) {
if (!_UUID.isValidUUIDString(representation)) {
throw new BSONError("UUID string representation must be 32 hex digits or canonical hyphenated representation");
}
return ByteUtils.fromHex(representation.replace(/-/g, ""));
}
static isValidUUIDString(representation) {
return UUID_WITHOUT_DASHES.test(representation) || UUID_WITH_DASHES.test(representation);
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
return `new UUID(${inspect(this.toHexString(), options)})`;
}
};
var Code = class _Code extends BSONValue {
get _bsontype() {
return "Code";
}
constructor(code, scope) {
super();
this.code = code.toString();
this.scope = scope ?? null;
}
toJSON() {
if (this.scope != null) {
return { code: this.code, scope: this.scope };
}
return { code: this.code };
}
toExtendedJSON() {
if (this.scope) {
return { $code: this.code, $scope: this.scope };
}
return { $code: this.code };
}
static fromExtendedJSON(doc) {
return new _Code(doc.$code, doc.$scope);
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
let parametersString = inspect(this.code, options);
const multiLineFn = parametersString.includes("\n");
if (this.scope != null) {
parametersString += `,${multiLineFn ? "\n" : " "}${inspect(this.scope, options)}`;
}
const endingNewline = multiLineFn && this.scope === null;
return `new Code(${multiLineFn ? "\n" : ""}${parametersString}${endingNewline ? "\n" : ""})`;
}
};
function isDBRefLike(value) {
return value != null && typeof value === "object" && "$id" in value && value.$id != null && "$ref" in value && typeof value.$ref === "string" && (!("$db" in value) || "$db" in value && typeof value.$db === "string");
}
var DBRef = class _DBRef extends BSONValue {
get _bsontype() {
return "DBRef";
}
constructor(collection, oid, db, fields) {
super();
const parts = collection.split(".");
if (parts.length === 2) {
db = parts.shift();
collection = parts.shift();
}
this.collection = collection;
this.oid = oid;
this.db = db;
this.fields = fields || {};
}
get namespace() {
return this.collection;
}
set namespace(value) {
this.collection = value;
}
toJSON() {
const o = Object.assign({
$ref: this.collection,
$id: this.oid
}, this.fields);
if (this.db != null)
o.$db = this.db;
return o;
}
toExtendedJSON(options) {
options = options || {};
let o = {
$ref: this.collection,
$id: this.oid
};
if (options.legacy) {
return o;
}
if (this.db)
o.$db = this.db;
o = Object.assign(o, this.fields);
return o;
}
static fromExtendedJSON(doc) {
const copy = Object.assign({}, doc);
delete copy.$ref;
delete copy.$id;
delete copy.$db;
return new _DBRef(doc.$ref, doc.$id, doc.$db, copy);
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
const args = [
inspect(this.namespace, options),
inspect(this.oid, options),
...this.db ? [inspect(this.db, options)] : [],
...Object.keys(this.fields).length > 0 ? [inspect(this.fields, options)] : []
];
args[1] = inspect === defaultInspect ? `new ObjectId(${args[1]})` : args[1];
return `new DBRef(${args.join(", ")})`;
}
};
var wasm = void 0;
try {
wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11])), {}).exports;
} catch {
}
var TWO_PWR_16_DBL = 1 << 16;
var TWO_PWR_24_DBL = 1 << 24;
var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
var INT_CACHE = {};
var UINT_CACHE = {};
var MAX_INT64_STRING_LENGTH = 20;
var DECIMAL_REG_EX = /^(\+?0|(\+|-)?[1-9][0-9]*)$/;
var Long = class _Long extends BSONValue {
get _bsontype() {
return "Long";
}
get __isLong__() {
return true;
}
constructor(low = 0, high, unsigned) {
super();
if (typeof low === "bigint") {
Object.assign(this, _Long.fromBigInt(low, !!high));
} else if (typeof low === "string") {
Object.assign(this, _Long.fromString(low, !!high));
} else {
this.low = low | 0;
this.high = high | 0;
this.unsigned = !!unsigned;
}
}
static fromBits(lowBits, highBits, unsigned) {
return new _Long(lowBits, highBits, unsigned);
}
static fromInt(value, unsigned) {
let obj, cachedObj, cache;
if (unsigned) {
value >>>= 0;
if (cache = 0 <= value && value < 256) {
cachedObj = UINT_CACHE[value];
if (cachedObj)
return cachedObj;
}
obj = _Long.fromBits(value, (value | 0) < 0 ? -1 : 0, true);
if (cache)
UINT_CACHE[value] = obj;
return obj;
} else {
value |= 0;
if (cache = -128 <= value && value < 128) {
cachedObj = INT_CACHE[value];
if (cachedObj)
return cachedObj;
}
obj = _Long.fromBits(value, value < 0 ? -1 : 0, false);
if (cache)
INT_CACHE[value] = obj;
return obj;
}
}
static fromNumber(value, unsigned) {
if (isNaN(value))
return unsigned ? _Long.UZERO : _Long.ZERO;
if (unsigned) {
if (value < 0)
return _Long.UZERO;
if (value >= TWO_PWR_64_DBL)
return _Long.MAX_UNSIGNED_VALUE;
} else {
if (value <= -TWO_PWR_63_DBL)
return _Long.MIN_VALUE;
if (value + 1 >= TWO_PWR_63_DBL)
return _Long.MAX_VALUE;
}
if (value < 0)
return _Long.fromNumber(-value, unsigned).neg();
return _Long.fromBits(value % TWO_PWR_32_DBL | 0, value / TWO_PWR_32_DBL | 0, unsigned);
}
static fromBigInt(value, unsigned) {
return _Long.fromString(value.toString(), unsigned);
}
static fromString(str, unsigned, radix) {
if (str.length === 0)
throw new BSONError("empty string");
if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
return _Long.ZERO;
if (typeof unsigned === "number") {
radix = unsigned, unsigned = false;
} else {
unsigned = !!unsigned;
}
radix = radix || 10;
if (radix < 2 || 36 < radix)
throw new BSONError("radix");
let p;
if ((p = str.indexOf("-")) > 0)
throw new BSONError("interior hyphen");
else if (p === 0) {
return _Long.fromString(str.substring(1), unsigned, radix).neg();
}
const radixToPower = _Long.fromNumber(Math.pow(radix, 8));
let result = _Long.ZERO;
for (let i = 0; i < str.length; i += 8) {
const size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
if (size < 8) {
const power = _Long.fromNumber(Math.pow(radix, size));
result = result.mul(power).add(_Long.fromNumber(value));
} else {
result = result.mul(radixToPower);
result = result.add(_Long.fromNumber(value));
}
}
result.unsigned = unsigned;
return result;
}
static fromBytes(bytes, unsigned, le) {
return le ? _Long.fromBytesLE(bytes, unsigned) : _Long.fromBytesBE(bytes, unsigned);
}
static fromBytesLE(bytes, unsigned) {
return new _Long(bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24, bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24, unsigned);
}
static fromBytesBE(bytes, unsigned) {
return new _Long(bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7], bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], unsigned);
}
static isLong(value) {
return value != null && typeof value === "object" && "__isLong__" in value && value.__isLong__ === true;
}
static fromValue(val, unsigned) {
if (typeof val === "number")
return _Long.fromNumber(val, unsigned);
if (typeof val === "string")
return _Long.fromString(val, unsigned);
return _Long.fromBits(val.low, val.high, typeof unsigned === "boolean" ? unsigned : val.unsigned);
}
add(addend) {
if (!_Long.isLong(addend))
addend = _Long.fromValue(addend);
const a48 = this.high >>> 16;
const a32 = this.high & 65535;
const a16 = this.low >>> 16;
const a00 = this.low & 65535;
const b48 = addend.high >>> 16;
const b32 = addend.high & 65535;
const b16 = addend.low >>> 16;
const b00 = addend.low & 65535;
let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
c00 += a00 + b00;
c16 += c00 >>> 16;
c00 &= 65535;
c16 += a16 + b16;
c32 += c16 >>> 16;
c16 &= 65535;
c32 += a32 + b32;
c48 += c32 >>> 16;
c32 &= 65535;
c48 += a48 + b48;
c48 &= 65535;
return _Long.fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
}
and(other) {
if (!_Long.isLong(other))
other = _Long.fromValue(other);
return _Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned);
}
compare(other) {
if (!_Long.isLong(other))
other = _Long.fromValue(other);
if (this.eq(other))
return 0;
const thisNeg = this.isNegative(), otherNeg = other.isNegative();
if (thisNeg && !otherNeg)
return -1;
if (!thisNeg && otherNeg)
return 1;
if (!this.unsigned)
return this.sub(other).isNegative() ? -1 : 1;
return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
}
comp(other) {
return this.compare(other);
}
divide(divisor) {
if (!_Long.isLong(divisor))
divisor = _Long.fromValue(divisor);
if (divisor.isZero())
throw new BSONError("division by zero");
if (wasm) {
if (!this.unsigned && this.high === -2147483648 && divisor.low === -1 && divisor.high === -1) {
return this;
}
const low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
return _Long.fromBits(low, wasm.get_high(), this.unsigned);
}
if (this.isZero())
return this.unsigned ? _Long.UZERO : _Long.ZERO;
let approx, rem, res;
if (!this.unsigned) {
if (this.eq(_Long.MIN_VALUE)) {
if (divisor.eq(_Long.ONE) || divisor.eq(_Long.NEG_ONE))
return _Long.MIN_VALUE;
else if (divisor.eq(_Long.MIN_VALUE))
return _Long.ONE;
else {
const halfThis = this.shr(1);
approx = halfThis.div(divisor).shl(1);
if (approx.eq(_Long.ZERO)) {
return divisor.isNegative() ? _Long.ONE : _Long.NEG_ONE;
} else {
rem = this.sub(divisor.mul(approx));
res = approx.add(rem.div(divisor));
return res;
}
}
} else if (divisor.eq(_Long.MIN_VALUE))
return this.unsigned ? _Long.UZERO : _Long.ZERO;
if (this.isNegative()) {
if (divisor.isNegative())
return this.neg().div(divisor.neg());
return this.neg().div(divisor).neg();
} else if (divisor.isNegative())
return this.div(divisor.neg()).neg();
res = _Long.ZERO;
} else {
if (!divisor.unsigned)
divisor = divisor.toUnsigned();
if (divisor.gt(this))
return _Long.UZERO;
if (divisor.gt(this.shru(1)))
return _Long.UONE;
res = _Long.UZERO;
}
rem = this;
while (rem.gte(divisor)) {
approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
const log2 = Math.ceil(Math.log(approx) / Math.LN2);
const delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48);
let approxRes = _Long.fromNumber(approx);
let approxRem = approxRes.mul(divisor);
while (approxRem.isNegative() || approxRem.gt(rem)) {
approx -= delta;
approxRes = _Long.fromNumber(approx, this.unsigned);
approxRem = approxRes.mul(divisor);
}
if (approxRes.isZero())
approxRes = _Long.ONE;
res = res.add(approxRes);
rem = rem.sub(approxRem);
}
return res;
}
div(divisor) {
return this.divide(divisor);
}
equals(other) {
if (!_Long.isLong(other))
other = _Long.fromValue(other);
if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
return false;
return this.high === other.high && this.low === other.low;
}
eq(other) {
return this.equals(other);
}
getHighBits() {
return this.high;
}
getHighBitsUnsigned() {
return this.high >>> 0;
}
getLowBits() {
return this.low;
}
getLowBitsUnsigned() {
return this.low >>> 0;
}
getNumBitsAbs() {
if (this.isNegative()) {
return this.eq(_Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
}
const val = this.high !== 0 ? this.high : this.low;
let bit;
for (bit = 31; bit > 0; bit--)
if ((val & 1 << bit) !== 0)
break;
return this.high !== 0 ? bit + 33 : bit + 1;
}
greaterThan(other) {
return this.comp(other) > 0;
}
gt(other) {
return this.greaterThan(other);
}
greaterThanOrEqual(other) {
return this.comp(other) >= 0;
}
gte(other) {
return this.greaterThanOrEqual(other);
}
ge(other) {
return this.greaterThanOrEqual(other);
}
isEven() {
return (this.low & 1) === 0;
}
isNegative() {
return !this.unsigned && this.high < 0;
}
isOdd() {
return (this.low & 1) === 1;
}
isPositive() {
return this.unsigned || this.high >= 0;
}
isZero() {
return this.high === 0 && this.low === 0;
}
lessThan(other) {
return this.comp(other) < 0;
}
lt(other) {
return this.lessThan(other);
}
lessThanOrEqual(other) {
return this.comp(other) <= 0;
}
lte(other) {
return this.lessThanOrEqual(other);
}
modulo(divisor) {
if (!_Long.isLong(divisor))
divisor = _Long.fromValue(divisor);
if (wasm) {
const low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
return _Long.fromBits(low, wasm.get_high(), this.unsigned);
}
return this.sub(this.div(divisor).mul(divisor));
}
mod(divisor) {
return this.modulo(divisor);
}
rem(divisor) {
return this.modulo(divisor);
}
multiply(multiplier) {
if (this.isZero())
return _Long.ZERO;
if (!_Long.isLong(multiplier))
multiplier = _Long.fromValue(multiplier);
if (wasm) {
const low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
return _Long.fromBits(low, wasm.get_high(), this.unsigned);
}
if (multiplier.isZero())
return _Long.ZERO;
if (this.eq(_Long.MIN_VALUE))
return multiplier.isOdd() ? _Long.MIN_VALUE : _Long.ZERO;
if (multiplier.eq(_Long.MIN_VALUE))
return this.isOdd() ? _Long.MIN_VALUE : _Long.ZERO;
if (this.isNegative()) {
if (multiplier.isNegative())
return this.neg().mul(multiplier.neg());
else
return this.neg().mul(multiplier).neg();
} else if (multiplier.isNegative())
return this.mul(multiplier.neg()).neg();
if (this.lt(_Long.TWO_PWR_24) && multiplier.lt(_Long.TWO_PWR_24))
return _Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
const a48 = this.high >>> 16;
const a32 = this.high & 65535;
const a16 = this.low >>> 16;
const a00 = this.low & 65535;
const b48 = multiplier.high >>> 16;
const b32 = multiplier.high & 65535;
const b16 = multiplier.low >>> 16;
const b00 = multiplier.low & 65535;
let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
c00 += a00 * b00;
c16 += c00 >>> 16;
c00 &= 65535;
c16 += a16 * b00;
c32 += c16 >>> 16;
c16 &= 65535;
c16 += a00 * b16;
c32 += c16 >>> 16;
c16 &= 65535;
c32 += a32 * b00;
c48 += c32 >>> 16;
c32 &= 65535;
c32 += a16 * b16;
c48 += c32 >>> 16;
c32 &= 65535;
c32 += a00 * b32;
c48 += c32 >>> 16;
c32 &= 65535;
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
c48 &= 65535;
return _Long.fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
}
mul(multiplier) {
return this.multiply(multiplier);
}
negate() {
if (!this.unsigned && this.eq(_Long.MIN_VALUE))
return _Long.MIN_VALUE;
return this.not().add(_Long.ONE);
}
neg() {
return this.negate();
}
not() {
return _Long.fromBits(~this.low, ~this.high, this.unsigned);
}
notEquals(other) {
return !this.equals(other);
}
neq(other) {
return this.notEquals(other);
}
ne(other) {
return this.notEquals(other);
}
or(other) {
if (!_Long.isLong(other))
other = _Long.fromValue(other);
return _Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned);
}
shiftLeft(numBits) {
if (_Long.isLong(numBits))
numBits = numBits.toInt();
if ((numBits &= 63) === 0)
return this;
else if (numBits < 32)
return _Long.fromBits(this.low << numBits, this.high << numBits | this.low >>> 32 - numBits, this.unsigned);
else
return _Long.fromBits(0, this.low << numBits - 32, this.unsigned);
}
shl(numBits) {
return this.shiftLeft(numBits);
}
shiftRight(numBits) {
if (_Long.isLong(numBits))
numBits = numBits.toInt();
if ((numBits &= 63) === 0)
return this;
else if (numBits < 32)
return _Long.fromBits(this.low >>> numBits | this.high << 32 - numBits, this.high >> numBits, this.unsigned);
else
return _Long.fromBits(this.high >> numBits - 32, this.high >= 0 ? 0 : -1, this.unsigned);
}
shr(numBits) {
return this.shiftRight(numBits);
}
shiftRightUnsigned(numBits) {
if (_Long.isLong(numBits))
numBits = numBits.toInt();
numBits &= 63;
if (numBits === 0)
return this;
else {
const high = this.high;
if (numBits < 32) {
const low = this.low;
return _Long.fromBits(low >>> numBits | high << 32 - numBits, high >>> numBits, this.unsigned);
} else if (numBits === 32)
return _Long.fromBits(high, 0, this.unsigned);
else
return _Long.fromBits(high >>> numBits - 32, 0, this.unsigned);
}
}
shr_u(numBits) {
return this.shiftRightUnsigned(numBits);
}
shru(numBits) {
return this.shiftRightUnsigned(numBits);
}
subtract(subtrahend) {
if (!_Long.isLong(subtrahend))
subtrahend = _Long.fromValue(subtrahend);
return this.add(subtrahend.neg());
}
sub(subtrahend) {
return this.subtract(subtrahend);
}
toInt() {
return this.unsigned ? this.low >>> 0 : this.low;
}
toNumber() {
if (this.unsigned)
return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
}
toBigInt() {
return BigInt(this.toString());
}
toBytes(le) {
return le ? this.toBytesLE() : this.toBytesBE();
}
toBytesLE() {
const hi = this.high, lo = this.low;
return [
lo & 255,
lo >>> 8 & 255,
lo >>> 16 & 255,
lo >>> 24,
hi & 255,
hi >>> 8 & 255,
hi >>> 16 & 255,
hi >>> 24
];
}
toBytesBE() {
const hi = this.high, lo = this.low;
return [
hi >>> 24,
hi >>> 16 & 255,
hi >>> 8 & 255,
hi & 255,
lo >>> 24,
lo >>> 16 & 255,
lo >>> 8 & 255,
lo & 255
];
}
toSigned() {
if (!this.unsigned)
return this;
return _Long.fromBits(this.low, this.high, false);
}
toString(radix) {
radix = radix || 10;
if (radix < 2 || 36 < radix)
throw new BSONError("radix");
if (this.isZero())
return "0";
if (this.isNegative()) {
if (this.eq(_Long.MIN_VALUE)) {
const radixLong = _Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
return div.toString(radix) + rem1.toInt().toString(radix);
} else
return "-" + this.neg().toString(radix);
}
const radixToPower = _Long.fromNumber(Math.pow(radix, 6), this.unsigned);
let rem = this;
let result = "";
while (true) {
const remDiv = rem.div(radixToPower);
const intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
let digits = intval.toString(radix);
rem = remDiv;
if (rem.isZero()) {
return digits + result;
} else {
while (digits.length < 6)
digits = "0" + digits;
result = "" + digits + result;
}
}
}
toUnsigned() {
if (this.unsigned)
return this;
return _Long.fromBits(this.low, this.high, true);
}
xor(other) {
if (!_Long.isLong(other))
other = _Long.fromValue(other);
return _Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
}
eqz() {
return this.isZero();
}
le(other) {
return this.lessThanOrEqual(other);
}
toExtendedJSON(options) {
if (options && options.relaxed)
return this.toNumber();
return { $numberLong: this.toString() };
}
static fromExtendedJSON(doc, options) {
const { useBigInt64 = false, relaxed = true } = { ...options };
if (doc.$numberLong.length > MAX_INT64_STRING_LENGTH) {
throw new BSONError("$numberLong string is too long");
}
if (!DECIMAL_REG_EX.test(doc.$numberLong)) {
throw new BSONError(`$numberLong string "${doc.$numberLong}" is in an invalid format`);
}
if (useBigInt64) {
const bigIntResult = BigInt(doc.$numberLong);
return BigInt.asIntN(64, bigIntResult);
}
const longResult = _Long.fromString(doc.$numberLong);
if (relaxed) {
return longResult.toNumber();
}
return longResult;
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
const longVal = inspect(this.toString(), options);
const unsignedVal = this.unsigned ? `, ${inspect(this.unsigned, options)}` : "";
return `new Long(${longVal}${unsignedVal})`;
}
};
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
Long.MAX_UNSIGNED_VALUE = Long.fromBits(4294967295 | 0, 4294967295 | 0, true);
Long.ZERO = Long.fromInt(0);
Long.UZERO = Long.fromInt(0, true);
Long.ONE = Long.fromInt(1);
Long.UONE = Long.fromInt(1, true);
Long.NEG_ONE = Long.fromInt(-1);
Long.MAX_VALUE = Long.fromBits(4294967295 | 0, 2147483647 | 0, false);
Long.MIN_VALUE = Long.fromBits(0, 2147483648 | 0, false);
var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
var PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i;
var EXPONENT_MAX = 6111;
var EXPONENT_MIN = -6176;
var EXPONENT_BIAS = 6176;
var MAX_DIGITS = 34;
var NAN_BUFFER = ByteUtils.fromNumberArray([
124,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
].reverse());
var INF_NEGATIVE_BUFFER = ByteUtils.fromNumberArray([
248,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
].reverse());
var INF_POSITIVE_BUFFER = ByteUtils.fromNumberArray([
120,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
].reverse());
var EXPONENT_REGEX = /^([-+])?(\d+)?$/;
var COMBINATION_MASK = 31;
var EXPONENT_MASK = 16383;
var COMBINATION_INFINITY = 30;
var COMBINATION_NAN = 31;
function isDigit(value) {
return !isNaN(parseInt(value, 10));
}
function divideu128(value) {
const DIVISOR = Long.fromNumber(1e3 * 1e3 * 1e3);
let _rem = Long.fromNumber(0);
if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
return { quotient: value, rem: _rem };
}
for (let i = 0; i <= 3; i++) {
_rem = _rem.shiftLeft(32);
_rem = _rem.add(new Long(value.parts[i], 0));
value.parts[i] = _rem.div(DIVISOR).low;
_rem = _rem.modulo(DIVISOR);
}
return { quotient: value, rem: _rem };
}
function multiply64x2(left, right) {
if (!left && !right) {
return { high: Long.fromNumber(0), low: Long.fromNumber(0) };
}
const leftHigh = left.shiftRightUnsigned(32);
const leftLow = new Long(left.getLowBits(), 0);
const rightHigh = right.shiftRightUnsigned(32);
const rightLow = new Long(right.getLowBits(), 0);
let productHigh = leftHigh.multiply(rightHigh);
let productMid = leftHigh.multiply(rightLow);
const productMid2 = leftLow.multiply(rightHigh);
let productLow = leftLow.multiply(rightLow);
productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
productMid = new Long(productMid.getLowBits(), 0).add(productMid2).add(productLow.shiftRightUnsigned(32));
productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0));
return { high: productHigh, low: productLow };
}
function lessThan(left, right) {
const uhleft = left.high >>> 0;
const uhright = right.high >>> 0;
if (uhleft < uhright) {
return true;
} else if (uhleft === uhright) {
const ulleft = left.low >>> 0;
const ulright = right.low >>> 0;
if (ulleft < ulright)
return true;
}
return false;
}
function invalidErr(string, message) {
throw new BSONError(`"${string}" is not a valid Decimal128 string - ${message}`);
}
var Decimal128 = class _Decimal128 extends BSONValue {
get _bsontype() {
return "Decimal128";
}
constructor(bytes) {
super();
if (typeof bytes === "string") {
this.bytes = _Decimal128.fromString(bytes).bytes;
} else if (isUint8Array(bytes)) {
if (bytes.byteLength !== 16) {
throw new BSONError("Decimal128 must take a Buffer of 16 bytes");
}
this.bytes = bytes;
} else {
throw new BSONError("Decimal128 must take a Buffer or string");
}
}
static fromString(representation) {
return _Decimal128._fromString(representation, { allowRounding: false });
}
static fromStringWithRounding(representation) {
return _Decimal128._fromString(representation, { allowRounding: true });
}
static _fromString(representation, options) {
let isNegative = false;
let sawSign = false;
let sawRadix = false;
let foundNonZero = false;
let significantDigits = 0;
let nDigitsRead = 0;
let nDigits = 0;
let radixPosition = 0;
let firstNonZero = 0;
const digits = [0];
let nDigitsStored = 0;
let digitsInsert = 0;
let lastDigit = 0;
let exponent = 0;
let significandHigh = new Long(0, 0);
let significandLow = new Long(0, 0);
let biasedExponent = 0;
let index2 = 0;
if (representation.length >= 7e3) {
throw new BSONError("" + representation + " not a valid Decimal128 string");
}
const stringMatch = representation.match(PARSE_STRING_REGEXP);
const infMatch = representation.match(PARSE_INF_REGEXP);
const nanMatch = representation.match(PARSE_NAN_REGEXP);
if (!stringMatch && !infMatch && !nanMatch || representation.length === 0) {
throw new BSONError("" + representation + " not a valid Decimal128 string");
}
if (stringMatch) {
const unsignedNumber = stringMatch[2];
const e = stringMatch[4];
const expSign = stringMatch[5];
const expNumber = stringMatch[6];
if (e && expNumber === void 0)
invalidErr(representation, "missing exponent power");
if (e && unsignedNumber === void 0)
invalidErr(representation, "missing exponent base");
if (e === void 0 && (expSign || expNumber)) {
invalidErr(representation, "missing e before exponent");
}
}
if (representation[index2] === "+" || representation[index2] === "-") {
sawSign = true;
isNegative = representation[index2++] === "-";
}
if (!isDigit(representation[index2]) && representation[index2] !== ".") {
if (representation[index2] === "i" || representation[index2] === "I") {
return new _Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
} else if (representation[index2] === "N") {
return new _Decimal128(NAN_BUFFER);
}
}
while (isDigit(representation[index2]) || representation[index2] === ".") {
if (representation[index2] === ".") {
if (sawRadix)
invalidErr(representation, "contains multiple periods");
sawRadix = true;
index2 = index2 + 1;
continue;
}
if (nDigitsStored < MAX_DIGITS) {
if (representation[index2] !== "0" || foundNonZero) {
if (!foundNonZero) {
firstNonZero = nDigitsRead;
}
foundNonZero = true;
digits[digitsInsert++] = parseInt(representation[index2], 10);
nDigitsStored = nDigitsStored + 1;
}
}
if (foundNonZero)
nDigits = nDigits + 1;
if (sawRadix)
radixPosition = radixPosition + 1;
nDigitsRead = nDigitsRead + 1;
index2 = index2 + 1;
}
if (sawRadix && !nDigitsRead)
throw new BSONError("" + representation + " not a valid Decimal128 string");
if (representation[index2] === "e" || representation[index2] === "E") {
const match = representation.substr(++index2).match(EXPONENT_REGEX);
if (!match || !match[2])
return new _Decimal128(NAN_BUFFER);
exponent = parseInt(match[0], 10);
index2 = index2 + match[0].length;
}
if (representation[index2])
return new _Decimal128(NAN_BUFFER);
if (!nDigitsStored) {
digits[0] = 0;
nDigits = 1;
nDigitsStored = 1;
significantDigits = 0;
} else {
lastDigit = nDigitsStored - 1;
significantDigits = nDigits;
if (significantDigits !== 1) {
while (representation[firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)] === "0") {
significantDigits = significantDigits - 1;
}
}
}
if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
exponent = EXPONENT_MIN;
} else {
exponent = exponent - radixPosition;
}
while (exponent > EXPONENT_MAX) {
lastDigit = lastDigit + 1;
if (lastDigit >= MAX_DIGITS) {
if (significantDigits === 0) {
exponent = EXPONENT_MAX;
break;
}
invalidErr(representation, "overflow");
}
exponent = exponent - 1;
}
if (options.allowRounding) {
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
if (lastDigit === 0 && significantDigits < nDigitsStored) {
exponent = EXPONENT_MIN;
significantDigits = 0;
break;
}
if (nDigitsStored < nDigits) {
nDigits = nDigits - 1;
} else {
lastDigit = lastDigit - 1;
}
if (exponent < EXPONENT_MAX) {
exponent = exponent + 1;
} else {
const digitsString = digits.join("");
if (digitsString.match(/^0+$/)) {
exponent = EXPONENT_MAX;
break;
}
invalidErr(representation, "overflow");
}
}
if (lastDigit + 1 < significantDigits) {
let endOfString = nDigitsRead;
if (sawRadix) {
firstNonZero = firstNonZero + 1;
endOfString = endOfString + 1;
}
if (sawSign) {
firstNonZero = firstNonZero + 1;
endOfString = endOfString + 1;
}
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
let roundBit = 0;
if (roundDigit >= 5) {
roundBit = 1;
if (roundDigit === 5) {
roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
for (let i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
if (parseInt(representation[i], 10)) {
roundBit = 1;
break;
}
}
}
}
if (roundBit) {
let dIdx = lastDigit;
for (; dIdx >= 0; dIdx--) {
if (++digits[dIdx] > 9) {
digits[dIdx] = 0;
if (dIdx === 0) {
if (exponent < EXPONENT_MAX) {
exponent = exponent + 1;
digits[dIdx] = 1;
} else {
return new _Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
}
}
} else {
break;
}
}
}
}
} else {
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
if (lastDigit === 0) {
if (significantDigits === 0) {
exponent = EXPONENT_MIN;
break;
}
invalidErr(representation, "exponent underflow");
}
if (nDigitsStored < nDigits) {
if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== "0" && significantDigits !== 0) {
invalidErr(representation, "inexact rounding");
}
nDigits = nDigits - 1;
} else {
if (digits[lastDigit] !== 0) {
invalidErr(representation, "inexact rounding");
}
lastDigit = lastDigit - 1;
}
if (exponent < EXPONENT_MAX) {
exponent = exponent + 1;
} else {
invalidErr(representation, "overflow");
}
}
if (lastDigit + 1 < significantDigits) {
if (sawRadix) {
firstNonZero = firstNonZero + 1;
}
if (sawSign) {
firstNonZero = firstNonZero + 1;
}
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
if (roundDigit !== 0) {
invalidErr(representation, "inexact rounding");
}
}
}
significandHigh = Long.fromNumber(0);
significandLow = Long.fromNumber(0);
if (significantDigits === 0) {
significandHigh = Long.fromNumber(0);
significandLow = Long.fromNumber(0);
} else if (lastDigit < 17) {
let dIdx = 0;
significandLow = Long.fromNumber(digits[dIdx++]);
significandHigh = new Long(0, 0);
for (; dIdx <= lastDigit; dIdx++) {
significandLow = significandLow.multiply(Long.fromNumber(10));
significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
}
} else {
let dIdx = 0;
significandHigh = Long.fromNumber(digits[dIdx++]);
for (; dIdx <= lastDigit - 17; dIdx++) {
significandHigh = significandHigh.multiply(Long.fromNumber(10));
significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx]));
}
significandLow = Long.fromNumber(digits[dIdx++]);
for (; dIdx <= lastDigit; dIdx++) {
significandLow = significandLow.multiply(Long.fromNumber(10));
significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
}
}
const significand = multiply64x2(significandHigh, Long.fromString("100000000000000000"));
significand.low = significand.low.add(significandLow);
if (lessThan(significand.low, significandLow)) {
significand.high = significand.high.add(Long.fromNumber(1));
}
biasedExponent = exponent + EXPONENT_BIAS;
const dec = { low: Long.fromNumber(0), high: Long.fromNumber(0) };
if (significand.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))) {
dec.high = dec.high.or(Long.fromNumber(3).shiftLeft(61));
dec.high = dec.high.or(Long.fromNumber(biasedExponent).and(Long.fromNumber(16383).shiftLeft(47)));
dec.high = dec.high.or(significand.high.and(Long.fromNumber(140737488355327)));
} else {
dec.high = dec.high.or(Long.fromNumber(biasedExponent & 16383).shiftLeft(49));
dec.high = dec.high.or(significand.high.and(Long.fromNumber(562949953421311)));
}
dec.low = significand.low;
if (isNegative) {
dec.high = dec.high.or(Long.fromString("9223372036854775808"));
}
const buffer2 = ByteUtils.allocate(16);
index2 = 0;
buffer2[index2++] = dec.low.low & 255;
buffer2[index2++] = dec.low.low >> 8 & 255;
buffer2[index2++] = dec.low.low >> 16 & 255;
buffer2[index2++] = dec.low.low >> 24 & 255;
buffer2[index2++] = dec.low.high & 255;
buffer2[index2++] = dec.low.high >> 8 & 255;
buffer2[index2++] = dec.low.high >> 16 & 255;
buffer2[index2++] = dec.low.high >> 24 & 255;
buffer2[index2++] = dec.high.low & 255;
buffer2[index2++] = dec.high.low >> 8 & 255;
buffer2[index2++] = dec.high.low >> 16 & 255;
buffer2[index2++] = dec.high.low >> 24 & 255;
buffer2[index2++] = dec.high.high & 255;
buffer2[index2++] = dec.high.high >> 8 & 255;
buffer2[index2++] = dec.high.high >> 16 & 255;
buffer2[index2++] = dec.high.high >> 24 & 255;
return new _Decimal128(buffer2);
}
toString() {
let biased_exponent;
let significand_digits = 0;
const significand = new Array(36);
for (let i = 0; i < significand.length; i++)
significand[i] = 0;
let index2 = 0;
let is_zero = false;
let significand_msb;
let significand128 = { parts: [0, 0, 0, 0] };
let j, k;
const string = [];
index2 = 0;
const buffer2 = this.bytes;
const low = buffer2[index2++] | buffer2[index2++] << 8 | buffer2[index2++] << 16 | buffer2[index2++] << 24;
const midl = buffer2[index2++] | buffer2[index2++] << 8 | buffer2[index2++] << 16 | buffer2[index2++] << 24;
const midh = buffer2[index2++] | buffer2[index2++] << 8 | buffer2[index2++] << 16 | buffer2[index2++] << 24;
const high = buffer2[index2++] | buffer2[index2++] << 8 | buffer2[index2++] << 16 | buffer2[index2++] << 24;
index2 = 0;
const dec = {
low: new Long(low, midl),
high: new Long(midh, high)
};
if (dec.high.lessThan(Long.ZERO)) {
string.push("-");
}
const combination = high >> 26 & COMBINATION_MASK;
if (combination >> 3 === 3) {
if (combination === COMBINATION_INFINITY) {
return string.join("") + "Infinity";
} else if (combination === COMBINATION_NAN) {
return "NaN";
} else {
biased_exponent = high >> 15 & EXPONENT_MASK;
significand_msb = 8 + (high >> 14 & 1);
}
} else {
significand_msb = high >> 14 & 7;
biased_exponent = high >> 17 & EXPONENT_MASK;
}
const exponent = biased_exponent - EXPONENT_BIAS;
significand128.parts[0] = (high & 16383) + ((significand_msb & 15) << 14);
significand128.parts[1] = midh;
significand128.parts[2] = midl;
significand128.parts[3] = low;
if (significand128.parts[0] === 0 && significand128.parts[1] === 0 && significand128.parts[2] === 0 && significand128.parts[3] === 0) {
is_zero = true;
} else {
for (k = 3; k >= 0; k--) {
let least_digits = 0;
const result = divideu128(significand128);
significand128 = result.quotient;
least_digits = result.rem.low;
if (!least_digits)
continue;
for (j = 8; j >= 0; j--) {
significand[k * 9 + j] = least_digits % 10;
least_digits = Math.floor(least_digits / 10);
}
}
}
if (is_zero) {
significand_digits = 1;
significand[index2] = 0;
} else {
significand_digits = 36;
while (!significand[index2]) {
significand_digits = significand_digits - 1;
index2 = index2 + 1;
}
}
const scientific_exponent = significand_digits - 1 + exponent;
if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) {
if (significand_digits > 34) {
string.push(`${0}`);
if (exponent > 0)
string.push(`E+${exponent}`);
else if (exponent < 0)
string.push(`E${exponent}`);
return string.join("");
}
string.push(`${significand[index2++]}`);
significand_digits = significand_digits - 1;
if (significand_digits) {
string.push(".");
}
for (let i = 0; i < significand_digits; i++) {
string.push(`${significand[index2++]}`);
}
string.push("E");
if (scientific_exponent > 0) {
string.push(`+${scientific_exponent}`);
} else {
string.push(`${scientific_exponent}`);
}
} else {
if (exponent >= 0) {
for (let i = 0; i < significand_digits; i++) {
string.push(`${significand[index2++]}`);
}
} else {
let radix_position = significand_digits + exponent;
if (radix_position > 0) {
for (let i = 0; i < radix_position; i++) {
string.push(`${significand[index2++]}`);
}
} else {
string.push("0");
}
string.push(".");
while (radix_position++ < 0) {
string.push("0");
}
for (let i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
string.push(`${significand[index2++]}`);
}
}
}
return string.join("");
}
toJSON() {
return { $numberDecimal: this.toString() };
}
toExtendedJSON() {
return { $numberDecimal: this.toString() };
}
static fromExtendedJSON(doc) {
return _Decimal128.fromString(doc.$numberDecimal);
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
const d128string = inspect(this.toString(), options);
return `new Decimal128(${d128string})`;
}
};
var Double = class _Double extends BSONValue {
get _bsontype() {
return "Double";
}
constructor(value) {
super();
if (value instanceof Number) {
value = value.valueOf();
}
this.value = +value;
}
valueOf() {
return this.value;
}
toJSON() {
return this.value;
}
toString(radix) {
return this.value.toString(radix);
}
toExtendedJSON(options) {
if (options && (options.legacy || options.relaxed && isFinite(this.value))) {
return this.value;
}
if (Object.is(Math.sign(this.value), -0)) {
return { $numberDouble: "-0.0" };
}
return {
$numberDouble: Number.isInteger(this.value) ? this.value.toFixed(1) : this.value.toString()
};
}
static fromExtendedJSON(doc, options) {
const doubleValue = parseFloat(doc.$numberDouble);
return options && options.relaxed ? doubleValue : new _Double(doubleValue);
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
return `new Double(${inspect(this.value, options)})`;
}
};
var Int32 = class _Int32 extends BSONValue {
get _bsontype() {
return "Int32";
}
constructor(value) {
super();
if (value instanceof Number) {
value = value.valueOf();
}
this.value = +value | 0;
}
valueOf() {
return this.value;
}
toString(radix) {
return this.value.toString(radix);
}
toJSON() {
return this.value;
}
toExtendedJSON(options) {
if (options && (options.relaxed || options.legacy))
return this.value;
return { $numberInt: this.value.toString() };
}
static fromExtendedJSON(doc, options) {
return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new _Int32(doc.$numberInt);
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
return `new Int32(${inspect(this.value, options)})`;
}
};
var MaxKey = class _MaxKey extends BSONValue {
get _bsontype() {
return "MaxKey";
}
toExtendedJSON() {
return { $maxKey: 1 };
}
static fromExtendedJSON() {
return new _MaxKey();
}
inspect() {
return "new MaxKey()";
}
};
var MinKey = class _MinKey extends BSONValue {
get _bsontype() {
return "MinKey";
}
toExtendedJSON() {
return { $minKey: 1 };
}
static fromExtendedJSON() {
return new _MinKey();
}
inspect() {
return "new MinKey()";
}
};
var checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$");
var PROCESS_UNIQUE = null;
var kId = Symbol("id");
var ObjectId = class _ObjectId extends BSONValue {
get _bsontype() {
return "ObjectId";
}
constructor(inputId) {
super();
let workingId;
if (typeof inputId === "object" && inputId && "id" in inputId) {
if (typeof inputId.id !== "string" && !ArrayBuffer.isView(inputId.id)) {
throw new BSONError("Argument passed in must have an id that is of type string or Buffer");
}
if ("toHexString" in inputId && typeof inputId.toHexString === "function") {
workingId = ByteUtils.fromHex(inputId.toHexString());
} else {
workingId = inputId.id;
}
} else {
workingId = inputId;
}
if (workingId == null || typeof workingId === "number") {
this[kId] = _ObjectId.generate(typeof workingId === "number" ? workingId : void 0);
} else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
this[kId] = ByteUtils.toLocalBufferType(workingId);
} else if (typeof workingId === "string") {
if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
this[kId] = ByteUtils.fromHex(workingId);
} else {
throw new BSONError("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");
}
} else {
throw new BSONError("Argument passed in does not match the accepted types");
}
if (_ObjectId.cacheHexString) {
this.__id = ByteUtils.toHex(this.id);
}
}
get id() {
return this[kId];
}
set id(value) {
this[kId] = value;
if (_ObjectId.cacheHexString) {
this.__id = ByteUtils.toHex(value);
}
}
toHexString() {
if (_ObjectId.cacheHexString && this.__id) {
return this.__id;
}
const hexString = ByteUtils.toHex(this.id);
if (_ObjectId.cacheHexString && !this.__id) {
this.__id = hexString;
}
return hexString;
}
static getInc() {
return _ObjectId.index = (_ObjectId.index + 1) % 16777215;
}
static generate(time) {
if ("number" !== typeof time) {
time = Math.floor(Date.now() / 1e3);
}
const inc = _ObjectId.getInc();
const buffer2 = ByteUtils.allocate(12);
BSONDataView.fromUint8Array(buffer2).setUint32(0, time, false);
if (PROCESS_UNIQUE === null) {
PROCESS_UNIQUE = ByteUtils.randomBytes(5);
}
buffer2[4] = PROCESS_UNIQUE[0];
buffer2[5] = PROCESS_UNIQUE[1];
buffer2[6] = PROCESS_UNIQUE[2];
buffer2[7] = PROCESS_UNIQUE[3];
buffer2[8] = PROCESS_UNIQUE[4];
buffer2[11] = inc & 255;
buffer2[10] = inc >> 8 & 255;
buffer2[9] = inc >> 16 & 255;
return buffer2;
}
toString(encoding) {
if (encoding === "base64")
return ByteUtils.toBase64(this.id);
if (encoding === "hex")
return this.toHexString();
return this.toHexString();
}
toJSON() {
return this.toHexString();
}
static is(variable) {
return variable != null && typeof variable === "object" && "_bsontype" in variable && variable._bsontype === "ObjectId";
}
equals(otherId) {
if (otherId === void 0 || otherId === null) {
return false;
}
if (_ObjectId.is(otherId)) {
return this[kId][11] === otherId[kId][11] && ByteUtils.equals(this[kId], otherId[kId]);
}
if (typeof otherId === "string") {
return otherId.toLowerCase() === this.toHexString();
}
if (typeof otherId === "object" && typeof otherId.toHexString === "function") {
const otherIdString = otherId.toHexString();
const thisIdString = this.toHexString();
return typeof otherIdString === "string" && otherIdString.toLowerCase() === thisIdString;
}
return false;
}
getTimestamp() {
const timestamp = /* @__PURE__ */ new Date();
const time = BSONDataView.fromUint8Array(this.id).getUint32(0, false);
timestamp.setTime(Math.floor(time) * 1e3);
return timestamp;
}
static createPk() {
return new _ObjectId();
}
static createFromTime(time) {
const buffer2 = ByteUtils.fromNumberArray([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
BSONDataView.fromUint8Array(buffer2).setUint32(0, time, false);
return new _ObjectId(buffer2);
}
static createFromHexString(hexString) {
if (hexString?.length !== 24) {
throw new BSONError("hex string must be 24 characters");
}
return new _ObjectId(ByteUtils.fromHex(hexString));
}
static createFromBase64(base64) {
if (base64?.length !== 16) {
throw new BSONError("base64 string must be 16 characters");
}
return new _ObjectId(ByteUtils.fromBase64(base64));
}
static isValid(id) {
if (id == null)
return false;
try {
new _ObjectId(id);
return true;
} catch {
return false;
}
}
toExtendedJSON() {
if (this.toHexString)
return { $oid: this.toHexString() };
return { $oid: this.toString("hex") };
}
static fromExtendedJSON(doc) {
return new _ObjectId(doc.$oid);
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
return `new ObjectId(${inspect(this.toHexString(), options)})`;
}
};
ObjectId.index = Math.floor(Math.random() * 16777215);
function alphabetize(str) {
return str.split("").sort().join("");
}
var BSONRegExp = class _BSONRegExp extends BSONValue {
get _bsontype() {
return "BSONRegExp";
}
constructor(pattern, options) {
super();
this.pattern = pattern;
this.options = alphabetize(options ?? "");
if (this.pattern.indexOf("\0") !== -1) {
throw new BSONError(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);
}
if (this.options.indexOf("\0") !== -1) {
throw new BSONError(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);
}
for (let i = 0; i < this.options.length; i++) {
if (!(this.options[i] === "i" || this.options[i] === "m" || this.options[i] === "x" || this.options[i] === "l" || this.options[i] === "s" || this.options[i] === "u")) {
throw new BSONError(`The regular expression option [${this.options[i]}] is not supported`);
}
}
}
static parseOptions(options) {
return options ? options.split("").sort().join("") : "";
}
toExtendedJSON(options) {
options = options || {};
if (options.legacy) {
return { $regex: this.pattern, $options: this.options };
}
return { $regularExpression: { pattern: this.pattern, options: this.options } };
}
static fromExtendedJSON(doc) {
if ("$regex" in doc) {
if (typeof doc.$regex !== "string") {
if (doc.$regex._bsontype === "BSONRegExp") {
return doc;
}
} else {
return new _BSONRegExp(doc.$regex, _BSONRegExp.parseOptions(doc.$options));
}
}
if ("$regularExpression" in doc) {
return new _BSONRegExp(doc.$regularExpression.pattern, _BSONRegExp.parseOptions(doc.$regularExpression.options));
}
throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`);
}
inspect(depth, options, inspect) {
const stylize = getStylizeFunction(options) ?? ((v) => v);
inspect ??= defaultInspect;
const pattern = stylize(inspect(this.pattern), "regexp");
const flags = stylize(inspect(this.options), "regexp");
return `new BSONRegExp(${pattern}, ${flags})`;
}
};
var BSONSymbol = class _BSONSymbol extends BSONValue {
get _bsontype() {
return "BSONSymbol";
}
constructor(value) {
super();
this.value = value;
}
valueOf() {
return this.value;
}
toString() {
return this.value;
}
toJSON() {
return this.value;
}
toExtendedJSON() {
return { $symbol: this.value };
}
static fromExtendedJSON(doc) {
return new _BSONSymbol(doc.$symbol);
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
return `new BSONSymbol(${inspect(this.value, options)})`;
}
};
var LongWithoutOverridesClass = Long;
var Timestamp = class _Timestamp extends LongWithoutOverridesClass {
get _bsontype() {
return "Timestamp";
}
constructor(low) {
if (low == null) {
super(0, 0, true);
} else if (typeof low === "bigint") {
super(low, true);
} else if (Long.isLong(low)) {
super(low.low, low.high, true);
} else if (typeof low === "object" && "t" in low && "i" in low) {
if (typeof low.t !== "number" && (typeof low.t !== "object" || low.t._bsontype !== "Int32")) {
throw new BSONError("Timestamp constructed from { t, i } must provide t as a number");
}
if (typeof low.i !== "number" && (typeof low.i !== "object" || low.i._bsontype !== "Int32")) {
throw new BSONError("Timestamp constructed from { t, i } must provide i as a number");
}
const t = Number(low.t);
const i = Number(low.i);
if (t < 0 || Number.isNaN(t)) {
throw new BSONError("Timestamp constructed from { t, i } must provide a positive t");
}
if (i < 0 || Number.isNaN(i)) {
throw new BSONError("Timestamp constructed from { t, i } must provide a positive i");
}
if (t > 4294967295) {
throw new BSONError("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");
}
if (i > 4294967295) {
throw new BSONError("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");
}
super(i, t, true);
} else {
throw new BSONError("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }");
}
}
toJSON() {
return {
$timestamp: this.toString()
};
}
static fromInt(value) {
return new _Timestamp(Long.fromInt(value, true));
}
static fromNumber(value) {
return new _Timestamp(Long.fromNumber(value, true));
}
static fromBits(lowBits, highBits) {
return new _Timestamp({ i: lowBits, t: highBits });
}
static fromString(str, optRadix) {
return new _Timestamp(Long.fromString(str, true, optRadix));
}
toExtendedJSON() {
return { $timestamp: { t: this.high >>> 0, i: this.low >>> 0 } };
}
static fromExtendedJSON(doc) {
const i = Long.isLong(doc.$timestamp.i) ? doc.$timestamp.i.getLowBitsUnsigned() : doc.$timestamp.i;
const t = Long.isLong(doc.$timestamp.t) ? doc.$timestamp.t.getLowBitsUnsigned() : doc.$timestamp.t;
return new _Timestamp({ t, i });
}
inspect(depth, options, inspect) {
inspect ??= defaultInspect;
const t = inspect(this.high >>> 0, options);
const i = inspect(this.low >>> 0, options);
return `new Timestamp({ t: ${t}, i: ${i} })`;
}
};
Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
var JS_INT_MAX_LONG = Long.fromNumber(JS_INT_MAX);
var JS_INT_MIN_LONG = Long.fromNumber(JS_INT_MIN);
var NUMBER_SPACE = new DataView(new ArrayBuffer(8), 0, 8);
var FOUR_BYTE_VIEW_ON_NUMBER = new Uint8Array(NUMBER_SPACE.buffer, 0, 4);
var EIGHT_BYTE_VIEW_ON_NUMBER = new Uint8Array(NUMBER_SPACE.buffer, 0, 8);
function isBSONType(value) {
return value != null && typeof value === "object" && "_bsontype" in value && typeof value._bsontype === "string";
}
var keysToCodecs = {
$oid: ObjectId,
$binary: Binary,
$uuid: Binary,
$symbol: BSONSymbol,
$numberInt: Int32,
$numberDecimal: Decimal128,
$numberDouble: Double,
$numberLong: Long,
$minKey: MinKey,
$maxKey: MaxKey,
$regex: BSONRegExp,
$regularExpression: BSONRegExp,
$timestamp: Timestamp
};
function deserializeValue(value, options = {}) {
if (typeof value === "number") {
const in32BitRange = value <= BSON_INT32_MAX && value >= BSON_INT32_MIN;
const in64BitRange = value <= BSON_INT64_MAX && value >= BSON_INT64_MIN;
if (options.relaxed || options.legacy) {
return value;
}
if (Number.isInteger(value) && !Object.is(value, -0)) {
if (in32BitRange) {
return new Int32(value);
}
if (in64BitRange) {
if (options.useBigInt64) {
return BigInt(value);
}
return Long.fromNumber(value);
}
}
return new Double(value);
}
if (value == null || typeof value !== "object")
return value;
if (value.$undefined)
return null;
const keys = Object.keys(value).filter((k) => k.startsWith("$") && value[k] != null);
for (let i = 0; i < keys.length; i++) {
const c = keysToCodecs[keys[i]];
if (c)
return c.fromExtendedJSON(value, options);
}
if (value.$date != null) {
const d = value.$date;
const date = /* @__PURE__ */ new Date();
if (options.legacy) {
if (typeof d === "number")
date.setTime(d);
else if (typeof d === "string")
date.setTime(Date.parse(d));
else if (typeof d === "bigint")
date.setTime(Number(d));
else
throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
} else {
if (typeof d === "string")
date.setTime(Date.parse(d));
else if (Long.isLong(d))
date.setTime(d.toNumber());
else if (typeof d === "number" && options.relaxed)
date.setTime(d);
else if (typeof d === "bigint")
date.setTime(Number(d));
else
throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
}
return date;
}
if (value.$code != null) {
const copy = Object.assign({}, value);
if (value.$scope) {
copy.$scope = deserializeValue(value.$scope);
}
return Code.fromExtendedJSON(value);
}
if (isDBRefLike(value) || value.$dbPointer) {
const v = value.$ref ? value : value.$dbPointer;
if (v instanceof DBRef)
return v;
const dollarKeys = Object.keys(v).filter((k) => k.startsWith("$"));
let valid = true;
dollarKeys.forEach((k) => {
if (["$ref", "$id", "$db"].indexOf(k) === -1)
valid = false;
});
if (valid)
return DBRef.fromExtendedJSON(v);
}
return value;
}
function serializeArray(array, options) {
return array.map((v, index2) => {
options.seenObjects.push({ propertyName: `index ${index2}`, obj: null });
try {
return serializeValue(v, options);
} finally {
options.seenObjects.pop();
}
});
}
function getISOString(date) {
const isoStr = date.toISOString();
return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + "Z";
}
function serializeValue(value, options) {
if (value instanceof Map || isMap(value)) {
const obj = /* @__PURE__ */ Object.create(null);
for (const [k, v] of value) {
if (typeof k !== "string") {
throw new BSONError("Can only serialize maps with string keys");
}
obj[k] = v;
}
return serializeValue(obj, options);
}
if ((typeof value === "object" || typeof value === "function") && value !== null) {
const index2 = options.seenObjects.findIndex((entry) => entry.obj === value);
if (index2 !== -1) {
const props = options.seenObjects.map((entry) => entry.propertyName);
const leadingPart = props.slice(0, index2).map((prop2) => `${prop2} -> `).join("");
const alreadySeen = props[index2];
const circularPart = " -> " + props.slice(index2 + 1, props.length - 1).map((prop2) => `${prop2} -> `).join("");
const current = props[props.length - 1];
const leadingSpace = " ".repeat(leadingPart.length + alreadySeen.length / 2);
const dashes = "-".repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
throw new BSONError(`Converting circular structure to EJSON:
${leadingPart}${alreadySeen}${circularPart}${current}
${leadingSpace}\\${dashes}/`);
}
options.seenObjects[options.seenObjects.length - 1].obj = value;
}
if (Array.isArray(value))
return serializeArray(value, options);
if (value === void 0)
return null;
if (value instanceof Date || isDate(value)) {
const dateNum = value.getTime(), inRange = dateNum > -1 && dateNum < 2534023188e5;
if (options.legacy) {
return options.relaxed && inRange ? { $date: value.getTime() } : { $date: getISOString(value) };
}
return options.relaxed && inRange ? { $date: getISOString(value) } : { $date: { $numberLong: value.getTime().toString() } };
}
if (typeof value === "number" && (!options.relaxed || !isFinite(value))) {
if (Number.isInteger(value) && !Object.is(value, -0)) {
if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
return { $numberInt: value.toString() };
}
if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX) {
return { $numberLong: value.toString() };
}
}
return { $numberDouble: Object.is(value, -0) ? "-0.0" : value.toString() };
}
if (typeof value === "bigint") {
if (!options.relaxed) {
return { $numberLong: BigInt.asIntN(64, value).toString() };
}
return Number(BigInt.asIntN(64, value));
}
if (value instanceof RegExp || isRegExp(value)) {
let flags = value.flags;
if (flags === void 0) {
const match = value.toString().match(/[gimuy]*$/);
if (match) {
flags = match[0];
}
}
const rx = new BSONRegExp(value.source, flags);
return rx.toExtendedJSON(options);
}
if (value != null && typeof value === "object")
return serializeDocument(value, options);
return value;
}
var BSON_TYPE_MAPPINGS = {
Binary: (o) => new Binary(o.value(), o.sub_type),
Code: (o) => new Code(o.code, o.scope),
DBRef: (o) => new DBRef(o.collection || o.namespace, o.oid, o.db, o.fields),
Decimal128: (o) => new Decimal128(o.bytes),
Double: (o) => new Double(o.value),
Int32: (o) => new Int32(o.value),
Long: (o) => Long.fromBits(o.low != null ? o.low : o.low_, o.low != null ? o.high : o.high_, o.low != null ? o.unsigned : o.unsigned_),
MaxKey: () => new MaxKey(),
MinKey: () => new MinKey(),
ObjectId: (o) => new ObjectId(o),
BSONRegExp: (o) => new BSONRegExp(o.pattern, o.options),
BSONSymbol: (o) => new BSONSymbol(o.value),
Timestamp: (o) => Timestamp.fromBits(o.low, o.high)
};
function serializeDocument(doc, options) {
if (doc == null || typeof doc !== "object")
throw new BSONError("not an object instance");
const bsontype = doc._bsontype;
if (typeof bsontype === "undefined") {
const _doc = {};
for (const name of Object.keys(doc)) {
options.seenObjects.push({ propertyName: name, obj: null });
try {
const value = serializeValue(doc[name], options);
if (name === "__proto__") {
Object.defineProperty(_doc, name, {
value,
writable: true,
enumerable: true,
configurable: true
});
} else {
_doc[name] = value;
}
} finally {
options.seenObjects.pop();
}
}
return _doc;
} else if (doc != null && typeof doc === "object" && typeof doc._bsontype === "string" && doc[Symbol.for("@@mdb.bson.version")] !== BSON_MAJOR_VERSION) {
throw new BSONVersionError();
} else if (isBSONType(doc)) {
let outDoc = doc;
if (typeof outDoc.toExtendedJSON !== "function") {
const mapper = BSON_TYPE_MAPPINGS[doc._bsontype];
if (!mapper) {
throw new BSONError("Unrecognized or invalid _bsontype: " + doc._bsontype);
}
outDoc = mapper(outDoc);
}
if (bsontype === "Code" && outDoc.scope) {
outDoc = new Code(outDoc.code, serializeValue(outDoc.scope, options));
} else if (bsontype === "DBRef" && outDoc.oid) {
outDoc = new DBRef(serializeValue(outDoc.collection, options), serializeValue(outDoc.oid, options), serializeValue(outDoc.db, options), serializeValue(outDoc.fields, options));
}
return outDoc.toExtendedJSON(options);
} else {
throw new BSONError("_bsontype must be a string, but was: " + typeof bsontype);
}
}
function parse(text, options) {
const ejsonOptions = {
useBigInt64: options?.useBigInt64 ?? false,
relaxed: options?.relaxed ?? true,
legacy: options?.legacy ?? false
};
return JSON.parse(text, (key, value) => {
if (key.indexOf("\0") !== -1) {
throw new BSONError(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(key)}`);
}
return deserializeValue(value, ejsonOptions);
});
}
function stringify(value, replacer, space, options) {
if (space != null && typeof space === "object") {
options = space;
space = 0;
}
if (replacer != null && typeof replacer === "object" && !Array.isArray(replacer)) {
options = replacer;
replacer = void 0;
space = 0;
}
const serializeOptions = Object.assign({ relaxed: true, legacy: false }, options, {
seenObjects: [{ propertyName: "(root)", obj: null }]
});
const doc = serializeValue(value, serializeOptions);
return JSON.stringify(doc, replacer, space);
}
function EJSONserialize(value, options) {
options = options || {};
return JSON.parse(stringify(value, options));
}
function EJSONdeserialize(ejson, options) {
options = options || {};
return parse(JSON.stringify(ejson), options);
}
var EJSON = /* @__PURE__ */ Object.create(null);
EJSON.parse = parse;
EJSON.stringify = stringify;
EJSON.serialize = EJSONserialize;
EJSON.deserialize = EJSONdeserialize;
Object.freeze(EJSON);
var MAXSIZE = 1024 * 1024 * 17;
var buffer = ByteUtils.allocate(MAXSIZE);
// src/models/Base.ts
var jsonExcludeKeys = ["updatedAt", "__v"];
var saveExcludeKeys = ["createdAt", "updatedAt", "__v", "_id"];
var isTrue = (obj) => {
return obj === "true" || obj === "TRUE" || obj === "True" || obj === "on" || obj === "ON" || obj === true || obj === 1 || obj === "1" || obj === "YES" || obj === "yes";
};
var BaseModule = class {
static db;
updateFromReq(data) {
for (let key in data) {
if (saveExcludeKeys.indexOf(key) == -1) {
this[key] = data[key];
}
}
}
/**
* 插入或更新
* @param condition
* @param data
*/
static insertOrUpdate(condition, data) {
return this.findOneAndUpdate(condition, data, { upsert: true, new: true, setDefaultsOnInsert: true });
}
/**
* 虚拟删除
* @param {string[]} ids
*/
static deleteVirtual(ids) {
return this.updateMany(
// @ts-ignore
{
_id: { $in: ids }
},
{
$set: {
deleted: true,
deleteTime: /* @__PURE__ */ new Date()
}
}
);
}
/**
* 自定义分页查询
* @param data
* @param {boolean} json
*/
static async pageQuery(data, json = false) {
let { start, limit, page } = data;
limit = +limit || 10;
start = +start || (+page - 1) * limit || 0;
let { opt, sort } = this.parseQueryParam(data);
let records = await this.find(opt).sort(sort).skip(start).limit(limit);
let total = await this.countDocuments(opt);
if (json) {
records.map((o) => o.toJson());
}
return { records, total, start, limit };
}
toJson() {
let result = {};
for (let key in this._doc) {
if (checkJson(this, key + "") && jsonExcludeKeys.indexOf(key) == -1) {
result[key] = this[key];
}
}
return result;
}
/**
* 通用的查询条件拼接方法
* @param {{}} params req.params
* @param options
* sort: 排序 比如: {createdAt: 1} 默认是 {_id: 1}
* opt: 设置一些特殊的过滤条件, 比如{deleted: 0}
* timeKey: 如果需要查询创建时间, 而且创建时间不为 createdAt, 可以用此字段设置
* matchKey: 指定关键字查询的匹配字段, 可为string或[string]
*
* @return {{opt: any, sort: {_id: number}}}
*/
static parseQueryParam(params, options) {
const opt = { deleted: { $ne: true } };
let obj = this.schema.paths;
for (let key in params) {
if (key !== "sort" && obj.hasOwnProperty(key)) {
switch (obj[key].instance) {
case "String":
opt[key] = { $regex: params[key], $options: "i" };
break;
case "Number":
opt[key] = params[key];
break;
case "Array":
if (Array.isArray(params[key])) {
opt[key] = { $in: params[key] };
} else {
opt[key] = params[key];
}
break;
case "Date":
break;
case "Boolean":
opt[key] = isTrue(params[key]);
break;
case "ObjectID":
if (/^[0-9a-fA-F]{24}$/.test(params[key])) {
opt[key] = new ObjectId(params[key]);
}
break;
}
}
}
if (params.hasOwnProperty("key") && params["key"]) {
let orArr = [];
if (options?.matchKey) {
if (Array.isArray(options?.matchKey)) {
for (let key in options?.matchKey) {
let _tmp = {};
_tmp[key] = { $regex: params["key"], $options: "i" };
orArr.push(_tmp);
}
} else {
let _tmp = {};
_tmp[options.matchKey] = { $regex: params["key"], $options: "i" };
orArr.push(_tmp);
}
} else {
for (let key in obj) {
if (obj[key].instance === "String") {
let _tmp = {};
_tmp[key] = { $regex: params["key"], $options: "i" };
orArr.push(_tmp);
}
}
}
Object.assign(opt, { $or: orArr });
}
let timeKey = options?.timeKey ? options.timeKey : "createdAt";
if (params.hasOwnProperty("timeBegin") && !params.hasOwnProperty("timeEnd")) {
let timeBegin = params["timeBegin"];
if (!(timeBegin instanceof Date)) {
timeBegin = new Date(parseInt(timeBegin));
}
opt[timeKey] = { $gte: timeBegin };
} else if (params.hasOwnProperty("timeBegin") && params.hasOwnProperty("timeEnd")) {
let timeBegin = params["timeBegin"];
if (!(timeBegin instanceof Date)) {
timeBegin = new Date(parseInt(timeBegin));
}
let timeEnd = params["timeEnd"];
if (!(timeEnd instanceof Date)) {
timeEnd = new Date(parseInt(timeEnd));
}
let tmpB = {};
tmpB[timeKey] = { $gte: timeBegin };
let tmpE = {};
tmpE[timeKey] = { $lte: timeEnd };
opt["$and"] = [tmpB, tmpE];
} else if (!params.hasOwnProperty("timeBegin") && params.hasOwnProperty("timeEnd")) {
let timeEnd = params["timeEnd"];
if (!(timeEnd instanceof Date)) {
timeEnd = new Date(parseInt(timeEnd));
}
opt[timeKey] = { $lte: timeEnd };
}
if (options?.opt) {
Object.assign(opt, options.opt);
}
let sort = { _id: 1 };
if (params.hasOwnProperty("sort")) {
sort = params["sort"];
}
return { opt, sort };
}
getTimestampOfID() {
return this._id.getTimestamp();
}
};
// src/models/UserLog.ts
var UserLogClass = class extends BaseModule {
user;
name;
method;
path;
referer;
user_agent;
ip;
params;
};
__decorateClass([
prop()
], UserLogClass.prototype, "user", 2);
__decorateClass([
prop()
], UserLogClass.prototype, "name", 2);
__decorateClass([
prop()
], UserLogClass.prototype, "method", 2);
__decorateClass([
prop()
], UserLogClass.prototype, "path", 2);
__decorateClass([
prop()
], UserLogClass.prototype, "referer", 2);
__decorateClass([
prop()
], UserLogClass.prototype, "user_agent", 2);
__decorateClass([
prop()
], UserLogClass.prototype, "ip", 2);
__decorateClass([
prop({ type: mongoose2.Schema.Types.Mixed })
], UserLogClass.prototype, "params", 2);
UserLogClass = __decorateClass([
dbconn(),
index({ user: 1 }, { unique: false }),
index({ name: 1 }, { unique: false }),
modelOptions({ schemaOptions: { collection: "user_log", timestamps: true }, options: { allowMixed: Severity.ALLOW } })
], UserLogClass);
var UserLog = getModelForClass(UserLogClass, { existingConnection: UserLogClass["db"] });
// src/queue/logger.queue.ts
var LoggerQueue = class {
queue;
constructor() {
this.queue = createAsyncQueue();
}
addLog(name, req, logObj = {}) {
this.queue.push(async () => {
const user = req.user;
const ip = req.headers["x-forwarded-for"] || req.ip;
const path = req.url;
const params = req.method === "GET" ? req.query : req.body;
const dataObj = JSON.stringify(logObj) === "{}" ? params : logObj;
try {
const history = new UserLog({
user: user ? user.id : "",
path,
method: req.method,
params: dataObj,
referer: req.headers["referer"],
user_agent: req.headers["user-agent"],
ip,
name
});
await history.save();
} catch (err) {
logger.error("error add user log: ");
logger.error(err);
}
});
}
};
LoggerQueue = __decorateClass([
singleton
], LoggerQueue);
// src/logger/logger.ts
import { colorConsole } from "tracer";
var level = process.env.NODE_ENV === "production" ? "info" : "log";
var _logger = colorConsole({ dateformat: "yyyy-mm-dd HH:MM:ss.L", level });
Object.assign(_logger, {
db: (name, req, logObj) => {
logObj = logObj || {};
new LoggerQueue().addLog(name, req, logObj);
}
});
var logger = _logger;
export {
BaseModule,
NoJsonClass,
UserLog,
checkJson,
dbconn,
logger,
noJson
};
/*! Bundled license information:
reflect-metadata/Reflect.js:
(*! *****************************************************************************
Copyright (C) Microsoft. All rights reserved.
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
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** *)
*/
//# sourceMappingURL=index.js.map