@eeplatform/basic-edu 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +23 -12
- package/dist/index.js +363 -3393
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +396 -3422
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -706,7 +706,7 @@ var require_papaparse = __commonJS({
|
|
|
706
706
|
function ParserHandle(_config) {
|
|
707
707
|
var MAX_FLOAT = Math.pow(2, 53);
|
|
708
708
|
var MIN_FLOAT = -MAX_FLOAT;
|
|
709
|
-
var
|
|
709
|
+
var FLOAT = /^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/;
|
|
710
710
|
var ISO_DATE = /^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/;
|
|
711
711
|
var self2 = this;
|
|
712
712
|
var _stepCounter = 0;
|
|
@@ -817,7 +817,7 @@ var require_papaparse = __commonJS({
|
|
|
817
817
|
return _config.skipEmptyLines === "greedy" ? s.join("").trim() === "" : s.length === 1 && s[0].length === 0;
|
|
818
818
|
}
|
|
819
819
|
function testFloat(s) {
|
|
820
|
-
if (
|
|
820
|
+
if (FLOAT.test(s)) {
|
|
821
821
|
var floatValue = parseFloat(s);
|
|
822
822
|
if (floatValue > MIN_FLOAT && floatValue < MAX_FLOAT) {
|
|
823
823
|
return true;
|
|
@@ -1362,6 +1362,7 @@ __export(src_exports, {
|
|
|
1362
1362
|
schemaPlantilla: () => schemaPlantilla,
|
|
1363
1363
|
schemaRegion: () => schemaRegion,
|
|
1364
1364
|
schemaSchool: () => schemaSchool,
|
|
1365
|
+
schemaSchoolUpdate: () => schemaSchoolUpdate,
|
|
1365
1366
|
schemaStockCard: () => schemaStockCard,
|
|
1366
1367
|
useAssetController: () => useAssetController,
|
|
1367
1368
|
useAssetRepo: () => useAssetRepo,
|
|
@@ -4052,6 +4053,20 @@ function modelDivision(value) {
|
|
|
4052
4053
|
throw new Error("Invalid _id.");
|
|
4053
4054
|
}
|
|
4054
4055
|
}
|
|
4056
|
+
if (value.region && typeof value.region === "string") {
|
|
4057
|
+
try {
|
|
4058
|
+
value.region = import_mongodb9.ObjectId.createFromTime(value.region);
|
|
4059
|
+
} catch (error2) {
|
|
4060
|
+
throw new Error("Invalid region.");
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4063
|
+
if (value.superintendent && typeof value.superintendent === "string") {
|
|
4064
|
+
try {
|
|
4065
|
+
value.superintendent = import_mongodb9.ObjectId.createFromTime(value.superintendent);
|
|
4066
|
+
} catch (error2) {
|
|
4067
|
+
throw new Error("Invalid superintendent.");
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4055
4070
|
return {
|
|
4056
4071
|
_id: value._id,
|
|
4057
4072
|
name: value.name,
|
|
@@ -4133,7 +4148,8 @@ function useDivisionRepo() {
|
|
|
4133
4148
|
page = 1,
|
|
4134
4149
|
limit = 10,
|
|
4135
4150
|
sort = {},
|
|
4136
|
-
status = "active"
|
|
4151
|
+
status = "active",
|
|
4152
|
+
region = ""
|
|
4137
4153
|
} = {}) {
|
|
4138
4154
|
page = page > 0 ? page - 1 : 0;
|
|
4139
4155
|
const query = {
|
|
@@ -4151,6 +4167,17 @@ function useDivisionRepo() {
|
|
|
4151
4167
|
query.$text = { $search: search };
|
|
4152
4168
|
cacheKeyOptions.search = search;
|
|
4153
4169
|
}
|
|
4170
|
+
if (region) {
|
|
4171
|
+
try {
|
|
4172
|
+
query.region = new import_mongodb10.ObjectId(region);
|
|
4173
|
+
} catch (error) {
|
|
4174
|
+
import_nodejs_utils15.logger.log({
|
|
4175
|
+
level: "error",
|
|
4176
|
+
message: "Invalid region ID format."
|
|
4177
|
+
});
|
|
4178
|
+
}
|
|
4179
|
+
cacheKeyOptions.region = region;
|
|
4180
|
+
}
|
|
4154
4181
|
const cacheKey = (0, import_nodejs_utils15.makeCacheKey)(namespace_collection, cacheKeyOptions);
|
|
4155
4182
|
import_nodejs_utils15.logger.log({
|
|
4156
4183
|
level: "info",
|
|
@@ -4421,13 +4448,15 @@ function useDivisionController() {
|
|
|
4421
4448
|
page: import_joi10.default.number().min(1).optional().allow("", null),
|
|
4422
4449
|
limit: import_joi10.default.number().min(1).optional().allow("", null),
|
|
4423
4450
|
search: import_joi10.default.string().optional().allow("", null),
|
|
4424
|
-
status: import_joi10.default.string().optional().allow("", null)
|
|
4451
|
+
status: import_joi10.default.string().optional().allow("", null),
|
|
4452
|
+
region: import_joi10.default.string().hex().optional().allow("", null)
|
|
4425
4453
|
});
|
|
4426
4454
|
const { error } = validation.validate(query);
|
|
4427
4455
|
const page = typeof req.query.page === "string" ? Number(req.query.page) : 1;
|
|
4428
4456
|
const limit = typeof req.query.limit === "string" ? Number(req.query.limit) : 10;
|
|
4429
4457
|
const search = req.query.search ?? "";
|
|
4430
4458
|
const status = req.query.status ?? "active";
|
|
4459
|
+
const region = req.query.region ?? "";
|
|
4431
4460
|
const isPageNumber = isFinite(page);
|
|
4432
4461
|
if (!isPageNumber) {
|
|
4433
4462
|
next(new import_nodejs_utils17.BadRequestError("Invalid page number."));
|
|
@@ -4443,7 +4472,7 @@ function useDivisionController() {
|
|
|
4443
4472
|
return;
|
|
4444
4473
|
}
|
|
4445
4474
|
try {
|
|
4446
|
-
const data = await _getAll({ page, limit, search, status });
|
|
4475
|
+
const data = await _getAll({ page, limit, search, status, region });
|
|
4447
4476
|
res.json(data);
|
|
4448
4477
|
return;
|
|
4449
4478
|
} catch (error2) {
|
|
@@ -4566,24 +4595,46 @@ var schemaSchool = import_joi11.default.object({
|
|
|
4566
4595
|
_id: import_joi11.default.string().hex().optional().allow(null, ""),
|
|
4567
4596
|
id: import_joi11.default.string().min(1).max(50).required(),
|
|
4568
4597
|
name: import_joi11.default.string().min(1).max(100).required(),
|
|
4569
|
-
region: import_joi11.default.string().hex().
|
|
4598
|
+
region: import_joi11.default.string().hex().required(),
|
|
4570
4599
|
regionName: import_joi11.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4571
|
-
division: import_joi11.default.string().hex().
|
|
4600
|
+
division: import_joi11.default.string().hex().required(),
|
|
4572
4601
|
divisionName: import_joi11.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4573
4602
|
principal: import_joi11.default.string().hex().optional().allow(null, ""),
|
|
4574
4603
|
principalName: import_joi11.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4575
4604
|
street: import_joi11.default.string().max(200).optional().allow(null, ""),
|
|
4576
4605
|
barangay: import_joi11.default.string().max(200).optional().allow(null, ""),
|
|
4577
|
-
|
|
4606
|
+
cityMunicipality: import_joi11.default.string().max(100).optional().allow(null, ""),
|
|
4578
4607
|
province: import_joi11.default.string().max(100).optional().allow(null, ""),
|
|
4608
|
+
provincePSGC: import_joi11.default.number().optional().allow(null, ""),
|
|
4609
|
+
cityMunicipalityPSGC: import_joi11.default.number().optional().allow(null, ""),
|
|
4579
4610
|
postalCode: import_joi11.default.string().max(20).optional().allow(null, ""),
|
|
4580
4611
|
contactNumber: import_joi11.default.string().max(20).optional().allow(null, ""),
|
|
4581
4612
|
email: import_joi11.default.string().email().max(100).optional().allow(null, ""),
|
|
4613
|
+
status: import_joi11.default.string().optional().allow(null, ""),
|
|
4582
4614
|
createdBy: import_joi11.default.string().optional().allow(null, ""),
|
|
4583
4615
|
createdAt: import_joi11.default.string().isoDate().optional().allow(null, ""),
|
|
4584
4616
|
updatedAt: import_joi11.default.string().isoDate().optional().allow(null, ""),
|
|
4585
4617
|
deletedAt: import_joi11.default.string().isoDate().optional().allow(null, "")
|
|
4586
4618
|
});
|
|
4619
|
+
var schemaSchoolUpdate = import_joi11.default.object({
|
|
4620
|
+
id: import_joi11.default.string().min(1).max(50).required(),
|
|
4621
|
+
name: import_joi11.default.string().min(1).max(100).required(),
|
|
4622
|
+
region: import_joi11.default.string().hex().required(),
|
|
4623
|
+
regionName: import_joi11.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4624
|
+
division: import_joi11.default.string().hex().required(),
|
|
4625
|
+
divisionName: import_joi11.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4626
|
+
principal: import_joi11.default.string().hex().optional().allow(null, ""),
|
|
4627
|
+
principalName: import_joi11.default.string().min(1).max(100).optional().allow(null, ""),
|
|
4628
|
+
street: import_joi11.default.string().max(200).optional().allow(null, ""),
|
|
4629
|
+
barangay: import_joi11.default.string().max(200).optional().allow(null, ""),
|
|
4630
|
+
cityMunicipality: import_joi11.default.string().max(100).optional().allow(null, ""),
|
|
4631
|
+
province: import_joi11.default.string().max(100).optional().allow(null, ""),
|
|
4632
|
+
provincePSGC: import_joi11.default.number().optional().allow(null, ""),
|
|
4633
|
+
cityMunicipalityPSGC: import_joi11.default.number().optional().allow(null, ""),
|
|
4634
|
+
postalCode: import_joi11.default.string().max(20).optional().allow(null, ""),
|
|
4635
|
+
contactNumber: import_joi11.default.string().max(20).optional().allow(null, ""),
|
|
4636
|
+
email: import_joi11.default.string().email().max(100).optional().allow(null, "")
|
|
4637
|
+
});
|
|
4587
4638
|
function modelSchool(value) {
|
|
4588
4639
|
const { error } = schemaSchool.validate(value);
|
|
4589
4640
|
if (error) {
|
|
@@ -4596,6 +4647,27 @@ function modelSchool(value) {
|
|
|
4596
4647
|
throw new Error("Invalid _id.");
|
|
4597
4648
|
}
|
|
4598
4649
|
}
|
|
4650
|
+
if (value.region && typeof value.region === "string") {
|
|
4651
|
+
try {
|
|
4652
|
+
value.region = new import_mongodb11.ObjectId(value.region);
|
|
4653
|
+
} catch (error2) {
|
|
4654
|
+
throw new Error("Invalid region.");
|
|
4655
|
+
}
|
|
4656
|
+
}
|
|
4657
|
+
if (value.division && typeof value.division === "string") {
|
|
4658
|
+
try {
|
|
4659
|
+
value.division = new import_mongodb11.ObjectId(value.division);
|
|
4660
|
+
} catch (error2) {
|
|
4661
|
+
throw new Error("Invalid region.");
|
|
4662
|
+
}
|
|
4663
|
+
}
|
|
4664
|
+
if (value.principal && typeof value.principal === "string") {
|
|
4665
|
+
try {
|
|
4666
|
+
value.principal = new import_mongodb11.ObjectId(value.principal);
|
|
4667
|
+
} catch (error2) {
|
|
4668
|
+
throw new Error("Invalid principal.");
|
|
4669
|
+
}
|
|
4670
|
+
}
|
|
4599
4671
|
return {
|
|
4600
4672
|
_id: value._id,
|
|
4601
4673
|
id: value.id,
|
|
@@ -4606,14 +4678,16 @@ function modelSchool(value) {
|
|
|
4606
4678
|
divisionName: value.divisionName ?? "",
|
|
4607
4679
|
principal: value.principal,
|
|
4608
4680
|
principalName: value.principalName ?? "",
|
|
4609
|
-
status: value.status ?? "active",
|
|
4610
4681
|
street: value.street ?? "",
|
|
4611
4682
|
barangay: value.barangay ?? "",
|
|
4612
|
-
|
|
4683
|
+
cityMunicipality: value.cityMunicipality ?? "",
|
|
4613
4684
|
province: value.province ?? "",
|
|
4614
4685
|
postalCode: value.postalCode ?? "",
|
|
4615
4686
|
contactNumber: value.contactNumber ?? "",
|
|
4616
4687
|
email: value.email ?? "",
|
|
4688
|
+
status: value.status ?? "active",
|
|
4689
|
+
provincePSGC: value.provincePSGC ?? 0,
|
|
4690
|
+
cityMunicipalityPSGC: value.cityMunicipalityPSGC ?? 0,
|
|
4617
4691
|
createdBy: value.createdBy ?? "",
|
|
4618
4692
|
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
4619
4693
|
updatedAt: value.updatedAt ?? "",
|
|
@@ -4638,7 +4712,7 @@ function useSchoolRepo() {
|
|
|
4638
4712
|
{ key: { name: 1 } },
|
|
4639
4713
|
{ key: { createdAt: 1 } },
|
|
4640
4714
|
{ key: { name: "text" } },
|
|
4641
|
-
{ key: {
|
|
4715
|
+
{ key: { id: 1, status: 1 }, unique: true, name: "unique_school_id" }
|
|
4642
4716
|
]);
|
|
4643
4717
|
} catch (error) {
|
|
4644
4718
|
throw new Error("Failed to create index on schools.");
|
|
@@ -4657,25 +4731,35 @@ function useSchoolRepo() {
|
|
|
4657
4731
|
});
|
|
4658
4732
|
});
|
|
4659
4733
|
}
|
|
4660
|
-
async function add(value, session) {
|
|
4734
|
+
async function add(value, session, clearCache = true) {
|
|
4661
4735
|
try {
|
|
4662
4736
|
value = modelSchool(value);
|
|
4663
4737
|
const res = await collection.insertOne(value, { session });
|
|
4664
|
-
|
|
4738
|
+
if (clearCache) {
|
|
4739
|
+
delCachedData();
|
|
4740
|
+
}
|
|
4665
4741
|
return res.insertedId;
|
|
4666
4742
|
} catch (error) {
|
|
4667
4743
|
import_nodejs_utils19.logger.log({
|
|
4668
4744
|
level: "error",
|
|
4669
|
-
message: error.message
|
|
4745
|
+
message: `Failed to add school: ${error.message}`,
|
|
4746
|
+
metadata: {
|
|
4747
|
+
code: error.code,
|
|
4748
|
+
codeName: error.codeName,
|
|
4749
|
+
errorLabels: error.errorLabelSet ? Array.from(error.errorLabelSet) : [],
|
|
4750
|
+
schoolName: value?.name || "unknown",
|
|
4751
|
+
hasSession: !!session,
|
|
4752
|
+
transactionNumber: error.errorResponse?.txnNumber || "unknown"
|
|
4753
|
+
}
|
|
4670
4754
|
});
|
|
4671
4755
|
if (error instanceof import_nodejs_utils19.AppError) {
|
|
4672
4756
|
throw error;
|
|
4673
4757
|
} else {
|
|
4674
4758
|
const isDuplicated = error.message.includes("duplicate");
|
|
4675
4759
|
if (isDuplicated) {
|
|
4676
|
-
throw new import_nodejs_utils19.BadRequestError("
|
|
4760
|
+
throw new import_nodejs_utils19.BadRequestError("Duplicate, school already exists.");
|
|
4677
4761
|
}
|
|
4678
|
-
throw new
|
|
4762
|
+
throw new import_nodejs_utils19.InternalServerError("Failed to add school.");
|
|
4679
4763
|
}
|
|
4680
4764
|
}
|
|
4681
4765
|
}
|
|
@@ -4917,6 +5001,24 @@ function useSchoolRepo() {
|
|
|
4917
5001
|
throw new import_nodejs_utils19.InternalServerError(`Failed to update school ${field}.`);
|
|
4918
5002
|
}
|
|
4919
5003
|
}
|
|
5004
|
+
async function updateById(_id, options, session) {
|
|
5005
|
+
const { error } = schemaSchoolUpdate.validate(options);
|
|
5006
|
+
if (error) {
|
|
5007
|
+
throw new import_nodejs_utils19.BadRequestError(`Invalid school data: ${error.message}`);
|
|
5008
|
+
}
|
|
5009
|
+
try {
|
|
5010
|
+
_id = new import_mongodb12.ObjectId(_id);
|
|
5011
|
+
} catch (error2) {
|
|
5012
|
+
throw new import_nodejs_utils19.BadRequestError("Invalid ID.");
|
|
5013
|
+
}
|
|
5014
|
+
try {
|
|
5015
|
+
await collection.updateOne({ _id }, { $set: options }, { session });
|
|
5016
|
+
delCachedData();
|
|
5017
|
+
return `Successfully updated school.`;
|
|
5018
|
+
} catch (error2) {
|
|
5019
|
+
throw new import_nodejs_utils19.InternalServerError(`Failed to update school.`);
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
4920
5022
|
async function deleteById(_id) {
|
|
4921
5023
|
try {
|
|
4922
5024
|
_id = new import_mongodb12.ObjectId(_id);
|
|
@@ -4926,7 +5028,7 @@ function useSchoolRepo() {
|
|
|
4926
5028
|
try {
|
|
4927
5029
|
await collection.updateOne(
|
|
4928
5030
|
{ _id },
|
|
4929
|
-
{ $set: { deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
5031
|
+
{ $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
4930
5032
|
);
|
|
4931
5033
|
delCachedData();
|
|
4932
5034
|
return "Successfully deleted school.";
|
|
@@ -4942,8 +5044,10 @@ function useSchoolRepo() {
|
|
|
4942
5044
|
getPendingByCreatedBy,
|
|
4943
5045
|
updateStatusById,
|
|
4944
5046
|
updateFieldById,
|
|
5047
|
+
updateById,
|
|
4945
5048
|
deleteById,
|
|
4946
|
-
getByName
|
|
5049
|
+
getByName,
|
|
5050
|
+
delCachedData
|
|
4947
5051
|
};
|
|
4948
5052
|
}
|
|
4949
5053
|
|
|
@@ -7018,11 +7122,11 @@ var CFB = /* @__PURE__ */ function _CFB() {
|
|
|
7018
7122
|
}
|
|
7019
7123
|
return o;
|
|
7020
7124
|
}
|
|
7021
|
-
var
|
|
7125
|
+
var fs2;
|
|
7022
7126
|
function get_fs() {
|
|
7023
|
-
return
|
|
7127
|
+
return fs2 || (fs2 = {});
|
|
7024
7128
|
}
|
|
7025
|
-
function
|
|
7129
|
+
function parse3(file, options) {
|
|
7026
7130
|
if (file[0] == 80 && file[1] == 75)
|
|
7027
7131
|
return parse_zip2(file, options);
|
|
7028
7132
|
if ((file[0] | 32) == 109 && (file[1] | 32) == 105)
|
|
@@ -7343,7 +7447,7 @@ var CFB = /* @__PURE__ */ function _CFB() {
|
|
|
7343
7447
|
}
|
|
7344
7448
|
function read_file(filename2, options) {
|
|
7345
7449
|
get_fs();
|
|
7346
|
-
return
|
|
7450
|
+
return parse3(fs2.readFileSync(filename2), options);
|
|
7347
7451
|
}
|
|
7348
7452
|
function read(blob, options) {
|
|
7349
7453
|
var type = options && options.type;
|
|
@@ -7355,11 +7459,11 @@ var CFB = /* @__PURE__ */ function _CFB() {
|
|
|
7355
7459
|
case "file":
|
|
7356
7460
|
return read_file(blob, options);
|
|
7357
7461
|
case "base64":
|
|
7358
|
-
return
|
|
7462
|
+
return parse3(s2a(Base64_decode(blob)), options);
|
|
7359
7463
|
case "binary":
|
|
7360
|
-
return
|
|
7464
|
+
return parse3(s2a(blob), options);
|
|
7361
7465
|
}
|
|
7362
|
-
return
|
|
7466
|
+
return parse3(
|
|
7363
7467
|
/*::typeof blob == 'string' ? new Buffer(blob, 'utf-8') : */
|
|
7364
7468
|
blob,
|
|
7365
7469
|
options
|
|
@@ -7725,7 +7829,7 @@ var CFB = /* @__PURE__ */ function _CFB() {
|
|
|
7725
7829
|
function write_file(cfb, filename2, options) {
|
|
7726
7830
|
get_fs();
|
|
7727
7831
|
var o = _write(cfb, options);
|
|
7728
|
-
|
|
7832
|
+
fs2.writeFileSync(filename2, o);
|
|
7729
7833
|
}
|
|
7730
7834
|
function a2s2(o) {
|
|
7731
7835
|
var out = new Array(o.length);
|
|
@@ -7738,7 +7842,7 @@ var CFB = /* @__PURE__ */ function _CFB() {
|
|
|
7738
7842
|
switch (options && options.type || "buffer") {
|
|
7739
7843
|
case "file":
|
|
7740
7844
|
get_fs();
|
|
7741
|
-
|
|
7845
|
+
fs2.writeFileSync(options.filename, o);
|
|
7742
7846
|
return o;
|
|
7743
7847
|
case "binary":
|
|
7744
7848
|
return typeof o == "string" ? o : a2s2(o);
|
|
@@ -8717,7 +8821,7 @@ var CFB = /* @__PURE__ */ function _CFB() {
|
|
|
8717
8821
|
}
|
|
8718
8822
|
exports.find = find;
|
|
8719
8823
|
exports.read = read;
|
|
8720
|
-
exports.parse =
|
|
8824
|
+
exports.parse = parse3;
|
|
8721
8825
|
exports.write = write;
|
|
8722
8826
|
exports.writeFile = write_file;
|
|
8723
8827
|
exports.utils = {
|
|
@@ -32747,7 +32851,7 @@ function sheet_to_json(sheet, opts) {
|
|
|
32747
32851
|
return out;
|
|
32748
32852
|
}
|
|
32749
32853
|
var qreg = /"/g;
|
|
32750
|
-
function make_csv_row(sheet, r, R, cols,
|
|
32854
|
+
function make_csv_row(sheet, r, R, cols, fs2, rs, FS, o) {
|
|
32751
32855
|
var isempty = true;
|
|
32752
32856
|
var row = [], txt = "", rr = encode_row(R);
|
|
32753
32857
|
for (var C = r.s.c; C <= r.e.c; ++C) {
|
|
@@ -32760,7 +32864,7 @@ function make_csv_row(sheet, r, R, cols, fs, rs, FS, o) {
|
|
|
32760
32864
|
isempty = false;
|
|
32761
32865
|
txt = "" + (o.rawNumbers && val.t == "n" ? val.v : format_cell(val, null, o));
|
|
32762
32866
|
for (var i = 0, cc = 0; i !== txt.length; ++i)
|
|
32763
|
-
if ((cc = txt.charCodeAt(i)) ===
|
|
32867
|
+
if ((cc = txt.charCodeAt(i)) === fs2 || cc === rs || cc === 34 || o.forceQuotes) {
|
|
32764
32868
|
txt = '"' + txt.replace(qreg, '""') + '"';
|
|
32765
32869
|
break;
|
|
32766
32870
|
}
|
|
@@ -32785,7 +32889,7 @@ function sheet_to_csv(sheet, opts) {
|
|
|
32785
32889
|
if (sheet == null || sheet["!ref"] == null)
|
|
32786
32890
|
return "";
|
|
32787
32891
|
var r = safe_decode_range(sheet["!ref"]);
|
|
32788
|
-
var FS = o.FS !== void 0 ? o.FS : ",",
|
|
32892
|
+
var FS = o.FS !== void 0 ? o.FS : ",", fs2 = FS.charCodeAt(0);
|
|
32789
32893
|
var RS = o.RS !== void 0 ? o.RS : "\n", rs = RS.charCodeAt(0);
|
|
32790
32894
|
var endregex = new RegExp((FS == "|" ? "\\|" : FS) + "+$");
|
|
32791
32895
|
var row = "", cols = [];
|
|
@@ -32799,7 +32903,7 @@ function sheet_to_csv(sheet, opts) {
|
|
|
32799
32903
|
for (var R = r.s.r; R <= r.e.r; ++R) {
|
|
32800
32904
|
if ((rowinfo[R] || {}).hidden)
|
|
32801
32905
|
continue;
|
|
32802
|
-
row = make_csv_row(sheet, r, R, cols,
|
|
32906
|
+
row = make_csv_row(sheet, r, R, cols, fs2, rs, FS, o);
|
|
32803
32907
|
if (row == null) {
|
|
32804
32908
|
continue;
|
|
32805
32909
|
}
|
|
@@ -33108,3218 +33212,16 @@ var version = XLSX.version;
|
|
|
33108
33212
|
|
|
33109
33213
|
// src/resources/school/school.service.ts
|
|
33110
33214
|
var Papa = __toESM(require_papaparse());
|
|
33111
|
-
|
|
33112
|
-
// node_modules/bson/lib/bson.node.mjs
|
|
33113
|
-
var import_crypto = require("crypto");
|
|
33114
|
-
var TypedArrayPrototypeGetSymbolToStringTag = (() => {
|
|
33115
|
-
const g = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag).get;
|
|
33116
|
-
return (value) => g.call(value);
|
|
33117
|
-
})();
|
|
33118
|
-
function isUint8Array(value) {
|
|
33119
|
-
return TypedArrayPrototypeGetSymbolToStringTag(value) === "Uint8Array";
|
|
33120
|
-
}
|
|
33121
|
-
function isAnyArrayBuffer(value) {
|
|
33122
|
-
return typeof value === "object" && value != null && Symbol.toStringTag in value && (value[Symbol.toStringTag] === "ArrayBuffer" || value[Symbol.toStringTag] === "SharedArrayBuffer");
|
|
33123
|
-
}
|
|
33124
|
-
function isRegExp(regexp) {
|
|
33125
|
-
return regexp instanceof RegExp || Object.prototype.toString.call(regexp) === "[object RegExp]";
|
|
33126
|
-
}
|
|
33127
|
-
function isMap(value) {
|
|
33128
|
-
return typeof value === "object" && value != null && Symbol.toStringTag in value && value[Symbol.toStringTag] === "Map";
|
|
33129
|
-
}
|
|
33130
|
-
function isDate(date) {
|
|
33131
|
-
return date instanceof Date || Object.prototype.toString.call(date) === "[object Date]";
|
|
33132
|
-
}
|
|
33133
|
-
function defaultInspect(x, _options) {
|
|
33134
|
-
return JSON.stringify(x, (k, v) => {
|
|
33135
|
-
if (typeof v === "bigint") {
|
|
33136
|
-
return { $numberLong: `${v}` };
|
|
33137
|
-
} else if (isMap(v)) {
|
|
33138
|
-
return Object.fromEntries(v);
|
|
33139
|
-
}
|
|
33140
|
-
return v;
|
|
33141
|
-
});
|
|
33142
|
-
}
|
|
33143
|
-
function getStylizeFunction(options) {
|
|
33144
|
-
const stylizeExists = options != null && typeof options === "object" && "stylize" in options && typeof options.stylize === "function";
|
|
33145
|
-
if (stylizeExists) {
|
|
33146
|
-
return options.stylize;
|
|
33147
|
-
}
|
|
33148
|
-
}
|
|
33149
|
-
var BSON_MAJOR_VERSION = 6;
|
|
33150
|
-
var BSON_VERSION_SYMBOL = Symbol.for("@@mdb.bson.version");
|
|
33151
|
-
var BSON_INT32_MAX = 2147483647;
|
|
33152
|
-
var BSON_INT32_MIN = -2147483648;
|
|
33153
|
-
var BSON_INT64_MAX = Math.pow(2, 63) - 1;
|
|
33154
|
-
var BSON_INT64_MIN = -Math.pow(2, 63);
|
|
33155
|
-
var JS_INT_MAX = Math.pow(2, 53);
|
|
33156
|
-
var JS_INT_MIN = -Math.pow(2, 53);
|
|
33157
|
-
var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
|
|
33158
|
-
var BSONType = Object.freeze({
|
|
33159
|
-
double: 1,
|
|
33160
|
-
string: 2,
|
|
33161
|
-
object: 3,
|
|
33162
|
-
array: 4,
|
|
33163
|
-
binData: 5,
|
|
33164
|
-
undefined: 6,
|
|
33165
|
-
objectId: 7,
|
|
33166
|
-
bool: 8,
|
|
33167
|
-
date: 9,
|
|
33168
|
-
null: 10,
|
|
33169
|
-
regex: 11,
|
|
33170
|
-
dbPointer: 12,
|
|
33171
|
-
javascript: 13,
|
|
33172
|
-
symbol: 14,
|
|
33173
|
-
javascriptWithScope: 15,
|
|
33174
|
-
int: 16,
|
|
33175
|
-
timestamp: 17,
|
|
33176
|
-
long: 18,
|
|
33177
|
-
decimal: 19,
|
|
33178
|
-
minKey: -1,
|
|
33179
|
-
maxKey: 127
|
|
33180
|
-
});
|
|
33181
|
-
var BSONError = class extends Error {
|
|
33182
|
-
get bsonError() {
|
|
33183
|
-
return true;
|
|
33184
|
-
}
|
|
33185
|
-
get name() {
|
|
33186
|
-
return "BSONError";
|
|
33187
|
-
}
|
|
33188
|
-
constructor(message, options) {
|
|
33189
|
-
super(message, options);
|
|
33190
|
-
}
|
|
33191
|
-
static isBSONError(value) {
|
|
33192
|
-
return value != null && typeof value === "object" && "bsonError" in value && value.bsonError === true && "name" in value && "message" in value && "stack" in value;
|
|
33193
|
-
}
|
|
33194
|
-
};
|
|
33195
|
-
var BSONVersionError = class extends BSONError {
|
|
33196
|
-
get name() {
|
|
33197
|
-
return "BSONVersionError";
|
|
33198
|
-
}
|
|
33199
|
-
constructor() {
|
|
33200
|
-
super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.x.x`);
|
|
33201
|
-
}
|
|
33202
|
-
};
|
|
33203
|
-
var BSONRuntimeError = class extends BSONError {
|
|
33204
|
-
get name() {
|
|
33205
|
-
return "BSONRuntimeError";
|
|
33206
|
-
}
|
|
33207
|
-
constructor(message) {
|
|
33208
|
-
super(message);
|
|
33209
|
-
}
|
|
33210
|
-
};
|
|
33211
|
-
var BSONOffsetError = class extends BSONError {
|
|
33212
|
-
get name() {
|
|
33213
|
-
return "BSONOffsetError";
|
|
33214
|
-
}
|
|
33215
|
-
constructor(message, offset, options) {
|
|
33216
|
-
super(`${message}. offset: ${offset}`, options);
|
|
33217
|
-
this.offset = offset;
|
|
33218
|
-
}
|
|
33219
|
-
};
|
|
33220
|
-
var TextDecoderFatal;
|
|
33221
|
-
var TextDecoderNonFatal;
|
|
33222
|
-
function parseUtf8(buffer2, start, end, fatal) {
|
|
33223
|
-
if (fatal) {
|
|
33224
|
-
TextDecoderFatal ?? (TextDecoderFatal = new TextDecoder("utf8", { fatal: true }));
|
|
33225
|
-
try {
|
|
33226
|
-
return TextDecoderFatal.decode(buffer2.subarray(start, end));
|
|
33227
|
-
} catch (cause) {
|
|
33228
|
-
throw new BSONError("Invalid UTF-8 string in BSON document", { cause });
|
|
33229
|
-
}
|
|
33230
|
-
}
|
|
33231
|
-
TextDecoderNonFatal ?? (TextDecoderNonFatal = new TextDecoder("utf8", { fatal: false }));
|
|
33232
|
-
return TextDecoderNonFatal.decode(buffer2.subarray(start, end));
|
|
33233
|
-
}
|
|
33234
|
-
function tryReadBasicLatin(uint8array, start, end) {
|
|
33235
|
-
if (uint8array.length === 0) {
|
|
33236
|
-
return "";
|
|
33237
|
-
}
|
|
33238
|
-
const stringByteLength = end - start;
|
|
33239
|
-
if (stringByteLength === 0) {
|
|
33240
|
-
return "";
|
|
33241
|
-
}
|
|
33242
|
-
if (stringByteLength > 20) {
|
|
33243
|
-
return null;
|
|
33244
|
-
}
|
|
33245
|
-
if (stringByteLength === 1 && uint8array[start] < 128) {
|
|
33246
|
-
return String.fromCharCode(uint8array[start]);
|
|
33247
|
-
}
|
|
33248
|
-
if (stringByteLength === 2 && uint8array[start] < 128 && uint8array[start + 1] < 128) {
|
|
33249
|
-
return String.fromCharCode(uint8array[start]) + String.fromCharCode(uint8array[start + 1]);
|
|
33250
|
-
}
|
|
33251
|
-
if (stringByteLength === 3 && uint8array[start] < 128 && uint8array[start + 1] < 128 && uint8array[start + 2] < 128) {
|
|
33252
|
-
return String.fromCharCode(uint8array[start]) + String.fromCharCode(uint8array[start + 1]) + String.fromCharCode(uint8array[start + 2]);
|
|
33253
|
-
}
|
|
33254
|
-
const latinBytes = [];
|
|
33255
|
-
for (let i = start; i < end; i++) {
|
|
33256
|
-
const byte = uint8array[i];
|
|
33257
|
-
if (byte > 127) {
|
|
33258
|
-
return null;
|
|
33259
|
-
}
|
|
33260
|
-
latinBytes.push(byte);
|
|
33261
|
-
}
|
|
33262
|
-
return String.fromCharCode(...latinBytes);
|
|
33263
|
-
}
|
|
33264
|
-
function tryWriteBasicLatin(destination, source, offset) {
|
|
33265
|
-
if (source.length === 0)
|
|
33266
|
-
return 0;
|
|
33267
|
-
if (source.length > 25)
|
|
33268
|
-
return null;
|
|
33269
|
-
if (destination.length - offset < source.length)
|
|
33270
|
-
return null;
|
|
33271
|
-
for (let charOffset = 0, destinationOffset = offset; charOffset < source.length; charOffset++, destinationOffset++) {
|
|
33272
|
-
const char = source.charCodeAt(charOffset);
|
|
33273
|
-
if (char > 127)
|
|
33274
|
-
return null;
|
|
33275
|
-
destination[destinationOffset] = char;
|
|
33276
|
-
}
|
|
33277
|
-
return source.length;
|
|
33278
|
-
}
|
|
33279
|
-
var nodeJsByteUtils = {
|
|
33280
|
-
toLocalBufferType(potentialBuffer) {
|
|
33281
|
-
if (Buffer.isBuffer(potentialBuffer)) {
|
|
33282
|
-
return potentialBuffer;
|
|
33283
|
-
}
|
|
33284
|
-
if (ArrayBuffer.isView(potentialBuffer)) {
|
|
33285
|
-
return Buffer.from(potentialBuffer.buffer, potentialBuffer.byteOffset, potentialBuffer.byteLength);
|
|
33286
|
-
}
|
|
33287
|
-
const stringTag = potentialBuffer?.[Symbol.toStringTag] ?? Object.prototype.toString.call(potentialBuffer);
|
|
33288
|
-
if (stringTag === "ArrayBuffer" || stringTag === "SharedArrayBuffer" || stringTag === "[object ArrayBuffer]" || stringTag === "[object SharedArrayBuffer]") {
|
|
33289
|
-
return Buffer.from(potentialBuffer);
|
|
33290
|
-
}
|
|
33291
|
-
throw new BSONError(`Cannot create Buffer from the passed potentialBuffer.`);
|
|
33292
|
-
},
|
|
33293
|
-
allocate(size) {
|
|
33294
|
-
return Buffer.alloc(size);
|
|
33295
|
-
},
|
|
33296
|
-
allocateUnsafe(size) {
|
|
33297
|
-
return Buffer.allocUnsafe(size);
|
|
33298
|
-
},
|
|
33299
|
-
equals(a, b) {
|
|
33300
|
-
return nodeJsByteUtils.toLocalBufferType(a).equals(b);
|
|
33301
|
-
},
|
|
33302
|
-
fromNumberArray(array) {
|
|
33303
|
-
return Buffer.from(array);
|
|
33304
|
-
},
|
|
33305
|
-
fromBase64(base64) {
|
|
33306
|
-
return Buffer.from(base64, "base64");
|
|
33307
|
-
},
|
|
33308
|
-
toBase64(buffer2) {
|
|
33309
|
-
return nodeJsByteUtils.toLocalBufferType(buffer2).toString("base64");
|
|
33310
|
-
},
|
|
33311
|
-
fromISO88591(codePoints) {
|
|
33312
|
-
return Buffer.from(codePoints, "binary");
|
|
33313
|
-
},
|
|
33314
|
-
toISO88591(buffer2) {
|
|
33315
|
-
return nodeJsByteUtils.toLocalBufferType(buffer2).toString("binary");
|
|
33316
|
-
},
|
|
33317
|
-
fromHex(hex) {
|
|
33318
|
-
return Buffer.from(hex, "hex");
|
|
33319
|
-
},
|
|
33320
|
-
toHex(buffer2) {
|
|
33321
|
-
return nodeJsByteUtils.toLocalBufferType(buffer2).toString("hex");
|
|
33322
|
-
},
|
|
33323
|
-
toUTF8(buffer2, start, end, fatal) {
|
|
33324
|
-
const basicLatin = end - start <= 20 ? tryReadBasicLatin(buffer2, start, end) : null;
|
|
33325
|
-
if (basicLatin != null) {
|
|
33326
|
-
return basicLatin;
|
|
33327
|
-
}
|
|
33328
|
-
const string = nodeJsByteUtils.toLocalBufferType(buffer2).toString("utf8", start, end);
|
|
33329
|
-
if (fatal) {
|
|
33330
|
-
for (let i = 0; i < string.length; i++) {
|
|
33331
|
-
if (string.charCodeAt(i) === 65533) {
|
|
33332
|
-
parseUtf8(buffer2, start, end, true);
|
|
33333
|
-
break;
|
|
33334
|
-
}
|
|
33335
|
-
}
|
|
33336
|
-
}
|
|
33337
|
-
return string;
|
|
33338
|
-
},
|
|
33339
|
-
utf8ByteLength(input) {
|
|
33340
|
-
return Buffer.byteLength(input, "utf8");
|
|
33341
|
-
},
|
|
33342
|
-
encodeUTF8Into(buffer2, source, byteOffset) {
|
|
33343
|
-
const latinBytesWritten = tryWriteBasicLatin(buffer2, source, byteOffset);
|
|
33344
|
-
if (latinBytesWritten != null) {
|
|
33345
|
-
return latinBytesWritten;
|
|
33346
|
-
}
|
|
33347
|
-
return nodeJsByteUtils.toLocalBufferType(buffer2).write(source, byteOffset, void 0, "utf8");
|
|
33348
|
-
},
|
|
33349
|
-
randomBytes: import_crypto.randomBytes,
|
|
33350
|
-
swap32(buffer2) {
|
|
33351
|
-
return nodeJsByteUtils.toLocalBufferType(buffer2).swap32();
|
|
33352
|
-
}
|
|
33353
|
-
};
|
|
33354
|
-
function isReactNative() {
|
|
33355
|
-
const { navigator: navigator2 } = globalThis;
|
|
33356
|
-
return typeof navigator2 === "object" && navigator2.product === "ReactNative";
|
|
33357
|
-
}
|
|
33358
|
-
function webMathRandomBytes(byteLength) {
|
|
33359
|
-
if (byteLength < 0) {
|
|
33360
|
-
throw new RangeError(`The argument 'byteLength' is invalid. Received ${byteLength}`);
|
|
33361
|
-
}
|
|
33362
|
-
return webByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
|
|
33363
|
-
}
|
|
33364
|
-
var webRandomBytes = (() => {
|
|
33365
|
-
const { crypto } = globalThis;
|
|
33366
|
-
if (crypto != null && typeof crypto.getRandomValues === "function") {
|
|
33367
|
-
return (byteLength) => {
|
|
33368
|
-
return crypto.getRandomValues(webByteUtils.allocate(byteLength));
|
|
33369
|
-
};
|
|
33370
|
-
} else {
|
|
33371
|
-
if (isReactNative()) {
|
|
33372
|
-
const { console: console2 } = globalThis;
|
|
33373
|
-
console2?.warn?.("BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.");
|
|
33374
|
-
}
|
|
33375
|
-
return webMathRandomBytes;
|
|
33376
|
-
}
|
|
33377
|
-
})();
|
|
33378
|
-
var HEX_DIGIT = /(\d|[a-f])/i;
|
|
33379
|
-
var webByteUtils = {
|
|
33380
|
-
toLocalBufferType(potentialUint8array) {
|
|
33381
|
-
const stringTag = potentialUint8array?.[Symbol.toStringTag] ?? Object.prototype.toString.call(potentialUint8array);
|
|
33382
|
-
if (stringTag === "Uint8Array") {
|
|
33383
|
-
return potentialUint8array;
|
|
33384
|
-
}
|
|
33385
|
-
if (ArrayBuffer.isView(potentialUint8array)) {
|
|
33386
|
-
return new Uint8Array(potentialUint8array.buffer.slice(potentialUint8array.byteOffset, potentialUint8array.byteOffset + potentialUint8array.byteLength));
|
|
33387
|
-
}
|
|
33388
|
-
if (stringTag === "ArrayBuffer" || stringTag === "SharedArrayBuffer" || stringTag === "[object ArrayBuffer]" || stringTag === "[object SharedArrayBuffer]") {
|
|
33389
|
-
return new Uint8Array(potentialUint8array);
|
|
33390
|
-
}
|
|
33391
|
-
throw new BSONError(`Cannot make a Uint8Array from passed potentialBuffer.`);
|
|
33392
|
-
},
|
|
33393
|
-
allocate(size) {
|
|
33394
|
-
if (typeof size !== "number") {
|
|
33395
|
-
throw new TypeError(`The "size" argument must be of type number. Received ${String(size)}`);
|
|
33396
|
-
}
|
|
33397
|
-
return new Uint8Array(size);
|
|
33398
|
-
},
|
|
33399
|
-
allocateUnsafe(size) {
|
|
33400
|
-
return webByteUtils.allocate(size);
|
|
33401
|
-
},
|
|
33402
|
-
equals(a, b) {
|
|
33403
|
-
if (a.byteLength !== b.byteLength) {
|
|
33404
|
-
return false;
|
|
33405
|
-
}
|
|
33406
|
-
for (let i = 0; i < a.byteLength; i++) {
|
|
33407
|
-
if (a[i] !== b[i]) {
|
|
33408
|
-
return false;
|
|
33409
|
-
}
|
|
33410
|
-
}
|
|
33411
|
-
return true;
|
|
33412
|
-
},
|
|
33413
|
-
fromNumberArray(array) {
|
|
33414
|
-
return Uint8Array.from(array);
|
|
33415
|
-
},
|
|
33416
|
-
fromBase64(base64) {
|
|
33417
|
-
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
33418
|
-
},
|
|
33419
|
-
toBase64(uint8array) {
|
|
33420
|
-
return btoa(webByteUtils.toISO88591(uint8array));
|
|
33421
|
-
},
|
|
33422
|
-
fromISO88591(codePoints) {
|
|
33423
|
-
return Uint8Array.from(codePoints, (c) => c.charCodeAt(0) & 255);
|
|
33424
|
-
},
|
|
33425
|
-
toISO88591(uint8array) {
|
|
33426
|
-
return Array.from(Uint16Array.from(uint8array), (b) => String.fromCharCode(b)).join("");
|
|
33427
|
-
},
|
|
33428
|
-
fromHex(hex) {
|
|
33429
|
-
const evenLengthHex = hex.length % 2 === 0 ? hex : hex.slice(0, hex.length - 1);
|
|
33430
|
-
const buffer2 = [];
|
|
33431
|
-
for (let i = 0; i < evenLengthHex.length; i += 2) {
|
|
33432
|
-
const firstDigit = evenLengthHex[i];
|
|
33433
|
-
const secondDigit = evenLengthHex[i + 1];
|
|
33434
|
-
if (!HEX_DIGIT.test(firstDigit)) {
|
|
33435
|
-
break;
|
|
33436
|
-
}
|
|
33437
|
-
if (!HEX_DIGIT.test(secondDigit)) {
|
|
33438
|
-
break;
|
|
33439
|
-
}
|
|
33440
|
-
const hexDigit = Number.parseInt(`${firstDigit}${secondDigit}`, 16);
|
|
33441
|
-
buffer2.push(hexDigit);
|
|
33442
|
-
}
|
|
33443
|
-
return Uint8Array.from(buffer2);
|
|
33444
|
-
},
|
|
33445
|
-
toHex(uint8array) {
|
|
33446
|
-
return Array.from(uint8array, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
33447
|
-
},
|
|
33448
|
-
toUTF8(uint8array, start, end, fatal) {
|
|
33449
|
-
const basicLatin = end - start <= 20 ? tryReadBasicLatin(uint8array, start, end) : null;
|
|
33450
|
-
if (basicLatin != null) {
|
|
33451
|
-
return basicLatin;
|
|
33452
|
-
}
|
|
33453
|
-
return parseUtf8(uint8array, start, end, fatal);
|
|
33454
|
-
},
|
|
33455
|
-
utf8ByteLength(input) {
|
|
33456
|
-
return new TextEncoder().encode(input).byteLength;
|
|
33457
|
-
},
|
|
33458
|
-
encodeUTF8Into(uint8array, source, byteOffset) {
|
|
33459
|
-
const bytes = new TextEncoder().encode(source);
|
|
33460
|
-
uint8array.set(bytes, byteOffset);
|
|
33461
|
-
return bytes.byteLength;
|
|
33462
|
-
},
|
|
33463
|
-
randomBytes: webRandomBytes,
|
|
33464
|
-
swap32(buffer2) {
|
|
33465
|
-
if (buffer2.length % 4 !== 0) {
|
|
33466
|
-
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
33467
|
-
}
|
|
33468
|
-
for (let i = 0; i < buffer2.length; i += 4) {
|
|
33469
|
-
const byte0 = buffer2[i];
|
|
33470
|
-
const byte1 = buffer2[i + 1];
|
|
33471
|
-
const byte2 = buffer2[i + 2];
|
|
33472
|
-
const byte3 = buffer2[i + 3];
|
|
33473
|
-
buffer2[i] = byte3;
|
|
33474
|
-
buffer2[i + 1] = byte2;
|
|
33475
|
-
buffer2[i + 2] = byte1;
|
|
33476
|
-
buffer2[i + 3] = byte0;
|
|
33477
|
-
}
|
|
33478
|
-
return buffer2;
|
|
33479
|
-
}
|
|
33480
|
-
};
|
|
33481
|
-
var hasGlobalBuffer = typeof Buffer === "function" && Buffer.prototype?._isBuffer !== true;
|
|
33482
|
-
var ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
|
|
33483
|
-
var BSONValue = class {
|
|
33484
|
-
get [BSON_VERSION_SYMBOL]() {
|
|
33485
|
-
return BSON_MAJOR_VERSION;
|
|
33486
|
-
}
|
|
33487
|
-
[Symbol.for("nodejs.util.inspect.custom")](depth, options, inspect) {
|
|
33488
|
-
return this.inspect(depth, options, inspect);
|
|
33489
|
-
}
|
|
33490
|
-
};
|
|
33491
|
-
var FLOAT = new Float64Array(1);
|
|
33492
|
-
var FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
|
|
33493
|
-
FLOAT[0] = -1;
|
|
33494
|
-
var isBigEndian = FLOAT_BYTES[7] === 0;
|
|
33495
|
-
var NumberUtils = {
|
|
33496
|
-
isBigEndian,
|
|
33497
|
-
getNonnegativeInt32LE(source, offset) {
|
|
33498
|
-
if (source[offset + 3] > 127) {
|
|
33499
|
-
throw new RangeError(`Size cannot be negative at offset: ${offset}`);
|
|
33500
|
-
}
|
|
33501
|
-
return source[offset] | source[offset + 1] << 8 | source[offset + 2] << 16 | source[offset + 3] << 24;
|
|
33502
|
-
},
|
|
33503
|
-
getInt32LE(source, offset) {
|
|
33504
|
-
return source[offset] | source[offset + 1] << 8 | source[offset + 2] << 16 | source[offset + 3] << 24;
|
|
33505
|
-
},
|
|
33506
|
-
getUint32LE(source, offset) {
|
|
33507
|
-
return source[offset] + source[offset + 1] * 256 + source[offset + 2] * 65536 + source[offset + 3] * 16777216;
|
|
33508
|
-
},
|
|
33509
|
-
getUint32BE(source, offset) {
|
|
33510
|
-
return source[offset + 3] + source[offset + 2] * 256 + source[offset + 1] * 65536 + source[offset] * 16777216;
|
|
33511
|
-
},
|
|
33512
|
-
getBigInt64LE(source, offset) {
|
|
33513
|
-
const hi = BigInt(source[offset + 4] + source[offset + 5] * 256 + source[offset + 6] * 65536 + (source[offset + 7] << 24));
|
|
33514
|
-
const lo = BigInt(source[offset] + source[offset + 1] * 256 + source[offset + 2] * 65536 + source[offset + 3] * 16777216);
|
|
33515
|
-
return (hi << BigInt(32)) + lo;
|
|
33516
|
-
},
|
|
33517
|
-
getFloat64LE: isBigEndian ? (source, offset) => {
|
|
33518
|
-
FLOAT_BYTES[7] = source[offset];
|
|
33519
|
-
FLOAT_BYTES[6] = source[offset + 1];
|
|
33520
|
-
FLOAT_BYTES[5] = source[offset + 2];
|
|
33521
|
-
FLOAT_BYTES[4] = source[offset + 3];
|
|
33522
|
-
FLOAT_BYTES[3] = source[offset + 4];
|
|
33523
|
-
FLOAT_BYTES[2] = source[offset + 5];
|
|
33524
|
-
FLOAT_BYTES[1] = source[offset + 6];
|
|
33525
|
-
FLOAT_BYTES[0] = source[offset + 7];
|
|
33526
|
-
return FLOAT[0];
|
|
33527
|
-
} : (source, offset) => {
|
|
33528
|
-
FLOAT_BYTES[0] = source[offset];
|
|
33529
|
-
FLOAT_BYTES[1] = source[offset + 1];
|
|
33530
|
-
FLOAT_BYTES[2] = source[offset + 2];
|
|
33531
|
-
FLOAT_BYTES[3] = source[offset + 3];
|
|
33532
|
-
FLOAT_BYTES[4] = source[offset + 4];
|
|
33533
|
-
FLOAT_BYTES[5] = source[offset + 5];
|
|
33534
|
-
FLOAT_BYTES[6] = source[offset + 6];
|
|
33535
|
-
FLOAT_BYTES[7] = source[offset + 7];
|
|
33536
|
-
return FLOAT[0];
|
|
33537
|
-
},
|
|
33538
|
-
setInt32BE(destination, offset, value) {
|
|
33539
|
-
destination[offset + 3] = value;
|
|
33540
|
-
value >>>= 8;
|
|
33541
|
-
destination[offset + 2] = value;
|
|
33542
|
-
value >>>= 8;
|
|
33543
|
-
destination[offset + 1] = value;
|
|
33544
|
-
value >>>= 8;
|
|
33545
|
-
destination[offset] = value;
|
|
33546
|
-
return 4;
|
|
33547
|
-
},
|
|
33548
|
-
setInt32LE(destination, offset, value) {
|
|
33549
|
-
destination[offset] = value;
|
|
33550
|
-
value >>>= 8;
|
|
33551
|
-
destination[offset + 1] = value;
|
|
33552
|
-
value >>>= 8;
|
|
33553
|
-
destination[offset + 2] = value;
|
|
33554
|
-
value >>>= 8;
|
|
33555
|
-
destination[offset + 3] = value;
|
|
33556
|
-
return 4;
|
|
33557
|
-
},
|
|
33558
|
-
setBigInt64LE(destination, offset, value) {
|
|
33559
|
-
const mask32bits = BigInt(4294967295);
|
|
33560
|
-
let lo = Number(value & mask32bits);
|
|
33561
|
-
destination[offset] = lo;
|
|
33562
|
-
lo >>= 8;
|
|
33563
|
-
destination[offset + 1] = lo;
|
|
33564
|
-
lo >>= 8;
|
|
33565
|
-
destination[offset + 2] = lo;
|
|
33566
|
-
lo >>= 8;
|
|
33567
|
-
destination[offset + 3] = lo;
|
|
33568
|
-
let hi = Number(value >> BigInt(32) & mask32bits);
|
|
33569
|
-
destination[offset + 4] = hi;
|
|
33570
|
-
hi >>= 8;
|
|
33571
|
-
destination[offset + 5] = hi;
|
|
33572
|
-
hi >>= 8;
|
|
33573
|
-
destination[offset + 6] = hi;
|
|
33574
|
-
hi >>= 8;
|
|
33575
|
-
destination[offset + 7] = hi;
|
|
33576
|
-
return 8;
|
|
33577
|
-
},
|
|
33578
|
-
setFloat64LE: isBigEndian ? (destination, offset, value) => {
|
|
33579
|
-
FLOAT[0] = value;
|
|
33580
|
-
destination[offset] = FLOAT_BYTES[7];
|
|
33581
|
-
destination[offset + 1] = FLOAT_BYTES[6];
|
|
33582
|
-
destination[offset + 2] = FLOAT_BYTES[5];
|
|
33583
|
-
destination[offset + 3] = FLOAT_BYTES[4];
|
|
33584
|
-
destination[offset + 4] = FLOAT_BYTES[3];
|
|
33585
|
-
destination[offset + 5] = FLOAT_BYTES[2];
|
|
33586
|
-
destination[offset + 6] = FLOAT_BYTES[1];
|
|
33587
|
-
destination[offset + 7] = FLOAT_BYTES[0];
|
|
33588
|
-
return 8;
|
|
33589
|
-
} : (destination, offset, value) => {
|
|
33590
|
-
FLOAT[0] = value;
|
|
33591
|
-
destination[offset] = FLOAT_BYTES[0];
|
|
33592
|
-
destination[offset + 1] = FLOAT_BYTES[1];
|
|
33593
|
-
destination[offset + 2] = FLOAT_BYTES[2];
|
|
33594
|
-
destination[offset + 3] = FLOAT_BYTES[3];
|
|
33595
|
-
destination[offset + 4] = FLOAT_BYTES[4];
|
|
33596
|
-
destination[offset + 5] = FLOAT_BYTES[5];
|
|
33597
|
-
destination[offset + 6] = FLOAT_BYTES[6];
|
|
33598
|
-
destination[offset + 7] = FLOAT_BYTES[7];
|
|
33599
|
-
return 8;
|
|
33600
|
-
}
|
|
33601
|
-
};
|
|
33602
|
-
var Binary = class extends BSONValue {
|
|
33603
|
-
get _bsontype() {
|
|
33604
|
-
return "Binary";
|
|
33605
|
-
}
|
|
33606
|
-
constructor(buffer2, subType) {
|
|
33607
|
-
super();
|
|
33608
|
-
if (!(buffer2 == null) && typeof buffer2 === "string" && !ArrayBuffer.isView(buffer2) && !isAnyArrayBuffer(buffer2) && !Array.isArray(buffer2)) {
|
|
33609
|
-
throw new BSONError("Binary can only be constructed from Uint8Array or number[]");
|
|
33610
|
-
}
|
|
33611
|
-
this.sub_type = subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT;
|
|
33612
|
-
if (buffer2 == null) {
|
|
33613
|
-
this.buffer = ByteUtils.allocate(Binary.BUFFER_SIZE);
|
|
33614
|
-
this.position = 0;
|
|
33615
|
-
} else {
|
|
33616
|
-
this.buffer = Array.isArray(buffer2) ? ByteUtils.fromNumberArray(buffer2) : ByteUtils.toLocalBufferType(buffer2);
|
|
33617
|
-
this.position = this.buffer.byteLength;
|
|
33618
|
-
}
|
|
33619
|
-
}
|
|
33620
|
-
put(byteValue) {
|
|
33621
|
-
if (typeof byteValue === "string" && byteValue.length !== 1) {
|
|
33622
|
-
throw new BSONError("only accepts single character String");
|
|
33623
|
-
} else if (typeof byteValue !== "number" && byteValue.length !== 1)
|
|
33624
|
-
throw new BSONError("only accepts single character Uint8Array or Array");
|
|
33625
|
-
let decodedByte;
|
|
33626
|
-
if (typeof byteValue === "string") {
|
|
33627
|
-
decodedByte = byteValue.charCodeAt(0);
|
|
33628
|
-
} else if (typeof byteValue === "number") {
|
|
33629
|
-
decodedByte = byteValue;
|
|
33630
|
-
} else {
|
|
33631
|
-
decodedByte = byteValue[0];
|
|
33632
|
-
}
|
|
33633
|
-
if (decodedByte < 0 || decodedByte > 255) {
|
|
33634
|
-
throw new BSONError("only accepts number in a valid unsigned byte range 0-255");
|
|
33635
|
-
}
|
|
33636
|
-
if (this.buffer.byteLength > this.position) {
|
|
33637
|
-
this.buffer[this.position++] = decodedByte;
|
|
33638
|
-
} else {
|
|
33639
|
-
const newSpace = ByteUtils.allocate(Binary.BUFFER_SIZE + this.buffer.length);
|
|
33640
|
-
newSpace.set(this.buffer, 0);
|
|
33641
|
-
this.buffer = newSpace;
|
|
33642
|
-
this.buffer[this.position++] = decodedByte;
|
|
33643
|
-
}
|
|
33644
|
-
}
|
|
33645
|
-
write(sequence, offset) {
|
|
33646
|
-
offset = typeof offset === "number" ? offset : this.position;
|
|
33647
|
-
if (this.buffer.byteLength < offset + sequence.length) {
|
|
33648
|
-
const newSpace = ByteUtils.allocate(this.buffer.byteLength + sequence.length);
|
|
33649
|
-
newSpace.set(this.buffer, 0);
|
|
33650
|
-
this.buffer = newSpace;
|
|
33651
|
-
}
|
|
33652
|
-
if (ArrayBuffer.isView(sequence)) {
|
|
33653
|
-
this.buffer.set(ByteUtils.toLocalBufferType(sequence), offset);
|
|
33654
|
-
this.position = offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
|
|
33655
|
-
} else if (typeof sequence === "string") {
|
|
33656
|
-
throw new BSONError("input cannot be string");
|
|
33657
|
-
}
|
|
33658
|
-
}
|
|
33659
|
-
read(position, length) {
|
|
33660
|
-
length = length && length > 0 ? length : this.position;
|
|
33661
|
-
const end = position + length;
|
|
33662
|
-
return this.buffer.subarray(position, end > this.position ? this.position : end);
|
|
33663
|
-
}
|
|
33664
|
-
value() {
|
|
33665
|
-
return this.buffer.length === this.position ? this.buffer : this.buffer.subarray(0, this.position);
|
|
33666
|
-
}
|
|
33667
|
-
length() {
|
|
33668
|
-
return this.position;
|
|
33669
|
-
}
|
|
33670
|
-
toJSON() {
|
|
33671
|
-
return ByteUtils.toBase64(this.buffer.subarray(0, this.position));
|
|
33672
|
-
}
|
|
33673
|
-
toString(encoding) {
|
|
33674
|
-
if (encoding === "hex")
|
|
33675
|
-
return ByteUtils.toHex(this.buffer.subarray(0, this.position));
|
|
33676
|
-
if (encoding === "base64")
|
|
33677
|
-
return ByteUtils.toBase64(this.buffer.subarray(0, this.position));
|
|
33678
|
-
if (encoding === "utf8" || encoding === "utf-8")
|
|
33679
|
-
return ByteUtils.toUTF8(this.buffer, 0, this.position, false);
|
|
33680
|
-
return ByteUtils.toUTF8(this.buffer, 0, this.position, false);
|
|
33681
|
-
}
|
|
33682
|
-
toExtendedJSON(options) {
|
|
33683
|
-
options = options || {};
|
|
33684
|
-
if (this.sub_type === Binary.SUBTYPE_VECTOR) {
|
|
33685
|
-
validateBinaryVector(this);
|
|
33686
|
-
}
|
|
33687
|
-
const base64String = ByteUtils.toBase64(this.buffer);
|
|
33688
|
-
const subType = Number(this.sub_type).toString(16);
|
|
33689
|
-
if (options.legacy) {
|
|
33690
|
-
return {
|
|
33691
|
-
$binary: base64String,
|
|
33692
|
-
$type: subType.length === 1 ? "0" + subType : subType
|
|
33693
|
-
};
|
|
33694
|
-
}
|
|
33695
|
-
return {
|
|
33696
|
-
$binary: {
|
|
33697
|
-
base64: base64String,
|
|
33698
|
-
subType: subType.length === 1 ? "0" + subType : subType
|
|
33699
|
-
}
|
|
33700
|
-
};
|
|
33701
|
-
}
|
|
33702
|
-
toUUID() {
|
|
33703
|
-
if (this.sub_type === Binary.SUBTYPE_UUID) {
|
|
33704
|
-
return new UUID(this.buffer.subarray(0, this.position));
|
|
33705
|
-
}
|
|
33706
|
-
throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`);
|
|
33707
|
-
}
|
|
33708
|
-
static createFromHexString(hex, subType) {
|
|
33709
|
-
return new Binary(ByteUtils.fromHex(hex), subType);
|
|
33710
|
-
}
|
|
33711
|
-
static createFromBase64(base64, subType) {
|
|
33712
|
-
return new Binary(ByteUtils.fromBase64(base64), subType);
|
|
33713
|
-
}
|
|
33714
|
-
static fromExtendedJSON(doc, options) {
|
|
33715
|
-
options = options || {};
|
|
33716
|
-
let data;
|
|
33717
|
-
let type;
|
|
33718
|
-
if ("$binary" in doc) {
|
|
33719
|
-
if (options.legacy && typeof doc.$binary === "string" && "$type" in doc) {
|
|
33720
|
-
type = doc.$type ? parseInt(doc.$type, 16) : 0;
|
|
33721
|
-
data = ByteUtils.fromBase64(doc.$binary);
|
|
33722
|
-
} else {
|
|
33723
|
-
if (typeof doc.$binary !== "string") {
|
|
33724
|
-
type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
|
|
33725
|
-
data = ByteUtils.fromBase64(doc.$binary.base64);
|
|
33726
|
-
}
|
|
33727
|
-
}
|
|
33728
|
-
} else if ("$uuid" in doc) {
|
|
33729
|
-
type = 4;
|
|
33730
|
-
data = UUID.bytesFromString(doc.$uuid);
|
|
33731
|
-
}
|
|
33732
|
-
if (!data) {
|
|
33733
|
-
throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`);
|
|
33734
|
-
}
|
|
33735
|
-
return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
|
|
33736
|
-
}
|
|
33737
|
-
inspect(depth, options, inspect) {
|
|
33738
|
-
inspect ?? (inspect = defaultInspect);
|
|
33739
|
-
const base64 = ByteUtils.toBase64(this.buffer.subarray(0, this.position));
|
|
33740
|
-
const base64Arg = inspect(base64, options);
|
|
33741
|
-
const subTypeArg = inspect(this.sub_type, options);
|
|
33742
|
-
return `Binary.createFromBase64(${base64Arg}, ${subTypeArg})`;
|
|
33743
|
-
}
|
|
33744
|
-
toInt8Array() {
|
|
33745
|
-
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
|
33746
|
-
throw new BSONError("Binary sub_type is not Vector");
|
|
33747
|
-
}
|
|
33748
|
-
if (this.buffer[0] !== Binary.VECTOR_TYPE.Int8) {
|
|
33749
|
-
throw new BSONError("Binary datatype field is not Int8");
|
|
33750
|
-
}
|
|
33751
|
-
validateBinaryVector(this);
|
|
33752
|
-
return new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
|
|
33753
|
-
}
|
|
33754
|
-
toFloat32Array() {
|
|
33755
|
-
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
|
33756
|
-
throw new BSONError("Binary sub_type is not Vector");
|
|
33757
|
-
}
|
|
33758
|
-
if (this.buffer[0] !== Binary.VECTOR_TYPE.Float32) {
|
|
33759
|
-
throw new BSONError("Binary datatype field is not Float32");
|
|
33760
|
-
}
|
|
33761
|
-
validateBinaryVector(this);
|
|
33762
|
-
const floatBytes = new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
|
|
33763
|
-
if (NumberUtils.isBigEndian)
|
|
33764
|
-
ByteUtils.swap32(floatBytes);
|
|
33765
|
-
return new Float32Array(floatBytes.buffer);
|
|
33766
|
-
}
|
|
33767
|
-
toPackedBits() {
|
|
33768
|
-
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
|
33769
|
-
throw new BSONError("Binary sub_type is not Vector");
|
|
33770
|
-
}
|
|
33771
|
-
if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
|
|
33772
|
-
throw new BSONError("Binary datatype field is not packed bit");
|
|
33773
|
-
}
|
|
33774
|
-
validateBinaryVector(this);
|
|
33775
|
-
return new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position));
|
|
33776
|
-
}
|
|
33777
|
-
toBits() {
|
|
33778
|
-
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
|
33779
|
-
throw new BSONError("Binary sub_type is not Vector");
|
|
33780
|
-
}
|
|
33781
|
-
if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
|
|
33782
|
-
throw new BSONError("Binary datatype field is not packed bit");
|
|
33783
|
-
}
|
|
33784
|
-
validateBinaryVector(this);
|
|
33785
|
-
const byteCount = this.length() - 2;
|
|
33786
|
-
const bitCount = byteCount * 8 - this.buffer[1];
|
|
33787
|
-
const bits = new Int8Array(bitCount);
|
|
33788
|
-
for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
|
|
33789
|
-
const byteOffset = bitOffset / 8 | 0;
|
|
33790
|
-
const byte = this.buffer[byteOffset + 2];
|
|
33791
|
-
const shift = 7 - bitOffset % 8;
|
|
33792
|
-
const bit = byte >> shift & 1;
|
|
33793
|
-
bits[bitOffset] = bit;
|
|
33794
|
-
}
|
|
33795
|
-
return bits;
|
|
33796
|
-
}
|
|
33797
|
-
static fromInt8Array(array) {
|
|
33798
|
-
const buffer2 = ByteUtils.allocate(array.byteLength + 2);
|
|
33799
|
-
buffer2[0] = Binary.VECTOR_TYPE.Int8;
|
|
33800
|
-
buffer2[1] = 0;
|
|
33801
|
-
const intBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
33802
|
-
buffer2.set(intBytes, 2);
|
|
33803
|
-
const bin = new this(buffer2, this.SUBTYPE_VECTOR);
|
|
33804
|
-
validateBinaryVector(bin);
|
|
33805
|
-
return bin;
|
|
33806
|
-
}
|
|
33807
|
-
static fromFloat32Array(array) {
|
|
33808
|
-
const binaryBytes = ByteUtils.allocate(array.byteLength + 2);
|
|
33809
|
-
binaryBytes[0] = Binary.VECTOR_TYPE.Float32;
|
|
33810
|
-
binaryBytes[1] = 0;
|
|
33811
|
-
const floatBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
|
33812
|
-
binaryBytes.set(floatBytes, 2);
|
|
33813
|
-
if (NumberUtils.isBigEndian)
|
|
33814
|
-
ByteUtils.swap32(new Uint8Array(binaryBytes.buffer, 2));
|
|
33815
|
-
const bin = new this(binaryBytes, this.SUBTYPE_VECTOR);
|
|
33816
|
-
validateBinaryVector(bin);
|
|
33817
|
-
return bin;
|
|
33818
|
-
}
|
|
33819
|
-
static fromPackedBits(array, padding = 0) {
|
|
33820
|
-
const buffer2 = ByteUtils.allocate(array.byteLength + 2);
|
|
33821
|
-
buffer2[0] = Binary.VECTOR_TYPE.PackedBit;
|
|
33822
|
-
buffer2[1] = padding;
|
|
33823
|
-
buffer2.set(array, 2);
|
|
33824
|
-
const bin = new this(buffer2, this.SUBTYPE_VECTOR);
|
|
33825
|
-
validateBinaryVector(bin);
|
|
33826
|
-
return bin;
|
|
33827
|
-
}
|
|
33828
|
-
static fromBits(bits) {
|
|
33829
|
-
const byteLength = bits.length + 7 >>> 3;
|
|
33830
|
-
const bytes = new Uint8Array(byteLength + 2);
|
|
33831
|
-
bytes[0] = Binary.VECTOR_TYPE.PackedBit;
|
|
33832
|
-
const remainder = bits.length % 8;
|
|
33833
|
-
bytes[1] = remainder === 0 ? 0 : 8 - remainder;
|
|
33834
|
-
for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
|
|
33835
|
-
const byteOffset = bitOffset >>> 3;
|
|
33836
|
-
const bit = bits[bitOffset];
|
|
33837
|
-
if (bit !== 0 && bit !== 1) {
|
|
33838
|
-
throw new BSONError(`Invalid bit value at ${bitOffset}: must be 0 or 1, found ${bits[bitOffset]}`);
|
|
33839
|
-
}
|
|
33840
|
-
if (bit === 0)
|
|
33841
|
-
continue;
|
|
33842
|
-
const shift = 7 - bitOffset % 8;
|
|
33843
|
-
bytes[byteOffset + 2] |= bit << shift;
|
|
33844
|
-
}
|
|
33845
|
-
return new this(bytes, Binary.SUBTYPE_VECTOR);
|
|
33846
|
-
}
|
|
33847
|
-
};
|
|
33848
|
-
Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
33849
|
-
Binary.BUFFER_SIZE = 256;
|
|
33850
|
-
Binary.SUBTYPE_DEFAULT = 0;
|
|
33851
|
-
Binary.SUBTYPE_FUNCTION = 1;
|
|
33852
|
-
Binary.SUBTYPE_BYTE_ARRAY = 2;
|
|
33853
|
-
Binary.SUBTYPE_UUID_OLD = 3;
|
|
33854
|
-
Binary.SUBTYPE_UUID = 4;
|
|
33855
|
-
Binary.SUBTYPE_MD5 = 5;
|
|
33856
|
-
Binary.SUBTYPE_ENCRYPTED = 6;
|
|
33857
|
-
Binary.SUBTYPE_COLUMN = 7;
|
|
33858
|
-
Binary.SUBTYPE_SENSITIVE = 8;
|
|
33859
|
-
Binary.SUBTYPE_VECTOR = 9;
|
|
33860
|
-
Binary.SUBTYPE_USER_DEFINED = 128;
|
|
33861
|
-
Binary.VECTOR_TYPE = Object.freeze({
|
|
33862
|
-
Int8: 3,
|
|
33863
|
-
Float32: 39,
|
|
33864
|
-
PackedBit: 16
|
|
33865
|
-
});
|
|
33866
|
-
function validateBinaryVector(vector) {
|
|
33867
|
-
if (vector.sub_type !== Binary.SUBTYPE_VECTOR)
|
|
33868
|
-
return;
|
|
33869
|
-
const size = vector.position;
|
|
33870
|
-
const datatype = vector.buffer[0];
|
|
33871
|
-
const padding = vector.buffer[1];
|
|
33872
|
-
if ((datatype === Binary.VECTOR_TYPE.Float32 || datatype === Binary.VECTOR_TYPE.Int8) && padding !== 0) {
|
|
33873
|
-
throw new BSONError("Invalid Vector: padding must be zero for int8 and float32 vectors");
|
|
33874
|
-
}
|
|
33875
|
-
if (datatype === Binary.VECTOR_TYPE.Float32) {
|
|
33876
|
-
if (size !== 0 && size - 2 !== 0 && (size - 2) % 4 !== 0) {
|
|
33877
|
-
throw new BSONError("Invalid Vector: Float32 vector must contain a multiple of 4 bytes");
|
|
33878
|
-
}
|
|
33879
|
-
}
|
|
33880
|
-
if (datatype === Binary.VECTOR_TYPE.PackedBit && padding !== 0 && size === 2) {
|
|
33881
|
-
throw new BSONError("Invalid Vector: padding must be zero for packed bit vectors that are empty");
|
|
33882
|
-
}
|
|
33883
|
-
if (datatype === Binary.VECTOR_TYPE.PackedBit && padding > 7) {
|
|
33884
|
-
throw new BSONError(`Invalid Vector: padding must be a value between 0 and 7. found: ${padding}`);
|
|
33885
|
-
}
|
|
33886
|
-
}
|
|
33887
|
-
var UUID_BYTE_LENGTH = 16;
|
|
33888
|
-
var UUID_WITHOUT_DASHES = /^[0-9A-F]{32}$/i;
|
|
33889
|
-
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;
|
|
33890
|
-
var UUID = class extends Binary {
|
|
33891
|
-
constructor(input) {
|
|
33892
|
-
let bytes;
|
|
33893
|
-
if (input == null) {
|
|
33894
|
-
bytes = UUID.generate();
|
|
33895
|
-
} else if (input instanceof UUID) {
|
|
33896
|
-
bytes = ByteUtils.toLocalBufferType(new Uint8Array(input.buffer));
|
|
33897
|
-
} else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
|
|
33898
|
-
bytes = ByteUtils.toLocalBufferType(input);
|
|
33899
|
-
} else if (typeof input === "string") {
|
|
33900
|
-
bytes = UUID.bytesFromString(input);
|
|
33901
|
-
} else {
|
|
33902
|
-
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).");
|
|
33903
|
-
}
|
|
33904
|
-
super(bytes, BSON_BINARY_SUBTYPE_UUID_NEW);
|
|
33905
|
-
}
|
|
33906
|
-
get id() {
|
|
33907
|
-
return this.buffer;
|
|
33908
|
-
}
|
|
33909
|
-
set id(value) {
|
|
33910
|
-
this.buffer = value;
|
|
33911
|
-
}
|
|
33912
|
-
toHexString(includeDashes = true) {
|
|
33913
|
-
if (includeDashes) {
|
|
33914
|
-
return [
|
|
33915
|
-
ByteUtils.toHex(this.buffer.subarray(0, 4)),
|
|
33916
|
-
ByteUtils.toHex(this.buffer.subarray(4, 6)),
|
|
33917
|
-
ByteUtils.toHex(this.buffer.subarray(6, 8)),
|
|
33918
|
-
ByteUtils.toHex(this.buffer.subarray(8, 10)),
|
|
33919
|
-
ByteUtils.toHex(this.buffer.subarray(10, 16))
|
|
33920
|
-
].join("-");
|
|
33921
|
-
}
|
|
33922
|
-
return ByteUtils.toHex(this.buffer);
|
|
33923
|
-
}
|
|
33924
|
-
toString(encoding) {
|
|
33925
|
-
if (encoding === "hex")
|
|
33926
|
-
return ByteUtils.toHex(this.id);
|
|
33927
|
-
if (encoding === "base64")
|
|
33928
|
-
return ByteUtils.toBase64(this.id);
|
|
33929
|
-
return this.toHexString();
|
|
33930
|
-
}
|
|
33931
|
-
toJSON() {
|
|
33932
|
-
return this.toHexString();
|
|
33933
|
-
}
|
|
33934
|
-
equals(otherId) {
|
|
33935
|
-
if (!otherId) {
|
|
33936
|
-
return false;
|
|
33937
|
-
}
|
|
33938
|
-
if (otherId instanceof UUID) {
|
|
33939
|
-
return ByteUtils.equals(otherId.id, this.id);
|
|
33940
|
-
}
|
|
33941
|
-
try {
|
|
33942
|
-
return ByteUtils.equals(new UUID(otherId).id, this.id);
|
|
33943
|
-
} catch {
|
|
33944
|
-
return false;
|
|
33945
|
-
}
|
|
33946
|
-
}
|
|
33947
|
-
toBinary() {
|
|
33948
|
-
return new Binary(this.id, Binary.SUBTYPE_UUID);
|
|
33949
|
-
}
|
|
33950
|
-
static generate() {
|
|
33951
|
-
const bytes = ByteUtils.randomBytes(UUID_BYTE_LENGTH);
|
|
33952
|
-
bytes[6] = bytes[6] & 15 | 64;
|
|
33953
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
33954
|
-
return bytes;
|
|
33955
|
-
}
|
|
33956
|
-
static isValid(input) {
|
|
33957
|
-
if (!input) {
|
|
33958
|
-
return false;
|
|
33959
|
-
}
|
|
33960
|
-
if (typeof input === "string") {
|
|
33961
|
-
return UUID.isValidUUIDString(input);
|
|
33962
|
-
}
|
|
33963
|
-
if (isUint8Array(input)) {
|
|
33964
|
-
return input.byteLength === UUID_BYTE_LENGTH;
|
|
33965
|
-
}
|
|
33966
|
-
return input._bsontype === "Binary" && input.sub_type === this.SUBTYPE_UUID && input.buffer.byteLength === 16;
|
|
33967
|
-
}
|
|
33968
|
-
static createFromHexString(hexString) {
|
|
33969
|
-
const buffer2 = UUID.bytesFromString(hexString);
|
|
33970
|
-
return new UUID(buffer2);
|
|
33971
|
-
}
|
|
33972
|
-
static createFromBase64(base64) {
|
|
33973
|
-
return new UUID(ByteUtils.fromBase64(base64));
|
|
33974
|
-
}
|
|
33975
|
-
static bytesFromString(representation) {
|
|
33976
|
-
if (!UUID.isValidUUIDString(representation)) {
|
|
33977
|
-
throw new BSONError("UUID string representation must be 32 hex digits or canonical hyphenated representation");
|
|
33978
|
-
}
|
|
33979
|
-
return ByteUtils.fromHex(representation.replace(/-/g, ""));
|
|
33980
|
-
}
|
|
33981
|
-
static isValidUUIDString(representation) {
|
|
33982
|
-
return UUID_WITHOUT_DASHES.test(representation) || UUID_WITH_DASHES.test(representation);
|
|
33983
|
-
}
|
|
33984
|
-
inspect(depth, options, inspect) {
|
|
33985
|
-
inspect ?? (inspect = defaultInspect);
|
|
33986
|
-
return `new UUID(${inspect(this.toHexString(), options)})`;
|
|
33987
|
-
}
|
|
33988
|
-
};
|
|
33989
|
-
var Code = class extends BSONValue {
|
|
33990
|
-
get _bsontype() {
|
|
33991
|
-
return "Code";
|
|
33992
|
-
}
|
|
33993
|
-
constructor(code, scope) {
|
|
33994
|
-
super();
|
|
33995
|
-
this.code = code.toString();
|
|
33996
|
-
this.scope = scope ?? null;
|
|
33997
|
-
}
|
|
33998
|
-
toJSON() {
|
|
33999
|
-
if (this.scope != null) {
|
|
34000
|
-
return { code: this.code, scope: this.scope };
|
|
34001
|
-
}
|
|
34002
|
-
return { code: this.code };
|
|
34003
|
-
}
|
|
34004
|
-
toExtendedJSON() {
|
|
34005
|
-
if (this.scope) {
|
|
34006
|
-
return { $code: this.code, $scope: this.scope };
|
|
34007
|
-
}
|
|
34008
|
-
return { $code: this.code };
|
|
34009
|
-
}
|
|
34010
|
-
static fromExtendedJSON(doc) {
|
|
34011
|
-
return new Code(doc.$code, doc.$scope);
|
|
34012
|
-
}
|
|
34013
|
-
inspect(depth, options, inspect) {
|
|
34014
|
-
inspect ?? (inspect = defaultInspect);
|
|
34015
|
-
let parametersString = inspect(this.code, options);
|
|
34016
|
-
const multiLineFn = parametersString.includes("\n");
|
|
34017
|
-
if (this.scope != null) {
|
|
34018
|
-
parametersString += `,${multiLineFn ? "\n" : " "}${inspect(this.scope, options)}`;
|
|
34019
|
-
}
|
|
34020
|
-
const endingNewline = multiLineFn && this.scope === null;
|
|
34021
|
-
return `new Code(${multiLineFn ? "\n" : ""}${parametersString}${endingNewline ? "\n" : ""})`;
|
|
34022
|
-
}
|
|
34023
|
-
};
|
|
34024
|
-
function isDBRefLike(value) {
|
|
34025
|
-
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");
|
|
34026
|
-
}
|
|
34027
|
-
var DBRef = class extends BSONValue {
|
|
34028
|
-
get _bsontype() {
|
|
34029
|
-
return "DBRef";
|
|
34030
|
-
}
|
|
34031
|
-
constructor(collection, oid, db, fields) {
|
|
34032
|
-
super();
|
|
34033
|
-
const parts = collection.split(".");
|
|
34034
|
-
if (parts.length === 2) {
|
|
34035
|
-
db = parts.shift();
|
|
34036
|
-
collection = parts.shift();
|
|
34037
|
-
}
|
|
34038
|
-
this.collection = collection;
|
|
34039
|
-
this.oid = oid;
|
|
34040
|
-
this.db = db;
|
|
34041
|
-
this.fields = fields || {};
|
|
34042
|
-
}
|
|
34043
|
-
get namespace() {
|
|
34044
|
-
return this.collection;
|
|
34045
|
-
}
|
|
34046
|
-
set namespace(value) {
|
|
34047
|
-
this.collection = value;
|
|
34048
|
-
}
|
|
34049
|
-
toJSON() {
|
|
34050
|
-
const o = Object.assign({
|
|
34051
|
-
$ref: this.collection,
|
|
34052
|
-
$id: this.oid
|
|
34053
|
-
}, this.fields);
|
|
34054
|
-
if (this.db != null)
|
|
34055
|
-
o.$db = this.db;
|
|
34056
|
-
return o;
|
|
34057
|
-
}
|
|
34058
|
-
toExtendedJSON(options) {
|
|
34059
|
-
options = options || {};
|
|
34060
|
-
let o = {
|
|
34061
|
-
$ref: this.collection,
|
|
34062
|
-
$id: this.oid
|
|
34063
|
-
};
|
|
34064
|
-
if (options.legacy) {
|
|
34065
|
-
return o;
|
|
34066
|
-
}
|
|
34067
|
-
if (this.db)
|
|
34068
|
-
o.$db = this.db;
|
|
34069
|
-
o = Object.assign(o, this.fields);
|
|
34070
|
-
return o;
|
|
34071
|
-
}
|
|
34072
|
-
static fromExtendedJSON(doc) {
|
|
34073
|
-
const copy = Object.assign({}, doc);
|
|
34074
|
-
delete copy.$ref;
|
|
34075
|
-
delete copy.$id;
|
|
34076
|
-
delete copy.$db;
|
|
34077
|
-
return new DBRef(doc.$ref, doc.$id, doc.$db, copy);
|
|
34078
|
-
}
|
|
34079
|
-
inspect(depth, options, inspect) {
|
|
34080
|
-
inspect ?? (inspect = defaultInspect);
|
|
34081
|
-
const args = [
|
|
34082
|
-
inspect(this.namespace, options),
|
|
34083
|
-
inspect(this.oid, options),
|
|
34084
|
-
...this.db ? [inspect(this.db, options)] : [],
|
|
34085
|
-
...Object.keys(this.fields).length > 0 ? [inspect(this.fields, options)] : []
|
|
34086
|
-
];
|
|
34087
|
-
args[1] = inspect === defaultInspect ? `new ObjectId(${args[1]})` : args[1];
|
|
34088
|
-
return `new DBRef(${args.join(", ")})`;
|
|
34089
|
-
}
|
|
34090
|
-
};
|
|
34091
|
-
function removeLeadingZerosAndExplicitPlus(str) {
|
|
34092
|
-
if (str === "") {
|
|
34093
|
-
return str;
|
|
34094
|
-
}
|
|
34095
|
-
let startIndex = 0;
|
|
34096
|
-
const isNegative = str[startIndex] === "-";
|
|
34097
|
-
const isExplicitlyPositive = str[startIndex] === "+";
|
|
34098
|
-
if (isExplicitlyPositive || isNegative) {
|
|
34099
|
-
startIndex += 1;
|
|
34100
|
-
}
|
|
34101
|
-
let foundInsignificantZero = false;
|
|
34102
|
-
for (; startIndex < str.length && str[startIndex] === "0"; ++startIndex) {
|
|
34103
|
-
foundInsignificantZero = true;
|
|
34104
|
-
}
|
|
34105
|
-
if (!foundInsignificantZero) {
|
|
34106
|
-
return isExplicitlyPositive ? str.slice(1) : str;
|
|
34107
|
-
}
|
|
34108
|
-
return `${isNegative ? "-" : ""}${str.length === startIndex ? "0" : str.slice(startIndex)}`;
|
|
34109
|
-
}
|
|
34110
|
-
function validateStringCharacters(str, radix) {
|
|
34111
|
-
radix = radix ?? 10;
|
|
34112
|
-
const validCharacters = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, radix);
|
|
34113
|
-
const regex = new RegExp(`[^-+${validCharacters}]`, "i");
|
|
34114
|
-
return regex.test(str) ? false : str;
|
|
34115
|
-
}
|
|
34116
|
-
var wasm = void 0;
|
|
34117
|
-
try {
|
|
34118
|
-
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;
|
|
34119
|
-
} catch {
|
|
34120
|
-
}
|
|
34121
|
-
var TWO_PWR_16_DBL = 1 << 16;
|
|
34122
|
-
var TWO_PWR_24_DBL = 1 << 24;
|
|
34123
|
-
var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
|
|
34124
|
-
var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
|
|
34125
|
-
var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
|
|
34126
|
-
var INT_CACHE = {};
|
|
34127
|
-
var UINT_CACHE = {};
|
|
34128
|
-
var MAX_INT64_STRING_LENGTH = 20;
|
|
34129
|
-
var DECIMAL_REG_EX = /^(\+?0|(\+|-)?[1-9][0-9]*)$/;
|
|
34130
|
-
var Long = class extends BSONValue {
|
|
34131
|
-
get _bsontype() {
|
|
34132
|
-
return "Long";
|
|
34133
|
-
}
|
|
34134
|
-
get __isLong__() {
|
|
34135
|
-
return true;
|
|
34136
|
-
}
|
|
34137
|
-
constructor(lowOrValue = 0, highOrUnsigned, unsigned) {
|
|
34138
|
-
super();
|
|
34139
|
-
const unsignedBool = typeof highOrUnsigned === "boolean" ? highOrUnsigned : Boolean(unsigned);
|
|
34140
|
-
const high = typeof highOrUnsigned === "number" ? highOrUnsigned : 0;
|
|
34141
|
-
const res = typeof lowOrValue === "string" ? Long.fromString(lowOrValue, unsignedBool) : typeof lowOrValue === "bigint" ? Long.fromBigInt(lowOrValue, unsignedBool) : { low: lowOrValue | 0, high: high | 0, unsigned: unsignedBool };
|
|
34142
|
-
this.low = res.low;
|
|
34143
|
-
this.high = res.high;
|
|
34144
|
-
this.unsigned = res.unsigned;
|
|
34145
|
-
}
|
|
34146
|
-
static fromBits(lowBits, highBits, unsigned) {
|
|
34147
|
-
return new Long(lowBits, highBits, unsigned);
|
|
34148
|
-
}
|
|
34149
|
-
static fromInt(value, unsigned) {
|
|
34150
|
-
let obj, cachedObj, cache;
|
|
34151
|
-
if (unsigned) {
|
|
34152
|
-
value >>>= 0;
|
|
34153
|
-
if (cache = 0 <= value && value < 256) {
|
|
34154
|
-
cachedObj = UINT_CACHE[value];
|
|
34155
|
-
if (cachedObj)
|
|
34156
|
-
return cachedObj;
|
|
34157
|
-
}
|
|
34158
|
-
obj = Long.fromBits(value, (value | 0) < 0 ? -1 : 0, true);
|
|
34159
|
-
if (cache)
|
|
34160
|
-
UINT_CACHE[value] = obj;
|
|
34161
|
-
return obj;
|
|
34162
|
-
} else {
|
|
34163
|
-
value |= 0;
|
|
34164
|
-
if (cache = -128 <= value && value < 128) {
|
|
34165
|
-
cachedObj = INT_CACHE[value];
|
|
34166
|
-
if (cachedObj)
|
|
34167
|
-
return cachedObj;
|
|
34168
|
-
}
|
|
34169
|
-
obj = Long.fromBits(value, value < 0 ? -1 : 0, false);
|
|
34170
|
-
if (cache)
|
|
34171
|
-
INT_CACHE[value] = obj;
|
|
34172
|
-
return obj;
|
|
34173
|
-
}
|
|
34174
|
-
}
|
|
34175
|
-
static fromNumber(value, unsigned) {
|
|
34176
|
-
if (isNaN(value))
|
|
34177
|
-
return unsigned ? Long.UZERO : Long.ZERO;
|
|
34178
|
-
if (unsigned) {
|
|
34179
|
-
if (value < 0)
|
|
34180
|
-
return Long.UZERO;
|
|
34181
|
-
if (value >= TWO_PWR_64_DBL)
|
|
34182
|
-
return Long.MAX_UNSIGNED_VALUE;
|
|
34183
|
-
} else {
|
|
34184
|
-
if (value <= -9223372036854776e3)
|
|
34185
|
-
return Long.MIN_VALUE;
|
|
34186
|
-
if (value + 1 >= TWO_PWR_63_DBL)
|
|
34187
|
-
return Long.MAX_VALUE;
|
|
34188
|
-
}
|
|
34189
|
-
if (value < 0)
|
|
34190
|
-
return Long.fromNumber(-value, unsigned).neg();
|
|
34191
|
-
return Long.fromBits(value % TWO_PWR_32_DBL | 0, value / TWO_PWR_32_DBL | 0, unsigned);
|
|
34192
|
-
}
|
|
34193
|
-
static fromBigInt(value, unsigned) {
|
|
34194
|
-
const FROM_BIGINT_BIT_MASK = BigInt(4294967295);
|
|
34195
|
-
const FROM_BIGINT_BIT_SHIFT = BigInt(32);
|
|
34196
|
-
return new Long(Number(value & FROM_BIGINT_BIT_MASK), Number(value >> FROM_BIGINT_BIT_SHIFT & FROM_BIGINT_BIT_MASK), unsigned);
|
|
34197
|
-
}
|
|
34198
|
-
static _fromString(str, unsigned, radix) {
|
|
34199
|
-
if (str.length === 0)
|
|
34200
|
-
throw new BSONError("empty string");
|
|
34201
|
-
if (radix < 2 || 36 < radix)
|
|
34202
|
-
throw new BSONError("radix");
|
|
34203
|
-
let p;
|
|
34204
|
-
if ((p = str.indexOf("-")) > 0)
|
|
34205
|
-
throw new BSONError("interior hyphen");
|
|
34206
|
-
else if (p === 0) {
|
|
34207
|
-
return Long._fromString(str.substring(1), unsigned, radix).neg();
|
|
34208
|
-
}
|
|
34209
|
-
const radixToPower = Long.fromNumber(Math.pow(radix, 8));
|
|
34210
|
-
let result = Long.ZERO;
|
|
34211
|
-
for (let i = 0; i < str.length; i += 8) {
|
|
34212
|
-
const size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
|
|
34213
|
-
if (size < 8) {
|
|
34214
|
-
const power = Long.fromNumber(Math.pow(radix, size));
|
|
34215
|
-
result = result.mul(power).add(Long.fromNumber(value));
|
|
34216
|
-
} else {
|
|
34217
|
-
result = result.mul(radixToPower);
|
|
34218
|
-
result = result.add(Long.fromNumber(value));
|
|
34219
|
-
}
|
|
34220
|
-
}
|
|
34221
|
-
result.unsigned = unsigned;
|
|
34222
|
-
return result;
|
|
34223
|
-
}
|
|
34224
|
-
static fromStringStrict(str, unsignedOrRadix, radix) {
|
|
34225
|
-
let unsigned = false;
|
|
34226
|
-
if (typeof unsignedOrRadix === "number") {
|
|
34227
|
-
radix = unsignedOrRadix, unsignedOrRadix = false;
|
|
34228
|
-
} else {
|
|
34229
|
-
unsigned = !!unsignedOrRadix;
|
|
34230
|
-
}
|
|
34231
|
-
radix ?? (radix = 10);
|
|
34232
|
-
if (str.trim() !== str) {
|
|
34233
|
-
throw new BSONError(`Input: '${str}' contains leading and/or trailing whitespace`);
|
|
34234
|
-
}
|
|
34235
|
-
if (!validateStringCharacters(str, radix)) {
|
|
34236
|
-
throw new BSONError(`Input: '${str}' contains invalid characters for radix: ${radix}`);
|
|
34237
|
-
}
|
|
34238
|
-
const cleanedStr = removeLeadingZerosAndExplicitPlus(str);
|
|
34239
|
-
const result = Long._fromString(cleanedStr, unsigned, radix);
|
|
34240
|
-
if (result.toString(radix).toLowerCase() !== cleanedStr.toLowerCase()) {
|
|
34241
|
-
throw new BSONError(`Input: ${str} is not representable as ${result.unsigned ? "an unsigned" : "a signed"} 64-bit Long ${radix != null ? `with radix: ${radix}` : ""}`);
|
|
34242
|
-
}
|
|
34243
|
-
return result;
|
|
34244
|
-
}
|
|
34245
|
-
static fromString(str, unsignedOrRadix, radix) {
|
|
34246
|
-
let unsigned = false;
|
|
34247
|
-
if (typeof unsignedOrRadix === "number") {
|
|
34248
|
-
radix = unsignedOrRadix, unsignedOrRadix = false;
|
|
34249
|
-
} else {
|
|
34250
|
-
unsigned = !!unsignedOrRadix;
|
|
34251
|
-
}
|
|
34252
|
-
radix ?? (radix = 10);
|
|
34253
|
-
if (str === "NaN" && radix < 24) {
|
|
34254
|
-
return Long.ZERO;
|
|
34255
|
-
} else if ((str === "Infinity" || str === "+Infinity" || str === "-Infinity") && radix < 35) {
|
|
34256
|
-
return Long.ZERO;
|
|
34257
|
-
}
|
|
34258
|
-
return Long._fromString(str, unsigned, radix);
|
|
34259
|
-
}
|
|
34260
|
-
static fromBytes(bytes, unsigned, le) {
|
|
34261
|
-
return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
|
|
34262
|
-
}
|
|
34263
|
-
static fromBytesLE(bytes, unsigned) {
|
|
34264
|
-
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);
|
|
34265
|
-
}
|
|
34266
|
-
static fromBytesBE(bytes, unsigned) {
|
|
34267
|
-
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);
|
|
34268
|
-
}
|
|
34269
|
-
static isLong(value) {
|
|
34270
|
-
return value != null && typeof value === "object" && "__isLong__" in value && value.__isLong__ === true;
|
|
34271
|
-
}
|
|
34272
|
-
static fromValue(val, unsigned) {
|
|
34273
|
-
if (typeof val === "number")
|
|
34274
|
-
return Long.fromNumber(val, unsigned);
|
|
34275
|
-
if (typeof val === "string")
|
|
34276
|
-
return Long.fromString(val, unsigned);
|
|
34277
|
-
return Long.fromBits(val.low, val.high, typeof unsigned === "boolean" ? unsigned : val.unsigned);
|
|
34278
|
-
}
|
|
34279
|
-
add(addend) {
|
|
34280
|
-
if (!Long.isLong(addend))
|
|
34281
|
-
addend = Long.fromValue(addend);
|
|
34282
|
-
const a48 = this.high >>> 16;
|
|
34283
|
-
const a32 = this.high & 65535;
|
|
34284
|
-
const a16 = this.low >>> 16;
|
|
34285
|
-
const a00 = this.low & 65535;
|
|
34286
|
-
const b48 = addend.high >>> 16;
|
|
34287
|
-
const b32 = addend.high & 65535;
|
|
34288
|
-
const b16 = addend.low >>> 16;
|
|
34289
|
-
const b00 = addend.low & 65535;
|
|
34290
|
-
let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
|
34291
|
-
c00 += a00 + b00;
|
|
34292
|
-
c16 += c00 >>> 16;
|
|
34293
|
-
c00 &= 65535;
|
|
34294
|
-
c16 += a16 + b16;
|
|
34295
|
-
c32 += c16 >>> 16;
|
|
34296
|
-
c16 &= 65535;
|
|
34297
|
-
c32 += a32 + b32;
|
|
34298
|
-
c48 += c32 >>> 16;
|
|
34299
|
-
c32 &= 65535;
|
|
34300
|
-
c48 += a48 + b48;
|
|
34301
|
-
c48 &= 65535;
|
|
34302
|
-
return Long.fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
|
|
34303
|
-
}
|
|
34304
|
-
and(other) {
|
|
34305
|
-
if (!Long.isLong(other))
|
|
34306
|
-
other = Long.fromValue(other);
|
|
34307
|
-
return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned);
|
|
34308
|
-
}
|
|
34309
|
-
compare(other) {
|
|
34310
|
-
if (!Long.isLong(other))
|
|
34311
|
-
other = Long.fromValue(other);
|
|
34312
|
-
if (this.eq(other))
|
|
34313
|
-
return 0;
|
|
34314
|
-
const thisNeg = this.isNegative(), otherNeg = other.isNegative();
|
|
34315
|
-
if (thisNeg && !otherNeg)
|
|
34316
|
-
return -1;
|
|
34317
|
-
if (!thisNeg && otherNeg)
|
|
34318
|
-
return 1;
|
|
34319
|
-
if (!this.unsigned)
|
|
34320
|
-
return this.sub(other).isNegative() ? -1 : 1;
|
|
34321
|
-
return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
|
|
34322
|
-
}
|
|
34323
|
-
comp(other) {
|
|
34324
|
-
return this.compare(other);
|
|
34325
|
-
}
|
|
34326
|
-
divide(divisor) {
|
|
34327
|
-
if (!Long.isLong(divisor))
|
|
34328
|
-
divisor = Long.fromValue(divisor);
|
|
34329
|
-
if (divisor.isZero())
|
|
34330
|
-
throw new BSONError("division by zero");
|
|
34331
|
-
if (wasm) {
|
|
34332
|
-
if (!this.unsigned && this.high === -2147483648 && divisor.low === -1 && divisor.high === -1) {
|
|
34333
|
-
return this;
|
|
34334
|
-
}
|
|
34335
|
-
const low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
|
|
34336
|
-
return Long.fromBits(low, wasm.get_high(), this.unsigned);
|
|
34337
|
-
}
|
|
34338
|
-
if (this.isZero())
|
|
34339
|
-
return this.unsigned ? Long.UZERO : Long.ZERO;
|
|
34340
|
-
let approx, rem, res;
|
|
34341
|
-
if (!this.unsigned) {
|
|
34342
|
-
if (this.eq(Long.MIN_VALUE)) {
|
|
34343
|
-
if (divisor.eq(Long.ONE) || divisor.eq(Long.NEG_ONE))
|
|
34344
|
-
return Long.MIN_VALUE;
|
|
34345
|
-
else if (divisor.eq(Long.MIN_VALUE))
|
|
34346
|
-
return Long.ONE;
|
|
34347
|
-
else {
|
|
34348
|
-
const halfThis = this.shr(1);
|
|
34349
|
-
approx = halfThis.div(divisor).shl(1);
|
|
34350
|
-
if (approx.eq(Long.ZERO)) {
|
|
34351
|
-
return divisor.isNegative() ? Long.ONE : Long.NEG_ONE;
|
|
34352
|
-
} else {
|
|
34353
|
-
rem = this.sub(divisor.mul(approx));
|
|
34354
|
-
res = approx.add(rem.div(divisor));
|
|
34355
|
-
return res;
|
|
34356
|
-
}
|
|
34357
|
-
}
|
|
34358
|
-
} else if (divisor.eq(Long.MIN_VALUE))
|
|
34359
|
-
return this.unsigned ? Long.UZERO : Long.ZERO;
|
|
34360
|
-
if (this.isNegative()) {
|
|
34361
|
-
if (divisor.isNegative())
|
|
34362
|
-
return this.neg().div(divisor.neg());
|
|
34363
|
-
return this.neg().div(divisor).neg();
|
|
34364
|
-
} else if (divisor.isNegative())
|
|
34365
|
-
return this.div(divisor.neg()).neg();
|
|
34366
|
-
res = Long.ZERO;
|
|
34367
|
-
} else {
|
|
34368
|
-
if (!divisor.unsigned)
|
|
34369
|
-
divisor = divisor.toUnsigned();
|
|
34370
|
-
if (divisor.gt(this))
|
|
34371
|
-
return Long.UZERO;
|
|
34372
|
-
if (divisor.gt(this.shru(1)))
|
|
34373
|
-
return Long.UONE;
|
|
34374
|
-
res = Long.UZERO;
|
|
34375
|
-
}
|
|
34376
|
-
rem = this;
|
|
34377
|
-
while (rem.gte(divisor)) {
|
|
34378
|
-
approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
|
|
34379
|
-
const log2 = Math.ceil(Math.log(approx) / Math.LN2);
|
|
34380
|
-
const delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48);
|
|
34381
|
-
let approxRes = Long.fromNumber(approx);
|
|
34382
|
-
let approxRem = approxRes.mul(divisor);
|
|
34383
|
-
while (approxRem.isNegative() || approxRem.gt(rem)) {
|
|
34384
|
-
approx -= delta;
|
|
34385
|
-
approxRes = Long.fromNumber(approx, this.unsigned);
|
|
34386
|
-
approxRem = approxRes.mul(divisor);
|
|
34387
|
-
}
|
|
34388
|
-
if (approxRes.isZero())
|
|
34389
|
-
approxRes = Long.ONE;
|
|
34390
|
-
res = res.add(approxRes);
|
|
34391
|
-
rem = rem.sub(approxRem);
|
|
34392
|
-
}
|
|
34393
|
-
return res;
|
|
34394
|
-
}
|
|
34395
|
-
div(divisor) {
|
|
34396
|
-
return this.divide(divisor);
|
|
34397
|
-
}
|
|
34398
|
-
equals(other) {
|
|
34399
|
-
if (!Long.isLong(other))
|
|
34400
|
-
other = Long.fromValue(other);
|
|
34401
|
-
if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
|
|
34402
|
-
return false;
|
|
34403
|
-
return this.high === other.high && this.low === other.low;
|
|
34404
|
-
}
|
|
34405
|
-
eq(other) {
|
|
34406
|
-
return this.equals(other);
|
|
34407
|
-
}
|
|
34408
|
-
getHighBits() {
|
|
34409
|
-
return this.high;
|
|
34410
|
-
}
|
|
34411
|
-
getHighBitsUnsigned() {
|
|
34412
|
-
return this.high >>> 0;
|
|
34413
|
-
}
|
|
34414
|
-
getLowBits() {
|
|
34415
|
-
return this.low;
|
|
34416
|
-
}
|
|
34417
|
-
getLowBitsUnsigned() {
|
|
34418
|
-
return this.low >>> 0;
|
|
34419
|
-
}
|
|
34420
|
-
getNumBitsAbs() {
|
|
34421
|
-
if (this.isNegative()) {
|
|
34422
|
-
return this.eq(Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
|
|
34423
|
-
}
|
|
34424
|
-
const val = this.high !== 0 ? this.high : this.low;
|
|
34425
|
-
let bit;
|
|
34426
|
-
for (bit = 31; bit > 0; bit--)
|
|
34427
|
-
if ((val & 1 << bit) !== 0)
|
|
34428
|
-
break;
|
|
34429
|
-
return this.high !== 0 ? bit + 33 : bit + 1;
|
|
34430
|
-
}
|
|
34431
|
-
greaterThan(other) {
|
|
34432
|
-
return this.comp(other) > 0;
|
|
34433
|
-
}
|
|
34434
|
-
gt(other) {
|
|
34435
|
-
return this.greaterThan(other);
|
|
34436
|
-
}
|
|
34437
|
-
greaterThanOrEqual(other) {
|
|
34438
|
-
return this.comp(other) >= 0;
|
|
34439
|
-
}
|
|
34440
|
-
gte(other) {
|
|
34441
|
-
return this.greaterThanOrEqual(other);
|
|
34442
|
-
}
|
|
34443
|
-
ge(other) {
|
|
34444
|
-
return this.greaterThanOrEqual(other);
|
|
34445
|
-
}
|
|
34446
|
-
isEven() {
|
|
34447
|
-
return (this.low & 1) === 0;
|
|
34448
|
-
}
|
|
34449
|
-
isNegative() {
|
|
34450
|
-
return !this.unsigned && this.high < 0;
|
|
34451
|
-
}
|
|
34452
|
-
isOdd() {
|
|
34453
|
-
return (this.low & 1) === 1;
|
|
34454
|
-
}
|
|
34455
|
-
isPositive() {
|
|
34456
|
-
return this.unsigned || this.high >= 0;
|
|
34457
|
-
}
|
|
34458
|
-
isZero() {
|
|
34459
|
-
return this.high === 0 && this.low === 0;
|
|
34460
|
-
}
|
|
34461
|
-
lessThan(other) {
|
|
34462
|
-
return this.comp(other) < 0;
|
|
34463
|
-
}
|
|
34464
|
-
lt(other) {
|
|
34465
|
-
return this.lessThan(other);
|
|
34466
|
-
}
|
|
34467
|
-
lessThanOrEqual(other) {
|
|
34468
|
-
return this.comp(other) <= 0;
|
|
34469
|
-
}
|
|
34470
|
-
lte(other) {
|
|
34471
|
-
return this.lessThanOrEqual(other);
|
|
34472
|
-
}
|
|
34473
|
-
modulo(divisor) {
|
|
34474
|
-
if (!Long.isLong(divisor))
|
|
34475
|
-
divisor = Long.fromValue(divisor);
|
|
34476
|
-
if (wasm) {
|
|
34477
|
-
const low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
|
|
34478
|
-
return Long.fromBits(low, wasm.get_high(), this.unsigned);
|
|
34479
|
-
}
|
|
34480
|
-
return this.sub(this.div(divisor).mul(divisor));
|
|
34481
|
-
}
|
|
34482
|
-
mod(divisor) {
|
|
34483
|
-
return this.modulo(divisor);
|
|
34484
|
-
}
|
|
34485
|
-
rem(divisor) {
|
|
34486
|
-
return this.modulo(divisor);
|
|
34487
|
-
}
|
|
34488
|
-
multiply(multiplier) {
|
|
34489
|
-
if (this.isZero())
|
|
34490
|
-
return Long.ZERO;
|
|
34491
|
-
if (!Long.isLong(multiplier))
|
|
34492
|
-
multiplier = Long.fromValue(multiplier);
|
|
34493
|
-
if (wasm) {
|
|
34494
|
-
const low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
|
|
34495
|
-
return Long.fromBits(low, wasm.get_high(), this.unsigned);
|
|
34496
|
-
}
|
|
34497
|
-
if (multiplier.isZero())
|
|
34498
|
-
return Long.ZERO;
|
|
34499
|
-
if (this.eq(Long.MIN_VALUE))
|
|
34500
|
-
return multiplier.isOdd() ? Long.MIN_VALUE : Long.ZERO;
|
|
34501
|
-
if (multiplier.eq(Long.MIN_VALUE))
|
|
34502
|
-
return this.isOdd() ? Long.MIN_VALUE : Long.ZERO;
|
|
34503
|
-
if (this.isNegative()) {
|
|
34504
|
-
if (multiplier.isNegative())
|
|
34505
|
-
return this.neg().mul(multiplier.neg());
|
|
34506
|
-
else
|
|
34507
|
-
return this.neg().mul(multiplier).neg();
|
|
34508
|
-
} else if (multiplier.isNegative())
|
|
34509
|
-
return this.mul(multiplier.neg()).neg();
|
|
34510
|
-
if (this.lt(Long.TWO_PWR_24) && multiplier.lt(Long.TWO_PWR_24))
|
|
34511
|
-
return Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
|
|
34512
|
-
const a48 = this.high >>> 16;
|
|
34513
|
-
const a32 = this.high & 65535;
|
|
34514
|
-
const a16 = this.low >>> 16;
|
|
34515
|
-
const a00 = this.low & 65535;
|
|
34516
|
-
const b48 = multiplier.high >>> 16;
|
|
34517
|
-
const b32 = multiplier.high & 65535;
|
|
34518
|
-
const b16 = multiplier.low >>> 16;
|
|
34519
|
-
const b00 = multiplier.low & 65535;
|
|
34520
|
-
let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
|
34521
|
-
c00 += a00 * b00;
|
|
34522
|
-
c16 += c00 >>> 16;
|
|
34523
|
-
c00 &= 65535;
|
|
34524
|
-
c16 += a16 * b00;
|
|
34525
|
-
c32 += c16 >>> 16;
|
|
34526
|
-
c16 &= 65535;
|
|
34527
|
-
c16 += a00 * b16;
|
|
34528
|
-
c32 += c16 >>> 16;
|
|
34529
|
-
c16 &= 65535;
|
|
34530
|
-
c32 += a32 * b00;
|
|
34531
|
-
c48 += c32 >>> 16;
|
|
34532
|
-
c32 &= 65535;
|
|
34533
|
-
c32 += a16 * b16;
|
|
34534
|
-
c48 += c32 >>> 16;
|
|
34535
|
-
c32 &= 65535;
|
|
34536
|
-
c32 += a00 * b32;
|
|
34537
|
-
c48 += c32 >>> 16;
|
|
34538
|
-
c32 &= 65535;
|
|
34539
|
-
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
|
34540
|
-
c48 &= 65535;
|
|
34541
|
-
return Long.fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
|
|
34542
|
-
}
|
|
34543
|
-
mul(multiplier) {
|
|
34544
|
-
return this.multiply(multiplier);
|
|
34545
|
-
}
|
|
34546
|
-
negate() {
|
|
34547
|
-
if (!this.unsigned && this.eq(Long.MIN_VALUE))
|
|
34548
|
-
return Long.MIN_VALUE;
|
|
34549
|
-
return this.not().add(Long.ONE);
|
|
34550
|
-
}
|
|
34551
|
-
neg() {
|
|
34552
|
-
return this.negate();
|
|
34553
|
-
}
|
|
34554
|
-
not() {
|
|
34555
|
-
return Long.fromBits(~this.low, ~this.high, this.unsigned);
|
|
34556
|
-
}
|
|
34557
|
-
notEquals(other) {
|
|
34558
|
-
return !this.equals(other);
|
|
34559
|
-
}
|
|
34560
|
-
neq(other) {
|
|
34561
|
-
return this.notEquals(other);
|
|
34562
|
-
}
|
|
34563
|
-
ne(other) {
|
|
34564
|
-
return this.notEquals(other);
|
|
34565
|
-
}
|
|
34566
|
-
or(other) {
|
|
34567
|
-
if (!Long.isLong(other))
|
|
34568
|
-
other = Long.fromValue(other);
|
|
34569
|
-
return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned);
|
|
34570
|
-
}
|
|
34571
|
-
shiftLeft(numBits) {
|
|
34572
|
-
if (Long.isLong(numBits))
|
|
34573
|
-
numBits = numBits.toInt();
|
|
34574
|
-
if ((numBits &= 63) === 0)
|
|
34575
|
-
return this;
|
|
34576
|
-
else if (numBits < 32)
|
|
34577
|
-
return Long.fromBits(this.low << numBits, this.high << numBits | this.low >>> 32 - numBits, this.unsigned);
|
|
34578
|
-
else
|
|
34579
|
-
return Long.fromBits(0, this.low << numBits - 32, this.unsigned);
|
|
34580
|
-
}
|
|
34581
|
-
shl(numBits) {
|
|
34582
|
-
return this.shiftLeft(numBits);
|
|
34583
|
-
}
|
|
34584
|
-
shiftRight(numBits) {
|
|
34585
|
-
if (Long.isLong(numBits))
|
|
34586
|
-
numBits = numBits.toInt();
|
|
34587
|
-
if ((numBits &= 63) === 0)
|
|
34588
|
-
return this;
|
|
34589
|
-
else if (numBits < 32)
|
|
34590
|
-
return Long.fromBits(this.low >>> numBits | this.high << 32 - numBits, this.high >> numBits, this.unsigned);
|
|
34591
|
-
else
|
|
34592
|
-
return Long.fromBits(this.high >> numBits - 32, this.high >= 0 ? 0 : -1, this.unsigned);
|
|
34593
|
-
}
|
|
34594
|
-
shr(numBits) {
|
|
34595
|
-
return this.shiftRight(numBits);
|
|
34596
|
-
}
|
|
34597
|
-
shiftRightUnsigned(numBits) {
|
|
34598
|
-
if (Long.isLong(numBits))
|
|
34599
|
-
numBits = numBits.toInt();
|
|
34600
|
-
numBits &= 63;
|
|
34601
|
-
if (numBits === 0)
|
|
34602
|
-
return this;
|
|
34603
|
-
else {
|
|
34604
|
-
const high = this.high;
|
|
34605
|
-
if (numBits < 32) {
|
|
34606
|
-
const low = this.low;
|
|
34607
|
-
return Long.fromBits(low >>> numBits | high << 32 - numBits, high >>> numBits, this.unsigned);
|
|
34608
|
-
} else if (numBits === 32)
|
|
34609
|
-
return Long.fromBits(high, 0, this.unsigned);
|
|
34610
|
-
else
|
|
34611
|
-
return Long.fromBits(high >>> numBits - 32, 0, this.unsigned);
|
|
34612
|
-
}
|
|
34613
|
-
}
|
|
34614
|
-
shr_u(numBits) {
|
|
34615
|
-
return this.shiftRightUnsigned(numBits);
|
|
34616
|
-
}
|
|
34617
|
-
shru(numBits) {
|
|
34618
|
-
return this.shiftRightUnsigned(numBits);
|
|
34619
|
-
}
|
|
34620
|
-
subtract(subtrahend) {
|
|
34621
|
-
if (!Long.isLong(subtrahend))
|
|
34622
|
-
subtrahend = Long.fromValue(subtrahend);
|
|
34623
|
-
return this.add(subtrahend.neg());
|
|
34624
|
-
}
|
|
34625
|
-
sub(subtrahend) {
|
|
34626
|
-
return this.subtract(subtrahend);
|
|
34627
|
-
}
|
|
34628
|
-
toInt() {
|
|
34629
|
-
return this.unsigned ? this.low >>> 0 : this.low;
|
|
34630
|
-
}
|
|
34631
|
-
toNumber() {
|
|
34632
|
-
if (this.unsigned)
|
|
34633
|
-
return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
|
|
34634
|
-
return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
|
|
34635
|
-
}
|
|
34636
|
-
toBigInt() {
|
|
34637
|
-
return BigInt(this.toString());
|
|
34638
|
-
}
|
|
34639
|
-
toBytes(le) {
|
|
34640
|
-
return le ? this.toBytesLE() : this.toBytesBE();
|
|
34641
|
-
}
|
|
34642
|
-
toBytesLE() {
|
|
34643
|
-
const hi = this.high, lo = this.low;
|
|
34644
|
-
return [
|
|
34645
|
-
lo & 255,
|
|
34646
|
-
lo >>> 8 & 255,
|
|
34647
|
-
lo >>> 16 & 255,
|
|
34648
|
-
lo >>> 24,
|
|
34649
|
-
hi & 255,
|
|
34650
|
-
hi >>> 8 & 255,
|
|
34651
|
-
hi >>> 16 & 255,
|
|
34652
|
-
hi >>> 24
|
|
34653
|
-
];
|
|
34654
|
-
}
|
|
34655
|
-
toBytesBE() {
|
|
34656
|
-
const hi = this.high, lo = this.low;
|
|
34657
|
-
return [
|
|
34658
|
-
hi >>> 24,
|
|
34659
|
-
hi >>> 16 & 255,
|
|
34660
|
-
hi >>> 8 & 255,
|
|
34661
|
-
hi & 255,
|
|
34662
|
-
lo >>> 24,
|
|
34663
|
-
lo >>> 16 & 255,
|
|
34664
|
-
lo >>> 8 & 255,
|
|
34665
|
-
lo & 255
|
|
34666
|
-
];
|
|
34667
|
-
}
|
|
34668
|
-
toSigned() {
|
|
34669
|
-
if (!this.unsigned)
|
|
34670
|
-
return this;
|
|
34671
|
-
return Long.fromBits(this.low, this.high, false);
|
|
34672
|
-
}
|
|
34673
|
-
toString(radix) {
|
|
34674
|
-
radix = radix || 10;
|
|
34675
|
-
if (radix < 2 || 36 < radix)
|
|
34676
|
-
throw new BSONError("radix");
|
|
34677
|
-
if (this.isZero())
|
|
34678
|
-
return "0";
|
|
34679
|
-
if (this.isNegative()) {
|
|
34680
|
-
if (this.eq(Long.MIN_VALUE)) {
|
|
34681
|
-
const radixLong = Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
|
|
34682
|
-
return div.toString(radix) + rem1.toInt().toString(radix);
|
|
34683
|
-
} else
|
|
34684
|
-
return "-" + this.neg().toString(radix);
|
|
34685
|
-
}
|
|
34686
|
-
const radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned);
|
|
34687
|
-
let rem = this;
|
|
34688
|
-
let result = "";
|
|
34689
|
-
while (true) {
|
|
34690
|
-
const remDiv = rem.div(radixToPower);
|
|
34691
|
-
const intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
|
|
34692
|
-
let digits = intval.toString(radix);
|
|
34693
|
-
rem = remDiv;
|
|
34694
|
-
if (rem.isZero()) {
|
|
34695
|
-
return digits + result;
|
|
34696
|
-
} else {
|
|
34697
|
-
while (digits.length < 6)
|
|
34698
|
-
digits = "0" + digits;
|
|
34699
|
-
result = "" + digits + result;
|
|
34700
|
-
}
|
|
34701
|
-
}
|
|
34702
|
-
}
|
|
34703
|
-
toUnsigned() {
|
|
34704
|
-
if (this.unsigned)
|
|
34705
|
-
return this;
|
|
34706
|
-
return Long.fromBits(this.low, this.high, true);
|
|
34707
|
-
}
|
|
34708
|
-
xor(other) {
|
|
34709
|
-
if (!Long.isLong(other))
|
|
34710
|
-
other = Long.fromValue(other);
|
|
34711
|
-
return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
|
|
34712
|
-
}
|
|
34713
|
-
eqz() {
|
|
34714
|
-
return this.isZero();
|
|
34715
|
-
}
|
|
34716
|
-
le(other) {
|
|
34717
|
-
return this.lessThanOrEqual(other);
|
|
34718
|
-
}
|
|
34719
|
-
toExtendedJSON(options) {
|
|
34720
|
-
if (options && options.relaxed)
|
|
34721
|
-
return this.toNumber();
|
|
34722
|
-
return { $numberLong: this.toString() };
|
|
34723
|
-
}
|
|
34724
|
-
static fromExtendedJSON(doc, options) {
|
|
34725
|
-
const { useBigInt64 = false, relaxed = true } = { ...options };
|
|
34726
|
-
if (doc.$numberLong.length > MAX_INT64_STRING_LENGTH) {
|
|
34727
|
-
throw new BSONError("$numberLong string is too long");
|
|
34728
|
-
}
|
|
34729
|
-
if (!DECIMAL_REG_EX.test(doc.$numberLong)) {
|
|
34730
|
-
throw new BSONError(`$numberLong string "${doc.$numberLong}" is in an invalid format`);
|
|
34731
|
-
}
|
|
34732
|
-
if (useBigInt64) {
|
|
34733
|
-
const bigIntResult = BigInt(doc.$numberLong);
|
|
34734
|
-
return BigInt.asIntN(64, bigIntResult);
|
|
34735
|
-
}
|
|
34736
|
-
const longResult = Long.fromString(doc.$numberLong);
|
|
34737
|
-
if (relaxed) {
|
|
34738
|
-
return longResult.toNumber();
|
|
34739
|
-
}
|
|
34740
|
-
return longResult;
|
|
34741
|
-
}
|
|
34742
|
-
inspect(depth, options, inspect) {
|
|
34743
|
-
inspect ?? (inspect = defaultInspect);
|
|
34744
|
-
const longVal = inspect(this.toString(), options);
|
|
34745
|
-
const unsignedVal = this.unsigned ? `, ${inspect(this.unsigned, options)}` : "";
|
|
34746
|
-
return `new Long(${longVal}${unsignedVal})`;
|
|
34747
|
-
}
|
|
34748
|
-
};
|
|
34749
|
-
Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
|
|
34750
|
-
Long.MAX_UNSIGNED_VALUE = Long.fromBits(4294967295 | 0, 4294967295 | 0, true);
|
|
34751
|
-
Long.ZERO = Long.fromInt(0);
|
|
34752
|
-
Long.UZERO = Long.fromInt(0, true);
|
|
34753
|
-
Long.ONE = Long.fromInt(1);
|
|
34754
|
-
Long.UONE = Long.fromInt(1, true);
|
|
34755
|
-
Long.NEG_ONE = Long.fromInt(-1);
|
|
34756
|
-
Long.MAX_VALUE = Long.fromBits(4294967295 | 0, 2147483647 | 0, false);
|
|
34757
|
-
Long.MIN_VALUE = Long.fromBits(0, 2147483648 | 0, false);
|
|
34758
|
-
var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
|
|
34759
|
-
var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
|
|
34760
|
-
var PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i;
|
|
34761
|
-
var EXPONENT_MAX = 6111;
|
|
34762
|
-
var EXPONENT_MIN = -6176;
|
|
34763
|
-
var EXPONENT_BIAS = 6176;
|
|
34764
|
-
var MAX_DIGITS = 34;
|
|
34765
|
-
var NAN_BUFFER = ByteUtils.fromNumberArray([
|
|
34766
|
-
124,
|
|
34767
|
-
0,
|
|
34768
|
-
0,
|
|
34769
|
-
0,
|
|
34770
|
-
0,
|
|
34771
|
-
0,
|
|
34772
|
-
0,
|
|
34773
|
-
0,
|
|
34774
|
-
0,
|
|
34775
|
-
0,
|
|
34776
|
-
0,
|
|
34777
|
-
0,
|
|
34778
|
-
0,
|
|
34779
|
-
0,
|
|
34780
|
-
0,
|
|
34781
|
-
0
|
|
34782
|
-
].reverse());
|
|
34783
|
-
var INF_NEGATIVE_BUFFER = ByteUtils.fromNumberArray([
|
|
34784
|
-
248,
|
|
34785
|
-
0,
|
|
34786
|
-
0,
|
|
34787
|
-
0,
|
|
34788
|
-
0,
|
|
34789
|
-
0,
|
|
34790
|
-
0,
|
|
34791
|
-
0,
|
|
34792
|
-
0,
|
|
34793
|
-
0,
|
|
34794
|
-
0,
|
|
34795
|
-
0,
|
|
34796
|
-
0,
|
|
34797
|
-
0,
|
|
34798
|
-
0,
|
|
34799
|
-
0
|
|
34800
|
-
].reverse());
|
|
34801
|
-
var INF_POSITIVE_BUFFER = ByteUtils.fromNumberArray([
|
|
34802
|
-
120,
|
|
34803
|
-
0,
|
|
34804
|
-
0,
|
|
34805
|
-
0,
|
|
34806
|
-
0,
|
|
34807
|
-
0,
|
|
34808
|
-
0,
|
|
34809
|
-
0,
|
|
34810
|
-
0,
|
|
34811
|
-
0,
|
|
34812
|
-
0,
|
|
34813
|
-
0,
|
|
34814
|
-
0,
|
|
34815
|
-
0,
|
|
34816
|
-
0,
|
|
34817
|
-
0
|
|
34818
|
-
].reverse());
|
|
34819
|
-
var EXPONENT_REGEX = /^([-+])?(\d+)?$/;
|
|
34820
|
-
var COMBINATION_MASK = 31;
|
|
34821
|
-
var EXPONENT_MASK = 16383;
|
|
34822
|
-
var COMBINATION_INFINITY = 30;
|
|
34823
|
-
var COMBINATION_NAN = 31;
|
|
34824
|
-
function isDigit(value) {
|
|
34825
|
-
return !isNaN(parseInt(value, 10));
|
|
34826
|
-
}
|
|
34827
|
-
function divideu128(value) {
|
|
34828
|
-
const DIVISOR = Long.fromNumber(1e3 * 1e3 * 1e3);
|
|
34829
|
-
let _rem = Long.fromNumber(0);
|
|
34830
|
-
if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
|
|
34831
|
-
return { quotient: value, rem: _rem };
|
|
34832
|
-
}
|
|
34833
|
-
for (let i = 0; i <= 3; i++) {
|
|
34834
|
-
_rem = _rem.shiftLeft(32);
|
|
34835
|
-
_rem = _rem.add(new Long(value.parts[i], 0));
|
|
34836
|
-
value.parts[i] = _rem.div(DIVISOR).low;
|
|
34837
|
-
_rem = _rem.modulo(DIVISOR);
|
|
34838
|
-
}
|
|
34839
|
-
return { quotient: value, rem: _rem };
|
|
34840
|
-
}
|
|
34841
|
-
function multiply64x2(left, right) {
|
|
34842
|
-
if (!left && !right) {
|
|
34843
|
-
return { high: Long.fromNumber(0), low: Long.fromNumber(0) };
|
|
34844
|
-
}
|
|
34845
|
-
const leftHigh = left.shiftRightUnsigned(32);
|
|
34846
|
-
const leftLow = new Long(left.getLowBits(), 0);
|
|
34847
|
-
const rightHigh = right.shiftRightUnsigned(32);
|
|
34848
|
-
const rightLow = new Long(right.getLowBits(), 0);
|
|
34849
|
-
let productHigh = leftHigh.multiply(rightHigh);
|
|
34850
|
-
let productMid = leftHigh.multiply(rightLow);
|
|
34851
|
-
const productMid2 = leftLow.multiply(rightHigh);
|
|
34852
|
-
let productLow = leftLow.multiply(rightLow);
|
|
34853
|
-
productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
|
|
34854
|
-
productMid = new Long(productMid.getLowBits(), 0).add(productMid2).add(productLow.shiftRightUnsigned(32));
|
|
34855
|
-
productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
|
|
34856
|
-
productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0));
|
|
34857
|
-
return { high: productHigh, low: productLow };
|
|
34858
|
-
}
|
|
34859
|
-
function lessThan(left, right) {
|
|
34860
|
-
const uhleft = left.high >>> 0;
|
|
34861
|
-
const uhright = right.high >>> 0;
|
|
34862
|
-
if (uhleft < uhright) {
|
|
34863
|
-
return true;
|
|
34864
|
-
} else if (uhleft === uhright) {
|
|
34865
|
-
const ulleft = left.low >>> 0;
|
|
34866
|
-
const ulright = right.low >>> 0;
|
|
34867
|
-
if (ulleft < ulright)
|
|
34868
|
-
return true;
|
|
34869
|
-
}
|
|
34870
|
-
return false;
|
|
34871
|
-
}
|
|
34872
|
-
function invalidErr(string, message) {
|
|
34873
|
-
throw new BSONError(`"${string}" is not a valid Decimal128 string - ${message}`);
|
|
34874
|
-
}
|
|
34875
|
-
var Decimal128 = class extends BSONValue {
|
|
34876
|
-
get _bsontype() {
|
|
34877
|
-
return "Decimal128";
|
|
34878
|
-
}
|
|
34879
|
-
constructor(bytes) {
|
|
34880
|
-
super();
|
|
34881
|
-
if (typeof bytes === "string") {
|
|
34882
|
-
this.bytes = Decimal128.fromString(bytes).bytes;
|
|
34883
|
-
} else if (bytes instanceof Uint8Array || isUint8Array(bytes)) {
|
|
34884
|
-
if (bytes.byteLength !== 16) {
|
|
34885
|
-
throw new BSONError("Decimal128 must take a Buffer of 16 bytes");
|
|
34886
|
-
}
|
|
34887
|
-
this.bytes = bytes;
|
|
34888
|
-
} else {
|
|
34889
|
-
throw new BSONError("Decimal128 must take a Buffer or string");
|
|
34890
|
-
}
|
|
34891
|
-
}
|
|
34892
|
-
static fromString(representation) {
|
|
34893
|
-
return Decimal128._fromString(representation, { allowRounding: false });
|
|
34894
|
-
}
|
|
34895
|
-
static fromStringWithRounding(representation) {
|
|
34896
|
-
return Decimal128._fromString(representation, { allowRounding: true });
|
|
34897
|
-
}
|
|
34898
|
-
static _fromString(representation, options) {
|
|
34899
|
-
let isNegative = false;
|
|
34900
|
-
let sawSign = false;
|
|
34901
|
-
let sawRadix = false;
|
|
34902
|
-
let foundNonZero = false;
|
|
34903
|
-
let significantDigits = 0;
|
|
34904
|
-
let nDigitsRead = 0;
|
|
34905
|
-
let nDigits = 0;
|
|
34906
|
-
let radixPosition = 0;
|
|
34907
|
-
let firstNonZero = 0;
|
|
34908
|
-
const digits = [0];
|
|
34909
|
-
let nDigitsStored = 0;
|
|
34910
|
-
let digitsInsert = 0;
|
|
34911
|
-
let lastDigit = 0;
|
|
34912
|
-
let exponent = 0;
|
|
34913
|
-
let significandHigh = new Long(0, 0);
|
|
34914
|
-
let significandLow = new Long(0, 0);
|
|
34915
|
-
let biasedExponent = 0;
|
|
34916
|
-
let index = 0;
|
|
34917
|
-
if (representation.length >= 7e3) {
|
|
34918
|
-
throw new BSONError("" + representation + " not a valid Decimal128 string");
|
|
34919
|
-
}
|
|
34920
|
-
const stringMatch = representation.match(PARSE_STRING_REGEXP);
|
|
34921
|
-
const infMatch = representation.match(PARSE_INF_REGEXP);
|
|
34922
|
-
const nanMatch = representation.match(PARSE_NAN_REGEXP);
|
|
34923
|
-
if (!stringMatch && !infMatch && !nanMatch || representation.length === 0) {
|
|
34924
|
-
throw new BSONError("" + representation + " not a valid Decimal128 string");
|
|
34925
|
-
}
|
|
34926
|
-
if (stringMatch) {
|
|
34927
|
-
const unsignedNumber = stringMatch[2];
|
|
34928
|
-
const e = stringMatch[4];
|
|
34929
|
-
const expSign = stringMatch[5];
|
|
34930
|
-
const expNumber = stringMatch[6];
|
|
34931
|
-
if (e && expNumber === void 0)
|
|
34932
|
-
invalidErr(representation, "missing exponent power");
|
|
34933
|
-
if (e && unsignedNumber === void 0)
|
|
34934
|
-
invalidErr(representation, "missing exponent base");
|
|
34935
|
-
if (e === void 0 && (expSign || expNumber)) {
|
|
34936
|
-
invalidErr(representation, "missing e before exponent");
|
|
34937
|
-
}
|
|
34938
|
-
}
|
|
34939
|
-
if (representation[index] === "+" || representation[index] === "-") {
|
|
34940
|
-
sawSign = true;
|
|
34941
|
-
isNegative = representation[index++] === "-";
|
|
34942
|
-
}
|
|
34943
|
-
if (!isDigit(representation[index]) && representation[index] !== ".") {
|
|
34944
|
-
if (representation[index] === "i" || representation[index] === "I") {
|
|
34945
|
-
return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
|
|
34946
|
-
} else if (representation[index] === "N") {
|
|
34947
|
-
return new Decimal128(NAN_BUFFER);
|
|
34948
|
-
}
|
|
34949
|
-
}
|
|
34950
|
-
while (isDigit(representation[index]) || representation[index] === ".") {
|
|
34951
|
-
if (representation[index] === ".") {
|
|
34952
|
-
if (sawRadix)
|
|
34953
|
-
invalidErr(representation, "contains multiple periods");
|
|
34954
|
-
sawRadix = true;
|
|
34955
|
-
index = index + 1;
|
|
34956
|
-
continue;
|
|
34957
|
-
}
|
|
34958
|
-
if (nDigitsStored < MAX_DIGITS) {
|
|
34959
|
-
if (representation[index] !== "0" || foundNonZero) {
|
|
34960
|
-
if (!foundNonZero) {
|
|
34961
|
-
firstNonZero = nDigitsRead;
|
|
34962
|
-
}
|
|
34963
|
-
foundNonZero = true;
|
|
34964
|
-
digits[digitsInsert++] = parseInt(representation[index], 10);
|
|
34965
|
-
nDigitsStored = nDigitsStored + 1;
|
|
34966
|
-
}
|
|
34967
|
-
}
|
|
34968
|
-
if (foundNonZero)
|
|
34969
|
-
nDigits = nDigits + 1;
|
|
34970
|
-
if (sawRadix)
|
|
34971
|
-
radixPosition = radixPosition + 1;
|
|
34972
|
-
nDigitsRead = nDigitsRead + 1;
|
|
34973
|
-
index = index + 1;
|
|
34974
|
-
}
|
|
34975
|
-
if (sawRadix && !nDigitsRead)
|
|
34976
|
-
throw new BSONError("" + representation + " not a valid Decimal128 string");
|
|
34977
|
-
if (representation[index] === "e" || representation[index] === "E") {
|
|
34978
|
-
const match = representation.substr(++index).match(EXPONENT_REGEX);
|
|
34979
|
-
if (!match || !match[2])
|
|
34980
|
-
return new Decimal128(NAN_BUFFER);
|
|
34981
|
-
exponent = parseInt(match[0], 10);
|
|
34982
|
-
index = index + match[0].length;
|
|
34983
|
-
}
|
|
34984
|
-
if (representation[index])
|
|
34985
|
-
return new Decimal128(NAN_BUFFER);
|
|
34986
|
-
if (!nDigitsStored) {
|
|
34987
|
-
digits[0] = 0;
|
|
34988
|
-
nDigits = 1;
|
|
34989
|
-
nDigitsStored = 1;
|
|
34990
|
-
significantDigits = 0;
|
|
34991
|
-
} else {
|
|
34992
|
-
lastDigit = nDigitsStored - 1;
|
|
34993
|
-
significantDigits = nDigits;
|
|
34994
|
-
if (significantDigits !== 1) {
|
|
34995
|
-
while (representation[firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)] === "0") {
|
|
34996
|
-
significantDigits = significantDigits - 1;
|
|
34997
|
-
}
|
|
34998
|
-
}
|
|
34999
|
-
}
|
|
35000
|
-
if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
|
|
35001
|
-
exponent = EXPONENT_MIN;
|
|
35002
|
-
} else {
|
|
35003
|
-
exponent = exponent - radixPosition;
|
|
35004
|
-
}
|
|
35005
|
-
while (exponent > EXPONENT_MAX) {
|
|
35006
|
-
lastDigit = lastDigit + 1;
|
|
35007
|
-
if (lastDigit >= MAX_DIGITS) {
|
|
35008
|
-
if (significantDigits === 0) {
|
|
35009
|
-
exponent = EXPONENT_MAX;
|
|
35010
|
-
break;
|
|
35011
|
-
}
|
|
35012
|
-
invalidErr(representation, "overflow");
|
|
35013
|
-
}
|
|
35014
|
-
exponent = exponent - 1;
|
|
35015
|
-
}
|
|
35016
|
-
if (options.allowRounding) {
|
|
35017
|
-
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
|
|
35018
|
-
if (lastDigit === 0 && significantDigits < nDigitsStored) {
|
|
35019
|
-
exponent = EXPONENT_MIN;
|
|
35020
|
-
significantDigits = 0;
|
|
35021
|
-
break;
|
|
35022
|
-
}
|
|
35023
|
-
if (nDigitsStored < nDigits) {
|
|
35024
|
-
nDigits = nDigits - 1;
|
|
35025
|
-
} else {
|
|
35026
|
-
lastDigit = lastDigit - 1;
|
|
35027
|
-
}
|
|
35028
|
-
if (exponent < EXPONENT_MAX) {
|
|
35029
|
-
exponent = exponent + 1;
|
|
35030
|
-
} else {
|
|
35031
|
-
const digitsString = digits.join("");
|
|
35032
|
-
if (digitsString.match(/^0+$/)) {
|
|
35033
|
-
exponent = EXPONENT_MAX;
|
|
35034
|
-
break;
|
|
35035
|
-
}
|
|
35036
|
-
invalidErr(representation, "overflow");
|
|
35037
|
-
}
|
|
35038
|
-
}
|
|
35039
|
-
if (lastDigit + 1 < significantDigits) {
|
|
35040
|
-
let endOfString = nDigitsRead;
|
|
35041
|
-
if (sawRadix) {
|
|
35042
|
-
firstNonZero = firstNonZero + 1;
|
|
35043
|
-
endOfString = endOfString + 1;
|
|
35044
|
-
}
|
|
35045
|
-
if (sawSign) {
|
|
35046
|
-
firstNonZero = firstNonZero + 1;
|
|
35047
|
-
endOfString = endOfString + 1;
|
|
35048
|
-
}
|
|
35049
|
-
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
|
|
35050
|
-
let roundBit = 0;
|
|
35051
|
-
if (roundDigit >= 5) {
|
|
35052
|
-
roundBit = 1;
|
|
35053
|
-
if (roundDigit === 5) {
|
|
35054
|
-
roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
|
|
35055
|
-
for (let i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
|
|
35056
|
-
if (parseInt(representation[i], 10)) {
|
|
35057
|
-
roundBit = 1;
|
|
35058
|
-
break;
|
|
35059
|
-
}
|
|
35060
|
-
}
|
|
35061
|
-
}
|
|
35062
|
-
}
|
|
35063
|
-
if (roundBit) {
|
|
35064
|
-
let dIdx = lastDigit;
|
|
35065
|
-
for (; dIdx >= 0; dIdx--) {
|
|
35066
|
-
if (++digits[dIdx] > 9) {
|
|
35067
|
-
digits[dIdx] = 0;
|
|
35068
|
-
if (dIdx === 0) {
|
|
35069
|
-
if (exponent < EXPONENT_MAX) {
|
|
35070
|
-
exponent = exponent + 1;
|
|
35071
|
-
digits[dIdx] = 1;
|
|
35072
|
-
} else {
|
|
35073
|
-
return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
|
|
35074
|
-
}
|
|
35075
|
-
}
|
|
35076
|
-
} else {
|
|
35077
|
-
break;
|
|
35078
|
-
}
|
|
35079
|
-
}
|
|
35080
|
-
}
|
|
35081
|
-
}
|
|
35082
|
-
} else {
|
|
35083
|
-
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
|
|
35084
|
-
if (lastDigit === 0) {
|
|
35085
|
-
if (significantDigits === 0) {
|
|
35086
|
-
exponent = EXPONENT_MIN;
|
|
35087
|
-
break;
|
|
35088
|
-
}
|
|
35089
|
-
invalidErr(representation, "exponent underflow");
|
|
35090
|
-
}
|
|
35091
|
-
if (nDigitsStored < nDigits) {
|
|
35092
|
-
if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== "0" && significantDigits !== 0) {
|
|
35093
|
-
invalidErr(representation, "inexact rounding");
|
|
35094
|
-
}
|
|
35095
|
-
nDigits = nDigits - 1;
|
|
35096
|
-
} else {
|
|
35097
|
-
if (digits[lastDigit] !== 0) {
|
|
35098
|
-
invalidErr(representation, "inexact rounding");
|
|
35099
|
-
}
|
|
35100
|
-
lastDigit = lastDigit - 1;
|
|
35101
|
-
}
|
|
35102
|
-
if (exponent < EXPONENT_MAX) {
|
|
35103
|
-
exponent = exponent + 1;
|
|
35104
|
-
} else {
|
|
35105
|
-
invalidErr(representation, "overflow");
|
|
35106
|
-
}
|
|
35107
|
-
}
|
|
35108
|
-
if (lastDigit + 1 < significantDigits) {
|
|
35109
|
-
if (sawRadix) {
|
|
35110
|
-
firstNonZero = firstNonZero + 1;
|
|
35111
|
-
}
|
|
35112
|
-
if (sawSign) {
|
|
35113
|
-
firstNonZero = firstNonZero + 1;
|
|
35114
|
-
}
|
|
35115
|
-
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
|
|
35116
|
-
if (roundDigit !== 0) {
|
|
35117
|
-
invalidErr(representation, "inexact rounding");
|
|
35118
|
-
}
|
|
35119
|
-
}
|
|
35120
|
-
}
|
|
35121
|
-
significandHigh = Long.fromNumber(0);
|
|
35122
|
-
significandLow = Long.fromNumber(0);
|
|
35123
|
-
if (significantDigits === 0) {
|
|
35124
|
-
significandHigh = Long.fromNumber(0);
|
|
35125
|
-
significandLow = Long.fromNumber(0);
|
|
35126
|
-
} else if (lastDigit < 17) {
|
|
35127
|
-
let dIdx = 0;
|
|
35128
|
-
significandLow = Long.fromNumber(digits[dIdx++]);
|
|
35129
|
-
significandHigh = new Long(0, 0);
|
|
35130
|
-
for (; dIdx <= lastDigit; dIdx++) {
|
|
35131
|
-
significandLow = significandLow.multiply(Long.fromNumber(10));
|
|
35132
|
-
significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
|
|
35133
|
-
}
|
|
35134
|
-
} else {
|
|
35135
|
-
let dIdx = 0;
|
|
35136
|
-
significandHigh = Long.fromNumber(digits[dIdx++]);
|
|
35137
|
-
for (; dIdx <= lastDigit - 17; dIdx++) {
|
|
35138
|
-
significandHigh = significandHigh.multiply(Long.fromNumber(10));
|
|
35139
|
-
significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx]));
|
|
35140
|
-
}
|
|
35141
|
-
significandLow = Long.fromNumber(digits[dIdx++]);
|
|
35142
|
-
for (; dIdx <= lastDigit; dIdx++) {
|
|
35143
|
-
significandLow = significandLow.multiply(Long.fromNumber(10));
|
|
35144
|
-
significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
|
|
35145
|
-
}
|
|
35146
|
-
}
|
|
35147
|
-
const significand = multiply64x2(significandHigh, Long.fromString("100000000000000000"));
|
|
35148
|
-
significand.low = significand.low.add(significandLow);
|
|
35149
|
-
if (lessThan(significand.low, significandLow)) {
|
|
35150
|
-
significand.high = significand.high.add(Long.fromNumber(1));
|
|
35151
|
-
}
|
|
35152
|
-
biasedExponent = exponent + EXPONENT_BIAS;
|
|
35153
|
-
const dec2 = { low: Long.fromNumber(0), high: Long.fromNumber(0) };
|
|
35154
|
-
if (significand.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))) {
|
|
35155
|
-
dec2.high = dec2.high.or(Long.fromNumber(3).shiftLeft(61));
|
|
35156
|
-
dec2.high = dec2.high.or(Long.fromNumber(biasedExponent).and(Long.fromNumber(16383).shiftLeft(47)));
|
|
35157
|
-
dec2.high = dec2.high.or(significand.high.and(Long.fromNumber(140737488355327)));
|
|
35158
|
-
} else {
|
|
35159
|
-
dec2.high = dec2.high.or(Long.fromNumber(biasedExponent & 16383).shiftLeft(49));
|
|
35160
|
-
dec2.high = dec2.high.or(significand.high.and(Long.fromNumber(562949953421311)));
|
|
35161
|
-
}
|
|
35162
|
-
dec2.low = significand.low;
|
|
35163
|
-
if (isNegative) {
|
|
35164
|
-
dec2.high = dec2.high.or(Long.fromString("9223372036854775808"));
|
|
35165
|
-
}
|
|
35166
|
-
const buffer2 = ByteUtils.allocateUnsafe(16);
|
|
35167
|
-
index = 0;
|
|
35168
|
-
buffer2[index++] = dec2.low.low & 255;
|
|
35169
|
-
buffer2[index++] = dec2.low.low >> 8 & 255;
|
|
35170
|
-
buffer2[index++] = dec2.low.low >> 16 & 255;
|
|
35171
|
-
buffer2[index++] = dec2.low.low >> 24 & 255;
|
|
35172
|
-
buffer2[index++] = dec2.low.high & 255;
|
|
35173
|
-
buffer2[index++] = dec2.low.high >> 8 & 255;
|
|
35174
|
-
buffer2[index++] = dec2.low.high >> 16 & 255;
|
|
35175
|
-
buffer2[index++] = dec2.low.high >> 24 & 255;
|
|
35176
|
-
buffer2[index++] = dec2.high.low & 255;
|
|
35177
|
-
buffer2[index++] = dec2.high.low >> 8 & 255;
|
|
35178
|
-
buffer2[index++] = dec2.high.low >> 16 & 255;
|
|
35179
|
-
buffer2[index++] = dec2.high.low >> 24 & 255;
|
|
35180
|
-
buffer2[index++] = dec2.high.high & 255;
|
|
35181
|
-
buffer2[index++] = dec2.high.high >> 8 & 255;
|
|
35182
|
-
buffer2[index++] = dec2.high.high >> 16 & 255;
|
|
35183
|
-
buffer2[index++] = dec2.high.high >> 24 & 255;
|
|
35184
|
-
return new Decimal128(buffer2);
|
|
35185
|
-
}
|
|
35186
|
-
toString() {
|
|
35187
|
-
let biased_exponent;
|
|
35188
|
-
let significand_digits = 0;
|
|
35189
|
-
const significand = new Array(36);
|
|
35190
|
-
for (let i = 0; i < significand.length; i++)
|
|
35191
|
-
significand[i] = 0;
|
|
35192
|
-
let index = 0;
|
|
35193
|
-
let is_zero = false;
|
|
35194
|
-
let significand_msb;
|
|
35195
|
-
let significand128 = { parts: [0, 0, 0, 0] };
|
|
35196
|
-
let j, k;
|
|
35197
|
-
const string = [];
|
|
35198
|
-
index = 0;
|
|
35199
|
-
const buffer2 = this.bytes;
|
|
35200
|
-
const low = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
|
|
35201
|
-
const midl = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
|
|
35202
|
-
const midh = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
|
|
35203
|
-
const high = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
|
|
35204
|
-
index = 0;
|
|
35205
|
-
const dec2 = {
|
|
35206
|
-
low: new Long(low, midl),
|
|
35207
|
-
high: new Long(midh, high)
|
|
35208
|
-
};
|
|
35209
|
-
if (dec2.high.lessThan(Long.ZERO)) {
|
|
35210
|
-
string.push("-");
|
|
35211
|
-
}
|
|
35212
|
-
const combination = high >> 26 & COMBINATION_MASK;
|
|
35213
|
-
if (combination >> 3 === 3) {
|
|
35214
|
-
if (combination === COMBINATION_INFINITY) {
|
|
35215
|
-
return string.join("") + "Infinity";
|
|
35216
|
-
} else if (combination === COMBINATION_NAN) {
|
|
35217
|
-
return "NaN";
|
|
35218
|
-
} else {
|
|
35219
|
-
biased_exponent = high >> 15 & EXPONENT_MASK;
|
|
35220
|
-
significand_msb = 8 + (high >> 14 & 1);
|
|
35221
|
-
}
|
|
35222
|
-
} else {
|
|
35223
|
-
significand_msb = high >> 14 & 7;
|
|
35224
|
-
biased_exponent = high >> 17 & EXPONENT_MASK;
|
|
35225
|
-
}
|
|
35226
|
-
const exponent = biased_exponent - EXPONENT_BIAS;
|
|
35227
|
-
significand128.parts[0] = (high & 16383) + ((significand_msb & 15) << 14);
|
|
35228
|
-
significand128.parts[1] = midh;
|
|
35229
|
-
significand128.parts[2] = midl;
|
|
35230
|
-
significand128.parts[3] = low;
|
|
35231
|
-
if (significand128.parts[0] === 0 && significand128.parts[1] === 0 && significand128.parts[2] === 0 && significand128.parts[3] === 0) {
|
|
35232
|
-
is_zero = true;
|
|
35233
|
-
} else {
|
|
35234
|
-
for (k = 3; k >= 0; k--) {
|
|
35235
|
-
let least_digits = 0;
|
|
35236
|
-
const result = divideu128(significand128);
|
|
35237
|
-
significand128 = result.quotient;
|
|
35238
|
-
least_digits = result.rem.low;
|
|
35239
|
-
if (!least_digits)
|
|
35240
|
-
continue;
|
|
35241
|
-
for (j = 8; j >= 0; j--) {
|
|
35242
|
-
significand[k * 9 + j] = least_digits % 10;
|
|
35243
|
-
least_digits = Math.floor(least_digits / 10);
|
|
35244
|
-
}
|
|
35245
|
-
}
|
|
35246
|
-
}
|
|
35247
|
-
if (is_zero) {
|
|
35248
|
-
significand_digits = 1;
|
|
35249
|
-
significand[index] = 0;
|
|
35250
|
-
} else {
|
|
35251
|
-
significand_digits = 36;
|
|
35252
|
-
while (!significand[index]) {
|
|
35253
|
-
significand_digits = significand_digits - 1;
|
|
35254
|
-
index = index + 1;
|
|
35255
|
-
}
|
|
35256
|
-
}
|
|
35257
|
-
const scientific_exponent = significand_digits - 1 + exponent;
|
|
35258
|
-
if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) {
|
|
35259
|
-
if (significand_digits > 34) {
|
|
35260
|
-
string.push(`${0}`);
|
|
35261
|
-
if (exponent > 0)
|
|
35262
|
-
string.push(`E+${exponent}`);
|
|
35263
|
-
else if (exponent < 0)
|
|
35264
|
-
string.push(`E${exponent}`);
|
|
35265
|
-
return string.join("");
|
|
35266
|
-
}
|
|
35267
|
-
string.push(`${significand[index++]}`);
|
|
35268
|
-
significand_digits = significand_digits - 1;
|
|
35269
|
-
if (significand_digits) {
|
|
35270
|
-
string.push(".");
|
|
35271
|
-
}
|
|
35272
|
-
for (let i = 0; i < significand_digits; i++) {
|
|
35273
|
-
string.push(`${significand[index++]}`);
|
|
35274
|
-
}
|
|
35275
|
-
string.push("E");
|
|
35276
|
-
if (scientific_exponent > 0) {
|
|
35277
|
-
string.push(`+${scientific_exponent}`);
|
|
35278
|
-
} else {
|
|
35279
|
-
string.push(`${scientific_exponent}`);
|
|
35280
|
-
}
|
|
35281
|
-
} else {
|
|
35282
|
-
if (exponent >= 0) {
|
|
35283
|
-
for (let i = 0; i < significand_digits; i++) {
|
|
35284
|
-
string.push(`${significand[index++]}`);
|
|
35285
|
-
}
|
|
35286
|
-
} else {
|
|
35287
|
-
let radix_position = significand_digits + exponent;
|
|
35288
|
-
if (radix_position > 0) {
|
|
35289
|
-
for (let i = 0; i < radix_position; i++) {
|
|
35290
|
-
string.push(`${significand[index++]}`);
|
|
35291
|
-
}
|
|
35292
|
-
} else {
|
|
35293
|
-
string.push("0");
|
|
35294
|
-
}
|
|
35295
|
-
string.push(".");
|
|
35296
|
-
while (radix_position++ < 0) {
|
|
35297
|
-
string.push("0");
|
|
35298
|
-
}
|
|
35299
|
-
for (let i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
|
|
35300
|
-
string.push(`${significand[index++]}`);
|
|
35301
|
-
}
|
|
35302
|
-
}
|
|
35303
|
-
}
|
|
35304
|
-
return string.join("");
|
|
35305
|
-
}
|
|
35306
|
-
toJSON() {
|
|
35307
|
-
return { $numberDecimal: this.toString() };
|
|
35308
|
-
}
|
|
35309
|
-
toExtendedJSON() {
|
|
35310
|
-
return { $numberDecimal: this.toString() };
|
|
35311
|
-
}
|
|
35312
|
-
static fromExtendedJSON(doc) {
|
|
35313
|
-
return Decimal128.fromString(doc.$numberDecimal);
|
|
35314
|
-
}
|
|
35315
|
-
inspect(depth, options, inspect) {
|
|
35316
|
-
inspect ?? (inspect = defaultInspect);
|
|
35317
|
-
const d128string = inspect(this.toString(), options);
|
|
35318
|
-
return `new Decimal128(${d128string})`;
|
|
35319
|
-
}
|
|
35320
|
-
};
|
|
35321
|
-
var Double = class extends BSONValue {
|
|
35322
|
-
get _bsontype() {
|
|
35323
|
-
return "Double";
|
|
35324
|
-
}
|
|
35325
|
-
constructor(value) {
|
|
35326
|
-
super();
|
|
35327
|
-
if (value instanceof Number) {
|
|
35328
|
-
value = value.valueOf();
|
|
35329
|
-
}
|
|
35330
|
-
this.value = +value;
|
|
35331
|
-
}
|
|
35332
|
-
static fromString(value) {
|
|
35333
|
-
const coercedValue = Number(value);
|
|
35334
|
-
if (value === "NaN")
|
|
35335
|
-
return new Double(NaN);
|
|
35336
|
-
if (value === "Infinity")
|
|
35337
|
-
return new Double(Infinity);
|
|
35338
|
-
if (value === "-Infinity")
|
|
35339
|
-
return new Double(-Infinity);
|
|
35340
|
-
if (!Number.isFinite(coercedValue)) {
|
|
35341
|
-
throw new BSONError(`Input: ${value} is not representable as a Double`);
|
|
35342
|
-
}
|
|
35343
|
-
if (value.trim() !== value) {
|
|
35344
|
-
throw new BSONError(`Input: '${value}' contains whitespace`);
|
|
35345
|
-
}
|
|
35346
|
-
if (value === "") {
|
|
35347
|
-
throw new BSONError(`Input is an empty string`);
|
|
35348
|
-
}
|
|
35349
|
-
if (/[^-0-9.+eE]/.test(value)) {
|
|
35350
|
-
throw new BSONError(`Input: '${value}' is not in decimal or exponential notation`);
|
|
35351
|
-
}
|
|
35352
|
-
return new Double(coercedValue);
|
|
35353
|
-
}
|
|
35354
|
-
valueOf() {
|
|
35355
|
-
return this.value;
|
|
35356
|
-
}
|
|
35357
|
-
toJSON() {
|
|
35358
|
-
return this.value;
|
|
35359
|
-
}
|
|
35360
|
-
toString(radix) {
|
|
35361
|
-
return this.value.toString(radix);
|
|
35362
|
-
}
|
|
35363
|
-
toExtendedJSON(options) {
|
|
35364
|
-
if (options && (options.legacy || options.relaxed && isFinite(this.value))) {
|
|
35365
|
-
return this.value;
|
|
35366
|
-
}
|
|
35367
|
-
if (Object.is(Math.sign(this.value), -0)) {
|
|
35368
|
-
return { $numberDouble: "-0.0" };
|
|
35369
|
-
}
|
|
35370
|
-
return {
|
|
35371
|
-
$numberDouble: Number.isInteger(this.value) ? this.value.toFixed(1) : this.value.toString()
|
|
35372
|
-
};
|
|
35373
|
-
}
|
|
35374
|
-
static fromExtendedJSON(doc, options) {
|
|
35375
|
-
const doubleValue = parseFloat(doc.$numberDouble);
|
|
35376
|
-
return options && options.relaxed ? doubleValue : new Double(doubleValue);
|
|
35377
|
-
}
|
|
35378
|
-
inspect(depth, options, inspect) {
|
|
35379
|
-
inspect ?? (inspect = defaultInspect);
|
|
35380
|
-
return `new Double(${inspect(this.value, options)})`;
|
|
35381
|
-
}
|
|
35382
|
-
};
|
|
35383
|
-
var Int32 = class extends BSONValue {
|
|
35384
|
-
get _bsontype() {
|
|
35385
|
-
return "Int32";
|
|
35386
|
-
}
|
|
35387
|
-
constructor(value) {
|
|
35388
|
-
super();
|
|
35389
|
-
if (value instanceof Number) {
|
|
35390
|
-
value = value.valueOf();
|
|
35391
|
-
}
|
|
35392
|
-
this.value = +value | 0;
|
|
35393
|
-
}
|
|
35394
|
-
static fromString(value) {
|
|
35395
|
-
const cleanedValue = removeLeadingZerosAndExplicitPlus(value);
|
|
35396
|
-
const coercedValue = Number(value);
|
|
35397
|
-
if (BSON_INT32_MAX < coercedValue) {
|
|
35398
|
-
throw new BSONError(`Input: '${value}' is larger than the maximum value for Int32`);
|
|
35399
|
-
} else if (BSON_INT32_MIN > coercedValue) {
|
|
35400
|
-
throw new BSONError(`Input: '${value}' is smaller than the minimum value for Int32`);
|
|
35401
|
-
} else if (!Number.isSafeInteger(coercedValue)) {
|
|
35402
|
-
throw new BSONError(`Input: '${value}' is not a safe integer`);
|
|
35403
|
-
} else if (coercedValue.toString() !== cleanedValue) {
|
|
35404
|
-
throw new BSONError(`Input: '${value}' is not a valid Int32 string`);
|
|
35405
|
-
}
|
|
35406
|
-
return new Int32(coercedValue);
|
|
35407
|
-
}
|
|
35408
|
-
valueOf() {
|
|
35409
|
-
return this.value;
|
|
35410
|
-
}
|
|
35411
|
-
toString(radix) {
|
|
35412
|
-
return this.value.toString(radix);
|
|
35413
|
-
}
|
|
35414
|
-
toJSON() {
|
|
35415
|
-
return this.value;
|
|
35416
|
-
}
|
|
35417
|
-
toExtendedJSON(options) {
|
|
35418
|
-
if (options && (options.relaxed || options.legacy))
|
|
35419
|
-
return this.value;
|
|
35420
|
-
return { $numberInt: this.value.toString() };
|
|
35421
|
-
}
|
|
35422
|
-
static fromExtendedJSON(doc, options) {
|
|
35423
|
-
return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt);
|
|
35424
|
-
}
|
|
35425
|
-
inspect(depth, options, inspect) {
|
|
35426
|
-
inspect ?? (inspect = defaultInspect);
|
|
35427
|
-
return `new Int32(${inspect(this.value, options)})`;
|
|
35428
|
-
}
|
|
35429
|
-
};
|
|
35430
|
-
var MaxKey = class extends BSONValue {
|
|
35431
|
-
get _bsontype() {
|
|
35432
|
-
return "MaxKey";
|
|
35433
|
-
}
|
|
35434
|
-
toExtendedJSON() {
|
|
35435
|
-
return { $maxKey: 1 };
|
|
35436
|
-
}
|
|
35437
|
-
static fromExtendedJSON() {
|
|
35438
|
-
return new MaxKey();
|
|
35439
|
-
}
|
|
35440
|
-
inspect() {
|
|
35441
|
-
return "new MaxKey()";
|
|
35442
|
-
}
|
|
35443
|
-
};
|
|
35444
|
-
var MinKey = class extends BSONValue {
|
|
35445
|
-
get _bsontype() {
|
|
35446
|
-
return "MinKey";
|
|
35447
|
-
}
|
|
35448
|
-
toExtendedJSON() {
|
|
35449
|
-
return { $minKey: 1 };
|
|
35450
|
-
}
|
|
35451
|
-
static fromExtendedJSON() {
|
|
35452
|
-
return new MinKey();
|
|
35453
|
-
}
|
|
35454
|
-
inspect() {
|
|
35455
|
-
return "new MinKey()";
|
|
35456
|
-
}
|
|
35457
|
-
};
|
|
35458
|
-
var PROCESS_UNIQUE = null;
|
|
35459
|
-
var __idCache = /* @__PURE__ */ new WeakMap();
|
|
35460
|
-
var ObjectId13 = class extends BSONValue {
|
|
35461
|
-
get _bsontype() {
|
|
35462
|
-
return "ObjectId";
|
|
35463
|
-
}
|
|
35464
|
-
constructor(inputId) {
|
|
35465
|
-
super();
|
|
35466
|
-
let workingId;
|
|
35467
|
-
if (typeof inputId === "object" && inputId && "id" in inputId) {
|
|
35468
|
-
if (typeof inputId.id !== "string" && !ArrayBuffer.isView(inputId.id)) {
|
|
35469
|
-
throw new BSONError("Argument passed in must have an id that is of type string or Buffer");
|
|
35470
|
-
}
|
|
35471
|
-
if ("toHexString" in inputId && typeof inputId.toHexString === "function") {
|
|
35472
|
-
workingId = ByteUtils.fromHex(inputId.toHexString());
|
|
35473
|
-
} else {
|
|
35474
|
-
workingId = inputId.id;
|
|
35475
|
-
}
|
|
35476
|
-
} else {
|
|
35477
|
-
workingId = inputId;
|
|
35478
|
-
}
|
|
35479
|
-
if (workingId == null || typeof workingId === "number") {
|
|
35480
|
-
this.buffer = ObjectId13.generate(typeof workingId === "number" ? workingId : void 0);
|
|
35481
|
-
} else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
|
|
35482
|
-
this.buffer = ByteUtils.toLocalBufferType(workingId);
|
|
35483
|
-
} else if (typeof workingId === "string") {
|
|
35484
|
-
if (ObjectId13.validateHexString(workingId)) {
|
|
35485
|
-
this.buffer = ByteUtils.fromHex(workingId);
|
|
35486
|
-
if (ObjectId13.cacheHexString) {
|
|
35487
|
-
__idCache.set(this, workingId);
|
|
35488
|
-
}
|
|
35489
|
-
} else {
|
|
35490
|
-
throw new BSONError("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");
|
|
35491
|
-
}
|
|
35492
|
-
} else {
|
|
35493
|
-
throw new BSONError("Argument passed in does not match the accepted types");
|
|
35494
|
-
}
|
|
35495
|
-
}
|
|
35496
|
-
get id() {
|
|
35497
|
-
return this.buffer;
|
|
35498
|
-
}
|
|
35499
|
-
set id(value) {
|
|
35500
|
-
this.buffer = value;
|
|
35501
|
-
if (ObjectId13.cacheHexString) {
|
|
35502
|
-
__idCache.set(this, ByteUtils.toHex(value));
|
|
35503
|
-
}
|
|
35504
|
-
}
|
|
35505
|
-
static validateHexString(string) {
|
|
35506
|
-
if (string?.length !== 24)
|
|
35507
|
-
return false;
|
|
35508
|
-
for (let i = 0; i < 24; i++) {
|
|
35509
|
-
const char = string.charCodeAt(i);
|
|
35510
|
-
if (char >= 48 && char <= 57 || char >= 97 && char <= 102 || char >= 65 && char <= 70) {
|
|
35511
|
-
continue;
|
|
35512
|
-
}
|
|
35513
|
-
return false;
|
|
35514
|
-
}
|
|
35515
|
-
return true;
|
|
35516
|
-
}
|
|
35517
|
-
toHexString() {
|
|
35518
|
-
if (ObjectId13.cacheHexString) {
|
|
35519
|
-
const __id = __idCache.get(this);
|
|
35520
|
-
if (__id)
|
|
35521
|
-
return __id;
|
|
35522
|
-
}
|
|
35523
|
-
const hexString = ByteUtils.toHex(this.id);
|
|
35524
|
-
if (ObjectId13.cacheHexString) {
|
|
35525
|
-
__idCache.set(this, hexString);
|
|
35526
|
-
}
|
|
35527
|
-
return hexString;
|
|
35528
|
-
}
|
|
35529
|
-
static getInc() {
|
|
35530
|
-
return ObjectId13.index = (ObjectId13.index + 1) % 16777215;
|
|
35531
|
-
}
|
|
35532
|
-
static generate(time) {
|
|
35533
|
-
if ("number" !== typeof time) {
|
|
35534
|
-
time = Math.floor(Date.now() / 1e3);
|
|
35535
|
-
}
|
|
35536
|
-
const inc = ObjectId13.getInc();
|
|
35537
|
-
const buffer2 = ByteUtils.allocateUnsafe(12);
|
|
35538
|
-
NumberUtils.setInt32BE(buffer2, 0, time);
|
|
35539
|
-
if (PROCESS_UNIQUE === null) {
|
|
35540
|
-
PROCESS_UNIQUE = ByteUtils.randomBytes(5);
|
|
35541
|
-
}
|
|
35542
|
-
buffer2[4] = PROCESS_UNIQUE[0];
|
|
35543
|
-
buffer2[5] = PROCESS_UNIQUE[1];
|
|
35544
|
-
buffer2[6] = PROCESS_UNIQUE[2];
|
|
35545
|
-
buffer2[7] = PROCESS_UNIQUE[3];
|
|
35546
|
-
buffer2[8] = PROCESS_UNIQUE[4];
|
|
35547
|
-
buffer2[11] = inc & 255;
|
|
35548
|
-
buffer2[10] = inc >> 8 & 255;
|
|
35549
|
-
buffer2[9] = inc >> 16 & 255;
|
|
35550
|
-
return buffer2;
|
|
35551
|
-
}
|
|
35552
|
-
toString(encoding) {
|
|
35553
|
-
if (encoding === "base64")
|
|
35554
|
-
return ByteUtils.toBase64(this.id);
|
|
35555
|
-
if (encoding === "hex")
|
|
35556
|
-
return this.toHexString();
|
|
35557
|
-
return this.toHexString();
|
|
35558
|
-
}
|
|
35559
|
-
toJSON() {
|
|
35560
|
-
return this.toHexString();
|
|
35561
|
-
}
|
|
35562
|
-
static is(variable) {
|
|
35563
|
-
return variable != null && typeof variable === "object" && "_bsontype" in variable && variable._bsontype === "ObjectId";
|
|
35564
|
-
}
|
|
35565
|
-
equals(otherId) {
|
|
35566
|
-
if (otherId === void 0 || otherId === null) {
|
|
35567
|
-
return false;
|
|
35568
|
-
}
|
|
35569
|
-
if (ObjectId13.is(otherId)) {
|
|
35570
|
-
return this.buffer[11] === otherId.buffer[11] && ByteUtils.equals(this.buffer, otherId.buffer);
|
|
35571
|
-
}
|
|
35572
|
-
if (typeof otherId === "string") {
|
|
35573
|
-
return otherId.toLowerCase() === this.toHexString();
|
|
35574
|
-
}
|
|
35575
|
-
if (typeof otherId === "object" && typeof otherId.toHexString === "function") {
|
|
35576
|
-
const otherIdString = otherId.toHexString();
|
|
35577
|
-
const thisIdString = this.toHexString();
|
|
35578
|
-
return typeof otherIdString === "string" && otherIdString.toLowerCase() === thisIdString;
|
|
35579
|
-
}
|
|
35580
|
-
return false;
|
|
35581
|
-
}
|
|
35582
|
-
getTimestamp() {
|
|
35583
|
-
const timestamp = /* @__PURE__ */ new Date();
|
|
35584
|
-
const time = NumberUtils.getUint32BE(this.buffer, 0);
|
|
35585
|
-
timestamp.setTime(Math.floor(time) * 1e3);
|
|
35586
|
-
return timestamp;
|
|
35587
|
-
}
|
|
35588
|
-
static createPk() {
|
|
35589
|
-
return new ObjectId13();
|
|
35590
|
-
}
|
|
35591
|
-
serializeInto(uint8array, index) {
|
|
35592
|
-
uint8array[index] = this.buffer[0];
|
|
35593
|
-
uint8array[index + 1] = this.buffer[1];
|
|
35594
|
-
uint8array[index + 2] = this.buffer[2];
|
|
35595
|
-
uint8array[index + 3] = this.buffer[3];
|
|
35596
|
-
uint8array[index + 4] = this.buffer[4];
|
|
35597
|
-
uint8array[index + 5] = this.buffer[5];
|
|
35598
|
-
uint8array[index + 6] = this.buffer[6];
|
|
35599
|
-
uint8array[index + 7] = this.buffer[7];
|
|
35600
|
-
uint8array[index + 8] = this.buffer[8];
|
|
35601
|
-
uint8array[index + 9] = this.buffer[9];
|
|
35602
|
-
uint8array[index + 10] = this.buffer[10];
|
|
35603
|
-
uint8array[index + 11] = this.buffer[11];
|
|
35604
|
-
return 12;
|
|
35605
|
-
}
|
|
35606
|
-
static createFromTime(time) {
|
|
35607
|
-
const buffer2 = ByteUtils.allocate(12);
|
|
35608
|
-
for (let i = 11; i >= 4; i--)
|
|
35609
|
-
buffer2[i] = 0;
|
|
35610
|
-
NumberUtils.setInt32BE(buffer2, 0, time);
|
|
35611
|
-
return new ObjectId13(buffer2);
|
|
35612
|
-
}
|
|
35613
|
-
static createFromHexString(hexString) {
|
|
35614
|
-
if (hexString?.length !== 24) {
|
|
35615
|
-
throw new BSONError("hex string must be 24 characters");
|
|
35616
|
-
}
|
|
35617
|
-
return new ObjectId13(ByteUtils.fromHex(hexString));
|
|
35618
|
-
}
|
|
35619
|
-
static createFromBase64(base64) {
|
|
35620
|
-
if (base64?.length !== 16) {
|
|
35621
|
-
throw new BSONError("base64 string must be 16 characters");
|
|
35622
|
-
}
|
|
35623
|
-
return new ObjectId13(ByteUtils.fromBase64(base64));
|
|
35624
|
-
}
|
|
35625
|
-
static isValid(id) {
|
|
35626
|
-
if (id == null)
|
|
35627
|
-
return false;
|
|
35628
|
-
if (typeof id === "string")
|
|
35629
|
-
return ObjectId13.validateHexString(id);
|
|
35630
|
-
try {
|
|
35631
|
-
new ObjectId13(id);
|
|
35632
|
-
return true;
|
|
35633
|
-
} catch {
|
|
35634
|
-
return false;
|
|
35635
|
-
}
|
|
35636
|
-
}
|
|
35637
|
-
toExtendedJSON() {
|
|
35638
|
-
if (this.toHexString)
|
|
35639
|
-
return { $oid: this.toHexString() };
|
|
35640
|
-
return { $oid: this.toString("hex") };
|
|
35641
|
-
}
|
|
35642
|
-
static fromExtendedJSON(doc) {
|
|
35643
|
-
return new ObjectId13(doc.$oid);
|
|
35644
|
-
}
|
|
35645
|
-
isCached() {
|
|
35646
|
-
return ObjectId13.cacheHexString && __idCache.has(this);
|
|
35647
|
-
}
|
|
35648
|
-
inspect(depth, options, inspect) {
|
|
35649
|
-
inspect ?? (inspect = defaultInspect);
|
|
35650
|
-
return `new ObjectId(${inspect(this.toHexString(), options)})`;
|
|
35651
|
-
}
|
|
35652
|
-
};
|
|
35653
|
-
ObjectId13.index = Math.floor(Math.random() * 16777215);
|
|
35654
|
-
function internalCalculateObjectSize(object, serializeFunctions, ignoreUndefined) {
|
|
35655
|
-
let totalLength = 4 + 1;
|
|
35656
|
-
if (Array.isArray(object)) {
|
|
35657
|
-
for (let i = 0; i < object.length; i++) {
|
|
35658
|
-
totalLength += calculateElement(i.toString(), object[i], serializeFunctions, true, ignoreUndefined);
|
|
35659
|
-
}
|
|
35660
|
-
} else {
|
|
35661
|
-
if (typeof object?.toBSON === "function") {
|
|
35662
|
-
object = object.toBSON();
|
|
35663
|
-
}
|
|
35664
|
-
for (const key of Object.keys(object)) {
|
|
35665
|
-
totalLength += calculateElement(key, object[key], serializeFunctions, false, ignoreUndefined);
|
|
35666
|
-
}
|
|
35667
|
-
}
|
|
35668
|
-
return totalLength;
|
|
35669
|
-
}
|
|
35670
|
-
function calculateElement(name, value, serializeFunctions = false, isArray = false, ignoreUndefined = false) {
|
|
35671
|
-
if (typeof value?.toBSON === "function") {
|
|
35672
|
-
value = value.toBSON();
|
|
35673
|
-
}
|
|
35674
|
-
switch (typeof value) {
|
|
35675
|
-
case "string":
|
|
35676
|
-
return 1 + ByteUtils.utf8ByteLength(name) + 1 + 4 + ByteUtils.utf8ByteLength(value) + 1;
|
|
35677
|
-
case "number":
|
|
35678
|
-
if (Math.floor(value) === value && value >= JS_INT_MIN && value <= JS_INT_MAX) {
|
|
35679
|
-
if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
|
|
35680
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (4 + 1);
|
|
35681
|
-
} else {
|
|
35682
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
|
35683
|
-
}
|
|
35684
|
-
} else {
|
|
35685
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
|
35686
|
-
}
|
|
35687
|
-
case "undefined":
|
|
35688
|
-
if (isArray || !ignoreUndefined)
|
|
35689
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1;
|
|
35690
|
-
return 0;
|
|
35691
|
-
case "boolean":
|
|
35692
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (1 + 1);
|
|
35693
|
-
case "object":
|
|
35694
|
-
if (value != null && typeof value._bsontype === "string" && value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
35695
|
-
throw new BSONVersionError();
|
|
35696
|
-
} else if (value == null || value._bsontype === "MinKey" || value._bsontype === "MaxKey") {
|
|
35697
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1;
|
|
35698
|
-
} else if (value._bsontype === "ObjectId") {
|
|
35699
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (12 + 1);
|
|
35700
|
-
} else if (value instanceof Date || isDate(value)) {
|
|
35701
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
|
35702
|
-
} else if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer || isAnyArrayBuffer(value)) {
|
|
35703
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (1 + 4 + 1) + value.byteLength;
|
|
35704
|
-
} else if (value._bsontype === "Long" || value._bsontype === "Double" || value._bsontype === "Timestamp") {
|
|
35705
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
|
35706
|
-
} else if (value._bsontype === "Decimal128") {
|
|
35707
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (16 + 1);
|
|
35708
|
-
} else if (value._bsontype === "Code") {
|
|
35709
|
-
if (value.scope != null && Object.keys(value.scope).length > 0) {
|
|
35710
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + 4 + 4 + ByteUtils.utf8ByteLength(value.code.toString()) + 1 + internalCalculateObjectSize(value.scope, serializeFunctions, ignoreUndefined);
|
|
35711
|
-
} else {
|
|
35712
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + 4 + ByteUtils.utf8ByteLength(value.code.toString()) + 1;
|
|
35713
|
-
}
|
|
35714
|
-
} else if (value._bsontype === "Binary") {
|
|
35715
|
-
const binary = value;
|
|
35716
|
-
if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
|
|
35717
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (binary.position + 1 + 4 + 1 + 4);
|
|
35718
|
-
} else {
|
|
35719
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (binary.position + 1 + 4 + 1);
|
|
35720
|
-
}
|
|
35721
|
-
} else if (value._bsontype === "Symbol") {
|
|
35722
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + ByteUtils.utf8ByteLength(value.value) + 4 + 1 + 1;
|
|
35723
|
-
} else if (value._bsontype === "DBRef") {
|
|
35724
|
-
const ordered_values = Object.assign({
|
|
35725
|
-
$ref: value.collection,
|
|
35726
|
-
$id: value.oid
|
|
35727
|
-
}, value.fields);
|
|
35728
|
-
if (value.db != null) {
|
|
35729
|
-
ordered_values["$db"] = value.db;
|
|
35730
|
-
}
|
|
35731
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + internalCalculateObjectSize(ordered_values, serializeFunctions, ignoreUndefined);
|
|
35732
|
-
} else if (value instanceof RegExp || isRegExp(value)) {
|
|
35733
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + ByteUtils.utf8ByteLength(value.source) + 1 + (value.global ? 1 : 0) + (value.ignoreCase ? 1 : 0) + (value.multiline ? 1 : 0) + 1;
|
|
35734
|
-
} else if (value._bsontype === "BSONRegExp") {
|
|
35735
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + ByteUtils.utf8ByteLength(value.pattern) + 1 + ByteUtils.utf8ByteLength(value.options) + 1;
|
|
35736
|
-
} else {
|
|
35737
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + internalCalculateObjectSize(value, serializeFunctions, ignoreUndefined) + 1;
|
|
35738
|
-
}
|
|
35739
|
-
case "function":
|
|
35740
|
-
if (serializeFunctions) {
|
|
35741
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + 4 + ByteUtils.utf8ByteLength(value.toString()) + 1;
|
|
35742
|
-
}
|
|
35743
|
-
return 0;
|
|
35744
|
-
case "bigint":
|
|
35745
|
-
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
|
35746
|
-
case "symbol":
|
|
35747
|
-
return 0;
|
|
35748
|
-
default:
|
|
35749
|
-
throw new BSONError(`Unrecognized JS type: ${typeof value}`);
|
|
35750
|
-
}
|
|
35751
|
-
}
|
|
35752
|
-
function alphabetize(str) {
|
|
35753
|
-
return str.split("").sort().join("");
|
|
35754
|
-
}
|
|
35755
|
-
var BSONRegExp = class extends BSONValue {
|
|
35756
|
-
get _bsontype() {
|
|
35757
|
-
return "BSONRegExp";
|
|
35758
|
-
}
|
|
35759
|
-
constructor(pattern, options) {
|
|
35760
|
-
super();
|
|
35761
|
-
this.pattern = pattern;
|
|
35762
|
-
this.options = alphabetize(options ?? "");
|
|
35763
|
-
if (this.pattern.indexOf("\0") !== -1) {
|
|
35764
|
-
throw new BSONError(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);
|
|
35765
|
-
}
|
|
35766
|
-
if (this.options.indexOf("\0") !== -1) {
|
|
35767
|
-
throw new BSONError(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);
|
|
35768
|
-
}
|
|
35769
|
-
for (let i = 0; i < this.options.length; i++) {
|
|
35770
|
-
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")) {
|
|
35771
|
-
throw new BSONError(`The regular expression option [${this.options[i]}] is not supported`);
|
|
35772
|
-
}
|
|
35773
|
-
}
|
|
35774
|
-
}
|
|
35775
|
-
static parseOptions(options) {
|
|
35776
|
-
return options ? options.split("").sort().join("") : "";
|
|
35777
|
-
}
|
|
35778
|
-
toExtendedJSON(options) {
|
|
35779
|
-
options = options || {};
|
|
35780
|
-
if (options.legacy) {
|
|
35781
|
-
return { $regex: this.pattern, $options: this.options };
|
|
35782
|
-
}
|
|
35783
|
-
return { $regularExpression: { pattern: this.pattern, options: this.options } };
|
|
35784
|
-
}
|
|
35785
|
-
static fromExtendedJSON(doc) {
|
|
35786
|
-
if ("$regex" in doc) {
|
|
35787
|
-
if (typeof doc.$regex !== "string") {
|
|
35788
|
-
if (doc.$regex._bsontype === "BSONRegExp") {
|
|
35789
|
-
return doc;
|
|
35790
|
-
}
|
|
35791
|
-
} else {
|
|
35792
|
-
return new BSONRegExp(doc.$regex, BSONRegExp.parseOptions(doc.$options));
|
|
35793
|
-
}
|
|
35794
|
-
}
|
|
35795
|
-
if ("$regularExpression" in doc) {
|
|
35796
|
-
return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
|
|
35797
|
-
}
|
|
35798
|
-
throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`);
|
|
35799
|
-
}
|
|
35800
|
-
inspect(depth, options, inspect) {
|
|
35801
|
-
const stylize = getStylizeFunction(options) ?? ((v) => v);
|
|
35802
|
-
inspect ?? (inspect = defaultInspect);
|
|
35803
|
-
const pattern = stylize(inspect(this.pattern), "regexp");
|
|
35804
|
-
const flags = stylize(inspect(this.options), "regexp");
|
|
35805
|
-
return `new BSONRegExp(${pattern}, ${flags})`;
|
|
35806
|
-
}
|
|
35807
|
-
};
|
|
35808
|
-
var BSONSymbol = class extends BSONValue {
|
|
35809
|
-
get _bsontype() {
|
|
35810
|
-
return "BSONSymbol";
|
|
35811
|
-
}
|
|
35812
|
-
constructor(value) {
|
|
35813
|
-
super();
|
|
35814
|
-
this.value = value;
|
|
35815
|
-
}
|
|
35816
|
-
valueOf() {
|
|
35817
|
-
return this.value;
|
|
35818
|
-
}
|
|
35819
|
-
toString() {
|
|
35820
|
-
return this.value;
|
|
35821
|
-
}
|
|
35822
|
-
toJSON() {
|
|
35823
|
-
return this.value;
|
|
35824
|
-
}
|
|
35825
|
-
toExtendedJSON() {
|
|
35826
|
-
return { $symbol: this.value };
|
|
35827
|
-
}
|
|
35828
|
-
static fromExtendedJSON(doc) {
|
|
35829
|
-
return new BSONSymbol(doc.$symbol);
|
|
35830
|
-
}
|
|
35831
|
-
inspect(depth, options, inspect) {
|
|
35832
|
-
inspect ?? (inspect = defaultInspect);
|
|
35833
|
-
return `new BSONSymbol(${inspect(this.value, options)})`;
|
|
35834
|
-
}
|
|
35835
|
-
};
|
|
35836
|
-
var LongWithoutOverridesClass = Long;
|
|
35837
|
-
var Timestamp = class extends LongWithoutOverridesClass {
|
|
35838
|
-
get _bsontype() {
|
|
35839
|
-
return "Timestamp";
|
|
35840
|
-
}
|
|
35841
|
-
get i() {
|
|
35842
|
-
return this.low >>> 0;
|
|
35843
|
-
}
|
|
35844
|
-
get t() {
|
|
35845
|
-
return this.high >>> 0;
|
|
35846
|
-
}
|
|
35847
|
-
constructor(low) {
|
|
35848
|
-
if (low == null) {
|
|
35849
|
-
super(0, 0, true);
|
|
35850
|
-
} else if (typeof low === "bigint") {
|
|
35851
|
-
super(low, true);
|
|
35852
|
-
} else if (Long.isLong(low)) {
|
|
35853
|
-
super(low.low, low.high, true);
|
|
35854
|
-
} else if (typeof low === "object" && "t" in low && "i" in low) {
|
|
35855
|
-
if (typeof low.t !== "number" && (typeof low.t !== "object" || low.t._bsontype !== "Int32")) {
|
|
35856
|
-
throw new BSONError("Timestamp constructed from { t, i } must provide t as a number");
|
|
35857
|
-
}
|
|
35858
|
-
if (typeof low.i !== "number" && (typeof low.i !== "object" || low.i._bsontype !== "Int32")) {
|
|
35859
|
-
throw new BSONError("Timestamp constructed from { t, i } must provide i as a number");
|
|
35860
|
-
}
|
|
35861
|
-
const t = Number(low.t);
|
|
35862
|
-
const i = Number(low.i);
|
|
35863
|
-
if (t < 0 || Number.isNaN(t)) {
|
|
35864
|
-
throw new BSONError("Timestamp constructed from { t, i } must provide a positive t");
|
|
35865
|
-
}
|
|
35866
|
-
if (i < 0 || Number.isNaN(i)) {
|
|
35867
|
-
throw new BSONError("Timestamp constructed from { t, i } must provide a positive i");
|
|
35868
|
-
}
|
|
35869
|
-
if (t > 4294967295) {
|
|
35870
|
-
throw new BSONError("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");
|
|
35871
|
-
}
|
|
35872
|
-
if (i > 4294967295) {
|
|
35873
|
-
throw new BSONError("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");
|
|
35874
|
-
}
|
|
35875
|
-
super(i, t, true);
|
|
35876
|
-
} else {
|
|
35877
|
-
throw new BSONError("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }");
|
|
35878
|
-
}
|
|
35879
|
-
}
|
|
35880
|
-
toJSON() {
|
|
35881
|
-
return {
|
|
35882
|
-
$timestamp: this.toString()
|
|
35883
|
-
};
|
|
35884
|
-
}
|
|
35885
|
-
static fromInt(value) {
|
|
35886
|
-
return new Timestamp(Long.fromInt(value, true));
|
|
35887
|
-
}
|
|
35888
|
-
static fromNumber(value) {
|
|
35889
|
-
return new Timestamp(Long.fromNumber(value, true));
|
|
35890
|
-
}
|
|
35891
|
-
static fromBits(lowBits, highBits) {
|
|
35892
|
-
return new Timestamp({ i: lowBits, t: highBits });
|
|
35893
|
-
}
|
|
35894
|
-
static fromString(str, optRadix) {
|
|
35895
|
-
return new Timestamp(Long.fromString(str, true, optRadix));
|
|
35896
|
-
}
|
|
35897
|
-
toExtendedJSON() {
|
|
35898
|
-
return { $timestamp: { t: this.t, i: this.i } };
|
|
35899
|
-
}
|
|
35900
|
-
static fromExtendedJSON(doc) {
|
|
35901
|
-
const i = Long.isLong(doc.$timestamp.i) ? doc.$timestamp.i.getLowBitsUnsigned() : doc.$timestamp.i;
|
|
35902
|
-
const t = Long.isLong(doc.$timestamp.t) ? doc.$timestamp.t.getLowBitsUnsigned() : doc.$timestamp.t;
|
|
35903
|
-
return new Timestamp({ t, i });
|
|
35904
|
-
}
|
|
35905
|
-
inspect(depth, options, inspect) {
|
|
35906
|
-
inspect ?? (inspect = defaultInspect);
|
|
35907
|
-
const t = inspect(this.t, options);
|
|
35908
|
-
const i = inspect(this.i, options);
|
|
35909
|
-
return `new Timestamp({ t: ${t}, i: ${i} })`;
|
|
35910
|
-
}
|
|
35911
|
-
};
|
|
35912
|
-
Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
|
35913
|
-
var JS_INT_MAX_LONG = Long.fromNumber(JS_INT_MAX);
|
|
35914
|
-
var JS_INT_MIN_LONG = Long.fromNumber(JS_INT_MIN);
|
|
35915
|
-
function isBSONType(value) {
|
|
35916
|
-
return value != null && typeof value === "object" && "_bsontype" in value && typeof value._bsontype === "string";
|
|
35917
|
-
}
|
|
35918
|
-
var keysToCodecs = {
|
|
35919
|
-
$oid: ObjectId13,
|
|
35920
|
-
$binary: Binary,
|
|
35921
|
-
$uuid: Binary,
|
|
35922
|
-
$symbol: BSONSymbol,
|
|
35923
|
-
$numberInt: Int32,
|
|
35924
|
-
$numberDecimal: Decimal128,
|
|
35925
|
-
$numberDouble: Double,
|
|
35926
|
-
$numberLong: Long,
|
|
35927
|
-
$minKey: MinKey,
|
|
35928
|
-
$maxKey: MaxKey,
|
|
35929
|
-
$regex: BSONRegExp,
|
|
35930
|
-
$regularExpression: BSONRegExp,
|
|
35931
|
-
$timestamp: Timestamp
|
|
35932
|
-
};
|
|
35933
|
-
function deserializeValue(value, options = {}) {
|
|
35934
|
-
if (typeof value === "number") {
|
|
35935
|
-
const in32BitRange = value <= BSON_INT32_MAX && value >= BSON_INT32_MIN;
|
|
35936
|
-
const in64BitRange = value <= BSON_INT64_MAX && value >= BSON_INT64_MIN;
|
|
35937
|
-
if (options.relaxed || options.legacy) {
|
|
35938
|
-
return value;
|
|
35939
|
-
}
|
|
35940
|
-
if (Number.isInteger(value) && !Object.is(value, -0)) {
|
|
35941
|
-
if (in32BitRange) {
|
|
35942
|
-
return new Int32(value);
|
|
35943
|
-
}
|
|
35944
|
-
if (in64BitRange) {
|
|
35945
|
-
if (options.useBigInt64) {
|
|
35946
|
-
return BigInt(value);
|
|
35947
|
-
}
|
|
35948
|
-
return Long.fromNumber(value);
|
|
35949
|
-
}
|
|
35950
|
-
}
|
|
35951
|
-
return new Double(value);
|
|
35952
|
-
}
|
|
35953
|
-
if (value == null || typeof value !== "object")
|
|
35954
|
-
return value;
|
|
35955
|
-
if (value.$undefined)
|
|
35956
|
-
return null;
|
|
35957
|
-
const keys2 = Object.keys(value).filter((k) => k.startsWith("$") && value[k] != null);
|
|
35958
|
-
for (let i = 0; i < keys2.length; i++) {
|
|
35959
|
-
const c = keysToCodecs[keys2[i]];
|
|
35960
|
-
if (c)
|
|
35961
|
-
return c.fromExtendedJSON(value, options);
|
|
35962
|
-
}
|
|
35963
|
-
if (value.$date != null) {
|
|
35964
|
-
const d = value.$date;
|
|
35965
|
-
const date = /* @__PURE__ */ new Date();
|
|
35966
|
-
if (options.legacy) {
|
|
35967
|
-
if (typeof d === "number")
|
|
35968
|
-
date.setTime(d);
|
|
35969
|
-
else if (typeof d === "string")
|
|
35970
|
-
date.setTime(Date.parse(d));
|
|
35971
|
-
else if (typeof d === "bigint")
|
|
35972
|
-
date.setTime(Number(d));
|
|
35973
|
-
else
|
|
35974
|
-
throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
|
|
35975
|
-
} else {
|
|
35976
|
-
if (typeof d === "string")
|
|
35977
|
-
date.setTime(Date.parse(d));
|
|
35978
|
-
else if (Long.isLong(d))
|
|
35979
|
-
date.setTime(d.toNumber());
|
|
35980
|
-
else if (typeof d === "number" && options.relaxed)
|
|
35981
|
-
date.setTime(d);
|
|
35982
|
-
else if (typeof d === "bigint")
|
|
35983
|
-
date.setTime(Number(d));
|
|
35984
|
-
else
|
|
35985
|
-
throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
|
|
35986
|
-
}
|
|
35987
|
-
return date;
|
|
35988
|
-
}
|
|
35989
|
-
if (value.$code != null) {
|
|
35990
|
-
const copy = Object.assign({}, value);
|
|
35991
|
-
if (value.$scope) {
|
|
35992
|
-
copy.$scope = deserializeValue(value.$scope);
|
|
35993
|
-
}
|
|
35994
|
-
return Code.fromExtendedJSON(value);
|
|
35995
|
-
}
|
|
35996
|
-
if (isDBRefLike(value) || value.$dbPointer) {
|
|
35997
|
-
const v = value.$ref ? value : value.$dbPointer;
|
|
35998
|
-
if (v instanceof DBRef)
|
|
35999
|
-
return v;
|
|
36000
|
-
const dollarKeys = Object.keys(v).filter((k) => k.startsWith("$"));
|
|
36001
|
-
let valid = true;
|
|
36002
|
-
dollarKeys.forEach((k) => {
|
|
36003
|
-
if (["$ref", "$id", "$db"].indexOf(k) === -1)
|
|
36004
|
-
valid = false;
|
|
36005
|
-
});
|
|
36006
|
-
if (valid)
|
|
36007
|
-
return DBRef.fromExtendedJSON(v);
|
|
36008
|
-
}
|
|
36009
|
-
return value;
|
|
36010
|
-
}
|
|
36011
|
-
function serializeArray(array, options) {
|
|
36012
|
-
return array.map((v, index) => {
|
|
36013
|
-
options.seenObjects.push({ propertyName: `index ${index}`, obj: null });
|
|
36014
|
-
try {
|
|
36015
|
-
return serializeValue(v, options);
|
|
36016
|
-
} finally {
|
|
36017
|
-
options.seenObjects.pop();
|
|
36018
|
-
}
|
|
36019
|
-
});
|
|
36020
|
-
}
|
|
36021
|
-
function getISOString(date) {
|
|
36022
|
-
const isoStr = date.toISOString();
|
|
36023
|
-
return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + "Z";
|
|
36024
|
-
}
|
|
36025
|
-
function serializeValue(value, options) {
|
|
36026
|
-
if (value instanceof Map || isMap(value)) {
|
|
36027
|
-
const obj = /* @__PURE__ */ Object.create(null);
|
|
36028
|
-
for (const [k, v] of value) {
|
|
36029
|
-
if (typeof k !== "string") {
|
|
36030
|
-
throw new BSONError("Can only serialize maps with string keys");
|
|
36031
|
-
}
|
|
36032
|
-
obj[k] = v;
|
|
36033
|
-
}
|
|
36034
|
-
return serializeValue(obj, options);
|
|
36035
|
-
}
|
|
36036
|
-
if ((typeof value === "object" || typeof value === "function") && value !== null) {
|
|
36037
|
-
const index = options.seenObjects.findIndex((entry) => entry.obj === value);
|
|
36038
|
-
if (index !== -1) {
|
|
36039
|
-
const props = options.seenObjects.map((entry) => entry.propertyName);
|
|
36040
|
-
const leadingPart = props.slice(0, index).map((prop) => `${prop} -> `).join("");
|
|
36041
|
-
const alreadySeen = props[index];
|
|
36042
|
-
const circularPart = " -> " + props.slice(index + 1, props.length - 1).map((prop) => `${prop} -> `).join("");
|
|
36043
|
-
const current = props[props.length - 1];
|
|
36044
|
-
const leadingSpace = " ".repeat(leadingPart.length + alreadySeen.length / 2);
|
|
36045
|
-
const dashes = "-".repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
|
|
36046
|
-
throw new BSONError(`Converting circular structure to EJSON:
|
|
36047
|
-
${leadingPart}${alreadySeen}${circularPart}${current}
|
|
36048
|
-
${leadingSpace}\\${dashes}/`);
|
|
36049
|
-
}
|
|
36050
|
-
options.seenObjects[options.seenObjects.length - 1].obj = value;
|
|
36051
|
-
}
|
|
36052
|
-
if (Array.isArray(value))
|
|
36053
|
-
return serializeArray(value, options);
|
|
36054
|
-
if (value === void 0)
|
|
36055
|
-
return null;
|
|
36056
|
-
if (value instanceof Date || isDate(value)) {
|
|
36057
|
-
const dateNum = value.getTime(), inRange = dateNum > -1 && dateNum < 2534023188e5;
|
|
36058
|
-
if (options.legacy) {
|
|
36059
|
-
return options.relaxed && inRange ? { $date: value.getTime() } : { $date: getISOString(value) };
|
|
36060
|
-
}
|
|
36061
|
-
return options.relaxed && inRange ? { $date: getISOString(value) } : { $date: { $numberLong: value.getTime().toString() } };
|
|
36062
|
-
}
|
|
36063
|
-
if (typeof value === "number" && (!options.relaxed || !isFinite(value))) {
|
|
36064
|
-
if (Number.isInteger(value) && !Object.is(value, -0)) {
|
|
36065
|
-
if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
|
|
36066
|
-
return { $numberInt: value.toString() };
|
|
36067
|
-
}
|
|
36068
|
-
if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX) {
|
|
36069
|
-
return { $numberLong: value.toString() };
|
|
36070
|
-
}
|
|
36071
|
-
}
|
|
36072
|
-
return { $numberDouble: Object.is(value, -0) ? "-0.0" : value.toString() };
|
|
36073
|
-
}
|
|
36074
|
-
if (typeof value === "bigint") {
|
|
36075
|
-
if (!options.relaxed) {
|
|
36076
|
-
return { $numberLong: BigInt.asIntN(64, value).toString() };
|
|
36077
|
-
}
|
|
36078
|
-
return Number(BigInt.asIntN(64, value));
|
|
36079
|
-
}
|
|
36080
|
-
if (value instanceof RegExp || isRegExp(value)) {
|
|
36081
|
-
let flags = value.flags;
|
|
36082
|
-
if (flags === void 0) {
|
|
36083
|
-
const match = value.toString().match(/[gimuy]*$/);
|
|
36084
|
-
if (match) {
|
|
36085
|
-
flags = match[0];
|
|
36086
|
-
}
|
|
36087
|
-
}
|
|
36088
|
-
const rx = new BSONRegExp(value.source, flags);
|
|
36089
|
-
return rx.toExtendedJSON(options);
|
|
36090
|
-
}
|
|
36091
|
-
if (value != null && typeof value === "object")
|
|
36092
|
-
return serializeDocument(value, options);
|
|
36093
|
-
return value;
|
|
36094
|
-
}
|
|
36095
|
-
var BSON_TYPE_MAPPINGS = {
|
|
36096
|
-
Binary: (o) => new Binary(o.value(), o.sub_type),
|
|
36097
|
-
Code: (o) => new Code(o.code, o.scope),
|
|
36098
|
-
DBRef: (o) => new DBRef(o.collection || o.namespace, o.oid, o.db, o.fields),
|
|
36099
|
-
Decimal128: (o) => new Decimal128(o.bytes),
|
|
36100
|
-
Double: (o) => new Double(o.value),
|
|
36101
|
-
Int32: (o) => new Int32(o.value),
|
|
36102
|
-
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_),
|
|
36103
|
-
MaxKey: () => new MaxKey(),
|
|
36104
|
-
MinKey: () => new MinKey(),
|
|
36105
|
-
ObjectId: (o) => new ObjectId13(o),
|
|
36106
|
-
BSONRegExp: (o) => new BSONRegExp(o.pattern, o.options),
|
|
36107
|
-
BSONSymbol: (o) => new BSONSymbol(o.value),
|
|
36108
|
-
Timestamp: (o) => Timestamp.fromBits(o.low, o.high)
|
|
36109
|
-
};
|
|
36110
|
-
function serializeDocument(doc, options) {
|
|
36111
|
-
if (doc == null || typeof doc !== "object")
|
|
36112
|
-
throw new BSONError("not an object instance");
|
|
36113
|
-
const bsontype = doc._bsontype;
|
|
36114
|
-
if (typeof bsontype === "undefined") {
|
|
36115
|
-
const _doc = {};
|
|
36116
|
-
for (const name of Object.keys(doc)) {
|
|
36117
|
-
options.seenObjects.push({ propertyName: name, obj: null });
|
|
36118
|
-
try {
|
|
36119
|
-
const value = serializeValue(doc[name], options);
|
|
36120
|
-
if (name === "__proto__") {
|
|
36121
|
-
Object.defineProperty(_doc, name, {
|
|
36122
|
-
value,
|
|
36123
|
-
writable: true,
|
|
36124
|
-
enumerable: true,
|
|
36125
|
-
configurable: true
|
|
36126
|
-
});
|
|
36127
|
-
} else {
|
|
36128
|
-
_doc[name] = value;
|
|
36129
|
-
}
|
|
36130
|
-
} finally {
|
|
36131
|
-
options.seenObjects.pop();
|
|
36132
|
-
}
|
|
36133
|
-
}
|
|
36134
|
-
return _doc;
|
|
36135
|
-
} else if (doc != null && typeof doc === "object" && typeof doc._bsontype === "string" && doc[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
36136
|
-
throw new BSONVersionError();
|
|
36137
|
-
} else if (isBSONType(doc)) {
|
|
36138
|
-
let outDoc = doc;
|
|
36139
|
-
if (typeof outDoc.toExtendedJSON !== "function") {
|
|
36140
|
-
const mapper = BSON_TYPE_MAPPINGS[doc._bsontype];
|
|
36141
|
-
if (!mapper) {
|
|
36142
|
-
throw new BSONError("Unrecognized or invalid _bsontype: " + doc._bsontype);
|
|
36143
|
-
}
|
|
36144
|
-
outDoc = mapper(outDoc);
|
|
36145
|
-
}
|
|
36146
|
-
if (bsontype === "Code" && outDoc.scope) {
|
|
36147
|
-
outDoc = new Code(outDoc.code, serializeValue(outDoc.scope, options));
|
|
36148
|
-
} else if (bsontype === "DBRef" && outDoc.oid) {
|
|
36149
|
-
outDoc = new DBRef(serializeValue(outDoc.collection, options), serializeValue(outDoc.oid, options), serializeValue(outDoc.db, options), serializeValue(outDoc.fields, options));
|
|
36150
|
-
}
|
|
36151
|
-
return outDoc.toExtendedJSON(options);
|
|
36152
|
-
} else {
|
|
36153
|
-
throw new BSONError("_bsontype must be a string, but was: " + typeof bsontype);
|
|
36154
|
-
}
|
|
36155
|
-
}
|
|
36156
|
-
function parse(text, options) {
|
|
36157
|
-
const ejsonOptions = {
|
|
36158
|
-
useBigInt64: options?.useBigInt64 ?? false,
|
|
36159
|
-
relaxed: options?.relaxed ?? true,
|
|
36160
|
-
legacy: options?.legacy ?? false
|
|
36161
|
-
};
|
|
36162
|
-
return JSON.parse(text, (key, value) => {
|
|
36163
|
-
if (key.indexOf("\0") !== -1) {
|
|
36164
|
-
throw new BSONError(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(key)}`);
|
|
36165
|
-
}
|
|
36166
|
-
return deserializeValue(value, ejsonOptions);
|
|
36167
|
-
});
|
|
36168
|
-
}
|
|
36169
|
-
function stringify(value, replacer, space, options) {
|
|
36170
|
-
if (space != null && typeof space === "object") {
|
|
36171
|
-
options = space;
|
|
36172
|
-
space = 0;
|
|
36173
|
-
}
|
|
36174
|
-
if (replacer != null && typeof replacer === "object" && !Array.isArray(replacer)) {
|
|
36175
|
-
options = replacer;
|
|
36176
|
-
replacer = void 0;
|
|
36177
|
-
space = 0;
|
|
36178
|
-
}
|
|
36179
|
-
const serializeOptions = Object.assign({ relaxed: true, legacy: false }, options, {
|
|
36180
|
-
seenObjects: [{ propertyName: "(root)", obj: null }]
|
|
36181
|
-
});
|
|
36182
|
-
const doc = serializeValue(value, serializeOptions);
|
|
36183
|
-
return JSON.stringify(doc, replacer, space);
|
|
36184
|
-
}
|
|
36185
|
-
function EJSONserialize(value, options) {
|
|
36186
|
-
options = options || {};
|
|
36187
|
-
return JSON.parse(stringify(value, options));
|
|
36188
|
-
}
|
|
36189
|
-
function EJSONdeserialize(ejson, options) {
|
|
36190
|
-
options = options || {};
|
|
36191
|
-
return parse(JSON.stringify(ejson), options);
|
|
36192
|
-
}
|
|
36193
|
-
var EJSON = /* @__PURE__ */ Object.create(null);
|
|
36194
|
-
EJSON.parse = parse;
|
|
36195
|
-
EJSON.stringify = stringify;
|
|
36196
|
-
EJSON.serialize = EJSONserialize;
|
|
36197
|
-
EJSON.deserialize = EJSONdeserialize;
|
|
36198
|
-
Object.freeze(EJSON);
|
|
36199
|
-
var BSONElementType = {
|
|
36200
|
-
double: 1,
|
|
36201
|
-
string: 2,
|
|
36202
|
-
object: 3,
|
|
36203
|
-
array: 4,
|
|
36204
|
-
binData: 5,
|
|
36205
|
-
undefined: 6,
|
|
36206
|
-
objectId: 7,
|
|
36207
|
-
bool: 8,
|
|
36208
|
-
date: 9,
|
|
36209
|
-
null: 10,
|
|
36210
|
-
regex: 11,
|
|
36211
|
-
dbPointer: 12,
|
|
36212
|
-
javascript: 13,
|
|
36213
|
-
symbol: 14,
|
|
36214
|
-
javascriptWithScope: 15,
|
|
36215
|
-
int: 16,
|
|
36216
|
-
timestamp: 17,
|
|
36217
|
-
long: 18,
|
|
36218
|
-
decimal: 19,
|
|
36219
|
-
minKey: 255,
|
|
36220
|
-
maxKey: 127
|
|
36221
|
-
};
|
|
36222
|
-
function getSize(source, offset) {
|
|
36223
|
-
try {
|
|
36224
|
-
return NumberUtils.getNonnegativeInt32LE(source, offset);
|
|
36225
|
-
} catch (cause) {
|
|
36226
|
-
throw new BSONOffsetError("BSON size cannot be negative", offset, { cause });
|
|
36227
|
-
}
|
|
36228
|
-
}
|
|
36229
|
-
function findNull(bytes, offset) {
|
|
36230
|
-
let nullTerminatorOffset = offset;
|
|
36231
|
-
for (; bytes[nullTerminatorOffset] !== 0; nullTerminatorOffset++)
|
|
36232
|
-
;
|
|
36233
|
-
if (nullTerminatorOffset === bytes.length - 1) {
|
|
36234
|
-
throw new BSONOffsetError("Null terminator not found", offset);
|
|
36235
|
-
}
|
|
36236
|
-
return nullTerminatorOffset;
|
|
36237
|
-
}
|
|
36238
|
-
function parseToElements(bytes, startOffset = 0) {
|
|
36239
|
-
startOffset ?? (startOffset = 0);
|
|
36240
|
-
if (bytes.length < 5) {
|
|
36241
|
-
throw new BSONOffsetError(`Input must be at least 5 bytes, got ${bytes.length} bytes`, startOffset);
|
|
36242
|
-
}
|
|
36243
|
-
const documentSize = getSize(bytes, startOffset);
|
|
36244
|
-
if (documentSize > bytes.length - startOffset) {
|
|
36245
|
-
throw new BSONOffsetError(`Parsed documentSize (${documentSize} bytes) does not match input length (${bytes.length} bytes)`, startOffset);
|
|
36246
|
-
}
|
|
36247
|
-
if (bytes[startOffset + documentSize - 1] !== 0) {
|
|
36248
|
-
throw new BSONOffsetError("BSON documents must end in 0x00", startOffset + documentSize);
|
|
36249
|
-
}
|
|
36250
|
-
const elements = [];
|
|
36251
|
-
let offset = startOffset + 4;
|
|
36252
|
-
while (offset <= documentSize + startOffset) {
|
|
36253
|
-
const type = bytes[offset];
|
|
36254
|
-
offset += 1;
|
|
36255
|
-
if (type === 0) {
|
|
36256
|
-
if (offset - startOffset !== documentSize) {
|
|
36257
|
-
throw new BSONOffsetError(`Invalid 0x00 type byte`, offset);
|
|
36258
|
-
}
|
|
36259
|
-
break;
|
|
36260
|
-
}
|
|
36261
|
-
const nameOffset = offset;
|
|
36262
|
-
const nameLength = findNull(bytes, offset) - nameOffset;
|
|
36263
|
-
offset += nameLength + 1;
|
|
36264
|
-
let length;
|
|
36265
|
-
if (type === BSONElementType.double || type === BSONElementType.long || type === BSONElementType.date || type === BSONElementType.timestamp) {
|
|
36266
|
-
length = 8;
|
|
36267
|
-
} else if (type === BSONElementType.int) {
|
|
36268
|
-
length = 4;
|
|
36269
|
-
} else if (type === BSONElementType.objectId) {
|
|
36270
|
-
length = 12;
|
|
36271
|
-
} else if (type === BSONElementType.decimal) {
|
|
36272
|
-
length = 16;
|
|
36273
|
-
} else if (type === BSONElementType.bool) {
|
|
36274
|
-
length = 1;
|
|
36275
|
-
} else if (type === BSONElementType.null || type === BSONElementType.undefined || type === BSONElementType.maxKey || type === BSONElementType.minKey) {
|
|
36276
|
-
length = 0;
|
|
36277
|
-
} else if (type === BSONElementType.regex) {
|
|
36278
|
-
length = findNull(bytes, findNull(bytes, offset) + 1) + 1 - offset;
|
|
36279
|
-
} else if (type === BSONElementType.object || type === BSONElementType.array || type === BSONElementType.javascriptWithScope) {
|
|
36280
|
-
length = getSize(bytes, offset);
|
|
36281
|
-
} else if (type === BSONElementType.string || type === BSONElementType.binData || type === BSONElementType.dbPointer || type === BSONElementType.javascript || type === BSONElementType.symbol) {
|
|
36282
|
-
length = getSize(bytes, offset) + 4;
|
|
36283
|
-
if (type === BSONElementType.binData) {
|
|
36284
|
-
length += 1;
|
|
36285
|
-
}
|
|
36286
|
-
if (type === BSONElementType.dbPointer) {
|
|
36287
|
-
length += 12;
|
|
36288
|
-
}
|
|
36289
|
-
} else {
|
|
36290
|
-
throw new BSONOffsetError(`Invalid 0x${type.toString(16).padStart(2, "0")} type byte`, offset);
|
|
36291
|
-
}
|
|
36292
|
-
if (length > documentSize) {
|
|
36293
|
-
throw new BSONOffsetError("value reports length larger than document", offset);
|
|
36294
|
-
}
|
|
36295
|
-
elements.push([type, nameOffset, nameLength, offset, length]);
|
|
36296
|
-
offset += length;
|
|
36297
|
-
}
|
|
36298
|
-
return elements;
|
|
36299
|
-
}
|
|
36300
|
-
var onDemand = /* @__PURE__ */ Object.create(null);
|
|
36301
|
-
onDemand.parseToElements = parseToElements;
|
|
36302
|
-
onDemand.ByteUtils = ByteUtils;
|
|
36303
|
-
onDemand.NumberUtils = NumberUtils;
|
|
36304
|
-
Object.freeze(onDemand);
|
|
36305
|
-
var MAXSIZE = 1024 * 1024 * 17;
|
|
36306
|
-
var buffer = ByteUtils.allocate(MAXSIZE);
|
|
36307
|
-
function calculateObjectSize(object, options = {}) {
|
|
36308
|
-
options = options || {};
|
|
36309
|
-
const serializeFunctions = typeof options.serializeFunctions === "boolean" ? options.serializeFunctions : false;
|
|
36310
|
-
const ignoreUndefined = typeof options.ignoreUndefined === "boolean" ? options.ignoreUndefined : true;
|
|
36311
|
-
return internalCalculateObjectSize(object, serializeFunctions, ignoreUndefined);
|
|
36312
|
-
}
|
|
36313
|
-
|
|
36314
|
-
// src/resources/school/school.service.ts
|
|
33215
|
+
var fs = __toESM(require("fs"));
|
|
36315
33216
|
function useSchoolService() {
|
|
36316
33217
|
const {
|
|
36317
33218
|
add: addSchool,
|
|
36318
33219
|
getPendingByCreatedBy,
|
|
36319
33220
|
updateStatusById,
|
|
36320
|
-
getById
|
|
33221
|
+
getById,
|
|
33222
|
+
delCachedData: delCachedSchoolData
|
|
36321
33223
|
} = useSchoolRepo();
|
|
36322
|
-
const { addRole } = (0, import_core2.useRoleRepo)();
|
|
33224
|
+
const { addRole, delCachedData: delCachedRoleData } = (0, import_core2.useRoleRepo)();
|
|
36323
33225
|
const { getUserById } = (0, import_core2.useUserRepo)();
|
|
36324
33226
|
const { add: addMember } = (0, import_core2.useMemberRepo)();
|
|
36325
33227
|
async function register(value) {
|
|
@@ -36457,27 +33359,21 @@ function useSchoolService() {
|
|
|
36457
33359
|
await session.endSession();
|
|
36458
33360
|
}
|
|
36459
33361
|
}
|
|
36460
|
-
async function addBulk(file,
|
|
36461
|
-
const
|
|
36462
|
-
|
|
36463
|
-
|
|
36464
|
-
|
|
36465
|
-
);
|
|
33362
|
+
async function addBulk(file, payload) {
|
|
33363
|
+
const isCSV = file.mimetype.includes("csv") || file.originalname.endsWith(".csv");
|
|
33364
|
+
const isExcel = file.mimetype.includes("sheet") || file.originalname.endsWith(".xlsx") || file.originalname.endsWith(".xls");
|
|
33365
|
+
if (!isCSV && !isExcel) {
|
|
33366
|
+
throw new import_nodejs_utils20.BadRequestError("Only CSV and Excel files are supported");
|
|
36466
33367
|
}
|
|
36467
|
-
let
|
|
36468
|
-
const validatedSchools = [];
|
|
36469
|
-
const totalSize = validatedSchools.reduce(
|
|
36470
|
-
(sum, school) => sum + calculateObjectSize(school),
|
|
36471
|
-
0
|
|
36472
|
-
);
|
|
33368
|
+
let rawData = [];
|
|
36473
33369
|
try {
|
|
36474
|
-
if (
|
|
36475
|
-
const
|
|
36476
|
-
const
|
|
36477
|
-
const worksheet = workbook.Sheets[
|
|
36478
|
-
|
|
36479
|
-
} else
|
|
36480
|
-
const csvText =
|
|
33370
|
+
if (isExcel) {
|
|
33371
|
+
const fileBuffer = await fs.promises.readFile(file.path);
|
|
33372
|
+
const workbook = readSync(fileBuffer);
|
|
33373
|
+
const worksheet = workbook.Sheets[workbook.SheetNames[0]];
|
|
33374
|
+
rawData = utils.sheet_to_json(worksheet);
|
|
33375
|
+
} else {
|
|
33376
|
+
const csvText = await fs.promises.readFile(file.path, "utf8");
|
|
36481
33377
|
const parseResult = Papa.parse(csvText, {
|
|
36482
33378
|
header: true,
|
|
36483
33379
|
skipEmptyLines: true,
|
|
@@ -36488,146 +33384,136 @@ function useSchoolService() {
|
|
|
36488
33384
|
`CSV parsing error: ${parseResult.errors[0].message}`
|
|
36489
33385
|
);
|
|
36490
33386
|
}
|
|
36491
|
-
|
|
36492
|
-
} else {
|
|
36493
|
-
throw new import_nodejs_utils20.BadRequestError(
|
|
36494
|
-
"Unsupported file type. Please upload an Excel (.xlsx, .xls) or CSV (.csv) file."
|
|
36495
|
-
);
|
|
36496
|
-
}
|
|
36497
|
-
if (!schools || schools.length === 0) {
|
|
36498
|
-
throw new import_nodejs_utils20.BadRequestError("No data found in the uploaded file.");
|
|
33387
|
+
rawData = parseResult.data;
|
|
36499
33388
|
}
|
|
36500
|
-
|
|
36501
|
-
|
|
36502
|
-
|
|
36503
|
-
|
|
36504
|
-
|
|
36505
|
-
|
|
36506
|
-
|
|
36507
|
-
|
|
36508
|
-
|
|
36509
|
-
|
|
36510
|
-
|
|
36511
|
-
|
|
36512
|
-
|
|
36513
|
-
|
|
36514
|
-
|
|
36515
|
-
|
|
36516
|
-
|
|
36517
|
-
|
|
36518
|
-
continue;
|
|
36519
|
-
}
|
|
36520
|
-
const school = {
|
|
36521
|
-
id: schoolId.trim(),
|
|
36522
|
-
name: schoolName.trim(),
|
|
36523
|
-
street: district.trim(),
|
|
36524
|
-
// Use district as street
|
|
36525
|
-
barangay: "",
|
|
36526
|
-
city: district.trim(),
|
|
36527
|
-
// Use district as city
|
|
36528
|
-
province: "",
|
|
36529
|
-
// Will need to be set based on region/division
|
|
36530
|
-
postalCode: "",
|
|
36531
|
-
principalName: "",
|
|
36532
|
-
email: "",
|
|
36533
|
-
contactNumber: "",
|
|
36534
|
-
region,
|
|
36535
|
-
regionName: "",
|
|
36536
|
-
// Will be populated from region lookup
|
|
36537
|
-
division,
|
|
36538
|
-
divisionName: "",
|
|
36539
|
-
// Will be populated from division lookup
|
|
36540
|
-
status: "active"
|
|
36541
|
-
};
|
|
36542
|
-
const { error } = schemaSchool.validate(school);
|
|
36543
|
-
if (error) {
|
|
36544
|
-
errors.push(`Row ${rowNumber}: ${error.message}`);
|
|
36545
|
-
continue;
|
|
36546
|
-
}
|
|
36547
|
-
validatedSchools.push(school);
|
|
36548
|
-
} catch (error) {
|
|
36549
|
-
errors.push(
|
|
36550
|
-
`Row ${rowNumber}: ${error.message || "Invalid data format"}`
|
|
36551
|
-
);
|
|
36552
|
-
}
|
|
33389
|
+
} catch (error) {
|
|
33390
|
+
throw new import_nodejs_utils20.BadRequestError(`File parsing error: ${error.message}`);
|
|
33391
|
+
}
|
|
33392
|
+
if (!rawData.length) {
|
|
33393
|
+
throw new import_nodejs_utils20.BadRequestError("No data found in file");
|
|
33394
|
+
}
|
|
33395
|
+
const schools = [];
|
|
33396
|
+
const errors = [];
|
|
33397
|
+
for (let i = 0; i < rawData.length; i++) {
|
|
33398
|
+
const row = rawData[i];
|
|
33399
|
+
const rowNum = i + 1;
|
|
33400
|
+
const schoolId = (row.schoolId || row.id || "").toString().trim();
|
|
33401
|
+
const name = (row.name || "").toString().trim();
|
|
33402
|
+
const province = (row.province || "").toString().trim();
|
|
33403
|
+
const cityMunicipality = (row.cityMunicipality || "").toString().trim();
|
|
33404
|
+
if (!schoolId) {
|
|
33405
|
+
errors.push(`Row ${rowNum}: schoolId is required`);
|
|
33406
|
+
continue;
|
|
36553
33407
|
}
|
|
36554
|
-
if (
|
|
36555
|
-
|
|
36556
|
-
|
|
36557
|
-
${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
|
|
36558
|
-
... and ${errors.length - 10} more errors` : ""}`
|
|
36559
|
-
);
|
|
33408
|
+
if (!name) {
|
|
33409
|
+
errors.push(`Row ${rowNum}: name is required`);
|
|
33410
|
+
continue;
|
|
36560
33411
|
}
|
|
36561
|
-
if (
|
|
36562
|
-
|
|
36563
|
-
|
|
36564
|
-
);
|
|
33412
|
+
if (!province) {
|
|
33413
|
+
errors.push(`Row ${rowNum}: province is required`);
|
|
33414
|
+
continue;
|
|
36565
33415
|
}
|
|
36566
|
-
if (
|
|
36567
|
-
|
|
36568
|
-
|
|
36569
|
-
totalSize / 1024 / 1024
|
|
36570
|
-
)}MB) exceeds MongoDB transaction limit of 16MB. Please reduce the number of records or split into smaller files.`
|
|
36571
|
-
);
|
|
33416
|
+
if (!cityMunicipality) {
|
|
33417
|
+
errors.push(`Row ${rowNum}: city/municipality is required`);
|
|
33418
|
+
continue;
|
|
36572
33419
|
}
|
|
36573
|
-
|
|
36574
|
-
|
|
36575
|
-
|
|
33420
|
+
const school = {
|
|
33421
|
+
id: schoolId,
|
|
33422
|
+
name,
|
|
33423
|
+
region: payload.region,
|
|
33424
|
+
regionName: payload.regionName,
|
|
33425
|
+
division: payload.division,
|
|
33426
|
+
divisionName: payload.divisionName,
|
|
33427
|
+
province,
|
|
33428
|
+
cityMunicipality,
|
|
33429
|
+
status: "active"
|
|
33430
|
+
};
|
|
33431
|
+
const { error } = schemaSchool.validate(school);
|
|
33432
|
+
if (error) {
|
|
33433
|
+
errors.push(`Row ${rowNum}: ${error.message}`);
|
|
33434
|
+
continue;
|
|
36576
33435
|
}
|
|
36577
|
-
|
|
33436
|
+
schools.push(school);
|
|
36578
33437
|
}
|
|
36579
|
-
|
|
36580
|
-
|
|
36581
|
-
|
|
33438
|
+
if (errors.length > 0) {
|
|
33439
|
+
throw new import_nodejs_utils20.BadRequestError(
|
|
33440
|
+
`Validation errors:
|
|
33441
|
+
${errors.slice(0, 5).join("\n")}${errors.length > 5 ? `
|
|
33442
|
+
...and ${errors.length - 5} more` : ""}`
|
|
33443
|
+
);
|
|
36582
33444
|
}
|
|
36583
|
-
|
|
33445
|
+
const results = {
|
|
33446
|
+
successful: 0,
|
|
33447
|
+
failed: 0,
|
|
33448
|
+
skipped: 0,
|
|
33449
|
+
errors: []
|
|
33450
|
+
};
|
|
33451
|
+
const { getByName: getPSGCByName } = (0, import_core2.usePSGCRepo)();
|
|
33452
|
+
for (let i = 0; i < schools.length; i++) {
|
|
33453
|
+
const session = import_nodejs_utils20.useAtlas.getClient()?.startSession();
|
|
33454
|
+
if (!session) {
|
|
33455
|
+
throw new Error("Unable to start MongoDB session");
|
|
33456
|
+
}
|
|
36584
33457
|
session.startTransaction();
|
|
36585
|
-
const
|
|
36586
|
-
|
|
36587
|
-
|
|
36588
|
-
|
|
36589
|
-
|
|
36590
|
-
|
|
36591
|
-
|
|
36592
|
-
|
|
36593
|
-
|
|
36594
|
-
{
|
|
36595
|
-
id: schoolId.toString(),
|
|
36596
|
-
type: "basic-edu-school",
|
|
36597
|
-
name: "Admin",
|
|
36598
|
-
permissions: ["*"],
|
|
36599
|
-
status: "active",
|
|
36600
|
-
default: true
|
|
36601
|
-
},
|
|
36602
|
-
session
|
|
33458
|
+
const school = schools[i];
|
|
33459
|
+
try {
|
|
33460
|
+
const provincePSGC = await getPSGCByName({
|
|
33461
|
+
name: school.province ?? "",
|
|
33462
|
+
type: "Prov"
|
|
33463
|
+
});
|
|
33464
|
+
if (!provincePSGC) {
|
|
33465
|
+
throw new import_nodejs_utils20.BadRequestError(
|
|
33466
|
+
`Province '${school.province}' not found in PSGC data.`
|
|
36603
33467
|
);
|
|
36604
|
-
|
|
36605
|
-
|
|
33468
|
+
}
|
|
33469
|
+
const cityMunPSGC = await getPSGCByName({
|
|
33470
|
+
name: school.cityMunicipality ?? "",
|
|
33471
|
+
cityMunicipality: true,
|
|
33472
|
+
code: provincePSGC.code
|
|
33473
|
+
});
|
|
33474
|
+
if (!cityMunPSGC) {
|
|
33475
|
+
throw new import_nodejs_utils20.BadRequestError(
|
|
33476
|
+
`City/Municipality '${school.cityMunicipality}' not found in PSGC data.`
|
|
33477
|
+
);
|
|
33478
|
+
}
|
|
33479
|
+
school.provincePSGC = provincePSGC.code ?? 0;
|
|
33480
|
+
school.cityMunicipalityPSGC = cityMunPSGC.code ?? 0;
|
|
33481
|
+
const schoolId = await addSchool(school, session, false);
|
|
33482
|
+
await addRole(
|
|
33483
|
+
{
|
|
33484
|
+
id: schoolId.toString(),
|
|
33485
|
+
type: "basic-edu-school",
|
|
33486
|
+
name: "Admin",
|
|
33487
|
+
permissions: ["*"],
|
|
33488
|
+
status: "active",
|
|
33489
|
+
default: true
|
|
33490
|
+
},
|
|
33491
|
+
session,
|
|
33492
|
+
false
|
|
33493
|
+
);
|
|
33494
|
+
results.successful++;
|
|
33495
|
+
await session.commitTransaction();
|
|
33496
|
+
} catch (error) {
|
|
33497
|
+
if (String(error.message).toLowerCase().includes("duplicate")) {
|
|
33498
|
+
results.skipped = (results.skipped || 0) + 1;
|
|
33499
|
+
} else {
|
|
36606
33500
|
results.failed++;
|
|
36607
|
-
results.errors.push(
|
|
33501
|
+
results.errors.push(`${school.name}: ${error.message}`);
|
|
36608
33502
|
}
|
|
33503
|
+
await session.abortTransaction();
|
|
33504
|
+
} finally {
|
|
33505
|
+
await session.endSession();
|
|
36609
33506
|
}
|
|
36610
|
-
await session.commitTransaction();
|
|
36611
|
-
return {
|
|
36612
|
-
message: `Bulk upload completed. ${results.successful} schools added successfully.`,
|
|
36613
|
-
details: {
|
|
36614
|
-
successful: results.successful,
|
|
36615
|
-
failed: results.failed,
|
|
36616
|
-
total: validatedSchools.length,
|
|
36617
|
-
totalSizeMB: Math.round(totalSize / 1024 / 1024 * 100) / 100,
|
|
36618
|
-
errors: results.errors
|
|
36619
|
-
}
|
|
36620
|
-
};
|
|
36621
|
-
} catch (error) {
|
|
36622
|
-
import_nodejs_utils20.logger.log({
|
|
36623
|
-
level: "error",
|
|
36624
|
-
message: `Error in bulk school upload: ${error.message}`
|
|
36625
|
-
});
|
|
36626
|
-
await session.abortTransaction();
|
|
36627
|
-
throw error;
|
|
36628
|
-
} finally {
|
|
36629
|
-
await session.endSession();
|
|
36630
33507
|
}
|
|
33508
|
+
delCachedSchoolData();
|
|
33509
|
+
delCachedRoleData();
|
|
33510
|
+
return {
|
|
33511
|
+
message: `Processed ${schools.length} schools: ${results.successful} successful, ${results.failed} failed`,
|
|
33512
|
+
successful: results.successful,
|
|
33513
|
+
failed: results.failed,
|
|
33514
|
+
errors: results.errors,
|
|
33515
|
+
skipped: results.skipped
|
|
33516
|
+
};
|
|
36631
33517
|
}
|
|
36632
33518
|
return {
|
|
36633
33519
|
register,
|
|
@@ -36644,7 +33530,10 @@ function useSchoolController() {
|
|
|
36644
33530
|
const {
|
|
36645
33531
|
getAll: _getAll,
|
|
36646
33532
|
getPendingByCreatedBy: _getPendingByCreatedBy,
|
|
36647
|
-
updateStatusById: _updateStatusById
|
|
33533
|
+
updateStatusById: _updateStatusById,
|
|
33534
|
+
updateFieldById: _updateFieldById,
|
|
33535
|
+
updateById: _updateById,
|
|
33536
|
+
deleteById: _deleteById
|
|
36648
33537
|
} = useSchoolRepo();
|
|
36649
33538
|
const {
|
|
36650
33539
|
add: _addSchool,
|
|
@@ -36783,21 +33672,35 @@ function useSchoolController() {
|
|
|
36783
33672
|
}
|
|
36784
33673
|
async function addBulk(req, res, next) {
|
|
36785
33674
|
if (!req.file) {
|
|
36786
|
-
res.status(400).
|
|
33675
|
+
res.status(400).json({
|
|
33676
|
+
error: "File is required. Please upload a CSV or Excel file (.csv, .xlsx, .xls)"
|
|
33677
|
+
});
|
|
36787
33678
|
return;
|
|
36788
33679
|
}
|
|
36789
|
-
const { region, division } = req.body;
|
|
33680
|
+
const { region, regionName, division, divisionName } = req.body;
|
|
36790
33681
|
const validation = import_joi12.default.object({
|
|
36791
33682
|
region: import_joi12.default.string().hex().required(),
|
|
36792
|
-
|
|
33683
|
+
regionName: import_joi12.default.string().min(1).required(),
|
|
33684
|
+
division: import_joi12.default.string().hex().required(),
|
|
33685
|
+
divisionName: import_joi12.default.string().min(1).required()
|
|
33686
|
+
});
|
|
33687
|
+
const { error } = validation.validate({
|
|
33688
|
+
region,
|
|
33689
|
+
regionName,
|
|
33690
|
+
division,
|
|
33691
|
+
divisionName
|
|
36793
33692
|
});
|
|
36794
|
-
const { error } = validation.validate({ region, division });
|
|
36795
33693
|
if (error) {
|
|
36796
33694
|
next(new import_nodejs_utils21.BadRequestError(`Validation error: ${error.message}`));
|
|
36797
33695
|
return;
|
|
36798
33696
|
}
|
|
36799
33697
|
try {
|
|
36800
|
-
const result = await _addBulk(req.file,
|
|
33698
|
+
const result = await _addBulk(req.file, {
|
|
33699
|
+
region,
|
|
33700
|
+
regionName,
|
|
33701
|
+
division,
|
|
33702
|
+
divisionName
|
|
33703
|
+
});
|
|
36801
33704
|
res.status(201).json(result);
|
|
36802
33705
|
return;
|
|
36803
33706
|
} catch (error2) {
|
|
@@ -36805,6 +33708,69 @@ function useSchoolController() {
|
|
|
36805
33708
|
return;
|
|
36806
33709
|
}
|
|
36807
33710
|
}
|
|
33711
|
+
async function updateFieldById(req, res, next) {
|
|
33712
|
+
const _id = req.params.id;
|
|
33713
|
+
const { field, value } = req.body;
|
|
33714
|
+
const validation = import_joi12.default.object({
|
|
33715
|
+
_id: import_joi12.default.string().hex().required(),
|
|
33716
|
+
field: import_joi12.default.string().valid("name", "director", "directorName").required(),
|
|
33717
|
+
value: import_joi12.default.string().required()
|
|
33718
|
+
});
|
|
33719
|
+
const { error } = validation.validate({ _id, field, value });
|
|
33720
|
+
if (error) {
|
|
33721
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33722
|
+
return;
|
|
33723
|
+
}
|
|
33724
|
+
try {
|
|
33725
|
+
const message = await _updateFieldById({ _id, field, value });
|
|
33726
|
+
res.json({ message });
|
|
33727
|
+
return;
|
|
33728
|
+
} catch (error2) {
|
|
33729
|
+
next(error2);
|
|
33730
|
+
}
|
|
33731
|
+
}
|
|
33732
|
+
async function updateById(req, res, next) {
|
|
33733
|
+
const id = req.params.id;
|
|
33734
|
+
const payload = req.body;
|
|
33735
|
+
const validation = import_joi12.default.object({
|
|
33736
|
+
id: import_joi12.default.string().hex().required()
|
|
33737
|
+
});
|
|
33738
|
+
const { error: idError } = validation.validate({ id });
|
|
33739
|
+
if (idError) {
|
|
33740
|
+
next(new import_nodejs_utils21.BadRequestError(idError.message));
|
|
33741
|
+
return;
|
|
33742
|
+
}
|
|
33743
|
+
const { error } = schemaSchoolUpdate.validate(payload);
|
|
33744
|
+
if (error) {
|
|
33745
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33746
|
+
return;
|
|
33747
|
+
}
|
|
33748
|
+
try {
|
|
33749
|
+
const message = await _updateById(id, payload);
|
|
33750
|
+
res.json({ message });
|
|
33751
|
+
return;
|
|
33752
|
+
} catch (error2) {
|
|
33753
|
+
next(error2);
|
|
33754
|
+
}
|
|
33755
|
+
}
|
|
33756
|
+
async function deleteById(req, res, next) {
|
|
33757
|
+
const _id = req.params.id;
|
|
33758
|
+
const validation = import_joi12.default.object({
|
|
33759
|
+
_id: import_joi12.default.string().hex().required()
|
|
33760
|
+
});
|
|
33761
|
+
const { error } = validation.validate({ _id });
|
|
33762
|
+
if (error) {
|
|
33763
|
+
next(new import_nodejs_utils21.BadRequestError(error.message));
|
|
33764
|
+
return;
|
|
33765
|
+
}
|
|
33766
|
+
try {
|
|
33767
|
+
const message = await _deleteById(_id);
|
|
33768
|
+
res.json({ message });
|
|
33769
|
+
return;
|
|
33770
|
+
} catch (error2) {
|
|
33771
|
+
next(error2);
|
|
33772
|
+
}
|
|
33773
|
+
}
|
|
36808
33774
|
return {
|
|
36809
33775
|
add,
|
|
36810
33776
|
getAll,
|
|
@@ -36812,7 +33778,10 @@ function useSchoolController() {
|
|
|
36812
33778
|
updateStatusById,
|
|
36813
33779
|
registerSchool,
|
|
36814
33780
|
approveSchool,
|
|
36815
|
-
addBulk
|
|
33781
|
+
addBulk,
|
|
33782
|
+
updateFieldById,
|
|
33783
|
+
updateById,
|
|
33784
|
+
deleteById
|
|
36816
33785
|
};
|
|
36817
33786
|
}
|
|
36818
33787
|
|
|
@@ -38347,12 +35316,12 @@ ${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
|
|
|
38347
35316
|
failed: 0,
|
|
38348
35317
|
errors: []
|
|
38349
35318
|
};
|
|
38350
|
-
const
|
|
35319
|
+
const promises2 = [];
|
|
38351
35320
|
for (let i = 0; i < validatedPlantillas.length; i++) {
|
|
38352
35321
|
const plantilla = validatedPlantillas[i];
|
|
38353
|
-
|
|
35322
|
+
promises2.push(addPlantilla(plantilla, session, false));
|
|
38354
35323
|
}
|
|
38355
|
-
await Promise.all(
|
|
35324
|
+
await Promise.all(promises2);
|
|
38356
35325
|
await delCachedData();
|
|
38357
35326
|
await session.commitTransaction();
|
|
38358
35327
|
return {
|
|
@@ -38590,6 +35559,7 @@ dotenv.config();
|
|
|
38590
35559
|
schemaPlantilla,
|
|
38591
35560
|
schemaRegion,
|
|
38592
35561
|
schemaSchool,
|
|
35562
|
+
schemaSchoolUpdate,
|
|
38593
35563
|
schemaStockCard,
|
|
38594
35564
|
useAssetController,
|
|
38595
35565
|
useAssetRepo,
|