good commit
This commit is contained in:
parent
d1c8cae2c1
commit
4dc40622c7
1409 changed files with 1 additions and 326171 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
node_modules
|
||||
325
node_modules/.package-lock.json
generated
vendored
325
node_modules/.package-lock.json
generated
vendored
|
|
@ -1,325 +0,0 @@
|
|||
{
|
||||
"name": "jsmongo",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/@mongodb-js/saslprep": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.3.2.tgz",
|
||||
"integrity": "sha512-QgA5AySqB27cGTXBFmnpifAi7HxoGUeezwo6p9dI03MuDB6Pp33zgclqVb6oVK3j6I9Vesg0+oojW2XxB59SGg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"sparse-bitfield": "^3.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/webidl-conversions": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
|
||||
"integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/whatwg-url": {
|
||||
"version": "13.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-13.0.0.tgz",
|
||||
"integrity": "sha512-N8WXpbE6Wgri7KUSvrmQcqrMllKZ9uxkYWMt+mCSGwNc0Hsw9VQTW7ApqI4XNrx6/SaM2QQJCzMPDEXE058s+Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/webidl-conversions": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/bson": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bson/-/bson-7.0.0.tgz",
|
||||
"integrity": "sha512-Kwc6Wh4lQ5OmkqqKhYGKIuELXl+EPYSCObVE6bWsp1T/cGkOCBN0I8wF/T44BiuhHyNi1mmKVPXk60d41xZ7kw==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=20.19.0"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.4.3",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
||||
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "17.2.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz",
|
||||
"integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/kareem": {
|
||||
"version": "2.6.3",
|
||||
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz",
|
||||
"integrity": "sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/memory-pager": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
|
||||
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/mongodb": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.0.0.tgz",
|
||||
"integrity": "sha512-vG/A5cQrvGGvZm2mTnCSz1LUcbOPl83hfB6bxULKQ8oFZauyox/2xbZOoGNl+64m8VBrETkdGCDBdOsCr3F3jg==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@mongodb-js/saslprep": "^1.3.0",
|
||||
"bson": "^7.0.0",
|
||||
"mongodb-connection-string-url": "^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.19.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@aws-sdk/credential-providers": "^3.806.0",
|
||||
"@mongodb-js/zstd": "^7.0.0",
|
||||
"gcp-metadata": "^7.0.1",
|
||||
"kerberos": "^7.0.0",
|
||||
"mongodb-client-encryption": ">=7.0.0 <7.1.0",
|
||||
"snappy": "^7.3.2",
|
||||
"socks": "^2.8.6"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@aws-sdk/credential-providers": {
|
||||
"optional": true
|
||||
},
|
||||
"@mongodb-js/zstd": {
|
||||
"optional": true
|
||||
},
|
||||
"gcp-metadata": {
|
||||
"optional": true
|
||||
},
|
||||
"kerberos": {
|
||||
"optional": true
|
||||
},
|
||||
"mongodb-client-encryption": {
|
||||
"optional": true
|
||||
},
|
||||
"snappy": {
|
||||
"optional": true
|
||||
},
|
||||
"socks": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/mongodb-connection-string-url": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.0.tgz",
|
||||
"integrity": "sha512-irhhjRVLE20hbkRl4zpAYLnDMM+zIZnp0IDB9akAFFUZp/3XdOfwwddc7y6cNvF2WCEtfTYRwYbIfYa2kVY0og==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@types/whatwg-url": "^13.0.0",
|
||||
"whatwg-url": "^14.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.19.0"
|
||||
}
|
||||
},
|
||||
"node_modules/mongoose": {
|
||||
"version": "8.20.0",
|
||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.20.0.tgz",
|
||||
"integrity": "sha512-SxqNb8yx+VOjIOx2l7HqkGvYuLC/T85d+jPvqGDdUbKJFz/5PVSsVxQzypQsX7chenYvq5bd8jIr4LtunedE7g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bson": "^6.10.4",
|
||||
"kareem": "2.6.3",
|
||||
"mongodb": "~6.20.0",
|
||||
"mpath": "0.9.0",
|
||||
"mquery": "5.0.0",
|
||||
"ms": "2.1.3",
|
||||
"sift": "17.1.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.20.1"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/mongoose"
|
||||
}
|
||||
},
|
||||
"node_modules/mongoose/node_modules/@types/whatwg-url": {
|
||||
"version": "11.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz",
|
||||
"integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/webidl-conversions": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/mongoose/node_modules/bson": {
|
||||
"version": "6.10.4",
|
||||
"resolved": "https://registry.npmjs.org/bson/-/bson-6.10.4.tgz",
|
||||
"integrity": "sha512-WIsKqkSC0ABoBJuT1LEX+2HEvNmNKKgnTAyd0fL8qzK4SH2i9NXg+t08YtdZp/V9IZ33cxe3iV4yM0qg8lMQng==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=16.20.1"
|
||||
}
|
||||
},
|
||||
"node_modules/mongoose/node_modules/mongodb": {
|
||||
"version": "6.20.0",
|
||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.20.0.tgz",
|
||||
"integrity": "sha512-Tl6MEIU3K4Rq3TSHd+sZQqRBoGlFsOgNrH5ltAcFBV62Re3Fd+FcaVf8uSEQFOJ51SDowDVttBTONMfoYWrWlQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@mongodb-js/saslprep": "^1.3.0",
|
||||
"bson": "^6.10.4",
|
||||
"mongodb-connection-string-url": "^3.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.20.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@aws-sdk/credential-providers": "^3.188.0",
|
||||
"@mongodb-js/zstd": "^1.1.0 || ^2.0.0",
|
||||
"gcp-metadata": "^5.2.0",
|
||||
"kerberos": "^2.0.1",
|
||||
"mongodb-client-encryption": ">=6.0.0 <7",
|
||||
"snappy": "^7.3.2",
|
||||
"socks": "^2.7.1"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@aws-sdk/credential-providers": {
|
||||
"optional": true
|
||||
},
|
||||
"@mongodb-js/zstd": {
|
||||
"optional": true
|
||||
},
|
||||
"gcp-metadata": {
|
||||
"optional": true
|
||||
},
|
||||
"kerberos": {
|
||||
"optional": true
|
||||
},
|
||||
"mongodb-client-encryption": {
|
||||
"optional": true
|
||||
},
|
||||
"snappy": {
|
||||
"optional": true
|
||||
},
|
||||
"socks": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/mongoose/node_modules/mongodb-connection-string-url": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.2.tgz",
|
||||
"integrity": "sha512-rMO7CGo/9BFwyZABcKAWL8UJwH/Kc2x0g72uhDWzG48URRax5TCIcJ7Rc3RZqffZzO/Gwff/jyKwCU9TN8gehA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@types/whatwg-url": "^11.0.2",
|
||||
"whatwg-url": "^14.1.0 || ^13.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/mpath": {
|
||||
"version": "0.9.0",
|
||||
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz",
|
||||
"integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/mquery": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz",
|
||||
"integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"debug": "4.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/punycode": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
||||
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/sift": {
|
||||
"version": "17.1.3",
|
||||
"resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz",
|
||||
"integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/sparse-bitfield": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
|
||||
"integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"memory-pager": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/tr46": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz",
|
||||
"integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"punycode": "^2.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/webidl-conversions": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
|
||||
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/whatwg-url": {
|
||||
"version": "14.2.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz",
|
||||
"integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tr46": "^5.1.0",
|
||||
"webidl-conversions": "^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
node_modules/@mongodb-js/saslprep/LICENSE
generated
vendored
22
node_modules/@mongodb-js/saslprep/LICENSE
generated
vendored
|
|
@ -1,22 +0,0 @@
|
|||
Copyright (c) 2014 Dmitry Tsvettsikh
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
4
node_modules/@mongodb-js/saslprep/dist/.esm-wrapper.mjs
generated
vendored
4
node_modules/@mongodb-js/saslprep/dist/.esm-wrapper.mjs
generated
vendored
|
|
@ -1,4 +0,0 @@
|
|||
import mod from "./node.js";
|
||||
|
||||
export default mod;
|
||||
export const saslprep = mod.saslprep;
|
||||
5
node_modules/@mongodb-js/saslprep/dist/browser.d.ts
generated
vendored
5
node_modules/@mongodb-js/saslprep/dist/browser.d.ts
generated
vendored
|
|
@ -1,5 +0,0 @@
|
|||
declare const saslprep: (input: string, opts?: {
|
||||
allowUnassigned?: boolean;
|
||||
} | undefined) => string;
|
||||
export = saslprep;
|
||||
//# sourceMappingURL=browser.d.ts.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/browser.d.ts.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/browser.d.ts.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,QAAQ;;wBAAmC,CAAC;AAIlD,SAAS,QAAQ,CAAC"}
|
||||
12
node_modules/@mongodb-js/saslprep/dist/browser.js
generated
vendored
12
node_modules/@mongodb-js/saslprep/dist/browser.js
generated
vendored
|
|
@ -1,12 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const index_1 = __importDefault(require("./index"));
|
||||
const memory_code_points_1 = require("./memory-code-points");
|
||||
const code_points_data_browser_1 = __importDefault(require("./code-points-data-browser"));
|
||||
const codePoints = (0, memory_code_points_1.createMemoryCodePoints)(code_points_data_browser_1.default);
|
||||
const saslprep = index_1.default.bind(null, codePoints);
|
||||
Object.assign(saslprep, { saslprep, default: saslprep });
|
||||
module.exports = saslprep;
|
||||
//# sourceMappingURL=browser.js.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/browser.js.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/browser.js.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":";;;;AAAA,oDAAgC;AAChC,6DAA8D;AAC9D,0FAA8C;AAE9C,MAAM,UAAU,GAAG,IAAA,2CAAsB,EAAC,kCAAI,CAAC,CAAC;AAEhD,MAAM,QAAQ,GAAG,eAAS,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEzD,iBAAS,QAAQ,CAAC"}
|
||||
3
node_modules/@mongodb-js/saslprep/dist/code-points-data-browser.d.ts
generated
vendored
3
node_modules/@mongodb-js/saslprep/dist/code-points-data-browser.d.ts
generated
vendored
|
|
@ -1,3 +0,0 @@
|
|||
declare const data: Buffer<ArrayBuffer>;
|
||||
export default data;
|
||||
//# sourceMappingURL=code-points-data-browser.d.ts.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/code-points-data-browser.d.ts.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/code-points-data-browser.d.ts.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"code-points-data-browser.d.ts","sourceRoot":"","sources":["../src/code-points-data-browser.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,IAAI,qBAGT,CAAC;AACF,eAAe,IAAI,CAAC"}
|
||||
5
node_modules/@mongodb-js/saslprep/dist/code-points-data-browser.js
generated
vendored
5
node_modules/@mongodb-js/saslprep/dist/code-points-data-browser.js
generated
vendored
File diff suppressed because one or more lines are too long
1
node_modules/@mongodb-js/saslprep/dist/code-points-data-browser.js.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/code-points-data-browser.js.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"code-points-data-browser.js","sourceRoot":"","sources":["../src/code-points-data-browser.ts"],"names":[],"mappings":";;AAAA,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CACtB,8sliBAA8sliB,EAC9sliB,QAAQ,CACT,CAAC;AACF,kBAAe,IAAI,CAAC"}
|
||||
3
node_modules/@mongodb-js/saslprep/dist/code-points-data.d.ts
generated
vendored
3
node_modules/@mongodb-js/saslprep/dist/code-points-data.d.ts
generated
vendored
|
|
@ -1,3 +0,0 @@
|
|||
declare const _default: Buffer<ArrayBufferLike>;
|
||||
export default _default;
|
||||
//# sourceMappingURL=code-points-data.d.ts.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/code-points-data.d.ts.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/code-points-data.d.ts.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"code-points-data.d.ts","sourceRoot":"","sources":["../src/code-points-data.ts"],"names":[],"mappings":";AAEA,wBAKE"}
|
||||
5
node_modules/@mongodb-js/saslprep/dist/code-points-data.js
generated
vendored
5
node_modules/@mongodb-js/saslprep/dist/code-points-data.js
generated
vendored
|
|
@ -1,5 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const zlib_1 = require("zlib");
|
||||
exports.default = (0, zlib_1.gunzipSync)(Buffer.from('H4sIAAAAAAACA+3dTYgcaRkA4LemO9Mhxm0FITnE9Cwr4jHgwgZ22B6YywqCJ0HQg5CL4sGTuOjCtGSF4CkHEW856MlTQHD3EJnWkU0Owh5VxE3LHlYQdNxd2U6mU59UV/d09fw4M2EySSXPAzNdP1/9fX/99bzVNZEN4jisRDulVFnQmLxm1aXF9Id/2/xMxNJ4XZlg576yuYlGt9gupV6xoFf8jhu9YvulVrFlp5XSx+lfvYhORGPXvqIRWSxERKtIm8bKFd10WNfKDS5Fo9jJWrq2+M2IlW+8uHgl/+BsROfPF4v5L7148Ur68Sha6dqZpYiVVy8tvLCWXo80Sf/lS89dGX2wHGvpzoXVn75/YWH5wmqe8uika82ViJXTy83Ve2k5Urozm38wm4/ls6t5uT6yfsTSJ7J3T0VKt8c5ExEXI8aFkH729c3eT+7EC6ca8cVULZUiYacX0R5PNWNxlh9L1y90q5kyzrpyy+9WcvOV6URntqw7La9sNVstXyczWVaWYbaaTYqzOHpr7pyiNT3/YzKuT63Z/FqKZlFTiuXtFM2vVOtIq7jiyKJbWZaOWD0euz0yoV2Z7kY0xq2x0YhfzVpmM5px9nTEH7JZ0ot5u39p0ma75Z472/s/H+2yr2inYyuq7fMvJivH2rM72N/Z3lyL31F2b1ya1P0zn816k2KP6JU9UzseucdQH5YqVeH/lFajSN2udg+TLJ9rksNxlvV2lki19rXKI43TPLejFu4ov7k3nMbhyhfY3Xb37f8BAGCf0eMTOH5szf154KmnNgKcnLb+Fzi2AfXktbN7fJelwTAiO/W5uQ2KINXRYu+znqo/WTAdLadURHmy3qciazd3bra4T3w16/f7t7Ms9U5gfJu10955sx1r3vmhBAAAAAAAgId20J1iZbDowNvIjuH427Gr5l/eiC+8OplZON8sVjx/qr9y+Pj+YRItT+NqAM+kkZs3AAAAAID6yfx1FwCAI97/dCh1/ub6SA0AAAAAAAAAgNoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAAAAAgPoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAAAAAgPoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAAAAAgPoT/wcAAAAAAACA+hutp5SiQpYAAAAAAAAAQO2MIpZiT804flnAE2fhwjOeAZXr76kOAAAAAAAA8FjNf4N/l0NE3U/vuVQskLpSd4/Yh2xu9xTu0tFeeNYsLI2f/VMdNxTzj6Je9E/+6pp6Nn3awW3A54goe4Bss6v+PGsjQGMAAAAAAOBp5XEgwH6e7J7rwEQHRb/XvAMAAAAAAAA8yzoDeQDwVGjIAgAAAAAAAACoPfF/AAAAAAAAAKg/8X8AAAAAAAAAqD/xfwAAAAAAAACoP/F/AAAAAAAAAKg/8X8AAAAAAAAAqD/xfwAAAAAAAACoP/F/AAAAAAAAAKg/8X8AAAAAAAAAqD/xfwAAAAAAAACoP/F/AAAAAAAAAKg/8X8AAAAAAAAAqL/GSkSkClkCAAAAAAAAALXTSAAAAAAAAABA3Y1kAQAAAAAAAADUX8RSXZ9dsHC9+M8Fg2Ex/em1lAZpEBGttcrVjZqLEa+k0XpKw9mG4zWx4ukPUMhkAQAAAAAAABzBqbSe3//rXOS9HxGdo4TqR2XkutCdBu+LaPZw/lBbO7cbHnh2C7N7AIo4evEznllqLqWUp/LnYOtpM2bnOH66wI1+9GO4sOuISwv/TOlumu56FDv3NZhc4mR9v7zYIrafr40j/Cccvj9Xns3t3mu99E7qxUv3bqS0/ouNH/08++RGemfQ+nsx/5uNXsQPGulynPvv3ZTW37zd+1ovrqaYpP/122X6Xpx779Z3zr/3YOPKW1lkaRDf31pPaf3j/msRsVGkL+d/f+/m4sJsPm1cfSsr16e8m9Ldj/KsnyIuR3nXw83Is3EhxLd/2V773ks3m/cj/THKUummdP9qKhIOImuOU0Xjwb3y+oqt735rpTetVbF9n8R4x9crRfO77TKqVOZpDclv5bfK18lMnk+q0K18UpxF/RrGXE0Zxtqx3tWSj+vxbL4XaasfKb0dRbtLW73JsfPGg177H+OmGKlfvS1msllt7JEJm9XOJqXR+Fkfo1H66uy5H1v3Xx5+uJmGLw9jro2u7Loj4PnuR6+f+e3d261+eazNhzrL7X83MohoHpS4PddV8ki1it61//pw1g7z6p1U/26Nm2llST57B5rUvuG0XqSU/rPd7jYrqWcbd+beJQ77BgPMDwn37/8BAGCf0eMTOH4cPlufv9VGgJOzqf8Fjm1APXkd7B7f5dF57GPMaWy/MTvjvNvtXj6h8W2+GXvnzXaseeeHEgAAAAAAAB7aQXeKlcGiadBoEOeLb2dtpGOL2MyOtf391a3P/zD96c3JzIP3t4oV797vrh8+vn+YRL5bBuj/AQAAAABqJvfHXQAAHkX82zfXAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACeAgkAAAAAAAAAqLuRLAAAAAAAAACA2hv9D1iu/VAYaAYA', 'base64'));
|
||||
//# sourceMappingURL=code-points-data.js.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/code-points-data.js.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/code-points-data.js.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"code-points-data.js","sourceRoot":"","sources":["../src/code-points-data.ts"],"names":[],"mappings":";;AAAA,+BAAkC;AAElC,kBAAe,IAAA,iBAAU,EACvB,MAAM,CAAC,IAAI,CACT,knFAAknF,EAClnF,QAAQ,CACT,CACF,CAAC"}
|
||||
7
node_modules/@mongodb-js/saslprep/dist/code-points-src.d.ts
generated
vendored
7
node_modules/@mongodb-js/saslprep/dist/code-points-src.d.ts
generated
vendored
|
|
@ -1,7 +0,0 @@
|
|||
export declare const unassigned_code_points: Set<number>;
|
||||
export declare const commonly_mapped_to_nothing: Set<number>;
|
||||
export declare const non_ASCII_space_characters: Set<number>;
|
||||
export declare const prohibited_characters: Set<number>;
|
||||
export declare const bidirectional_r_al: Set<number>;
|
||||
export declare const bidirectional_l: Set<number>;
|
||||
//# sourceMappingURL=code-points-src.d.ts.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/code-points-src.d.ts.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/code-points-src.d.ts.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"code-points-src.d.ts","sourceRoot":"","sources":["../src/code-points-src.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB,aA6YjC,CAAC;AAMH,eAAO,MAAM,0BAA0B,aAIrC,CAAC;AAMH,eAAO,MAAM,0BAA0B,aASrC,CAAC;AAMH,eAAO,MAAM,qBAAqB,aA6GhC,CAAC;AAMH,eAAO,MAAM,kBAAkB,aAmC7B,CAAC;AAMH,eAAO,MAAM,eAAe,aAyW1B,CAAC"}
|
||||
881
node_modules/@mongodb-js/saslprep/dist/code-points-src.js
generated
vendored
881
node_modules/@mongodb-js/saslprep/dist/code-points-src.js
generated
vendored
|
|
@ -1,881 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.bidirectional_l = exports.bidirectional_r_al = exports.prohibited_characters = exports.non_ASCII_space_characters = exports.commonly_mapped_to_nothing = exports.unassigned_code_points = void 0;
|
||||
const util_1 = require("./util");
|
||||
exports.unassigned_code_points = new Set([
|
||||
0x0221,
|
||||
...(0, util_1.range)(0x0234, 0x024f),
|
||||
...(0, util_1.range)(0x02ae, 0x02af),
|
||||
...(0, util_1.range)(0x02ef, 0x02ff),
|
||||
...(0, util_1.range)(0x0350, 0x035f),
|
||||
...(0, util_1.range)(0x0370, 0x0373),
|
||||
...(0, util_1.range)(0x0376, 0x0379),
|
||||
...(0, util_1.range)(0x037b, 0x037d),
|
||||
...(0, util_1.range)(0x037f, 0x0383),
|
||||
0x038b,
|
||||
0x038d,
|
||||
0x03a2,
|
||||
0x03cf,
|
||||
...(0, util_1.range)(0x03f7, 0x03ff),
|
||||
0x0487,
|
||||
0x04cf,
|
||||
...(0, util_1.range)(0x04f6, 0x04f7),
|
||||
...(0, util_1.range)(0x04fa, 0x04ff),
|
||||
...(0, util_1.range)(0x0510, 0x0530),
|
||||
...(0, util_1.range)(0x0557, 0x0558),
|
||||
0x0560,
|
||||
0x0588,
|
||||
...(0, util_1.range)(0x058b, 0x0590),
|
||||
0x05a2,
|
||||
0x05ba,
|
||||
...(0, util_1.range)(0x05c5, 0x05cf),
|
||||
...(0, util_1.range)(0x05eb, 0x05ef),
|
||||
...(0, util_1.range)(0x05f5, 0x060b),
|
||||
...(0, util_1.range)(0x060d, 0x061a),
|
||||
...(0, util_1.range)(0x061c, 0x061e),
|
||||
0x0620,
|
||||
...(0, util_1.range)(0x063b, 0x063f),
|
||||
...(0, util_1.range)(0x0656, 0x065f),
|
||||
...(0, util_1.range)(0x06ee, 0x06ef),
|
||||
0x06ff,
|
||||
0x070e,
|
||||
...(0, util_1.range)(0x072d, 0x072f),
|
||||
...(0, util_1.range)(0x074b, 0x077f),
|
||||
...(0, util_1.range)(0x07b2, 0x0900),
|
||||
0x0904,
|
||||
...(0, util_1.range)(0x093a, 0x093b),
|
||||
...(0, util_1.range)(0x094e, 0x094f),
|
||||
...(0, util_1.range)(0x0955, 0x0957),
|
||||
...(0, util_1.range)(0x0971, 0x0980),
|
||||
0x0984,
|
||||
...(0, util_1.range)(0x098d, 0x098e),
|
||||
...(0, util_1.range)(0x0991, 0x0992),
|
||||
0x09a9,
|
||||
0x09b1,
|
||||
...(0, util_1.range)(0x09b3, 0x09b5),
|
||||
...(0, util_1.range)(0x09ba, 0x09bb),
|
||||
0x09bd,
|
||||
...(0, util_1.range)(0x09c5, 0x09c6),
|
||||
...(0, util_1.range)(0x09c9, 0x09ca),
|
||||
...(0, util_1.range)(0x09ce, 0x09d6),
|
||||
...(0, util_1.range)(0x09d8, 0x09db),
|
||||
0x09de,
|
||||
...(0, util_1.range)(0x09e4, 0x09e5),
|
||||
...(0, util_1.range)(0x09fb, 0x0a01),
|
||||
...(0, util_1.range)(0x0a03, 0x0a04),
|
||||
...(0, util_1.range)(0x0a0b, 0x0a0e),
|
||||
...(0, util_1.range)(0x0a11, 0x0a12),
|
||||
0x0a29,
|
||||
0x0a31,
|
||||
0x0a34,
|
||||
0x0a37,
|
||||
...(0, util_1.range)(0x0a3a, 0x0a3b),
|
||||
0x0a3d,
|
||||
...(0, util_1.range)(0x0a43, 0x0a46),
|
||||
...(0, util_1.range)(0x0a49, 0x0a4a),
|
||||
...(0, util_1.range)(0x0a4e, 0x0a58),
|
||||
0x0a5d,
|
||||
...(0, util_1.range)(0x0a5f, 0x0a65),
|
||||
...(0, util_1.range)(0x0a75, 0x0a80),
|
||||
0x0a84,
|
||||
0x0a8c,
|
||||
0x0a8e,
|
||||
0x0a92,
|
||||
0x0aa9,
|
||||
0x0ab1,
|
||||
0x0ab4,
|
||||
...(0, util_1.range)(0x0aba, 0x0abb),
|
||||
0x0ac6,
|
||||
0x0aca,
|
||||
...(0, util_1.range)(0x0ace, 0x0acf),
|
||||
...(0, util_1.range)(0x0ad1, 0x0adf),
|
||||
...(0, util_1.range)(0x0ae1, 0x0ae5),
|
||||
...(0, util_1.range)(0x0af0, 0x0b00),
|
||||
0x0b04,
|
||||
...(0, util_1.range)(0x0b0d, 0x0b0e),
|
||||
...(0, util_1.range)(0x0b11, 0x0b12),
|
||||
0x0b29,
|
||||
0x0b31,
|
||||
...(0, util_1.range)(0x0b34, 0x0b35),
|
||||
...(0, util_1.range)(0x0b3a, 0x0b3b),
|
||||
...(0, util_1.range)(0x0b44, 0x0b46),
|
||||
...(0, util_1.range)(0x0b49, 0x0b4a),
|
||||
...(0, util_1.range)(0x0b4e, 0x0b55),
|
||||
...(0, util_1.range)(0x0b58, 0x0b5b),
|
||||
0x0b5e,
|
||||
...(0, util_1.range)(0x0b62, 0x0b65),
|
||||
...(0, util_1.range)(0x0b71, 0x0b81),
|
||||
0x0b84,
|
||||
...(0, util_1.range)(0x0b8b, 0x0b8d),
|
||||
0x0b91,
|
||||
...(0, util_1.range)(0x0b96, 0x0b98),
|
||||
0x0b9b,
|
||||
0x0b9d,
|
||||
...(0, util_1.range)(0x0ba0, 0x0ba2),
|
||||
...(0, util_1.range)(0x0ba5, 0x0ba7),
|
||||
...(0, util_1.range)(0x0bab, 0x0bad),
|
||||
0x0bb6,
|
||||
...(0, util_1.range)(0x0bba, 0x0bbd),
|
||||
...(0, util_1.range)(0x0bc3, 0x0bc5),
|
||||
0x0bc9,
|
||||
...(0, util_1.range)(0x0bce, 0x0bd6),
|
||||
...(0, util_1.range)(0x0bd8, 0x0be6),
|
||||
...(0, util_1.range)(0x0bf3, 0x0c00),
|
||||
0x0c04,
|
||||
0x0c0d,
|
||||
0x0c11,
|
||||
0x0c29,
|
||||
0x0c34,
|
||||
...(0, util_1.range)(0x0c3a, 0x0c3d),
|
||||
0x0c45,
|
||||
0x0c49,
|
||||
...(0, util_1.range)(0x0c4e, 0x0c54),
|
||||
...(0, util_1.range)(0x0c57, 0x0c5f),
|
||||
...(0, util_1.range)(0x0c62, 0x0c65),
|
||||
...(0, util_1.range)(0x0c70, 0x0c81),
|
||||
0x0c84,
|
||||
0x0c8d,
|
||||
0x0c91,
|
||||
0x0ca9,
|
||||
0x0cb4,
|
||||
...(0, util_1.range)(0x0cba, 0x0cbd),
|
||||
0x0cc5,
|
||||
0x0cc9,
|
||||
...(0, util_1.range)(0x0cce, 0x0cd4),
|
||||
...(0, util_1.range)(0x0cd7, 0x0cdd),
|
||||
0x0cdf,
|
||||
...(0, util_1.range)(0x0ce2, 0x0ce5),
|
||||
...(0, util_1.range)(0x0cf0, 0x0d01),
|
||||
0x0d04,
|
||||
0x0d0d,
|
||||
0x0d11,
|
||||
0x0d29,
|
||||
...(0, util_1.range)(0x0d3a, 0x0d3d),
|
||||
...(0, util_1.range)(0x0d44, 0x0d45),
|
||||
0x0d49,
|
||||
...(0, util_1.range)(0x0d4e, 0x0d56),
|
||||
...(0, util_1.range)(0x0d58, 0x0d5f),
|
||||
...(0, util_1.range)(0x0d62, 0x0d65),
|
||||
...(0, util_1.range)(0x0d70, 0x0d81),
|
||||
0x0d84,
|
||||
...(0, util_1.range)(0x0d97, 0x0d99),
|
||||
0x0db2,
|
||||
0x0dbc,
|
||||
...(0, util_1.range)(0x0dbe, 0x0dbf),
|
||||
...(0, util_1.range)(0x0dc7, 0x0dc9),
|
||||
...(0, util_1.range)(0x0dcb, 0x0dce),
|
||||
0x0dd5,
|
||||
0x0dd7,
|
||||
...(0, util_1.range)(0x0de0, 0x0df1),
|
||||
...(0, util_1.range)(0x0df5, 0x0e00),
|
||||
...(0, util_1.range)(0x0e3b, 0x0e3e),
|
||||
...(0, util_1.range)(0x0e5c, 0x0e80),
|
||||
0x0e83,
|
||||
...(0, util_1.range)(0x0e85, 0x0e86),
|
||||
0x0e89,
|
||||
...(0, util_1.range)(0x0e8b, 0x0e8c),
|
||||
...(0, util_1.range)(0x0e8e, 0x0e93),
|
||||
0x0e98,
|
||||
0x0ea0,
|
||||
0x0ea4,
|
||||
0x0ea6,
|
||||
...(0, util_1.range)(0x0ea8, 0x0ea9),
|
||||
0x0eac,
|
||||
0x0eba,
|
||||
...(0, util_1.range)(0x0ebe, 0x0ebf),
|
||||
0x0ec5,
|
||||
0x0ec7,
|
||||
...(0, util_1.range)(0x0ece, 0x0ecf),
|
||||
...(0, util_1.range)(0x0eda, 0x0edb),
|
||||
...(0, util_1.range)(0x0ede, 0x0eff),
|
||||
0x0f48,
|
||||
...(0, util_1.range)(0x0f6b, 0x0f70),
|
||||
...(0, util_1.range)(0x0f8c, 0x0f8f),
|
||||
0x0f98,
|
||||
0x0fbd,
|
||||
...(0, util_1.range)(0x0fcd, 0x0fce),
|
||||
...(0, util_1.range)(0x0fd0, 0x0fff),
|
||||
0x1022,
|
||||
0x1028,
|
||||
0x102b,
|
||||
...(0, util_1.range)(0x1033, 0x1035),
|
||||
...(0, util_1.range)(0x103a, 0x103f),
|
||||
...(0, util_1.range)(0x105a, 0x109f),
|
||||
...(0, util_1.range)(0x10c6, 0x10cf),
|
||||
...(0, util_1.range)(0x10f9, 0x10fa),
|
||||
...(0, util_1.range)(0x10fc, 0x10ff),
|
||||
...(0, util_1.range)(0x115a, 0x115e),
|
||||
...(0, util_1.range)(0x11a3, 0x11a7),
|
||||
...(0, util_1.range)(0x11fa, 0x11ff),
|
||||
0x1207,
|
||||
0x1247,
|
||||
0x1249,
|
||||
...(0, util_1.range)(0x124e, 0x124f),
|
||||
0x1257,
|
||||
0x1259,
|
||||
...(0, util_1.range)(0x125e, 0x125f),
|
||||
0x1287,
|
||||
0x1289,
|
||||
...(0, util_1.range)(0x128e, 0x128f),
|
||||
0x12af,
|
||||
0x12b1,
|
||||
...(0, util_1.range)(0x12b6, 0x12b7),
|
||||
0x12bf,
|
||||
0x12c1,
|
||||
...(0, util_1.range)(0x12c6, 0x12c7),
|
||||
0x12cf,
|
||||
0x12d7,
|
||||
0x12ef,
|
||||
0x130f,
|
||||
0x1311,
|
||||
...(0, util_1.range)(0x1316, 0x1317),
|
||||
0x131f,
|
||||
0x1347,
|
||||
...(0, util_1.range)(0x135b, 0x1360),
|
||||
...(0, util_1.range)(0x137d, 0x139f),
|
||||
...(0, util_1.range)(0x13f5, 0x1400),
|
||||
...(0, util_1.range)(0x1677, 0x167f),
|
||||
...(0, util_1.range)(0x169d, 0x169f),
|
||||
...(0, util_1.range)(0x16f1, 0x16ff),
|
||||
0x170d,
|
||||
...(0, util_1.range)(0x1715, 0x171f),
|
||||
...(0, util_1.range)(0x1737, 0x173f),
|
||||
...(0, util_1.range)(0x1754, 0x175f),
|
||||
0x176d,
|
||||
0x1771,
|
||||
...(0, util_1.range)(0x1774, 0x177f),
|
||||
...(0, util_1.range)(0x17dd, 0x17df),
|
||||
...(0, util_1.range)(0x17ea, 0x17ff),
|
||||
0x180f,
|
||||
...(0, util_1.range)(0x181a, 0x181f),
|
||||
...(0, util_1.range)(0x1878, 0x187f),
|
||||
...(0, util_1.range)(0x18aa, 0x1dff),
|
||||
...(0, util_1.range)(0x1e9c, 0x1e9f),
|
||||
...(0, util_1.range)(0x1efa, 0x1eff),
|
||||
...(0, util_1.range)(0x1f16, 0x1f17),
|
||||
...(0, util_1.range)(0x1f1e, 0x1f1f),
|
||||
...(0, util_1.range)(0x1f46, 0x1f47),
|
||||
...(0, util_1.range)(0x1f4e, 0x1f4f),
|
||||
0x1f58,
|
||||
0x1f5a,
|
||||
0x1f5c,
|
||||
0x1f5e,
|
||||
...(0, util_1.range)(0x1f7e, 0x1f7f),
|
||||
0x1fb5,
|
||||
0x1fc5,
|
||||
...(0, util_1.range)(0x1fd4, 0x1fd5),
|
||||
0x1fdc,
|
||||
...(0, util_1.range)(0x1ff0, 0x1ff1),
|
||||
0x1ff5,
|
||||
0x1fff,
|
||||
...(0, util_1.range)(0x2053, 0x2056),
|
||||
...(0, util_1.range)(0x2058, 0x205e),
|
||||
...(0, util_1.range)(0x2064, 0x2069),
|
||||
...(0, util_1.range)(0x2072, 0x2073),
|
||||
...(0, util_1.range)(0x208f, 0x209f),
|
||||
...(0, util_1.range)(0x20b2, 0x20cf),
|
||||
...(0, util_1.range)(0x20eb, 0x20ff),
|
||||
...(0, util_1.range)(0x213b, 0x213c),
|
||||
...(0, util_1.range)(0x214c, 0x2152),
|
||||
...(0, util_1.range)(0x2184, 0x218f),
|
||||
...(0, util_1.range)(0x23cf, 0x23ff),
|
||||
...(0, util_1.range)(0x2427, 0x243f),
|
||||
...(0, util_1.range)(0x244b, 0x245f),
|
||||
0x24ff,
|
||||
...(0, util_1.range)(0x2614, 0x2615),
|
||||
0x2618,
|
||||
...(0, util_1.range)(0x267e, 0x267f),
|
||||
...(0, util_1.range)(0x268a, 0x2700),
|
||||
0x2705,
|
||||
...(0, util_1.range)(0x270a, 0x270b),
|
||||
0x2728,
|
||||
0x274c,
|
||||
0x274e,
|
||||
...(0, util_1.range)(0x2753, 0x2755),
|
||||
0x2757,
|
||||
...(0, util_1.range)(0x275f, 0x2760),
|
||||
...(0, util_1.range)(0x2795, 0x2797),
|
||||
0x27b0,
|
||||
...(0, util_1.range)(0x27bf, 0x27cf),
|
||||
...(0, util_1.range)(0x27ec, 0x27ef),
|
||||
...(0, util_1.range)(0x2b00, 0x2e7f),
|
||||
0x2e9a,
|
||||
...(0, util_1.range)(0x2ef4, 0x2eff),
|
||||
...(0, util_1.range)(0x2fd6, 0x2fef),
|
||||
...(0, util_1.range)(0x2ffc, 0x2fff),
|
||||
0x3040,
|
||||
...(0, util_1.range)(0x3097, 0x3098),
|
||||
...(0, util_1.range)(0x3100, 0x3104),
|
||||
...(0, util_1.range)(0x312d, 0x3130),
|
||||
0x318f,
|
||||
...(0, util_1.range)(0x31b8, 0x31ef),
|
||||
...(0, util_1.range)(0x321d, 0x321f),
|
||||
...(0, util_1.range)(0x3244, 0x3250),
|
||||
...(0, util_1.range)(0x327c, 0x327e),
|
||||
...(0, util_1.range)(0x32cc, 0x32cf),
|
||||
0x32ff,
|
||||
...(0, util_1.range)(0x3377, 0x337a),
|
||||
...(0, util_1.range)(0x33de, 0x33df),
|
||||
0x33ff,
|
||||
...(0, util_1.range)(0x4db6, 0x4dff),
|
||||
...(0, util_1.range)(0x9fa6, 0x9fff),
|
||||
...(0, util_1.range)(0xa48d, 0xa48f),
|
||||
...(0, util_1.range)(0xa4c7, 0xabff),
|
||||
...(0, util_1.range)(0xd7a4, 0xd7ff),
|
||||
...(0, util_1.range)(0xfa2e, 0xfa2f),
|
||||
...(0, util_1.range)(0xfa6b, 0xfaff),
|
||||
...(0, util_1.range)(0xfb07, 0xfb12),
|
||||
...(0, util_1.range)(0xfb18, 0xfb1c),
|
||||
0xfb37,
|
||||
0xfb3d,
|
||||
0xfb3f,
|
||||
0xfb42,
|
||||
0xfb45,
|
||||
...(0, util_1.range)(0xfbb2, 0xfbd2),
|
||||
...(0, util_1.range)(0xfd40, 0xfd4f),
|
||||
...(0, util_1.range)(0xfd90, 0xfd91),
|
||||
...(0, util_1.range)(0xfdc8, 0xfdcf),
|
||||
...(0, util_1.range)(0xfdfd, 0xfdff),
|
||||
...(0, util_1.range)(0xfe10, 0xfe1f),
|
||||
...(0, util_1.range)(0xfe24, 0xfe2f),
|
||||
...(0, util_1.range)(0xfe47, 0xfe48),
|
||||
0xfe53,
|
||||
0xfe67,
|
||||
...(0, util_1.range)(0xfe6c, 0xfe6f),
|
||||
0xfe75,
|
||||
...(0, util_1.range)(0xfefd, 0xfefe),
|
||||
0xff00,
|
||||
...(0, util_1.range)(0xffbf, 0xffc1),
|
||||
...(0, util_1.range)(0xffc8, 0xffc9),
|
||||
...(0, util_1.range)(0xffd0, 0xffd1),
|
||||
...(0, util_1.range)(0xffd8, 0xffd9),
|
||||
...(0, util_1.range)(0xffdd, 0xffdf),
|
||||
0xffe7,
|
||||
...(0, util_1.range)(0xffef, 0xfff8),
|
||||
...(0, util_1.range)(0x10000, 0x102ff),
|
||||
0x1031f,
|
||||
...(0, util_1.range)(0x10324, 0x1032f),
|
||||
...(0, util_1.range)(0x1034b, 0x103ff),
|
||||
...(0, util_1.range)(0x10426, 0x10427),
|
||||
...(0, util_1.range)(0x1044e, 0x1cfff),
|
||||
...(0, util_1.range)(0x1d0f6, 0x1d0ff),
|
||||
...(0, util_1.range)(0x1d127, 0x1d129),
|
||||
...(0, util_1.range)(0x1d1de, 0x1d3ff),
|
||||
0x1d455,
|
||||
0x1d49d,
|
||||
...(0, util_1.range)(0x1d4a0, 0x1d4a1),
|
||||
...(0, util_1.range)(0x1d4a3, 0x1d4a4),
|
||||
...(0, util_1.range)(0x1d4a7, 0x1d4a8),
|
||||
0x1d4ad,
|
||||
0x1d4ba,
|
||||
0x1d4bc,
|
||||
0x1d4c1,
|
||||
0x1d4c4,
|
||||
0x1d506,
|
||||
...(0, util_1.range)(0x1d50b, 0x1d50c),
|
||||
0x1d515,
|
||||
0x1d51d,
|
||||
0x1d53a,
|
||||
0x1d53f,
|
||||
0x1d545,
|
||||
...(0, util_1.range)(0x1d547, 0x1d549),
|
||||
0x1d551,
|
||||
...(0, util_1.range)(0x1d6a4, 0x1d6a7),
|
||||
...(0, util_1.range)(0x1d7ca, 0x1d7cd),
|
||||
...(0, util_1.range)(0x1d800, 0x1fffd),
|
||||
...(0, util_1.range)(0x2a6d7, 0x2f7ff),
|
||||
...(0, util_1.range)(0x2fa1e, 0x2fffd),
|
||||
...(0, util_1.range)(0x30000, 0x3fffd),
|
||||
...(0, util_1.range)(0x40000, 0x4fffd),
|
||||
...(0, util_1.range)(0x50000, 0x5fffd),
|
||||
...(0, util_1.range)(0x60000, 0x6fffd),
|
||||
...(0, util_1.range)(0x70000, 0x7fffd),
|
||||
...(0, util_1.range)(0x80000, 0x8fffd),
|
||||
...(0, util_1.range)(0x90000, 0x9fffd),
|
||||
...(0, util_1.range)(0xa0000, 0xafffd),
|
||||
...(0, util_1.range)(0xb0000, 0xbfffd),
|
||||
...(0, util_1.range)(0xc0000, 0xcfffd),
|
||||
...(0, util_1.range)(0xd0000, 0xdfffd),
|
||||
0xe0000,
|
||||
...(0, util_1.range)(0xe0002, 0xe001f),
|
||||
...(0, util_1.range)(0xe0080, 0xefffd),
|
||||
]);
|
||||
exports.commonly_mapped_to_nothing = new Set([
|
||||
0x00ad, 0x034f, 0x1806, 0x180b, 0x180c, 0x180d, 0x200b, 0x200c, 0x200d,
|
||||
0x2060, 0xfe00, 0xfe01, 0xfe02, 0xfe03, 0xfe04, 0xfe05, 0xfe06, 0xfe07,
|
||||
0xfe08, 0xfe09, 0xfe0a, 0xfe0b, 0xfe0c, 0xfe0d, 0xfe0e, 0xfe0f, 0xfeff,
|
||||
]);
|
||||
exports.non_ASCII_space_characters = new Set([
|
||||
0x00a0, 0x1680,
|
||||
0x2000, 0x2001, 0x2002,
|
||||
0x2003, 0x2004,
|
||||
0x2005, 0x2006,
|
||||
0x2007, 0x2008,
|
||||
0x2009, 0x200a,
|
||||
0x200b, 0x202f,
|
||||
0x205f, 0x3000,
|
||||
]);
|
||||
exports.prohibited_characters = new Set([
|
||||
...exports.non_ASCII_space_characters,
|
||||
...(0, util_1.range)(0, 0x001f),
|
||||
0x007f,
|
||||
...(0, util_1.range)(0x0080, 0x009f),
|
||||
0x06dd,
|
||||
0x070f,
|
||||
0x180e,
|
||||
0x200c,
|
||||
0x200d,
|
||||
0x2028,
|
||||
0x2029,
|
||||
0x2060,
|
||||
0x2061,
|
||||
0x2062,
|
||||
0x2063,
|
||||
...(0, util_1.range)(0x206a, 0x206f),
|
||||
0xfeff,
|
||||
...(0, util_1.range)(0xfff9, 0xfffc),
|
||||
...(0, util_1.range)(0x1d173, 0x1d17a),
|
||||
...(0, util_1.range)(0xe000, 0xf8ff),
|
||||
...(0, util_1.range)(0xf0000, 0xffffd),
|
||||
...(0, util_1.range)(0x100000, 0x10fffd),
|
||||
...(0, util_1.range)(0xfdd0, 0xfdef),
|
||||
...(0, util_1.range)(0xfffe, 0xffff),
|
||||
...(0, util_1.range)(0x1fffe, 0x1ffff),
|
||||
...(0, util_1.range)(0x2fffe, 0x2ffff),
|
||||
...(0, util_1.range)(0x3fffe, 0x3ffff),
|
||||
...(0, util_1.range)(0x4fffe, 0x4ffff),
|
||||
...(0, util_1.range)(0x5fffe, 0x5ffff),
|
||||
...(0, util_1.range)(0x6fffe, 0x6ffff),
|
||||
...(0, util_1.range)(0x7fffe, 0x7ffff),
|
||||
...(0, util_1.range)(0x8fffe, 0x8ffff),
|
||||
...(0, util_1.range)(0x9fffe, 0x9ffff),
|
||||
...(0, util_1.range)(0xafffe, 0xaffff),
|
||||
...(0, util_1.range)(0xbfffe, 0xbffff),
|
||||
...(0, util_1.range)(0xcfffe, 0xcffff),
|
||||
...(0, util_1.range)(0xdfffe, 0xdffff),
|
||||
...(0, util_1.range)(0xefffe, 0xeffff),
|
||||
...(0, util_1.range)(0x10fffe, 0x10ffff),
|
||||
...(0, util_1.range)(0xd800, 0xdfff),
|
||||
0xfff9,
|
||||
0xfffa,
|
||||
0xfffb,
|
||||
0xfffc,
|
||||
0xfffd,
|
||||
...(0, util_1.range)(0x2ff0, 0x2ffb),
|
||||
0x0340,
|
||||
0x0341,
|
||||
0x200e,
|
||||
0x200f,
|
||||
0x202a,
|
||||
0x202b,
|
||||
0x202c,
|
||||
0x202d,
|
||||
0x202e,
|
||||
0x206a,
|
||||
0x206b,
|
||||
0x206c,
|
||||
0x206d,
|
||||
0x206e,
|
||||
0x206f,
|
||||
0xe0001,
|
||||
...(0, util_1.range)(0xe0020, 0xe007f),
|
||||
]);
|
||||
exports.bidirectional_r_al = new Set([
|
||||
0x05be,
|
||||
0x05c0,
|
||||
0x05c3,
|
||||
...(0, util_1.range)(0x05d0, 0x05ea),
|
||||
...(0, util_1.range)(0x05f0, 0x05f4),
|
||||
0x061b,
|
||||
0x061f,
|
||||
...(0, util_1.range)(0x0621, 0x063a),
|
||||
...(0, util_1.range)(0x0640, 0x064a),
|
||||
...(0, util_1.range)(0x066d, 0x066f),
|
||||
...(0, util_1.range)(0x0671, 0x06d5),
|
||||
0x06dd,
|
||||
...(0, util_1.range)(0x06e5, 0x06e6),
|
||||
...(0, util_1.range)(0x06fa, 0x06fe),
|
||||
...(0, util_1.range)(0x0700, 0x070d),
|
||||
0x0710,
|
||||
...(0, util_1.range)(0x0712, 0x072c),
|
||||
...(0, util_1.range)(0x0780, 0x07a5),
|
||||
0x07b1,
|
||||
0x200f,
|
||||
0xfb1d,
|
||||
...(0, util_1.range)(0xfb1f, 0xfb28),
|
||||
...(0, util_1.range)(0xfb2a, 0xfb36),
|
||||
...(0, util_1.range)(0xfb38, 0xfb3c),
|
||||
0xfb3e,
|
||||
...(0, util_1.range)(0xfb40, 0xfb41),
|
||||
...(0, util_1.range)(0xfb43, 0xfb44),
|
||||
...(0, util_1.range)(0xfb46, 0xfbb1),
|
||||
...(0, util_1.range)(0xfbd3, 0xfd3d),
|
||||
...(0, util_1.range)(0xfd50, 0xfd8f),
|
||||
...(0, util_1.range)(0xfd92, 0xfdc7),
|
||||
...(0, util_1.range)(0xfdf0, 0xfdfc),
|
||||
...(0, util_1.range)(0xfe70, 0xfe74),
|
||||
...(0, util_1.range)(0xfe76, 0xfefc),
|
||||
]);
|
||||
exports.bidirectional_l = new Set([
|
||||
...(0, util_1.range)(0x0041, 0x005a),
|
||||
...(0, util_1.range)(0x0061, 0x007a),
|
||||
0x00aa,
|
||||
0x00b5,
|
||||
0x00ba,
|
||||
...(0, util_1.range)(0x00c0, 0x00d6),
|
||||
...(0, util_1.range)(0x00d8, 0x00f6),
|
||||
...(0, util_1.range)(0x00f8, 0x0220),
|
||||
...(0, util_1.range)(0x0222, 0x0233),
|
||||
...(0, util_1.range)(0x0250, 0x02ad),
|
||||
...(0, util_1.range)(0x02b0, 0x02b8),
|
||||
...(0, util_1.range)(0x02bb, 0x02c1),
|
||||
...(0, util_1.range)(0x02d0, 0x02d1),
|
||||
...(0, util_1.range)(0x02e0, 0x02e4),
|
||||
0x02ee,
|
||||
0x037a,
|
||||
0x0386,
|
||||
...(0, util_1.range)(0x0388, 0x038a),
|
||||
0x038c,
|
||||
...(0, util_1.range)(0x038e, 0x03a1),
|
||||
...(0, util_1.range)(0x03a3, 0x03ce),
|
||||
...(0, util_1.range)(0x03d0, 0x03f5),
|
||||
...(0, util_1.range)(0x0400, 0x0482),
|
||||
...(0, util_1.range)(0x048a, 0x04ce),
|
||||
...(0, util_1.range)(0x04d0, 0x04f5),
|
||||
...(0, util_1.range)(0x04f8, 0x04f9),
|
||||
...(0, util_1.range)(0x0500, 0x050f),
|
||||
...(0, util_1.range)(0x0531, 0x0556),
|
||||
...(0, util_1.range)(0x0559, 0x055f),
|
||||
...(0, util_1.range)(0x0561, 0x0587),
|
||||
0x0589,
|
||||
0x0903,
|
||||
...(0, util_1.range)(0x0905, 0x0939),
|
||||
...(0, util_1.range)(0x093d, 0x0940),
|
||||
...(0, util_1.range)(0x0949, 0x094c),
|
||||
0x0950,
|
||||
...(0, util_1.range)(0x0958, 0x0961),
|
||||
...(0, util_1.range)(0x0964, 0x0970),
|
||||
...(0, util_1.range)(0x0982, 0x0983),
|
||||
...(0, util_1.range)(0x0985, 0x098c),
|
||||
...(0, util_1.range)(0x098f, 0x0990),
|
||||
...(0, util_1.range)(0x0993, 0x09a8),
|
||||
...(0, util_1.range)(0x09aa, 0x09b0),
|
||||
0x09b2,
|
||||
...(0, util_1.range)(0x09b6, 0x09b9),
|
||||
...(0, util_1.range)(0x09be, 0x09c0),
|
||||
...(0, util_1.range)(0x09c7, 0x09c8),
|
||||
...(0, util_1.range)(0x09cb, 0x09cc),
|
||||
0x09d7,
|
||||
...(0, util_1.range)(0x09dc, 0x09dd),
|
||||
...(0, util_1.range)(0x09df, 0x09e1),
|
||||
...(0, util_1.range)(0x09e6, 0x09f1),
|
||||
...(0, util_1.range)(0x09f4, 0x09fa),
|
||||
...(0, util_1.range)(0x0a05, 0x0a0a),
|
||||
...(0, util_1.range)(0x0a0f, 0x0a10),
|
||||
...(0, util_1.range)(0x0a13, 0x0a28),
|
||||
...(0, util_1.range)(0x0a2a, 0x0a30),
|
||||
...(0, util_1.range)(0x0a32, 0x0a33),
|
||||
...(0, util_1.range)(0x0a35, 0x0a36),
|
||||
...(0, util_1.range)(0x0a38, 0x0a39),
|
||||
...(0, util_1.range)(0x0a3e, 0x0a40),
|
||||
...(0, util_1.range)(0x0a59, 0x0a5c),
|
||||
0x0a5e,
|
||||
...(0, util_1.range)(0x0a66, 0x0a6f),
|
||||
...(0, util_1.range)(0x0a72, 0x0a74),
|
||||
0x0a83,
|
||||
...(0, util_1.range)(0x0a85, 0x0a8b),
|
||||
0x0a8d,
|
||||
...(0, util_1.range)(0x0a8f, 0x0a91),
|
||||
...(0, util_1.range)(0x0a93, 0x0aa8),
|
||||
...(0, util_1.range)(0x0aaa, 0x0ab0),
|
||||
...(0, util_1.range)(0x0ab2, 0x0ab3),
|
||||
...(0, util_1.range)(0x0ab5, 0x0ab9),
|
||||
...(0, util_1.range)(0x0abd, 0x0ac0),
|
||||
0x0ac9,
|
||||
...(0, util_1.range)(0x0acb, 0x0acc),
|
||||
0x0ad0,
|
||||
0x0ae0,
|
||||
...(0, util_1.range)(0x0ae6, 0x0aef),
|
||||
...(0, util_1.range)(0x0b02, 0x0b03),
|
||||
...(0, util_1.range)(0x0b05, 0x0b0c),
|
||||
...(0, util_1.range)(0x0b0f, 0x0b10),
|
||||
...(0, util_1.range)(0x0b13, 0x0b28),
|
||||
...(0, util_1.range)(0x0b2a, 0x0b30),
|
||||
...(0, util_1.range)(0x0b32, 0x0b33),
|
||||
...(0, util_1.range)(0x0b36, 0x0b39),
|
||||
...(0, util_1.range)(0x0b3d, 0x0b3e),
|
||||
0x0b40,
|
||||
...(0, util_1.range)(0x0b47, 0x0b48),
|
||||
...(0, util_1.range)(0x0b4b, 0x0b4c),
|
||||
0x0b57,
|
||||
...(0, util_1.range)(0x0b5c, 0x0b5d),
|
||||
...(0, util_1.range)(0x0b5f, 0x0b61),
|
||||
...(0, util_1.range)(0x0b66, 0x0b70),
|
||||
0x0b83,
|
||||
...(0, util_1.range)(0x0b85, 0x0b8a),
|
||||
...(0, util_1.range)(0x0b8e, 0x0b90),
|
||||
...(0, util_1.range)(0x0b92, 0x0b95),
|
||||
...(0, util_1.range)(0x0b99, 0x0b9a),
|
||||
0x0b9c,
|
||||
...(0, util_1.range)(0x0b9e, 0x0b9f),
|
||||
...(0, util_1.range)(0x0ba3, 0x0ba4),
|
||||
...(0, util_1.range)(0x0ba8, 0x0baa),
|
||||
...(0, util_1.range)(0x0bae, 0x0bb5),
|
||||
...(0, util_1.range)(0x0bb7, 0x0bb9),
|
||||
...(0, util_1.range)(0x0bbe, 0x0bbf),
|
||||
...(0, util_1.range)(0x0bc1, 0x0bc2),
|
||||
...(0, util_1.range)(0x0bc6, 0x0bc8),
|
||||
...(0, util_1.range)(0x0bca, 0x0bcc),
|
||||
0x0bd7,
|
||||
...(0, util_1.range)(0x0be7, 0x0bf2),
|
||||
...(0, util_1.range)(0x0c01, 0x0c03),
|
||||
...(0, util_1.range)(0x0c05, 0x0c0c),
|
||||
...(0, util_1.range)(0x0c0e, 0x0c10),
|
||||
...(0, util_1.range)(0x0c12, 0x0c28),
|
||||
...(0, util_1.range)(0x0c2a, 0x0c33),
|
||||
...(0, util_1.range)(0x0c35, 0x0c39),
|
||||
...(0, util_1.range)(0x0c41, 0x0c44),
|
||||
...(0, util_1.range)(0x0c60, 0x0c61),
|
||||
...(0, util_1.range)(0x0c66, 0x0c6f),
|
||||
...(0, util_1.range)(0x0c82, 0x0c83),
|
||||
...(0, util_1.range)(0x0c85, 0x0c8c),
|
||||
...(0, util_1.range)(0x0c8e, 0x0c90),
|
||||
...(0, util_1.range)(0x0c92, 0x0ca8),
|
||||
...(0, util_1.range)(0x0caa, 0x0cb3),
|
||||
...(0, util_1.range)(0x0cb5, 0x0cb9),
|
||||
0x0cbe,
|
||||
...(0, util_1.range)(0x0cc0, 0x0cc4),
|
||||
...(0, util_1.range)(0x0cc7, 0x0cc8),
|
||||
...(0, util_1.range)(0x0cca, 0x0ccb),
|
||||
...(0, util_1.range)(0x0cd5, 0x0cd6),
|
||||
0x0cde,
|
||||
...(0, util_1.range)(0x0ce0, 0x0ce1),
|
||||
...(0, util_1.range)(0x0ce6, 0x0cef),
|
||||
...(0, util_1.range)(0x0d02, 0x0d03),
|
||||
...(0, util_1.range)(0x0d05, 0x0d0c),
|
||||
...(0, util_1.range)(0x0d0e, 0x0d10),
|
||||
...(0, util_1.range)(0x0d12, 0x0d28),
|
||||
...(0, util_1.range)(0x0d2a, 0x0d39),
|
||||
...(0, util_1.range)(0x0d3e, 0x0d40),
|
||||
...(0, util_1.range)(0x0d46, 0x0d48),
|
||||
...(0, util_1.range)(0x0d4a, 0x0d4c),
|
||||
0x0d57,
|
||||
...(0, util_1.range)(0x0d60, 0x0d61),
|
||||
...(0, util_1.range)(0x0d66, 0x0d6f),
|
||||
...(0, util_1.range)(0x0d82, 0x0d83),
|
||||
...(0, util_1.range)(0x0d85, 0x0d96),
|
||||
...(0, util_1.range)(0x0d9a, 0x0db1),
|
||||
...(0, util_1.range)(0x0db3, 0x0dbb),
|
||||
0x0dbd,
|
||||
...(0, util_1.range)(0x0dc0, 0x0dc6),
|
||||
...(0, util_1.range)(0x0dcf, 0x0dd1),
|
||||
...(0, util_1.range)(0x0dd8, 0x0ddf),
|
||||
...(0, util_1.range)(0x0df2, 0x0df4),
|
||||
...(0, util_1.range)(0x0e01, 0x0e30),
|
||||
...(0, util_1.range)(0x0e32, 0x0e33),
|
||||
...(0, util_1.range)(0x0e40, 0x0e46),
|
||||
...(0, util_1.range)(0x0e4f, 0x0e5b),
|
||||
...(0, util_1.range)(0x0e81, 0x0e82),
|
||||
0x0e84,
|
||||
...(0, util_1.range)(0x0e87, 0x0e88),
|
||||
0x0e8a,
|
||||
0x0e8d,
|
||||
...(0, util_1.range)(0x0e94, 0x0e97),
|
||||
...(0, util_1.range)(0x0e99, 0x0e9f),
|
||||
...(0, util_1.range)(0x0ea1, 0x0ea3),
|
||||
0x0ea5,
|
||||
0x0ea7,
|
||||
...(0, util_1.range)(0x0eaa, 0x0eab),
|
||||
...(0, util_1.range)(0x0ead, 0x0eb0),
|
||||
...(0, util_1.range)(0x0eb2, 0x0eb3),
|
||||
0x0ebd,
|
||||
...(0, util_1.range)(0x0ec0, 0x0ec4),
|
||||
0x0ec6,
|
||||
...(0, util_1.range)(0x0ed0, 0x0ed9),
|
||||
...(0, util_1.range)(0x0edc, 0x0edd),
|
||||
...(0, util_1.range)(0x0f00, 0x0f17),
|
||||
...(0, util_1.range)(0x0f1a, 0x0f34),
|
||||
0x0f36,
|
||||
0x0f38,
|
||||
...(0, util_1.range)(0x0f3e, 0x0f47),
|
||||
...(0, util_1.range)(0x0f49, 0x0f6a),
|
||||
0x0f7f,
|
||||
0x0f85,
|
||||
...(0, util_1.range)(0x0f88, 0x0f8b),
|
||||
...(0, util_1.range)(0x0fbe, 0x0fc5),
|
||||
...(0, util_1.range)(0x0fc7, 0x0fcc),
|
||||
0x0fcf,
|
||||
...(0, util_1.range)(0x1000, 0x1021),
|
||||
...(0, util_1.range)(0x1023, 0x1027),
|
||||
...(0, util_1.range)(0x1029, 0x102a),
|
||||
0x102c,
|
||||
0x1031,
|
||||
0x1038,
|
||||
...(0, util_1.range)(0x1040, 0x1057),
|
||||
...(0, util_1.range)(0x10a0, 0x10c5),
|
||||
...(0, util_1.range)(0x10d0, 0x10f8),
|
||||
0x10fb,
|
||||
...(0, util_1.range)(0x1100, 0x1159),
|
||||
...(0, util_1.range)(0x115f, 0x11a2),
|
||||
...(0, util_1.range)(0x11a8, 0x11f9),
|
||||
...(0, util_1.range)(0x1200, 0x1206),
|
||||
...(0, util_1.range)(0x1208, 0x1246),
|
||||
0x1248,
|
||||
...(0, util_1.range)(0x124a, 0x124d),
|
||||
...(0, util_1.range)(0x1250, 0x1256),
|
||||
0x1258,
|
||||
...(0, util_1.range)(0x125a, 0x125d),
|
||||
...(0, util_1.range)(0x1260, 0x1286),
|
||||
0x1288,
|
||||
...(0, util_1.range)(0x128a, 0x128d),
|
||||
...(0, util_1.range)(0x1290, 0x12ae),
|
||||
0x12b0,
|
||||
...(0, util_1.range)(0x12b2, 0x12b5),
|
||||
...(0, util_1.range)(0x12b8, 0x12be),
|
||||
0x12c0,
|
||||
...(0, util_1.range)(0x12c2, 0x12c5),
|
||||
...(0, util_1.range)(0x12c8, 0x12ce),
|
||||
...(0, util_1.range)(0x12d0, 0x12d6),
|
||||
...(0, util_1.range)(0x12d8, 0x12ee),
|
||||
...(0, util_1.range)(0x12f0, 0x130e),
|
||||
0x1310,
|
||||
...(0, util_1.range)(0x1312, 0x1315),
|
||||
...(0, util_1.range)(0x1318, 0x131e),
|
||||
...(0, util_1.range)(0x1320, 0x1346),
|
||||
...(0, util_1.range)(0x1348, 0x135a),
|
||||
...(0, util_1.range)(0x1361, 0x137c),
|
||||
...(0, util_1.range)(0x13a0, 0x13f4),
|
||||
...(0, util_1.range)(0x1401, 0x1676),
|
||||
...(0, util_1.range)(0x1681, 0x169a),
|
||||
...(0, util_1.range)(0x16a0, 0x16f0),
|
||||
...(0, util_1.range)(0x1700, 0x170c),
|
||||
...(0, util_1.range)(0x170e, 0x1711),
|
||||
...(0, util_1.range)(0x1720, 0x1731),
|
||||
...(0, util_1.range)(0x1735, 0x1736),
|
||||
...(0, util_1.range)(0x1740, 0x1751),
|
||||
...(0, util_1.range)(0x1760, 0x176c),
|
||||
...(0, util_1.range)(0x176e, 0x1770),
|
||||
...(0, util_1.range)(0x1780, 0x17b6),
|
||||
...(0, util_1.range)(0x17be, 0x17c5),
|
||||
...(0, util_1.range)(0x17c7, 0x17c8),
|
||||
...(0, util_1.range)(0x17d4, 0x17da),
|
||||
0x17dc,
|
||||
...(0, util_1.range)(0x17e0, 0x17e9),
|
||||
...(0, util_1.range)(0x1810, 0x1819),
|
||||
...(0, util_1.range)(0x1820, 0x1877),
|
||||
...(0, util_1.range)(0x1880, 0x18a8),
|
||||
...(0, util_1.range)(0x1e00, 0x1e9b),
|
||||
...(0, util_1.range)(0x1ea0, 0x1ef9),
|
||||
...(0, util_1.range)(0x1f00, 0x1f15),
|
||||
...(0, util_1.range)(0x1f18, 0x1f1d),
|
||||
...(0, util_1.range)(0x1f20, 0x1f45),
|
||||
...(0, util_1.range)(0x1f48, 0x1f4d),
|
||||
...(0, util_1.range)(0x1f50, 0x1f57),
|
||||
0x1f59,
|
||||
0x1f5b,
|
||||
0x1f5d,
|
||||
...(0, util_1.range)(0x1f5f, 0x1f7d),
|
||||
...(0, util_1.range)(0x1f80, 0x1fb4),
|
||||
...(0, util_1.range)(0x1fb6, 0x1fbc),
|
||||
0x1fbe,
|
||||
...(0, util_1.range)(0x1fc2, 0x1fc4),
|
||||
...(0, util_1.range)(0x1fc6, 0x1fcc),
|
||||
...(0, util_1.range)(0x1fd0, 0x1fd3),
|
||||
...(0, util_1.range)(0x1fd6, 0x1fdb),
|
||||
...(0, util_1.range)(0x1fe0, 0x1fec),
|
||||
...(0, util_1.range)(0x1ff2, 0x1ff4),
|
||||
...(0, util_1.range)(0x1ff6, 0x1ffc),
|
||||
0x200e,
|
||||
0x2071,
|
||||
0x207f,
|
||||
0x2102,
|
||||
0x2107,
|
||||
...(0, util_1.range)(0x210a, 0x2113),
|
||||
0x2115,
|
||||
...(0, util_1.range)(0x2119, 0x211d),
|
||||
0x2124,
|
||||
0x2126,
|
||||
0x2128,
|
||||
...(0, util_1.range)(0x212a, 0x212d),
|
||||
...(0, util_1.range)(0x212f, 0x2131),
|
||||
...(0, util_1.range)(0x2133, 0x2139),
|
||||
...(0, util_1.range)(0x213d, 0x213f),
|
||||
...(0, util_1.range)(0x2145, 0x2149),
|
||||
...(0, util_1.range)(0x2160, 0x2183),
|
||||
...(0, util_1.range)(0x2336, 0x237a),
|
||||
0x2395,
|
||||
...(0, util_1.range)(0x249c, 0x24e9),
|
||||
...(0, util_1.range)(0x3005, 0x3007),
|
||||
...(0, util_1.range)(0x3021, 0x3029),
|
||||
...(0, util_1.range)(0x3031, 0x3035),
|
||||
...(0, util_1.range)(0x3038, 0x303c),
|
||||
...(0, util_1.range)(0x3041, 0x3096),
|
||||
...(0, util_1.range)(0x309d, 0x309f),
|
||||
...(0, util_1.range)(0x30a1, 0x30fa),
|
||||
...(0, util_1.range)(0x30fc, 0x30ff),
|
||||
...(0, util_1.range)(0x3105, 0x312c),
|
||||
...(0, util_1.range)(0x3131, 0x318e),
|
||||
...(0, util_1.range)(0x3190, 0x31b7),
|
||||
...(0, util_1.range)(0x31f0, 0x321c),
|
||||
...(0, util_1.range)(0x3220, 0x3243),
|
||||
...(0, util_1.range)(0x3260, 0x327b),
|
||||
...(0, util_1.range)(0x327f, 0x32b0),
|
||||
...(0, util_1.range)(0x32c0, 0x32cb),
|
||||
...(0, util_1.range)(0x32d0, 0x32fe),
|
||||
...(0, util_1.range)(0x3300, 0x3376),
|
||||
...(0, util_1.range)(0x337b, 0x33dd),
|
||||
...(0, util_1.range)(0x33e0, 0x33fe),
|
||||
...(0, util_1.range)(0x3400, 0x4db5),
|
||||
...(0, util_1.range)(0x4e00, 0x9fa5),
|
||||
...(0, util_1.range)(0xa000, 0xa48c),
|
||||
...(0, util_1.range)(0xac00, 0xd7a3),
|
||||
...(0, util_1.range)(0xd800, 0xfa2d),
|
||||
...(0, util_1.range)(0xfa30, 0xfa6a),
|
||||
...(0, util_1.range)(0xfb00, 0xfb06),
|
||||
...(0, util_1.range)(0xfb13, 0xfb17),
|
||||
...(0, util_1.range)(0xff21, 0xff3a),
|
||||
...(0, util_1.range)(0xff41, 0xff5a),
|
||||
...(0, util_1.range)(0xff66, 0xffbe),
|
||||
...(0, util_1.range)(0xffc2, 0xffc7),
|
||||
...(0, util_1.range)(0xffca, 0xffcf),
|
||||
...(0, util_1.range)(0xffd2, 0xffd7),
|
||||
...(0, util_1.range)(0xffda, 0xffdc),
|
||||
...(0, util_1.range)(0x10300, 0x1031e),
|
||||
...(0, util_1.range)(0x10320, 0x10323),
|
||||
...(0, util_1.range)(0x10330, 0x1034a),
|
||||
...(0, util_1.range)(0x10400, 0x10425),
|
||||
...(0, util_1.range)(0x10428, 0x1044d),
|
||||
...(0, util_1.range)(0x1d000, 0x1d0f5),
|
||||
...(0, util_1.range)(0x1d100, 0x1d126),
|
||||
...(0, util_1.range)(0x1d12a, 0x1d166),
|
||||
...(0, util_1.range)(0x1d16a, 0x1d172),
|
||||
...(0, util_1.range)(0x1d183, 0x1d184),
|
||||
...(0, util_1.range)(0x1d18c, 0x1d1a9),
|
||||
...(0, util_1.range)(0x1d1ae, 0x1d1dd),
|
||||
...(0, util_1.range)(0x1d400, 0x1d454),
|
||||
...(0, util_1.range)(0x1d456, 0x1d49c),
|
||||
...(0, util_1.range)(0x1d49e, 0x1d49f),
|
||||
0x1d4a2,
|
||||
...(0, util_1.range)(0x1d4a5, 0x1d4a6),
|
||||
...(0, util_1.range)(0x1d4a9, 0x1d4ac),
|
||||
...(0, util_1.range)(0x1d4ae, 0x1d4b9),
|
||||
0x1d4bb,
|
||||
...(0, util_1.range)(0x1d4bd, 0x1d4c0),
|
||||
...(0, util_1.range)(0x1d4c2, 0x1d4c3),
|
||||
...(0, util_1.range)(0x1d4c5, 0x1d505),
|
||||
...(0, util_1.range)(0x1d507, 0x1d50a),
|
||||
...(0, util_1.range)(0x1d50d, 0x1d514),
|
||||
...(0, util_1.range)(0x1d516, 0x1d51c),
|
||||
...(0, util_1.range)(0x1d51e, 0x1d539),
|
||||
...(0, util_1.range)(0x1d53b, 0x1d53e),
|
||||
...(0, util_1.range)(0x1d540, 0x1d544),
|
||||
0x1d546,
|
||||
...(0, util_1.range)(0x1d54a, 0x1d550),
|
||||
...(0, util_1.range)(0x1d552, 0x1d6a3),
|
||||
...(0, util_1.range)(0x1d6a8, 0x1d7c9),
|
||||
...(0, util_1.range)(0x20000, 0x2a6d6),
|
||||
...(0, util_1.range)(0x2f800, 0x2fa1d),
|
||||
...(0, util_1.range)(0xf0000, 0xffffd),
|
||||
...(0, util_1.range)(0x100000, 0x10fffd),
|
||||
]);
|
||||
//# sourceMappingURL=code-points-src.js.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/code-points-src.js.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/code-points-src.js.map
generated
vendored
File diff suppressed because one or more lines are too long
2
node_modules/@mongodb-js/saslprep/dist/generate-code-points.d.ts
generated
vendored
2
node_modules/@mongodb-js/saslprep/dist/generate-code-points.d.ts
generated
vendored
|
|
@ -1,2 +0,0 @@
|
|||
export {};
|
||||
//# sourceMappingURL=generate-code-points.d.ts.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/generate-code-points.d.ts.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/generate-code-points.d.ts.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"generate-code-points.d.ts","sourceRoot":"","sources":["../src/generate-code-points.ts"],"names":[],"mappings":""}
|
||||
83
node_modules/@mongodb-js/saslprep/dist/generate-code-points.js
generated
vendored
83
node_modules/@mongodb-js/saslprep/dist/generate-code-points.js
generated
vendored
|
|
@ -1,83 +0,0 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const zlib_1 = require("zlib");
|
||||
const sparse_bitfield_1 = __importDefault(require("sparse-bitfield"));
|
||||
const codePoints = __importStar(require("./code-points-src"));
|
||||
const fs_1 = require("fs");
|
||||
const prettier = __importStar(require("prettier"));
|
||||
const unassigned_code_points = (0, sparse_bitfield_1.default)();
|
||||
const commonly_mapped_to_nothing = (0, sparse_bitfield_1.default)();
|
||||
const non_ascii_space_characters = (0, sparse_bitfield_1.default)();
|
||||
const prohibited_characters = (0, sparse_bitfield_1.default)();
|
||||
const bidirectional_r_al = (0, sparse_bitfield_1.default)();
|
||||
const bidirectional_l = (0, sparse_bitfield_1.default)();
|
||||
function traverse(bits, src) {
|
||||
for (const code of src.keys()) {
|
||||
bits.set(code, true);
|
||||
}
|
||||
const buffer = bits.toBuffer();
|
||||
return Buffer.concat([createSize(buffer), buffer]);
|
||||
}
|
||||
function createSize(buffer) {
|
||||
const buf = Buffer.alloc(4);
|
||||
buf.writeUInt32BE(buffer.length);
|
||||
return buf;
|
||||
}
|
||||
const memory = [];
|
||||
memory.push(traverse(unassigned_code_points, codePoints.unassigned_code_points), traverse(commonly_mapped_to_nothing, codePoints.commonly_mapped_to_nothing), traverse(non_ascii_space_characters, codePoints.non_ASCII_space_characters), traverse(prohibited_characters, codePoints.prohibited_characters), traverse(bidirectional_r_al, codePoints.bidirectional_r_al), traverse(bidirectional_l, codePoints.bidirectional_l));
|
||||
async function writeCodepoints() {
|
||||
const config = await prettier.resolveConfig(__dirname);
|
||||
const formatOptions = { ...config, parser: 'typescript' };
|
||||
function write(stream, chunk) {
|
||||
return new Promise((resolve) => stream.write(chunk, () => resolve()));
|
||||
}
|
||||
await write((0, fs_1.createWriteStream)(process.argv[2]), await prettier.format(`import { gunzipSync } from 'zlib';
|
||||
|
||||
export default gunzipSync(
|
||||
Buffer.from(
|
||||
'${(0, zlib_1.gzipSync)(Buffer.concat(memory), { level: 9 }).toString('base64')}',
|
||||
'base64'
|
||||
)
|
||||
);
|
||||
`, formatOptions));
|
||||
const fsStreamUncompressedData = (0, fs_1.createWriteStream)(process.argv[3]);
|
||||
await write(fsStreamUncompressedData, await prettier.format(`const data = Buffer.from('${Buffer.concat(memory).toString('base64')}', 'base64');\nexport default data;\n`, formatOptions));
|
||||
}
|
||||
writeCodepoints().catch((error) => console.error('error occurred generating saslprep codepoint data', { error }));
|
||||
//# sourceMappingURL=generate-code-points.js.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/generate-code-points.js.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/generate-code-points.js.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"generate-code-points.js","sourceRoot":"","sources":["../src/generate-code-points.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAgC;AAChC,sEAAuC;AACvC,8DAAgD;AAChD,2BAAuC;AACvC,mDAAqC;AAGrC,MAAM,sBAAsB,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAC1C,MAAM,0BAA0B,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAC9C,MAAM,0BAA0B,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAC9C,MAAM,qBAAqB,GAAG,IAAA,yBAAQ,GAAE,CAAC;AACzC,MAAM,kBAAkB,GAAG,IAAA,yBAAQ,GAAE,CAAC;AACtC,MAAM,eAAe,GAAG,IAAA,yBAAQ,GAAE,CAAC;AAMnC,SAAS,QAAQ,CAAC,IAA+B,EAAE,GAAgB;IACjE,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC9B,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,UAAU,CAAC,MAAc;IAChC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5B,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,MAAM,GAAa,EAAE,CAAC;AAE5B,MAAM,CAAC,IAAI,CACT,QAAQ,CAAC,sBAAsB,EAAE,UAAU,CAAC,sBAAsB,CAAC,EACnE,QAAQ,CAAC,0BAA0B,EAAE,UAAU,CAAC,0BAA0B,CAAC,EAC3E,QAAQ,CAAC,0BAA0B,EAAE,UAAU,CAAC,0BAA0B,CAAC,EAC3E,QAAQ,CAAC,qBAAqB,EAAE,UAAU,CAAC,qBAAqB,CAAC,EACjE,QAAQ,CAAC,kBAAkB,EAAE,UAAU,CAAC,kBAAkB,CAAC,EAC3D,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC,eAAe,CAAC,CACtD,CAAC;AAEF,KAAK,UAAU,eAAe;IAC5B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,MAAM,aAAa,GAAG,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IAE1D,SAAS,KAAK,CAAC,MAAgB,EAAE,KAAa;QAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;IACD,MAAM,KAAK,CACT,IAAA,sBAAiB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAClC,MAAM,QAAQ,CAAC,MAAM,CACnB;;;;SAIG,IAAA,eAAQ,EAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;;;;GAItE,EACG,aAAa,CACd,CACF,CAAC;IAEF,MAAM,wBAAwB,GAAG,IAAA,sBAAiB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpE,MAAM,KAAK,CACT,wBAAwB,EACxB,MAAM,QAAQ,CAAC,MAAM,CACnB,6BAA6B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CACzD,QAAQ,CACT,uCAAuC,EACxC,aAAa,CACd,CACF,CAAC;AACJ,CAAC;AAED,eAAe,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAEhC,OAAO,CAAC,KAAK,CAAC,mDAAmD,EAAE,EAAE,KAAK,EAAE,CAAC,CAC9E,CAAC"}
|
||||
11
node_modules/@mongodb-js/saslprep/dist/index.d.ts
generated
vendored
11
node_modules/@mongodb-js/saslprep/dist/index.d.ts
generated
vendored
|
|
@ -1,11 +0,0 @@
|
|||
import type { createMemoryCodePoints } from './memory-code-points';
|
||||
declare function saslprep({ unassigned_code_points, commonly_mapped_to_nothing, non_ASCII_space_characters, prohibited_characters, bidirectional_r_al, bidirectional_l, }: ReturnType<typeof createMemoryCodePoints>, input: string, opts?: {
|
||||
allowUnassigned?: boolean;
|
||||
}): string;
|
||||
declare namespace saslprep {
|
||||
export var saslprep: typeof import(".");
|
||||
var _a: typeof import(".");
|
||||
export { _a as default };
|
||||
}
|
||||
export = saslprep;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/index.d.ts.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/index.d.ts.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAsCnE,iBAAS,QAAQ,CACf,EACE,sBAAsB,EACtB,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,GAChB,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,EAC5C,KAAK,EAAE,MAAM,EACb,IAAI,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAO,GACvC,MAAM,CAqGR;kBAhHQ,QAAQ;;;;;AAoHjB,SAAS,QAAQ,CAAC"}
|
||||
65
node_modules/@mongodb-js/saslprep/dist/index.js
generated
vendored
65
node_modules/@mongodb-js/saslprep/dist/index.js
generated
vendored
|
|
@ -1,65 +0,0 @@
|
|||
"use strict";
|
||||
const getCodePoint = (character) => character.codePointAt(0);
|
||||
const first = (x) => x[0];
|
||||
const last = (x) => x[x.length - 1];
|
||||
function toCodePoints(input) {
|
||||
const codepoints = [];
|
||||
const size = input.length;
|
||||
for (let i = 0; i < size; i += 1) {
|
||||
const before = input.charCodeAt(i);
|
||||
if (before >= 0xd800 && before <= 0xdbff && size > i + 1) {
|
||||
const next = input.charCodeAt(i + 1);
|
||||
if (next >= 0xdc00 && next <= 0xdfff) {
|
||||
codepoints.push((before - 0xd800) * 0x400 + next - 0xdc00 + 0x10000);
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
codepoints.push(before);
|
||||
}
|
||||
return codepoints;
|
||||
}
|
||||
function saslprep({ unassigned_code_points, commonly_mapped_to_nothing, non_ASCII_space_characters, prohibited_characters, bidirectional_r_al, bidirectional_l, }, input, opts = {}) {
|
||||
const mapping2space = non_ASCII_space_characters;
|
||||
const mapping2nothing = commonly_mapped_to_nothing;
|
||||
if (typeof input !== 'string') {
|
||||
throw new TypeError('Expected string.');
|
||||
}
|
||||
if (input.length === 0) {
|
||||
return '';
|
||||
}
|
||||
const mapped_input = toCodePoints(input)
|
||||
.map((character) => (mapping2space.get(character) ? 0x20 : character))
|
||||
.filter((character) => !mapping2nothing.get(character));
|
||||
const normalized_input = String.fromCodePoint
|
||||
.apply(null, mapped_input)
|
||||
.normalize('NFKC');
|
||||
const normalized_map = toCodePoints(normalized_input);
|
||||
const hasProhibited = normalized_map.some((character) => prohibited_characters.get(character));
|
||||
if (hasProhibited) {
|
||||
throw new Error('Prohibited character, see https://tools.ietf.org/html/rfc4013#section-2.3');
|
||||
}
|
||||
if (opts.allowUnassigned !== true) {
|
||||
const hasUnassigned = normalized_map.some((character) => unassigned_code_points.get(character));
|
||||
if (hasUnassigned) {
|
||||
throw new Error('Unassigned code point, see https://tools.ietf.org/html/rfc4013#section-2.5');
|
||||
}
|
||||
}
|
||||
const hasBidiRAL = normalized_map.some((character) => bidirectional_r_al.get(character));
|
||||
const hasBidiL = normalized_map.some((character) => bidirectional_l.get(character));
|
||||
if (hasBidiRAL && hasBidiL) {
|
||||
throw new Error('String must not contain RandALCat and LCat at the same time,' +
|
||||
' see https://tools.ietf.org/html/rfc3454#section-6');
|
||||
}
|
||||
const isFirstBidiRAL = bidirectional_r_al.get(getCodePoint(first(normalized_input)));
|
||||
const isLastBidiRAL = bidirectional_r_al.get(getCodePoint(last(normalized_input)));
|
||||
if (hasBidiRAL && !(isFirstBidiRAL && isLastBidiRAL)) {
|
||||
throw new Error('Bidirectional RandALCat character must be the first and the last' +
|
||||
' character of the string, see https://tools.ietf.org/html/rfc3454#section-6');
|
||||
}
|
||||
return normalized_input;
|
||||
}
|
||||
saslprep.saslprep = saslprep;
|
||||
saslprep.default = saslprep;
|
||||
module.exports = saslprep;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/index.js.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/index.js.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAGA,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;AACrE,MAAM,KAAK,GAAG,CAA2B,CAAI,EAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,MAAM,IAAI,GAAG,CAA2B,CAAI,EAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAO5E,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;IAE1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAEnC,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAErC,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACrC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;gBACrE,CAAC,IAAI,CAAC,CAAC;gBACP,SAAS;YACX,CAAC;QACH,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAKD,SAAS,QAAQ,CACf,EACE,sBAAsB,EACtB,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,GAC2B,EAC5C,KAAa,EACb,OAAsC,EAAE;IAQxC,MAAM,aAAa,GAAG,0BAA0B,CAAC;IAMjD,MAAM,eAAe,GAAG,0BAA0B,CAAC;IAEnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IAGD,MAAM,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC;SAErC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;SAErE,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAG1D,MAAM,gBAAgB,GAAG,MAAM,CAAC,aAAa;SAC1C,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC;SACzB,SAAS,CAAC,MAAM,CAAC,CAAC;IAErB,MAAM,cAAc,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC;IAGtD,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACtD,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,CACrC,CAAC;IAEF,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IAGD,IAAI,IAAI,CAAC,eAAe,KAAK,IAAI,EAAE,CAAC;QAClC,MAAM,aAAa,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACtD,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,CACtC,CAAC;QAEF,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;QACJ,CAAC;IACH,CAAC;IAID,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACnD,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,CAClC,CAAC;IAEF,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACjD,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAC/B,CAAC;IAIF,IAAI,UAAU,IAAI,QAAQ,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,8DAA8D;YAC5D,oDAAoD,CACvD,CAAC;IACJ,CAAC;IAQD,MAAM,cAAc,GAAG,kBAAkB,CAAC,GAAG,CAC3C,YAAY,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAE,CACvC,CAAC;IACF,MAAM,aAAa,GAAG,kBAAkB,CAAC,GAAG,CAC1C,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAE,CACtC,CAAC;IAEF,IAAI,UAAU,IAAI,CAAC,CAAC,cAAc,IAAI,aAAa,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACb,kEAAkE;YAChE,6EAA6E,CAChF,CAAC;IACJ,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC;AAC5B,iBAAS,QAAQ,CAAC"}
|
||||
10
node_modules/@mongodb-js/saslprep/dist/memory-code-points.d.ts
generated
vendored
10
node_modules/@mongodb-js/saslprep/dist/memory-code-points.d.ts
generated
vendored
|
|
@ -1,10 +0,0 @@
|
|||
import bitfield from 'sparse-bitfield';
|
||||
export declare function createMemoryCodePoints(data: Buffer): {
|
||||
unassigned_code_points: bitfield.BitFieldInstance;
|
||||
commonly_mapped_to_nothing: bitfield.BitFieldInstance;
|
||||
non_ASCII_space_characters: bitfield.BitFieldInstance;
|
||||
prohibited_characters: bitfield.BitFieldInstance;
|
||||
bidirectional_r_al: bitfield.BitFieldInstance;
|
||||
bidirectional_l: bitfield.BitFieldInstance;
|
||||
};
|
||||
//# sourceMappingURL=memory-code-points.d.ts.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/memory-code-points.d.ts.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/memory-code-points.d.ts.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"memory-code-points.d.ts","sourceRoot":"","sources":["../src/memory-code-points.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAEvC,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM;;;;;;;EA+BlD"}
|
||||
32
node_modules/@mongodb-js/saslprep/dist/memory-code-points.js
generated
vendored
32
node_modules/@mongodb-js/saslprep/dist/memory-code-points.js
generated
vendored
|
|
@ -1,32 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createMemoryCodePoints = createMemoryCodePoints;
|
||||
const sparse_bitfield_1 = __importDefault(require("sparse-bitfield"));
|
||||
function createMemoryCodePoints(data) {
|
||||
let offset = 0;
|
||||
function read() {
|
||||
const size = data.readUInt32BE(offset);
|
||||
offset += 4;
|
||||
const codepoints = data.slice(offset, offset + size);
|
||||
offset += size;
|
||||
return (0, sparse_bitfield_1.default)({ buffer: codepoints });
|
||||
}
|
||||
const unassigned_code_points = read();
|
||||
const commonly_mapped_to_nothing = read();
|
||||
const non_ASCII_space_characters = read();
|
||||
const prohibited_characters = read();
|
||||
const bidirectional_r_al = read();
|
||||
const bidirectional_l = read();
|
||||
return {
|
||||
unassigned_code_points,
|
||||
commonly_mapped_to_nothing,
|
||||
non_ASCII_space_characters,
|
||||
prohibited_characters,
|
||||
bidirectional_r_al,
|
||||
bidirectional_l,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=memory-code-points.js.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/memory-code-points.js.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/memory-code-points.js.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"memory-code-points.js","sourceRoot":"","sources":["../src/memory-code-points.ts"],"names":[],"mappings":";;;;;AAEA,wDA+BC;AAjCD,sEAAuC;AAEvC,SAAgB,sBAAsB,CAAC,IAAY;IACjD,IAAI,MAAM,GAAG,CAAC,CAAC;IAKf,SAAS,IAAI;QACX,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,IAAI,CAAC,CAAC;QAEZ,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;QACrD,MAAM,IAAI,IAAI,CAAC;QAEf,OAAO,IAAA,yBAAQ,EAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,sBAAsB,GAAG,IAAI,EAAE,CAAC;IACtC,MAAM,0BAA0B,GAAG,IAAI,EAAE,CAAC;IAC1C,MAAM,0BAA0B,GAAG,IAAI,EAAE,CAAC;IAC1C,MAAM,qBAAqB,GAAG,IAAI,EAAE,CAAC;IACrC,MAAM,kBAAkB,GAAG,IAAI,EAAE,CAAC;IAClC,MAAM,eAAe,GAAG,IAAI,EAAE,CAAC;IAE/B,OAAO;QACL,sBAAsB;QACtB,0BAA0B;QAC1B,0BAA0B;QAC1B,qBAAqB;QACrB,kBAAkB;QAClB,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
||||
10
node_modules/@mongodb-js/saslprep/dist/node.d.ts
generated
vendored
10
node_modules/@mongodb-js/saslprep/dist/node.d.ts
generated
vendored
|
|
@ -1,10 +0,0 @@
|
|||
declare function saslprep(input: string, opts?: {
|
||||
allowUnassigned?: boolean;
|
||||
}): string;
|
||||
declare namespace saslprep {
|
||||
export var saslprep: typeof import("./node");
|
||||
var _a: typeof import("./node");
|
||||
export { _a as default };
|
||||
}
|
||||
export = saslprep;
|
||||
//# sourceMappingURL=node.d.ts.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/node.d.ts.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/node.d.ts.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAMA,iBAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAE7E;kBAFQ,QAAQ;;;;;AAOjB,SAAS,QAAQ,CAAC"}
|
||||
15
node_modules/@mongodb-js/saslprep/dist/node.js
generated
vendored
15
node_modules/@mongodb-js/saslprep/dist/node.js
generated
vendored
|
|
@ -1,15 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
const index_1 = __importDefault(require("./index"));
|
||||
const memory_code_points_1 = require("./memory-code-points");
|
||||
const code_points_data_1 = __importDefault(require("./code-points-data"));
|
||||
const codePoints = (0, memory_code_points_1.createMemoryCodePoints)(code_points_data_1.default);
|
||||
function saslprep(input, opts) {
|
||||
return (0, index_1.default)(codePoints, input, opts);
|
||||
}
|
||||
saslprep.saslprep = saslprep;
|
||||
saslprep.default = saslprep;
|
||||
module.exports = saslprep;
|
||||
//# sourceMappingURL=node.js.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/node.js.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/node.js.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";;;;AAAA,oDAAgC;AAChC,6DAA8D;AAC9D,0EAAsC;AAEtC,MAAM,UAAU,GAAG,IAAA,2CAAsB,EAAC,0BAAI,CAAC,CAAC;AAEhD,SAAS,QAAQ,CAAC,KAAa,EAAE,IAAoC;IACnE,OAAO,IAAA,eAAS,EAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC;AAE5B,iBAAS,QAAQ,CAAC"}
|
||||
2
node_modules/@mongodb-js/saslprep/dist/util.d.ts
generated
vendored
2
node_modules/@mongodb-js/saslprep/dist/util.d.ts
generated
vendored
|
|
@ -1,2 +0,0 @@
|
|||
export declare function range(from: number, to: number): number[];
|
||||
//# sourceMappingURL=util.d.ts.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/util.d.ts.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/util.d.ts.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAGA,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxD"}
|
||||
11
node_modules/@mongodb-js/saslprep/dist/util.js
generated
vendored
11
node_modules/@mongodb-js/saslprep/dist/util.js
generated
vendored
|
|
@ -1,11 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.range = range;
|
||||
function range(from, to) {
|
||||
const list = new Array(to - from + 1);
|
||||
for (let i = 0; i < list.length; i += 1) {
|
||||
list[i] = from + i;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
//# sourceMappingURL=util.js.map
|
||||
1
node_modules/@mongodb-js/saslprep/dist/util.js.map
generated
vendored
1
node_modules/@mongodb-js/saslprep/dist/util.js.map
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAGA,sBAQC;AARD,SAAgB,KAAK,CAAC,IAAY,EAAE,EAAU;IAE5C,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;IAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
||||
87
node_modules/@mongodb-js/saslprep/package.json
generated
vendored
87
node_modules/@mongodb-js/saslprep/package.json
generated
vendored
|
|
@ -1,87 +0,0 @@
|
|||
{
|
||||
"name": "@mongodb-js/saslprep",
|
||||
"description": "SASLprep: Stringprep Profile for User Names and Passwords, rfc4013",
|
||||
"keywords": [
|
||||
"sasl",
|
||||
"saslprep",
|
||||
"stringprep",
|
||||
"rfc4013",
|
||||
"4013"
|
||||
],
|
||||
"author": "Dmitry Tsvettsikh <me@reklatsmasters.com>",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "dist/node.js",
|
||||
"bugs": {
|
||||
"url": "https://jira.mongodb.org/projects/COMPASS/issues",
|
||||
"email": "compass@mongodb.com"
|
||||
},
|
||||
"homepage": "https://github.com/mongodb-js/devtools-shared/tree/main/packages/saslprep",
|
||||
"version": "1.3.2",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mongodb-js/devtools-shared.git"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"browser": {
|
||||
"types": "./dist/browser.d.ts",
|
||||
"default": "./dist/browser.js"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/node.d.ts",
|
||||
"default": "./dist/.esm-wrapper.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/node.d.ts",
|
||||
"default": "./dist/node.js"
|
||||
}
|
||||
},
|
||||
"types": "./dist/node.d.ts",
|
||||
"scripts": {
|
||||
"gen-code-points": "ts-node src/generate-code-points.ts src/code-points-data.ts src/code-points-data-browser.ts",
|
||||
"bootstrap": "npm run compile",
|
||||
"prepublishOnly": "npm run compile",
|
||||
"compile": "npm run gen-code-points && tsc -p tsconfig.json && gen-esm-wrapper . ./dist/.esm-wrapper.mjs",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"eslint": "eslint",
|
||||
"prettier": "prettier",
|
||||
"lint": "npm run eslint . && npm run prettier -- --check .",
|
||||
"depcheck": "depcheck",
|
||||
"check": "npm run typecheck && npm run lint && npm run depcheck",
|
||||
"check-ci": "npm run check",
|
||||
"test": "mocha",
|
||||
"test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
|
||||
"test-watch": "npm run test -- --watch",
|
||||
"test-ci": "npm run test-cov",
|
||||
"reformat": "npm run prettier -- --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"sparse-bitfield": "^3.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mongodb-js/eslint-config-devtools": "0.9.12",
|
||||
"@mongodb-js/mocha-config-devtools": "^1.0.5",
|
||||
"@mongodb-js/prettier-config-devtools": "^1.0.2",
|
||||
"@mongodb-js/tsconfig-devtools": "^1.0.4",
|
||||
"@types/chai": "^4.2.21",
|
||||
"@types/mocha": "^9.1.1",
|
||||
"@types/node": "^22.15.30",
|
||||
"@types/sinon-chai": "^3.2.5",
|
||||
"@types/sparse-bitfield": "^3.0.1",
|
||||
"chai": "^4.5.0",
|
||||
"depcheck": "^1.4.7",
|
||||
"eslint": "^7.25.0",
|
||||
"gen-esm-wrapper": "^1.1.3",
|
||||
"mocha": "^8.4.0",
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^3.5.3",
|
||||
"sinon": "^9.2.3",
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"gitHead": "8928faef983172b1ade2647008b9f6a0183e4a13"
|
||||
}
|
||||
29
node_modules/@mongodb-js/saslprep/readme.md
generated
vendored
29
node_modules/@mongodb-js/saslprep/readme.md
generated
vendored
|
|
@ -1,29 +0,0 @@
|
|||
# saslprep
|
||||
|
||||
_Note: This is a fork of the original [`saslprep`](https://www.npmjs.com/package/saslprep) npm package
|
||||
and provides equivalent functionality._
|
||||
|
||||
Stringprep Profile for User Names and Passwords, [rfc4013](https://tools.ietf.org/html/rfc4013)
|
||||
|
||||
### Usage
|
||||
|
||||
```js
|
||||
const saslprep = require('@mongodb-js/saslprep');
|
||||
|
||||
saslprep('password\u00AD'); // password
|
||||
saslprep('password\u0007'); // Error: prohibited character
|
||||
```
|
||||
|
||||
### API
|
||||
|
||||
##### `saslprep(input: String, opts: Options): String`
|
||||
|
||||
Normalize user name or password.
|
||||
|
||||
##### `Options.allowUnassigned: bool`
|
||||
|
||||
A special behavior for unassigned code points, see https://tools.ietf.org/html/rfc4013#section-2.5. Disabled by default.
|
||||
|
||||
## License
|
||||
|
||||
MIT, 2017-2019 (c) Dmitriy Tsvettsikh
|
||||
21
node_modules/@types/webidl-conversions/LICENSE
generated
vendored
21
node_modules/@types/webidl-conversions/LICENSE
generated
vendored
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE
|
||||
15
node_modules/@types/webidl-conversions/README.md
generated
vendored
15
node_modules/@types/webidl-conversions/README.md
generated
vendored
|
|
@ -1,15 +0,0 @@
|
|||
# Installation
|
||||
> `npm install --save @types/webidl-conversions`
|
||||
|
||||
# Summary
|
||||
This package contains type definitions for webidl-conversions (https://github.com/jsdom/webidl-conversions#readme).
|
||||
|
||||
# Details
|
||||
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/webidl-conversions.
|
||||
|
||||
### Additional Details
|
||||
* Last updated: Tue, 07 Nov 2023 15:11:36 GMT
|
||||
* Dependencies: none
|
||||
|
||||
# Credits
|
||||
These definitions were written by [ExE Boss](https://github.com/ExE-Boss), and [BendingBender](https://github.com/BendingBender).
|
||||
91
node_modules/@types/webidl-conversions/index.d.ts
generated
vendored
91
node_modules/@types/webidl-conversions/index.d.ts
generated
vendored
|
|
@ -1,91 +0,0 @@
|
|||
declare namespace WebIDLConversions {
|
||||
interface Globals {
|
||||
[key: string]: unknown;
|
||||
|
||||
Number: (value?: unknown) => number;
|
||||
String: (value?: unknown) => string;
|
||||
TypeError: new(message?: string) => TypeError;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
context?: string | undefined;
|
||||
globals?: Globals | undefined;
|
||||
}
|
||||
|
||||
interface IntegerOptions extends Options {
|
||||
enforceRange?: boolean | undefined;
|
||||
clamp?: boolean | undefined;
|
||||
}
|
||||
|
||||
interface StringOptions extends Options {
|
||||
treatNullAsEmptyString?: boolean | undefined;
|
||||
}
|
||||
|
||||
interface BufferSourceOptions extends Options {
|
||||
allowShared?: boolean | undefined;
|
||||
}
|
||||
|
||||
type IntegerConversion = (V: unknown, opts?: IntegerOptions) => number;
|
||||
type StringConversion = (V: unknown, opts?: StringOptions) => string;
|
||||
type NumberConversion = (V: unknown, opts?: Options) => number;
|
||||
}
|
||||
|
||||
declare const WebIDLConversions: {
|
||||
any<V>(V: V, opts?: WebIDLConversions.Options): V;
|
||||
undefined(V?: unknown, opts?: WebIDLConversions.Options): void;
|
||||
boolean(V: unknown, opts?: WebIDLConversions.Options): boolean;
|
||||
|
||||
byte(V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
|
||||
octet(V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
|
||||
|
||||
short(V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
|
||||
["unsigned short"](V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
|
||||
|
||||
long(V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
|
||||
["unsigned long"](V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
|
||||
|
||||
["long long"](V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
|
||||
["unsigned long long"](V: unknown, opts?: WebIDLConversions.IntegerOptions): number;
|
||||
|
||||
double(V: unknown, opts?: WebIDLConversions.Options): number;
|
||||
["unrestricted double"](V: unknown, opts?: WebIDLConversions.Options): number;
|
||||
|
||||
float(V: unknown, opts?: WebIDLConversions.Options): number;
|
||||
["unrestricted float"](V: unknown, opts?: WebIDLConversions.Options): number;
|
||||
|
||||
DOMString(V: unknown, opts?: WebIDLConversions.StringOptions): string;
|
||||
ByteString(V: unknown, opts?: WebIDLConversions.StringOptions): string;
|
||||
USVString(V: unknown, opts?: WebIDLConversions.StringOptions): string;
|
||||
|
||||
object<V>(V: V, opts?: WebIDLConversions.Options): V extends object ? V : V & object;
|
||||
ArrayBuffer(
|
||||
V: unknown,
|
||||
opts?: WebIDLConversions.BufferSourceOptions & { allowShared?: false | undefined },
|
||||
): ArrayBuffer;
|
||||
ArrayBuffer(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): ArrayBufferLike;
|
||||
DataView(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): DataView;
|
||||
|
||||
Int8Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Int8Array;
|
||||
Int16Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Int16Array;
|
||||
Int32Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Int32Array;
|
||||
|
||||
Uint8Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Uint8Array;
|
||||
Uint16Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Uint16Array;
|
||||
Uint32Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Uint32Array;
|
||||
Uint8ClampedArray(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Uint8ClampedArray;
|
||||
|
||||
Float32Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Float32Array;
|
||||
Float64Array(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): Float64Array;
|
||||
|
||||
ArrayBufferView(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): ArrayBufferView;
|
||||
BufferSource(
|
||||
V: unknown,
|
||||
opts?: WebIDLConversions.BufferSourceOptions & { allowShared?: false | undefined },
|
||||
): ArrayBuffer | ArrayBufferView;
|
||||
BufferSource(V: unknown, opts?: WebIDLConversions.BufferSourceOptions): ArrayBufferLike | ArrayBufferView;
|
||||
|
||||
DOMTimeStamp(V: unknown, opts?: WebIDLConversions.Options): number;
|
||||
};
|
||||
|
||||
// This can't use ES6 style exports, as those can't have spaces in export names.
|
||||
export = WebIDLConversions;
|
||||
30
node_modules/@types/webidl-conversions/package.json
generated
vendored
30
node_modules/@types/webidl-conversions/package.json
generated
vendored
|
|
@ -1,30 +0,0 @@
|
|||
{
|
||||
"name": "@types/webidl-conversions",
|
||||
"version": "7.0.3",
|
||||
"description": "TypeScript definitions for webidl-conversions",
|
||||
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/webidl-conversions",
|
||||
"license": "MIT",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "ExE Boss",
|
||||
"githubUsername": "ExE-Boss",
|
||||
"url": "https://github.com/ExE-Boss"
|
||||
},
|
||||
{
|
||||
"name": "BendingBender",
|
||||
"githubUsername": "BendingBender",
|
||||
"url": "https://github.com/BendingBender"
|
||||
}
|
||||
],
|
||||
"main": "",
|
||||
"types": "index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
||||
"directory": "types/webidl-conversions"
|
||||
},
|
||||
"scripts": {},
|
||||
"dependencies": {},
|
||||
"typesPublisherContentHash": "ff1514e10869784e8b7cca9c4099a4213d3f14b48c198b1bf116300df94bf608",
|
||||
"typeScriptVersion": "4.5"
|
||||
}
|
||||
21
node_modules/@types/whatwg-url/LICENSE
generated
vendored
21
node_modules/@types/whatwg-url/LICENSE
generated
vendored
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE
|
||||
15
node_modules/@types/whatwg-url/README.md
generated
vendored
15
node_modules/@types/whatwg-url/README.md
generated
vendored
|
|
@ -1,15 +0,0 @@
|
|||
# Installation
|
||||
> `npm install --save @types/whatwg-url`
|
||||
|
||||
# Summary
|
||||
This package contains type definitions for whatwg-url (https://github.com/jsdom/whatwg-url#readme).
|
||||
|
||||
# Details
|
||||
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/whatwg-url.
|
||||
|
||||
### Additional Details
|
||||
* Last updated: Tue, 12 Nov 2024 00:46:36 GMT
|
||||
* Dependencies: [@types/webidl-conversions](https://npmjs.com/package/@types/webidl-conversions)
|
||||
|
||||
# Credits
|
||||
These definitions were written by [Alexander Marks](https://github.com/aomarks), [ExE Boss](https://github.com/ExE-Boss), and [BendingBender](https://github.com/BendingBender).
|
||||
172
node_modules/@types/whatwg-url/index.d.ts
generated
vendored
172
node_modules/@types/whatwg-url/index.d.ts
generated
vendored
|
|
@ -1,172 +0,0 @@
|
|||
/// <reference lib="es2020"/>
|
||||
/** https://url.spec.whatwg.org/#url-representation */
|
||||
export interface URLRecord {
|
||||
scheme: string;
|
||||
username: string;
|
||||
password: string;
|
||||
host: string | number | IPv6Address | null;
|
||||
port: number | null;
|
||||
path: string | string[];
|
||||
query: string | null;
|
||||
fragment: string | null;
|
||||
}
|
||||
|
||||
/** https://url.spec.whatwg.org/#concept-ipv6 */
|
||||
export type IPv6Address = [number, number, number, number, number, number, number, number];
|
||||
|
||||
/** https://url.spec.whatwg.org/#url-class */
|
||||
export class URL {
|
||||
constructor(url: string, base?: string | URL);
|
||||
|
||||
static canParse(url: string, base?: string): boolean;
|
||||
|
||||
get href(): string;
|
||||
set href(V: string);
|
||||
|
||||
get origin(): string;
|
||||
|
||||
get protocol(): string;
|
||||
set protocol(V: string);
|
||||
|
||||
get username(): string;
|
||||
set username(V: string);
|
||||
|
||||
get password(): string;
|
||||
set password(V: string);
|
||||
|
||||
get host(): string;
|
||||
set host(V: string);
|
||||
|
||||
get hostname(): string;
|
||||
set hostname(V: string);
|
||||
|
||||
get port(): string;
|
||||
set port(V: string);
|
||||
|
||||
get pathname(): string;
|
||||
set pathname(V: string);
|
||||
|
||||
get search(): string;
|
||||
set search(V: string);
|
||||
|
||||
get searchParams(): URLSearchParams;
|
||||
|
||||
get hash(): string;
|
||||
set hash(V: string);
|
||||
|
||||
toJSON(): string;
|
||||
|
||||
readonly [Symbol.toStringTag]: "URL";
|
||||
}
|
||||
|
||||
/** https://url.spec.whatwg.org/#interface-urlsearchparams */
|
||||
export class URLSearchParams {
|
||||
constructor(
|
||||
init?:
|
||||
| ReadonlyArray<readonly [name: string, value: string]>
|
||||
| Iterable<readonly [name: string, value: string]>
|
||||
| { readonly [name: string]: string }
|
||||
| string,
|
||||
);
|
||||
|
||||
get size(): number;
|
||||
append(name: string, value: string): void;
|
||||
delete(name: string, value?: string): void;
|
||||
get(name: string): string | null;
|
||||
getAll(name: string): string[];
|
||||
has(name: string, value?: string): boolean;
|
||||
set(name: string, value: string): void;
|
||||
sort(): void;
|
||||
|
||||
keys(): IterableIterator<string>;
|
||||
values(): IterableIterator<string>;
|
||||
entries(): IterableIterator<[name: string, value: string]>;
|
||||
forEach<THIS_ARG = void>(
|
||||
callback: (this: THIS_ARG, value: string, name: string, searchParams: this) => void,
|
||||
thisArg?: THIS_ARG,
|
||||
): void;
|
||||
|
||||
readonly [Symbol.toStringTag]: "URLSearchParams";
|
||||
[Symbol.iterator](): IterableIterator<[name: string, value: string]>;
|
||||
}
|
||||
|
||||
/** https://url.spec.whatwg.org/#concept-url-parser */
|
||||
export function parseURL(input: string, options?: { readonly baseURL?: URLRecord | undefined }): URLRecord | null;
|
||||
|
||||
/** https://url.spec.whatwg.org/#concept-basic-url-parser */
|
||||
export function basicURLParse(
|
||||
input: string,
|
||||
options?: {
|
||||
baseURL?: URLRecord | undefined;
|
||||
url?: URLRecord | undefined;
|
||||
stateOverride?: StateOverride | undefined;
|
||||
},
|
||||
): URLRecord | null;
|
||||
|
||||
/** https://url.spec.whatwg.org/#scheme-start-state */
|
||||
export type StateOverride =
|
||||
| "scheme start"
|
||||
| "scheme"
|
||||
| "no scheme"
|
||||
| "special relative or authority"
|
||||
| "path or authority"
|
||||
| "relative"
|
||||
| "relative slash"
|
||||
| "special authority slashes"
|
||||
| "special authority ignore slashes"
|
||||
| "authority"
|
||||
| "host"
|
||||
| "hostname"
|
||||
| "port"
|
||||
| "file"
|
||||
| "file slash"
|
||||
| "file host"
|
||||
| "path start"
|
||||
| "path"
|
||||
| "opaque path"
|
||||
| "query"
|
||||
| "fragment";
|
||||
|
||||
/** https://url.spec.whatwg.org/#concept-url-serializer */
|
||||
export function serializeURL(urlRecord: URLRecord, excludeFragment?: boolean): string;
|
||||
|
||||
/** https://url.spec.whatwg.org/#concept-host-serializer */
|
||||
export function serializeHost(host: string | number | IPv6Address): string;
|
||||
|
||||
/** https://url.spec.whatwg.org/#url-path-serializer */
|
||||
export function serializePath(urlRecord: URLRecord): string;
|
||||
|
||||
/** https://url.spec.whatwg.org/#serialize-an-integer */
|
||||
export function serializeInteger(number: number): string;
|
||||
|
||||
/** https://html.spec.whatwg.org#ascii-serialisation-of-an-origin */
|
||||
export function serializeURLOrigin(urlRecord: URLRecord): string;
|
||||
|
||||
/** https://url.spec.whatwg.org/#set-the-username */
|
||||
export function setTheUsername(urlRecord: URLRecord, username: string): void;
|
||||
|
||||
/** https://url.spec.whatwg.org/#set-the-password */
|
||||
export function setThePassword(urlRecord: URLRecord, password: string): void;
|
||||
|
||||
/** https://url.spec.whatwg.org/#url-opaque-path */
|
||||
export function hasAnOpaquePath(urlRecord: URLRecord): boolean;
|
||||
|
||||
/** https://url.spec.whatwg.org/#cannot-have-a-username-password-port */
|
||||
export function cannotHaveAUsernamePasswordPort(urlRecord: URLRecord): boolean;
|
||||
|
||||
/** https://url.spec.whatwg.org/#percent-decode */
|
||||
export function percentDecodeBytes(buffer: TypedArray): Uint8Array;
|
||||
|
||||
/** https://url.spec.whatwg.org/#string-percent-decode */
|
||||
export function percentDecodeString(string: string): Uint8Array;
|
||||
|
||||
export type TypedArray =
|
||||
| Uint8Array
|
||||
| Uint8ClampedArray
|
||||
| Uint16Array
|
||||
| Uint32Array
|
||||
| Int8Array
|
||||
| Int16Array
|
||||
| Int32Array
|
||||
| Float32Array
|
||||
| Float64Array;
|
||||
22
node_modules/@types/whatwg-url/lib/URL-impl.d.ts
generated
vendored
22
node_modules/@types/whatwg-url/lib/URL-impl.d.ts
generated
vendored
|
|
@ -1,22 +0,0 @@
|
|||
import { Globals } from "webidl-conversions";
|
||||
import { implementation as URLSearchParamsImpl } from "./URLSearchParams-impl";
|
||||
|
||||
declare class URLImpl {
|
||||
constructor(globalObject: Globals, constructorArgs: readonly [url: string, base?: string]);
|
||||
|
||||
href: string;
|
||||
readonly origin: string;
|
||||
protocol: string;
|
||||
username: string;
|
||||
password: string;
|
||||
host: string;
|
||||
hostname: string;
|
||||
port: string;
|
||||
pathname: string;
|
||||
search: string;
|
||||
readonly searchParams: URLSearchParamsImpl;
|
||||
hash: string;
|
||||
|
||||
toJSON(): string;
|
||||
}
|
||||
export { URLImpl as implementation };
|
||||
66
node_modules/@types/whatwg-url/lib/URL.d.ts
generated
vendored
66
node_modules/@types/whatwg-url/lib/URL.d.ts
generated
vendored
|
|
@ -1,66 +0,0 @@
|
|||
import { URL } from "../index";
|
||||
import { implementation as URLImpl } from "./URL-impl";
|
||||
|
||||
/**
|
||||
* Checks whether `obj` is a `URL` object with an implementation
|
||||
* provided by this package.
|
||||
*/
|
||||
export function is(obj: unknown): obj is URL;
|
||||
|
||||
/**
|
||||
* Checks whether `obj` is a `URLImpl` WebIDL2JS implementation object
|
||||
* provided by this package.
|
||||
*/
|
||||
export function isImpl(obj: unknown): obj is URLImpl;
|
||||
|
||||
/**
|
||||
* Converts the `URL` wrapper into a `URLImpl` object.
|
||||
*
|
||||
* @throws {TypeError} If `obj` is not a `URL` wrapper instance provided by this package.
|
||||
*/
|
||||
export function convert(globalObject: object, obj: unknown, { context }?: { context: string }): URLImpl;
|
||||
|
||||
/**
|
||||
* Creates a new `URL` instance.
|
||||
*
|
||||
* @throws {Error} If the `globalObject` doesn't have a WebIDL2JS constructor
|
||||
* registry or a `URL` constructor provided by this package
|
||||
* in the WebIDL2JS constructor registry.
|
||||
*/
|
||||
export function create(globalObject: object, constructorArgs: readonly [url: string, base?: string]): URL;
|
||||
|
||||
/**
|
||||
* Calls `create()` and returns the internal `URLImpl`.
|
||||
*
|
||||
* @throws {Error} If the `globalObject` doesn't have a WebIDL2JS constructor
|
||||
* registry or a `URL` constructor provided by this package
|
||||
* in the WebIDL2JS constructor registry.
|
||||
*/
|
||||
export function createImpl(globalObject: object, constructorArgs: readonly [url: string, base?: string]): URLImpl;
|
||||
|
||||
/**
|
||||
* Initializes the `URL` instance, called by `create()`.
|
||||
*
|
||||
* Useful when manually sub-classing a non-constructable wrapper object.
|
||||
*/
|
||||
export function setup<T extends URL>(
|
||||
obj: T,
|
||||
globalObject: object,
|
||||
constructorArgs: readonly [url: string, base?: string],
|
||||
): T;
|
||||
|
||||
/**
|
||||
* Creates a new `URL` object without runing the constructor steps.
|
||||
*
|
||||
* Useful when implementing specifications that initialize objects
|
||||
* in different ways than their constructors do.
|
||||
*/
|
||||
declare function _new(globalObject: object, newTarget?: new(url: string, base?: string) => URL): URLImpl;
|
||||
export { _new as new };
|
||||
|
||||
/**
|
||||
* Installs the `URL` constructor onto the `globalObject`.
|
||||
*
|
||||
* @throws {Error} If the target `globalObject` doesn't have an `Error` constructor.
|
||||
*/
|
||||
export function install(globalObject: object, globalNames: readonly string[]): void;
|
||||
20
node_modules/@types/whatwg-url/lib/URLSearchParams-impl.d.ts
generated
vendored
20
node_modules/@types/whatwg-url/lib/URLSearchParams-impl.d.ts
generated
vendored
|
|
@ -1,20 +0,0 @@
|
|||
declare class URLSearchParamsImpl {
|
||||
constructor(
|
||||
globalObject: object,
|
||||
constructorArgs: readonly [
|
||||
init?: ReadonlyArray<readonly [name: string, value: string]> | { readonly [name: string]: string } | string,
|
||||
],
|
||||
privateData: { readonly doNotStripQMark?: boolean | undefined },
|
||||
);
|
||||
|
||||
append(name: string, value: string): void;
|
||||
delete(name: string): void;
|
||||
get(name: string): string | null;
|
||||
getAll(name: string): string[];
|
||||
has(name: string): boolean;
|
||||
set(name: string, value: string): void;
|
||||
sort(): void;
|
||||
|
||||
[Symbol.iterator](): IterableIterator<[name: string, value: string]>;
|
||||
}
|
||||
export { URLSearchParamsImpl as implementation };
|
||||
92
node_modules/@types/whatwg-url/lib/URLSearchParams.d.ts
generated
vendored
92
node_modules/@types/whatwg-url/lib/URLSearchParams.d.ts
generated
vendored
|
|
@ -1,92 +0,0 @@
|
|||
import { URLSearchParams } from "../index";
|
||||
import { implementation as URLSearchParamsImpl } from "./URLSearchParams-impl";
|
||||
|
||||
/**
|
||||
* Checks whether `obj` is a `URLSearchParams` object with an implementation
|
||||
* provided by this package.
|
||||
*/
|
||||
export function is(obj: unknown): obj is URLSearchParams;
|
||||
|
||||
/**
|
||||
* Checks whether `obj` is a `URLSearchParamsImpl` WebIDL2JS implementation object
|
||||
* provided by this package.
|
||||
*/
|
||||
export function isImpl(obj: unknown): obj is URLSearchParamsImpl;
|
||||
|
||||
/**
|
||||
* Converts the `URLSearchParams` wrapper into a `URLSearchParamsImpl` object.
|
||||
*
|
||||
* @throws {TypeError} If `obj` is not a `URLSearchParams` wrapper instance provided by this package.
|
||||
*/
|
||||
export function convert(globalObject: object, obj: unknown, { context }?: { context: string }): URLSearchParamsImpl;
|
||||
|
||||
export function createDefaultIterator<TIteratorKind extends "key" | "value" | "key+value">(
|
||||
globalObject: object,
|
||||
target: URLSearchParamsImpl,
|
||||
kind: TIteratorKind,
|
||||
): IterableIterator<TIteratorKind extends "key" | "value" ? string : [name: string, value: string]>;
|
||||
|
||||
/**
|
||||
* Creates a new `URLSearchParams` instance.
|
||||
*
|
||||
* @throws {Error} If the `globalObject` doesn't have a WebIDL2JS constructor
|
||||
* registry or a `URLSearchParams` constructor provided by this package
|
||||
* in the WebIDL2JS constructor registry.
|
||||
*/
|
||||
export function create(
|
||||
globalObject: object,
|
||||
constructorArgs?: readonly [
|
||||
init: ReadonlyArray<[name: string, value: string]> | { readonly [name: string]: string } | string,
|
||||
],
|
||||
privateData?: { doNotStripQMark?: boolean | undefined },
|
||||
): URLSearchParams;
|
||||
|
||||
/**
|
||||
* Calls `create()` and returns the internal `URLSearchParamsImpl`.
|
||||
*
|
||||
* @throws {Error} If the `globalObject` doesn't have a WebIDL2JS constructor
|
||||
* registry or a `URLSearchParams` constructor provided by this package
|
||||
* in the WebIDL2JS constructor registry.
|
||||
*/
|
||||
export function createImpl(
|
||||
globalObject: object,
|
||||
constructorArgs?: readonly [
|
||||
init: ReadonlyArray<[name: string, value: string]> | { readonly [name: string]: string } | string,
|
||||
],
|
||||
privateData?: { doNotStripQMark?: boolean | undefined },
|
||||
): URLSearchParamsImpl;
|
||||
|
||||
/**
|
||||
* Initializes the `URLSearchParams` instance, called by `create()`.
|
||||
*
|
||||
* Useful when manually sub-classing a non-constructable wrapper object.
|
||||
*/
|
||||
export function setup<T extends URLSearchParams>(
|
||||
obj: T,
|
||||
globalObject: object,
|
||||
constructorArgs?: readonly [
|
||||
init: ReadonlyArray<[name: string, value: string]> | { readonly [name: string]: string } | string,
|
||||
],
|
||||
privateData?: { doNotStripQMark?: boolean | undefined },
|
||||
): T;
|
||||
|
||||
/**
|
||||
* Creates a new `URLSearchParams` object without runing the constructor steps.
|
||||
*
|
||||
* Useful when implementing specifications that initialize objects
|
||||
* in different ways than their constructors do.
|
||||
*/
|
||||
declare function _new(
|
||||
globalObject: object,
|
||||
newTarget?: new(
|
||||
init: ReadonlyArray<[name: string, value: string]> | { readonly [name: string]: string } | string,
|
||||
) => URLSearchParams,
|
||||
): URLSearchParamsImpl;
|
||||
export { _new as new };
|
||||
|
||||
/**
|
||||
* Installs the `URLSearchParams` constructor onto the `globalObject`.
|
||||
*
|
||||
* @throws {Error} If the target `globalObject` doesn't have an `Error` constructor.
|
||||
*/
|
||||
export function install(globalObject: object, globalNames: readonly string[]): void;
|
||||
38
node_modules/@types/whatwg-url/package.json
generated
vendored
38
node_modules/@types/whatwg-url/package.json
generated
vendored
|
|
@ -1,38 +0,0 @@
|
|||
{
|
||||
"name": "@types/whatwg-url",
|
||||
"version": "13.0.0",
|
||||
"description": "TypeScript definitions for whatwg-url",
|
||||
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/whatwg-url",
|
||||
"license": "MIT",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Alexander Marks",
|
||||
"githubUsername": "aomarks",
|
||||
"url": "https://github.com/aomarks"
|
||||
},
|
||||
{
|
||||
"name": "ExE Boss",
|
||||
"githubUsername": "ExE-Boss",
|
||||
"url": "https://github.com/ExE-Boss"
|
||||
},
|
||||
{
|
||||
"name": "BendingBender",
|
||||
"githubUsername": "BendingBender",
|
||||
"url": "https://github.com/BendingBender"
|
||||
}
|
||||
],
|
||||
"main": "",
|
||||
"types": "index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
||||
"directory": "types/whatwg-url"
|
||||
},
|
||||
"scripts": {},
|
||||
"dependencies": {
|
||||
"@types/webidl-conversions": "*"
|
||||
},
|
||||
"peerDependencies": {},
|
||||
"typesPublisherContentHash": "fd4818c1b74d8ef43c58e984d60d82658280822821b6ea5d4978f4007f29c39c",
|
||||
"typeScriptVersion": "4.9"
|
||||
}
|
||||
4
node_modules/@types/whatwg-url/webidl2js-wrapper.d.ts
generated
vendored
4
node_modules/@types/whatwg-url/webidl2js-wrapper.d.ts
generated
vendored
|
|
@ -1,4 +0,0 @@
|
|||
import * as URL from "./lib/URL";
|
||||
import * as URLSearchParams from "./lib/URLSearchParams";
|
||||
|
||||
export { URL, URLSearchParams };
|
||||
201
node_modules/bson/LICENSE.md
generated
vendored
201
node_modules/bson/LICENSE.md
generated
vendored
|
|
@ -1,201 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
291
node_modules/bson/README.md
generated
vendored
291
node_modules/bson/README.md
generated
vendored
|
|
@ -1,291 +0,0 @@
|
|||
# BSON parser
|
||||
|
||||
BSON is short for "Binary JSON," and is the binary-encoded serialization of JSON-like documents.
|
||||
You can learn more about it in [the specification](http://bsonspec.org).
|
||||
|
||||
### Table of Contents
|
||||
|
||||
- [Usage](#usage)
|
||||
- [Bugs/Feature Requests](#bugs--feature-requests)
|
||||
- [Installation](#installation)
|
||||
- [Documentation](#documentation)
|
||||
- [FAQ](#faq)
|
||||
|
||||
|
||||
### Release Integrity
|
||||
|
||||
Releases are created automatically and signed using the [Node team's GPG key](https://pgp.mongodb.com/node-driver.asc). This applies to the git tag as well as all release packages provided as part of a GitHub release. To verify the provided packages, download the key and import it using gpg:
|
||||
|
||||
```shell
|
||||
gpg --import node-driver.asc
|
||||
```
|
||||
|
||||
The GitHub release contains a detached signature file for the NPM package (named
|
||||
`bson-X.Y.Z.tgz.sig`).
|
||||
|
||||
The following command returns the link npm package.
|
||||
```shell
|
||||
npm view bson@vX.Y.Z dist.tarball
|
||||
```
|
||||
|
||||
Using the result of the above command, a `curl` command can return the official npm package for the release.
|
||||
|
||||
To verify the integrity of the downloaded package, run the following command:
|
||||
```shell
|
||||
gpg --verify bson-X.Y.Z.tgz.sig bson-X.Y.Z.tgz
|
||||
```
|
||||
|
||||
>[!Note]
|
||||
No verification is done when using npm to install the package. The contents of the Github tarball and npm's tarball are identical.
|
||||
|
||||
## Bugs / Feature Requests
|
||||
|
||||
Think you've found a bug? Want to see a new feature in `bson`? Please open a case in our issue management tool, JIRA:
|
||||
|
||||
1. Create an account and login: [jira.mongodb.org](https://jira.mongodb.org)
|
||||
2. Navigate to the NODE project: [jira.mongodb.org/browse/NODE](https://jira.mongodb.org/browse/NODE)
|
||||
3. Click **Create Issue** - Please provide as much information as possible about the issue and how to reproduce it.
|
||||
|
||||
Bug reports in JIRA for the NODE driver project are **public**.
|
||||
|
||||
## Usage
|
||||
|
||||
To build a new version perform the following operations:
|
||||
|
||||
```
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Node.js or Bundling Usage
|
||||
|
||||
When using a bundler or Node.js you can import bson using the package name:
|
||||
|
||||
```js
|
||||
import { BSON, EJSON, ObjectId } from 'bson';
|
||||
// or:
|
||||
// const { BSON, EJSON, ObjectId } = require('bson');
|
||||
|
||||
const bytes = BSON.serialize({ _id: new ObjectId() });
|
||||
console.log(bytes);
|
||||
const doc = BSON.deserialize(bytes);
|
||||
console.log(EJSON.stringify(doc));
|
||||
// {"_id":{"$oid":"..."}}
|
||||
```
|
||||
|
||||
### Browser Usage
|
||||
|
||||
If you are working directly in the browser without a bundler please use the `.mjs` bundle like so:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import { BSON, EJSON, ObjectId } from './lib/bson.mjs';
|
||||
|
||||
const bytes = BSON.serialize({ _id: new ObjectId() });
|
||||
console.log(bytes);
|
||||
const doc = BSON.deserialize(bytes);
|
||||
console.log(EJSON.stringify(doc));
|
||||
// {"_id":{"$oid":"..."}}
|
||||
</script>
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install bson
|
||||
```
|
||||
|
||||
### MongoDB Node.js Driver Version Compatibility
|
||||
|
||||
Only the following version combinations with the [MongoDB Node.js Driver](https://github.com/mongodb/node-mongodb-native) are considered stable.
|
||||
|
||||
| | `bson@1.x` | `bson@4.x` | `bson@5.x` | `bson@6.x` | `bson@7.x` |
|
||||
| ------------- | ---------- | ---------- | ---------- | ---------- | ---------- |
|
||||
| `mongodb@7.x` | N/A | N/A | N/A | N/A | ✓ |
|
||||
| `mongodb@6.x` | N/A | N/A | N/A | ✓ | N/A |
|
||||
| `mongodb@5.x` | N/A | N/A | ✓ | N/A | N/A |
|
||||
| `mongodb@4.x` | N/A | ✓ | N/A | N/A | N/A |
|
||||
| `mongodb@3.x` | ✓ | N/A | N/A | N/A | N/A |
|
||||
|
||||
## Documentation
|
||||
|
||||
### BSON
|
||||
|
||||
[API documentation](https://mongodb.github.io/node-mongodb-native/Next/modules/BSON.html)
|
||||
|
||||
<a name="EJSON"></a>
|
||||
|
||||
### EJSON
|
||||
|
||||
- [EJSON](#EJSON)
|
||||
|
||||
- [.parse(text, [options])](#EJSON.parse)
|
||||
|
||||
- [.stringify(value, [replacer], [space], [options])](#EJSON.stringify)
|
||||
|
||||
- [.serialize(bson, [options])](#EJSON.serialize)
|
||||
|
||||
- [.deserialize(ejson, [options])](#EJSON.deserialize)
|
||||
|
||||
<a name="EJSON.parse"></a>
|
||||
|
||||
#### _EJSON_.parse(text, [options])
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| ----------------- | -------------------- | ----------------- | ---------------------------------------------------------------------------------- |
|
||||
| text | <code>string</code> | | |
|
||||
| [options] | <code>object</code> | | Optional settings |
|
||||
| [options.relaxed] | <code>boolean</code> | <code>true</code> | Attempt to return native JS types where possible, rather than BSON types (if true) |
|
||||
|
||||
Parse an Extended JSON string, constructing the JavaScript value or object described by that
|
||||
string.
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const { EJSON } = require('bson');
|
||||
const text = '{ "int32": { "$numberInt": "10" } }';
|
||||
|
||||
// prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
|
||||
console.log(EJSON.parse(text, { relaxed: false }));
|
||||
|
||||
// prints { int32: 10 }
|
||||
console.log(EJSON.parse(text));
|
||||
```
|
||||
|
||||
<a name="EJSON.stringify"></a>
|
||||
|
||||
#### _EJSON_.stringify(value, [replacer], [space], [options])
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| ----------------- | ------------------------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| value | <code>object</code> | | The value to convert to extended JSON |
|
||||
| [replacer] | <code>function</code> \| <code>array</code> | | A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string |
|
||||
| [space] | <code>string</code> \| <code>number</code> | | A String or Number object that's used to insert white space into the output JSON string for readability purposes. |
|
||||
| [options] | <code>object</code> | | Optional settings |
|
||||
| [options.relaxed] | <code>boolean</code> | <code>true</code> | Enabled Extended JSON's `relaxed` mode |
|
||||
| [options.legacy] | <code>boolean</code> | <code>true</code> | Output in Extended JSON v1 |
|
||||
|
||||
Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer
|
||||
function is specified or optionally including only the specified properties if a replacer array
|
||||
is specified.
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const { EJSON } = require('bson');
|
||||
const Int32 = require('mongodb').Int32;
|
||||
const doc = { int32: new Int32(10) };
|
||||
|
||||
// prints '{"int32":{"$numberInt":"10"}}'
|
||||
console.log(EJSON.stringify(doc, { relaxed: false }));
|
||||
|
||||
// prints '{"int32":10}'
|
||||
console.log(EJSON.stringify(doc));
|
||||
```
|
||||
|
||||
<a name="EJSON.serialize"></a>
|
||||
|
||||
#### _EJSON_.serialize(bson, [options])
|
||||
|
||||
| Param | Type | Description |
|
||||
| --------- | ------------------- | ---------------------------------------------------- |
|
||||
| bson | <code>object</code> | The object to serialize |
|
||||
| [options] | <code>object</code> | Optional settings passed to the `stringify` function |
|
||||
|
||||
Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
|
||||
|
||||
<a name="EJSON.deserialize"></a>
|
||||
|
||||
#### _EJSON_.deserialize(ejson, [options])
|
||||
|
||||
| Param | Type | Description |
|
||||
| --------- | ------------------- | -------------------------------------------- |
|
||||
| ejson | <code>object</code> | The Extended JSON object to deserialize |
|
||||
| [options] | <code>object</code> | Optional settings passed to the parse method |
|
||||
|
||||
Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
|
||||
|
||||
## Error Handling
|
||||
|
||||
It is our recommendation to use `BSONError.isBSONError()` checks on errors and to avoid relying on parsing `error.message` and `error.name` strings in your code. We guarantee `BSONError.isBSONError()` checks will pass according to semver guidelines, but errors may be sub-classed or their messages may change at any time, even patch releases, as we see fit to increase the helpfulness of the errors.
|
||||
|
||||
Any new errors we add to the driver will directly extend an existing error class and no existing error will be moved to a different parent class outside of a major release.
|
||||
This means `BSONError.isBSONError()` will always be able to accurately capture the errors that our BSON library throws.
|
||||
|
||||
Hypothetical example: A collection in our Db has an issue with UTF-8 data:
|
||||
|
||||
```ts
|
||||
let documentCount = 0;
|
||||
const cursor = collection.find({}, { utf8Validation: true });
|
||||
try {
|
||||
for await (const doc of cursor) documentCount += 1;
|
||||
} catch (error) {
|
||||
if (BSONError.isBSONError(error)) {
|
||||
console.log(`Found the troublemaker UTF-8!: ${documentCount} ${error.message}`);
|
||||
return documentCount;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
```
|
||||
|
||||
## React Native
|
||||
|
||||
js-bson requires the `atob`, `btoa` and `TextEncoder` globals. Older versions of React Native did not support these global objects, and so
|
||||
[js-bson v5.4.0](https://github.com/mongodb/js-bson/releases/tag/v5.4.0) added support for bundled polyfills for these globals. Newer versions
|
||||
of Hermes includes these globals, and so the polyfills for are no longer needed in the js-bson package.
|
||||
|
||||
If you find yourself on a version of React Native that does not have these globals, either:
|
||||
|
||||
1. polyfill them yourself
|
||||
2. upgrade to a later version of hermes
|
||||
3. use a version of js-bson `>=5.4.0` and `<7.0.0`
|
||||
|
||||
One additional polyfill, `crypto.getRandomValues` is recommended and can be installed with the following command:
|
||||
|
||||
```sh
|
||||
npm install --save react-native-get-random-values
|
||||
```
|
||||
|
||||
The following snippet should be placed at the top of the entrypoint (by default this is the root `index.js` file) for React Native projects using the BSON library. These lines must be placed for any code that imports `BSON`.
|
||||
|
||||
```typescript
|
||||
// Required Polyfills For ReactNative
|
||||
import 'react-native-get-random-values';
|
||||
```
|
||||
|
||||
Finally, import the `BSON` library like so:
|
||||
|
||||
```typescript
|
||||
import { BSON, EJSON } from 'bson';
|
||||
```
|
||||
|
||||
This will cause React Native to import the `node_modules/bson/lib/bson.rn.cjs` bundle (see the `"react-native"` setting we have in the `"exports"` section of our [package.json](./package.json).)
|
||||
|
||||
### Technical Note about React Native module import
|
||||
|
||||
The `"exports"` definition in our `package.json` will result in BSON's CommonJS bundle being imported in a React Native project instead of the ES module bundle. Importing the CommonJS bundle is necessary because BSON's ES module bundle of BSON uses top-level await, which is not supported syntax in [React Native's runtime hermes](https://hermesengine.dev/).
|
||||
|
||||
## FAQ
|
||||
|
||||
#### Why does `undefined` get converted to `null`?
|
||||
|
||||
The `undefined` BSON type has been [deprecated for many years](http://bsonspec.org/spec.html), so this library has dropped support for it. Use the `ignoreUndefined` option (for example, from the [driver](http://mongodb.github.io/node-mongodb-native/2.2/api/MongoClient.html#connect) ) to instead remove `undefined` keys.
|
||||
|
||||
#### How do I add custom serialization logic?
|
||||
|
||||
This library looks for `toBSON()` functions on every path, and calls the `toBSON()` function to get the value to serialize.
|
||||
|
||||
```javascript
|
||||
const BSON = require('bson');
|
||||
|
||||
class CustomSerialize {
|
||||
toBSON() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
const obj = { answer: new CustomSerialize() };
|
||||
// "{ answer: 42 }"
|
||||
console.log(BSON.deserialize(BSON.serialize(obj)));
|
||||
```
|
||||
1729
node_modules/bson/bson.d.ts
generated
vendored
1729
node_modules/bson/bson.d.ts
generated
vendored
File diff suppressed because it is too large
Load diff
19
node_modules/bson/etc/prepare.js
generated
vendored
19
node_modules/bson/etc/prepare.js
generated
vendored
|
|
@ -1,19 +0,0 @@
|
|||
#! /usr/bin/env node
|
||||
var cp = require('child_process');
|
||||
var fs = require('fs');
|
||||
|
||||
var nodeMajorVersion = +process.version.match(/^v(\d+)\.\d+/)[1];
|
||||
|
||||
if (fs.existsSync('src') && nodeMajorVersion >= 10) {
|
||||
cp.spawnSync('npm', ['run', 'build'], { stdio: 'inherit', shell: true });
|
||||
} else {
|
||||
if (!fs.existsSync('lib')) {
|
||||
console.warn('BSON: No compiled javascript present, the library is not installed correctly.');
|
||||
if (nodeMajorVersion < 10) {
|
||||
console.warn(
|
||||
'This library can only be compiled in nodejs version 10 or later, currently running: ' +
|
||||
nodeMajorVersion
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
4675
node_modules/bson/lib/bson.bundle.js
generated
vendored
4675
node_modules/bson/lib/bson.bundle.js
generated
vendored
File diff suppressed because it is too large
Load diff
1
node_modules/bson/lib/bson.bundle.js.map
generated
vendored
1
node_modules/bson/lib/bson.bundle.js.map
generated
vendored
File diff suppressed because one or more lines are too long
4670
node_modules/bson/lib/bson.cjs
generated
vendored
4670
node_modules/bson/lib/bson.cjs
generated
vendored
File diff suppressed because it is too large
Load diff
1
node_modules/bson/lib/bson.cjs.map
generated
vendored
1
node_modules/bson/lib/bson.cjs.map
generated
vendored
File diff suppressed because one or more lines are too long
4639
node_modules/bson/lib/bson.mjs
generated
vendored
4639
node_modules/bson/lib/bson.mjs
generated
vendored
File diff suppressed because it is too large
Load diff
1
node_modules/bson/lib/bson.mjs.map
generated
vendored
1
node_modules/bson/lib/bson.mjs.map
generated
vendored
File diff suppressed because one or more lines are too long
4639
node_modules/bson/lib/bson.node.mjs
generated
vendored
4639
node_modules/bson/lib/bson.node.mjs
generated
vendored
File diff suppressed because it is too large
Load diff
1
node_modules/bson/lib/bson.node.mjs.map
generated
vendored
1
node_modules/bson/lib/bson.node.mjs.map
generated
vendored
File diff suppressed because one or more lines are too long
4680
node_modules/bson/lib/bson.rn.cjs
generated
vendored
4680
node_modules/bson/lib/bson.rn.cjs
generated
vendored
File diff suppressed because it is too large
Load diff
1
node_modules/bson/lib/bson.rn.cjs.map
generated
vendored
1
node_modules/bson/lib/bson.rn.cjs.map
generated
vendored
File diff suppressed because one or more lines are too long
118
node_modules/bson/package.json
generated
vendored
118
node_modules/bson/package.json
generated
vendored
|
|
@ -1,118 +0,0 @@
|
|||
{
|
||||
"name": "bson",
|
||||
"description": "A bson parser for node.js and the browser",
|
||||
"keywords": [
|
||||
"mongodb",
|
||||
"bson",
|
||||
"parser"
|
||||
],
|
||||
"files": [
|
||||
"lib",
|
||||
"src",
|
||||
"bson.d.ts",
|
||||
"etc/prepare.js",
|
||||
"vendor"
|
||||
],
|
||||
"types": "bson.d.ts",
|
||||
"version": "7.0.0",
|
||||
"author": {
|
||||
"name": "The MongoDB NodeJS Team",
|
||||
"email": "dbx-node@mongodb.com"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"contributors": [],
|
||||
"repository": "mongodb/js-bson",
|
||||
"bugs": {
|
||||
"url": "https://jira.mongodb.org/projects/NODE/issues/"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
||||
"@microsoft/api-extractor": "^7.52.5",
|
||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||
"@rollup/plugin-typescript": "^12.1.2",
|
||||
"@types/chai": "^4.3.17",
|
||||
"@types/mocha": "^10.0.7",
|
||||
"@types/node": "^24.2.1",
|
||||
"@types/sinon": "^17.0.4",
|
||||
"@types/sinon-chai": "^3.2.12",
|
||||
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
||||
"@typescript-eslint/parser": "^8.31.1",
|
||||
"benchmark": "^2.1.4",
|
||||
"chai": "^4.4.1",
|
||||
"chalk": "^5.3.0",
|
||||
"dbx-js-tools": "github:mongodb-js/dbx-js-tools#main",
|
||||
"eslint": "^9.33.0",
|
||||
"eslint-config-prettier": "^10.1.2",
|
||||
"eslint-plugin-prettier": "^5.2.6",
|
||||
"eslint-plugin-tsdoc": "^0.4.0",
|
||||
"magic-string": "^0.30.11",
|
||||
"mocha": "^11.7.1",
|
||||
"node-fetch": "^3.3.2",
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^3.5.3",
|
||||
"rollup": "^4.40.1",
|
||||
"sinon": "^21.0.0",
|
||||
"sinon-chai": "^3.7.0",
|
||||
"source-map-support": "^0.5.21",
|
||||
"tar": "^7.4.3",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsd": "^0.33.0",
|
||||
"typescript": "^5.8.3",
|
||||
"typescript-cached-transpile": "0.0.6",
|
||||
"uuid": "^11.1.0"
|
||||
},
|
||||
"tsd": {
|
||||
"directory": "test/types",
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"target": "esnext",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"native": false
|
||||
},
|
||||
"main": "./lib/bson.cjs",
|
||||
"module": "./lib/bson.node.mjs",
|
||||
"exports": {
|
||||
"browser": {
|
||||
"types": "./bson.d.ts",
|
||||
"default": "./lib/bson.mjs"
|
||||
},
|
||||
"react-native": "./lib/bson.rn.cjs",
|
||||
"default": {
|
||||
"types": "./bson.d.ts",
|
||||
"import": "./lib/bson.node.mjs",
|
||||
"require": "./lib/bson.cjs"
|
||||
}
|
||||
},
|
||||
"compass:exports": {
|
||||
"import": "./lib/bson.cjs",
|
||||
"require": "./lib/bson.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.19.0"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "npm run build",
|
||||
"test": "npm run check:node && npm run check:web",
|
||||
"check:node": "WEB=false mocha test/node",
|
||||
"check:tsd": "npm run build:dts && tsd",
|
||||
"check:web": "WEB=true mocha test/node",
|
||||
"check:granular-bench": "npm run build:bench && npm run check:baseline-bench && node ./test/bench/etc/run_granular_benchmarks.js",
|
||||
"check:spec-bench": "npm run build:bench && npm run check:baseline-bench && node ./test/bench/lib/spec/bsonBench.js",
|
||||
"check:custom-bench": "npm run build && npm run check:baseline-bench && node ./test/bench/custom/main.mjs",
|
||||
"check:baseline-bench": "node ./test/bench/etc/cpuBaseline.js",
|
||||
"build:bench": "cd test/bench && npx tsc",
|
||||
"build:ts": "node ./node_modules/typescript/bin/tsc",
|
||||
"build:dts": "npm run build:ts && api-extractor run --typescript-compiler-folder node_modules/typescript --local && node etc/clean_definition_files.cjs",
|
||||
"build:bundle": "rollup -c rollup.config.mjs",
|
||||
"build": "npm run build:dts && npm run build:bundle",
|
||||
"check:lint": "ESLINT_USE_FLAT_CONFIG=false eslint -v && ESLINT_USE_FLAT_CONFIG=false eslint --ext '.js,.ts' --max-warnings=0 src test && npm run build:dts && npm run check:tsd",
|
||||
"format": "ESLINT_USE_FLAT_CONFIG=false eslint --ext '.js,.ts' src test --fix",
|
||||
"check:coverage": "nyc --check-coverage npm run check:node",
|
||||
"prepare": "node etc/prepare.js",
|
||||
"release": "standard-version -i HISTORY.md"
|
||||
}
|
||||
}
|
||||
751
node_modules/bson/src/binary.ts
generated
vendored
751
node_modules/bson/src/binary.ts
generated
vendored
|
|
@ -1,751 +0,0 @@
|
|||
import { type InspectFn, defaultInspect, isAnyArrayBuffer, isUint8Array } from './parser/utils';
|
||||
import type { EJSONOptions } from './extended_json';
|
||||
import { BSONError } from './error';
|
||||
import { BSON_BINARY_SUBTYPE_UUID_NEW } from './constants';
|
||||
import { ByteUtils } from './utils/byte_utils';
|
||||
import { BSONValue } from './bson_value';
|
||||
import { NumberUtils } from './utils/number_utils';
|
||||
|
||||
/** @public */
|
||||
export type BinarySequence = Uint8Array | number[];
|
||||
|
||||
/** @public */
|
||||
export interface BinaryExtendedLegacy {
|
||||
$type: string;
|
||||
$binary: string;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface BinaryExtended {
|
||||
$binary: {
|
||||
subType: string;
|
||||
base64: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON Binary type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class Binary extends BSONValue {
|
||||
get _bsontype(): 'Binary' {
|
||||
return 'Binary';
|
||||
}
|
||||
|
||||
/**
|
||||
* Binary default subtype
|
||||
* @internal
|
||||
*/
|
||||
private static readonly BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
||||
|
||||
/** Initial buffer default size */
|
||||
static readonly BUFFER_SIZE = 256;
|
||||
/** Default BSON type */
|
||||
static readonly SUBTYPE_DEFAULT = 0;
|
||||
/** Function BSON type */
|
||||
static readonly SUBTYPE_FUNCTION = 1;
|
||||
/**
|
||||
* Legacy default BSON Binary type
|
||||
* @deprecated BSON Binary subtype 2 is deprecated in the BSON specification
|
||||
*/
|
||||
static readonly SUBTYPE_BYTE_ARRAY = 2;
|
||||
/** Deprecated UUID BSON type @deprecated Please use SUBTYPE_UUID */
|
||||
static readonly SUBTYPE_UUID_OLD = 3;
|
||||
/** UUID BSON type */
|
||||
static readonly SUBTYPE_UUID = 4;
|
||||
/** MD5 BSON type */
|
||||
static readonly SUBTYPE_MD5 = 5;
|
||||
/** Encrypted BSON type */
|
||||
static readonly SUBTYPE_ENCRYPTED = 6;
|
||||
/** Column BSON type */
|
||||
static readonly SUBTYPE_COLUMN = 7;
|
||||
/** Sensitive BSON type */
|
||||
static readonly SUBTYPE_SENSITIVE = 8;
|
||||
/** Vector BSON type */
|
||||
static readonly SUBTYPE_VECTOR = 9;
|
||||
/** User BSON type */
|
||||
static readonly SUBTYPE_USER_DEFINED = 128;
|
||||
|
||||
/** datatype of a Binary Vector (subtype: 9) */
|
||||
static readonly VECTOR_TYPE = Object.freeze({
|
||||
Int8: 0x03,
|
||||
Float32: 0x27,
|
||||
PackedBit: 0x10
|
||||
} as const);
|
||||
|
||||
/**
|
||||
* The bytes of the Binary value.
|
||||
*
|
||||
* The format of a Binary value in BSON is defined as:
|
||||
* ```txt
|
||||
* binary ::= int32 subtype (byte*)
|
||||
* ```
|
||||
*
|
||||
* This `buffer` is the "(byte*)" segment.
|
||||
*
|
||||
* Unless the value is subtype 2, then deserialize will read the first 4 bytes as an int32 and set this to the remaining bytes.
|
||||
*
|
||||
* ```txt
|
||||
* binary ::= int32 unsigned_byte(2) int32 (byte*)
|
||||
* ```
|
||||
*
|
||||
* @see https://bsonspec.org/spec.html
|
||||
*/
|
||||
public buffer: Uint8Array;
|
||||
/**
|
||||
* The binary subtype.
|
||||
*
|
||||
* Current defined values are:
|
||||
*
|
||||
* - `unsigned_byte(0)` Generic binary subtype
|
||||
* - `unsigned_byte(1)` Function
|
||||
* - `unsigned_byte(2)` Binary (Deprecated)
|
||||
* - `unsigned_byte(3)` UUID (Deprecated)
|
||||
* - `unsigned_byte(4)` UUID
|
||||
* - `unsigned_byte(5)` MD5
|
||||
* - `unsigned_byte(6)` Encrypted BSON value
|
||||
* - `unsigned_byte(7)` Compressed BSON column
|
||||
* - `unsigned_byte(8)` Sensitive
|
||||
* - `unsigned_byte(9)` Vector
|
||||
* - `unsigned_byte(128)` - `unsigned_byte(255)` User defined
|
||||
*/
|
||||
public sub_type: number;
|
||||
/**
|
||||
* The Binary's `buffer` can be larger than the Binary's content.
|
||||
* This property is used to determine where the content ends in the buffer.
|
||||
*/
|
||||
public position: number;
|
||||
|
||||
/**
|
||||
* Create a new Binary instance.
|
||||
* @param buffer - a buffer object containing the binary data.
|
||||
* @param subType - the option binary type.
|
||||
*/
|
||||
constructor(buffer?: BinarySequence, subType?: number) {
|
||||
super();
|
||||
if (
|
||||
!(buffer == null) &&
|
||||
typeof buffer === 'string' &&
|
||||
!ArrayBuffer.isView(buffer) &&
|
||||
!isAnyArrayBuffer(buffer) &&
|
||||
!Array.isArray(buffer)
|
||||
) {
|
||||
throw new BSONError('Binary can only be constructed from Uint8Array or number[]');
|
||||
}
|
||||
|
||||
this.sub_type = subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT;
|
||||
|
||||
if (buffer == null) {
|
||||
// create an empty binary buffer
|
||||
this.buffer = ByteUtils.allocate(Binary.BUFFER_SIZE);
|
||||
this.position = 0;
|
||||
} else {
|
||||
this.buffer = Array.isArray(buffer)
|
||||
? ByteUtils.fromNumberArray(buffer)
|
||||
: ByteUtils.toLocalBufferType(buffer);
|
||||
this.position = this.buffer.byteLength;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates this binary with byte_value.
|
||||
*
|
||||
* @param byteValue - a single byte we wish to write.
|
||||
*/
|
||||
put(byteValue: string | number | Uint8Array | number[]): void {
|
||||
// If it's a string and a has more than one character throw an error
|
||||
if (typeof byteValue === 'string' && byteValue.length !== 1) {
|
||||
throw new BSONError('only accepts single character String');
|
||||
} else if (typeof byteValue !== 'number' && byteValue.length !== 1)
|
||||
throw new BSONError('only accepts single character Uint8Array or Array');
|
||||
|
||||
// Decode the byte value once
|
||||
let decodedByte: number;
|
||||
if (typeof byteValue === 'string') {
|
||||
decodedByte = byteValue.charCodeAt(0);
|
||||
} else if (typeof byteValue === 'number') {
|
||||
decodedByte = byteValue;
|
||||
} else {
|
||||
decodedByte = byteValue[0];
|
||||
}
|
||||
|
||||
if (decodedByte < 0 || decodedByte > 255) {
|
||||
throw new BSONError('only accepts number in a valid unsigned byte range 0-255');
|
||||
}
|
||||
|
||||
if (this.buffer.byteLength > this.position) {
|
||||
this.buffer[this.position++] = decodedByte;
|
||||
} else {
|
||||
const newSpace = ByteUtils.allocate(Binary.BUFFER_SIZE + this.buffer.length);
|
||||
newSpace.set(this.buffer, 0);
|
||||
this.buffer = newSpace;
|
||||
this.buffer[this.position++] = decodedByte;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a buffer to the binary.
|
||||
*
|
||||
* @param sequence - a string or buffer to be written to the Binary BSON object.
|
||||
* @param offset - specify the binary of where to write the content.
|
||||
*/
|
||||
write(sequence: BinarySequence, offset: number): void {
|
||||
offset = typeof offset === 'number' ? offset : this.position;
|
||||
|
||||
// If the buffer is to small let's extend the buffer
|
||||
if (this.buffer.byteLength < offset + sequence.length) {
|
||||
const newSpace = ByteUtils.allocate(this.buffer.byteLength + sequence.length);
|
||||
newSpace.set(this.buffer, 0);
|
||||
|
||||
// Assign the new buffer
|
||||
this.buffer = newSpace;
|
||||
}
|
||||
|
||||
if (ArrayBuffer.isView(sequence)) {
|
||||
this.buffer.set(ByteUtils.toLocalBufferType(sequence), offset);
|
||||
this.position =
|
||||
offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
|
||||
} else if (typeof sequence === 'string') {
|
||||
throw new BSONError('input cannot be string');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a view of **length** bytes starting at **position**.
|
||||
*
|
||||
* @param position - read from the given position in the Binary.
|
||||
* @param length - the number of bytes to read.
|
||||
*/
|
||||
read(position: number, length: number): Uint8Array {
|
||||
length = length && length > 0 ? length : this.position;
|
||||
const end = position + length;
|
||||
return this.buffer.subarray(position, end > this.position ? this.position : end);
|
||||
}
|
||||
|
||||
/** returns a view of the binary value as a Uint8Array */
|
||||
value(): Uint8Array {
|
||||
// Optimize to serialize for the situation where the data == size of buffer
|
||||
return this.buffer.length === this.position
|
||||
? this.buffer
|
||||
: this.buffer.subarray(0, this.position);
|
||||
}
|
||||
|
||||
/** the length of the binary sequence */
|
||||
length(): number {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
toJSON(): string {
|
||||
return ByteUtils.toBase64(this.buffer.subarray(0, this.position));
|
||||
}
|
||||
|
||||
toString(encoding?: 'hex' | 'base64' | 'utf8' | 'utf-8'): string {
|
||||
if (encoding === 'hex') return ByteUtils.toHex(this.buffer.subarray(0, this.position));
|
||||
if (encoding === 'base64') return ByteUtils.toBase64(this.buffer.subarray(0, this.position));
|
||||
if (encoding === 'utf8' || encoding === 'utf-8')
|
||||
return ByteUtils.toUTF8(this.buffer, 0, this.position, false);
|
||||
return ByteUtils.toUTF8(this.buffer, 0, this.position, false);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(options?: EJSONOptions): BinaryExtendedLegacy | BinaryExtended {
|
||||
options = options || {};
|
||||
|
||||
if (this.sub_type === Binary.SUBTYPE_VECTOR) {
|
||||
validateBinaryVector(this);
|
||||
}
|
||||
|
||||
const base64String = ByteUtils.toBase64(this.buffer);
|
||||
|
||||
const subType = Number(this.sub_type).toString(16);
|
||||
if (options.legacy) {
|
||||
return {
|
||||
$binary: base64String,
|
||||
$type: subType.length === 1 ? '0' + subType : subType
|
||||
};
|
||||
}
|
||||
return {
|
||||
$binary: {
|
||||
base64: base64String,
|
||||
subType: subType.length === 1 ? '0' + subType : subType
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
toUUID(): UUID {
|
||||
if (this.sub_type === Binary.SUBTYPE_UUID) {
|
||||
return new UUID(this.buffer.subarray(0, this.position));
|
||||
}
|
||||
|
||||
throw new BSONError(
|
||||
`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`
|
||||
);
|
||||
}
|
||||
|
||||
/** Creates an Binary instance from a hex digit string */
|
||||
static createFromHexString(hex: string, subType?: number): Binary {
|
||||
return new Binary(ByteUtils.fromHex(hex), subType);
|
||||
}
|
||||
|
||||
/** Creates an Binary instance from a base64 string */
|
||||
static createFromBase64(base64: string, subType?: number): Binary {
|
||||
return new Binary(ByteUtils.fromBase64(base64), subType);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(
|
||||
doc: BinaryExtendedLegacy | BinaryExtended | UUIDExtended,
|
||||
options?: EJSONOptions
|
||||
): Binary {
|
||||
options = options || {};
|
||||
let data: Uint8Array | undefined;
|
||||
let type;
|
||||
if ('$binary' in doc) {
|
||||
if (options.legacy && typeof doc.$binary === 'string' && '$type' in doc) {
|
||||
type = doc.$type ? parseInt(doc.$type, 16) : 0;
|
||||
data = ByteUtils.fromBase64(doc.$binary);
|
||||
} else {
|
||||
if (typeof doc.$binary !== 'string') {
|
||||
type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
|
||||
data = ByteUtils.fromBase64(doc.$binary.base64);
|
||||
}
|
||||
}
|
||||
} else if ('$uuid' in doc) {
|
||||
type = 4;
|
||||
data = UUID.bytesFromString(doc.$uuid);
|
||||
}
|
||||
if (!data) {
|
||||
throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`);
|
||||
}
|
||||
return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
|
||||
}
|
||||
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
const base64 = ByteUtils.toBase64(this.buffer.subarray(0, this.position));
|
||||
const base64Arg = inspect(base64, options);
|
||||
const subTypeArg = inspect(this.sub_type, options);
|
||||
return `Binary.createFromBase64(${base64Arg}, ${subTypeArg})`;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this Binary represents a Int8 Vector (`binary.buffer[0] === Binary.VECTOR_TYPE.Int8`),
|
||||
* returns a copy of the bytes in a new Int8Array.
|
||||
*
|
||||
* If the Binary is not a Vector, or the datatype is not Int8, an error is thrown.
|
||||
*/
|
||||
public toInt8Array(): Int8Array {
|
||||
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
||||
throw new BSONError('Binary sub_type is not Vector');
|
||||
}
|
||||
|
||||
if (this.buffer[0] !== Binary.VECTOR_TYPE.Int8) {
|
||||
throw new BSONError('Binary datatype field is not Int8');
|
||||
}
|
||||
|
||||
validateBinaryVector(this);
|
||||
|
||||
return new Int8Array(
|
||||
this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If this Binary represents a Float32 Vector (`binary.buffer[0] === Binary.VECTOR_TYPE.Float32`),
|
||||
* returns a copy of the bytes in a new Float32Array.
|
||||
*
|
||||
* If the Binary is not a Vector, or the datatype is not Float32, an error is thrown.
|
||||
*/
|
||||
public toFloat32Array(): Float32Array {
|
||||
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
||||
throw new BSONError('Binary sub_type is not Vector');
|
||||
}
|
||||
|
||||
if (this.buffer[0] !== Binary.VECTOR_TYPE.Float32) {
|
||||
throw new BSONError('Binary datatype field is not Float32');
|
||||
}
|
||||
|
||||
validateBinaryVector(this);
|
||||
|
||||
const floatBytes = new Uint8Array(
|
||||
this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position)
|
||||
);
|
||||
|
||||
if (NumberUtils.isBigEndian) ByteUtils.swap32(floatBytes);
|
||||
|
||||
return new Float32Array(floatBytes.buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* If this Binary represents packed bit Vector (`binary.buffer[0] === Binary.VECTOR_TYPE.PackedBit`),
|
||||
* returns a copy of the bytes that are packed bits.
|
||||
*
|
||||
* Use `toBits` to get the unpacked bits.
|
||||
*
|
||||
* If the Binary is not a Vector, or the datatype is not PackedBit, an error is thrown.
|
||||
*/
|
||||
public toPackedBits(): Uint8Array {
|
||||
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
||||
throw new BSONError('Binary sub_type is not Vector');
|
||||
}
|
||||
|
||||
if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
|
||||
throw new BSONError('Binary datatype field is not packed bit');
|
||||
}
|
||||
|
||||
validateBinaryVector(this);
|
||||
|
||||
return new Uint8Array(
|
||||
this.buffer.buffer.slice(this.buffer.byteOffset + 2, this.buffer.byteOffset + this.position)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If this Binary represents a Packed bit Vector (`binary.buffer[0] === Binary.VECTOR_TYPE.PackedBit`),
|
||||
* returns a copy of the bit unpacked into a new Int8Array.
|
||||
*
|
||||
* Use `toPackedBits` to get the bits still in packed form.
|
||||
*
|
||||
* If the Binary is not a Vector, or the datatype is not PackedBit, an error is thrown.
|
||||
*/
|
||||
public toBits(): Int8Array {
|
||||
if (this.sub_type !== Binary.SUBTYPE_VECTOR) {
|
||||
throw new BSONError('Binary sub_type is not Vector');
|
||||
}
|
||||
|
||||
if (this.buffer[0] !== Binary.VECTOR_TYPE.PackedBit) {
|
||||
throw new BSONError('Binary datatype field is not packed bit');
|
||||
}
|
||||
|
||||
validateBinaryVector(this);
|
||||
|
||||
const byteCount = this.length() - 2;
|
||||
const bitCount = byteCount * 8 - this.buffer[1];
|
||||
const bits = new Int8Array(bitCount);
|
||||
|
||||
for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
|
||||
const byteOffset = (bitOffset / 8) | 0;
|
||||
const byte = this.buffer[byteOffset + 2];
|
||||
const shift = 7 - (bitOffset % 8);
|
||||
const bit = (byte >> shift) & 1;
|
||||
bits[bitOffset] = bit;
|
||||
}
|
||||
|
||||
return bits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Binary representing an Int8 Vector.
|
||||
* @param array - The array to store as a view on the Binary class
|
||||
*/
|
||||
public static fromInt8Array(array: Int8Array): Binary {
|
||||
const buffer = ByteUtils.allocate(array.byteLength + 2);
|
||||
buffer[0] = Binary.VECTOR_TYPE.Int8;
|
||||
buffer[1] = 0;
|
||||
const intBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
||||
buffer.set(intBytes, 2);
|
||||
const bin = new this(buffer, this.SUBTYPE_VECTOR);
|
||||
validateBinaryVector(bin);
|
||||
return bin;
|
||||
}
|
||||
|
||||
/** Constructs a Binary representing an Float32 Vector. */
|
||||
public static fromFloat32Array(array: Float32Array): Binary {
|
||||
const binaryBytes = ByteUtils.allocate(array.byteLength + 2);
|
||||
binaryBytes[0] = Binary.VECTOR_TYPE.Float32;
|
||||
binaryBytes[1] = 0;
|
||||
|
||||
const floatBytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
|
||||
binaryBytes.set(floatBytes, 2);
|
||||
|
||||
if (NumberUtils.isBigEndian) ByteUtils.swap32(new Uint8Array(binaryBytes.buffer, 2));
|
||||
|
||||
const bin = new this(binaryBytes, this.SUBTYPE_VECTOR);
|
||||
validateBinaryVector(bin);
|
||||
return bin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Binary representing a packed bit Vector.
|
||||
*
|
||||
* Use `fromBits` to pack an array of 1s and 0s.
|
||||
*/
|
||||
public static fromPackedBits(array: Uint8Array, padding = 0): Binary {
|
||||
const buffer = ByteUtils.allocate(array.byteLength + 2);
|
||||
buffer[0] = Binary.VECTOR_TYPE.PackedBit;
|
||||
buffer[1] = padding;
|
||||
buffer.set(array, 2);
|
||||
const bin = new this(buffer, this.SUBTYPE_VECTOR);
|
||||
validateBinaryVector(bin);
|
||||
return bin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a Binary representing an Packed Bit Vector.
|
||||
* @param array - The array of 1s and 0s to pack into the Binary instance
|
||||
*/
|
||||
public static fromBits(bits: ArrayLike<number>): Binary {
|
||||
const byteLength = (bits.length + 7) >>> 3; // ceil(bits.length / 8)
|
||||
const bytes = new Uint8Array(byteLength + 2);
|
||||
bytes[0] = Binary.VECTOR_TYPE.PackedBit;
|
||||
|
||||
const remainder = bits.length % 8;
|
||||
bytes[1] = remainder === 0 ? 0 : 8 - remainder;
|
||||
|
||||
for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
|
||||
const byteOffset = bitOffset >>> 3; // floor(bitOffset / 8)
|
||||
const bit = bits[bitOffset];
|
||||
|
||||
if (bit !== 0 && bit !== 1) {
|
||||
throw new BSONError(
|
||||
`Invalid bit value at ${bitOffset}: must be 0 or 1, found ${bits[bitOffset]}`
|
||||
);
|
||||
}
|
||||
|
||||
if (bit === 0) continue;
|
||||
|
||||
const shift = 7 - (bitOffset % 8);
|
||||
bytes[byteOffset + 2] |= bit << shift;
|
||||
}
|
||||
|
||||
return new this(bytes, Binary.SUBTYPE_VECTOR);
|
||||
}
|
||||
}
|
||||
|
||||
export function validateBinaryVector(vector: Binary): void {
|
||||
if (vector.sub_type !== Binary.SUBTYPE_VECTOR) return;
|
||||
|
||||
const size = vector.position;
|
||||
|
||||
// NOTE: Validation is only applied to **KNOWN** vector types
|
||||
// If a new datatype is introduced, a future version of the library will need to add validation
|
||||
const datatype = vector.buffer[0];
|
||||
|
||||
// NOTE: We do not enable noUncheckedIndexedAccess so TS believes this is always number
|
||||
// a Binary vector may be empty, in which case the padding is undefined
|
||||
// this possible value is tolerable for our validation checks
|
||||
const padding: number | undefined = vector.buffer[1];
|
||||
|
||||
if (
|
||||
(datatype === Binary.VECTOR_TYPE.Float32 || datatype === Binary.VECTOR_TYPE.Int8) &&
|
||||
padding !== 0
|
||||
) {
|
||||
throw new BSONError('Invalid Vector: padding must be zero for int8 and float32 vectors');
|
||||
}
|
||||
|
||||
if (datatype === Binary.VECTOR_TYPE.Float32) {
|
||||
if (size !== 0 && size - 2 !== 0 && (size - 2) % 4 !== 0) {
|
||||
throw new BSONError('Invalid Vector: Float32 vector must contain a multiple of 4 bytes');
|
||||
}
|
||||
}
|
||||
|
||||
if (datatype === Binary.VECTOR_TYPE.PackedBit && padding !== 0 && size === 2) {
|
||||
throw new BSONError(
|
||||
'Invalid Vector: padding must be zero for packed bit vectors that are empty'
|
||||
);
|
||||
}
|
||||
|
||||
if (datatype === Binary.VECTOR_TYPE.PackedBit && padding > 7) {
|
||||
throw new BSONError(
|
||||
`Invalid Vector: padding must be a value between 0 and 7. found: ${padding}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export type UUIDExtended = {
|
||||
$uuid: string;
|
||||
};
|
||||
|
||||
const UUID_BYTE_LENGTH = 16;
|
||||
const UUID_WITHOUT_DASHES = /^[0-9A-F]{32}$/i;
|
||||
const UUID_WITH_DASHES = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
|
||||
|
||||
/**
|
||||
* A class representation of the BSON UUID type.
|
||||
* @public
|
||||
*/
|
||||
export class UUID extends Binary {
|
||||
/**
|
||||
* Create a UUID type
|
||||
*
|
||||
* When the argument to the constructor is omitted a random v4 UUID will be generated.
|
||||
*
|
||||
* @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
|
||||
*/
|
||||
constructor(input?: string | Uint8Array | UUID) {
|
||||
let bytes: Uint8Array;
|
||||
if (input == null) {
|
||||
bytes = UUID.generate();
|
||||
} else if (input instanceof UUID) {
|
||||
bytes = ByteUtils.toLocalBufferType(new Uint8Array(input.buffer));
|
||||
} else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
|
||||
bytes = ByteUtils.toLocalBufferType(input);
|
||||
} else if (typeof input === 'string') {
|
||||
bytes = UUID.bytesFromString(input);
|
||||
} else {
|
||||
throw new BSONError(
|
||||
'Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).'
|
||||
);
|
||||
}
|
||||
super(bytes, BSON_BINARY_SUBTYPE_UUID_NEW);
|
||||
}
|
||||
|
||||
/**
|
||||
* The UUID bytes
|
||||
* @readonly
|
||||
*/
|
||||
get id(): Uint8Array {
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
set id(value: Uint8Array) {
|
||||
this.buffer = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
|
||||
* @param includeDashes - should the string exclude dash-separators.
|
||||
*/
|
||||
toHexString(includeDashes = true): string {
|
||||
if (includeDashes) {
|
||||
return [
|
||||
ByteUtils.toHex(this.buffer.subarray(0, 4)),
|
||||
ByteUtils.toHex(this.buffer.subarray(4, 6)),
|
||||
ByteUtils.toHex(this.buffer.subarray(6, 8)),
|
||||
ByteUtils.toHex(this.buffer.subarray(8, 10)),
|
||||
ByteUtils.toHex(this.buffer.subarray(10, 16))
|
||||
].join('-');
|
||||
}
|
||||
return ByteUtils.toHex(this.buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
|
||||
*/
|
||||
toString(encoding?: 'hex' | 'base64'): string {
|
||||
if (encoding === 'hex') return ByteUtils.toHex(this.id);
|
||||
if (encoding === 'base64') return ByteUtils.toBase64(this.id);
|
||||
return this.toHexString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the id into its JSON string representation.
|
||||
* A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
*/
|
||||
toJSON(): string {
|
||||
return this.toHexString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the equality of this UUID with `otherID`.
|
||||
*
|
||||
* @param otherId - UUID instance to compare against.
|
||||
*/
|
||||
equals(otherId: string | Uint8Array | UUID): boolean {
|
||||
if (!otherId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (otherId instanceof UUID) {
|
||||
return ByteUtils.equals(otherId.id, this.id);
|
||||
}
|
||||
|
||||
try {
|
||||
return ByteUtils.equals(new UUID(otherId).id, this.id);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Binary instance from the current UUID.
|
||||
*/
|
||||
toBinary(): Binary {
|
||||
return new Binary(this.id, Binary.SUBTYPE_UUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a populated buffer containing a v4 uuid
|
||||
*/
|
||||
static generate(): Uint8Array {
|
||||
const bytes = ByteUtils.randomBytes(UUID_BYTE_LENGTH);
|
||||
|
||||
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
||||
// Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
|
||||
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
||||
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value is a valid bson UUID
|
||||
* @param input - UUID, string or Buffer to validate.
|
||||
*/
|
||||
static isValid(input: string | Uint8Array | UUID | Binary): boolean {
|
||||
if (!input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof input === 'string') {
|
||||
return UUID.isValidUUIDString(input);
|
||||
}
|
||||
|
||||
if (isUint8Array(input)) {
|
||||
return input.byteLength === UUID_BYTE_LENGTH;
|
||||
}
|
||||
|
||||
return (
|
||||
input._bsontype === 'Binary' &&
|
||||
input.sub_type === this.SUBTYPE_UUID &&
|
||||
input.buffer.byteLength === 16
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an UUID from a hex string representation of an UUID.
|
||||
* @param hexString - 32 or 36 character hex string (dashes excluded/included).
|
||||
*/
|
||||
static override createFromHexString(hexString: string): UUID {
|
||||
const buffer = UUID.bytesFromString(hexString);
|
||||
return new UUID(buffer);
|
||||
}
|
||||
|
||||
/** Creates an UUID from a base64 string representation of an UUID. */
|
||||
static override createFromBase64(base64: string): UUID {
|
||||
return new UUID(ByteUtils.fromBase64(base64));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static bytesFromString(representation: string) {
|
||||
if (!UUID.isValidUUIDString(representation)) {
|
||||
throw new BSONError(
|
||||
'UUID string representation must be 32 hex digits or canonical hyphenated representation'
|
||||
);
|
||||
}
|
||||
return ByteUtils.fromHex(representation.replace(/-/g, ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Validates a string to be a hex digit sequence with or without dashes.
|
||||
* The canonical hyphenated representation of a uuid is hex in 8-4-4-4-12 groups.
|
||||
*/
|
||||
static isValidUUIDString(representation: string) {
|
||||
return UUID_WITHOUT_DASHES.test(representation) || UUID_WITH_DASHES.test(representation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to a string representation of this Id.
|
||||
*
|
||||
* @returns return the 36 character hex string representation.
|
||||
*
|
||||
*/
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
return `new UUID(${inspect(this.toHexString(), options)})`;
|
||||
}
|
||||
}
|
||||
248
node_modules/bson/src/bson.ts
generated
vendored
248
node_modules/bson/src/bson.ts
generated
vendored
|
|
@ -1,248 +0,0 @@
|
|||
import { Binary, UUID } from './binary';
|
||||
import { Code } from './code';
|
||||
import { DBRef } from './db_ref';
|
||||
import { Decimal128 } from './decimal128';
|
||||
import { Double } from './double';
|
||||
import { Int32 } from './int_32';
|
||||
import { Long } from './long';
|
||||
import { MaxKey } from './max_key';
|
||||
import { MinKey } from './min_key';
|
||||
import { ObjectId } from './objectid';
|
||||
import { internalCalculateObjectSize } from './parser/calculate_size';
|
||||
// Parts of the parser
|
||||
import { internalDeserialize, type DeserializeOptions } from './parser/deserializer';
|
||||
import { serializeInto, type SerializeOptions } from './parser/serializer';
|
||||
import { BSONRegExp } from './regexp';
|
||||
import { BSONSymbol } from './symbol';
|
||||
import { Timestamp } from './timestamp';
|
||||
import { ByteUtils } from './utils/byte_utils';
|
||||
import { NumberUtils } from './utils/number_utils';
|
||||
export type { UUIDExtended, BinaryExtended, BinaryExtendedLegacy, BinarySequence } from './binary';
|
||||
export type { CodeExtended } from './code';
|
||||
export type { DBRefLike } from './db_ref';
|
||||
export type { Decimal128Extended } from './decimal128';
|
||||
export type { DoubleExtended } from './double';
|
||||
export type { EJSONOptions } from './extended_json';
|
||||
export type { Int32Extended } from './int_32';
|
||||
export type { LongExtended } from './long';
|
||||
export type { MaxKeyExtended } from './max_key';
|
||||
export type { MinKeyExtended } from './min_key';
|
||||
export type { ObjectIdExtended, ObjectIdLike } from './objectid';
|
||||
export type { BSONRegExpExtended, BSONRegExpExtendedLegacy } from './regexp';
|
||||
export type { BSONSymbolExtended } from './symbol';
|
||||
export type { LongWithoutOverrides, TimestampExtended, TimestampOverrides } from './timestamp';
|
||||
export type { LongWithoutOverridesClass } from './timestamp';
|
||||
export type { SerializeOptions, DeserializeOptions };
|
||||
|
||||
export {
|
||||
Code,
|
||||
BSONSymbol,
|
||||
DBRef,
|
||||
Binary,
|
||||
ObjectId,
|
||||
UUID,
|
||||
Long,
|
||||
Timestamp,
|
||||
Double,
|
||||
Int32,
|
||||
MinKey,
|
||||
MaxKey,
|
||||
BSONRegExp,
|
||||
Decimal128
|
||||
};
|
||||
export { BSONValue, bsonType, type BSONTypeTag } from './bson_value';
|
||||
export { BSONError, BSONVersionError, BSONRuntimeError, BSONOffsetError } from './error';
|
||||
export { BSONType } from './constants';
|
||||
export { EJSON } from './extended_json';
|
||||
export { onDemand, type OnDemand } from './parser/on_demand/index';
|
||||
|
||||
/** @public */
|
||||
export interface Document {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
// Default Max Size
|
||||
const MAXSIZE = 1024 * 1024 * 17;
|
||||
|
||||
// Current Internal Temporary Serialization Buffer
|
||||
let buffer = ByteUtils.allocate(MAXSIZE);
|
||||
|
||||
/**
|
||||
* Sets the size of the internal serialization buffer.
|
||||
*
|
||||
* @param size - The desired size for the internal serialization buffer in bytes
|
||||
* @public
|
||||
*/
|
||||
export function setInternalBufferSize(size: number): void {
|
||||
// Resize the internal serialization buffer if needed
|
||||
if (buffer.length < size) {
|
||||
buffer = ByteUtils.allocate(size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a Javascript object.
|
||||
*
|
||||
* @param object - the Javascript object to serialize.
|
||||
* @returns Buffer object containing the serialized object.
|
||||
* @public
|
||||
*/
|
||||
export function serialize(object: Document, options: SerializeOptions = {}): Uint8Array {
|
||||
// Unpack the options
|
||||
const checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;
|
||||
const serializeFunctions =
|
||||
typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
|
||||
const ignoreUndefined =
|
||||
typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
|
||||
const minInternalBufferSize =
|
||||
typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE;
|
||||
|
||||
// Resize the internal serialization buffer if needed
|
||||
if (buffer.length < minInternalBufferSize) {
|
||||
buffer = ByteUtils.allocate(minInternalBufferSize);
|
||||
}
|
||||
|
||||
// Attempt to serialize
|
||||
const serializationIndex = serializeInto(
|
||||
buffer,
|
||||
object,
|
||||
checkKeys,
|
||||
0,
|
||||
0,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
null
|
||||
);
|
||||
|
||||
// Create the final buffer
|
||||
const finishedBuffer = ByteUtils.allocateUnsafe(serializationIndex);
|
||||
|
||||
// Copy into the finished buffer
|
||||
finishedBuffer.set(buffer.subarray(0, serializationIndex), 0);
|
||||
|
||||
// Return the buffer
|
||||
return finishedBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a Javascript object using a predefined Buffer and index into the buffer,
|
||||
* useful when pre-allocating the space for serialization.
|
||||
*
|
||||
* @param object - the Javascript object to serialize.
|
||||
* @param finalBuffer - the Buffer you pre-allocated to store the serialized BSON object.
|
||||
* @returns the index pointing to the last written byte in the buffer.
|
||||
* @public
|
||||
*/
|
||||
export function serializeWithBufferAndIndex(
|
||||
object: Document,
|
||||
finalBuffer: Uint8Array,
|
||||
options: SerializeOptions = {}
|
||||
): number {
|
||||
// Unpack the options
|
||||
const checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;
|
||||
const serializeFunctions =
|
||||
typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
|
||||
const ignoreUndefined =
|
||||
typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
|
||||
const startIndex = typeof options.index === 'number' ? options.index : 0;
|
||||
|
||||
// Attempt to serialize
|
||||
const serializationIndex = serializeInto(
|
||||
buffer,
|
||||
object,
|
||||
checkKeys,
|
||||
0,
|
||||
0,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
null
|
||||
);
|
||||
|
||||
finalBuffer.set(buffer.subarray(0, serializationIndex), startIndex);
|
||||
|
||||
// Return the index
|
||||
return startIndex + serializationIndex - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize data as BSON.
|
||||
*
|
||||
* @param buffer - the buffer containing the serialized set of BSON documents.
|
||||
* @returns returns the deserialized Javascript Object.
|
||||
* @public
|
||||
*/
|
||||
export function deserialize(buffer: Uint8Array, options: DeserializeOptions = {}): Document {
|
||||
return internalDeserialize(ByteUtils.toLocalBufferType(buffer), options);
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export type CalculateObjectSizeOptions = Pick<
|
||||
SerializeOptions,
|
||||
'serializeFunctions' | 'ignoreUndefined'
|
||||
>;
|
||||
|
||||
/**
|
||||
* Calculate the bson size for a passed in Javascript object.
|
||||
*
|
||||
* @param object - the Javascript object to calculate the BSON byte size for
|
||||
* @returns size of BSON object in bytes
|
||||
* @public
|
||||
*/
|
||||
export function calculateObjectSize(
|
||||
object: Document,
|
||||
options: CalculateObjectSizeOptions = {}
|
||||
): number {
|
||||
options = options || {};
|
||||
|
||||
const serializeFunctions =
|
||||
typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
|
||||
const ignoreUndefined =
|
||||
typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
|
||||
|
||||
return internalCalculateObjectSize(object, serializeFunctions, ignoreUndefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize stream data as BSON documents.
|
||||
*
|
||||
* @param data - the buffer containing the serialized set of BSON documents.
|
||||
* @param startIndex - the start index in the data Buffer where the deserialization is to start.
|
||||
* @param numberOfDocuments - number of documents to deserialize.
|
||||
* @param documents - an array where to store the deserialized documents.
|
||||
* @param docStartIndex - the index in the documents array from where to start inserting documents.
|
||||
* @param options - additional options used for the deserialization.
|
||||
* @returns next index in the buffer after deserialization **x** numbers of documents.
|
||||
* @public
|
||||
*/
|
||||
export function deserializeStream(
|
||||
data: Uint8Array | ArrayBuffer,
|
||||
startIndex: number,
|
||||
numberOfDocuments: number,
|
||||
documents: Document[],
|
||||
docStartIndex: number,
|
||||
options: DeserializeOptions
|
||||
): number {
|
||||
const internalOptions = Object.assign(
|
||||
{ allowObjectSmallerThanBufferSize: true, index: 0 },
|
||||
options
|
||||
);
|
||||
const bufferData = ByteUtils.toLocalBufferType(data);
|
||||
|
||||
let index = startIndex;
|
||||
// Loop over all documents
|
||||
for (let i = 0; i < numberOfDocuments; i++) {
|
||||
// Find size of the document
|
||||
const size = NumberUtils.getInt32LE(bufferData, index);
|
||||
// Update options with index
|
||||
internalOptions.index = index;
|
||||
// Parse the document at this point
|
||||
documents[docStartIndex + i] = internalDeserialize(bufferData, internalOptions);
|
||||
// Adjust index by the document size
|
||||
index = index + size;
|
||||
}
|
||||
|
||||
// Return object containing end index of parsing and list of documents
|
||||
return index;
|
||||
}
|
||||
55
node_modules/bson/src/bson_value.ts
generated
vendored
55
node_modules/bson/src/bson_value.ts
generated
vendored
|
|
@ -1,55 +0,0 @@
|
|||
import { BSON_MAJOR_VERSION } from './constants';
|
||||
import { type InspectFn } from './parser/utils';
|
||||
import { BSON_VERSION_SYMBOL } from './constants';
|
||||
|
||||
/** @public */
|
||||
export type BSONTypeTag =
|
||||
| 'BSONRegExp'
|
||||
| 'BSONSymbol'
|
||||
| 'ObjectId'
|
||||
| 'Binary'
|
||||
| 'Decimal128'
|
||||
| 'Double'
|
||||
| 'Int32'
|
||||
| 'Long'
|
||||
| 'MaxKey'
|
||||
| 'MinKey'
|
||||
| 'Timestamp'
|
||||
| 'Code'
|
||||
| 'DBRef';
|
||||
|
||||
/** @public */
|
||||
export const bsonType = Symbol.for('@@mdb.bson.type');
|
||||
|
||||
/** @public */
|
||||
export abstract class BSONValue {
|
||||
/** @public */
|
||||
public abstract get _bsontype(): BSONTypeTag;
|
||||
|
||||
public get [bsonType](): this['_bsontype'] {
|
||||
return this._bsontype;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
get [BSON_VERSION_SYMBOL](): typeof BSON_MAJOR_VERSION {
|
||||
return BSON_MAJOR_VERSION;
|
||||
}
|
||||
|
||||
[Symbol.for('nodejs.util.inspect.custom')](
|
||||
depth?: number,
|
||||
options?: unknown,
|
||||
inspect?: InspectFn
|
||||
): string {
|
||||
return this.inspect(depth, options, inspect);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* Prints a human-readable string of BSON value information
|
||||
* If invoked manually without node.js.inspect function, this will default to a modified JSON.stringify
|
||||
*/
|
||||
public abstract inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
|
||||
|
||||
/** @internal */
|
||||
abstract toExtendedJSON(): unknown;
|
||||
}
|
||||
69
node_modules/bson/src/code.ts
generated
vendored
69
node_modules/bson/src/code.ts
generated
vendored
|
|
@ -1,69 +0,0 @@
|
|||
import type { Document } from './bson';
|
||||
import { BSONValue } from './bson_value';
|
||||
import { type InspectFn, defaultInspect } from './parser/utils';
|
||||
|
||||
/** @public */
|
||||
export interface CodeExtended {
|
||||
$code: string;
|
||||
$scope?: Document;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON Code type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class Code extends BSONValue {
|
||||
get _bsontype(): 'Code' {
|
||||
return 'Code';
|
||||
}
|
||||
|
||||
code: string;
|
||||
|
||||
// a code instance having a null scope is what determines whether
|
||||
// it is BSONType 0x0D (just code) / 0x0F (code with scope)
|
||||
scope: Document | null;
|
||||
|
||||
/**
|
||||
* @param code - a string or function.
|
||||
* @param scope - an optional scope for the function.
|
||||
*/
|
||||
constructor(code: string | Function, scope?: Document | null) {
|
||||
super();
|
||||
this.code = code.toString();
|
||||
this.scope = scope ?? null;
|
||||
}
|
||||
|
||||
toJSON(): { code: string; scope?: Document } {
|
||||
if (this.scope != null) {
|
||||
return { code: this.code, scope: this.scope };
|
||||
}
|
||||
|
||||
return { code: this.code };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(): CodeExtended {
|
||||
if (this.scope) {
|
||||
return { $code: this.code, $scope: this.scope };
|
||||
}
|
||||
|
||||
return { $code: this.code };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(doc: CodeExtended): Code {
|
||||
return new Code(doc.$code, doc.$scope);
|
||||
}
|
||||
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
let parametersString = inspect(this.code, options);
|
||||
const multiLineFn = parametersString.includes('\n');
|
||||
if (this.scope != null) {
|
||||
parametersString += `,${multiLineFn ? '\n' : ' '}${inspect(this.scope, options)}`;
|
||||
}
|
||||
const endingNewline = multiLineFn && this.scope === null;
|
||||
return `new Code(${multiLineFn ? '\n' : ''}${parametersString}${endingNewline ? '\n' : ''})`;
|
||||
}
|
||||
}
|
||||
147
node_modules/bson/src/constants.ts
generated
vendored
147
node_modules/bson/src/constants.ts
generated
vendored
|
|
@ -1,147 +0,0 @@
|
|||
/** @internal */
|
||||
export const BSON_MAJOR_VERSION = 7;
|
||||
|
||||
/** @internal */
|
||||
export const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
|
||||
|
||||
/** @internal */
|
||||
export const BSON_INT32_MAX = 0x7fffffff;
|
||||
/** @internal */
|
||||
export const BSON_INT32_MIN = -0x80000000;
|
||||
/** @internal */
|
||||
export const BSON_INT64_MAX = Math.pow(2, 63) - 1;
|
||||
/** @internal */
|
||||
export const BSON_INT64_MIN = -Math.pow(2, 63);
|
||||
|
||||
/**
|
||||
* Any integer up to 2^53 can be precisely represented by a double.
|
||||
* @internal
|
||||
*/
|
||||
export const JS_INT_MAX = Math.pow(2, 53);
|
||||
|
||||
/**
|
||||
* Any integer down to -2^53 can be precisely represented by a double.
|
||||
* @internal
|
||||
*/
|
||||
export const JS_INT_MIN = -Math.pow(2, 53);
|
||||
|
||||
/** Number BSON Type @internal */
|
||||
export const BSON_DATA_NUMBER = 1;
|
||||
|
||||
/** String BSON Type @internal */
|
||||
export const BSON_DATA_STRING = 2;
|
||||
|
||||
/** Object BSON Type @internal */
|
||||
export const BSON_DATA_OBJECT = 3;
|
||||
|
||||
/** Array BSON Type @internal */
|
||||
export const BSON_DATA_ARRAY = 4;
|
||||
|
||||
/** Binary BSON Type @internal */
|
||||
export const BSON_DATA_BINARY = 5;
|
||||
|
||||
/** Binary BSON Type @internal */
|
||||
export const BSON_DATA_UNDEFINED = 6;
|
||||
|
||||
/** ObjectId BSON Type @internal */
|
||||
export const BSON_DATA_OID = 7;
|
||||
|
||||
/** Boolean BSON Type @internal */
|
||||
export const BSON_DATA_BOOLEAN = 8;
|
||||
|
||||
/** Date BSON Type @internal */
|
||||
export const BSON_DATA_DATE = 9;
|
||||
|
||||
/** null BSON Type @internal */
|
||||
export const BSON_DATA_NULL = 10;
|
||||
|
||||
/** RegExp BSON Type @internal */
|
||||
export const BSON_DATA_REGEXP = 11;
|
||||
|
||||
/** Code BSON Type @internal */
|
||||
export const BSON_DATA_DBPOINTER = 12;
|
||||
|
||||
/** Code BSON Type @internal */
|
||||
export const BSON_DATA_CODE = 13;
|
||||
|
||||
/** Symbol BSON Type @internal */
|
||||
export const BSON_DATA_SYMBOL = 14;
|
||||
|
||||
/** Code with Scope BSON Type @internal */
|
||||
export const BSON_DATA_CODE_W_SCOPE = 15;
|
||||
|
||||
/** 32 bit Integer BSON Type @internal */
|
||||
export const BSON_DATA_INT = 16;
|
||||
|
||||
/** Timestamp BSON Type @internal */
|
||||
export const BSON_DATA_TIMESTAMP = 17;
|
||||
|
||||
/** Long BSON Type @internal */
|
||||
export const BSON_DATA_LONG = 18;
|
||||
|
||||
/** Decimal128 BSON Type @internal */
|
||||
export const BSON_DATA_DECIMAL128 = 19;
|
||||
|
||||
/** MinKey BSON Type @internal */
|
||||
export const BSON_DATA_MIN_KEY = 0xff;
|
||||
|
||||
/** MaxKey BSON Type @internal */
|
||||
export const BSON_DATA_MAX_KEY = 0x7f;
|
||||
|
||||
/** Binary Default Type @internal */
|
||||
export const BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
||||
|
||||
/** Binary Function Type @internal */
|
||||
export const BSON_BINARY_SUBTYPE_FUNCTION = 1;
|
||||
|
||||
/** Binary Byte Array Type @internal */
|
||||
export const BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
|
||||
|
||||
/** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
|
||||
export const BSON_BINARY_SUBTYPE_UUID = 3;
|
||||
|
||||
/** Binary UUID Type @internal */
|
||||
export const BSON_BINARY_SUBTYPE_UUID_NEW = 4;
|
||||
|
||||
/** Binary MD5 Type @internal */
|
||||
export const BSON_BINARY_SUBTYPE_MD5 = 5;
|
||||
|
||||
/** Encrypted BSON type @internal */
|
||||
export const BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
|
||||
|
||||
/** Column BSON type @internal */
|
||||
export const BSON_BINARY_SUBTYPE_COLUMN = 7;
|
||||
|
||||
/** Sensitive BSON type @internal */
|
||||
export const BSON_BINARY_SUBTYPE_SENSITIVE = 8;
|
||||
|
||||
/** Binary User Defined Type @internal */
|
||||
export const BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
|
||||
|
||||
/** @public */
|
||||
export const BSONType = Object.freeze({
|
||||
double: 1,
|
||||
string: 2,
|
||||
object: 3,
|
||||
array: 4,
|
||||
binData: 5,
|
||||
undefined: 6,
|
||||
objectId: 7,
|
||||
bool: 8,
|
||||
date: 9,
|
||||
null: 10,
|
||||
regex: 11,
|
||||
dbPointer: 12,
|
||||
javascript: 13,
|
||||
symbol: 14,
|
||||
javascriptWithScope: 15,
|
||||
int: 16,
|
||||
timestamp: 17,
|
||||
long: 18,
|
||||
decimal: 19,
|
||||
minKey: -1,
|
||||
maxKey: 127
|
||||
} as const);
|
||||
|
||||
/** @public */
|
||||
export type BSONType = (typeof BSONType)[keyof typeof BSONType];
|
||||
128
node_modules/bson/src/db_ref.ts
generated
vendored
128
node_modules/bson/src/db_ref.ts
generated
vendored
|
|
@ -1,128 +0,0 @@
|
|||
import type { Document } from './bson';
|
||||
import { BSONValue } from './bson_value';
|
||||
import type { EJSONOptions } from './extended_json';
|
||||
import type { ObjectId } from './objectid';
|
||||
import { type InspectFn, defaultInspect } from './parser/utils';
|
||||
|
||||
/** @public */
|
||||
export interface DBRefLike {
|
||||
$ref: string;
|
||||
$id: ObjectId;
|
||||
$db?: string;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function isDBRefLike(value: unknown): value is DBRefLike {
|
||||
return (
|
||||
value != null &&
|
||||
typeof value === 'object' &&
|
||||
'$id' in value &&
|
||||
value.$id != null &&
|
||||
'$ref' in value &&
|
||||
typeof value.$ref === 'string' &&
|
||||
// If '$db' is defined it MUST be a string, otherwise it should be absent
|
||||
(!('$db' in value) || ('$db' in value && typeof value.$db === 'string'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON DBRef type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class DBRef extends BSONValue {
|
||||
get _bsontype(): 'DBRef' {
|
||||
return 'DBRef';
|
||||
}
|
||||
|
||||
collection!: string;
|
||||
oid!: ObjectId;
|
||||
db?: string;
|
||||
fields!: Document;
|
||||
|
||||
/**
|
||||
* @param collection - the collection name.
|
||||
* @param oid - the reference ObjectId.
|
||||
* @param db - optional db name, if omitted the reference is local to the current db.
|
||||
*/
|
||||
constructor(collection: string, oid: ObjectId, db?: string, fields?: Document) {
|
||||
super();
|
||||
// check if namespace has been provided
|
||||
const parts = collection.split('.');
|
||||
if (parts.length === 2) {
|
||||
db = parts.shift();
|
||||
collection = parts.shift()!;
|
||||
}
|
||||
|
||||
this.collection = collection;
|
||||
this.oid = oid;
|
||||
this.db = db;
|
||||
this.fields = fields || {};
|
||||
}
|
||||
|
||||
// Property provided for compatibility with the 1.x parser
|
||||
// the 1.x parser used a "namespace" property, while 4.x uses "collection"
|
||||
|
||||
/** @internal */
|
||||
get namespace(): string {
|
||||
return this.collection;
|
||||
}
|
||||
|
||||
set namespace(value: string) {
|
||||
this.collection = value;
|
||||
}
|
||||
|
||||
toJSON(): DBRefLike & Document {
|
||||
const o = Object.assign(
|
||||
{
|
||||
$ref: this.collection,
|
||||
$id: this.oid
|
||||
},
|
||||
this.fields
|
||||
);
|
||||
|
||||
if (this.db != null) o.$db = this.db;
|
||||
return o;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(options?: EJSONOptions): DBRefLike {
|
||||
options = options || {};
|
||||
let o: DBRefLike = {
|
||||
$ref: this.collection,
|
||||
$id: this.oid
|
||||
};
|
||||
|
||||
if (options.legacy) {
|
||||
return o;
|
||||
}
|
||||
|
||||
if (this.db) o.$db = this.db;
|
||||
o = Object.assign(o, this.fields);
|
||||
return o;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(doc: DBRefLike): DBRef {
|
||||
const copy = Object.assign({}, doc) as Partial<DBRefLike>;
|
||||
delete copy.$ref;
|
||||
delete copy.$id;
|
||||
delete copy.$db;
|
||||
return new DBRef(doc.$ref, doc.$id, doc.$db, copy);
|
||||
}
|
||||
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
|
||||
const args = [
|
||||
inspect(this.namespace, options),
|
||||
inspect(this.oid, options),
|
||||
...(this.db ? [inspect(this.db, options)] : []),
|
||||
...(Object.keys(this.fields).length > 0 ? [inspect(this.fields, options)] : [])
|
||||
];
|
||||
|
||||
args[1] = inspect === defaultInspect ? `new ObjectId(${args[1]})` : args[1];
|
||||
|
||||
return `new DBRef(${args.join(', ')})`;
|
||||
}
|
||||
}
|
||||
855
node_modules/bson/src/decimal128.ts
generated
vendored
855
node_modules/bson/src/decimal128.ts
generated
vendored
|
|
@ -1,855 +0,0 @@
|
|||
import { BSONValue } from './bson_value';
|
||||
import { BSONError } from './error';
|
||||
import { Long } from './long';
|
||||
import { type InspectFn, defaultInspect, isUint8Array } from './parser/utils';
|
||||
import { ByteUtils } from './utils/byte_utils';
|
||||
|
||||
const PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
|
||||
const PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
|
||||
const PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i;
|
||||
|
||||
const EXPONENT_MAX = 6111;
|
||||
const EXPONENT_MIN = -6176;
|
||||
const EXPONENT_BIAS = 6176;
|
||||
const MAX_DIGITS = 34;
|
||||
|
||||
// Nan value bits as 32 bit values (due to lack of longs)
|
||||
const NAN_BUFFER = ByteUtils.fromNumberArray(
|
||||
[
|
||||
0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
].reverse()
|
||||
);
|
||||
// Infinity value bits 32 bit values (due to lack of longs)
|
||||
const INF_NEGATIVE_BUFFER = ByteUtils.fromNumberArray(
|
||||
[
|
||||
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
].reverse()
|
||||
);
|
||||
const INF_POSITIVE_BUFFER = ByteUtils.fromNumberArray(
|
||||
[
|
||||
0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
].reverse()
|
||||
);
|
||||
|
||||
const EXPONENT_REGEX = /^([-+])?(\d+)?$/;
|
||||
|
||||
// Extract least significant 5 bits
|
||||
const COMBINATION_MASK = 0x1f;
|
||||
// Extract least significant 14 bits
|
||||
const EXPONENT_MASK = 0x3fff;
|
||||
// Value of combination field for Inf
|
||||
const COMBINATION_INFINITY = 30;
|
||||
// Value of combination field for NaN
|
||||
const COMBINATION_NAN = 31;
|
||||
|
||||
// Detect if the value is a digit
|
||||
function isDigit(value: string): boolean {
|
||||
return !isNaN(parseInt(value, 10));
|
||||
}
|
||||
|
||||
// Divide two uint128 values
|
||||
function divideu128(value: { parts: [number, number, number, number] }) {
|
||||
const DIVISOR = Long.fromNumber(1000 * 1000 * 1000);
|
||||
let _rem = Long.fromNumber(0);
|
||||
|
||||
if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
|
||||
return { quotient: value, rem: _rem };
|
||||
}
|
||||
|
||||
for (let i = 0; i <= 3; i++) {
|
||||
// Adjust remainder to match value of next dividend
|
||||
_rem = _rem.shiftLeft(32);
|
||||
// Add the divided to _rem
|
||||
_rem = _rem.add(new Long(value.parts[i], 0));
|
||||
value.parts[i] = _rem.div(DIVISOR).low;
|
||||
_rem = _rem.modulo(DIVISOR);
|
||||
}
|
||||
|
||||
return { quotient: value, rem: _rem };
|
||||
}
|
||||
|
||||
// Multiply two Long values and return the 128 bit value
|
||||
function multiply64x2(left: Long, right: Long): { high: Long; low: Long } {
|
||||
if (!left && !right) {
|
||||
return { high: Long.fromNumber(0), low: Long.fromNumber(0) };
|
||||
}
|
||||
|
||||
const leftHigh = left.shiftRightUnsigned(32);
|
||||
const leftLow = new Long(left.getLowBits(), 0);
|
||||
const rightHigh = right.shiftRightUnsigned(32);
|
||||
const rightLow = new Long(right.getLowBits(), 0);
|
||||
|
||||
let productHigh = leftHigh.multiply(rightHigh);
|
||||
let productMid = leftHigh.multiply(rightLow);
|
||||
const productMid2 = leftLow.multiply(rightHigh);
|
||||
let productLow = leftLow.multiply(rightLow);
|
||||
|
||||
productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
|
||||
productMid = new Long(productMid.getLowBits(), 0)
|
||||
.add(productMid2)
|
||||
.add(productLow.shiftRightUnsigned(32));
|
||||
|
||||
productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
|
||||
productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0));
|
||||
|
||||
// Return the 128 bit result
|
||||
return { high: productHigh, low: productLow };
|
||||
}
|
||||
|
||||
function lessThan(left: Long, right: Long): boolean {
|
||||
// Make values unsigned
|
||||
const uhleft = left.high >>> 0;
|
||||
const uhright = right.high >>> 0;
|
||||
|
||||
// Compare high bits first
|
||||
if (uhleft < uhright) {
|
||||
return true;
|
||||
} else if (uhleft === uhright) {
|
||||
const ulleft = left.low >>> 0;
|
||||
const ulright = right.low >>> 0;
|
||||
if (ulleft < ulright) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function invalidErr(string: string, message: string) {
|
||||
throw new BSONError(`"${string}" is not a valid Decimal128 string - ${message}`);
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface Decimal128Extended {
|
||||
$numberDecimal: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON Decimal128 type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class Decimal128 extends BSONValue {
|
||||
get _bsontype(): 'Decimal128' {
|
||||
return 'Decimal128';
|
||||
}
|
||||
|
||||
readonly bytes!: Uint8Array;
|
||||
|
||||
/**
|
||||
* @param bytes - a buffer containing the raw Decimal128 bytes in little endian order,
|
||||
* or a string representation as returned by .toString()
|
||||
*/
|
||||
constructor(bytes: Uint8Array | string) {
|
||||
super();
|
||||
if (typeof bytes === 'string') {
|
||||
this.bytes = Decimal128.fromString(bytes).bytes;
|
||||
} else if (bytes instanceof Uint8Array || isUint8Array(bytes)) {
|
||||
if (bytes.byteLength !== 16) {
|
||||
throw new BSONError('Decimal128 must take a Buffer of 16 bytes');
|
||||
}
|
||||
this.bytes = bytes;
|
||||
} else {
|
||||
throw new BSONError('Decimal128 must take a Buffer or string');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Decimal128 instance from a string representation
|
||||
*
|
||||
* @param representation - a numeric string representation.
|
||||
*/
|
||||
static fromString(representation: string): Decimal128 {
|
||||
return Decimal128._fromString(representation, { allowRounding: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Decimal128 instance from a string representation, allowing for rounding to 34
|
||||
* significant digits
|
||||
*
|
||||
* @example Example of a number that will be rounded
|
||||
* ```ts
|
||||
* > let d = Decimal128.fromString('37.499999999999999196428571428571375')
|
||||
* Uncaught:
|
||||
* BSONError: "37.499999999999999196428571428571375" is not a valid Decimal128 string - inexact rounding
|
||||
* at invalidErr (/home/wajames/js-bson/lib/bson.cjs:1402:11)
|
||||
* at Decimal128.fromStringInternal (/home/wajames/js-bson/lib/bson.cjs:1633:25)
|
||||
* at Decimal128.fromString (/home/wajames/js-bson/lib/bson.cjs:1424:27)
|
||||
*
|
||||
* > d = Decimal128.fromStringWithRounding('37.499999999999999196428571428571375')
|
||||
* new Decimal128("37.49999999999999919642857142857138")
|
||||
* ```
|
||||
* @param representation - a numeric string representation.
|
||||
*/
|
||||
static fromStringWithRounding(representation: string): Decimal128 {
|
||||
return Decimal128._fromString(representation, { allowRounding: true });
|
||||
}
|
||||
|
||||
private static _fromString(representation: string, options: { allowRounding: boolean }) {
|
||||
// Parse state tracking
|
||||
let isNegative = false;
|
||||
let sawSign = false;
|
||||
let sawRadix = false;
|
||||
let foundNonZero = false;
|
||||
|
||||
// Total number of significant digits (no leading or trailing zero)
|
||||
let significantDigits = 0;
|
||||
// Total number of significand digits read
|
||||
let nDigitsRead = 0;
|
||||
// Total number of digits (no leading zeros)
|
||||
let nDigits = 0;
|
||||
// The number of the digits after radix
|
||||
let radixPosition = 0;
|
||||
// The index of the first non-zero in *str*
|
||||
let firstNonZero = 0;
|
||||
|
||||
// Digits Array
|
||||
const digits = [0];
|
||||
// The number of digits in digits
|
||||
let nDigitsStored = 0;
|
||||
// Insertion pointer for digits
|
||||
let digitsInsert = 0;
|
||||
// The index of the last digit
|
||||
let lastDigit = 0;
|
||||
|
||||
// Exponent
|
||||
let exponent = 0;
|
||||
// The high 17 digits of the significand
|
||||
let significandHigh = new Long(0, 0);
|
||||
// The low 17 digits of the significand
|
||||
let significandLow = new Long(0, 0);
|
||||
// The biased exponent
|
||||
let biasedExponent = 0;
|
||||
|
||||
// Read index
|
||||
let index = 0;
|
||||
|
||||
// Naively prevent against REDOS attacks.
|
||||
// TODO: implementing a custom parsing for this, or refactoring the regex would yield
|
||||
// further gains.
|
||||
if (representation.length >= 7000) {
|
||||
throw new BSONError('' + representation + ' not a valid Decimal128 string');
|
||||
}
|
||||
|
||||
// Results
|
||||
const stringMatch = representation.match(PARSE_STRING_REGEXP);
|
||||
const infMatch = representation.match(PARSE_INF_REGEXP);
|
||||
const nanMatch = representation.match(PARSE_NAN_REGEXP);
|
||||
|
||||
// Validate the string
|
||||
if ((!stringMatch && !infMatch && !nanMatch) || representation.length === 0) {
|
||||
throw new BSONError('' + representation + ' not a valid Decimal128 string');
|
||||
}
|
||||
|
||||
if (stringMatch) {
|
||||
// full_match = stringMatch[0]
|
||||
// sign = stringMatch[1]
|
||||
|
||||
const unsignedNumber = stringMatch[2];
|
||||
// stringMatch[3] is undefined if a whole number (ex "1", 12")
|
||||
// but defined if a number w/ decimal in it (ex "1.0, 12.2")
|
||||
|
||||
const e = stringMatch[4];
|
||||
const expSign = stringMatch[5];
|
||||
const expNumber = stringMatch[6];
|
||||
|
||||
// they provided e, but didn't give an exponent number. for ex "1e"
|
||||
if (e && expNumber === undefined) invalidErr(representation, 'missing exponent power');
|
||||
|
||||
// they provided e, but didn't give a number before it. for ex "e1"
|
||||
if (e && unsignedNumber === undefined) invalidErr(representation, 'missing exponent base');
|
||||
|
||||
if (e === undefined && (expSign || expNumber)) {
|
||||
invalidErr(representation, 'missing e before exponent');
|
||||
}
|
||||
}
|
||||
|
||||
// Get the negative or positive sign
|
||||
if (representation[index] === '+' || representation[index] === '-') {
|
||||
sawSign = true;
|
||||
isNegative = representation[index++] === '-';
|
||||
}
|
||||
|
||||
// Check if user passed Infinity or NaN
|
||||
if (!isDigit(representation[index]) && representation[index] !== '.') {
|
||||
if (representation[index] === 'i' || representation[index] === 'I') {
|
||||
return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
|
||||
} else if (representation[index] === 'N') {
|
||||
return new Decimal128(NAN_BUFFER);
|
||||
}
|
||||
}
|
||||
|
||||
// Read all the digits
|
||||
while (isDigit(representation[index]) || representation[index] === '.') {
|
||||
if (representation[index] === '.') {
|
||||
if (sawRadix) invalidErr(representation, 'contains multiple periods');
|
||||
|
||||
sawRadix = true;
|
||||
index = index + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nDigitsStored < MAX_DIGITS) {
|
||||
if (representation[index] !== '0' || foundNonZero) {
|
||||
if (!foundNonZero) {
|
||||
firstNonZero = nDigitsRead;
|
||||
}
|
||||
|
||||
foundNonZero = true;
|
||||
|
||||
// Only store 34 digits
|
||||
digits[digitsInsert++] = parseInt(representation[index], 10);
|
||||
nDigitsStored = nDigitsStored + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundNonZero) nDigits = nDigits + 1;
|
||||
if (sawRadix) radixPosition = radixPosition + 1;
|
||||
|
||||
nDigitsRead = nDigitsRead + 1;
|
||||
index = index + 1;
|
||||
}
|
||||
|
||||
if (sawRadix && !nDigitsRead)
|
||||
throw new BSONError('' + representation + ' not a valid Decimal128 string');
|
||||
|
||||
// Read exponent if exists
|
||||
if (representation[index] === 'e' || representation[index] === 'E') {
|
||||
// Read exponent digits
|
||||
const match = representation.substr(++index).match(EXPONENT_REGEX);
|
||||
|
||||
// No digits read
|
||||
if (!match || !match[2]) return new Decimal128(NAN_BUFFER);
|
||||
|
||||
// Get exponent
|
||||
exponent = parseInt(match[0], 10);
|
||||
|
||||
// Adjust the index
|
||||
index = index + match[0].length;
|
||||
}
|
||||
|
||||
// Return not a number
|
||||
if (representation[index]) return new Decimal128(NAN_BUFFER);
|
||||
|
||||
// Done reading input
|
||||
// Find first non-zero digit in digits
|
||||
if (!nDigitsStored) {
|
||||
digits[0] = 0;
|
||||
nDigits = 1;
|
||||
nDigitsStored = 1;
|
||||
significantDigits = 0;
|
||||
} else {
|
||||
lastDigit = nDigitsStored - 1;
|
||||
significantDigits = nDigits;
|
||||
if (significantDigits !== 1) {
|
||||
while (
|
||||
representation[
|
||||
firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)
|
||||
] === '0'
|
||||
) {
|
||||
significantDigits = significantDigits - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normalization of exponent
|
||||
// Correct exponent based on radix position, and shift significand as needed
|
||||
// to represent user input
|
||||
|
||||
// Overflow prevention
|
||||
if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
|
||||
exponent = EXPONENT_MIN;
|
||||
} else {
|
||||
exponent = exponent - radixPosition;
|
||||
}
|
||||
|
||||
// Attempt to normalize the exponent
|
||||
while (exponent > EXPONENT_MAX) {
|
||||
// Shift exponent to significand and decrease
|
||||
lastDigit = lastDigit + 1;
|
||||
if (lastDigit >= MAX_DIGITS) {
|
||||
// Check if we have a zero then just hard clamp, otherwise fail
|
||||
if (significantDigits === 0) {
|
||||
exponent = EXPONENT_MAX;
|
||||
break;
|
||||
}
|
||||
|
||||
invalidErr(representation, 'overflow');
|
||||
}
|
||||
exponent = exponent - 1;
|
||||
}
|
||||
|
||||
if (options.allowRounding) {
|
||||
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
|
||||
// Shift last digit. can only do this if < significant digits than # stored.
|
||||
if (lastDigit === 0 && significantDigits < nDigitsStored) {
|
||||
exponent = EXPONENT_MIN;
|
||||
significantDigits = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (nDigitsStored < nDigits) {
|
||||
// adjust to match digits not stored
|
||||
nDigits = nDigits - 1;
|
||||
} else {
|
||||
// adjust to round
|
||||
lastDigit = lastDigit - 1;
|
||||
}
|
||||
|
||||
if (exponent < EXPONENT_MAX) {
|
||||
exponent = exponent + 1;
|
||||
} else {
|
||||
// Check if we have a zero then just hard clamp, otherwise fail
|
||||
const digitsString = digits.join('');
|
||||
if (digitsString.match(/^0+$/)) {
|
||||
exponent = EXPONENT_MAX;
|
||||
break;
|
||||
}
|
||||
invalidErr(representation, 'overflow');
|
||||
}
|
||||
}
|
||||
|
||||
// Round
|
||||
// We've normalized the exponent, but might still need to round.
|
||||
if (lastDigit + 1 < significantDigits) {
|
||||
let endOfString = nDigitsRead;
|
||||
|
||||
// If we have seen a radix point, 'string' is 1 longer than we have
|
||||
// documented with ndigits_read, so inc the position of the first nonzero
|
||||
// digit and the position that digits are read to.
|
||||
if (sawRadix) {
|
||||
firstNonZero = firstNonZero + 1;
|
||||
endOfString = endOfString + 1;
|
||||
}
|
||||
// if negative, we need to increment again to account for - sign at start.
|
||||
if (sawSign) {
|
||||
firstNonZero = firstNonZero + 1;
|
||||
endOfString = endOfString + 1;
|
||||
}
|
||||
|
||||
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
|
||||
let roundBit = 0;
|
||||
|
||||
if (roundDigit >= 5) {
|
||||
roundBit = 1;
|
||||
if (roundDigit === 5) {
|
||||
roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
|
||||
for (let i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
|
||||
if (parseInt(representation[i], 10)) {
|
||||
roundBit = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (roundBit) {
|
||||
let dIdx = lastDigit;
|
||||
|
||||
for (; dIdx >= 0; dIdx--) {
|
||||
if (++digits[dIdx] > 9) {
|
||||
digits[dIdx] = 0;
|
||||
|
||||
// overflowed most significant digit
|
||||
if (dIdx === 0) {
|
||||
if (exponent < EXPONENT_MAX) {
|
||||
exponent = exponent + 1;
|
||||
digits[dIdx] = 1;
|
||||
} else {
|
||||
return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
|
||||
// Shift last digit. can only do this if < significant digits than # stored.
|
||||
if (lastDigit === 0) {
|
||||
if (significantDigits === 0) {
|
||||
exponent = EXPONENT_MIN;
|
||||
break;
|
||||
}
|
||||
|
||||
invalidErr(representation, 'exponent underflow');
|
||||
}
|
||||
|
||||
if (nDigitsStored < nDigits) {
|
||||
if (
|
||||
representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
|
||||
significantDigits !== 0
|
||||
) {
|
||||
invalidErr(representation, 'inexact rounding');
|
||||
}
|
||||
// adjust to match digits not stored
|
||||
nDigits = nDigits - 1;
|
||||
} else {
|
||||
if (digits[lastDigit] !== 0) {
|
||||
invalidErr(representation, 'inexact rounding');
|
||||
}
|
||||
// adjust to round
|
||||
lastDigit = lastDigit - 1;
|
||||
}
|
||||
|
||||
if (exponent < EXPONENT_MAX) {
|
||||
exponent = exponent + 1;
|
||||
} else {
|
||||
invalidErr(representation, 'overflow');
|
||||
}
|
||||
}
|
||||
|
||||
// Round
|
||||
// We've normalized the exponent, but might still need to round.
|
||||
if (lastDigit + 1 < significantDigits) {
|
||||
// If we have seen a radix point, 'string' is 1 longer than we have
|
||||
// documented with ndigits_read, so inc the position of the first nonzero
|
||||
// digit and the position that digits are read to.
|
||||
if (sawRadix) {
|
||||
firstNonZero = firstNonZero + 1;
|
||||
}
|
||||
// if saw sign, we need to increment again to account for - or + sign at start.
|
||||
if (sawSign) {
|
||||
firstNonZero = firstNonZero + 1;
|
||||
}
|
||||
|
||||
const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
|
||||
|
||||
if (roundDigit !== 0) {
|
||||
invalidErr(representation, 'inexact rounding');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Encode significand
|
||||
// The high 17 digits of the significand
|
||||
significandHigh = Long.fromNumber(0);
|
||||
// The low 17 digits of the significand
|
||||
significandLow = Long.fromNumber(0);
|
||||
|
||||
// read a zero
|
||||
if (significantDigits === 0) {
|
||||
significandHigh = Long.fromNumber(0);
|
||||
significandLow = Long.fromNumber(0);
|
||||
} else if (lastDigit < 17) {
|
||||
let dIdx = 0;
|
||||
significandLow = Long.fromNumber(digits[dIdx++]);
|
||||
significandHigh = new Long(0, 0);
|
||||
|
||||
for (; dIdx <= lastDigit; dIdx++) {
|
||||
significandLow = significandLow.multiply(Long.fromNumber(10));
|
||||
significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
|
||||
}
|
||||
} else {
|
||||
let dIdx = 0;
|
||||
significandHigh = Long.fromNumber(digits[dIdx++]);
|
||||
|
||||
for (; dIdx <= lastDigit - 17; dIdx++) {
|
||||
significandHigh = significandHigh.multiply(Long.fromNumber(10));
|
||||
significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx]));
|
||||
}
|
||||
|
||||
significandLow = Long.fromNumber(digits[dIdx++]);
|
||||
|
||||
for (; dIdx <= lastDigit; dIdx++) {
|
||||
significandLow = significandLow.multiply(Long.fromNumber(10));
|
||||
significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
|
||||
}
|
||||
}
|
||||
|
||||
const significand = multiply64x2(significandHigh, Long.fromString('100000000000000000'));
|
||||
significand.low = significand.low.add(significandLow);
|
||||
|
||||
if (lessThan(significand.low, significandLow)) {
|
||||
significand.high = significand.high.add(Long.fromNumber(1));
|
||||
}
|
||||
|
||||
// Biased exponent
|
||||
biasedExponent = exponent + EXPONENT_BIAS;
|
||||
const dec = { low: Long.fromNumber(0), high: Long.fromNumber(0) };
|
||||
|
||||
// Encode combination, exponent, and significand.
|
||||
if (
|
||||
significand.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))
|
||||
) {
|
||||
// Encode '11' into bits 1 to 3
|
||||
dec.high = dec.high.or(Long.fromNumber(0x3).shiftLeft(61));
|
||||
dec.high = dec.high.or(
|
||||
Long.fromNumber(biasedExponent).and(Long.fromNumber(0x3fff).shiftLeft(47))
|
||||
);
|
||||
dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x7fffffffffff)));
|
||||
} else {
|
||||
dec.high = dec.high.or(Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49));
|
||||
dec.high = dec.high.or(significand.high.and(Long.fromNumber(0x1ffffffffffff)));
|
||||
}
|
||||
|
||||
dec.low = significand.low;
|
||||
|
||||
// Encode sign
|
||||
if (isNegative) {
|
||||
dec.high = dec.high.or(Long.fromString('9223372036854775808'));
|
||||
}
|
||||
|
||||
// Encode into a buffer
|
||||
const buffer = ByteUtils.allocateUnsafe(16);
|
||||
index = 0;
|
||||
|
||||
// Encode the low 64 bits of the decimal
|
||||
// Encode low bits
|
||||
buffer[index++] = dec.low.low & 0xff;
|
||||
buffer[index++] = (dec.low.low >> 8) & 0xff;
|
||||
buffer[index++] = (dec.low.low >> 16) & 0xff;
|
||||
buffer[index++] = (dec.low.low >> 24) & 0xff;
|
||||
// Encode high bits
|
||||
buffer[index++] = dec.low.high & 0xff;
|
||||
buffer[index++] = (dec.low.high >> 8) & 0xff;
|
||||
buffer[index++] = (dec.low.high >> 16) & 0xff;
|
||||
buffer[index++] = (dec.low.high >> 24) & 0xff;
|
||||
|
||||
// Encode the high 64 bits of the decimal
|
||||
// Encode low bits
|
||||
buffer[index++] = dec.high.low & 0xff;
|
||||
buffer[index++] = (dec.high.low >> 8) & 0xff;
|
||||
buffer[index++] = (dec.high.low >> 16) & 0xff;
|
||||
buffer[index++] = (dec.high.low >> 24) & 0xff;
|
||||
// Encode high bits
|
||||
buffer[index++] = dec.high.high & 0xff;
|
||||
buffer[index++] = (dec.high.high >> 8) & 0xff;
|
||||
buffer[index++] = (dec.high.high >> 16) & 0xff;
|
||||
buffer[index++] = (dec.high.high >> 24) & 0xff;
|
||||
|
||||
// Return the new Decimal128
|
||||
return new Decimal128(buffer);
|
||||
}
|
||||
/** Create a string representation of the raw Decimal128 value */
|
||||
toString(): string {
|
||||
// Note: bits in this routine are referred to starting at 0,
|
||||
// from the sign bit, towards the coefficient.
|
||||
|
||||
// decoded biased exponent (14 bits)
|
||||
let biased_exponent;
|
||||
// the number of significand digits
|
||||
let significand_digits = 0;
|
||||
// the base-10 digits in the significand
|
||||
const significand = new Array<number>(36);
|
||||
for (let i = 0; i < significand.length; i++) significand[i] = 0;
|
||||
// read pointer into significand
|
||||
let index = 0;
|
||||
|
||||
// true if the number is zero
|
||||
let is_zero = false;
|
||||
|
||||
// the most significant significand bits (50-46)
|
||||
let significand_msb;
|
||||
// temporary storage for significand decoding
|
||||
let significand128: { parts: [number, number, number, number] } = { parts: [0, 0, 0, 0] };
|
||||
// indexing variables
|
||||
let j, k;
|
||||
|
||||
// Output string
|
||||
const string: string[] = [];
|
||||
|
||||
// Unpack index
|
||||
index = 0;
|
||||
|
||||
// Buffer reference
|
||||
const buffer = this.bytes;
|
||||
|
||||
// Unpack the low 64bits into a long
|
||||
// bits 96 - 127
|
||||
const low =
|
||||
buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
|
||||
// bits 64 - 95
|
||||
const midl =
|
||||
buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
|
||||
|
||||
// Unpack the high 64bits into a long
|
||||
// bits 32 - 63
|
||||
const midh =
|
||||
buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
|
||||
// bits 0 - 31
|
||||
const high =
|
||||
buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
|
||||
|
||||
// Unpack index
|
||||
index = 0;
|
||||
|
||||
// Create the state of the decimal
|
||||
const dec = {
|
||||
low: new Long(low, midl),
|
||||
high: new Long(midh, high)
|
||||
};
|
||||
|
||||
if (dec.high.lessThan(Long.ZERO)) {
|
||||
string.push('-');
|
||||
}
|
||||
|
||||
// Decode combination field and exponent
|
||||
// bits 1 - 5
|
||||
const combination = (high >> 26) & COMBINATION_MASK;
|
||||
|
||||
if (combination >> 3 === 3) {
|
||||
// Check for 'special' values
|
||||
if (combination === COMBINATION_INFINITY) {
|
||||
return string.join('') + 'Infinity';
|
||||
} else if (combination === COMBINATION_NAN) {
|
||||
return 'NaN';
|
||||
} else {
|
||||
biased_exponent = (high >> 15) & EXPONENT_MASK;
|
||||
significand_msb = 0x08 + ((high >> 14) & 0x01);
|
||||
}
|
||||
} else {
|
||||
significand_msb = (high >> 14) & 0x07;
|
||||
biased_exponent = (high >> 17) & EXPONENT_MASK;
|
||||
}
|
||||
|
||||
// unbiased exponent
|
||||
const exponent = biased_exponent - EXPONENT_BIAS;
|
||||
|
||||
// Create string of significand digits
|
||||
|
||||
// Convert the 114-bit binary number represented by
|
||||
// (significand_high, significand_low) to at most 34 decimal
|
||||
// digits through modulo and division.
|
||||
significand128.parts[0] = (high & 0x3fff) + ((significand_msb & 0xf) << 14);
|
||||
significand128.parts[1] = midh;
|
||||
significand128.parts[2] = midl;
|
||||
significand128.parts[3] = low;
|
||||
|
||||
if (
|
||||
significand128.parts[0] === 0 &&
|
||||
significand128.parts[1] === 0 &&
|
||||
significand128.parts[2] === 0 &&
|
||||
significand128.parts[3] === 0
|
||||
) {
|
||||
is_zero = true;
|
||||
} else {
|
||||
for (k = 3; k >= 0; k--) {
|
||||
let least_digits = 0;
|
||||
// Perform the divide
|
||||
const result = divideu128(significand128);
|
||||
significand128 = result.quotient;
|
||||
least_digits = result.rem.low;
|
||||
|
||||
// We now have the 9 least significant digits (in base 2).
|
||||
// Convert and output to string.
|
||||
if (!least_digits) continue;
|
||||
|
||||
for (j = 8; j >= 0; j--) {
|
||||
// significand[k * 9 + j] = Math.round(least_digits % 10);
|
||||
significand[k * 9 + j] = least_digits % 10;
|
||||
// least_digits = Math.round(least_digits / 10);
|
||||
least_digits = Math.floor(least_digits / 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output format options:
|
||||
// Scientific - [-]d.dddE(+/-)dd or [-]dE(+/-)dd
|
||||
// Regular - ddd.ddd
|
||||
|
||||
if (is_zero) {
|
||||
significand_digits = 1;
|
||||
significand[index] = 0;
|
||||
} else {
|
||||
significand_digits = 36;
|
||||
while (!significand[index]) {
|
||||
significand_digits = significand_digits - 1;
|
||||
index = index + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// the exponent if scientific notation is used
|
||||
const scientific_exponent = significand_digits - 1 + exponent;
|
||||
|
||||
// The scientific exponent checks are dictated by the string conversion
|
||||
// specification and are somewhat arbitrary cutoffs.
|
||||
//
|
||||
// We must check exponent > 0, because if this is the case, the number
|
||||
// has trailing zeros. However, we *cannot* output these trailing zeros,
|
||||
// because doing so would change the precision of the value, and would
|
||||
// change stored data if the string converted number is round tripped.
|
||||
if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) {
|
||||
// Scientific format
|
||||
|
||||
// if there are too many significant digits, we should just be treating numbers
|
||||
// as + or - 0 and using the non-scientific exponent (this is for the "invalid
|
||||
// representation should be treated as 0/-0" spec cases in decimal128-1.json)
|
||||
if (significand_digits > 34) {
|
||||
string.push(`${0}`);
|
||||
if (exponent > 0) string.push(`E+${exponent}`);
|
||||
else if (exponent < 0) string.push(`E${exponent}`);
|
||||
return string.join('');
|
||||
}
|
||||
|
||||
string.push(`${significand[index++]}`);
|
||||
significand_digits = significand_digits - 1;
|
||||
|
||||
if (significand_digits) {
|
||||
string.push('.');
|
||||
}
|
||||
|
||||
for (let i = 0; i < significand_digits; i++) {
|
||||
string.push(`${significand[index++]}`);
|
||||
}
|
||||
|
||||
// Exponent
|
||||
string.push('E');
|
||||
if (scientific_exponent > 0) {
|
||||
string.push(`+${scientific_exponent}`);
|
||||
} else {
|
||||
string.push(`${scientific_exponent}`);
|
||||
}
|
||||
} else {
|
||||
// Regular format with no decimal place
|
||||
if (exponent >= 0) {
|
||||
for (let i = 0; i < significand_digits; i++) {
|
||||
string.push(`${significand[index++]}`);
|
||||
}
|
||||
} else {
|
||||
let radix_position = significand_digits + exponent;
|
||||
|
||||
// non-zero digits before radix
|
||||
if (radix_position > 0) {
|
||||
for (let i = 0; i < radix_position; i++) {
|
||||
string.push(`${significand[index++]}`);
|
||||
}
|
||||
} else {
|
||||
string.push('0');
|
||||
}
|
||||
|
||||
string.push('.');
|
||||
// add leading zeros after radix
|
||||
while (radix_position++ < 0) {
|
||||
string.push('0');
|
||||
}
|
||||
|
||||
for (let i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
|
||||
string.push(`${significand[index++]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string.join('');
|
||||
}
|
||||
|
||||
toJSON(): Decimal128Extended {
|
||||
return { $numberDecimal: this.toString() };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(): Decimal128Extended {
|
||||
return { $numberDecimal: this.toString() };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(doc: Decimal128Extended): Decimal128 {
|
||||
return Decimal128.fromString(doc.$numberDecimal);
|
||||
}
|
||||
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
const d128string = inspect(this.toString(), options);
|
||||
return `new Decimal128(${d128string})`;
|
||||
}
|
||||
}
|
||||
115
node_modules/bson/src/double.ts
generated
vendored
115
node_modules/bson/src/double.ts
generated
vendored
|
|
@ -1,115 +0,0 @@
|
|||
import { BSONValue } from './bson_value';
|
||||
import { BSONError } from './error';
|
||||
import type { EJSONOptions } from './extended_json';
|
||||
import { type InspectFn, defaultInspect } from './parser/utils';
|
||||
|
||||
/** @public */
|
||||
export interface DoubleExtended {
|
||||
$numberDouble: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON Double type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class Double extends BSONValue {
|
||||
get _bsontype(): 'Double' {
|
||||
return 'Double';
|
||||
}
|
||||
|
||||
value!: number;
|
||||
/**
|
||||
* Create a Double type
|
||||
*
|
||||
* @param value - the number we want to represent as a double.
|
||||
*/
|
||||
constructor(value: number) {
|
||||
super();
|
||||
if ((value as unknown) instanceof Number) {
|
||||
value = value.valueOf();
|
||||
}
|
||||
|
||||
this.value = +value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to create an double type from string.
|
||||
*
|
||||
* This method will throw a BSONError on any string input that is not representable as a IEEE-754 64-bit double.
|
||||
* Notably, this method will also throw on the following string formats:
|
||||
* - Strings in non-decimal and non-exponential formats (binary, hex, or octal digits)
|
||||
* - Strings with characters other than numeric, floating point, or leading sign characters (Note: 'Infinity', '-Infinity', and 'NaN' input strings are still allowed)
|
||||
* - Strings with leading and/or trailing whitespace
|
||||
*
|
||||
* Strings with leading zeros, however, are also allowed
|
||||
*
|
||||
* @param value - the string we want to represent as a double.
|
||||
*/
|
||||
static fromString(value: string): Double {
|
||||
const coercedValue = Number(value);
|
||||
|
||||
if (value === 'NaN') return new Double(NaN);
|
||||
if (value === 'Infinity') return new Double(Infinity);
|
||||
if (value === '-Infinity') return new Double(-Infinity);
|
||||
|
||||
if (!Number.isFinite(coercedValue)) {
|
||||
throw new BSONError(`Input: ${value} is not representable as a Double`);
|
||||
}
|
||||
if (value.trim() !== value) {
|
||||
throw new BSONError(`Input: '${value}' contains whitespace`);
|
||||
}
|
||||
if (value === '') {
|
||||
throw new BSONError(`Input is an empty string`);
|
||||
}
|
||||
if (/[^-0-9.+eE]/.test(value)) {
|
||||
throw new BSONError(`Input: '${value}' is not in decimal or exponential notation`);
|
||||
}
|
||||
return new Double(coercedValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Access the number value.
|
||||
*
|
||||
* @returns returns the wrapped double number.
|
||||
*/
|
||||
valueOf(): number {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
toJSON(): number {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
toString(radix?: number): string {
|
||||
return this.value.toString(radix);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(options?: EJSONOptions): number | DoubleExtended {
|
||||
if (options && (options.legacy || (options.relaxed && isFinite(this.value)))) {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
if (Object.is(Math.sign(this.value), -0)) {
|
||||
// NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
|
||||
// explicitly provided `-0` then we need to ensure the sign makes it into the output
|
||||
return { $numberDouble: '-0.0' };
|
||||
}
|
||||
|
||||
return {
|
||||
$numberDouble: Number.isInteger(this.value) ? this.value.toFixed(1) : this.value.toString()
|
||||
};
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(doc: DoubleExtended, options?: EJSONOptions): number | Double {
|
||||
const doubleValue = parseFloat(doc.$numberDouble);
|
||||
return options && options.relaxed ? doubleValue : new Double(doubleValue);
|
||||
}
|
||||
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
return `new Double(${inspect(this.value, options)})`;
|
||||
}
|
||||
}
|
||||
105
node_modules/bson/src/error.ts
generated
vendored
105
node_modules/bson/src/error.ts
generated
vendored
|
|
@ -1,105 +0,0 @@
|
|||
import { BSON_MAJOR_VERSION } from './constants';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @category Error
|
||||
*
|
||||
* `BSONError` objects are thrown when BSON encounters an error.
|
||||
*
|
||||
* This is the parent class for all the other errors thrown by this library.
|
||||
*/
|
||||
export class BSONError extends Error {
|
||||
/**
|
||||
* @internal
|
||||
* The underlying algorithm for isBSONError may change to improve how strict it is
|
||||
* about determining if an input is a BSONError. But it must remain backwards compatible
|
||||
* with previous minors & patches of the current major version.
|
||||
*/
|
||||
protected get bsonError(): true {
|
||||
return true;
|
||||
}
|
||||
|
||||
override get name(): string {
|
||||
return 'BSONError';
|
||||
}
|
||||
|
||||
constructor(message: string, options?: { cause?: unknown }) {
|
||||
super(message, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* All errors thrown from the BSON library inherit from `BSONError`.
|
||||
* This method can assist with determining if an error originates from the BSON library
|
||||
* even if it does not pass an `instanceof` check against this class' constructor.
|
||||
*
|
||||
* @param value - any javascript value that needs type checking
|
||||
*/
|
||||
public static isBSONError(value: unknown): value is BSONError {
|
||||
return (
|
||||
value != null &&
|
||||
typeof value === 'object' &&
|
||||
'bsonError' in value &&
|
||||
value.bsonError === true &&
|
||||
// Do not access the following properties, just check existence
|
||||
'name' in value &&
|
||||
'message' in value &&
|
||||
'stack' in value
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @category Error
|
||||
*/
|
||||
export class BSONVersionError extends BSONError {
|
||||
get name(): 'BSONVersionError' {
|
||||
return 'BSONVersionError';
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.x.x`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @category Error
|
||||
*
|
||||
* An error generated when BSON functions encounter an unexpected input
|
||||
* or reaches an unexpected/invalid internal state
|
||||
*
|
||||
*/
|
||||
export class BSONRuntimeError extends BSONError {
|
||||
get name(): 'BSONRuntimeError' {
|
||||
return 'BSONRuntimeError';
|
||||
}
|
||||
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @category Error
|
||||
*
|
||||
* @experimental
|
||||
*
|
||||
* An error generated when BSON bytes are invalid.
|
||||
* Reports the offset the parser was able to reach before encountering the error.
|
||||
*/
|
||||
export class BSONOffsetError extends BSONError {
|
||||
public get name(): 'BSONOffsetError' {
|
||||
return 'BSONOffsetError';
|
||||
}
|
||||
|
||||
public offset: number;
|
||||
|
||||
constructor(message: string, offset: number, options?: { cause?: unknown }) {
|
||||
super(`${message}. offset: ${offset}`, options);
|
||||
this.offset = offset;
|
||||
}
|
||||
}
|
||||
513
node_modules/bson/src/extended_json.ts
generated
vendored
513
node_modules/bson/src/extended_json.ts
generated
vendored
|
|
@ -1,513 +0,0 @@
|
|||
import { Binary } from './binary';
|
||||
import type { Document } from './bson';
|
||||
import { Code } from './code';
|
||||
import {
|
||||
BSON_INT32_MAX,
|
||||
BSON_INT32_MIN,
|
||||
BSON_INT64_MAX,
|
||||
BSON_INT64_MIN,
|
||||
BSON_MAJOR_VERSION,
|
||||
BSON_VERSION_SYMBOL
|
||||
} from './constants';
|
||||
import { DBRef, isDBRefLike } from './db_ref';
|
||||
import { Decimal128 } from './decimal128';
|
||||
import { Double } from './double';
|
||||
import { BSONError, BSONRuntimeError, BSONVersionError } from './error';
|
||||
import { Int32 } from './int_32';
|
||||
import { Long } from './long';
|
||||
import { MaxKey } from './max_key';
|
||||
import { MinKey } from './min_key';
|
||||
import { ObjectId } from './objectid';
|
||||
import { isDate, isRegExp, isMap } from './parser/utils';
|
||||
import { BSONRegExp } from './regexp';
|
||||
import { BSONSymbol } from './symbol';
|
||||
import { Timestamp } from './timestamp';
|
||||
|
||||
/** @public */
|
||||
export type EJSONOptions = {
|
||||
/**
|
||||
* Output using the Extended JSON v1 spec
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
legacy?: boolean;
|
||||
/**
|
||||
* Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types
|
||||
* @defaultValue `false` */
|
||||
relaxed?: boolean;
|
||||
/**
|
||||
* Enable native bigint support
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
useBigInt64?: boolean;
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
type BSONType =
|
||||
| Binary
|
||||
| Code
|
||||
| DBRef
|
||||
| Decimal128
|
||||
| Double
|
||||
| Int32
|
||||
| Long
|
||||
| MaxKey
|
||||
| MinKey
|
||||
| ObjectId
|
||||
| BSONRegExp
|
||||
| BSONSymbol
|
||||
| Timestamp;
|
||||
|
||||
function isBSONType(value: unknown): value is BSONType {
|
||||
return (
|
||||
value != null &&
|
||||
typeof value === 'object' &&
|
||||
'_bsontype' in value &&
|
||||
typeof value._bsontype === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
// all the types where we don't need to do any special processing and can just pass the EJSON
|
||||
//straight to type.fromExtendedJSON
|
||||
const keysToCodecs = {
|
||||
$oid: ObjectId,
|
||||
$binary: Binary,
|
||||
$uuid: Binary,
|
||||
$symbol: BSONSymbol,
|
||||
$numberInt: Int32,
|
||||
$numberDecimal: Decimal128,
|
||||
$numberDouble: Double,
|
||||
$numberLong: Long,
|
||||
$minKey: MinKey,
|
||||
$maxKey: MaxKey,
|
||||
$regex: BSONRegExp,
|
||||
$regularExpression: BSONRegExp,
|
||||
$timestamp: Timestamp
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function deserializeValue(value: any, options: EJSONOptions = {}) {
|
||||
if (typeof value === 'number') {
|
||||
// TODO(NODE-4377): EJSON js number handling diverges from BSON
|
||||
const in32BitRange = value <= BSON_INT32_MAX && value >= BSON_INT32_MIN;
|
||||
const in64BitRange = value <= BSON_INT64_MAX && value >= BSON_INT64_MIN;
|
||||
|
||||
if (options.relaxed || options.legacy) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (Number.isInteger(value) && !Object.is(value, -0)) {
|
||||
// interpret as being of the smallest BSON integer type that can represent the number exactly
|
||||
if (in32BitRange) {
|
||||
return new Int32(value);
|
||||
}
|
||||
if (in64BitRange) {
|
||||
if (options.useBigInt64) {
|
||||
return BigInt(value);
|
||||
}
|
||||
return Long.fromNumber(value);
|
||||
}
|
||||
}
|
||||
|
||||
// If the number is a non-integer or out of integer range, should interpret as BSON Double.
|
||||
return new Double(value);
|
||||
}
|
||||
|
||||
// from here on out we're looking for bson types, so bail if its not an object
|
||||
if (value == null || typeof value !== 'object') return value;
|
||||
|
||||
// upgrade deprecated undefined to null
|
||||
if (value.$undefined) return null;
|
||||
|
||||
const keys = Object.keys(value).filter(
|
||||
k => k.startsWith('$') && value[k] != null
|
||||
) as (keyof typeof keysToCodecs)[];
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const c = keysToCodecs[keys[i]];
|
||||
if (c) return c.fromExtendedJSON(value, options);
|
||||
}
|
||||
|
||||
if (value.$date != null) {
|
||||
const d = value.$date;
|
||||
const date = new Date();
|
||||
|
||||
if (options.legacy) {
|
||||
if (typeof d === 'number') date.setTime(d);
|
||||
else if (typeof d === 'string') date.setTime(Date.parse(d));
|
||||
else if (typeof d === 'bigint') date.setTime(Number(d));
|
||||
else throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
|
||||
} else {
|
||||
if (typeof d === 'string') date.setTime(Date.parse(d));
|
||||
else if (Long.isLong(d)) date.setTime(d.toNumber());
|
||||
else if (typeof d === 'number' && options.relaxed) date.setTime(d);
|
||||
else if (typeof d === 'bigint') date.setTime(Number(d));
|
||||
else throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
if (value.$code != null) {
|
||||
const copy = Object.assign({}, value);
|
||||
if (value.$scope) {
|
||||
copy.$scope = deserializeValue(value.$scope);
|
||||
}
|
||||
|
||||
return Code.fromExtendedJSON(value);
|
||||
}
|
||||
|
||||
if (isDBRefLike(value) || value.$dbPointer) {
|
||||
const v = value.$ref ? value : value.$dbPointer;
|
||||
|
||||
// we run into this in a "degenerate EJSON" case (with $id and $ref order flipped)
|
||||
// because of the order JSON.parse goes through the document
|
||||
if (v instanceof DBRef) return v;
|
||||
|
||||
const dollarKeys = Object.keys(v).filter(k => k.startsWith('$'));
|
||||
let valid = true;
|
||||
dollarKeys.forEach(k => {
|
||||
if (['$ref', '$id', '$db'].indexOf(k) === -1) valid = false;
|
||||
});
|
||||
|
||||
// only make DBRef if $ keys are all valid
|
||||
if (valid) return DBRef.fromExtendedJSON(v);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
type EJSONSerializeOptions = EJSONOptions & {
|
||||
seenObjects: { obj: unknown; propertyName: string }[];
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function serializeArray(array: any[], options: EJSONSerializeOptions): any[] {
|
||||
return array.map((v: unknown, index: number) => {
|
||||
options.seenObjects.push({ propertyName: `index ${index}`, obj: null });
|
||||
try {
|
||||
return serializeValue(v, options);
|
||||
} finally {
|
||||
options.seenObjects.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getISOString(date: Date) {
|
||||
const isoStr = date.toISOString();
|
||||
// we should only show milliseconds in timestamp if they're non-zero
|
||||
return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + 'Z';
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function serializeValue(value: any, options: EJSONSerializeOptions): any {
|
||||
if (value instanceof Map || isMap(value)) {
|
||||
const obj: Record<string, unknown> = Object.create(null);
|
||||
for (const [k, v] of value) {
|
||||
if (typeof k !== 'string') {
|
||||
throw new BSONError('Can only serialize maps with string keys');
|
||||
}
|
||||
obj[k] = v;
|
||||
}
|
||||
|
||||
return serializeValue(obj, options);
|
||||
}
|
||||
|
||||
if ((typeof value === 'object' || typeof value === 'function') && value !== null) {
|
||||
const index = options.seenObjects.findIndex(entry => entry.obj === value);
|
||||
if (index !== -1) {
|
||||
const props = options.seenObjects.map(entry => entry.propertyName);
|
||||
const leadingPart = props
|
||||
.slice(0, index)
|
||||
.map(prop => `${prop} -> `)
|
||||
.join('');
|
||||
const alreadySeen = props[index];
|
||||
const circularPart =
|
||||
' -> ' +
|
||||
props
|
||||
.slice(index + 1, props.length - 1)
|
||||
.map(prop => `${prop} -> `)
|
||||
.join('');
|
||||
const current = props[props.length - 1];
|
||||
const leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
|
||||
const dashes = '-'.repeat(
|
||||
circularPart.length + (alreadySeen.length + current.length) / 2 - 1
|
||||
);
|
||||
|
||||
throw new BSONError(
|
||||
'Converting circular structure to EJSON:\n' +
|
||||
` ${leadingPart}${alreadySeen}${circularPart}${current}\n` +
|
||||
` ${leadingSpace}\\${dashes}/`
|
||||
);
|
||||
}
|
||||
options.seenObjects[options.seenObjects.length - 1].obj = value;
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) return serializeArray(value, options);
|
||||
|
||||
if (value === undefined) return null;
|
||||
|
||||
if (value instanceof Date || isDate(value)) {
|
||||
const dateNum = value.getTime(),
|
||||
// is it in year range 1970-9999?
|
||||
inRange = dateNum > -1 && dateNum < 253402318800000;
|
||||
|
||||
if (options.legacy) {
|
||||
return options.relaxed && inRange
|
||||
? { $date: value.getTime() }
|
||||
: { $date: getISOString(value) };
|
||||
}
|
||||
return options.relaxed && inRange
|
||||
? { $date: getISOString(value) }
|
||||
: { $date: { $numberLong: value.getTime().toString() } };
|
||||
}
|
||||
|
||||
if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
|
||||
if (Number.isInteger(value) && !Object.is(value, -0)) {
|
||||
// interpret as being of the smallest BSON integer type that can represent the number exactly
|
||||
if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
|
||||
return { $numberInt: value.toString() };
|
||||
}
|
||||
if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX) {
|
||||
// TODO(NODE-4377): EJSON js number handling diverges from BSON
|
||||
return { $numberLong: value.toString() };
|
||||
}
|
||||
}
|
||||
return { $numberDouble: Object.is(value, -0) ? '-0.0' : value.toString() };
|
||||
}
|
||||
|
||||
if (typeof value === 'bigint') {
|
||||
if (!options.relaxed) {
|
||||
return { $numberLong: BigInt.asIntN(64, value).toString() };
|
||||
}
|
||||
return Number(BigInt.asIntN(64, value));
|
||||
}
|
||||
|
||||
if (value instanceof RegExp || isRegExp(value)) {
|
||||
let flags = value.flags;
|
||||
if (flags === undefined) {
|
||||
const match = value.toString().match(/[gimuy]*$/);
|
||||
if (match) {
|
||||
flags = match[0];
|
||||
}
|
||||
}
|
||||
|
||||
const rx = new BSONRegExp(value.source, flags);
|
||||
return rx.toExtendedJSON(options);
|
||||
}
|
||||
|
||||
if (value != null && typeof value === 'object') return serializeDocument(value, options);
|
||||
return value;
|
||||
}
|
||||
|
||||
const BSON_TYPE_MAPPINGS = {
|
||||
Binary: (o: Binary) => new Binary(o.value(), o.sub_type),
|
||||
Code: (o: Code) => new Code(o.code, o.scope),
|
||||
DBRef: (o: DBRef) => new DBRef(o.collection || o.namespace, o.oid, o.db, o.fields), // "namespace" for 1.x library backwards compat
|
||||
Decimal128: (o: Decimal128) => new Decimal128(o.bytes),
|
||||
Double: (o: Double) => new Double(o.value),
|
||||
Int32: (o: Int32) => new Int32(o.value),
|
||||
Long: (
|
||||
o: Long & {
|
||||
low_: number;
|
||||
high_: number;
|
||||
unsigned_: boolean | undefined;
|
||||
}
|
||||
) =>
|
||||
Long.fromBits(
|
||||
// underscore variants for 1.x backwards compatibility
|
||||
o.low != null ? o.low : o.low_,
|
||||
o.low != null ? o.high : o.high_,
|
||||
o.low != null ? o.unsigned : o.unsigned_
|
||||
),
|
||||
MaxKey: () => new MaxKey(),
|
||||
MinKey: () => new MinKey(),
|
||||
ObjectId: (o: ObjectId) => new ObjectId(o),
|
||||
BSONRegExp: (o: BSONRegExp) => new BSONRegExp(o.pattern, o.options),
|
||||
BSONSymbol: (o: BSONSymbol) => new BSONSymbol(o.value),
|
||||
Timestamp: (o: Timestamp) => Timestamp.fromBits(o.low, o.high)
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function serializeDocument(doc: any, options: EJSONSerializeOptions) {
|
||||
if (doc == null || typeof doc !== 'object') throw new BSONError('not an object instance');
|
||||
|
||||
const bsontype: BSONType['_bsontype'] = doc._bsontype;
|
||||
if (typeof bsontype === 'undefined') {
|
||||
// It's a regular object. Recursively serialize its property values.
|
||||
const _doc: Document = {};
|
||||
for (const name of Object.keys(doc)) {
|
||||
options.seenObjects.push({ propertyName: name, obj: null });
|
||||
try {
|
||||
const value = serializeValue(doc[name], options);
|
||||
if (name === '__proto__') {
|
||||
Object.defineProperty(_doc, name, {
|
||||
value,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
} else {
|
||||
_doc[name] = value;
|
||||
}
|
||||
} finally {
|
||||
options.seenObjects.pop();
|
||||
}
|
||||
}
|
||||
return _doc;
|
||||
} else if (
|
||||
doc != null &&
|
||||
typeof doc === 'object' &&
|
||||
typeof doc._bsontype === 'string' &&
|
||||
doc[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION
|
||||
) {
|
||||
throw new BSONVersionError();
|
||||
} else if (isBSONType(doc)) {
|
||||
// the "document" is really just a BSON type object
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let outDoc: any = doc;
|
||||
if (typeof outDoc.toExtendedJSON !== 'function') {
|
||||
// There's no EJSON serialization function on the object. It's probably an
|
||||
// object created by a previous version of this library (or another library)
|
||||
// that's duck-typing objects to look like they were generated by this library).
|
||||
// Copy the object into this library's version of that type.
|
||||
const mapper = BSON_TYPE_MAPPINGS[doc._bsontype];
|
||||
if (!mapper) {
|
||||
throw new BSONError('Unrecognized or invalid _bsontype: ' + doc._bsontype);
|
||||
}
|
||||
outDoc = mapper(outDoc);
|
||||
}
|
||||
|
||||
// Two BSON types may have nested objects that may need to be serialized too
|
||||
if (bsontype === 'Code' && outDoc.scope) {
|
||||
outDoc = new Code(outDoc.code, serializeValue(outDoc.scope, options));
|
||||
} else if (bsontype === 'DBRef' && outDoc.oid) {
|
||||
outDoc = new DBRef(
|
||||
serializeValue(outDoc.collection, options),
|
||||
serializeValue(outDoc.oid, options),
|
||||
serializeValue(outDoc.db, options),
|
||||
serializeValue(outDoc.fields, options)
|
||||
);
|
||||
}
|
||||
|
||||
return outDoc.toExtendedJSON(options);
|
||||
} else {
|
||||
throw new BSONError('_bsontype must be a string, but was: ' + typeof bsontype);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an Extended JSON string, constructing the JavaScript value or object described by that
|
||||
* string.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* const { EJSON } = require('bson');
|
||||
* const text = '{ "int32": { "$numberInt": "10" } }';
|
||||
*
|
||||
* // prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
|
||||
* console.log(EJSON.parse(text, { relaxed: false }));
|
||||
*
|
||||
* // prints { int32: 10 }
|
||||
* console.log(EJSON.parse(text));
|
||||
* ```
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function parse(text: string, options?: EJSONOptions): any {
|
||||
const ejsonOptions = {
|
||||
useBigInt64: options?.useBigInt64 ?? false,
|
||||
relaxed: options?.relaxed ?? true,
|
||||
legacy: options?.legacy ?? false
|
||||
};
|
||||
return JSON.parse(text, (key, value) => {
|
||||
if (key.indexOf('\x00') !== -1) {
|
||||
throw new BSONError(
|
||||
`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(key)}`
|
||||
);
|
||||
}
|
||||
return deserializeValue(value, ejsonOptions);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer
|
||||
* function is specified or optionally including only the specified properties if a replacer array
|
||||
* is specified.
|
||||
*
|
||||
* @param value - The value to convert to extended JSON
|
||||
* @param replacer - A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string
|
||||
* @param space - A String or Number object that's used to insert white space into the output JSON string for readability purposes.
|
||||
* @param options - Optional settings
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* const { EJSON } = require('bson');
|
||||
* const Int32 = require('mongodb').Int32;
|
||||
* const doc = { int32: new Int32(10) };
|
||||
*
|
||||
* // prints '{"int32":{"$numberInt":"10"}}'
|
||||
* console.log(EJSON.stringify(doc, { relaxed: false }));
|
||||
*
|
||||
* // prints '{"int32":10}'
|
||||
* console.log(EJSON.stringify(doc));
|
||||
* ```
|
||||
*/
|
||||
function stringify(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
value: any,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | EJSONOptions,
|
||||
space?: string | number,
|
||||
options?: EJSONOptions
|
||||
): string {
|
||||
if (space != null && typeof space === 'object') {
|
||||
options = space;
|
||||
space = 0;
|
||||
}
|
||||
if (replacer != null && typeof replacer === 'object' && !Array.isArray(replacer)) {
|
||||
options = replacer;
|
||||
replacer = undefined;
|
||||
space = 0;
|
||||
}
|
||||
const serializeOptions = Object.assign({ relaxed: true, legacy: false }, options, {
|
||||
seenObjects: [{ propertyName: '(root)', obj: null }]
|
||||
});
|
||||
|
||||
const doc = serializeValue(value, serializeOptions);
|
||||
return JSON.stringify(doc, replacer as Parameters<JSON['stringify']>[1], space);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
|
||||
*
|
||||
* @param value - The object to serialize
|
||||
* @param options - Optional settings passed to the `stringify` function
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function EJSONserialize(value: any, options?: EJSONOptions): Document {
|
||||
options = options || {};
|
||||
return JSON.parse(stringify(value, options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
|
||||
*
|
||||
* @param ejson - The Extended JSON object to deserialize
|
||||
* @param options - Optional settings passed to the parse method
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function EJSONdeserialize(ejson: Document, options?: EJSONOptions): any {
|
||||
options = options || {};
|
||||
return parse(JSON.stringify(ejson), options);
|
||||
}
|
||||
|
||||
/** @public */
|
||||
const EJSON: {
|
||||
parse: typeof parse;
|
||||
stringify: typeof stringify;
|
||||
serialize: typeof EJSONserialize;
|
||||
deserialize: typeof EJSONdeserialize;
|
||||
} = Object.create(null);
|
||||
EJSON.parse = parse;
|
||||
EJSON.stringify = stringify;
|
||||
EJSON.serialize = EJSONserialize;
|
||||
EJSON.deserialize = EJSONdeserialize;
|
||||
Object.freeze(EJSON);
|
||||
export { EJSON };
|
||||
19
node_modules/bson/src/index.ts
generated
vendored
19
node_modules/bson/src/index.ts
generated
vendored
|
|
@ -1,19 +0,0 @@
|
|||
import * as BSON from './bson';
|
||||
|
||||
// Export all named properties from BSON to support
|
||||
// import { ObjectId, serialize } from 'bson';
|
||||
// const { ObjectId, serialize } = require('bson');
|
||||
export * from './bson';
|
||||
|
||||
// Export BSON as a namespace to support:
|
||||
// import { BSON } from 'bson';
|
||||
// const { BSON } = require('bson');
|
||||
export { BSON };
|
||||
|
||||
// BSON does **NOT** have a default export
|
||||
|
||||
// The following will crash in es module environments
|
||||
// import BSON from 'bson';
|
||||
|
||||
// The following will work as expected, BSON as a namespace of all the APIs (BSON.ObjectId, BSON.serialize)
|
||||
// const BSON = require('bson');
|
||||
101
node_modules/bson/src/int_32.ts
generated
vendored
101
node_modules/bson/src/int_32.ts
generated
vendored
|
|
@ -1,101 +0,0 @@
|
|||
import { BSONValue } from './bson_value';
|
||||
import { BSON_INT32_MAX, BSON_INT32_MIN } from './constants';
|
||||
import { BSONError } from './error';
|
||||
import type { EJSONOptions } from './extended_json';
|
||||
import { type InspectFn, defaultInspect } from './parser/utils';
|
||||
import { removeLeadingZerosAndExplicitPlus } from './utils/string_utils';
|
||||
|
||||
/** @public */
|
||||
export interface Int32Extended {
|
||||
$numberInt: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of a BSON Int32 type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class Int32 extends BSONValue {
|
||||
get _bsontype(): 'Int32' {
|
||||
return 'Int32';
|
||||
}
|
||||
|
||||
value!: number;
|
||||
/**
|
||||
* Create an Int32 type
|
||||
*
|
||||
* @param value - the number we want to represent as an int32.
|
||||
*/
|
||||
constructor(value: number | string) {
|
||||
super();
|
||||
if ((value as unknown) instanceof Number) {
|
||||
value = value.valueOf();
|
||||
}
|
||||
|
||||
this.value = +value | 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to create an Int32 type from string.
|
||||
*
|
||||
* This method will throw a BSONError on any string input that is not representable as an Int32.
|
||||
* Notably, this method will also throw on the following string formats:
|
||||
* - Strings in non-decimal formats (exponent notation, binary, hex, or octal digits)
|
||||
* - Strings non-numeric and non-leading sign characters (ex: '2.0', '24,000')
|
||||
* - Strings with leading and/or trailing whitespace
|
||||
*
|
||||
* Strings with leading zeros, however, are allowed.
|
||||
*
|
||||
* @param value - the string we want to represent as an int32.
|
||||
*/
|
||||
static fromString(value: string): Int32 {
|
||||
const cleanedValue = removeLeadingZerosAndExplicitPlus(value);
|
||||
|
||||
const coercedValue = Number(value);
|
||||
|
||||
if (BSON_INT32_MAX < coercedValue) {
|
||||
throw new BSONError(`Input: '${value}' is larger than the maximum value for Int32`);
|
||||
} else if (BSON_INT32_MIN > coercedValue) {
|
||||
throw new BSONError(`Input: '${value}' is smaller than the minimum value for Int32`);
|
||||
} else if (!Number.isSafeInteger(coercedValue)) {
|
||||
throw new BSONError(`Input: '${value}' is not a safe integer`);
|
||||
} else if (coercedValue.toString() !== cleanedValue) {
|
||||
// catch all case
|
||||
throw new BSONError(`Input: '${value}' is not a valid Int32 string`);
|
||||
}
|
||||
return new Int32(coercedValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Access the number value.
|
||||
*
|
||||
* @returns returns the wrapped int32 number.
|
||||
*/
|
||||
valueOf(): number {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
toString(radix?: number): string {
|
||||
return this.value.toString(radix);
|
||||
}
|
||||
|
||||
toJSON(): number {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(options?: EJSONOptions): number | Int32Extended {
|
||||
if (options && (options.relaxed || options.legacy)) return this.value;
|
||||
return { $numberInt: this.value.toString() };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(doc: Int32Extended, options?: EJSONOptions): number | Int32 {
|
||||
return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt);
|
||||
}
|
||||
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
return `new Int32(${inspect(this.value, options)})`;
|
||||
}
|
||||
}
|
||||
1240
node_modules/bson/src/long.ts
generated
vendored
1240
node_modules/bson/src/long.ts
generated
vendored
File diff suppressed because it is too large
Load diff
31
node_modules/bson/src/max_key.ts
generated
vendored
31
node_modules/bson/src/max_key.ts
generated
vendored
|
|
@ -1,31 +0,0 @@
|
|||
import { BSONValue } from './bson_value';
|
||||
|
||||
/** @public */
|
||||
export interface MaxKeyExtended {
|
||||
$maxKey: 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON MaxKey type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class MaxKey extends BSONValue {
|
||||
get _bsontype(): 'MaxKey' {
|
||||
return 'MaxKey';
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(): MaxKeyExtended {
|
||||
return { $maxKey: 1 };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(): MaxKey {
|
||||
return new MaxKey();
|
||||
}
|
||||
|
||||
inspect(): string {
|
||||
return 'new MaxKey()';
|
||||
}
|
||||
}
|
||||
31
node_modules/bson/src/min_key.ts
generated
vendored
31
node_modules/bson/src/min_key.ts
generated
vendored
|
|
@ -1,31 +0,0 @@
|
|||
import { BSONValue } from './bson_value';
|
||||
|
||||
/** @public */
|
||||
export interface MinKeyExtended {
|
||||
$minKey: 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON MinKey type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class MinKey extends BSONValue {
|
||||
get _bsontype(): 'MinKey' {
|
||||
return 'MinKey';
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(): MinKeyExtended {
|
||||
return { $minKey: 1 };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(): MinKey {
|
||||
return new MinKey();
|
||||
}
|
||||
|
||||
inspect(): string {
|
||||
return 'new MinKey()';
|
||||
}
|
||||
}
|
||||
382
node_modules/bson/src/objectid.ts
generated
vendored
382
node_modules/bson/src/objectid.ts
generated
vendored
|
|
@ -1,382 +0,0 @@
|
|||
import { BSONValue } from './bson_value';
|
||||
import { BSONError } from './error';
|
||||
import { type InspectFn, defaultInspect } from './parser/utils';
|
||||
import { ByteUtils } from './utils/byte_utils';
|
||||
import { NumberUtils } from './utils/number_utils';
|
||||
|
||||
// Unique sequence for the current process (initialized on first use)
|
||||
let PROCESS_UNIQUE: Uint8Array | null = null;
|
||||
|
||||
/** ObjectId hexString cache @internal */
|
||||
const __idCache = new WeakMap(); // TODO(NODE-6549): convert this to #__id private field when target updated to ES2022
|
||||
|
||||
/** @public */
|
||||
export interface ObjectIdLike {
|
||||
id: string | Uint8Array;
|
||||
__id?: string;
|
||||
toHexString(): string;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface ObjectIdExtended {
|
||||
$oid: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON ObjectId type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class ObjectId extends BSONValue {
|
||||
get _bsontype(): 'ObjectId' {
|
||||
return 'ObjectId';
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private static index = Math.floor(Math.random() * 0xffffff);
|
||||
|
||||
static cacheHexString: boolean;
|
||||
|
||||
/** ObjectId Bytes @internal */
|
||||
private buffer!: Uint8Array;
|
||||
|
||||
/** To generate a new ObjectId, use ObjectId() with no argument. */
|
||||
constructor();
|
||||
/**
|
||||
* Create ObjectId from a 24 character hex string.
|
||||
*
|
||||
* @param inputId - A 24 character hex string.
|
||||
*/
|
||||
constructor(inputId: string);
|
||||
/**
|
||||
* Create ObjectId from the BSON ObjectId type.
|
||||
*
|
||||
* @param inputId - The BSON ObjectId type.
|
||||
*/
|
||||
constructor(inputId: ObjectId);
|
||||
/**
|
||||
* Create ObjectId from the object type that has the toHexString method.
|
||||
*
|
||||
* @param inputId - The ObjectIdLike type.
|
||||
*/
|
||||
constructor(inputId: ObjectIdLike);
|
||||
/**
|
||||
* Create ObjectId from a 12 byte binary Buffer.
|
||||
*
|
||||
* @param inputId - A 12 byte binary Buffer.
|
||||
*/
|
||||
constructor(inputId: Uint8Array);
|
||||
/**
|
||||
* Implementation overload.
|
||||
*
|
||||
* @param inputId - All input types that are used in the constructor implementation.
|
||||
*/
|
||||
constructor(inputId?: string | ObjectId | ObjectIdLike | Uint8Array);
|
||||
/**
|
||||
* Create a new ObjectId.
|
||||
*
|
||||
* @param inputId - An input value to create a new ObjectId from.
|
||||
*/
|
||||
constructor(inputId?: string | ObjectId | ObjectIdLike | Uint8Array) {
|
||||
super();
|
||||
// workingId is set based on type of input and whether valid id exists for the input
|
||||
let workingId;
|
||||
if (typeof inputId === 'object' && inputId && 'id' in inputId) {
|
||||
if (typeof inputId.id !== 'string' && !ArrayBuffer.isView(inputId.id)) {
|
||||
throw new BSONError('Argument passed in must have an id that is of type string or Buffer');
|
||||
}
|
||||
if ('toHexString' in inputId && typeof inputId.toHexString === 'function') {
|
||||
workingId = ByteUtils.fromHex(inputId.toHexString());
|
||||
} else {
|
||||
workingId = inputId.id;
|
||||
}
|
||||
} else {
|
||||
workingId = inputId;
|
||||
}
|
||||
|
||||
// The following cases use workingId to construct an ObjectId
|
||||
if (workingId == null) {
|
||||
// The most common use case (blank id, new objectId instance)
|
||||
// Generate a new id
|
||||
this.buffer = ObjectId.generate();
|
||||
} else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
|
||||
// If instanceof matches we can escape calling ensure buffer in Node.js environments
|
||||
this.buffer = ByteUtils.toLocalBufferType(workingId);
|
||||
} else if (typeof workingId === 'string') {
|
||||
if (ObjectId.validateHexString(workingId)) {
|
||||
this.buffer = ByteUtils.fromHex(workingId);
|
||||
// If we are caching the hex string
|
||||
if (ObjectId.cacheHexString) {
|
||||
__idCache.set(this, workingId);
|
||||
}
|
||||
} else {
|
||||
throw new BSONError(
|
||||
'input must be a 24 character hex string, 12 byte Uint8Array, or an integer'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new BSONError('Argument passed in does not match the accepted types');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The ObjectId bytes
|
||||
* @readonly
|
||||
*/
|
||||
get id(): Uint8Array {
|
||||
return this.buffer;
|
||||
}
|
||||
|
||||
set id(value: Uint8Array) {
|
||||
this.buffer = value;
|
||||
if (ObjectId.cacheHexString) {
|
||||
__idCache.set(this, ByteUtils.toHex(value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Validates the input string is a valid hex representation of an ObjectId.
|
||||
*/
|
||||
private static validateHexString(string: string): boolean {
|
||||
if (string?.length !== 24) return false;
|
||||
for (let i = 0; i < 24; i++) {
|
||||
const char = string.charCodeAt(i);
|
||||
if (
|
||||
// Check for ASCII 0-9
|
||||
(char >= 48 && char <= 57) ||
|
||||
// Check for ASCII a-f
|
||||
(char >= 97 && char <= 102) ||
|
||||
// Check for ASCII A-F
|
||||
(char >= 65 && char <= 70)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Returns the ObjectId id as a 24 lowercase character hex string representation */
|
||||
toHexString(): string {
|
||||
if (ObjectId.cacheHexString) {
|
||||
const __id = __idCache.get(this);
|
||||
if (__id) return __id;
|
||||
}
|
||||
|
||||
const hexString = ByteUtils.toHex(this.id);
|
||||
|
||||
if (ObjectId.cacheHexString) {
|
||||
__idCache.set(this, hexString);
|
||||
}
|
||||
|
||||
return hexString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the ObjectId index
|
||||
* @internal
|
||||
*/
|
||||
private static getInc(): number {
|
||||
return (ObjectId.index = (ObjectId.index + 1) % 0xffffff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a 12 byte id buffer used in ObjectId's
|
||||
*
|
||||
* @param time - pass in a second based timestamp.
|
||||
*/
|
||||
static generate(time?: number): Uint8Array {
|
||||
if ('number' !== typeof time) {
|
||||
time = Math.floor(Date.now() / 1000);
|
||||
}
|
||||
|
||||
const inc = ObjectId.getInc();
|
||||
const buffer = ByteUtils.allocateUnsafe(12);
|
||||
|
||||
// 4-byte timestamp
|
||||
NumberUtils.setInt32BE(buffer, 0, time);
|
||||
|
||||
// set PROCESS_UNIQUE if yet not initialized
|
||||
if (PROCESS_UNIQUE === null) {
|
||||
PROCESS_UNIQUE = ByteUtils.randomBytes(5);
|
||||
}
|
||||
|
||||
// 5-byte process unique
|
||||
buffer[4] = PROCESS_UNIQUE[0];
|
||||
buffer[5] = PROCESS_UNIQUE[1];
|
||||
buffer[6] = PROCESS_UNIQUE[2];
|
||||
buffer[7] = PROCESS_UNIQUE[3];
|
||||
buffer[8] = PROCESS_UNIQUE[4];
|
||||
|
||||
// 3-byte counter
|
||||
buffer[11] = inc & 0xff;
|
||||
buffer[10] = (inc >> 8) & 0xff;
|
||||
buffer[9] = (inc >> 16) & 0xff;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the id into a 24 character hex string for printing, unless encoding is provided.
|
||||
* @param encoding - hex or base64
|
||||
*/
|
||||
toString(encoding?: 'hex' | 'base64'): string {
|
||||
// Is the id a buffer then use the buffer toString method to return the format
|
||||
if (encoding === 'base64') return ByteUtils.toBase64(this.id);
|
||||
if (encoding === 'hex') return this.toHexString();
|
||||
return this.toHexString();
|
||||
}
|
||||
|
||||
/** Converts to its JSON the 24 character hex string representation. */
|
||||
toJSON(): string {
|
||||
return this.toHexString();
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private static is(variable: unknown): variable is ObjectId {
|
||||
return (
|
||||
variable != null &&
|
||||
typeof variable === 'object' &&
|
||||
'_bsontype' in variable &&
|
||||
variable._bsontype === 'ObjectId'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the equality of this ObjectId with `otherID`.
|
||||
*
|
||||
* @param otherId - ObjectId instance to compare against.
|
||||
*/
|
||||
equals(otherId: string | ObjectId | ObjectIdLike | undefined | null): boolean {
|
||||
if (otherId === undefined || otherId === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ObjectId.is(otherId)) {
|
||||
return (
|
||||
this.buffer[11] === otherId.buffer[11] && ByteUtils.equals(this.buffer, otherId.buffer)
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof otherId === 'string') {
|
||||
return otherId.toLowerCase() === this.toHexString();
|
||||
}
|
||||
|
||||
if (typeof otherId === 'object' && typeof otherId.toHexString === 'function') {
|
||||
const otherIdString = otherId.toHexString();
|
||||
const thisIdString = this.toHexString();
|
||||
return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Returns the generation date (accurate up to the second) that this ID was generated. */
|
||||
getTimestamp(): Date {
|
||||
const timestamp = new Date();
|
||||
const time = NumberUtils.getUint32BE(this.buffer, 0);
|
||||
timestamp.setTime(Math.floor(time) * 1000);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static createPk(): ObjectId {
|
||||
return new ObjectId();
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
serializeInto(uint8array: Uint8Array, index: number): 12 {
|
||||
uint8array[index] = this.buffer[0];
|
||||
uint8array[index + 1] = this.buffer[1];
|
||||
uint8array[index + 2] = this.buffer[2];
|
||||
uint8array[index + 3] = this.buffer[3];
|
||||
uint8array[index + 4] = this.buffer[4];
|
||||
uint8array[index + 5] = this.buffer[5];
|
||||
uint8array[index + 6] = this.buffer[6];
|
||||
uint8array[index + 7] = this.buffer[7];
|
||||
uint8array[index + 8] = this.buffer[8];
|
||||
uint8array[index + 9] = this.buffer[9];
|
||||
uint8array[index + 10] = this.buffer[10];
|
||||
uint8array[index + 11] = this.buffer[11];
|
||||
return 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId.
|
||||
*
|
||||
* @param time - an integer number representing a number of seconds.
|
||||
*/
|
||||
static createFromTime(time: number): ObjectId {
|
||||
const buffer = ByteUtils.allocate(12);
|
||||
for (let i = 11; i >= 4; i--) buffer[i] = 0;
|
||||
// Encode time into first 4 bytes
|
||||
NumberUtils.setInt32BE(buffer, 0, time);
|
||||
// Return the new objectId
|
||||
return new ObjectId(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ObjectId from a hex string representation of an ObjectId.
|
||||
*
|
||||
* @param hexString - create a ObjectId from a passed in 24 character hexstring.
|
||||
*/
|
||||
static createFromHexString(hexString: string): ObjectId {
|
||||
if (hexString?.length !== 24) {
|
||||
throw new BSONError('hex string must be 24 characters');
|
||||
}
|
||||
|
||||
return new ObjectId(ByteUtils.fromHex(hexString));
|
||||
}
|
||||
|
||||
/** Creates an ObjectId instance from a base64 string */
|
||||
static createFromBase64(base64: string): ObjectId {
|
||||
if (base64?.length !== 16) {
|
||||
throw new BSONError('base64 string must be 16 characters');
|
||||
}
|
||||
|
||||
return new ObjectId(ByteUtils.fromBase64(base64));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value can be used to create a valid bson ObjectId
|
||||
* @param id - any JS value
|
||||
*/
|
||||
static isValid(id: string | ObjectId | ObjectIdLike | Uint8Array): boolean {
|
||||
if (id == null) return false;
|
||||
if (typeof id === 'string') return ObjectId.validateHexString(id);
|
||||
|
||||
try {
|
||||
new ObjectId(id);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(): ObjectIdExtended {
|
||||
if (this.toHexString) return { $oid: this.toHexString() };
|
||||
return { $oid: this.toString('hex') };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(doc: ObjectIdExtended): ObjectId {
|
||||
return new ObjectId(doc.$oid);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private isCached(): boolean {
|
||||
return ObjectId.cacheHexString && __idCache.has(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts to a string representation of this Id.
|
||||
*
|
||||
* @returns return the 24 character hex string representation.
|
||||
*/
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
return `new ObjectId(${inspect(this.toHexString(), options)})`;
|
||||
}
|
||||
}
|
||||
35
node_modules/bson/src/parse_utf8.ts
generated
vendored
35
node_modules/bson/src/parse_utf8.ts
generated
vendored
|
|
@ -1,35 +0,0 @@
|
|||
import { BSONError } from './error';
|
||||
|
||||
type TextDecoder = {
|
||||
readonly encoding: string;
|
||||
readonly fatal: boolean;
|
||||
readonly ignoreBOM: boolean;
|
||||
decode(input?: Uint8Array): string;
|
||||
};
|
||||
type TextDecoderConstructor = {
|
||||
new (label: 'utf8', options: { fatal: boolean; ignoreBOM?: boolean }): TextDecoder;
|
||||
};
|
||||
|
||||
// parse utf8 globals
|
||||
declare const TextDecoder: TextDecoderConstructor;
|
||||
let TextDecoderFatal: TextDecoder;
|
||||
let TextDecoderNonFatal: TextDecoder;
|
||||
|
||||
/**
|
||||
* Determines if the passed in bytes are valid utf8
|
||||
* @param bytes - An array of 8-bit bytes. Must be indexable and have length property
|
||||
* @param start - The index to start validating
|
||||
* @param end - The index to end validating
|
||||
*/
|
||||
export function parseUtf8(buffer: Uint8Array, start: number, end: number, fatal: boolean): string {
|
||||
if (fatal) {
|
||||
TextDecoderFatal ??= new TextDecoder('utf8', { fatal: true });
|
||||
try {
|
||||
return TextDecoderFatal.decode(buffer.subarray(start, end));
|
||||
} catch (cause) {
|
||||
throw new BSONError('Invalid UTF-8 string in BSON document', { cause });
|
||||
}
|
||||
}
|
||||
TextDecoderNonFatal ??= new TextDecoder('utf8', { fatal: false });
|
||||
return TextDecoderNonFatal.decode(buffer.subarray(start, end));
|
||||
}
|
||||
218
node_modules/bson/src/parser/calculate_size.ts
generated
vendored
218
node_modules/bson/src/parser/calculate_size.ts
generated
vendored
|
|
@ -1,218 +0,0 @@
|
|||
import { Binary } from '../binary';
|
||||
import type { Document } from '../bson';
|
||||
import { BSONError, BSONVersionError } from '../error';
|
||||
import * as constants from '../constants';
|
||||
import { ByteUtils } from '../utils/byte_utils';
|
||||
import { isAnyArrayBuffer, isDate, isRegExp } from './utils';
|
||||
|
||||
export function internalCalculateObjectSize(
|
||||
object: Document,
|
||||
serializeFunctions?: boolean,
|
||||
ignoreUndefined?: boolean
|
||||
): number {
|
||||
let totalLength = 4 + 1;
|
||||
|
||||
if (Array.isArray(object)) {
|
||||
for (let i = 0; i < object.length; i++) {
|
||||
totalLength += calculateElement(
|
||||
i.toString(),
|
||||
object[i],
|
||||
serializeFunctions,
|
||||
true,
|
||||
ignoreUndefined
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// If we have toBSON defined, override the current object
|
||||
|
||||
if (typeof object?.toBSON === 'function') {
|
||||
object = object.toBSON();
|
||||
}
|
||||
|
||||
// Calculate size
|
||||
for (const key of Object.keys(object)) {
|
||||
totalLength += calculateElement(key, object[key], serializeFunctions, false, ignoreUndefined);
|
||||
}
|
||||
}
|
||||
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function calculateElement(
|
||||
name: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
value: any,
|
||||
serializeFunctions = false,
|
||||
isArray = false,
|
||||
ignoreUndefined = false
|
||||
) {
|
||||
// If we have toBSON defined, override the current object
|
||||
if (typeof value?.toBSON === 'function') {
|
||||
value = value.toBSON();
|
||||
}
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return 1 + ByteUtils.utf8ByteLength(name) + 1 + 4 + ByteUtils.utf8ByteLength(value) + 1;
|
||||
case 'number':
|
||||
if (
|
||||
Math.floor(value) === value &&
|
||||
value >= constants.JS_INT_MIN &&
|
||||
value <= constants.JS_INT_MAX
|
||||
) {
|
||||
if (value >= constants.BSON_INT32_MIN && value <= constants.BSON_INT32_MAX) {
|
||||
// 32 bit
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (4 + 1);
|
||||
} else {
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
||||
}
|
||||
} else {
|
||||
// 64 bit
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
||||
}
|
||||
case 'undefined':
|
||||
if (isArray || !ignoreUndefined)
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1;
|
||||
return 0;
|
||||
case 'boolean':
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (1 + 1);
|
||||
case 'object':
|
||||
if (
|
||||
value != null &&
|
||||
typeof value._bsontype === 'string' &&
|
||||
value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION
|
||||
) {
|
||||
throw new BSONVersionError();
|
||||
} else if (value == null || value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1;
|
||||
} else if (value._bsontype === 'ObjectId') {
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (12 + 1);
|
||||
} else if (value instanceof Date || isDate(value)) {
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
||||
} else if (
|
||||
ArrayBuffer.isView(value) ||
|
||||
value instanceof ArrayBuffer ||
|
||||
isAnyArrayBuffer(value)
|
||||
) {
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (1 + 4 + 1) + value.byteLength
|
||||
);
|
||||
} else if (
|
||||
value._bsontype === 'Long' ||
|
||||
value._bsontype === 'Double' ||
|
||||
value._bsontype === 'Timestamp'
|
||||
) {
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
||||
} else if (value._bsontype === 'Decimal128') {
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (16 + 1);
|
||||
} else if (value._bsontype === 'Code') {
|
||||
// Calculate size depending on the availability of a scope
|
||||
if (value.scope != null && Object.keys(value.scope).length > 0) {
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) +
|
||||
1 +
|
||||
4 +
|
||||
4 +
|
||||
ByteUtils.utf8ByteLength(value.code.toString()) +
|
||||
1 +
|
||||
internalCalculateObjectSize(value.scope, serializeFunctions, ignoreUndefined)
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) +
|
||||
1 +
|
||||
4 +
|
||||
ByteUtils.utf8ByteLength(value.code.toString()) +
|
||||
1
|
||||
);
|
||||
}
|
||||
} else if (value._bsontype === 'Binary') {
|
||||
const binary: Binary = value;
|
||||
// Check what kind of subtype we have
|
||||
if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) +
|
||||
(binary.position + 1 + 4 + 1 + 4)
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (binary.position + 1 + 4 + 1)
|
||||
);
|
||||
}
|
||||
} else if (value._bsontype === 'Symbol') {
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) +
|
||||
ByteUtils.utf8ByteLength(value.value) +
|
||||
4 +
|
||||
1 +
|
||||
1
|
||||
);
|
||||
} else if (value._bsontype === 'DBRef') {
|
||||
// Set up correct object for serialization
|
||||
const ordered_values = Object.assign(
|
||||
{
|
||||
$ref: value.collection,
|
||||
$id: value.oid
|
||||
},
|
||||
value.fields
|
||||
);
|
||||
|
||||
// Add db reference if it exists
|
||||
if (value.db != null) {
|
||||
ordered_values['$db'] = value.db;
|
||||
}
|
||||
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) +
|
||||
1 +
|
||||
internalCalculateObjectSize(ordered_values, serializeFunctions, ignoreUndefined)
|
||||
);
|
||||
} else if (value instanceof RegExp || isRegExp(value)) {
|
||||
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
|
||||
);
|
||||
} else if (value._bsontype === 'BSONRegExp') {
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) +
|
||||
1 +
|
||||
ByteUtils.utf8ByteLength(value.pattern) +
|
||||
1 +
|
||||
ByteUtils.utf8ByteLength(value.options) +
|
||||
1
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) +
|
||||
internalCalculateObjectSize(value, serializeFunctions, ignoreUndefined) +
|
||||
1
|
||||
);
|
||||
}
|
||||
case 'function':
|
||||
if (serializeFunctions) {
|
||||
return (
|
||||
(name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) +
|
||||
1 +
|
||||
4 +
|
||||
ByteUtils.utf8ByteLength(value.toString()) +
|
||||
1
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
case 'bigint':
|
||||
return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
|
||||
case 'symbol':
|
||||
return 0;
|
||||
default:
|
||||
throw new BSONError(`Unrecognized JS type: ${typeof value}`);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
627
node_modules/bson/src/parser/deserializer.ts
generated
vendored
627
node_modules/bson/src/parser/deserializer.ts
generated
vendored
|
|
@ -1,627 +0,0 @@
|
|||
import { Binary, UUID } from '../binary';
|
||||
import type { Document } from '../bson';
|
||||
import { Code } from '../code';
|
||||
import * as constants from '../constants';
|
||||
import { DBRef, type DBRefLike, isDBRefLike } from '../db_ref';
|
||||
import { Decimal128 } from '../decimal128';
|
||||
import { Double } from '../double';
|
||||
import { BSONError } from '../error';
|
||||
import { Int32 } from '../int_32';
|
||||
import { Long } from '../long';
|
||||
import { MaxKey } from '../max_key';
|
||||
import { MinKey } from '../min_key';
|
||||
import { ObjectId } from '../objectid';
|
||||
import { BSONRegExp } from '../regexp';
|
||||
import { BSONSymbol } from '../symbol';
|
||||
import { Timestamp } from '../timestamp';
|
||||
import { ByteUtils } from '../utils/byte_utils';
|
||||
import { NumberUtils } from '../utils/number_utils';
|
||||
|
||||
/** @public */
|
||||
export interface DeserializeOptions {
|
||||
/**
|
||||
* when deserializing a Long return as a BigInt.
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
useBigInt64?: boolean;
|
||||
/**
|
||||
* when deserializing a Long will fit it into a Number if it's smaller than 53 bits.
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
promoteLongs?: boolean;
|
||||
/**
|
||||
* when deserializing a Binary will return it as a node.js Buffer instance.
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
promoteBuffers?: boolean;
|
||||
/**
|
||||
* when deserializing will promote BSON values to their Node.js closest equivalent types.
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
promoteValues?: boolean;
|
||||
/**
|
||||
* allow to specify if there what fields we wish to return as unserialized raw buffer.
|
||||
* @defaultValue `null`
|
||||
*/
|
||||
fieldsAsRaw?: Document;
|
||||
/**
|
||||
* return BSON regular expressions as BSONRegExp instances.
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
bsonRegExp?: boolean;
|
||||
/**
|
||||
* allows the buffer to be larger than the parsed BSON object.
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
allowObjectSmallerThanBufferSize?: boolean;
|
||||
/**
|
||||
* Offset into buffer to begin reading document from
|
||||
* @defaultValue `0`
|
||||
*/
|
||||
index?: number;
|
||||
|
||||
raw?: boolean;
|
||||
/** Allows for opt-out utf-8 validation for all keys or
|
||||
* specified keys. Must be all true or all false.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* // disables validation on all keys
|
||||
* validation: { utf8: false }
|
||||
*
|
||||
* // enables validation only on specified keys a, b, and c
|
||||
* validation: { utf8: { a: true, b: true, c: true } }
|
||||
*
|
||||
* // disables validation only on specified keys a, b
|
||||
* validation: { utf8: { a: false, b: false } }
|
||||
* ```
|
||||
*/
|
||||
validation?: { utf8: boolean | Record<string, true> | Record<string, false> };
|
||||
}
|
||||
|
||||
// Internal long versions
|
||||
const JS_INT_MAX_LONG = Long.fromNumber(constants.JS_INT_MAX);
|
||||
const JS_INT_MIN_LONG = Long.fromNumber(constants.JS_INT_MIN);
|
||||
|
||||
export function internalDeserialize(
|
||||
buffer: Uint8Array,
|
||||
options: DeserializeOptions,
|
||||
isArray?: boolean
|
||||
): Document {
|
||||
options = options == null ? {} : options;
|
||||
const index = options && options.index ? options.index : 0;
|
||||
// Read the document size
|
||||
const size = NumberUtils.getInt32LE(buffer, index);
|
||||
|
||||
if (size < 5) {
|
||||
throw new BSONError(`bson size must be >= 5, is ${size}`);
|
||||
}
|
||||
|
||||
if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
|
||||
throw new BSONError(`buffer length ${buffer.length} must be >= bson size ${size}`);
|
||||
}
|
||||
|
||||
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
|
||||
throw new BSONError(`buffer length ${buffer.length} must === bson size ${size}`);
|
||||
}
|
||||
|
||||
if (size + index > buffer.byteLength) {
|
||||
throw new BSONError(
|
||||
`(bson size ${size} + options.index ${index} must be <= buffer length ${buffer.byteLength})`
|
||||
);
|
||||
}
|
||||
|
||||
// Illegal end value
|
||||
if (buffer[index + size - 1] !== 0) {
|
||||
throw new BSONError(
|
||||
"One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00"
|
||||
);
|
||||
}
|
||||
|
||||
// Start deserialization
|
||||
return deserializeObject(buffer, index, options, isArray);
|
||||
}
|
||||
|
||||
const allowedDBRefKeys = /^\$ref$|^\$id$|^\$db$/;
|
||||
|
||||
function deserializeObject(
|
||||
buffer: Uint8Array,
|
||||
index: number,
|
||||
options: DeserializeOptions,
|
||||
isArray = false
|
||||
) {
|
||||
const fieldsAsRaw = options['fieldsAsRaw'] == null ? null : options['fieldsAsRaw'];
|
||||
|
||||
// Return raw bson buffer instead of parsing it
|
||||
const raw = options['raw'] == null ? false : options['raw'];
|
||||
|
||||
// Return BSONRegExp objects instead of native regular expressions
|
||||
const bsonRegExp = typeof options['bsonRegExp'] === 'boolean' ? options['bsonRegExp'] : false;
|
||||
|
||||
// Controls the promotion of values vs wrapper classes
|
||||
const promoteBuffers = options.promoteBuffers ?? false;
|
||||
const promoteLongs = options.promoteLongs ?? true;
|
||||
const promoteValues = options.promoteValues ?? true;
|
||||
const useBigInt64 = options.useBigInt64 ?? false;
|
||||
|
||||
if (useBigInt64 && !promoteValues) {
|
||||
throw new BSONError('Must either request bigint or Long for int64 deserialization');
|
||||
}
|
||||
|
||||
if (useBigInt64 && !promoteLongs) {
|
||||
throw new BSONError('Must either request bigint or Long for int64 deserialization');
|
||||
}
|
||||
|
||||
// Ensures default validation option if none given
|
||||
const validation = options.validation == null ? { utf8: true } : options.validation;
|
||||
|
||||
// Shows if global utf-8 validation is enabled or disabled
|
||||
let globalUTFValidation = true;
|
||||
// Reflects utf-8 validation setting regardless of global or specific key validation
|
||||
let validationSetting: boolean;
|
||||
// Set of keys either to enable or disable validation on
|
||||
let utf8KeysSet;
|
||||
|
||||
// Check for boolean uniformity and empty validation option
|
||||
const utf8ValidatedKeys = validation.utf8;
|
||||
if (typeof utf8ValidatedKeys === 'boolean') {
|
||||
validationSetting = utf8ValidatedKeys;
|
||||
} else {
|
||||
globalUTFValidation = false;
|
||||
const utf8ValidationValues = Object.keys(utf8ValidatedKeys).map(function (key) {
|
||||
return utf8ValidatedKeys[key];
|
||||
});
|
||||
if (utf8ValidationValues.length === 0) {
|
||||
throw new BSONError('UTF-8 validation setting cannot be empty');
|
||||
}
|
||||
if (typeof utf8ValidationValues[0] !== 'boolean') {
|
||||
throw new BSONError('Invalid UTF-8 validation option, must specify boolean values');
|
||||
}
|
||||
validationSetting = utf8ValidationValues[0];
|
||||
// Ensures boolean uniformity in utf-8 validation (all true or all false)
|
||||
if (!utf8ValidationValues.every(item => item === validationSetting)) {
|
||||
throw new BSONError('Invalid UTF-8 validation option - keys must be all true or all false');
|
||||
}
|
||||
}
|
||||
|
||||
// Add keys to set that will either be validated or not based on validationSetting
|
||||
if (!globalUTFValidation) {
|
||||
utf8KeysSet = new Set();
|
||||
|
||||
for (const key of Object.keys(utf8ValidatedKeys)) {
|
||||
utf8KeysSet.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the start index
|
||||
const startIndex = index;
|
||||
|
||||
// Validate that we have at least 4 bytes of buffer
|
||||
if (buffer.length < 5) throw new BSONError('corrupt bson message < 5 bytes long');
|
||||
|
||||
// Read the document size
|
||||
const size = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
|
||||
// Ensure buffer is valid size
|
||||
if (size < 5 || size > buffer.length) throw new BSONError('corrupt bson message');
|
||||
|
||||
// Create holding object
|
||||
const object: Document = isArray ? [] : {};
|
||||
// Used for arrays to skip having to perform utf8 decoding
|
||||
let arrayIndex = 0;
|
||||
const done = false;
|
||||
|
||||
let isPossibleDBRef = isArray ? false : null;
|
||||
|
||||
// While we have more left data left keep parsing
|
||||
while (!done) {
|
||||
// Read the type
|
||||
const elementType = buffer[index++];
|
||||
|
||||
// If we get a zero it's the last byte, exit
|
||||
if (elementType === 0) break;
|
||||
|
||||
// Get the start search index
|
||||
let i = index;
|
||||
// Locate the end of the c string
|
||||
while (buffer[i] !== 0x00 && i < buffer.length) {
|
||||
i++;
|
||||
}
|
||||
|
||||
// If are at the end of the buffer there is a problem with the document
|
||||
if (i >= buffer.byteLength) throw new BSONError('Bad BSON Document: illegal CString');
|
||||
|
||||
// Represents the key
|
||||
const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer, index, i, false);
|
||||
|
||||
// shouldValidateKey is true if the key should be validated, false otherwise
|
||||
let shouldValidateKey = true;
|
||||
if (globalUTFValidation || utf8KeysSet?.has(name)) {
|
||||
shouldValidateKey = validationSetting;
|
||||
} else {
|
||||
shouldValidateKey = !validationSetting;
|
||||
}
|
||||
|
||||
if (isPossibleDBRef !== false && (name as string)[0] === '$') {
|
||||
isPossibleDBRef = allowedDBRefKeys.test(name as string);
|
||||
}
|
||||
let value;
|
||||
|
||||
index = i + 1;
|
||||
|
||||
if (elementType === constants.BSON_DATA_STRING) {
|
||||
const stringSize = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
if (
|
||||
stringSize <= 0 ||
|
||||
stringSize > buffer.length - index ||
|
||||
buffer[index + stringSize - 1] !== 0
|
||||
) {
|
||||
throw new BSONError('bad string length in bson');
|
||||
}
|
||||
value = ByteUtils.toUTF8(buffer, index, index + stringSize - 1, shouldValidateKey);
|
||||
index = index + stringSize;
|
||||
} else if (elementType === constants.BSON_DATA_OID) {
|
||||
const oid = ByteUtils.allocateUnsafe(12);
|
||||
for (let i = 0; i < 12; i++) oid[i] = buffer[index + i];
|
||||
value = new ObjectId(oid);
|
||||
index = index + 12;
|
||||
} else if (elementType === constants.BSON_DATA_INT && promoteValues === false) {
|
||||
value = new Int32(NumberUtils.getInt32LE(buffer, index));
|
||||
index += 4;
|
||||
} else if (elementType === constants.BSON_DATA_INT) {
|
||||
value = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
} else if (elementType === constants.BSON_DATA_NUMBER) {
|
||||
value = NumberUtils.getFloat64LE(buffer, index);
|
||||
index += 8;
|
||||
if (promoteValues === false) value = new Double(value);
|
||||
} else if (elementType === constants.BSON_DATA_DATE) {
|
||||
const lowBits = NumberUtils.getInt32LE(buffer, index);
|
||||
const highBits = NumberUtils.getInt32LE(buffer, index + 4);
|
||||
index += 8;
|
||||
|
||||
value = new Date(new Long(lowBits, highBits).toNumber());
|
||||
} else if (elementType === constants.BSON_DATA_BOOLEAN) {
|
||||
if (buffer[index] !== 0 && buffer[index] !== 1)
|
||||
throw new BSONError('illegal boolean type value');
|
||||
value = buffer[index++] === 1;
|
||||
} else if (elementType === constants.BSON_DATA_OBJECT) {
|
||||
const _index = index;
|
||||
const objectSize = NumberUtils.getInt32LE(buffer, index);
|
||||
|
||||
if (objectSize <= 0 || objectSize > buffer.length - index)
|
||||
throw new BSONError('bad embedded document length in bson');
|
||||
|
||||
// We have a raw value
|
||||
if (raw) {
|
||||
value = buffer.subarray(index, index + objectSize);
|
||||
} else {
|
||||
let objectOptions = options;
|
||||
if (!globalUTFValidation) {
|
||||
objectOptions = { ...options, validation: { utf8: shouldValidateKey } };
|
||||
}
|
||||
value = deserializeObject(buffer, _index, objectOptions, false);
|
||||
}
|
||||
|
||||
index = index + objectSize;
|
||||
} else if (elementType === constants.BSON_DATA_ARRAY) {
|
||||
const _index = index;
|
||||
const objectSize = NumberUtils.getInt32LE(buffer, index);
|
||||
let arrayOptions: DeserializeOptions = options;
|
||||
|
||||
// Stop index
|
||||
const stopIndex = index + objectSize;
|
||||
|
||||
// All elements of array to be returned as raw bson
|
||||
if (fieldsAsRaw && fieldsAsRaw[name]) {
|
||||
arrayOptions = { ...options, raw: true };
|
||||
}
|
||||
|
||||
if (!globalUTFValidation) {
|
||||
arrayOptions = { ...arrayOptions, validation: { utf8: shouldValidateKey } };
|
||||
}
|
||||
value = deserializeObject(buffer, _index, arrayOptions, true);
|
||||
index = index + objectSize;
|
||||
|
||||
if (buffer[index - 1] !== 0) throw new BSONError('invalid array terminator byte');
|
||||
if (index !== stopIndex) throw new BSONError('corrupted array bson');
|
||||
} else if (elementType === constants.BSON_DATA_UNDEFINED) {
|
||||
value = undefined;
|
||||
} else if (elementType === constants.BSON_DATA_NULL) {
|
||||
value = null;
|
||||
} else if (elementType === constants.BSON_DATA_LONG) {
|
||||
if (useBigInt64) {
|
||||
value = NumberUtils.getBigInt64LE(buffer, index);
|
||||
index += 8;
|
||||
} else {
|
||||
// Unpack the low and high bits
|
||||
const lowBits = NumberUtils.getInt32LE(buffer, index);
|
||||
const highBits = NumberUtils.getInt32LE(buffer, index + 4);
|
||||
index += 8;
|
||||
|
||||
const long = new Long(lowBits, highBits);
|
||||
// Promote the long if possible
|
||||
if (promoteLongs && promoteValues === true) {
|
||||
value =
|
||||
long.lessThanOrEqual(JS_INT_MAX_LONG) && long.greaterThanOrEqual(JS_INT_MIN_LONG)
|
||||
? long.toNumber()
|
||||
: long;
|
||||
} else {
|
||||
value = long;
|
||||
}
|
||||
}
|
||||
} else if (elementType === constants.BSON_DATA_DECIMAL128) {
|
||||
// Buffer to contain the decimal bytes
|
||||
const bytes = ByteUtils.allocateUnsafe(16);
|
||||
// Copy the next 16 bytes into the bytes buffer
|
||||
for (let i = 0; i < 16; i++) bytes[i] = buffer[index + i];
|
||||
// Update index
|
||||
index = index + 16;
|
||||
// Assign the new Decimal128 value
|
||||
value = new Decimal128(bytes);
|
||||
} else if (elementType === constants.BSON_DATA_BINARY) {
|
||||
let binarySize = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
const totalBinarySize = binarySize;
|
||||
const subType = buffer[index++];
|
||||
|
||||
// Did we have a negative binary size, throw
|
||||
if (binarySize < 0) throw new BSONError('Negative binary type element size found');
|
||||
|
||||
// Is the length longer than the document
|
||||
if (binarySize > buffer.byteLength)
|
||||
throw new BSONError('Binary type size larger than document size');
|
||||
|
||||
// If we have subtype 2 skip the 4 bytes for the size
|
||||
if (subType === Binary.SUBTYPE_BYTE_ARRAY) {
|
||||
binarySize = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
if (binarySize < 0)
|
||||
throw new BSONError('Negative binary type element size found for subtype 0x02');
|
||||
if (binarySize > totalBinarySize - 4)
|
||||
throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
|
||||
if (binarySize < totalBinarySize - 4)
|
||||
throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
|
||||
}
|
||||
|
||||
if (promoteBuffers && promoteValues) {
|
||||
value = ByteUtils.toLocalBufferType(buffer.subarray(index, index + binarySize));
|
||||
} else {
|
||||
value = new Binary(buffer.subarray(index, index + binarySize), subType);
|
||||
if (subType === constants.BSON_BINARY_SUBTYPE_UUID_NEW && UUID.isValid(value)) {
|
||||
value = value.toUUID();
|
||||
}
|
||||
}
|
||||
|
||||
// Update the index
|
||||
index = index + binarySize;
|
||||
} else if (elementType === constants.BSON_DATA_REGEXP && bsonRegExp === false) {
|
||||
// Get the start search index
|
||||
i = index;
|
||||
// Locate the end of the c string
|
||||
while (buffer[i] !== 0x00 && i < buffer.length) {
|
||||
i++;
|
||||
}
|
||||
// If are at the end of the buffer there is a problem with the document
|
||||
if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString');
|
||||
// Return the C string
|
||||
const source = ByteUtils.toUTF8(buffer, index, i, false);
|
||||
// Create the regexp
|
||||
index = i + 1;
|
||||
|
||||
// Get the start search index
|
||||
i = index;
|
||||
// Locate the end of the c string
|
||||
while (buffer[i] !== 0x00 && i < buffer.length) {
|
||||
i++;
|
||||
}
|
||||
// If are at the end of the buffer there is a problem with the document
|
||||
if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString');
|
||||
// Return the C string
|
||||
const regExpOptions = ByteUtils.toUTF8(buffer, index, i, false);
|
||||
index = i + 1;
|
||||
|
||||
// For each option add the corresponding one for javascript
|
||||
const optionsArray = new Array(regExpOptions.length);
|
||||
|
||||
// Parse options
|
||||
for (i = 0; i < regExpOptions.length; i++) {
|
||||
switch (regExpOptions[i]) {
|
||||
case 'm':
|
||||
optionsArray[i] = 'm';
|
||||
break;
|
||||
case 's':
|
||||
optionsArray[i] = 'g';
|
||||
break;
|
||||
case 'i':
|
||||
optionsArray[i] = 'i';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
value = new RegExp(source, optionsArray.join(''));
|
||||
} else if (elementType === constants.BSON_DATA_REGEXP && bsonRegExp === true) {
|
||||
// Get the start search index
|
||||
i = index;
|
||||
// Locate the end of the c string
|
||||
while (buffer[i] !== 0x00 && i < buffer.length) {
|
||||
i++;
|
||||
}
|
||||
// If are at the end of the buffer there is a problem with the document
|
||||
if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString');
|
||||
// Return the C string
|
||||
const source = ByteUtils.toUTF8(buffer, index, i, false);
|
||||
index = i + 1;
|
||||
|
||||
// Get the start search index
|
||||
i = index;
|
||||
// Locate the end of the c string
|
||||
while (buffer[i] !== 0x00 && i < buffer.length) {
|
||||
i++;
|
||||
}
|
||||
// If are at the end of the buffer there is a problem with the document
|
||||
if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString');
|
||||
// Return the C string
|
||||
const regExpOptions = ByteUtils.toUTF8(buffer, index, i, false);
|
||||
index = i + 1;
|
||||
|
||||
// Set the object
|
||||
value = new BSONRegExp(source, regExpOptions);
|
||||
} else if (elementType === constants.BSON_DATA_SYMBOL) {
|
||||
const stringSize = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
if (
|
||||
stringSize <= 0 ||
|
||||
stringSize > buffer.length - index ||
|
||||
buffer[index + stringSize - 1] !== 0
|
||||
) {
|
||||
throw new BSONError('bad string length in bson');
|
||||
}
|
||||
const symbol = ByteUtils.toUTF8(buffer, index, index + stringSize - 1, shouldValidateKey);
|
||||
value = promoteValues ? symbol : new BSONSymbol(symbol);
|
||||
index = index + stringSize;
|
||||
} else if (elementType === constants.BSON_DATA_TIMESTAMP) {
|
||||
value = new Timestamp({
|
||||
i: NumberUtils.getUint32LE(buffer, index),
|
||||
t: NumberUtils.getUint32LE(buffer, index + 4)
|
||||
});
|
||||
index += 8;
|
||||
} else if (elementType === constants.BSON_DATA_MIN_KEY) {
|
||||
value = new MinKey();
|
||||
} else if (elementType === constants.BSON_DATA_MAX_KEY) {
|
||||
value = new MaxKey();
|
||||
} else if (elementType === constants.BSON_DATA_CODE) {
|
||||
const stringSize = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
if (
|
||||
stringSize <= 0 ||
|
||||
stringSize > buffer.length - index ||
|
||||
buffer[index + stringSize - 1] !== 0
|
||||
) {
|
||||
throw new BSONError('bad string length in bson');
|
||||
}
|
||||
const functionString = ByteUtils.toUTF8(
|
||||
buffer,
|
||||
index,
|
||||
index + stringSize - 1,
|
||||
shouldValidateKey
|
||||
);
|
||||
|
||||
value = new Code(functionString);
|
||||
|
||||
// Update parse index position
|
||||
index = index + stringSize;
|
||||
} else if (elementType === constants.BSON_DATA_CODE_W_SCOPE) {
|
||||
const totalSize = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
|
||||
// Element cannot be shorter than totalSize + stringSize + documentSize + terminator
|
||||
if (totalSize < 4 + 4 + 4 + 1) {
|
||||
throw new BSONError('code_w_scope total size shorter minimum expected length');
|
||||
}
|
||||
|
||||
// Get the code string size
|
||||
const stringSize = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
// Check if we have a valid string
|
||||
if (
|
||||
stringSize <= 0 ||
|
||||
stringSize > buffer.length - index ||
|
||||
buffer[index + stringSize - 1] !== 0
|
||||
) {
|
||||
throw new BSONError('bad string length in bson');
|
||||
}
|
||||
|
||||
// Javascript function
|
||||
const functionString = ByteUtils.toUTF8(
|
||||
buffer,
|
||||
index,
|
||||
index + stringSize - 1,
|
||||
shouldValidateKey
|
||||
);
|
||||
// Update parse index position
|
||||
index = index + stringSize;
|
||||
// Parse the element
|
||||
const _index = index;
|
||||
// Decode the size of the object document
|
||||
const objectSize = NumberUtils.getInt32LE(buffer, index);
|
||||
// Decode the scope object
|
||||
const scopeObject = deserializeObject(buffer, _index, options, false);
|
||||
// Adjust the index
|
||||
index = index + objectSize;
|
||||
|
||||
// Check if field length is too short
|
||||
if (totalSize < 4 + 4 + objectSize + stringSize) {
|
||||
throw new BSONError('code_w_scope total size is too short, truncating scope');
|
||||
}
|
||||
|
||||
// Check if totalSize field is too long
|
||||
if (totalSize > 4 + 4 + objectSize + stringSize) {
|
||||
throw new BSONError('code_w_scope total size is too long, clips outer document');
|
||||
}
|
||||
|
||||
value = new Code(functionString, scopeObject);
|
||||
} else if (elementType === constants.BSON_DATA_DBPOINTER) {
|
||||
// Get the code string size
|
||||
const stringSize = NumberUtils.getInt32LE(buffer, index);
|
||||
index += 4;
|
||||
// Check if we have a valid string
|
||||
if (
|
||||
stringSize <= 0 ||
|
||||
stringSize > buffer.length - index ||
|
||||
buffer[index + stringSize - 1] !== 0
|
||||
)
|
||||
throw new BSONError('bad string length in bson');
|
||||
// Namespace
|
||||
const namespace = ByteUtils.toUTF8(buffer, index, index + stringSize - 1, shouldValidateKey);
|
||||
// Update parse index position
|
||||
index = index + stringSize;
|
||||
|
||||
// Read the oid
|
||||
const oidBuffer = ByteUtils.allocateUnsafe(12);
|
||||
for (let i = 0; i < 12; i++) oidBuffer[i] = buffer[index + i];
|
||||
const oid = new ObjectId(oidBuffer);
|
||||
|
||||
// Update the index
|
||||
index = index + 12;
|
||||
|
||||
// Upgrade to DBRef type
|
||||
value = new DBRef(namespace, oid);
|
||||
} else {
|
||||
throw new BSONError(
|
||||
`Detected unknown BSON type ${elementType.toString(16)} for fieldname "${name}"`
|
||||
);
|
||||
}
|
||||
if (name === '__proto__') {
|
||||
Object.defineProperty(object, name, {
|
||||
value,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
} else {
|
||||
object[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the deserialization was against a valid array/object
|
||||
if (size !== index - startIndex) {
|
||||
if (isArray) throw new BSONError('corrupt array bson');
|
||||
throw new BSONError('corrupt object bson');
|
||||
}
|
||||
|
||||
// if we did not find "$ref", "$id", "$db", or found an extraneous $key, don't make a DBRef
|
||||
if (!isPossibleDBRef) return object;
|
||||
|
||||
if (isDBRefLike(object)) {
|
||||
const copy = Object.assign({}, object) as Partial<DBRefLike>;
|
||||
delete copy.$ref;
|
||||
delete copy.$id;
|
||||
delete copy.$db;
|
||||
return new DBRef(object.$ref, object.$id, object.$db, copy);
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
32
node_modules/bson/src/parser/on_demand/index.ts
generated
vendored
32
node_modules/bson/src/parser/on_demand/index.ts
generated
vendored
|
|
@ -1,32 +0,0 @@
|
|||
import { ByteUtils } from '../../utils/byte_utils';
|
||||
import { NumberUtils } from '../../utils/number_utils';
|
||||
import { type BSONElement, parseToElements } from './parse_to_elements';
|
||||
/**
|
||||
* @experimental
|
||||
* @public
|
||||
*
|
||||
* A new set of BSON APIs that are currently experimental and not intended for production use.
|
||||
*/
|
||||
export type OnDemand = {
|
||||
parseToElements: (this: void, bytes: Uint8Array, startOffset?: number) => Iterable<BSONElement>;
|
||||
// Types
|
||||
BSONElement: BSONElement;
|
||||
|
||||
// Utils
|
||||
ByteUtils: ByteUtils;
|
||||
NumberUtils: NumberUtils;
|
||||
};
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
* @public
|
||||
*/
|
||||
const onDemand: OnDemand = Object.create(null);
|
||||
|
||||
onDemand.parseToElements = parseToElements;
|
||||
onDemand.ByteUtils = ByteUtils;
|
||||
onDemand.NumberUtils = NumberUtils;
|
||||
|
||||
Object.freeze(onDemand);
|
||||
|
||||
export { onDemand };
|
||||
190
node_modules/bson/src/parser/on_demand/parse_to_elements.ts
generated
vendored
190
node_modules/bson/src/parser/on_demand/parse_to_elements.ts
generated
vendored
|
|
@ -1,190 +0,0 @@
|
|||
import { BSONOffsetError } from '../../error';
|
||||
import { NumberUtils } from '../../utils/number_utils';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @remarks
|
||||
* - This enum is const so the code we produce will inline the numbers
|
||||
* - `minKey` is set to 255 so unsigned comparisons succeed
|
||||
* - Modify with caution, double check the bundle contains literals
|
||||
*/
|
||||
const BSONElementType = {
|
||||
double: 1,
|
||||
string: 2,
|
||||
object: 3,
|
||||
array: 4,
|
||||
binData: 5,
|
||||
undefined: 6,
|
||||
objectId: 7,
|
||||
bool: 8,
|
||||
date: 9,
|
||||
null: 10,
|
||||
regex: 11,
|
||||
dbPointer: 12,
|
||||
javascript: 13,
|
||||
symbol: 14,
|
||||
javascriptWithScope: 15,
|
||||
int: 16,
|
||||
timestamp: 17,
|
||||
long: 18,
|
||||
decimal: 19,
|
||||
minKey: 255,
|
||||
maxKey: 127
|
||||
} as const;
|
||||
|
||||
type BSONElementType = (typeof BSONElementType)[keyof typeof BSONElementType];
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @experimental
|
||||
*/
|
||||
export type BSONElement = [
|
||||
type: number,
|
||||
nameOffset: number,
|
||||
nameLength: number,
|
||||
offset: number,
|
||||
length: number
|
||||
];
|
||||
|
||||
function getSize(source: Uint8Array, offset: number) {
|
||||
try {
|
||||
return NumberUtils.getNonnegativeInt32LE(source, offset);
|
||||
} catch (cause) {
|
||||
throw new BSONOffsetError('BSON size cannot be negative', offset, { cause });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for null terminator of a BSON element's value (Never the document null terminator)
|
||||
* **Does not** bounds check since this should **ONLY** be used within parseToElements which has asserted that `bytes` ends with a `0x00`.
|
||||
* So this will at most iterate to the document's terminator and error if that is the offset reached.
|
||||
*/
|
||||
function findNull(bytes: Uint8Array, offset: number): number {
|
||||
let nullTerminatorOffset = offset;
|
||||
|
||||
for (; bytes[nullTerminatorOffset] !== 0x00; nullTerminatorOffset++);
|
||||
|
||||
if (nullTerminatorOffset === bytes.length - 1) {
|
||||
// We reached the null terminator of the document, not a value's
|
||||
throw new BSONOffsetError('Null terminator not found', offset);
|
||||
}
|
||||
|
||||
return nullTerminatorOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @experimental
|
||||
*/
|
||||
export function parseToElements(
|
||||
bytes: Uint8Array,
|
||||
startOffset: number | null = 0
|
||||
): Iterable<BSONElement> {
|
||||
startOffset ??= 0;
|
||||
|
||||
if (bytes.length < 5) {
|
||||
throw new BSONOffsetError(
|
||||
`Input must be at least 5 bytes, got ${bytes.length} bytes`,
|
||||
startOffset
|
||||
);
|
||||
}
|
||||
|
||||
const documentSize = getSize(bytes, startOffset);
|
||||
|
||||
if (documentSize > bytes.length - startOffset) {
|
||||
throw new BSONOffsetError(
|
||||
`Parsed documentSize (${documentSize} bytes) does not match input length (${bytes.length} bytes)`,
|
||||
startOffset
|
||||
);
|
||||
}
|
||||
|
||||
if (bytes[startOffset + documentSize - 1] !== 0x00) {
|
||||
throw new BSONOffsetError('BSON documents must end in 0x00', startOffset + documentSize);
|
||||
}
|
||||
|
||||
const elements: BSONElement[] = [];
|
||||
let offset = startOffset + 4;
|
||||
|
||||
while (offset <= documentSize + startOffset) {
|
||||
const type = bytes[offset];
|
||||
offset += 1;
|
||||
|
||||
if (type === 0) {
|
||||
if (offset - startOffset !== documentSize) {
|
||||
throw new BSONOffsetError(`Invalid 0x00 type byte`, offset);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
const nameOffset = offset;
|
||||
const nameLength = findNull(bytes, offset) - nameOffset;
|
||||
offset += nameLength + 1;
|
||||
|
||||
let length: number;
|
||||
|
||||
if (
|
||||
type === BSONElementType.double ||
|
||||
type === BSONElementType.long ||
|
||||
type === BSONElementType.date ||
|
||||
type === BSONElementType.timestamp
|
||||
) {
|
||||
length = 8;
|
||||
} else if (type === BSONElementType.int) {
|
||||
length = 4;
|
||||
} else if (type === BSONElementType.objectId) {
|
||||
length = 12;
|
||||
} else if (type === BSONElementType.decimal) {
|
||||
length = 16;
|
||||
} else if (type === BSONElementType.bool) {
|
||||
length = 1;
|
||||
} else if (
|
||||
type === BSONElementType.null ||
|
||||
type === BSONElementType.undefined ||
|
||||
type === BSONElementType.maxKey ||
|
||||
type === BSONElementType.minKey
|
||||
) {
|
||||
length = 0;
|
||||
}
|
||||
// Needs a size calculation
|
||||
else if (type === BSONElementType.regex) {
|
||||
length = findNull(bytes, findNull(bytes, offset) + 1) + 1 - offset;
|
||||
} else if (
|
||||
type === BSONElementType.object ||
|
||||
type === BSONElementType.array ||
|
||||
type === BSONElementType.javascriptWithScope
|
||||
) {
|
||||
length = getSize(bytes, offset);
|
||||
} else if (
|
||||
type === BSONElementType.string ||
|
||||
type === BSONElementType.binData ||
|
||||
type === BSONElementType.dbPointer ||
|
||||
type === BSONElementType.javascript ||
|
||||
type === BSONElementType.symbol
|
||||
) {
|
||||
length = getSize(bytes, offset) + 4;
|
||||
if (type === BSONElementType.binData) {
|
||||
// binary subtype
|
||||
length += 1;
|
||||
}
|
||||
if (type === BSONElementType.dbPointer) {
|
||||
// dbPointer's objectId
|
||||
length += 12;
|
||||
}
|
||||
} else {
|
||||
throw new BSONOffsetError(
|
||||
`Invalid 0x${type.toString(16).padStart(2, '0')} type byte`,
|
||||
offset
|
||||
);
|
||||
}
|
||||
|
||||
if (length > documentSize) {
|
||||
throw new BSONOffsetError('value reports length larger than document', offset);
|
||||
}
|
||||
|
||||
elements.push([type, nameOffset, nameLength, offset, length]);
|
||||
offset += length;
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
954
node_modules/bson/src/parser/serializer.ts
generated
vendored
954
node_modules/bson/src/parser/serializer.ts
generated
vendored
|
|
@ -1,954 +0,0 @@
|
|||
import { Binary, validateBinaryVector } from '../binary';
|
||||
import type { BSONSymbol, DBRef, Document, MaxKey } from '../bson';
|
||||
import type { Code } from '../code';
|
||||
import * as constants from '../constants';
|
||||
import type { DBRefLike } from '../db_ref';
|
||||
import type { Decimal128 } from '../decimal128';
|
||||
import type { Double } from '../double';
|
||||
import { BSONError, BSONVersionError } from '../error';
|
||||
import type { Int32 } from '../int_32';
|
||||
import { Long } from '../long';
|
||||
import type { MinKey } from '../min_key';
|
||||
import type { ObjectId } from '../objectid';
|
||||
import type { BSONRegExp } from '../regexp';
|
||||
import { ByteUtils } from '../utils/byte_utils';
|
||||
import { NumberUtils } from '../utils/number_utils';
|
||||
import { isAnyArrayBuffer, isDate, isMap, isRegExp, isUint8Array } from './utils';
|
||||
|
||||
/** @public */
|
||||
export interface SerializeOptions {
|
||||
/**
|
||||
* the serializer will check if keys are valid.
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
checkKeys?: boolean;
|
||||
/**
|
||||
* serialize the javascript functions
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
serializeFunctions?: boolean;
|
||||
/**
|
||||
* serialize will not emit undefined fields
|
||||
* note that the driver sets this to `false`
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
ignoreUndefined?: boolean;
|
||||
/** @internal Resize internal buffer */
|
||||
minInternalBufferSize?: number;
|
||||
/**
|
||||
* the index in the buffer where we wish to start serializing into
|
||||
* @defaultValue `0`
|
||||
*/
|
||||
index?: number;
|
||||
}
|
||||
|
||||
const regexp = /\x00/; // eslint-disable-line no-control-regex
|
||||
const ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
|
||||
|
||||
/*
|
||||
* isArray indicates if we are writing to a BSON array (type 0x04)
|
||||
* which forces the "key" which really an array index as a string to be written as ascii
|
||||
* This will catch any errors in index as a string generation
|
||||
*/
|
||||
|
||||
function serializeString(buffer: Uint8Array, key: string, value: string, index: number) {
|
||||
// Encode String type
|
||||
buffer[index++] = constants.BSON_DATA_STRING;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes + 1;
|
||||
buffer[index - 1] = 0;
|
||||
// Write the string
|
||||
const size = ByteUtils.encodeUTF8Into(buffer, value, index + 4);
|
||||
// Write the size of the string to buffer
|
||||
NumberUtils.setInt32LE(buffer, index, size + 1);
|
||||
// Update index
|
||||
index = index + 4 + size;
|
||||
// Write zero
|
||||
buffer[index++] = 0;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeNumber(buffer: Uint8Array, key: string, value: number, index: number) {
|
||||
const isNegativeZero = Object.is(value, -0);
|
||||
|
||||
const type =
|
||||
!isNegativeZero &&
|
||||
Number.isSafeInteger(value) &&
|
||||
value <= constants.BSON_INT32_MAX &&
|
||||
value >= constants.BSON_INT32_MIN
|
||||
? constants.BSON_DATA_INT
|
||||
: constants.BSON_DATA_NUMBER;
|
||||
|
||||
buffer[index++] = type;
|
||||
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0x00;
|
||||
|
||||
if (type === constants.BSON_DATA_INT) {
|
||||
index += NumberUtils.setInt32LE(buffer, index, value);
|
||||
} else {
|
||||
index += NumberUtils.setFloat64LE(buffer, index, value);
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeBigInt(buffer: Uint8Array, key: string, value: bigint, index: number) {
|
||||
buffer[index++] = constants.BSON_DATA_LONG;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index += numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
|
||||
index += NumberUtils.setBigInt64LE(buffer, index, value);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeNull(buffer: Uint8Array, key: string, _: unknown, index: number) {
|
||||
// Set long type
|
||||
buffer[index++] = constants.BSON_DATA_NULL;
|
||||
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeBoolean(buffer: Uint8Array, key: string, value: boolean, index: number) {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_BOOLEAN;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
// Encode the boolean value
|
||||
buffer[index++] = value ? 1 : 0;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeDate(buffer: Uint8Array, key: string, value: Date, index: number) {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_DATE;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
|
||||
// Write the date
|
||||
const dateInMilis = Long.fromNumber(value.getTime());
|
||||
const lowBits = dateInMilis.getLowBits();
|
||||
const highBits = dateInMilis.getHighBits();
|
||||
// Encode low bits
|
||||
index += NumberUtils.setInt32LE(buffer, index, lowBits);
|
||||
// Encode high bits
|
||||
index += NumberUtils.setInt32LE(buffer, index, highBits);
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeRegExp(buffer: Uint8Array, key: string, value: RegExp, index: number) {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_REGEXP;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
if (value.source && value.source.match(regexp) != null) {
|
||||
throw new BSONError('value ' + value.source + ' must not contain null bytes');
|
||||
}
|
||||
// Adjust the index
|
||||
index = index + ByteUtils.encodeUTF8Into(buffer, value.source, index);
|
||||
// Write zero
|
||||
buffer[index++] = 0x00;
|
||||
// Write the parameters
|
||||
if (value.ignoreCase) buffer[index++] = 0x69; // i
|
||||
if (value.global) buffer[index++] = 0x73; // s
|
||||
if (value.multiline) buffer[index++] = 0x6d; // m
|
||||
|
||||
// Add ending zero
|
||||
buffer[index++] = 0x00;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeBSONRegExp(buffer: Uint8Array, key: string, value: BSONRegExp, index: number) {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_REGEXP;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
|
||||
// Check the pattern for 0 bytes
|
||||
if (value.pattern.match(regexp) != null) {
|
||||
// The BSON spec doesn't allow keys with null bytes because keys are
|
||||
// null-terminated.
|
||||
throw new BSONError('pattern ' + value.pattern + ' must not contain null bytes');
|
||||
}
|
||||
|
||||
// Adjust the index
|
||||
index = index + ByteUtils.encodeUTF8Into(buffer, value.pattern, index);
|
||||
// Write zero
|
||||
buffer[index++] = 0x00;
|
||||
// Write the options
|
||||
const sortedOptions = value.options.split('').sort().join('');
|
||||
index = index + ByteUtils.encodeUTF8Into(buffer, sortedOptions, index);
|
||||
// Add ending zero
|
||||
buffer[index++] = 0x00;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeMinMax(buffer: Uint8Array, key: string, value: MinKey | MaxKey, index: number) {
|
||||
// Write the type of either min or max key
|
||||
if (value === null) {
|
||||
buffer[index++] = constants.BSON_DATA_NULL;
|
||||
} else if (value._bsontype === 'MinKey') {
|
||||
buffer[index++] = constants.BSON_DATA_MIN_KEY;
|
||||
} else {
|
||||
buffer[index++] = constants.BSON_DATA_MAX_KEY;
|
||||
}
|
||||
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeObjectId(buffer: Uint8Array, key: string, value: ObjectId, index: number) {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_OID;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
|
||||
index += value.serializeInto(buffer, index);
|
||||
|
||||
// Adjust index
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeBuffer(buffer: Uint8Array, key: string, value: Uint8Array, index: number) {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_BINARY;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
// Get size of the buffer (current write point)
|
||||
const size = value.length;
|
||||
// Write the size of the string to buffer
|
||||
index += NumberUtils.setInt32LE(buffer, index, size);
|
||||
// Write the default subtype
|
||||
buffer[index++] = constants.BSON_BINARY_SUBTYPE_DEFAULT;
|
||||
// Copy the content form the binary field to the buffer
|
||||
if (size <= 16) {
|
||||
for (let i = 0; i < size; i++) buffer[index + i] = value[i];
|
||||
} else {
|
||||
buffer.set(value, index);
|
||||
}
|
||||
// Adjust the index
|
||||
index = index + size;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeObject(
|
||||
buffer: Uint8Array,
|
||||
key: string,
|
||||
value: Document,
|
||||
index: number,
|
||||
checkKeys: boolean,
|
||||
depth: number,
|
||||
serializeFunctions: boolean,
|
||||
ignoreUndefined: boolean,
|
||||
path: Set<Document>
|
||||
) {
|
||||
if (path.has(value)) {
|
||||
throw new BSONError('Cannot convert circular structure to BSON');
|
||||
}
|
||||
|
||||
path.add(value);
|
||||
|
||||
// Write the type
|
||||
buffer[index++] = Array.isArray(value) ? constants.BSON_DATA_ARRAY : constants.BSON_DATA_OBJECT;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
const endIndex = serializeInto(
|
||||
buffer,
|
||||
value,
|
||||
checkKeys,
|
||||
index,
|
||||
depth + 1,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
path
|
||||
);
|
||||
|
||||
path.delete(value);
|
||||
|
||||
return endIndex;
|
||||
}
|
||||
|
||||
function serializeDecimal128(buffer: Uint8Array, key: string, value: Decimal128, index: number) {
|
||||
buffer[index++] = constants.BSON_DATA_DECIMAL128;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
// Write the data from the value
|
||||
for (let i = 0; i < 16; i++) buffer[index + i] = value.bytes[i];
|
||||
return index + 16;
|
||||
}
|
||||
|
||||
function serializeLong(buffer: Uint8Array, key: string, value: Long, index: number) {
|
||||
// Write the type
|
||||
buffer[index++] =
|
||||
value._bsontype === 'Long' ? constants.BSON_DATA_LONG : constants.BSON_DATA_TIMESTAMP;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
// Write the date
|
||||
const lowBits = value.getLowBits();
|
||||
const highBits = value.getHighBits();
|
||||
// Encode low bits
|
||||
index += NumberUtils.setInt32LE(buffer, index, lowBits);
|
||||
// Encode high bits
|
||||
index += NumberUtils.setInt32LE(buffer, index, highBits);
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeInt32(buffer: Uint8Array, key: string, value: Int32 | number, index: number) {
|
||||
value = value.valueOf();
|
||||
// Set int type 32 bits or less
|
||||
buffer[index++] = constants.BSON_DATA_INT;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
// Write the int value
|
||||
index += NumberUtils.setInt32LE(buffer, index, value);
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeDouble(buffer: Uint8Array, key: string, value: Double, index: number) {
|
||||
// Encode as double
|
||||
buffer[index++] = constants.BSON_DATA_NUMBER;
|
||||
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
|
||||
// Write float
|
||||
index += NumberUtils.setFloat64LE(buffer, index, value.value);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeFunction(buffer: Uint8Array, key: string, value: Function, index: number) {
|
||||
buffer[index++] = constants.BSON_DATA_CODE;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
// Function string
|
||||
const functionString = value.toString();
|
||||
|
||||
// Write the string
|
||||
const size = ByteUtils.encodeUTF8Into(buffer, functionString, index + 4) + 1;
|
||||
// Write the size of the string to buffer
|
||||
NumberUtils.setInt32LE(buffer, index, size);
|
||||
// Update index
|
||||
index = index + 4 + size - 1;
|
||||
// Write zero
|
||||
buffer[index++] = 0;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeCode(
|
||||
buffer: Uint8Array,
|
||||
key: string,
|
||||
value: Code,
|
||||
index: number,
|
||||
checkKeys = false,
|
||||
depth = 0,
|
||||
serializeFunctions = false,
|
||||
ignoreUndefined = true,
|
||||
path: Set<Document>
|
||||
) {
|
||||
if (value.scope && typeof value.scope === 'object') {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_CODE_W_SCOPE;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
|
||||
// Starting index
|
||||
let startIndex = index;
|
||||
|
||||
// Serialize the function
|
||||
// Get the function string
|
||||
const functionString = value.code;
|
||||
// Index adjustment
|
||||
index = index + 4;
|
||||
// Write string into buffer
|
||||
const codeSize = ByteUtils.encodeUTF8Into(buffer, functionString, index + 4) + 1;
|
||||
// Write the size of the string to buffer
|
||||
NumberUtils.setInt32LE(buffer, index, codeSize);
|
||||
// Write end 0
|
||||
buffer[index + 4 + codeSize - 1] = 0;
|
||||
// Write the
|
||||
index = index + codeSize + 4;
|
||||
|
||||
// Serialize the scope value
|
||||
const endIndex = serializeInto(
|
||||
buffer,
|
||||
value.scope,
|
||||
checkKeys,
|
||||
index,
|
||||
depth + 1,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
path
|
||||
);
|
||||
index = endIndex - 1;
|
||||
|
||||
// Writ the total
|
||||
const totalSize = endIndex - startIndex;
|
||||
|
||||
// Write the total size of the object
|
||||
startIndex += NumberUtils.setInt32LE(buffer, startIndex, totalSize);
|
||||
// Write trailing zero
|
||||
buffer[index++] = 0;
|
||||
} else {
|
||||
buffer[index++] = constants.BSON_DATA_CODE;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
// Function string
|
||||
const functionString = value.code.toString();
|
||||
// Write the string
|
||||
const size = ByteUtils.encodeUTF8Into(buffer, functionString, index + 4) + 1;
|
||||
// Write the size of the string to buffer
|
||||
NumberUtils.setInt32LE(buffer, index, size);
|
||||
// Update index
|
||||
index = index + 4 + size - 1;
|
||||
// Write zero
|
||||
buffer[index++] = 0;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeBinary(buffer: Uint8Array, key: string, value: Binary, index: number) {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_BINARY;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
// Extract the buffer
|
||||
const data = value.buffer;
|
||||
// Calculate size
|
||||
let size = value.position;
|
||||
// Add the deprecated 02 type 4 bytes of size to total
|
||||
if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) size = size + 4;
|
||||
// Write the size of the string to buffer
|
||||
index += NumberUtils.setInt32LE(buffer, index, size);
|
||||
// Write the subtype to the buffer
|
||||
buffer[index++] = value.sub_type;
|
||||
|
||||
// If we have binary type 2 the 4 first bytes are the size
|
||||
if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
|
||||
size = size - 4;
|
||||
index += NumberUtils.setInt32LE(buffer, index, size);
|
||||
}
|
||||
|
||||
if (value.sub_type === Binary.SUBTYPE_VECTOR) {
|
||||
validateBinaryVector(value);
|
||||
}
|
||||
|
||||
if (size <= 16) {
|
||||
for (let i = 0; i < size; i++) buffer[index + i] = data[i];
|
||||
} else {
|
||||
buffer.set(data, index);
|
||||
}
|
||||
// Adjust the index
|
||||
index = index + value.position;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeSymbol(buffer: Uint8Array, key: string, value: BSONSymbol, index: number) {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_SYMBOL;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
// Write the string
|
||||
const size = ByteUtils.encodeUTF8Into(buffer, value.value, index + 4) + 1;
|
||||
// Write the size of the string to buffer
|
||||
NumberUtils.setInt32LE(buffer, index, size);
|
||||
// Update index
|
||||
index = index + 4 + size - 1;
|
||||
// Write zero
|
||||
buffer[index++] = 0;
|
||||
return index;
|
||||
}
|
||||
|
||||
function serializeDBRef(
|
||||
buffer: Uint8Array,
|
||||
key: string,
|
||||
value: DBRef,
|
||||
index: number,
|
||||
depth: number,
|
||||
serializeFunctions: boolean,
|
||||
path: Set<Document>
|
||||
) {
|
||||
// Write the type
|
||||
buffer[index++] = constants.BSON_DATA_OBJECT;
|
||||
// Number of written bytes
|
||||
const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer, key, index);
|
||||
|
||||
// Encode the name
|
||||
index = index + numberOfWrittenBytes;
|
||||
buffer[index++] = 0;
|
||||
|
||||
let startIndex = index;
|
||||
let output: DBRefLike = {
|
||||
$ref: value.collection || value.namespace, // "namespace" was what library 1.x called "collection"
|
||||
$id: value.oid
|
||||
};
|
||||
|
||||
if (value.db != null) {
|
||||
output.$db = value.db;
|
||||
}
|
||||
|
||||
output = Object.assign(output, value.fields);
|
||||
const endIndex = serializeInto(
|
||||
buffer,
|
||||
output,
|
||||
false,
|
||||
index,
|
||||
depth + 1,
|
||||
serializeFunctions,
|
||||
true,
|
||||
path
|
||||
);
|
||||
|
||||
// Calculate object size
|
||||
const size = endIndex - startIndex;
|
||||
// Write the size
|
||||
startIndex += NumberUtils.setInt32LE(buffer, index, size);
|
||||
// Set index
|
||||
return endIndex;
|
||||
}
|
||||
|
||||
export function serializeInto(
|
||||
buffer: Uint8Array,
|
||||
object: Document,
|
||||
checkKeys: boolean,
|
||||
startingIndex: number,
|
||||
depth: number,
|
||||
serializeFunctions: boolean,
|
||||
ignoreUndefined: boolean,
|
||||
path: Set<Document> | null
|
||||
): number {
|
||||
if (path == null) {
|
||||
// We are at the root input
|
||||
if (object == null) {
|
||||
// ONLY the root should turn into an empty document
|
||||
// BSON Empty document has a size of 5 (LE)
|
||||
buffer[0] = 0x05;
|
||||
buffer[1] = 0x00;
|
||||
buffer[2] = 0x00;
|
||||
buffer[3] = 0x00;
|
||||
// All documents end with null terminator
|
||||
buffer[4] = 0x00;
|
||||
return 5;
|
||||
}
|
||||
|
||||
if (Array.isArray(object)) {
|
||||
throw new BSONError('serialize does not support an array as the root input');
|
||||
}
|
||||
if (typeof object !== 'object') {
|
||||
throw new BSONError('serialize does not support non-object as the root input');
|
||||
} else if ('_bsontype' in object && typeof object._bsontype === 'string') {
|
||||
throw new BSONError(`BSON types cannot be serialized as a document`);
|
||||
} else if (
|
||||
isDate(object) ||
|
||||
isRegExp(object) ||
|
||||
isUint8Array(object) ||
|
||||
isAnyArrayBuffer(object)
|
||||
) {
|
||||
throw new BSONError(`date, regexp, typedarray, and arraybuffer cannot be BSON documents`);
|
||||
}
|
||||
|
||||
path = new Set();
|
||||
}
|
||||
|
||||
// Push the object to the path
|
||||
path.add(object);
|
||||
|
||||
// Start place to serialize into
|
||||
let index = startingIndex + 4;
|
||||
|
||||
// Special case isArray
|
||||
if (Array.isArray(object)) {
|
||||
// Get object keys
|
||||
for (let i = 0; i < object.length; i++) {
|
||||
const key = `${i}`;
|
||||
let value = object[i];
|
||||
|
||||
// Is there an override value
|
||||
if (typeof value?.toBSON === 'function') {
|
||||
value = value.toBSON();
|
||||
}
|
||||
|
||||
// Check the type of the value
|
||||
const type = typeof value;
|
||||
|
||||
if (value === undefined) {
|
||||
index = serializeNull(buffer, key, value, index);
|
||||
} else if (value === null) {
|
||||
index = serializeNull(buffer, key, value, index);
|
||||
} else if (type === 'string') {
|
||||
index = serializeString(buffer, key, value, index);
|
||||
} else if (type === 'number') {
|
||||
index = serializeNumber(buffer, key, value, index);
|
||||
} else if (type === 'bigint') {
|
||||
index = serializeBigInt(buffer, key, value, index);
|
||||
} else if (type === 'boolean') {
|
||||
index = serializeBoolean(buffer, key, value, index);
|
||||
} else if (type === 'object' && value._bsontype == null) {
|
||||
if (value instanceof Date || isDate(value)) {
|
||||
index = serializeDate(buffer, key, value, index);
|
||||
} else if (value instanceof Uint8Array || isUint8Array(value)) {
|
||||
index = serializeBuffer(buffer, key, value, index);
|
||||
} else if (value instanceof RegExp || isRegExp(value)) {
|
||||
index = serializeRegExp(buffer, key, value, index);
|
||||
} else {
|
||||
index = serializeObject(
|
||||
buffer,
|
||||
key,
|
||||
value,
|
||||
index,
|
||||
checkKeys,
|
||||
depth,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
path
|
||||
);
|
||||
}
|
||||
} else if (type === 'object') {
|
||||
if (value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION) {
|
||||
throw new BSONVersionError();
|
||||
} else if (value._bsontype === 'ObjectId') {
|
||||
index = serializeObjectId(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Decimal128') {
|
||||
index = serializeDecimal128(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
||||
index = serializeLong(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Double') {
|
||||
index = serializeDouble(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Code') {
|
||||
index = serializeCode(
|
||||
buffer,
|
||||
key,
|
||||
value,
|
||||
index,
|
||||
checkKeys,
|
||||
depth,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
path
|
||||
);
|
||||
} else if (value._bsontype === 'Binary') {
|
||||
index = serializeBinary(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'BSONSymbol') {
|
||||
index = serializeSymbol(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'DBRef') {
|
||||
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
||||
} else if (value._bsontype === 'BSONRegExp') {
|
||||
index = serializeBSONRegExp(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Int32') {
|
||||
index = serializeInt32(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
||||
index = serializeMinMax(buffer, key, value, index);
|
||||
} else if (typeof value._bsontype !== 'undefined') {
|
||||
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
||||
}
|
||||
} else if (type === 'function' && serializeFunctions) {
|
||||
index = serializeFunction(buffer, key, value, index);
|
||||
}
|
||||
}
|
||||
} else if (object instanceof Map || isMap(object)) {
|
||||
const iterator = object.entries();
|
||||
let done = false;
|
||||
|
||||
while (!done) {
|
||||
// Unpack the next entry
|
||||
const entry = iterator.next();
|
||||
done = !!entry.done;
|
||||
// Are we done, then skip and terminate
|
||||
if (done) continue;
|
||||
|
||||
// Get the entry values
|
||||
const key = entry.value ? entry.value[0] : undefined;
|
||||
let value = entry.value ? entry.value[1] : undefined;
|
||||
|
||||
if (typeof value?.toBSON === 'function') {
|
||||
value = value.toBSON();
|
||||
}
|
||||
|
||||
// Check the type of the value
|
||||
const type = typeof value;
|
||||
|
||||
// Check the key and throw error if it's illegal
|
||||
if (typeof key === 'string' && !ignoreKeys.has(key)) {
|
||||
if (key.match(regexp) != null) {
|
||||
// The BSON spec doesn't allow keys with null bytes because keys are
|
||||
// null-terminated.
|
||||
throw new BSONError('key ' + key + ' must not contain null bytes');
|
||||
}
|
||||
|
||||
if (checkKeys) {
|
||||
if ('$' === key[0]) {
|
||||
throw new BSONError('key ' + key + " must not start with '$'");
|
||||
} else if (key.includes('.')) {
|
||||
throw new BSONError('key ' + key + " must not contain '.'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (value === undefined) {
|
||||
if (ignoreUndefined === false) index = serializeNull(buffer, key, value, index);
|
||||
} else if (value === null) {
|
||||
index = serializeNull(buffer, key, value, index);
|
||||
} else if (type === 'string') {
|
||||
index = serializeString(buffer, key, value, index);
|
||||
} else if (type === 'number') {
|
||||
index = serializeNumber(buffer, key, value, index);
|
||||
} else if (type === 'bigint') {
|
||||
index = serializeBigInt(buffer, key, value, index);
|
||||
} else if (type === 'boolean') {
|
||||
index = serializeBoolean(buffer, key, value, index);
|
||||
} else if (type === 'object' && value._bsontype == null) {
|
||||
if (value instanceof Date || isDate(value)) {
|
||||
index = serializeDate(buffer, key, value, index);
|
||||
} else if (value instanceof Uint8Array || isUint8Array(value)) {
|
||||
index = serializeBuffer(buffer, key, value, index);
|
||||
} else if (value instanceof RegExp || isRegExp(value)) {
|
||||
index = serializeRegExp(buffer, key, value, index);
|
||||
} else {
|
||||
index = serializeObject(
|
||||
buffer,
|
||||
key,
|
||||
value,
|
||||
index,
|
||||
checkKeys,
|
||||
depth,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
path
|
||||
);
|
||||
}
|
||||
} else if (type === 'object') {
|
||||
if (value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION) {
|
||||
throw new BSONVersionError();
|
||||
} else if (value._bsontype === 'ObjectId') {
|
||||
index = serializeObjectId(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Decimal128') {
|
||||
index = serializeDecimal128(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
||||
index = serializeLong(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Double') {
|
||||
index = serializeDouble(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Code') {
|
||||
index = serializeCode(
|
||||
buffer,
|
||||
key,
|
||||
value,
|
||||
index,
|
||||
checkKeys,
|
||||
depth,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
path
|
||||
);
|
||||
} else if (value._bsontype === 'Binary') {
|
||||
index = serializeBinary(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'BSONSymbol') {
|
||||
index = serializeSymbol(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'DBRef') {
|
||||
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
||||
} else if (value._bsontype === 'BSONRegExp') {
|
||||
index = serializeBSONRegExp(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Int32') {
|
||||
index = serializeInt32(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
||||
index = serializeMinMax(buffer, key, value, index);
|
||||
} else if (typeof value._bsontype !== 'undefined') {
|
||||
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
||||
}
|
||||
} else if (type === 'function' && serializeFunctions) {
|
||||
index = serializeFunction(buffer, key, value, index);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (typeof object?.toBSON === 'function') {
|
||||
// Provided a custom serialization method
|
||||
object = object.toBSON();
|
||||
if (object != null && typeof object !== 'object') {
|
||||
throw new BSONError('toBSON function did not return an object');
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate over all the keys
|
||||
for (const key of Object.keys(object)) {
|
||||
let value = object[key];
|
||||
// Is there an override value
|
||||
if (typeof value?.toBSON === 'function') {
|
||||
value = value.toBSON();
|
||||
}
|
||||
|
||||
// Check the type of the value
|
||||
const type = typeof value;
|
||||
|
||||
// Check the key and throw error if it's illegal
|
||||
if (typeof key === 'string' && !ignoreKeys.has(key)) {
|
||||
if (key.match(regexp) != null) {
|
||||
// The BSON spec doesn't allow keys with null bytes because keys are
|
||||
// null-terminated.
|
||||
throw new BSONError('key ' + key + ' must not contain null bytes');
|
||||
}
|
||||
|
||||
if (checkKeys) {
|
||||
if ('$' === key[0]) {
|
||||
throw new BSONError('key ' + key + " must not start with '$'");
|
||||
} else if (key.includes('.')) {
|
||||
throw new BSONError('key ' + key + " must not contain '.'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (value === undefined) {
|
||||
if (ignoreUndefined === false) index = serializeNull(buffer, key, value, index);
|
||||
} else if (value === null) {
|
||||
index = serializeNull(buffer, key, value, index);
|
||||
} else if (type === 'string') {
|
||||
index = serializeString(buffer, key, value, index);
|
||||
} else if (type === 'number') {
|
||||
index = serializeNumber(buffer, key, value, index);
|
||||
} else if (type === 'bigint') {
|
||||
index = serializeBigInt(buffer, key, value, index);
|
||||
} else if (type === 'boolean') {
|
||||
index = serializeBoolean(buffer, key, value, index);
|
||||
} else if (type === 'object' && value._bsontype == null) {
|
||||
if (value instanceof Date || isDate(value)) {
|
||||
index = serializeDate(buffer, key, value, index);
|
||||
} else if (value instanceof Uint8Array || isUint8Array(value)) {
|
||||
index = serializeBuffer(buffer, key, value, index);
|
||||
} else if (value instanceof RegExp || isRegExp(value)) {
|
||||
index = serializeRegExp(buffer, key, value, index);
|
||||
} else {
|
||||
index = serializeObject(
|
||||
buffer,
|
||||
key,
|
||||
value,
|
||||
index,
|
||||
checkKeys,
|
||||
depth,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
path
|
||||
);
|
||||
}
|
||||
} else if (type === 'object') {
|
||||
if (value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION) {
|
||||
throw new BSONVersionError();
|
||||
} else if (value._bsontype === 'ObjectId') {
|
||||
index = serializeObjectId(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Decimal128') {
|
||||
index = serializeDecimal128(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
||||
index = serializeLong(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Double') {
|
||||
index = serializeDouble(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Code') {
|
||||
index = serializeCode(
|
||||
buffer,
|
||||
key,
|
||||
value,
|
||||
index,
|
||||
checkKeys,
|
||||
depth,
|
||||
serializeFunctions,
|
||||
ignoreUndefined,
|
||||
path
|
||||
);
|
||||
} else if (value._bsontype === 'Binary') {
|
||||
index = serializeBinary(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'BSONSymbol') {
|
||||
index = serializeSymbol(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'DBRef') {
|
||||
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
||||
} else if (value._bsontype === 'BSONRegExp') {
|
||||
index = serializeBSONRegExp(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'Int32') {
|
||||
index = serializeInt32(buffer, key, value, index);
|
||||
} else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
||||
index = serializeMinMax(buffer, key, value, index);
|
||||
} else if (typeof value._bsontype !== 'undefined') {
|
||||
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
||||
}
|
||||
} else if (type === 'function' && serializeFunctions) {
|
||||
index = serializeFunction(buffer, key, value, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the path
|
||||
path.delete(object);
|
||||
|
||||
// Final padding byte for object
|
||||
buffer[index++] = 0x00;
|
||||
|
||||
// Final size
|
||||
const size = index - startingIndex;
|
||||
// Write the size of the object
|
||||
startingIndex += NumberUtils.setInt32LE(buffer, startingIndex, size);
|
||||
return index;
|
||||
}
|
||||
69
node_modules/bson/src/parser/utils.ts
generated
vendored
69
node_modules/bson/src/parser/utils.ts
generated
vendored
|
|
@ -1,69 +0,0 @@
|
|||
const TypedArrayPrototypeGetSymbolToStringTag = (() => {
|
||||
// Type check system lovingly referenced from:
|
||||
// https://github.com/nodejs/node/blob/7450332339ed40481f470df2a3014e2ec355d8d8/lib/internal/util/types.js#L13-L15
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method -- the intention is to call this method with a bound value
|
||||
const g = Object.getOwnPropertyDescriptor(
|
||||
Object.getPrototypeOf(Uint8Array.prototype),
|
||||
Symbol.toStringTag
|
||||
)!.get!;
|
||||
|
||||
return (value: unknown) => g.call(value);
|
||||
})();
|
||||
|
||||
export function isUint8Array(value: unknown): value is Uint8Array {
|
||||
return TypedArrayPrototypeGetSymbolToStringTag(value) === 'Uint8Array';
|
||||
}
|
||||
|
||||
export function isAnyArrayBuffer(value: unknown): value is ArrayBuffer {
|
||||
return (
|
||||
typeof value === 'object' &&
|
||||
value != null &&
|
||||
Symbol.toStringTag in value &&
|
||||
(value[Symbol.toStringTag] === 'ArrayBuffer' ||
|
||||
value[Symbol.toStringTag] === 'SharedArrayBuffer')
|
||||
);
|
||||
}
|
||||
|
||||
export function isRegExp(regexp: unknown): regexp is RegExp {
|
||||
return regexp instanceof RegExp || Object.prototype.toString.call(regexp) === '[object RegExp]';
|
||||
}
|
||||
|
||||
export function isMap(value: unknown): value is Map<unknown, unknown> {
|
||||
return (
|
||||
typeof value === 'object' &&
|
||||
value != null &&
|
||||
Symbol.toStringTag in value &&
|
||||
value[Symbol.toStringTag] === 'Map'
|
||||
);
|
||||
}
|
||||
|
||||
export function isDate(date: unknown): date is Date {
|
||||
return date instanceof Date || Object.prototype.toString.call(date) === '[object Date]';
|
||||
}
|
||||
|
||||
export type InspectFn = (x: unknown, options?: unknown) => string;
|
||||
export function defaultInspect(x: unknown, _options?: unknown): string {
|
||||
return JSON.stringify(x, (k: string, v: unknown) => {
|
||||
if (typeof v === 'bigint') {
|
||||
return { $numberLong: `${v}` };
|
||||
} else if (isMap(v)) {
|
||||
return Object.fromEntries(v);
|
||||
}
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
type StylizeFunction = (x: string, style: string) => string;
|
||||
/** @internal */
|
||||
export function getStylizeFunction(options?: unknown): StylizeFunction | undefined {
|
||||
const stylizeExists =
|
||||
options != null &&
|
||||
typeof options === 'object' &&
|
||||
'stylize' in options &&
|
||||
typeof options.stylize === 'function';
|
||||
|
||||
if (stylizeExists) {
|
||||
return options.stylize as StylizeFunction;
|
||||
}
|
||||
}
|
||||
114
node_modules/bson/src/regexp.ts
generated
vendored
114
node_modules/bson/src/regexp.ts
generated
vendored
|
|
@ -1,114 +0,0 @@
|
|||
import { BSONValue } from './bson_value';
|
||||
import { BSONError } from './error';
|
||||
import type { EJSONOptions } from './extended_json';
|
||||
import { type InspectFn, defaultInspect, getStylizeFunction } from './parser/utils';
|
||||
|
||||
function alphabetize(str: string): string {
|
||||
return str.split('').sort().join('');
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface BSONRegExpExtendedLegacy {
|
||||
$regex: string | BSONRegExp;
|
||||
$options: string;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface BSONRegExpExtended {
|
||||
$regularExpression: {
|
||||
pattern: string;
|
||||
options: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON RegExp type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class BSONRegExp extends BSONValue {
|
||||
get _bsontype(): 'BSONRegExp' {
|
||||
return 'BSONRegExp';
|
||||
}
|
||||
|
||||
pattern!: string;
|
||||
options!: string;
|
||||
/**
|
||||
* @param pattern - The regular expression pattern to match
|
||||
* @param options - The regular expression options
|
||||
*/
|
||||
constructor(pattern: string, options?: string) {
|
||||
super();
|
||||
this.pattern = pattern;
|
||||
this.options = alphabetize(options ?? '');
|
||||
|
||||
if (this.pattern.indexOf('\x00') !== -1) {
|
||||
throw new BSONError(
|
||||
`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`
|
||||
);
|
||||
}
|
||||
if (this.options.indexOf('\x00') !== -1) {
|
||||
throw new BSONError(
|
||||
`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`
|
||||
);
|
||||
}
|
||||
|
||||
// Validate options
|
||||
for (let i = 0; i < this.options.length; i++) {
|
||||
if (
|
||||
!(
|
||||
this.options[i] === 'i' ||
|
||||
this.options[i] === 'm' ||
|
||||
this.options[i] === 'x' ||
|
||||
this.options[i] === 'l' ||
|
||||
this.options[i] === 's' ||
|
||||
this.options[i] === 'u'
|
||||
)
|
||||
) {
|
||||
throw new BSONError(`The regular expression option [${this.options[i]}] is not supported`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static parseOptions(options?: string): string {
|
||||
return options ? options.split('').sort().join('') : '';
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(options?: EJSONOptions): BSONRegExpExtendedLegacy | BSONRegExpExtended {
|
||||
options = options || {};
|
||||
if (options.legacy) {
|
||||
return { $regex: this.pattern, $options: this.options };
|
||||
}
|
||||
return { $regularExpression: { pattern: this.pattern, options: this.options } };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(doc: BSONRegExpExtendedLegacy | BSONRegExpExtended): BSONRegExp {
|
||||
if ('$regex' in doc) {
|
||||
if (typeof doc.$regex !== 'string') {
|
||||
// This is for $regex query operators that have extended json values.
|
||||
if (doc.$regex._bsontype === 'BSONRegExp') {
|
||||
return doc as unknown as BSONRegExp;
|
||||
}
|
||||
} else {
|
||||
return new BSONRegExp(doc.$regex, BSONRegExp.parseOptions(doc.$options));
|
||||
}
|
||||
}
|
||||
if ('$regularExpression' in doc) {
|
||||
return new BSONRegExp(
|
||||
doc.$regularExpression.pattern,
|
||||
BSONRegExp.parseOptions(doc.$regularExpression.options)
|
||||
);
|
||||
}
|
||||
throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`);
|
||||
}
|
||||
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
const stylize = getStylizeFunction(options) ?? (v => v);
|
||||
inspect ??= defaultInspect;
|
||||
const pattern = stylize(inspect(this.pattern), 'regexp');
|
||||
const flags = stylize(inspect(this.options), 'regexp');
|
||||
return `new BSONRegExp(${pattern}, ${flags})`;
|
||||
}
|
||||
}
|
||||
55
node_modules/bson/src/symbol.ts
generated
vendored
55
node_modules/bson/src/symbol.ts
generated
vendored
|
|
@ -1,55 +0,0 @@
|
|||
import { BSONValue } from './bson_value';
|
||||
import { type InspectFn, defaultInspect } from './parser/utils';
|
||||
|
||||
/** @public */
|
||||
export interface BSONSymbolExtended {
|
||||
$symbol: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representation of the BSON Symbol type.
|
||||
* @public
|
||||
* @category BSONType
|
||||
*/
|
||||
export class BSONSymbol extends BSONValue {
|
||||
get _bsontype(): 'BSONSymbol' {
|
||||
return 'BSONSymbol';
|
||||
}
|
||||
|
||||
value!: string;
|
||||
/**
|
||||
* @param value - the string representing the symbol.
|
||||
*/
|
||||
constructor(value: string) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/** Access the wrapped string value. */
|
||||
valueOf(): string {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
toJSON(): string {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(): BSONSymbolExtended {
|
||||
return { $symbol: this.value };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(doc: BSONSymbolExtended): BSONSymbol {
|
||||
return new BSONSymbol(doc.$symbol);
|
||||
}
|
||||
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
return `new BSONSymbol(${inspect(this.value, options)})`;
|
||||
}
|
||||
}
|
||||
176
node_modules/bson/src/timestamp.ts
generated
vendored
176
node_modules/bson/src/timestamp.ts
generated
vendored
|
|
@ -1,176 +0,0 @@
|
|||
import { bsonType } from './bson_value';
|
||||
import { BSONError } from './error';
|
||||
import type { Int32 } from './int_32';
|
||||
import { Long } from './long';
|
||||
import { type InspectFn, defaultInspect } from './parser/utils';
|
||||
|
||||
/** @public */
|
||||
export type TimestampOverrides =
|
||||
| '_bsontype'
|
||||
| 'toExtendedJSON'
|
||||
| 'fromExtendedJSON'
|
||||
| 'inspect'
|
||||
| typeof bsonType;
|
||||
/** @public */
|
||||
export type LongWithoutOverrides = new (
|
||||
low: unknown,
|
||||
high?: number | boolean,
|
||||
unsigned?: boolean
|
||||
) => {
|
||||
[P in Exclude<keyof Long, TimestampOverrides>]: Long[P];
|
||||
};
|
||||
/** @public */
|
||||
export const LongWithoutOverridesClass: LongWithoutOverrides =
|
||||
Long as unknown as LongWithoutOverrides;
|
||||
|
||||
/** @public */
|
||||
export interface TimestampExtended {
|
||||
$timestamp: {
|
||||
t: number;
|
||||
i: number;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @category BSONType
|
||||
*
|
||||
* A special type for _internal_ MongoDB use and is **not** associated with the regular Date type.
|
||||
*/
|
||||
export class Timestamp extends LongWithoutOverridesClass {
|
||||
get _bsontype(): 'Timestamp' {
|
||||
return 'Timestamp';
|
||||
}
|
||||
get [bsonType](): 'Timestamp' {
|
||||
return 'Timestamp';
|
||||
}
|
||||
|
||||
static readonly MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
|
||||
|
||||
/**
|
||||
* An incrementing ordinal for operations within a given second.
|
||||
*/
|
||||
get i(): number {
|
||||
return this.low >>> 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* A `time_t` value measuring seconds since the Unix epoch
|
||||
*/
|
||||
get t(): number {
|
||||
return this.high >>> 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int - A 64-bit bigint representing the Timestamp.
|
||||
*/
|
||||
constructor(int: bigint);
|
||||
/**
|
||||
* @param long - A 64-bit Long representing the Timestamp.
|
||||
*/
|
||||
constructor(long: Long);
|
||||
/**
|
||||
* @param value - A pair of two values indicating timestamp and increment.
|
||||
*/
|
||||
constructor(value: { t: number; i: number });
|
||||
constructor(low?: bigint | Long | { t: number | Int32; i: number | Int32 }) {
|
||||
if (low == null) {
|
||||
super(0, 0, true);
|
||||
} else if (typeof low === 'bigint') {
|
||||
super(low, true);
|
||||
} else if (Long.isLong(low)) {
|
||||
super(low.low, low.high, true);
|
||||
} else if (typeof low === 'object' && 't' in low && 'i' in low) {
|
||||
if (typeof low.t !== 'number' && (typeof low.t !== 'object' || low.t._bsontype !== 'Int32')) {
|
||||
throw new BSONError('Timestamp constructed from { t, i } must provide t as a number');
|
||||
}
|
||||
if (typeof low.i !== 'number' && (typeof low.i !== 'object' || low.i._bsontype !== 'Int32')) {
|
||||
throw new BSONError('Timestamp constructed from { t, i } must provide i as a number');
|
||||
}
|
||||
const t = Number(low.t);
|
||||
const i = Number(low.i);
|
||||
if (t < 0 || Number.isNaN(t)) {
|
||||
throw new BSONError('Timestamp constructed from { t, i } must provide a positive t');
|
||||
}
|
||||
if (i < 0 || Number.isNaN(i)) {
|
||||
throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
|
||||
}
|
||||
if (t > 0xffff_ffff) {
|
||||
throw new BSONError(
|
||||
'Timestamp constructed from { t, i } must provide t equal or less than uint32 max'
|
||||
);
|
||||
}
|
||||
if (i > 0xffff_ffff) {
|
||||
throw new BSONError(
|
||||
'Timestamp constructed from { t, i } must provide i equal or less than uint32 max'
|
||||
);
|
||||
}
|
||||
|
||||
super(i, t, true);
|
||||
} else {
|
||||
throw new BSONError(
|
||||
'A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
toJSON(): { $timestamp: string } {
|
||||
return {
|
||||
$timestamp: this.toString()
|
||||
};
|
||||
}
|
||||
|
||||
/** Returns a Timestamp represented by the given (32-bit) integer value. */
|
||||
static fromInt(value: number): Timestamp {
|
||||
return new Timestamp(Long.fromInt(value, true));
|
||||
}
|
||||
|
||||
/** Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned. */
|
||||
static fromNumber(value: number): Timestamp {
|
||||
return new Timestamp(Long.fromNumber(value, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits.
|
||||
*
|
||||
* @param lowBits - the low 32-bits.
|
||||
* @param highBits - the high 32-bits.
|
||||
*/
|
||||
static fromBits(lowBits: number, highBits: number): Timestamp {
|
||||
return new Timestamp({ i: lowBits, t: highBits });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Timestamp from the given string, optionally using the given radix.
|
||||
*
|
||||
* @param str - the textual representation of the Timestamp.
|
||||
* @param optRadix - the radix in which the text is written.
|
||||
*/
|
||||
static fromString(str: string, optRadix: number): Timestamp {
|
||||
return new Timestamp(Long.fromString(str, true, optRadix));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
toExtendedJSON(): TimestampExtended {
|
||||
return { $timestamp: { t: this.t, i: this.i } };
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
static fromExtendedJSON(doc: TimestampExtended): Timestamp {
|
||||
// The Long check is necessary because extended JSON has different behavior given the size of the input number
|
||||
const i = Long.isLong(doc.$timestamp.i)
|
||||
? doc.$timestamp.i.getLowBitsUnsigned() // Need to fetch the least significant 32 bits
|
||||
: doc.$timestamp.i;
|
||||
const t = Long.isLong(doc.$timestamp.t)
|
||||
? doc.$timestamp.t.getLowBitsUnsigned() // Need to fetch the least significant 32 bits
|
||||
: doc.$timestamp.t;
|
||||
return new Timestamp({ t, i });
|
||||
}
|
||||
|
||||
inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {
|
||||
inspect ??= defaultInspect;
|
||||
const t = inspect(this.t, options);
|
||||
const i = inspect(this.i, options);
|
||||
return `new Timestamp({ t: ${t}, i: ${i} })`;
|
||||
}
|
||||
}
|
||||
63
node_modules/bson/src/utils/byte_utils.ts
generated
vendored
63
node_modules/bson/src/utils/byte_utils.ts
generated
vendored
|
|
@ -1,63 +0,0 @@
|
|||
import { nodeJsByteUtils } from './node_byte_utils';
|
||||
import { webByteUtils } from './web_byte_utils';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @experimental
|
||||
*
|
||||
* A collection of functions that help work with data in a Uint8Array.
|
||||
* ByteUtils is configured at load time to use Node.js or Web based APIs for the internal implementations.
|
||||
*/
|
||||
export type ByteUtils = {
|
||||
/** Transforms the input to an instance of Buffer if running on node, otherwise Uint8Array */
|
||||
toLocalBufferType: (buffer: Uint8Array | ArrayBufferView | ArrayBuffer) => Uint8Array;
|
||||
/** Create empty space of size */
|
||||
allocate: (size: number) => Uint8Array;
|
||||
/** Create empty space of size, use pooled memory when available */
|
||||
allocateUnsafe: (size: number) => Uint8Array;
|
||||
/** Check if two Uint8Arrays are deep equal */
|
||||
equals: (a: Uint8Array, b: Uint8Array) => boolean;
|
||||
/** Check if two Uint8Arrays are deep equal */
|
||||
fromNumberArray: (array: number[]) => Uint8Array;
|
||||
/** Create a Uint8Array from a base64 string */
|
||||
fromBase64: (base64: string) => Uint8Array;
|
||||
/** Create a base64 string from bytes */
|
||||
toBase64: (buffer: Uint8Array) => string;
|
||||
/** **Legacy** binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format */
|
||||
fromISO88591: (codePoints: string) => Uint8Array;
|
||||
/** **Legacy** binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format */
|
||||
toISO88591: (buffer: Uint8Array) => string;
|
||||
/** Create a Uint8Array from a hex string */
|
||||
fromHex: (hex: string) => Uint8Array;
|
||||
/** Create a lowercase hex string from bytes */
|
||||
toHex: (buffer: Uint8Array) => string;
|
||||
/** Create a string from utf8 code units, fatal=true will throw an error if UTF-8 bytes are invalid, fatal=false will insert replacement characters */
|
||||
toUTF8: (buffer: Uint8Array, start: number, end: number, fatal: boolean) => string;
|
||||
/** Get the utf8 code unit count from a string if it were to be transformed to utf8 */
|
||||
utf8ByteLength: (input: string) => number;
|
||||
/** Encode UTF8 bytes generated from `source` string into `destination` at byteOffset. Returns the number of bytes encoded. */
|
||||
encodeUTF8Into: (destination: Uint8Array, source: string, byteOffset: number) => number;
|
||||
/** Generate a Uint8Array filled with random bytes with byteLength */
|
||||
randomBytes: (byteLength: number) => Uint8Array;
|
||||
/** Interprets `buffer` as an array of 32-bit values and swaps the byte order in-place. */
|
||||
swap32: (buffer: Uint8Array) => Uint8Array;
|
||||
};
|
||||
|
||||
declare const Buffer: { new (): unknown; prototype?: { _isBuffer?: boolean } } | undefined;
|
||||
|
||||
/**
|
||||
* Check that a global Buffer exists that is a function and
|
||||
* does not have a '_isBuffer' property defined on the prototype
|
||||
* (this is to prevent using the npm buffer)
|
||||
*/
|
||||
const hasGlobalBuffer = typeof Buffer === 'function' && Buffer.prototype?._isBuffer !== true;
|
||||
|
||||
/**
|
||||
* This is the only ByteUtils that should be used across the rest of the BSON library.
|
||||
*
|
||||
* The type annotation is important here, it asserts that each of the platform specific
|
||||
* utils implementations are compatible with the common one.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export const ByteUtils: ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
|
||||
104
node_modules/bson/src/utils/latin.ts
generated
vendored
104
node_modules/bson/src/utils/latin.ts
generated
vendored
|
|
@ -1,104 +0,0 @@
|
|||
/**
|
||||
* This function is an optimization for small basic latin strings.
|
||||
* @internal
|
||||
* @remarks
|
||||
* ### Important characteristics:
|
||||
* - If the uint8array or distance between start and end is 0 this function returns an empty string
|
||||
* - If the byteLength of the string is 1, 2, or 3 we invoke String.fromCharCode and manually offset into the buffer
|
||||
* - If the byteLength of the string is less than or equal to 20 an array of bytes is built and `String.fromCharCode.apply` is called with the result
|
||||
* - If any byte exceeds 128 this function returns null
|
||||
*
|
||||
* @param uint8array - A sequence of bytes that may contain basic latin characters
|
||||
* @param start - The start index from which to search the uint8array
|
||||
* @param end - The index to stop searching the uint8array
|
||||
* @returns string if all bytes are within the basic latin range, otherwise null
|
||||
*/
|
||||
export function tryReadBasicLatin(
|
||||
uint8array: Uint8Array,
|
||||
start: number,
|
||||
end: number
|
||||
): string | null {
|
||||
if (uint8array.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const stringByteLength = end - start;
|
||||
if (stringByteLength === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (stringByteLength > 20) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (stringByteLength === 1 && uint8array[start] < 128) {
|
||||
return String.fromCharCode(uint8array[start]);
|
||||
}
|
||||
|
||||
if (stringByteLength === 2 && uint8array[start] < 128 && uint8array[start + 1] < 128) {
|
||||
return String.fromCharCode(uint8array[start]) + String.fromCharCode(uint8array[start + 1]);
|
||||
}
|
||||
|
||||
if (
|
||||
stringByteLength === 3 &&
|
||||
uint8array[start] < 128 &&
|
||||
uint8array[start + 1] < 128 &&
|
||||
uint8array[start + 2] < 128
|
||||
) {
|
||||
return (
|
||||
String.fromCharCode(uint8array[start]) +
|
||||
String.fromCharCode(uint8array[start + 1]) +
|
||||
String.fromCharCode(uint8array[start + 2])
|
||||
);
|
||||
}
|
||||
|
||||
const latinBytes = [];
|
||||
for (let i = start; i < end; i++) {
|
||||
const byte = uint8array[i];
|
||||
if (byte > 127) {
|
||||
return null;
|
||||
}
|
||||
latinBytes.push(byte);
|
||||
}
|
||||
|
||||
return String.fromCharCode(...latinBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is an optimization for writing small basic latin strings.
|
||||
* @internal
|
||||
* @remarks
|
||||
* ### Important characteristics:
|
||||
* - If the string length is 0 return 0, do not perform any work
|
||||
* - If a string is longer than 25 code units return null
|
||||
* - If any code unit exceeds 128 this function returns null
|
||||
*
|
||||
* @param destination - The uint8array to serialize the string to
|
||||
* @param source - The string to turn into UTF-8 bytes if it fits in the basic latin range
|
||||
* @param offset - The position in the destination to begin writing bytes to
|
||||
* @returns the number of bytes written to destination if all code units are below 128, otherwise null
|
||||
*/
|
||||
export function tryWriteBasicLatin(
|
||||
destination: Uint8Array,
|
||||
source: string,
|
||||
offset: number
|
||||
): number | null {
|
||||
if (source.length === 0) return 0;
|
||||
|
||||
if (source.length > 25) return null;
|
||||
|
||||
if (destination.length - offset < source.length) return null;
|
||||
|
||||
for (
|
||||
let charOffset = 0, destinationOffset = offset;
|
||||
charOffset < source.length;
|
||||
charOffset++, destinationOffset++
|
||||
) {
|
||||
const char = source.charCodeAt(charOffset);
|
||||
if (char > 127) return null;
|
||||
|
||||
destination[destinationOffset] = char;
|
||||
}
|
||||
|
||||
return source.length;
|
||||
}
|
||||
161
node_modules/bson/src/utils/node_byte_utils.ts
generated
vendored
161
node_modules/bson/src/utils/node_byte_utils.ts
generated
vendored
|
|
@ -1,161 +0,0 @@
|
|||
import { BSONError } from '../error';
|
||||
import { parseUtf8 } from '../parse_utf8';
|
||||
import { tryReadBasicLatin, tryWriteBasicLatin } from './latin';
|
||||
|
||||
type NodeJsEncoding = 'base64' | 'hex' | 'utf8' | 'binary';
|
||||
type NodeJsBuffer = ArrayBufferView &
|
||||
Uint8Array & {
|
||||
write(string: string, offset: number, length: undefined, encoding: 'utf8'): number;
|
||||
copy(target: Uint8Array, targetStart: number, sourceStart: number, sourceEnd: number): number;
|
||||
toString: (this: Uint8Array, encoding: NodeJsEncoding, start?: number, end?: number) => string;
|
||||
equals: (this: Uint8Array, other: Uint8Array) => boolean;
|
||||
swap32: (this: NodeJsBuffer) => NodeJsBuffer;
|
||||
};
|
||||
type NodeJsBufferConstructor = Omit<Uint8ArrayConstructor, 'from'> & {
|
||||
alloc: (size: number) => NodeJsBuffer;
|
||||
allocUnsafe: (size: number) => NodeJsBuffer;
|
||||
from(array: number[]): NodeJsBuffer;
|
||||
from(array: Uint8Array): NodeJsBuffer;
|
||||
from(array: ArrayBuffer): NodeJsBuffer;
|
||||
from(array: ArrayBufferLike, byteOffset: number, byteLength: number): NodeJsBuffer;
|
||||
from(base64: string, encoding: NodeJsEncoding): NodeJsBuffer;
|
||||
byteLength(input: string, encoding: 'utf8'): number;
|
||||
isBuffer(value: unknown): value is NodeJsBuffer;
|
||||
};
|
||||
|
||||
// This can be nullish, but we gate the nodejs functions on being exported whether or not this exists
|
||||
// Node.js global
|
||||
declare const Buffer: NodeJsBufferConstructor;
|
||||
|
||||
/** @internal */
|
||||
function nodejsMathRandomBytes(byteLength: number): NodeJsBuffer {
|
||||
return nodeJsByteUtils.fromNumberArray(
|
||||
Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256))
|
||||
);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function nodejsSecureRandomBytes(byteLength: number): NodeJsBuffer {
|
||||
// @ts-expect-error: crypto.getRandomValues cannot actually be null here
|
||||
return crypto.getRandomValues(nodeJsByteUtils.allocate(byteLength));
|
||||
}
|
||||
|
||||
const nodejsRandomBytes = (() => {
|
||||
const { crypto } = globalThis as {
|
||||
crypto?: { getRandomValues?: (space: Uint8Array) => Uint8Array };
|
||||
};
|
||||
if (crypto != null && typeof crypto.getRandomValues === 'function') {
|
||||
return nodejsSecureRandomBytes;
|
||||
} else {
|
||||
return nodejsMathRandomBytes;
|
||||
}
|
||||
})();
|
||||
|
||||
/** @internal */
|
||||
export const nodeJsByteUtils = {
|
||||
toLocalBufferType(potentialBuffer: Uint8Array | NodeJsBuffer | ArrayBuffer): NodeJsBuffer {
|
||||
if (Buffer.isBuffer(potentialBuffer)) {
|
||||
return potentialBuffer;
|
||||
}
|
||||
|
||||
if (ArrayBuffer.isView(potentialBuffer)) {
|
||||
return Buffer.from(
|
||||
potentialBuffer.buffer,
|
||||
potentialBuffer.byteOffset,
|
||||
potentialBuffer.byteLength
|
||||
);
|
||||
}
|
||||
|
||||
const stringTag =
|
||||
potentialBuffer?.[Symbol.toStringTag] ?? Object.prototype.toString.call(potentialBuffer);
|
||||
if (
|
||||
stringTag === 'ArrayBuffer' ||
|
||||
stringTag === 'SharedArrayBuffer' ||
|
||||
stringTag === '[object ArrayBuffer]' ||
|
||||
stringTag === '[object SharedArrayBuffer]'
|
||||
) {
|
||||
return Buffer.from(potentialBuffer);
|
||||
}
|
||||
|
||||
throw new BSONError(`Cannot create Buffer from the passed potentialBuffer.`);
|
||||
},
|
||||
|
||||
allocate(size: number): NodeJsBuffer {
|
||||
return Buffer.alloc(size);
|
||||
},
|
||||
|
||||
allocateUnsafe(size: number): NodeJsBuffer {
|
||||
return Buffer.allocUnsafe(size);
|
||||
},
|
||||
|
||||
equals(a: Uint8Array, b: Uint8Array): boolean {
|
||||
return nodeJsByteUtils.toLocalBufferType(a).equals(b);
|
||||
},
|
||||
|
||||
fromNumberArray(array: number[]): NodeJsBuffer {
|
||||
return Buffer.from(array);
|
||||
},
|
||||
|
||||
fromBase64(base64: string): NodeJsBuffer {
|
||||
return Buffer.from(base64, 'base64');
|
||||
},
|
||||
|
||||
toBase64(buffer: Uint8Array): string {
|
||||
return nodeJsByteUtils.toLocalBufferType(buffer).toString('base64');
|
||||
},
|
||||
|
||||
/** **Legacy** binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format */
|
||||
fromISO88591(codePoints: string): NodeJsBuffer {
|
||||
return Buffer.from(codePoints, 'binary');
|
||||
},
|
||||
|
||||
/** **Legacy** binary strings are an outdated method of data transfer. Do not add public API support for interpreting this format */
|
||||
toISO88591(buffer: Uint8Array): string {
|
||||
return nodeJsByteUtils.toLocalBufferType(buffer).toString('binary');
|
||||
},
|
||||
|
||||
fromHex(hex: string): NodeJsBuffer {
|
||||
return Buffer.from(hex, 'hex');
|
||||
},
|
||||
|
||||
toHex(buffer: Uint8Array): string {
|
||||
return nodeJsByteUtils.toLocalBufferType(buffer).toString('hex');
|
||||
},
|
||||
|
||||
toUTF8(buffer: Uint8Array, start: number, end: number, fatal: boolean): string {
|
||||
const basicLatin = end - start <= 20 ? tryReadBasicLatin(buffer, start, end) : null;
|
||||
if (basicLatin != null) {
|
||||
return basicLatin;
|
||||
}
|
||||
|
||||
const string = nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
|
||||
if (fatal) {
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
if (string.charCodeAt(i) === 0xfffd) {
|
||||
parseUtf8(buffer, start, end, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return string;
|
||||
},
|
||||
|
||||
utf8ByteLength(input: string): number {
|
||||
return Buffer.byteLength(input, 'utf8');
|
||||
},
|
||||
|
||||
encodeUTF8Into(buffer: Uint8Array, source: string, byteOffset: number): number {
|
||||
const latinBytesWritten = tryWriteBasicLatin(buffer, source, byteOffset);
|
||||
if (latinBytesWritten != null) {
|
||||
return latinBytesWritten;
|
||||
}
|
||||
|
||||
return nodeJsByteUtils.toLocalBufferType(buffer).write(source, byteOffset, undefined, 'utf8');
|
||||
},
|
||||
|
||||
randomBytes: nodejsRandomBytes,
|
||||
|
||||
swap32(buffer: Uint8Array): NodeJsBuffer {
|
||||
return nodeJsByteUtils.toLocalBufferType(buffer).swap32();
|
||||
}
|
||||
};
|
||||
204
node_modules/bson/src/utils/number_utils.ts
generated
vendored
204
node_modules/bson/src/utils/number_utils.ts
generated
vendored
|
|
@ -1,204 +0,0 @@
|
|||
const FLOAT = new Float64Array(1);
|
||||
const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
|
||||
|
||||
FLOAT[0] = -1;
|
||||
// Little endian [0, 0, 0, 0, 0, 0, 240, 191]
|
||||
// Big endian [191, 240, 0, 0, 0, 0, 0, 0]
|
||||
const isBigEndian = FLOAT_BYTES[7] === 0;
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
* @public
|
||||
*
|
||||
* A collection of functions that get or set various numeric types and bit widths from a Uint8Array.
|
||||
*/
|
||||
export type NumberUtils = {
|
||||
/** Is true if the current system is big endian. */
|
||||
isBigEndian: boolean;
|
||||
/**
|
||||
* Parses a signed int32 at offset. Throws a `RangeError` if value is negative.
|
||||
*/
|
||||
getNonnegativeInt32LE: (source: Uint8Array, offset: number) => number;
|
||||
getInt32LE: (source: Uint8Array, offset: number) => number;
|
||||
getUint32LE: (source: Uint8Array, offset: number) => number;
|
||||
getUint32BE: (source: Uint8Array, offset: number) => number;
|
||||
getBigInt64LE: (source: Uint8Array, offset: number) => bigint;
|
||||
getFloat64LE: (source: Uint8Array, offset: number) => number;
|
||||
setInt32BE: (destination: Uint8Array, offset: number, value: number) => 4;
|
||||
setInt32LE: (destination: Uint8Array, offset: number, value: number) => 4;
|
||||
setBigInt64LE: (destination: Uint8Array, offset: number, value: bigint) => 8;
|
||||
setFloat64LE: (destination: Uint8Array, offset: number, value: number) => 8;
|
||||
};
|
||||
|
||||
/**
|
||||
* Number parsing and serializing utilities.
|
||||
*
|
||||
* @experimental
|
||||
* @public
|
||||
*/
|
||||
export const NumberUtils: NumberUtils = {
|
||||
isBigEndian,
|
||||
|
||||
getNonnegativeInt32LE(source: Uint8Array, offset: number): number {
|
||||
if (source[offset + 3] > 127) {
|
||||
throw new RangeError(`Size cannot be negative at offset: ${offset}`);
|
||||
}
|
||||
return (
|
||||
source[offset] |
|
||||
(source[offset + 1] << 8) |
|
||||
(source[offset + 2] << 16) |
|
||||
(source[offset + 3] << 24)
|
||||
);
|
||||
},
|
||||
|
||||
/** Reads a little-endian 32-bit integer from source */
|
||||
getInt32LE(source: Uint8Array, offset: number): number {
|
||||
return (
|
||||
source[offset] |
|
||||
(source[offset + 1] << 8) |
|
||||
(source[offset + 2] << 16) |
|
||||
(source[offset + 3] << 24)
|
||||
);
|
||||
},
|
||||
|
||||
/** Reads a little-endian 32-bit unsigned integer from source */
|
||||
getUint32LE(source: Uint8Array, offset: number): number {
|
||||
return (
|
||||
source[offset] +
|
||||
source[offset + 1] * 256 +
|
||||
source[offset + 2] * 65536 +
|
||||
source[offset + 3] * 16777216
|
||||
);
|
||||
},
|
||||
|
||||
/** Reads a big-endian 32-bit integer from source */
|
||||
getUint32BE(source: Uint8Array, offset: number): number {
|
||||
return (
|
||||
source[offset + 3] +
|
||||
source[offset + 2] * 256 +
|
||||
source[offset + 1] * 65536 +
|
||||
source[offset] * 16777216
|
||||
);
|
||||
},
|
||||
|
||||
/** Reads a little-endian 64-bit integer from source */
|
||||
getBigInt64LE(source: Uint8Array, offset: number): bigint {
|
||||
const hi = BigInt(
|
||||
source[offset + 4] +
|
||||
source[offset + 5] * 256 +
|
||||
source[offset + 6] * 65536 +
|
||||
(source[offset + 7] << 24)
|
||||
); // Overflow
|
||||
|
||||
const lo = BigInt(
|
||||
source[offset] +
|
||||
source[offset + 1] * 256 +
|
||||
source[offset + 2] * 65536 +
|
||||
source[offset + 3] * 16777216
|
||||
);
|
||||
|
||||
return (hi << 32n) + lo;
|
||||
},
|
||||
|
||||
/** Reads a little-endian 64-bit float from source */
|
||||
getFloat64LE: isBigEndian
|
||||
? (source: Uint8Array, offset: number) => {
|
||||
FLOAT_BYTES[7] = source[offset];
|
||||
FLOAT_BYTES[6] = source[offset + 1];
|
||||
FLOAT_BYTES[5] = source[offset + 2];
|
||||
FLOAT_BYTES[4] = source[offset + 3];
|
||||
FLOAT_BYTES[3] = source[offset + 4];
|
||||
FLOAT_BYTES[2] = source[offset + 5];
|
||||
FLOAT_BYTES[1] = source[offset + 6];
|
||||
FLOAT_BYTES[0] = source[offset + 7];
|
||||
return FLOAT[0];
|
||||
}
|
||||
: (source: Uint8Array, offset: number) => {
|
||||
FLOAT_BYTES[0] = source[offset];
|
||||
FLOAT_BYTES[1] = source[offset + 1];
|
||||
FLOAT_BYTES[2] = source[offset + 2];
|
||||
FLOAT_BYTES[3] = source[offset + 3];
|
||||
FLOAT_BYTES[4] = source[offset + 4];
|
||||
FLOAT_BYTES[5] = source[offset + 5];
|
||||
FLOAT_BYTES[6] = source[offset + 6];
|
||||
FLOAT_BYTES[7] = source[offset + 7];
|
||||
return FLOAT[0];
|
||||
},
|
||||
|
||||
/** Writes a big-endian 32-bit integer to destination, can be signed or unsigned */
|
||||
setInt32BE(destination: Uint8Array, offset: number, value: number): 4 {
|
||||
destination[offset + 3] = value;
|
||||
value >>>= 8;
|
||||
destination[offset + 2] = value;
|
||||
value >>>= 8;
|
||||
destination[offset + 1] = value;
|
||||
value >>>= 8;
|
||||
destination[offset] = value;
|
||||
return 4;
|
||||
},
|
||||
|
||||
/** Writes a little-endian 32-bit integer to destination, can be signed or unsigned */
|
||||
setInt32LE(destination: Uint8Array, offset: number, value: number): 4 {
|
||||
destination[offset] = value;
|
||||
value >>>= 8;
|
||||
destination[offset + 1] = value;
|
||||
value >>>= 8;
|
||||
destination[offset + 2] = value;
|
||||
value >>>= 8;
|
||||
destination[offset + 3] = value;
|
||||
return 4;
|
||||
},
|
||||
|
||||
/** Write a little-endian 64-bit integer to source */
|
||||
setBigInt64LE(destination: Uint8Array, offset: number, value: bigint): 8 {
|
||||
const mask32bits = 0xffff_ffffn;
|
||||
|
||||
/** lower 32 bits */
|
||||
let lo = Number(value & mask32bits);
|
||||
destination[offset] = lo;
|
||||
lo >>= 8;
|
||||
destination[offset + 1] = lo;
|
||||
lo >>= 8;
|
||||
destination[offset + 2] = lo;
|
||||
lo >>= 8;
|
||||
destination[offset + 3] = lo;
|
||||
|
||||
let hi = Number((value >> 32n) & mask32bits);
|
||||
destination[offset + 4] = hi;
|
||||
hi >>= 8;
|
||||
destination[offset + 5] = hi;
|
||||
hi >>= 8;
|
||||
destination[offset + 6] = hi;
|
||||
hi >>= 8;
|
||||
destination[offset + 7] = hi;
|
||||
|
||||
return 8;
|
||||
},
|
||||
|
||||
/** Writes a little-endian 64-bit float to destination */
|
||||
setFloat64LE: isBigEndian
|
||||
? (destination: Uint8Array, offset: number, value: number) => {
|
||||
FLOAT[0] = value;
|
||||
destination[offset] = FLOAT_BYTES[7];
|
||||
destination[offset + 1] = FLOAT_BYTES[6];
|
||||
destination[offset + 2] = FLOAT_BYTES[5];
|
||||
destination[offset + 3] = FLOAT_BYTES[4];
|
||||
destination[offset + 4] = FLOAT_BYTES[3];
|
||||
destination[offset + 5] = FLOAT_BYTES[2];
|
||||
destination[offset + 6] = FLOAT_BYTES[1];
|
||||
destination[offset + 7] = FLOAT_BYTES[0];
|
||||
return 8;
|
||||
}
|
||||
: (destination: Uint8Array, offset: number, value: number) => {
|
||||
FLOAT[0] = value;
|
||||
destination[offset] = FLOAT_BYTES[0];
|
||||
destination[offset + 1] = FLOAT_BYTES[1];
|
||||
destination[offset + 2] = FLOAT_BYTES[2];
|
||||
destination[offset + 3] = FLOAT_BYTES[3];
|
||||
destination[offset + 4] = FLOAT_BYTES[4];
|
||||
destination[offset + 5] = FLOAT_BYTES[5];
|
||||
destination[offset + 6] = FLOAT_BYTES[6];
|
||||
destination[offset + 7] = FLOAT_BYTES[7];
|
||||
return 8;
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue