Compare commits
2 Commits
3d47f2d539
...
6441027b89
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6441027b89 | ||
|
|
f4369ae8ba |
9
.env
9
.env
@ -1,7 +1,14 @@
|
||||
ENCRYPTION_SECRET=mySuperSecretKey123
|
||||
PORT=3000
|
||||
|
||||
<<<<<<< HEAD
|
||||
MYSQL_HOST = localhost
|
||||
MYSQL_USER = guardian
|
||||
MYSQL_PASSWORD = Admin@123
|
||||
MYSQL_DATABASE = guardiandb
|
||||
=======
|
||||
MYSQL_HOST =
|
||||
MYSQL_USER =
|
||||
MYSQL_PASSWORD =
|
||||
MYSQL_DATABASE =
|
||||
MYSQL_DATABASE =
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
node_modules/
|
||||
.env/
|
||||
24
app.js
24
app.js
@ -6,7 +6,14 @@ const userRoutes = require('./routes/userRoutes');
|
||||
const https = require('https');
|
||||
const fs = require("fs")
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
const {initWebSocket} = require('./services/webSocket')
|
||||
const { connectDB } = require('./config/database');
|
||||
connectDB();
|
||||
=======
|
||||
const {initWebSocket} = require('./services/webSocket')
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
const app = express();
|
||||
const sslOptions = {
|
||||
// key: fs.readFileSync('./certificates/fullchain.pem'),
|
||||
@ -15,9 +22,18 @@ const sslOptions = {
|
||||
// Create HTTP server (use HTTP for now to avoid SSL issues, in production use HTTPS with valid certificates)
|
||||
const server = require('http').createServer(app);
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
// Initialize WebSocket server
|
||||
initWebSocket(server);
|
||||
console.log('WebSocket server initialized');
|
||||
|
||||
connectDB()
|
||||
=======
|
||||
// Initialize WebSocket server
|
||||
initWebSocket(server);
|
||||
console.log('WebSocket server initialized');
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
// Middleware to parse JSON bodies
|
||||
app.use(express.json()); // 👈 Add this line
|
||||
|
||||
@ -25,7 +41,11 @@ app.use(express.json()); // 👈 Add this line
|
||||
app.use(express.static('public'));
|
||||
|
||||
// CORS Configuration
|
||||
<<<<<<< HEAD
|
||||
const allowedOrigins = ['https://guardiancalls.tech4bizsolutions.com','http://localhost:5174', 'https://dashboard.tech4biz.info','http://localhost:5173', 'http://192.168.1.35:5173']; // Replace as needed
|
||||
=======
|
||||
const allowedOrigins = ['https://guardiancalls.tech4bizsolutions.com','http://localhost:5174', 'https://yourfrontend.com','http://localhost:5173', 'http://192.168.1.35:5173']; // Replace as needed
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
|
||||
app.use((req, res, next) => {
|
||||
// Check if the request is for the WebSocket test page
|
||||
@ -76,4 +96,8 @@ const PORT = process.env.PORT || 3000;
|
||||
server.listen(PORT, () => {
|
||||
console.log(`HTTP server running on port ${PORT}`);
|
||||
console.log(`WebSocket server available at ws://localhost:${PORT}`);
|
||||
<<<<<<< HEAD
|
||||
});
|
||||
=======
|
||||
});
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
|
||||
@ -10,7 +10,11 @@ const connectDB = async () => {
|
||||
user: process.env.MYSQL_USER,
|
||||
password: process.env.MYSQL_PASSWORD,
|
||||
database: process.env.MYSQL_DATABASE,
|
||||
<<<<<<< HEAD
|
||||
port: process.env.MYSQL_PORT || 3306,
|
||||
=======
|
||||
port: process.env.PORT || 3306,
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
waitForConnections: true,
|
||||
connectionLimit: 100,
|
||||
queueLimit: 0,
|
||||
@ -31,4 +35,8 @@ const getPool = () => {
|
||||
return pool;
|
||||
};
|
||||
|
||||
module.exports = { connectDB, getPool };
|
||||
<<<<<<< HEAD
|
||||
module.exports = { connectDB, getPool };
|
||||
=======
|
||||
module.exports = { connectDB, getPool };
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
|
||||
7
config/schema.sql
Normal file
7
config/schema.sql
Normal file
@ -0,0 +1,7 @@
|
||||
CREATE TABLE user_alerts (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id VARCHAR(255) NOT NULL,
|
||||
alert JSON NOT NULL,
|
||||
acknowledged BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
@ -1,5 +1,11 @@
|
||||
const { fetchContacts } = require("../services/apiService");
|
||||
<<<<<<< HEAD
|
||||
const { sendAlertToUser } = require("../services/webSocket");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const {getPool} = require("../config/database")
|
||||
=======
|
||||
const { sendAlertToUser } = require("../services/webSocket")
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
|
||||
const fieldTitleMap = {
|
||||
Hq5fePgYMo1lfrJeSXkr: "call_frequency",
|
||||
@ -80,4 +86,58 @@ async function getNotifications(req,res){
|
||||
|
||||
}
|
||||
|
||||
module.exports = { getUserData ,getNotifications};
|
||||
<<<<<<< HEAD
|
||||
async function updateAlerts(req, res) {
|
||||
|
||||
let id = req.body.id
|
||||
|
||||
const authHeader = req.headers['authorization'];
|
||||
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
||||
return res.status(401).json({ error: 'Missing or invalid Authorization header' });
|
||||
}
|
||||
|
||||
const token = authHeader.split(' ')[1];
|
||||
if(!token || !id){
|
||||
return res.status(401).json({ error: 'token and id both are required' });
|
||||
}
|
||||
|
||||
console.log("ack token---",token)
|
||||
|
||||
let userId;
|
||||
|
||||
|
||||
try {
|
||||
const decoded = jwt.decode(token); // Use jwt.verify(token, secret) if validation is needed
|
||||
userId = decoded?.claims?.user_id;
|
||||
|
||||
if (!userId) {
|
||||
return res.status(401).json({ error: 'Invalid token: user_id missing' });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Token decode failed:', err);
|
||||
return res.status(401).json({ error: 'Failed to decode token' });
|
||||
}
|
||||
|
||||
try {
|
||||
const pool = getPool();
|
||||
// const placeholders = alertIds.map(() => '?').join(',');
|
||||
|
||||
const [result] = await pool.query(
|
||||
`UPDATE user_alerts SET acknowledged = 1 WHERE user_id = ? AND id = ?`,
|
||||
[userId, id]
|
||||
);
|
||||
|
||||
|
||||
res.status(200).json({
|
||||
message: 'Alerts updated successfully',
|
||||
affectedRows: result.affectedRows,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('❌ Failed to update alerts:', err);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
module.exports = { getUserData ,getNotifications,updateAlerts};
|
||||
=======
|
||||
module.exports = { getUserData ,getNotifications};
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
|
||||
190
node_modules/.package-lock.json
generated
vendored
190
node_modules/.package-lock.json
generated
vendored
@ -39,6 +39,18 @@
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
"node_modules/aws-ssl-profiles": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz",
|
||||
"integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 6.0.0"
|
||||
}
|
||||
},
|
||||
=======
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
"node_modules/axios": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz",
|
||||
@ -55,6 +67,18 @@
|
||||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||
"dev": true
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
"node_modules/bignumber.js": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
|
||||
"integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
=======
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
"node_modules/binary-extensions": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz",
|
||||
@ -302,6 +326,18 @@
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
"node_modules/denque": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz",
|
||||
"integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
}
|
||||
},
|
||||
=======
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
"node_modules/depd": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||
@ -561,6 +597,18 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
"node_modules/generate-function": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz",
|
||||
"integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"is-property": "^1.0.2"
|
||||
}
|
||||
},
|
||||
=======
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
@ -762,6 +810,15 @@
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz",
|
||||
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ=="
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
"node_modules/is-property": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz",
|
||||
"integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
=======
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
"node_modules/isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
@ -852,6 +909,39 @@
|
||||
"integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
"node_modules/long": {
|
||||
"version": "5.3.2",
|
||||
"resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz",
|
||||
"integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "7.18.3",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
|
||||
"integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
|
||||
"license": "ISC",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/lru.min": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.2.tgz",
|
||||
"integrity": "sha512-Nv9KddBcQSlQopmBHXSsZVY5xsdlZkdH/Iey0BlcBYggMd4two7cZnKOK9vmy3nY0O5RGH99z1PCeTpPqszUYg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"bun": ">=1.0.0",
|
||||
"deno": ">=1.30.0",
|
||||
"node": ">=8.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wellwelwel"
|
||||
}
|
||||
},
|
||||
=======
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
@ -990,6 +1080,86 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
"node_modules/mysql": {
|
||||
"version": "2.18.1",
|
||||
"resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz",
|
||||
"integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bignumber.js": "9.0.0",
|
||||
"readable-stream": "2.3.7",
|
||||
"safe-buffer": "5.1.2",
|
||||
"sqlstring": "2.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mysql/node_modules/readable-stream": {
|
||||
"version": "2.3.7",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
|
||||
"integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.3",
|
||||
"isarray": "~1.0.0",
|
||||
"process-nextick-args": "~2.0.0",
|
||||
"safe-buffer": "~5.1.1",
|
||||
"string_decoder": "~1.1.1",
|
||||
"util-deprecate": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/mysql/node_modules/safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/mysql2": {
|
||||
"version": "3.14.1",
|
||||
"resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.14.1.tgz",
|
||||
"integrity": "sha512-7ytuPQJjQB8TNAYX/H2yhL+iQOnIBjAMam361R7UAL0lOVXWjtdrmoL9HYKqKoLp/8UUTRcvo1QPvK9KL7wA8w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"aws-ssl-profiles": "^1.1.1",
|
||||
"denque": "^2.1.0",
|
||||
"generate-function": "^2.3.1",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"long": "^5.2.1",
|
||||
"lru.min": "^1.0.0",
|
||||
"named-placeholders": "^1.1.3",
|
||||
"seq-queue": "^0.0.5",
|
||||
"sqlstring": "^2.3.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/mysql2/node_modules/sqlstring": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz",
|
||||
"integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/named-placeholders": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz",
|
||||
"integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lru-cache": "^7.14.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
=======
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
"node_modules/negotiator": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
|
||||
@ -1267,6 +1437,14 @@
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
"node_modules/seq-queue": {
|
||||
"version": "0.0.5",
|
||||
"resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz",
|
||||
"integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q=="
|
||||
},
|
||||
=======
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
"node_modules/serve-static": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz",
|
||||
@ -1366,6 +1544,18 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
"node_modules/sqlstring": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz",
|
||||
"integrity": "sha512-ooAzh/7dxIG5+uDik1z/Rd1vli0+38izZhGzSa34FwR7IbelPWCCKSNIl8jlL/F7ERvy8CB2jNeM1E9i9mXMAQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
=======
|
||||
>>>>>>> 3d47f2d539024e036b3db88eb1e020180e656065
|
||||
"node_modules/statuses": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
||||
|
||||
19
node_modules/aws-ssl-profiles/LICENSE
generated
vendored
Normal file
19
node_modules/aws-ssl-profiles/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2024 Andrey Sidorov, Douglas Wilson, Weslley Araújo and contributors.
|
||||
|
||||
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.
|
||||
146
node_modules/aws-ssl-profiles/README.md
generated
vendored
Normal file
146
node_modules/aws-ssl-profiles/README.md
generated
vendored
Normal file
@ -0,0 +1,146 @@
|
||||
# AWS SSL Profiles
|
||||
|
||||
[**AWS RDS**](https://aws.amazon.com/rds/) **SSL** Certificates Bundles.
|
||||
|
||||
**Table of Contents**
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [**mysqljs/mysql**](#mysqljsmysql)
|
||||
- [**MySQL2**](#mysql2)
|
||||
- [**node-postgres**](#node-postgres)
|
||||
- [Custom `ssl` options](#custom-ssl-options)
|
||||
- [License](#license)
|
||||
- [Security](#security)
|
||||
- [Contributing](#contributing)
|
||||
- [Acknowledgements](#acknowledgements)
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install --save aws-ssl-profiles
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
### [mysqljs/mysql](https://github.com/mysqljs/mysql)
|
||||
|
||||
```js
|
||||
const mysql = require('mysql');
|
||||
const awsCaBundle = require('aws-ssl-profiles');
|
||||
|
||||
// mysql connection
|
||||
const connection = mysql.createConnection({
|
||||
//...
|
||||
ssl: awsCaBundle,
|
||||
});
|
||||
|
||||
// mysql connection pool
|
||||
const pool = mysql.createPool({
|
||||
//...
|
||||
ssl: awsCaBundle,
|
||||
});
|
||||
```
|
||||
|
||||
### [MySQL2](https://github.com/sidorares/node-mysql2)
|
||||
|
||||
```js
|
||||
const mysql = require('mysql2');
|
||||
const awsCaBundle = require('aws-ssl-profiles');
|
||||
|
||||
// mysql2 connection
|
||||
const connection = mysql.createConnection({
|
||||
//...
|
||||
ssl: awsCaBundle,
|
||||
});
|
||||
|
||||
// mysql2 connection pool
|
||||
const pool = mysql.createPool({
|
||||
//...
|
||||
ssl: awsCaBundle,
|
||||
});
|
||||
```
|
||||
|
||||
### [node-postgres](https://github.com/brianc/node-postgres)
|
||||
|
||||
```js
|
||||
const pg = require('pg');
|
||||
const awsCaBundle = require('aws-ssl-profiles');
|
||||
|
||||
// pg connection
|
||||
const client = new pg.Client({
|
||||
// ...
|
||||
ssl: awsCaBundle,
|
||||
});
|
||||
|
||||
// pg connection pool
|
||||
const pool = new pg.Pool({
|
||||
// ...
|
||||
ssl: awsCaBundle,
|
||||
});
|
||||
```
|
||||
|
||||
### Custom `ssl` options
|
||||
|
||||
Using **AWS SSL Profiles** with custom `ssl` options:
|
||||
|
||||
```js
|
||||
{
|
||||
// ...
|
||||
ssl: {
|
||||
...awsCaBundle,
|
||||
rejectUnauthorized: true,
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
{
|
||||
// ...
|
||||
ssl: {
|
||||
ca: awsCaBundle.ca,
|
||||
rejectUnauthorized: true,
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Custom bundles
|
||||
|
||||
```js
|
||||
const { proxyBundle } = require('aws-ssl-profiles');
|
||||
|
||||
{
|
||||
// ...
|
||||
ssl: proxyBundle,
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
**AWS SSL Profiles** is under the [**MIT License**](./LICENSE).
|
||||
|
||||
---
|
||||
|
||||
## Security
|
||||
|
||||
Please check the [**SECURITY.md**](./SECURITY.md).
|
||||
|
||||
---
|
||||
|
||||
## Contributing
|
||||
|
||||
Please check the [**CONTRIBUTING.md**](./CONTRIBUTING.md) for instructions.
|
||||
|
||||
---
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
[**Contributors**](https://github.com/mysqljs/aws-ssl-profiles/graphs/contributors).
|
||||
4
node_modules/aws-ssl-profiles/lib/@types/profiles.d.ts
generated
vendored
Normal file
4
node_modules/aws-ssl-profiles/lib/@types/profiles.d.ts
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
export type CA = string[];
|
||||
export type Profiles = {
|
||||
ca: CA;
|
||||
};
|
||||
2
node_modules/aws-ssl-profiles/lib/@types/profiles.js
generated
vendored
Normal file
2
node_modules/aws-ssl-profiles/lib/@types/profiles.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
8
node_modules/aws-ssl-profiles/lib/index.d.ts
generated
vendored
Normal file
8
node_modules/aws-ssl-profiles/lib/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import type { Profiles } from "./@types/profiles.js";
|
||||
export declare const proxyBundle: Profiles;
|
||||
declare const profiles: Profiles;
|
||||
declare module "aws-ssl-profiles" {
|
||||
const profiles: Profiles & { proxyBundle: Profiles };
|
||||
export = profiles;
|
||||
}
|
||||
export default profiles;
|
||||
13
node_modules/aws-ssl-profiles/lib/index.js
generated
vendored
Normal file
13
node_modules/aws-ssl-profiles/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const defaults_js_1 = require("./profiles/ca/defaults.js");
|
||||
const proxies_js_1 = require("./profiles/ca/proxies.js");
|
||||
const proxyBundle = {
|
||||
ca: proxies_js_1.proxies,
|
||||
};
|
||||
const profiles = {
|
||||
ca: [...defaults_js_1.defaults, ...proxies_js_1.proxies],
|
||||
};
|
||||
module.exports = profiles;
|
||||
module.exports.proxyBundle = proxyBundle;
|
||||
module.exports.default = profiles;
|
||||
9
node_modules/aws-ssl-profiles/lib/profiles/ca/defaults.d.ts
generated
vendored
Normal file
9
node_modules/aws-ssl-profiles/lib/profiles/ca/defaults.d.ts
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import type { CA } from '../../@types/profiles.js';
|
||||
/**
|
||||
* CA Certificates for **Amazon RDS** (2024)
|
||||
*
|
||||
* - https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html
|
||||
* - https://docs.amazonaws.cn/en_us/AmazonRDS/latest/AuroraUserGuide/UsingWithRDS.SSL.html
|
||||
* - https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless.html#aurora-serverless.tls
|
||||
*/
|
||||
export declare const defaults: CA;
|
||||
2888
node_modules/aws-ssl-profiles/lib/profiles/ca/defaults.js
generated
vendored
Normal file
2888
node_modules/aws-ssl-profiles/lib/profiles/ca/defaults.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8
node_modules/aws-ssl-profiles/lib/profiles/ca/proxies.d.ts
generated
vendored
Normal file
8
node_modules/aws-ssl-profiles/lib/profiles/ca/proxies.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import type { CA } from '../../@types/profiles.js';
|
||||
/**
|
||||
* CA Certificates for **Amazon RDS Proxy** (2024)
|
||||
*
|
||||
* - https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy.howitworks.html#rds-proxy-security.tls
|
||||
* - https://www.amazontrust.com/repository/
|
||||
*/
|
||||
export declare const proxies: CA;
|
||||
111
node_modules/aws-ssl-profiles/lib/profiles/ca/proxies.js
generated
vendored
Normal file
111
node_modules/aws-ssl-profiles/lib/profiles/ca/proxies.js
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.proxies = void 0;
|
||||
/**
|
||||
* CA Certificates for **Amazon RDS Proxy** (2024)
|
||||
*
|
||||
* - https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy.howitworks.html#rds-proxy-security.tls
|
||||
* - https://www.amazontrust.com/repository/
|
||||
*/
|
||||
exports.proxies = [
|
||||
'-----BEGIN CERTIFICATE-----\n' +
|
||||
'MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\n' +
|
||||
'ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n' +
|
||||
'b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\n' +
|
||||
'MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n' +
|
||||
'b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj\n' +
|
||||
'ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM\n' +
|
||||
'9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw\n' +
|
||||
'IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6\n' +
|
||||
'VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L\n' +
|
||||
'93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm\n' +
|
||||
'jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC\n' +
|
||||
'AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA\n' +
|
||||
'A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI\n' +
|
||||
'U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs\n' +
|
||||
'N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv\n' +
|
||||
'o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU\n' +
|
||||
'5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\n' +
|
||||
'rqXRfboQnoZsG4q5WTP468SQvvG5\n' +
|
||||
'-----END CERTIFICATE-----\n',
|
||||
'-----BEGIN CERTIFICATE-----\n' +
|
||||
'MIIFQTCCAymgAwIBAgITBmyf0pY1hp8KD+WGePhbJruKNzANBgkqhkiG9w0BAQwF\n' +
|
||||
'ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n' +
|
||||
'b24gUm9vdCBDQSAyMB4XDTE1MDUyNjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTEL\n' +
|
||||
'MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n' +
|
||||
'b3QgQ0EgMjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK2Wny2cSkxK\n' +
|
||||
'gXlRmeyKy2tgURO8TW0G/LAIjd0ZEGrHJgw12MBvIITplLGbhQPDW9tK6Mj4kHbZ\n' +
|
||||
'W0/jTOgGNk3Mmqw9DJArktQGGWCsN0R5hYGCrVo34A3MnaZMUnbqQ523BNFQ9lXg\n' +
|
||||
'1dKmSYXpN+nKfq5clU1Imj+uIFptiJXZNLhSGkOQsL9sBbm2eLfq0OQ6PBJTYv9K\n' +
|
||||
'8nu+NQWpEjTj82R0Yiw9AElaKP4yRLuH3WUnAnE72kr3H9rN9yFVkE8P7K6C4Z9r\n' +
|
||||
'2UXTu/Bfh+08LDmG2j/e7HJV63mjrdvdfLC6HM783k81ds8P+HgfajZRRidhW+me\n' +
|
||||
'z/CiVX18JYpvL7TFz4QuK/0NURBs+18bvBt+xa47mAExkv8LV/SasrlX6avvDXbR\n' +
|
||||
'8O70zoan4G7ptGmh32n2M8ZpLpcTnqWHsFcQgTfJU7O7f/aS0ZzQGPSSbtqDT6Zj\n' +
|
||||
'mUyl+17vIWR6IF9sZIUVyzfpYgwLKhbcAS4y2j5L9Z469hdAlO+ekQiG+r5jqFoz\n' +
|
||||
'7Mt0Q5X5bGlSNscpb/xVA1wf+5+9R+vnSUeVC06JIglJ4PVhHvG/LopyboBZ/1c6\n' +
|
||||
'+XUyo05f7O0oYtlNc/LMgRdg7c3r3NunysV+Ar3yVAhU/bQtCSwXVEqY0VThUWcI\n' +
|
||||
'0u1ufm8/0i2BWSlmy5A5lREedCf+3euvAgMBAAGjQjBAMA8GA1UdEwEB/wQFMAMB\n' +
|
||||
'Af8wDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBSwDPBMMPQFWAJI/TPlUq9LhONm\n' +
|
||||
'UjANBgkqhkiG9w0BAQwFAAOCAgEAqqiAjw54o+Ci1M3m9Zh6O+oAA7CXDpO8Wqj2\n' +
|
||||
'LIxyh6mx/H9z/WNxeKWHWc8w4Q0QshNabYL1auaAn6AFC2jkR2vHat+2/XcycuUY\n' +
|
||||
'+gn0oJMsXdKMdYV2ZZAMA3m3MSNjrXiDCYZohMr/+c8mmpJ5581LxedhpxfL86kS\n' +
|
||||
'k5Nrp+gvU5LEYFiwzAJRGFuFjWJZY7attN6a+yb3ACfAXVU3dJnJUH/jWS5E4ywl\n' +
|
||||
'7uxMMne0nxrpS10gxdr9HIcWxkPo1LsmmkVwXqkLN1PiRnsn/eBG8om3zEK2yygm\n' +
|
||||
'btmlyTrIQRNg91CMFa6ybRoVGld45pIq2WWQgj9sAq+uEjonljYE1x2igGOpm/Hl\n' +
|
||||
'urR8FLBOybEfdF849lHqm/osohHUqS0nGkWxr7JOcQ3AWEbWaQbLU8uz/mtBzUF+\n' +
|
||||
'fUwPfHJ5elnNXkoOrJupmHN5fLT0zLm4BwyydFy4x2+IoZCn9Kr5v2c69BoVYh63\n' +
|
||||
'n749sSmvZ6ES8lgQGVMDMBu4Gon2nL2XA46jCfMdiyHxtN/kHNGfZQIG6lzWE7OE\n' +
|
||||
'76KlXIx3KadowGuuQNKotOrN8I1LOJwZmhsoVLiJkO/KdYE+HvJkJMcYr07/R54H\n' +
|
||||
'9jVlpNMKVv/1F2Rs76giJUmTtt8AF9pYfl3uxRuw0dFfIRDH+fO6AgonB8Xx1sfT\n' +
|
||||
'4PsJYGw=\n' +
|
||||
'-----END CERTIFICATE-----\n',
|
||||
'-----BEGIN CERTIFICATE-----\n' +
|
||||
'MIIBtjCCAVugAwIBAgITBmyf1XSXNmY/Owua2eiedgPySjAKBggqhkjOPQQDAjA5\n' +
|
||||
'MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24g\n' +
|
||||
'Um9vdCBDQSAzMB4XDTE1MDUyNjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkG\n' +
|
||||
'A1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJvb3Qg\n' +
|
||||
'Q0EgMzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABCmXp8ZBf8ANm+gBG1bG8lKl\n' +
|
||||
'ui2yEujSLtf6ycXYqm0fc4E7O5hrOXwzpcVOho6AF2hiRVd9RFgdszflZwjrZt6j\n' +
|
||||
'QjBAMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBSr\n' +
|
||||
'ttvXBp43rDCGB5Fwx5zEGbF4wDAKBggqhkjOPQQDAgNJADBGAiEA4IWSoxe3jfkr\n' +
|
||||
'BqWTrBqYaGFy+uGh0PsceGCmQ5nFuMQCIQCcAu/xlJyzlvnrxir4tiz+OpAUFteM\n' +
|
||||
'YyRIHN8wfdVoOw==\n' +
|
||||
'-----END CERTIFICATE-----\n',
|
||||
'-----BEGIN CERTIFICATE-----\n' +
|
||||
'MIIB8jCCAXigAwIBAgITBmyf18G7EEwpQ+Vxe3ssyBrBDjAKBggqhkjOPQQDAzA5\n' +
|
||||
'MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6b24g\n' +
|
||||
'Um9vdCBDQSA0MB4XDTE1MDUyNjAwMDAwMFoXDTQwMDUyNjAwMDAwMFowOTELMAkG\n' +
|
||||
'A1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJvb3Qg\n' +
|
||||
'Q0EgNDB2MBAGByqGSM49AgEGBSuBBAAiA2IABNKrijdPo1MN/sGKe0uoe0ZLY7Bi\n' +
|
||||
'9i0b2whxIdIA6GO9mif78DluXeo9pcmBqqNbIJhFXRbb/egQbeOc4OO9X4Ri83Bk\n' +
|
||||
'M6DLJC9wuoihKqB1+IGuYgbEgds5bimwHvouXKNCMEAwDwYDVR0TAQH/BAUwAwEB\n' +
|
||||
'/zAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0OBBYEFNPsxzplbszh2naaVvuc84ZtV+WB\n' +
|
||||
'MAoGCCqGSM49BAMDA2gAMGUCMDqLIfG9fhGt0O9Yli/W651+kI0rz2ZVwyzjKKlw\n' +
|
||||
'CkcO8DdZEv8tmZQoTipPNU0zWgIxAOp1AE47xDqUEpHJWEadIRNyp4iciuRMStuW\n' +
|
||||
'1KyLa2tJElMzrdfkviT8tQp21KW8EA==\n' +
|
||||
'-----END CERTIFICATE-----\n',
|
||||
'-----BEGIN CERTIFICATE-----\n' +
|
||||
'MIID7zCCAtegAwIBAgIBADANBgkqhkiG9w0BAQsFADCBmDELMAkGA1UEBhMCVVMx\n' +
|
||||
'EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n' +
|
||||
'HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xOzA5BgNVBAMTMlN0YXJmaWVs\n' +
|
||||
'ZCBTZXJ2aWNlcyBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5\n' +
|
||||
'MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgZgxCzAJBgNVBAYTAlVTMRAwDgYD\n' +
|
||||
'VQQIEwdBcml6b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFy\n' +
|
||||
'ZmllbGQgVGVjaG5vbG9naWVzLCBJbmMuMTswOQYDVQQDEzJTdGFyZmllbGQgU2Vy\n' +
|
||||
'dmljZXMgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZI\n' +
|
||||
'hvcNAQEBBQADggEPADCCAQoCggEBANUMOsQq+U7i9b4Zl1+OiFOxHz/Lz58gE20p\n' +
|
||||
'OsgPfTz3a3Y4Y9k2YKibXlwAgLIvWX/2h/klQ4bnaRtSmpDhcePYLQ1Ob/bISdm2\n' +
|
||||
'8xpWriu2dBTrz/sm4xq6HZYuajtYlIlHVv8loJNwU4PahHQUw2eeBGg6345AWh1K\n' +
|
||||
'Ts9DkTvnVtYAcMtS7nt9rjrnvDH5RfbCYM8TWQIrgMw0R9+53pBlbQLPLJGmpufe\n' +
|
||||
'hRhJfGZOozptqbXuNC66DQO4M99H67FrjSXZm86B0UVGMpZwh94CDklDhbZsc7tk\n' +
|
||||
'6mFBrMnUVN+HL8cisibMn1lUaJ/8viovxFUcdUBgF4UCVTmLfwUCAwEAAaNCMEAw\n' +
|
||||
'DwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFJxfAN+q\n' +
|
||||
'AdcwKziIorhtSpzyEZGDMA0GCSqGSIb3DQEBCwUAA4IBAQBLNqaEd2ndOxmfZyMI\n' +
|
||||
'bw5hyf2E3F/YNoHN2BtBLZ9g3ccaaNnRbobhiCPPE95Dz+I0swSdHynVv/heyNXB\n' +
|
||||
've6SbzJ08pGCL72CQnqtKrcgfU28elUSwhXqvfdqlS5sdJ/PHLTyxQGjhdByPq1z\n' +
|
||||
'qwubdQxtRbeOlKyWN7Wg0I8VRw7j6IPdj/3vQQF3zCepYoUz8jcI73HPdwbeyBkd\n' +
|
||||
'iEDPfUYd/x7H4c7/I9vG+o1VTqkC50cRRj70/b17KSa7qWFiNyi2LSr2EIZkyXCn\n' +
|
||||
'0q23KXB56jzaYyWf/Wi3MOxw+3WKt21gZ7IeyLnp2KhvAotnDU0mV3HaIPzBSlCN\n' +
|
||||
'sSi6\n' +
|
||||
'-----END CERTIFICATE-----\n',
|
||||
];
|
||||
52
node_modules/aws-ssl-profiles/package.json
generated
vendored
Normal file
52
node_modules/aws-ssl-profiles/package.json
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "aws-ssl-profiles",
|
||||
"version": "1.1.2",
|
||||
"main": "lib/index.js",
|
||||
"author": "https://github.com/wellwelwel",
|
||||
"description": "AWS RDS SSL certificates bundles.",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mysqljs/aws-ssl-profiles"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mysqljs/aws-ssl-profiles/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^1.8.3",
|
||||
"@types/node": "^22.5.1",
|
||||
"@types/x509.js": "^1.0.3",
|
||||
"poku": "^2.5.0",
|
||||
"prettier": "^3.3.3",
|
||||
"tsx": "^4.19.0",
|
||||
"typescript": "^5.5.4",
|
||||
"x509.js": "^1.0.0"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 6.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"mysql",
|
||||
"mysql2",
|
||||
"pg",
|
||||
"postgres",
|
||||
"aws",
|
||||
"rds",
|
||||
"ssl",
|
||||
"certificates",
|
||||
"ca",
|
||||
"bundle"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "npx tsc",
|
||||
"postbuild": "cp src/index.d.ts lib/index.d.ts",
|
||||
"lint": "npx @biomejs/biome lint && prettier --check .",
|
||||
"lint:fix": "npx @biomejs/biome lint --write . && prettier --write .",
|
||||
"pretest": "npm run build",
|
||||
"test": "poku --parallel ./test",
|
||||
"test:ci": "npm run lint && npm run test"
|
||||
}
|
||||
}
|
||||
266
node_modules/bignumber.js/CHANGELOG.md
generated
vendored
Normal file
266
node_modules/bignumber.js/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,266 @@
|
||||
#### 9.0.0
|
||||
* 27/05/2019
|
||||
* For compatibility with legacy browsers, remove `Symbol` references.
|
||||
|
||||
#### 8.1.1
|
||||
* 24/02/2019
|
||||
* [BUGFIX] #222 Restore missing `var` to `export BigNumber`.
|
||||
* Allow any key in BigNumber.Instance in *bignumber.d.ts*.
|
||||
|
||||
#### 8.1.0
|
||||
* 23/02/2019
|
||||
* [NEW FEATURE] #220 Create a BigNumber using `{s, e, c}`.
|
||||
* [NEW FEATURE] `isBigNumber`: if `BigNumber.DEBUG` is `true`, also check that the BigNumber instance is well-formed.
|
||||
* Remove `instanceof` checks; just use `_isBigNumber` to identify a BigNumber instance.
|
||||
* Add `_isBigNumber` to prototype in *bignumber.mjs*.
|
||||
* Add tests for BigNumber creation from object.
|
||||
* Update *API.html*.
|
||||
|
||||
#### 8.0.2
|
||||
* 13/01/2019
|
||||
* #209 `toPrecision` without argument should follow `toString`.
|
||||
* Improve *Use* section of *README*.
|
||||
* Optimise `toString(10)`.
|
||||
* Add verson number to API doc.
|
||||
|
||||
#### 8.0.1
|
||||
* 01/11/2018
|
||||
* Rest parameter must be array type in *bignumber.d.ts*.
|
||||
|
||||
#### 8.0.0
|
||||
* 01/11/2018
|
||||
* [NEW FEATURE] Add `BigNumber.sum` method.
|
||||
* [NEW FEATURE]`toFormat`: add `prefix` and `suffix` options.
|
||||
* [NEW FEATURE] #178 Pass custom formatting to `toFormat`.
|
||||
* [BREAKING CHANGE] #184 `toFraction`: return array of BigNumbers not strings.
|
||||
* [NEW FEATURE] #185 Enable overwrite of `valueOf` to prevent accidental addition to string.
|
||||
* #183 Add Node.js `crypto` requirement to documentation.
|
||||
* [BREAKING CHANGE] #198 Disallow signs and whitespace in custom alphabet.
|
||||
* [NEW FEATURE] #188 Implement `util.inspect.custom` for Node.js REPL.
|
||||
* #170 Make `isBigNumber` a type guard in *bignumber.d.ts*.
|
||||
* [BREAKING CHANGE] `BigNumber.min` and `BigNumber.max`: don't accept an array.
|
||||
* Update *.travis.yml*.
|
||||
* Remove *bower.json*.
|
||||
|
||||
#### 7.2.1
|
||||
* 24/05/2018
|
||||
* Add `browser` field to *package.json*.
|
||||
|
||||
#### 7.2.0
|
||||
* 22/05/2018
|
||||
* #166 Correct *.mjs* file. Remove extension from `main` field in *package.json*.
|
||||
|
||||
#### 7.1.0
|
||||
* 18/05/2018
|
||||
* Add `module` field to *package.json* for *bignumber.mjs*.
|
||||
|
||||
#### 7.0.2
|
||||
* 17/05/2018
|
||||
* #165 Bugfix: upper-case letters for bases 11-36 in a custom alphabet.
|
||||
* Add note to *README* regarding creating BigNumbers from Number values.
|
||||
|
||||
#### 7.0.1
|
||||
* 26/04/2018
|
||||
* #158 Fix global object variable name typo.
|
||||
|
||||
#### 7.0.0
|
||||
* 26/04/2018
|
||||
* #143 Remove global BigNumber from typings.
|
||||
* #144 Enable compatibility with `Object.freeze(Object.prototype)`.
|
||||
* #148 #123 #11 Only throw on a number primitive with more than 15 significant digits if `BigNumber.DEBUG` is `true`.
|
||||
* Only throw on an invalid BigNumber value if `BigNumber.DEBUG` is `true`. Return BigNumber `NaN` instead.
|
||||
* #154 `exponentiatedBy`: allow BigNumber exponent.
|
||||
* #156 Prevent Content Security Policy *unsafe-eval* issue.
|
||||
* `toFraction`: allow `Infinity` maximum denominator.
|
||||
* Comment-out some excess tests to reduce test time.
|
||||
* Amend indentation and other spacing.
|
||||
|
||||
#### 6.0.0
|
||||
* 26/01/2018
|
||||
* #137 Implement `APLHABET` configuration option.
|
||||
* Remove `ERRORS` configuration option.
|
||||
* Remove `toDigits` method; extend `precision` method accordingly.
|
||||
* Remove s`round` method; extend `decimalPlaces` method accordingly.
|
||||
* Remove methods: `ceil`, `floor`, and `truncated`.
|
||||
* Remove method aliases: `add`, `cmp`, `isInt`, `isNeg`, `trunc`, `mul`, `neg` and `sub`.
|
||||
* Rename methods: `shift` to `shiftedBy`, `another` to `clone`, `toPower` to `exponentiatedBy`, and `equals` to `isEqualTo`.
|
||||
* Rename methods: add `is` prefix to `greaterThan`, `greaterThanOrEqualTo`, `lessThan` and `lessThanOrEqualTo`.
|
||||
* Add methods: `multipliedBy`, `isBigNumber`, `isPositive`, `integerValue`, `maximum` and `minimum`.
|
||||
* Refactor test suite.
|
||||
* Add *CHANGELOG.md*.
|
||||
* Rewrite *bignumber.d.ts*.
|
||||
* Redo API image.
|
||||
|
||||
#### 5.0.0
|
||||
* 27/11/2017
|
||||
* #81 Don't throw on constructor call without `new`.
|
||||
|
||||
#### 4.1.0
|
||||
* 26/09/2017
|
||||
* Remove node 0.6 from *.travis.yml*.
|
||||
* Add *bignumber.mjs*.
|
||||
|
||||
#### 4.0.4
|
||||
* 03/09/2017
|
||||
* Add missing aliases to *bignumber.d.ts*.
|
||||
|
||||
#### 4.0.3
|
||||
* 30/08/2017
|
||||
* Add types: *bignumber.d.ts*.
|
||||
|
||||
#### 4.0.2
|
||||
* 03/05/2017
|
||||
* #120 Workaround Safari/Webkit bug.
|
||||
|
||||
#### 4.0.1
|
||||
* 05/04/2017
|
||||
* #121 BigNumber.default to BigNumber['default'].
|
||||
|
||||
#### 4.0.0
|
||||
* 09/01/2017
|
||||
* Replace BigNumber.isBigNumber method with isBigNumber prototype property.
|
||||
|
||||
#### 3.1.2
|
||||
* 08/01/2017
|
||||
* Minor documentation edit.
|
||||
|
||||
#### 3.1.1
|
||||
* 08/01/2017
|
||||
* Uncomment `isBigNumber` tests.
|
||||
* Ignore dot files.
|
||||
|
||||
#### 3.1.0
|
||||
* 08/01/2017
|
||||
* Add `isBigNumber` method.
|
||||
|
||||
#### 3.0.2
|
||||
* 08/01/2017
|
||||
* Bugfix: Possible incorrect value of `ERRORS` after a `BigNumber.another` call (due to `parseNumeric` declaration in outer scope).
|
||||
|
||||
#### 3.0.1
|
||||
* 23/11/2016
|
||||
* Apply fix for old ipads with `%` issue, see #57 and #102.
|
||||
* Correct error message.
|
||||
|
||||
#### 3.0.0
|
||||
* 09/11/2016
|
||||
* Remove `require('crypto')` - leave it to the user.
|
||||
* Add `BigNumber.set` as `BigNumber.config` alias.
|
||||
* Default `POW_PRECISION` to `0`.
|
||||
|
||||
#### 2.4.0
|
||||
* 14/07/2016
|
||||
* #97 Add exports to support ES6 imports.
|
||||
|
||||
#### 2.3.0
|
||||
* 07/03/2016
|
||||
* #86 Add modulus parameter to `toPower`.
|
||||
|
||||
#### 2.2.0
|
||||
* 03/03/2016
|
||||
* #91 Permit larger JS integers.
|
||||
|
||||
#### 2.1.4
|
||||
* 15/12/2015
|
||||
* Correct UMD.
|
||||
|
||||
#### 2.1.3
|
||||
* 13/12/2015
|
||||
* Refactor re global object and crypto availability when bundling.
|
||||
|
||||
#### 2.1.2
|
||||
* 10/12/2015
|
||||
* Bugfix: `window.crypto` not assigned to `crypto`.
|
||||
|
||||
#### 2.1.1
|
||||
* 09/12/2015
|
||||
* Prevent code bundler from adding `crypto` shim.
|
||||
|
||||
#### 2.1.0
|
||||
* 26/10/2015
|
||||
* For `valueOf` and `toJSON`, include the minus sign with negative zero.
|
||||
|
||||
#### 2.0.8
|
||||
* 2/10/2015
|
||||
* Internal round function bugfix.
|
||||
|
||||
#### 2.0.6
|
||||
* 31/03/2015
|
||||
* Add bower.json. Tweak division after in-depth review.
|
||||
|
||||
#### 2.0.5
|
||||
* 25/03/2015
|
||||
* Amend README. Remove bitcoin address.
|
||||
|
||||
#### 2.0.4
|
||||
* 25/03/2015
|
||||
* Critical bugfix #58: division.
|
||||
|
||||
#### 2.0.3
|
||||
* 18/02/2015
|
||||
* Amend README. Add source map.
|
||||
|
||||
#### 2.0.2
|
||||
* 18/02/2015
|
||||
* Correct links.
|
||||
|
||||
#### 2.0.1
|
||||
* 18/02/2015
|
||||
* Add `max`, `min`, `precision`, `random`, `shiftedBy`, `toDigits` and `truncated` methods.
|
||||
* Add the short-forms: `add`, `mul`, `sd`, `sub` and `trunc`.
|
||||
* Add an `another` method to enable multiple independent constructors to be created.
|
||||
* Add support for the base 2, 8 and 16 prefixes `0b`, `0o` and `0x`.
|
||||
* Enable a rounding mode to be specified as a second parameter to `toExponential`, `toFixed`, `toFormat` and `toPrecision`.
|
||||
* Add a `CRYPTO` configuration property so cryptographically-secure pseudo-random number generation can be specified.
|
||||
* Add a `MODULO_MODE` configuration property to enable the rounding mode used by the `modulo` operation to be specified.
|
||||
* Add a `POW_PRECISION` configuration property to enable the number of significant digits calculated by the power operation to be limited.
|
||||
* Improve code quality.
|
||||
* Improve documentation.
|
||||
|
||||
#### 2.0.0
|
||||
* 29/12/2014
|
||||
* Add `dividedToIntegerBy`, `isInteger` and `toFormat` methods.
|
||||
* Remove the following short-forms: `isF`, `isZ`, `toE`, `toF`, `toFr`, `toN`, `toP`, `toS`.
|
||||
* Store a BigNumber's coefficient in base 1e14, rather than base 10.
|
||||
* Add fast path for integers to BigNumber constructor.
|
||||
* Incorporate the library into the online documentation.
|
||||
|
||||
#### 1.5.0
|
||||
* 13/11/2014
|
||||
* Add `toJSON` and `decimalPlaces` methods.
|
||||
|
||||
#### 1.4.1
|
||||
* 08/06/2014
|
||||
* Amend README.
|
||||
|
||||
#### 1.4.0
|
||||
* 08/05/2014
|
||||
* Add `toNumber`.
|
||||
|
||||
#### 1.3.0
|
||||
* 08/11/2013
|
||||
* Ensure correct rounding of `sqrt` in all, rather than almost all, cases.
|
||||
* Maximum radix to 64.
|
||||
|
||||
#### 1.2.1
|
||||
* 17/10/2013
|
||||
* Sign of zero when x < 0 and x + (-x) = 0.
|
||||
|
||||
#### 1.2.0
|
||||
* 19/9/2013
|
||||
* Throw Error objects for stack.
|
||||
|
||||
#### 1.1.1
|
||||
* 22/8/2013
|
||||
* Show original value in constructor error message.
|
||||
|
||||
#### 1.1.0
|
||||
* 1/8/2013
|
||||
* Allow numbers with trailing radix point.
|
||||
|
||||
#### 1.0.1
|
||||
* Bugfix: error messages with incorrect method name
|
||||
|
||||
#### 1.0.0
|
||||
* 8/11/2012
|
||||
* Initial release
|
||||
23
node_modules/bignumber.js/LICENCE
generated
vendored
Normal file
23
node_modules/bignumber.js/LICENCE
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
The MIT Licence.
|
||||
|
||||
Copyright (c) 2019 Michael Mclaughlin
|
||||
|
||||
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.
|
||||
|
||||
268
node_modules/bignumber.js/README.md
generated
vendored
Normal file
268
node_modules/bignumber.js/README.md
generated
vendored
Normal file
@ -0,0 +1,268 @@
|
||||

|
||||
|
||||
A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic.
|
||||
|
||||
[](https://travis-ci.org/MikeMcl/bignumber.js)
|
||||
|
||||
<br />
|
||||
|
||||
## Features
|
||||
|
||||
- Integers and decimals
|
||||
- Simple API but full-featured
|
||||
- Faster, smaller, and perhaps easier to use than JavaScript versions of Java's BigDecimal
|
||||
- 8 KB minified and gzipped
|
||||
- Replicates the `toExponential`, `toFixed`, `toPrecision` and `toString` methods of JavaScript's Number type
|
||||
- Includes a `toFraction` and a correctly-rounded `squareRoot` method
|
||||
- Supports cryptographically-secure pseudo-random number generation
|
||||
- No dependencies
|
||||
- Wide platform compatibility: uses JavaScript 1.5 (ECMAScript 3) features only
|
||||
- Comprehensive [documentation](http://mikemcl.github.io/bignumber.js/) and test set
|
||||
|
||||

|
||||
|
||||
If a smaller and simpler library is required see [big.js](https://github.com/MikeMcl/big.js/).
|
||||
It's less than half the size but only works with decimal numbers and only has half the methods.
|
||||
It also does not allow `NaN` or `Infinity`, or have the configuration options of this library.
|
||||
|
||||
See also [decimal.js](https://github.com/MikeMcl/decimal.js/), which among other things adds support for non-integer powers, and performs all operations to a specified number of significant digits.
|
||||
|
||||
## Load
|
||||
|
||||
The library is the single JavaScript file *bignumber.js* (or minified, *bignumber.min.js*).
|
||||
|
||||
Browser:
|
||||
|
||||
```html
|
||||
<script src='path/to/bignumber.js'></script>
|
||||
```
|
||||
|
||||
[Node.js](http://nodejs.org):
|
||||
|
||||
```bash
|
||||
$ npm install bignumber.js
|
||||
```
|
||||
|
||||
```javascript
|
||||
const BigNumber = require('bignumber.js');
|
||||
```
|
||||
|
||||
ES6 module:
|
||||
|
||||
```javascript
|
||||
import BigNumber from "./bignumber.mjs"
|
||||
```
|
||||
|
||||
AMD loader libraries such as [requireJS](http://requirejs.org/):
|
||||
|
||||
```javascript
|
||||
require(['bignumber'], function(BigNumber) {
|
||||
// Use BigNumber here in local scope. No global BigNumber.
|
||||
});
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
The library exports a single constructor function, [`BigNumber`](http://mikemcl.github.io/bignumber.js/#bignumber), which accepts a value of type Number, String or BigNumber,
|
||||
|
||||
```javascript
|
||||
let x = new BigNumber(123.4567);
|
||||
let y = BigNumber('123456.7e-3');
|
||||
let z = new BigNumber(x);
|
||||
x.isEqualTo(y) && y.isEqualTo(z) && x.isEqualTo(z); // true
|
||||
```
|
||||
|
||||
To get the string value of a BigNumber use [`toString()`](http://mikemcl.github.io/bignumber.js/#toS) or [`toFixed()`](http://mikemcl.github.io/bignumber.js/#toFix). Using `toFixed()` prevents exponential notation being returned, no matter how large or small the value.
|
||||
|
||||
```javascript
|
||||
let x = new BigNumber('1111222233334444555566');
|
||||
x.toString(); // "1.111222233334444555566e+21"
|
||||
x.toFixed(); // "1111222233334444555566"
|
||||
```
|
||||
|
||||
If the limited precision of Number values is not well understood, it is recommended to create BigNumbers from String values rather than Number values to avoid a potential loss of precision.
|
||||
|
||||
*In all further examples below, `let`, semicolons and `toString` calls are not shown. If a commented-out value is in quotes it means `toString` has been called on the preceding expression.*
|
||||
|
||||
```javascript
|
||||
// Precision loss from using numeric literals with more than 15 significant digits.
|
||||
new BigNumber(1.0000000000000001) // '1'
|
||||
new BigNumber(88259496234518.57) // '88259496234518.56'
|
||||
new BigNumber(99999999999999999999) // '100000000000000000000'
|
||||
|
||||
// Precision loss from using numeric literals outside the range of Number values.
|
||||
new BigNumber(2e+308) // 'Infinity'
|
||||
new BigNumber(1e-324) // '0'
|
||||
|
||||
// Precision loss from the unexpected result of arithmetic with Number values.
|
||||
new BigNumber(0.7 + 0.1) // '0.7999999999999999'
|
||||
```
|
||||
|
||||
When creating a BigNumber from a Number, note that a BigNumber is created from a Number's decimal `toString()` value not from its underlying binary value. If the latter is required, then pass the Number's `toString(2)` value and specify base 2.
|
||||
|
||||
```javascript
|
||||
new BigNumber(Number.MAX_VALUE.toString(2), 2)
|
||||
```
|
||||
|
||||
BigNumbers can be created from values in bases from 2 to 36. See [`ALPHABET`](http://mikemcl.github.io/bignumber.js/#alphabet) to extend this range.
|
||||
|
||||
```javascript
|
||||
a = new BigNumber(1011, 2) // "11"
|
||||
b = new BigNumber('zz.9', 36) // "1295.25"
|
||||
c = a.plus(b) // "1306.25"
|
||||
```
|
||||
|
||||
Performance is better if base 10 is NOT specified for decimal values. Only specify base 10 when it is desired that the number of decimal places of the input value be limited to the current [`DECIMAL_PLACES`](http://mikemcl.github.io/bignumber.js/#decimal-places) setting.
|
||||
|
||||
A BigNumber is immutable in the sense that it is not changed by its methods.
|
||||
|
||||
```javascript
|
||||
0.3 - 0.1 // 0.19999999999999998
|
||||
x = new BigNumber(0.3)
|
||||
x.minus(0.1) // "0.2"
|
||||
x // "0.3"
|
||||
```
|
||||
|
||||
The methods that return a BigNumber can be chained.
|
||||
|
||||
```javascript
|
||||
x.dividedBy(y).plus(z).times(9)
|
||||
x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').integerValue()
|
||||
```
|
||||
|
||||
Some of the longer method names have a shorter alias.
|
||||
|
||||
```javascript
|
||||
x.squareRoot().dividedBy(y).exponentiatedBy(3).isEqualTo(x.sqrt().div(y).pow(3)) // true
|
||||
x.modulo(y).multipliedBy(z).eq(x.mod(y).times(z)) // true
|
||||
```
|
||||
|
||||
As with JavaScript's Number type, there are [`toExponential`](http://mikemcl.github.io/bignumber.js/#toE), [`toFixed`](http://mikemcl.github.io/bignumber.js/#toFix) and [`toPrecision`](http://mikemcl.github.io/bignumber.js/#toP) methods.
|
||||
|
||||
```javascript
|
||||
x = new BigNumber(255.5)
|
||||
x.toExponential(5) // "2.55500e+2"
|
||||
x.toFixed(5) // "255.50000"
|
||||
x.toPrecision(5) // "255.50"
|
||||
x.toNumber() // 255.5
|
||||
```
|
||||
|
||||
A base can be specified for [`toString`](http://mikemcl.github.io/bignumber.js/#toS). Performance is better if base 10 is NOT specified, i.e. use `toString()` not `toString(10)`. Only specify base 10 when it is desired that the number of decimal places be limited to the current [`DECIMAL_PLACES`](http://mikemcl.github.io/bignumber.js/#decimal-places) setting.
|
||||
|
||||
```javascript
|
||||
x.toString(16) // "ff.8"
|
||||
```
|
||||
|
||||
There is a [`toFormat`](http://mikemcl.github.io/bignumber.js/#toFor) method which may be useful for internationalisation.
|
||||
|
||||
```javascript
|
||||
y = new BigNumber('1234567.898765')
|
||||
y.toFormat(2) // "1,234,567.90"
|
||||
```
|
||||
|
||||
The maximum number of decimal places of the result of an operation involving division (i.e. a division, square root, base conversion or negative power operation) is set using the `set` or `config` method of the `BigNumber` constructor.
|
||||
|
||||
The other arithmetic operations always give the exact result.
|
||||
|
||||
```javascript
|
||||
BigNumber.set({ DECIMAL_PLACES: 10, ROUNDING_MODE: 4 })
|
||||
|
||||
x = new BigNumber(2)
|
||||
y = new BigNumber(3)
|
||||
z = x.dividedBy(y) // "0.6666666667"
|
||||
z.squareRoot() // "0.8164965809"
|
||||
z.exponentiatedBy(-3) // "3.3749999995"
|
||||
z.toString(2) // "0.1010101011"
|
||||
z.multipliedBy(z) // "0.44444444448888888889"
|
||||
z.multipliedBy(z).decimalPlaces(10) // "0.4444444445"
|
||||
```
|
||||
|
||||
There is a [`toFraction`](http://mikemcl.github.io/bignumber.js/#toFr) method with an optional *maximum denominator* argument
|
||||
|
||||
```javascript
|
||||
y = new BigNumber(355)
|
||||
pi = y.dividedBy(113) // "3.1415929204"
|
||||
pi.toFraction() // [ "7853982301", "2500000000" ]
|
||||
pi.toFraction(1000) // [ "355", "113" ]
|
||||
```
|
||||
|
||||
and [`isNaN`](http://mikemcl.github.io/bignumber.js/#isNaN) and [`isFinite`](http://mikemcl.github.io/bignumber.js/#isF) methods, as `NaN` and `Infinity` are valid `BigNumber` values.
|
||||
|
||||
```javascript
|
||||
x = new BigNumber(NaN) // "NaN"
|
||||
y = new BigNumber(Infinity) // "Infinity"
|
||||
x.isNaN() && !y.isNaN() && !x.isFinite() && !y.isFinite() // true
|
||||
```
|
||||
|
||||
The value of a BigNumber is stored in a decimal floating point format in terms of a coefficient, exponent and sign.
|
||||
|
||||
```javascript
|
||||
x = new BigNumber(-123.456);
|
||||
x.c // [ 123, 45600000000000 ] coefficient (i.e. significand)
|
||||
x.e // 2 exponent
|
||||
x.s // -1 sign
|
||||
```
|
||||
|
||||
For advanced usage, multiple BigNumber constructors can be created, each with their own independent configuration.
|
||||
|
||||
```javascript
|
||||
// Set DECIMAL_PLACES for the original BigNumber constructor
|
||||
BigNumber.set({ DECIMAL_PLACES: 10 })
|
||||
|
||||
// Create another BigNumber constructor, optionally passing in a configuration object
|
||||
BN = BigNumber.clone({ DECIMAL_PLACES: 5 })
|
||||
|
||||
x = new BigNumber(1)
|
||||
y = new BN(1)
|
||||
|
||||
x.div(3) // '0.3333333333'
|
||||
y.div(3) // '0.33333'
|
||||
```
|
||||
|
||||
For further information see the [API](http://mikemcl.github.io/bignumber.js/) reference in the *doc* directory.
|
||||
|
||||
## Test
|
||||
|
||||
The *test/modules* directory contains the test scripts for each method.
|
||||
|
||||
The tests can be run with Node.js or a browser. For Node.js use
|
||||
|
||||
$ npm test
|
||||
|
||||
or
|
||||
|
||||
$ node test/test
|
||||
|
||||
To test a single method, use, for example
|
||||
|
||||
$ node test/methods/toFraction
|
||||
|
||||
For the browser, open *test/test.html*.
|
||||
|
||||
## Build
|
||||
|
||||
For Node, if [uglify-js](https://github.com/mishoo/UglifyJS2) is installed
|
||||
|
||||
npm install uglify-js -g
|
||||
|
||||
then
|
||||
|
||||
npm run build
|
||||
|
||||
will create *bignumber.min.js*.
|
||||
|
||||
A source map will also be created in the root directory.
|
||||
|
||||
## Feedback
|
||||
|
||||
Open an issue, or email
|
||||
|
||||
Michael
|
||||
|
||||
<a href="mailto:M8ch88l@gmail.com">M8ch88l@gmail.com</a>
|
||||
|
||||
## Licence
|
||||
|
||||
The MIT Licence.
|
||||
|
||||
See [LICENCE](https://github.com/MikeMcl/bignumber.js/blob/master/LICENCE).
|
||||
1829
node_modules/bignumber.js/bignumber.d.ts
generated
vendored
Normal file
1829
node_modules/bignumber.js/bignumber.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2902
node_modules/bignumber.js/bignumber.js
generated
vendored
Normal file
2902
node_modules/bignumber.js/bignumber.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/bignumber.js/bignumber.min.js
generated
vendored
Normal file
1
node_modules/bignumber.js/bignumber.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/bignumber.js/bignumber.min.js.map
generated
vendored
Normal file
1
node_modules/bignumber.js/bignumber.min.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2888
node_modules/bignumber.js/bignumber.mjs
generated
vendored
Normal file
2888
node_modules/bignumber.js/bignumber.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2237
node_modules/bignumber.js/doc/API.html
generated
vendored
Normal file
2237
node_modules/bignumber.js/doc/API.html
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
40
node_modules/bignumber.js/package.json
generated
vendored
Normal file
40
node_modules/bignumber.js/package.json
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "bignumber.js",
|
||||
"description": "A library for arbitrary-precision decimal and non-decimal arithmetic",
|
||||
"version": "9.0.0",
|
||||
"keywords": [
|
||||
"arbitrary",
|
||||
"precision",
|
||||
"arithmetic",
|
||||
"big",
|
||||
"number",
|
||||
"decimal",
|
||||
"float",
|
||||
"biginteger",
|
||||
"bigdecimal",
|
||||
"bignumber",
|
||||
"bigint",
|
||||
"bignum"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/MikeMcl/bignumber.js.git"
|
||||
},
|
||||
"main": "bignumber",
|
||||
"module": "bignumber.mjs",
|
||||
"browser": "bignumber.js",
|
||||
"types": "bignumber.d.ts",
|
||||
"author": {
|
||||
"name": "Michael Mclaughlin",
|
||||
"email": "M8ch88l@gmail.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "node test/test",
|
||||
"build": "uglifyjs bignumber.js --source-map -c -m -o bignumber.min.js"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
29
node_modules/denque/CHANGELOG.md
generated
vendored
Normal file
29
node_modules/denque/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
## 2.1.0
|
||||
|
||||
- fix: issue where `clear()` is still keeping references to the elements (#47)
|
||||
- refactor: performance optimizations for growth and array copy (#43)
|
||||
- refactor: performance optimizations for toArray and fromArray (#46)
|
||||
- test: add additional benchmarks for queue growth and `toArray` (#45)
|
||||
|
||||
## 2.0.1
|
||||
|
||||
- fix(types): incorrect return type on `size()`
|
||||
|
||||
## 2.0.0
|
||||
|
||||
- fix!: `push` & `unshift` now accept `undefined` values to match behaviour of `Array` (fixes #25) (#35)
|
||||
- This is only a **BREAKING** change if you are currently expecting `push(undefined)` and `unshift(undefined)` to do
|
||||
nothing - the new behaviour now correctly adds undefined values to the queue.
|
||||
- **Note**: behaviour of `push()` & `unshift()` (no arguments) remains unchanged (nothing gets added to the queue).
|
||||
- **Note**: If you need to differentiate between `undefined` values in the queue and the return value of `pop()` then
|
||||
check the queue `.length` before popping.
|
||||
- fix: incorrect methods in types definition file
|
||||
|
||||
## 1.5.1
|
||||
|
||||
- perf: minor performance tweak when growing queue size (#29)
|
||||
|
||||
## 1.5.0
|
||||
|
||||
- feat: adds capacity option for circular buffers (#27)
|
||||
|
||||
201
node_modules/denque/LICENSE
generated
vendored
Normal file
201
node_modules/denque/LICENSE
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
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 2018-present Invertase Limited
|
||||
|
||||
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.
|
||||
77
node_modules/denque/README.md
generated
vendored
Normal file
77
node_modules/denque/README.md
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
<p align="center">
|
||||
<h1 align="center">Denque</h1>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/package/denque"><img src="https://img.shields.io/npm/dm/denque.svg?style=flat-square" alt="NPM downloads"></a>
|
||||
<a href="https://www.npmjs.com/package/denque"><img src="https://img.shields.io/npm/v/denque.svg?style=flat-square" alt="NPM version"></a>
|
||||
<a href="https://github.com/invertase/denque/actions/workflows/testing.yam"><img src="https://github.com/invertase/denque/actions/workflows/testing.yaml/badge.svg" alt="Tests status"></a>
|
||||
<a href="https://codecov.io/gh/invertase/denque"><img src="https://codecov.io/gh/invertase/denque/branch/master/graph/badge.svg?token=rn91iI4bSe" alt="Coverage"></a>
|
||||
<a href="/LICENSE"><img src="https://img.shields.io/npm/l/denque.svg?style=flat-square" alt="License"></a>
|
||||
<a href="https://twitter.com/invertaseio"><img src="https://img.shields.io/twitter/follow/invertaseio.svg?style=social&label=Follow" alt="Follow on Twitter"></a>
|
||||
</p>
|
||||
|
||||
Denque is a well tested, extremely fast and lightweight [double-ended queue](http://en.wikipedia.org/wiki/Double-ended_queue)
|
||||
implementation with zero dependencies and includes TypeScript types.
|
||||
|
||||
Double-ended queues can also be used as a:
|
||||
|
||||
- [Stack](http://en.wikipedia.org/wiki/Stack_\(abstract_data_type\))
|
||||
- [Queue](http://en.wikipedia.org/wiki/Queue_\(data_structure\))
|
||||
|
||||
This implementation is currently the fastest available, even faster than `double-ended-queue`, see the [benchmarks](https://docs.page/invertase/denque/benchmarks).
|
||||
|
||||
Every queue operation is done at a constant `O(1)` - including random access from `.peekAt(index)`.
|
||||
|
||||
**Works on all node versions >= v0.10**
|
||||
|
||||
## Quick Start
|
||||
|
||||
Install the package:
|
||||
|
||||
```bash
|
||||
npm install denque
|
||||
```
|
||||
|
||||
Create and consume a queue:
|
||||
|
||||
```js
|
||||
const Denque = require("denque");
|
||||
|
||||
const denque = new Denque([1,2,3,4]);
|
||||
denque.shift(); // 1
|
||||
denque.pop(); // 4
|
||||
```
|
||||
|
||||
|
||||
See the [API reference documentation](https://docs.page/invertase/denque/api) for more examples.
|
||||
|
||||
---
|
||||
|
||||
## Who's using it?
|
||||
|
||||
- [Kafka Node.js client](https://www.npmjs.com/package/kafka-node)
|
||||
- [MariaDB Node.js client](https://www.npmjs.com/package/mariadb)
|
||||
- [MongoDB Node.js client](https://www.npmjs.com/package/mongodb)
|
||||
- [MySQL Node.js client](https://www.npmjs.com/package/mysql2)
|
||||
- [Redis Node.js clients](https://www.npmjs.com/package/redis)
|
||||
|
||||
... and [many more](https://www.npmjs.com/browse/depended/denque).
|
||||
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
- See [LICENSE](/LICENSE)
|
||||
|
||||
---
|
||||
|
||||
<p align="center">
|
||||
<a href="https://invertase.io/?utm_source=readme&utm_medium=footer&utm_campaign=denque">
|
||||
<img width="75px" src="https://static.invertase.io/assets/invertase/invertase-rounded-avatar.png">
|
||||
</a>
|
||||
<p align="center">
|
||||
Built and maintained by <a href="https://invertase.io/?utm_source=readme&utm_medium=footer&utm_campaign=denque">Invertase</a>.
|
||||
</p>
|
||||
</p>
|
||||
47
node_modules/denque/index.d.ts
generated
vendored
Normal file
47
node_modules/denque/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
declare class Denque<T = any> {
|
||||
length: number;
|
||||
|
||||
constructor();
|
||||
|
||||
constructor(array: T[]);
|
||||
|
||||
constructor(array: T[], options: IDenqueOptions);
|
||||
|
||||
push(item: T): number;
|
||||
|
||||
unshift(item: T): number;
|
||||
|
||||
pop(): T | undefined;
|
||||
|
||||
shift(): T | undefined;
|
||||
|
||||
peekBack(): T | undefined;
|
||||
|
||||
peekFront(): T | undefined;
|
||||
|
||||
peekAt(index: number): T | undefined;
|
||||
|
||||
get(index: number): T | undefined;
|
||||
|
||||
remove(index: number, count: number): T[];
|
||||
|
||||
removeOne(index: number): T | undefined;
|
||||
|
||||
splice(index: number, count: number, ...item: T[]): T[] | undefined;
|
||||
|
||||
isEmpty(): boolean;
|
||||
|
||||
clear(): void;
|
||||
|
||||
size(): number;
|
||||
|
||||
toString(): string;
|
||||
|
||||
toArray(): T[];
|
||||
}
|
||||
|
||||
interface IDenqueOptions {
|
||||
capacity?: number
|
||||
}
|
||||
|
||||
export = Denque;
|
||||
481
node_modules/denque/index.js
generated
vendored
Normal file
481
node_modules/denque/index.js
generated
vendored
Normal file
@ -0,0 +1,481 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Custom implementation of a double ended queue.
|
||||
*/
|
||||
function Denque(array, options) {
|
||||
var options = options || {};
|
||||
this._capacity = options.capacity;
|
||||
|
||||
this._head = 0;
|
||||
this._tail = 0;
|
||||
|
||||
if (Array.isArray(array)) {
|
||||
this._fromArray(array);
|
||||
} else {
|
||||
this._capacityMask = 0x3;
|
||||
this._list = new Array(4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* --------------
|
||||
* PUBLIC API
|
||||
* -------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the item at the specified index from the list.
|
||||
* 0 is the first element, 1 is the second, and so on...
|
||||
* Elements at negative values are that many from the end: -1 is one before the end
|
||||
* (the last element), -2 is two before the end (one before last), etc.
|
||||
* @param index
|
||||
* @returns {*}
|
||||
*/
|
||||
Denque.prototype.peekAt = function peekAt(index) {
|
||||
var i = index;
|
||||
// expect a number or return undefined
|
||||
if ((i !== (i | 0))) {
|
||||
return void 0;
|
||||
}
|
||||
var len = this.size();
|
||||
if (i >= len || i < -len) return undefined;
|
||||
if (i < 0) i += len;
|
||||
i = (this._head + i) & this._capacityMask;
|
||||
return this._list[i];
|
||||
};
|
||||
|
||||
/**
|
||||
* Alias for peekAt()
|
||||
* @param i
|
||||
* @returns {*}
|
||||
*/
|
||||
Denque.prototype.get = function get(i) {
|
||||
return this.peekAt(i);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the first item in the list without removing it.
|
||||
* @returns {*}
|
||||
*/
|
||||
Denque.prototype.peek = function peek() {
|
||||
if (this._head === this._tail) return undefined;
|
||||
return this._list[this._head];
|
||||
};
|
||||
|
||||
/**
|
||||
* Alias for peek()
|
||||
* @returns {*}
|
||||
*/
|
||||
Denque.prototype.peekFront = function peekFront() {
|
||||
return this.peek();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the item that is at the back of the queue without removing it.
|
||||
* Uses peekAt(-1)
|
||||
*/
|
||||
Denque.prototype.peekBack = function peekBack() {
|
||||
return this.peekAt(-1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the current length of the queue
|
||||
* @return {Number}
|
||||
*/
|
||||
Object.defineProperty(Denque.prototype, 'length', {
|
||||
get: function length() {
|
||||
return this.size();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Return the number of items on the list, or 0 if empty.
|
||||
* @returns {number}
|
||||
*/
|
||||
Denque.prototype.size = function size() {
|
||||
if (this._head === this._tail) return 0;
|
||||
if (this._head < this._tail) return this._tail - this._head;
|
||||
else return this._capacityMask + 1 - (this._head - this._tail);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an item at the beginning of the list.
|
||||
* @param item
|
||||
*/
|
||||
Denque.prototype.unshift = function unshift(item) {
|
||||
if (arguments.length === 0) return this.size();
|
||||
var len = this._list.length;
|
||||
this._head = (this._head - 1 + len) & this._capacityMask;
|
||||
this._list[this._head] = item;
|
||||
if (this._tail === this._head) this._growArray();
|
||||
if (this._capacity && this.size() > this._capacity) this.pop();
|
||||
if (this._head < this._tail) return this._tail - this._head;
|
||||
else return this._capacityMask + 1 - (this._head - this._tail);
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove and return the first item on the list,
|
||||
* Returns undefined if the list is empty.
|
||||
* @returns {*}
|
||||
*/
|
||||
Denque.prototype.shift = function shift() {
|
||||
var head = this._head;
|
||||
if (head === this._tail) return undefined;
|
||||
var item = this._list[head];
|
||||
this._list[head] = undefined;
|
||||
this._head = (head + 1) & this._capacityMask;
|
||||
if (head < 2 && this._tail > 10000 && this._tail <= this._list.length >>> 2) this._shrinkArray();
|
||||
return item;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an item to the bottom of the list.
|
||||
* @param item
|
||||
*/
|
||||
Denque.prototype.push = function push(item) {
|
||||
if (arguments.length === 0) return this.size();
|
||||
var tail = this._tail;
|
||||
this._list[tail] = item;
|
||||
this._tail = (tail + 1) & this._capacityMask;
|
||||
if (this._tail === this._head) {
|
||||
this._growArray();
|
||||
}
|
||||
if (this._capacity && this.size() > this._capacity) {
|
||||
this.shift();
|
||||
}
|
||||
if (this._head < this._tail) return this._tail - this._head;
|
||||
else return this._capacityMask + 1 - (this._head - this._tail);
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove and return the last item on the list.
|
||||
* Returns undefined if the list is empty.
|
||||
* @returns {*}
|
||||
*/
|
||||
Denque.prototype.pop = function pop() {
|
||||
var tail = this._tail;
|
||||
if (tail === this._head) return undefined;
|
||||
var len = this._list.length;
|
||||
this._tail = (tail - 1 + len) & this._capacityMask;
|
||||
var item = this._list[this._tail];
|
||||
this._list[this._tail] = undefined;
|
||||
if (this._head < 2 && tail > 10000 && tail <= len >>> 2) this._shrinkArray();
|
||||
return item;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove and return the item at the specified index from the list.
|
||||
* Returns undefined if the list is empty.
|
||||
* @param index
|
||||
* @returns {*}
|
||||
*/
|
||||
Denque.prototype.removeOne = function removeOne(index) {
|
||||
var i = index;
|
||||
// expect a number or return undefined
|
||||
if ((i !== (i | 0))) {
|
||||
return void 0;
|
||||
}
|
||||
if (this._head === this._tail) return void 0;
|
||||
var size = this.size();
|
||||
var len = this._list.length;
|
||||
if (i >= size || i < -size) return void 0;
|
||||
if (i < 0) i += size;
|
||||
i = (this._head + i) & this._capacityMask;
|
||||
var item = this._list[i];
|
||||
var k;
|
||||
if (index < size / 2) {
|
||||
for (k = index; k > 0; k--) {
|
||||
this._list[i] = this._list[i = (i - 1 + len) & this._capacityMask];
|
||||
}
|
||||
this._list[i] = void 0;
|
||||
this._head = (this._head + 1 + len) & this._capacityMask;
|
||||
} else {
|
||||
for (k = size - 1 - index; k > 0; k--) {
|
||||
this._list[i] = this._list[i = (i + 1 + len) & this._capacityMask];
|
||||
}
|
||||
this._list[i] = void 0;
|
||||
this._tail = (this._tail - 1 + len) & this._capacityMask;
|
||||
}
|
||||
return item;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove number of items from the specified index from the list.
|
||||
* Returns array of removed items.
|
||||
* Returns undefined if the list is empty.
|
||||
* @param index
|
||||
* @param count
|
||||
* @returns {array}
|
||||
*/
|
||||
Denque.prototype.remove = function remove(index, count) {
|
||||
var i = index;
|
||||
var removed;
|
||||
var del_count = count;
|
||||
// expect a number or return undefined
|
||||
if ((i !== (i | 0))) {
|
||||
return void 0;
|
||||
}
|
||||
if (this._head === this._tail) return void 0;
|
||||
var size = this.size();
|
||||
var len = this._list.length;
|
||||
if (i >= size || i < -size || count < 1) return void 0;
|
||||
if (i < 0) i += size;
|
||||
if (count === 1 || !count) {
|
||||
removed = new Array(1);
|
||||
removed[0] = this.removeOne(i);
|
||||
return removed;
|
||||
}
|
||||
if (i === 0 && i + count >= size) {
|
||||
removed = this.toArray();
|
||||
this.clear();
|
||||
return removed;
|
||||
}
|
||||
if (i + count > size) count = size - i;
|
||||
var k;
|
||||
removed = new Array(count);
|
||||
for (k = 0; k < count; k++) {
|
||||
removed[k] = this._list[(this._head + i + k) & this._capacityMask];
|
||||
}
|
||||
i = (this._head + i) & this._capacityMask;
|
||||
if (index + count === size) {
|
||||
this._tail = (this._tail - count + len) & this._capacityMask;
|
||||
for (k = count; k > 0; k--) {
|
||||
this._list[i = (i + 1 + len) & this._capacityMask] = void 0;
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
if (index === 0) {
|
||||
this._head = (this._head + count + len) & this._capacityMask;
|
||||
for (k = count - 1; k > 0; k--) {
|
||||
this._list[i = (i + 1 + len) & this._capacityMask] = void 0;
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
if (i < size / 2) {
|
||||
this._head = (this._head + index + count + len) & this._capacityMask;
|
||||
for (k = index; k > 0; k--) {
|
||||
this.unshift(this._list[i = (i - 1 + len) & this._capacityMask]);
|
||||
}
|
||||
i = (this._head - 1 + len) & this._capacityMask;
|
||||
while (del_count > 0) {
|
||||
this._list[i = (i - 1 + len) & this._capacityMask] = void 0;
|
||||
del_count--;
|
||||
}
|
||||
if (index < 0) this._tail = i;
|
||||
} else {
|
||||
this._tail = i;
|
||||
i = (i + count + len) & this._capacityMask;
|
||||
for (k = size - (count + index); k > 0; k--) {
|
||||
this.push(this._list[i++]);
|
||||
}
|
||||
i = this._tail;
|
||||
while (del_count > 0) {
|
||||
this._list[i = (i + 1 + len) & this._capacityMask] = void 0;
|
||||
del_count--;
|
||||
}
|
||||
}
|
||||
if (this._head < 2 && this._tail > 10000 && this._tail <= len >>> 2) this._shrinkArray();
|
||||
return removed;
|
||||
};
|
||||
|
||||
/**
|
||||
* Native splice implementation.
|
||||
* Remove number of items from the specified index from the list and/or add new elements.
|
||||
* Returns array of removed items or empty array if count == 0.
|
||||
* Returns undefined if the list is empty.
|
||||
*
|
||||
* @param index
|
||||
* @param count
|
||||
* @param {...*} [elements]
|
||||
* @returns {array}
|
||||
*/
|
||||
Denque.prototype.splice = function splice(index, count) {
|
||||
var i = index;
|
||||
// expect a number or return undefined
|
||||
if ((i !== (i | 0))) {
|
||||
return void 0;
|
||||
}
|
||||
var size = this.size();
|
||||
if (i < 0) i += size;
|
||||
if (i > size) return void 0;
|
||||
if (arguments.length > 2) {
|
||||
var k;
|
||||
var temp;
|
||||
var removed;
|
||||
var arg_len = arguments.length;
|
||||
var len = this._list.length;
|
||||
var arguments_index = 2;
|
||||
if (!size || i < size / 2) {
|
||||
temp = new Array(i);
|
||||
for (k = 0; k < i; k++) {
|
||||
temp[k] = this._list[(this._head + k) & this._capacityMask];
|
||||
}
|
||||
if (count === 0) {
|
||||
removed = [];
|
||||
if (i > 0) {
|
||||
this._head = (this._head + i + len) & this._capacityMask;
|
||||
}
|
||||
} else {
|
||||
removed = this.remove(i, count);
|
||||
this._head = (this._head + i + len) & this._capacityMask;
|
||||
}
|
||||
while (arg_len > arguments_index) {
|
||||
this.unshift(arguments[--arg_len]);
|
||||
}
|
||||
for (k = i; k > 0; k--) {
|
||||
this.unshift(temp[k - 1]);
|
||||
}
|
||||
} else {
|
||||
temp = new Array(size - (i + count));
|
||||
var leng = temp.length;
|
||||
for (k = 0; k < leng; k++) {
|
||||
temp[k] = this._list[(this._head + i + count + k) & this._capacityMask];
|
||||
}
|
||||
if (count === 0) {
|
||||
removed = [];
|
||||
if (i != size) {
|
||||
this._tail = (this._head + i + len) & this._capacityMask;
|
||||
}
|
||||
} else {
|
||||
removed = this.remove(i, count);
|
||||
this._tail = (this._tail - leng + len) & this._capacityMask;
|
||||
}
|
||||
while (arguments_index < arg_len) {
|
||||
this.push(arguments[arguments_index++]);
|
||||
}
|
||||
for (k = 0; k < leng; k++) {
|
||||
this.push(temp[k]);
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
} else {
|
||||
return this.remove(i, count);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Soft clear - does not reset capacity.
|
||||
*/
|
||||
Denque.prototype.clear = function clear() {
|
||||
this._list = new Array(this._list.length);
|
||||
this._head = 0;
|
||||
this._tail = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true or false whether the list is empty.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
Denque.prototype.isEmpty = function isEmpty() {
|
||||
return this._head === this._tail;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an array of all queue items.
|
||||
* @returns {Array}
|
||||
*/
|
||||
Denque.prototype.toArray = function toArray() {
|
||||
return this._copyArray(false);
|
||||
};
|
||||
|
||||
/**
|
||||
* -------------
|
||||
* INTERNALS
|
||||
* -------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fills the queue with items from an array
|
||||
* For use in the constructor
|
||||
* @param array
|
||||
* @private
|
||||
*/
|
||||
Denque.prototype._fromArray = function _fromArray(array) {
|
||||
var length = array.length;
|
||||
var capacity = this._nextPowerOf2(length);
|
||||
|
||||
this._list = new Array(capacity);
|
||||
this._capacityMask = capacity - 1;
|
||||
this._tail = length;
|
||||
|
||||
for (var i = 0; i < length; i++) this._list[i] = array[i];
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param fullCopy
|
||||
* @param size Initialize the array with a specific size. Will default to the current list size
|
||||
* @returns {Array}
|
||||
* @private
|
||||
*/
|
||||
Denque.prototype._copyArray = function _copyArray(fullCopy, size) {
|
||||
var src = this._list;
|
||||
var capacity = src.length;
|
||||
var length = this.length;
|
||||
size = size | length;
|
||||
|
||||
// No prealloc requested and the buffer is contiguous
|
||||
if (size == length && this._head < this._tail) {
|
||||
// Simply do a fast slice copy
|
||||
return this._list.slice(this._head, this._tail);
|
||||
}
|
||||
|
||||
var dest = new Array(size);
|
||||
|
||||
var k = 0;
|
||||
var i;
|
||||
if (fullCopy || this._head > this._tail) {
|
||||
for (i = this._head; i < capacity; i++) dest[k++] = src[i];
|
||||
for (i = 0; i < this._tail; i++) dest[k++] = src[i];
|
||||
} else {
|
||||
for (i = this._head; i < this._tail; i++) dest[k++] = src[i];
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Grows the internal list array.
|
||||
* @private
|
||||
*/
|
||||
Denque.prototype._growArray = function _growArray() {
|
||||
if (this._head != 0) {
|
||||
// double array size and copy existing data, head to end, then beginning to tail.
|
||||
var newList = this._copyArray(true, this._list.length << 1);
|
||||
|
||||
this._tail = this._list.length;
|
||||
this._head = 0;
|
||||
|
||||
this._list = newList;
|
||||
} else {
|
||||
this._tail = this._list.length;
|
||||
this._list.length <<= 1;
|
||||
}
|
||||
|
||||
this._capacityMask = (this._capacityMask << 1) | 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Shrinks the internal list array.
|
||||
* @private
|
||||
*/
|
||||
Denque.prototype._shrinkArray = function _shrinkArray() {
|
||||
this._list.length >>>= 1;
|
||||
this._capacityMask >>>= 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find the next power of 2, at least 4
|
||||
* @private
|
||||
* @param {number} num
|
||||
* @returns {number}
|
||||
*/
|
||||
Denque.prototype._nextPowerOf2 = function _nextPowerOf2(num) {
|
||||
var log2 = Math.log(num) / Math.log(2);
|
||||
var nextPow2 = 1 << (log2 + 1);
|
||||
|
||||
return Math.max(nextPow2, 4);
|
||||
}
|
||||
|
||||
module.exports = Denque;
|
||||
58
node_modules/denque/package.json
generated
vendored
Normal file
58
node_modules/denque/package.json
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "denque",
|
||||
"version": "2.1.0",
|
||||
"description": "The fastest javascript implementation of a double-ended queue. Used by the official Redis, MongoDB, MariaDB & MySQL libraries for Node.js and many other libraries. Maintains compatability with deque.",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
},
|
||||
"keywords": [
|
||||
"data-structure",
|
||||
"data-structures",
|
||||
"queue",
|
||||
"double",
|
||||
"end",
|
||||
"ended",
|
||||
"deque",
|
||||
"denque",
|
||||
"double-ended-queue"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "istanbul cover --report lcov _mocha && npm run typescript",
|
||||
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
||||
"typescript": "tsc --project ./test/type/tsconfig.json",
|
||||
"benchmark_thousand": "node benchmark/thousand",
|
||||
"benchmark_2mil": "node benchmark/two_million",
|
||||
"benchmark_splice": "node benchmark/splice",
|
||||
"benchmark_remove": "node benchmark/remove",
|
||||
"benchmark_removeOne": "node benchmark/removeOne",
|
||||
"benchmark_growth": "node benchmark/growth",
|
||||
"benchmark_toArray": "node benchmark/toArray",
|
||||
"benchmark_fromArray": "node benchmark/fromArray"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/invertase/denque.git"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"author": {
|
||||
"name": "Invertase",
|
||||
"email": "oss@invertase.io",
|
||||
"url": "http://github.com/invertase/"
|
||||
},
|
||||
"contributors": [
|
||||
"Mike Diarmid (Salakar) <mike@invertase.io>"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/invertase/denque/issues"
|
||||
},
|
||||
"homepage": "https://docs.page/invertase/denque",
|
||||
"devDependencies": {
|
||||
"benchmark": "^2.1.4",
|
||||
"codecov": "^3.8.3",
|
||||
"double-ended-queue": "^2.1.0-0",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^3.5.3",
|
||||
"typescript": "^3.4.1"
|
||||
}
|
||||
}
|
||||
3
node_modules/generate-function/.travis.yml
generated
vendored
Normal file
3
node_modules/generate-function/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
21
node_modules/generate-function/LICENSE
generated
vendored
Normal file
21
node_modules/generate-function/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Mathias Buus
|
||||
|
||||
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.
|
||||
89
node_modules/generate-function/README.md
generated
vendored
Normal file
89
node_modules/generate-function/README.md
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
# generate-function
|
||||
|
||||
Module that helps you write generated functions in Node
|
||||
|
||||
```
|
||||
npm install generate-function
|
||||
```
|
||||
|
||||
[](http://travis-ci.org/mafintosh/generate-function)
|
||||
|
||||
## Disclamer
|
||||
|
||||
Writing code that generates code is hard.
|
||||
You should only use this if you really, really, really need this for performance reasons (like schema validators / parsers etc).
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
const genfun = require('generate-function')
|
||||
const { d } = genfun.formats
|
||||
|
||||
function addNumber (val) {
|
||||
const gen = genfun()
|
||||
|
||||
gen(`
|
||||
function add (n) {')
|
||||
return n + ${d(val)}) // supports format strings to insert values
|
||||
}
|
||||
`)
|
||||
|
||||
return gen.toFunction() // will compile the function
|
||||
}
|
||||
|
||||
const add2 = addNumber(2)
|
||||
|
||||
console.log('1 + 2 =', add2(1))
|
||||
console.log(add2.toString()) // prints the generated function
|
||||
```
|
||||
|
||||
If you need to close over variables in your generated function pass them to `toFunction(scope)`
|
||||
|
||||
``` js
|
||||
function multiply (a, b) {
|
||||
return a * b
|
||||
}
|
||||
|
||||
function addAndMultiplyNumber (val) {
|
||||
const gen = genfun()
|
||||
|
||||
gen(`
|
||||
function (n) {
|
||||
if (typeof n !== 'number') {
|
||||
throw new Error('argument should be a number')
|
||||
}
|
||||
const result = multiply(${d(val)}, n + ${d(val)})
|
||||
return result
|
||||
}
|
||||
`)
|
||||
|
||||
// use gen.toString() if you want to see the generated source
|
||||
|
||||
return gen.toFunction({multiply})
|
||||
}
|
||||
|
||||
const addAndMultiply2 = addAndMultiplyNumber(2)
|
||||
|
||||
console.log(addAndMultiply2.toString())
|
||||
console.log('(3 + 2) * 2 =', addAndMultiply2(3))
|
||||
```
|
||||
|
||||
You can call `gen(src)` as many times as you want to append more source code to the function.
|
||||
|
||||
## Variables
|
||||
|
||||
If you need a unique safe identifier for the scope of the generated function call `str = gen.sym('friendlyName')`.
|
||||
These are safe to use for variable names etc.
|
||||
|
||||
## Object properties
|
||||
|
||||
If you need to access an object property use the `str = gen.property('objectName', 'propertyName')`.
|
||||
|
||||
This returns `'objectName.propertyName'` if `propertyName` is safe to use as a variable. Otherwise
|
||||
it returns `objectName[propertyNameAsString]`.
|
||||
|
||||
If you only pass `gen.property('propertyName')` it will only return the `propertyName` part safely
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
27
node_modules/generate-function/example.js
generated
vendored
Normal file
27
node_modules/generate-function/example.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
const genfun = require('./')
|
||||
const { d } = genfun.formats
|
||||
|
||||
function multiply (a, b) {
|
||||
return a * b
|
||||
}
|
||||
|
||||
function addAndMultiplyNumber (val) {
|
||||
const fn = genfun(`
|
||||
function (n) {
|
||||
if (typeof n !== 'number') {
|
||||
throw new Error('argument should be a number')
|
||||
}
|
||||
const result = multiply(${d(val)}, n + ${d(val)})
|
||||
return result
|
||||
}
|
||||
`)
|
||||
|
||||
// use fn.toString() if you want to see the generated source
|
||||
|
||||
return fn.toFunction({multiply})
|
||||
}
|
||||
|
||||
const addAndMultiply2 = addAndMultiplyNumber(2)
|
||||
|
||||
console.log(addAndMultiply2.toString())
|
||||
console.log('(3 + 2) * 2 =', addAndMultiply2(3))
|
||||
181
node_modules/generate-function/index.js
generated
vendored
Normal file
181
node_modules/generate-function/index.js
generated
vendored
Normal file
@ -0,0 +1,181 @@
|
||||
var util = require('util')
|
||||
var isProperty = require('is-property')
|
||||
|
||||
var INDENT_START = /[\{\[]/
|
||||
var INDENT_END = /[\}\]]/
|
||||
|
||||
// from https://mathiasbynens.be/notes/reserved-keywords
|
||||
var RESERVED = [
|
||||
'do',
|
||||
'if',
|
||||
'in',
|
||||
'for',
|
||||
'let',
|
||||
'new',
|
||||
'try',
|
||||
'var',
|
||||
'case',
|
||||
'else',
|
||||
'enum',
|
||||
'eval',
|
||||
'null',
|
||||
'this',
|
||||
'true',
|
||||
'void',
|
||||
'with',
|
||||
'await',
|
||||
'break',
|
||||
'catch',
|
||||
'class',
|
||||
'const',
|
||||
'false',
|
||||
'super',
|
||||
'throw',
|
||||
'while',
|
||||
'yield',
|
||||
'delete',
|
||||
'export',
|
||||
'import',
|
||||
'public',
|
||||
'return',
|
||||
'static',
|
||||
'switch',
|
||||
'typeof',
|
||||
'default',
|
||||
'extends',
|
||||
'finally',
|
||||
'package',
|
||||
'private',
|
||||
'continue',
|
||||
'debugger',
|
||||
'function',
|
||||
'arguments',
|
||||
'interface',
|
||||
'protected',
|
||||
'implements',
|
||||
'instanceof',
|
||||
'NaN',
|
||||
'undefined'
|
||||
]
|
||||
|
||||
var RESERVED_MAP = {}
|
||||
|
||||
for (var i = 0; i < RESERVED.length; i++) {
|
||||
RESERVED_MAP[RESERVED[i]] = true
|
||||
}
|
||||
|
||||
var isVariable = function (name) {
|
||||
return isProperty(name) && !RESERVED_MAP.hasOwnProperty(name)
|
||||
}
|
||||
|
||||
var formats = {
|
||||
s: function(s) {
|
||||
return '' + s
|
||||
},
|
||||
d: function(d) {
|
||||
return '' + Number(d)
|
||||
},
|
||||
o: function(o) {
|
||||
return JSON.stringify(o)
|
||||
}
|
||||
}
|
||||
|
||||
var genfun = function() {
|
||||
var lines = []
|
||||
var indent = 0
|
||||
var vars = {}
|
||||
|
||||
var push = function(str) {
|
||||
var spaces = ''
|
||||
while (spaces.length < indent*2) spaces += ' '
|
||||
lines.push(spaces+str)
|
||||
}
|
||||
|
||||
var pushLine = function(line) {
|
||||
if (INDENT_END.test(line.trim()[0]) && INDENT_START.test(line[line.length-1])) {
|
||||
indent--
|
||||
push(line)
|
||||
indent++
|
||||
return
|
||||
}
|
||||
if (INDENT_START.test(line[line.length-1])) {
|
||||
push(line)
|
||||
indent++
|
||||
return
|
||||
}
|
||||
if (INDENT_END.test(line.trim()[0])) {
|
||||
indent--
|
||||
push(line)
|
||||
return
|
||||
}
|
||||
|
||||
push(line)
|
||||
}
|
||||
|
||||
var line = function(fmt) {
|
||||
if (!fmt) return line
|
||||
|
||||
if (arguments.length === 1 && fmt.indexOf('\n') > -1) {
|
||||
var lines = fmt.trim().split('\n')
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
pushLine(lines[i].trim())
|
||||
}
|
||||
} else {
|
||||
pushLine(util.format.apply(util, arguments))
|
||||
}
|
||||
|
||||
return line
|
||||
}
|
||||
|
||||
line.scope = {}
|
||||
line.formats = formats
|
||||
|
||||
line.sym = function(name) {
|
||||
if (!name || !isVariable(name)) name = 'tmp'
|
||||
if (!vars[name]) vars[name] = 0
|
||||
return name + (vars[name]++ || '')
|
||||
}
|
||||
|
||||
line.property = function(obj, name) {
|
||||
if (arguments.length === 1) {
|
||||
name = obj
|
||||
obj = ''
|
||||
}
|
||||
|
||||
name = name + ''
|
||||
|
||||
if (isProperty(name)) return (obj ? obj + '.' + name : name)
|
||||
return obj ? obj + '[' + JSON.stringify(name) + ']' : JSON.stringify(name)
|
||||
}
|
||||
|
||||
line.toString = function() {
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
line.toFunction = function(scope) {
|
||||
if (!scope) scope = {}
|
||||
|
||||
var src = 'return ('+line.toString()+')'
|
||||
|
||||
Object.keys(line.scope).forEach(function (key) {
|
||||
if (!scope[key]) scope[key] = line.scope[key]
|
||||
})
|
||||
|
||||
var keys = Object.keys(scope).map(function(key) {
|
||||
return key
|
||||
})
|
||||
|
||||
var vals = keys.map(function(key) {
|
||||
return scope[key]
|
||||
})
|
||||
|
||||
return Function.apply(null, keys.concat(src)).apply(null, vals)
|
||||
}
|
||||
|
||||
if (arguments.length) line.apply(null, arguments)
|
||||
|
||||
return line
|
||||
}
|
||||
|
||||
genfun.formats = formats
|
||||
module.exports = genfun
|
||||
32
node_modules/generate-function/package.json
generated
vendored
Normal file
32
node_modules/generate-function/package.json
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "generate-function",
|
||||
"version": "2.3.1",
|
||||
"description": "Module that helps you write generated functions in Node",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "tape test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mafintosh/generate-function"
|
||||
},
|
||||
"keywords": [
|
||||
"generate",
|
||||
"code",
|
||||
"generation",
|
||||
"function",
|
||||
"performance"
|
||||
],
|
||||
"author": "Mathias Buus",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/generate-function/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mafintosh/generate-function",
|
||||
"devDependencies": {
|
||||
"tape": "^4.9.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-property": "^1.0.2"
|
||||
}
|
||||
}
|
||||
49
node_modules/generate-function/test.js
generated
vendored
Normal file
49
node_modules/generate-function/test.js
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
var tape = require('tape')
|
||||
var genfun = require('./')
|
||||
|
||||
tape('generate add function', function(t) {
|
||||
var fn = genfun()
|
||||
('function add(n) {')
|
||||
('return n + %d', 42)
|
||||
('}')
|
||||
|
||||
t.same(fn.toString(), 'function add(n) {\n return n + 42\n}', 'code is indented')
|
||||
t.same(fn.toFunction()(10), 52, 'function works')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('generate function + closed variables', function(t) {
|
||||
var fn = genfun()
|
||||
('function add(n) {')
|
||||
('return n + %d + number', 42)
|
||||
('}')
|
||||
|
||||
var notGood = fn.toFunction()
|
||||
var good = fn.toFunction({number:10})
|
||||
|
||||
try {
|
||||
notGood(10)
|
||||
t.ok(false, 'function should not work')
|
||||
} catch (err) {
|
||||
t.same(err.message, 'number is not defined', 'throws reference error')
|
||||
}
|
||||
|
||||
t.same(good(11), 63, 'function with closed var works')
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('generate property', function(t) {
|
||||
var gen = genfun()
|
||||
|
||||
t.same(gen.property('a'), 'a')
|
||||
t.same(gen.property('42'), '"42"')
|
||||
t.same(gen.property('b', 'a'), 'b.a')
|
||||
t.same(gen.property('b', '42'), 'b["42"]')
|
||||
t.same(gen.sym(42), 'tmp')
|
||||
t.same(gen.sym('a'), 'a')
|
||||
t.same(gen.sym('a'), 'a1')
|
||||
t.same(gen.sym(42), 'tmp1')
|
||||
t.same(gen.sym('const'), 'tmp2')
|
||||
|
||||
t.end()
|
||||
})
|
||||
17
node_modules/is-property/.npmignore
generated
vendored
Normal file
17
node_modules/is-property/.npmignore
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
|
||||
pids
|
||||
logs
|
||||
results
|
||||
|
||||
npm-debug.log
|
||||
node_modules/*
|
||||
*.DS_Store
|
||||
test/*
|
||||
22
node_modules/is-property/LICENSE
generated
vendored
Normal file
22
node_modules/is-property/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Mikola Lysenko
|
||||
|
||||
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.
|
||||
28
node_modules/is-property/README.md
generated
vendored
Normal file
28
node_modules/is-property/README.md
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
is-property
|
||||
===========
|
||||
Tests if a property of a JavaScript object can be accessed using the dot (.) notation or if it must be enclosed in brackets, (ie use x[" ... "])
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
```javascript
|
||||
var isProperty = require("is-property")
|
||||
|
||||
console.log(isProperty("foo")) //Prints true
|
||||
console.log(isProperty("0")) //Prints false
|
||||
```
|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
npm install is-property
|
||||
|
||||
### `require("is-property")(str)`
|
||||
Checks if str is a property
|
||||
|
||||
* `str` is a string which we will test if it is a property or not
|
||||
|
||||
**Returns** true or false depending if str is a property
|
||||
|
||||
## Credits
|
||||
(c) 2013 Mikola Lysenko. MIT License
|
||||
5
node_modules/is-property/is-property.js
generated
vendored
Normal file
5
node_modules/is-property/is-property.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
36
node_modules/is-property/package.json
generated
vendored
Normal file
36
node_modules/is-property/package.json
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "is-property",
|
||||
"version": "1.0.2",
|
||||
"description": "Tests if a JSON property can be accessed using . syntax",
|
||||
"main": "is-property.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"tape": "~1.0.4"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mikolalysenko/is-property.git"
|
||||
},
|
||||
"keywords": [
|
||||
"is",
|
||||
"property",
|
||||
"json",
|
||||
"dot",
|
||||
"bracket",
|
||||
".",
|
||||
"[]"
|
||||
],
|
||||
"author": "Mikola Lysenko",
|
||||
"license": "MIT",
|
||||
"readmeFilename": "README.md",
|
||||
"gitHead": "0a85ea5b6b1264ea1cdecc6e5cf186adbb3ffc50",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mikolalysenko/is-property/issues"
|
||||
}
|
||||
}
|
||||
202
node_modules/long/LICENSE
generated
vendored
Normal file
202
node_modules/long/LICENSE
generated
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
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.
|
||||
286
node_modules/long/README.md
generated
vendored
Normal file
286
node_modules/long/README.md
generated
vendored
Normal file
@ -0,0 +1,286 @@
|
||||
# long.js
|
||||
|
||||
A Long class for representing a 64 bit two's-complement integer value derived from the [Closure Library](https://github.com/google/closure-library)
|
||||
for stand-alone use and extended with unsigned support.
|
||||
|
||||
[](https://github.com/dcodeIO/long.js/actions/workflows/test.yml) [](https://github.com/dcodeIO/long.js/actions/workflows/publish.yml) [](https://www.npmjs.com/package/long)
|
||||
|
||||
## Background
|
||||
|
||||
As of [ECMA-262 5th Edition](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), "all the positive and negative integers
|
||||
whose magnitude is no greater than 2<sup>53</sup> are representable in the Number type", which is "representing the
|
||||
doubleprecision 64-bit format IEEE 754 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic".
|
||||
The [maximum safe integer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
|
||||
in JavaScript is 2<sup>53</sup>-1.
|
||||
|
||||
Example: 2<sup>64</sup>-1 is 1844674407370955**1615** but in JavaScript it evaluates to 1844674407370955**2000**.
|
||||
|
||||
Furthermore, bitwise operators in JavaScript "deal only with integers in the range −2<sup>31</sup> through
|
||||
2<sup>31</sup>−1, inclusive, or in the range 0 through 2<sup>32</sup>−1, inclusive. These operators accept any value of
|
||||
the Number type but first convert each such value to one of 2<sup>32</sup> integer values."
|
||||
|
||||
In some use cases, however, it is required to be able to reliably work with and perform bitwise operations on the full
|
||||
64 bits. This is where long.js comes into play.
|
||||
|
||||
## Usage
|
||||
|
||||
The package exports an ECMAScript module with an UMD fallback.
|
||||
|
||||
```
|
||||
$> npm install long
|
||||
```
|
||||
|
||||
```js
|
||||
import Long from "long";
|
||||
|
||||
var value = new Long(0xFFFFFFFF, 0x7FFFFFFF);
|
||||
console.log(value.toString());
|
||||
...
|
||||
```
|
||||
|
||||
Note that mixing ESM and CommonJS is not recommended as it yields different classes, albeit with the same functionality.
|
||||
|
||||
### Usage with a CDN
|
||||
|
||||
- From GitHub via [jsDelivr](https://www.jsdelivr.com):<br />
|
||||
`https://cdn.jsdelivr.net/gh/dcodeIO/long.js@TAG/index.js` (ESM)
|
||||
- From npm via [jsDelivr](https://www.jsdelivr.com):<br />
|
||||
`https://cdn.jsdelivr.net/npm/long@VERSION/index.js` (ESM)<br />
|
||||
`https://cdn.jsdelivr.net/npm/long@VERSION/umd/index.js` (UMD)
|
||||
- From npm via [unpkg](https://unpkg.com):<br />
|
||||
`https://unpkg.com/long@VERSION/index.js` (ESM)<br />
|
||||
`https://unpkg.com/long@VERSION/umd/index.js` (UMD)
|
||||
|
||||
Replace `TAG` respectively `VERSION` with a [specific version](https://github.com/dcodeIO/long.js/releases) or omit it (not recommended in production) to use main/latest.
|
||||
|
||||
## API
|
||||
|
||||
### Constructor
|
||||
|
||||
- new **Long**(low: `number`, high?: `number`, unsigned?: `boolean`)<br />
|
||||
Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as _signed_ integers. See the from\* functions below for more convenient ways of constructing Longs.
|
||||
|
||||
### Fields
|
||||
|
||||
- Long#**low**: `number`<br />
|
||||
The low 32 bits as a signed value.
|
||||
|
||||
- Long#**high**: `number`<br />
|
||||
The high 32 bits as a signed value.
|
||||
|
||||
- Long#**unsigned**: `boolean`<br />
|
||||
Whether unsigned or not.
|
||||
|
||||
### Constants
|
||||
|
||||
- Long.**ZERO**: `Long`<br />
|
||||
Signed zero.
|
||||
|
||||
- Long.**ONE**: `Long`<br />
|
||||
Signed one.
|
||||
|
||||
- Long.**NEG_ONE**: `Long`<br />
|
||||
Signed negative one.
|
||||
|
||||
- Long.**UZERO**: `Long`<br />
|
||||
Unsigned zero.
|
||||
|
||||
- Long.**UONE**: `Long`<br />
|
||||
Unsigned one.
|
||||
|
||||
- Long.**MAX_VALUE**: `Long`<br />
|
||||
Maximum signed value.
|
||||
|
||||
- Long.**MIN_VALUE**: `Long`<br />
|
||||
Minimum signed value.
|
||||
|
||||
- Long.**MAX_UNSIGNED_VALUE**: `Long`<br />
|
||||
Maximum unsigned value.
|
||||
|
||||
### Utility
|
||||
|
||||
- type **LongLike**: `Long | number | bigint | string`<br />
|
||||
Any value or object that either is or can be converted to a Long.
|
||||
|
||||
- Long.**isLong**(obj: `any`): `boolean`<br />
|
||||
Tests if the specified object is a Long.
|
||||
|
||||
- Long.**fromBits**(lowBits: `number`, highBits: `number`, unsigned?: `boolean`): `Long`<br />
|
||||
Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits.
|
||||
|
||||
- Long.**fromBytes**(bytes: `number[]`, unsigned?: `boolean`, le?: `boolean`): `Long`<br />
|
||||
Creates a Long from its byte representation.
|
||||
|
||||
- Long.**fromBytesLE**(bytes: `number[]`, unsigned?: `boolean`): `Long`<br />
|
||||
Creates a Long from its little endian byte representation.
|
||||
|
||||
- Long.**fromBytesBE**(bytes: `number[]`, unsigned?: `boolean`): `Long`<br />
|
||||
Creates a Long from its big endian byte representation.
|
||||
|
||||
- Long.**fromInt**(value: `number`, unsigned?: `boolean`): `Long`<br />
|
||||
Returns a Long representing the given 32 bit integer value.
|
||||
|
||||
- Long.**fromNumber**(value: `number`, unsigned?: `boolean`): `Long`<br />
|
||||
Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
|
||||
|
||||
- Long.**fromBigInt**(value: `bigint`, unsigned?: `boolean`): `Long`<br />
|
||||
Returns a Long representing the given big integer.
|
||||
|
||||
- Long.**fromString**(str: `string`, unsigned?: `boolean`, radix?: `number`)<br />
|
||||
Long.**fromString**(str: `string`, radix: `number`)<br />
|
||||
Returns a Long representation of the given string, written using the specified radix.
|
||||
|
||||
- Long.**fromValue**(val: `LongLike`, unsigned?: `boolean`): `Long`<br />
|
||||
Converts the specified value to a Long using the appropriate from\* function for its type.
|
||||
|
||||
### Methods
|
||||
|
||||
- Long#**add**(addend: `LongLike`): `Long`<br />
|
||||
Returns the sum of this and the specified Long.
|
||||
|
||||
- Long#**and**(other: `LongLike`): `Long`<br />
|
||||
Returns the bitwise AND of this Long and the specified.
|
||||
|
||||
- Long#**compare**/**comp**(other: `LongLike`): `number`<br />
|
||||
Compares this Long's value with the specified's. Returns `0` if they are the same, `1` if the this is greater and `-1` if the given one is greater.
|
||||
|
||||
- Long#**divide**/**div**(divisor: `LongLike`): `Long`<br />
|
||||
Returns this Long divided by the specified.
|
||||
|
||||
- Long#**equals**/**eq**(other: `LongLike`): `boolean`<br />
|
||||
Tests if this Long's value equals the specified's.
|
||||
|
||||
- Long#**getHighBits**(): `number`<br />
|
||||
Gets the high 32 bits as a signed integer.
|
||||
|
||||
- Long#**getHighBitsUnsigned**(): `number`<br />
|
||||
Gets the high 32 bits as an unsigned integer.
|
||||
|
||||
- Long#**getLowBits**(): `number`<br />
|
||||
Gets the low 32 bits as a signed integer.
|
||||
|
||||
- Long#**getLowBitsUnsigned**(): `number`<br />
|
||||
Gets the low 32 bits as an unsigned integer.
|
||||
|
||||
- Long#**getNumBitsAbs**(): `number`<br />
|
||||
Gets the number of bits needed to represent the absolute value of this Long.
|
||||
|
||||
- Long#**greaterThan**/**gt**(other: `LongLike`): `boolean`<br />
|
||||
Tests if this Long's value is greater than the specified's.
|
||||
|
||||
- Long#**greaterThanOrEqual**/**gte**/**ge**(other: `LongLike`): `boolean`<br />
|
||||
Tests if this Long's value is greater than or equal the specified's.
|
||||
|
||||
- Long#**isEven**(): `boolean`<br />
|
||||
Tests if this Long's value is even.
|
||||
|
||||
- Long#**isNegative**(): `boolean`<br />
|
||||
Tests if this Long's value is negative.
|
||||
|
||||
- Long#**isOdd**(): `boolean`<br />
|
||||
Tests if this Long's value is odd.
|
||||
|
||||
- Long#**isPositive**(): `boolean`<br />
|
||||
Tests if this Long's value is positive or zero.
|
||||
|
||||
- Long#**isSafeInteger**(): `boolean`<br />
|
||||
Tests if this Long can be safely represented as a JavaScript number.
|
||||
|
||||
- Long#**isZero**/**eqz**(): `boolean`<br />
|
||||
Tests if this Long's value equals zero.
|
||||
|
||||
- Long#**lessThan**/**lt**(other: `LongLike`): `boolean`<br />
|
||||
Tests if this Long's value is less than the specified's.
|
||||
|
||||
- Long#**lessThanOrEqual**/**lte**/**le**(other: `LongLike`): `boolean`<br />
|
||||
Tests if this Long's value is less than or equal the specified's.
|
||||
|
||||
- Long#**modulo**/**mod**/**rem**(divisor: `LongLike`): `Long`<br />
|
||||
Returns this Long modulo the specified.
|
||||
|
||||
- Long#**multiply**/**mul**(multiplier: `LongLike`): `Long`<br />
|
||||
Returns the product of this and the specified Long.
|
||||
|
||||
- Long#**negate**/**neg**(): `Long`<br />
|
||||
Negates this Long's value.
|
||||
|
||||
- Long#**not**(): `Long`<br />
|
||||
Returns the bitwise NOT of this Long.
|
||||
|
||||
- Long#**countLeadingZeros**/**clz**(): `number`<br />
|
||||
Returns count leading zeros of this Long.
|
||||
|
||||
- Long#**countTrailingZeros**/**ctz**(): `number`<br />
|
||||
Returns count trailing zeros of this Long.
|
||||
|
||||
- Long#**notEquals**/**neq**/**ne**(other: `LongLike`): `boolean`<br />
|
||||
Tests if this Long's value differs from the specified's.
|
||||
|
||||
- Long#**or**(other: `LongLike`): `Long`<br />
|
||||
Returns the bitwise OR of this Long and the specified.
|
||||
|
||||
- Long#**shiftLeft**/**shl**(numBits: `Long | number`): `Long`<br />
|
||||
Returns this Long with bits shifted to the left by the given amount.
|
||||
|
||||
- Long#**shiftRight**/**shr**(numBits: `Long | number`): `Long`<br />
|
||||
Returns this Long with bits arithmetically shifted to the right by the given amount.
|
||||
|
||||
- Long#**shiftRightUnsigned**/**shru**/**shr_u**(numBits: `Long | number`): `Long`<br />
|
||||
Returns this Long with bits logically shifted to the right by the given amount.
|
||||
|
||||
- Long#**rotateLeft**/**rotl**(numBits: `Long | number`): `Long`<br />
|
||||
Returns this Long with bits rotated to the left by the given amount.
|
||||
|
||||
- Long#**rotateRight**/**rotr**(numBits: `Long | number`): `Long`<br />
|
||||
Returns this Long with bits rotated to the right by the given amount.
|
||||
|
||||
- Long#**subtract**/**sub**(subtrahend: `LongLike`): `Long`<br />
|
||||
Returns the difference of this and the specified Long.
|
||||
|
||||
- Long#**toBytes**(le?: `boolean`): `number[]`<br />
|
||||
Converts this Long to its byte representation.
|
||||
|
||||
- Long#**toBytesLE**(): `number[]`<br />
|
||||
Converts this Long to its little endian byte representation.
|
||||
|
||||
- Long#**toBytesBE**(): `number[]`<br />
|
||||
Converts this Long to its big endian byte representation.
|
||||
|
||||
- Long#**toInt**(): `number`<br />
|
||||
Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
|
||||
|
||||
- Long#**toNumber**(): `number`<br />
|
||||
Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
|
||||
|
||||
- Long#**toBigInt**(): `bigint`<br />
|
||||
Converts the Long to its big integer representation.
|
||||
|
||||
- Long#**toSigned**(): `Long`<br />
|
||||
Converts this Long to signed.
|
||||
|
||||
- Long#**toString**(radix?: `number`): `string`<br />
|
||||
Converts the Long to a string written in the specified radix.
|
||||
|
||||
- Long#**toUnsigned**(): `Long`<br />
|
||||
Converts this Long to unsigned.
|
||||
|
||||
- Long#**xor**(other: `Long | number | string`): `Long`<br />
|
||||
Returns the bitwise XOR of this Long and the given one.
|
||||
|
||||
## WebAssembly support
|
||||
|
||||
[WebAssembly](http://webassembly.org) supports 64-bit integer arithmetic out of the box, hence a [tiny WebAssembly module](./wasm.wat) is used to compute operations like multiplication, division and remainder more efficiently (slow operations like division are around twice as fast), falling back to floating point based computations in JavaScript where WebAssembly is not yet supported, e.g., in older versions of node.
|
||||
|
||||
## Building
|
||||
|
||||
Building the UMD fallback:
|
||||
|
||||
```
|
||||
$> npm run build
|
||||
```
|
||||
|
||||
Running the [tests](./tests):
|
||||
|
||||
```
|
||||
$> npm test
|
||||
```
|
||||
2
node_modules/long/index.d.ts
generated
vendored
Normal file
2
node_modules/long/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import { Long } from "./types.js";
|
||||
export default Long;
|
||||
1581
node_modules/long/index.js
generated
vendored
Normal file
1581
node_modules/long/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
58
node_modules/long/package.json
generated
vendored
Normal file
58
node_modules/long/package.json
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "long",
|
||||
"version": "5.3.2",
|
||||
"author": "Daniel Wirtz <dcode@dcode.io>",
|
||||
"description": "A Long class for representing a 64-bit two's-complement integer value.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dcodeIO/long.js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/dcodeIO/long.js/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"math",
|
||||
"long",
|
||||
"int64"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"main": "umd/index.js",
|
||||
"types": "umd/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./umd/index.d.ts",
|
||||
"default": "./umd/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node scripts/build.js",
|
||||
"lint": "prettier --check .",
|
||||
"format": "prettier --write .",
|
||||
"test": "npm run test:unit && npm run test:typescript",
|
||||
"test:unit": "node tests",
|
||||
"test:typescript": "tsc --project tests/typescript/tsconfig.esnext.json && tsc --project tests/typescript/tsconfig.nodenext.json && tsc --project tests/typescript/tsconfig.commonjs.json && tsc --project tests/typescript/tsconfig.global.json"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"types.d.ts",
|
||||
"umd/index.js",
|
||||
"umd/index.d.ts",
|
||||
"umd/types.d.ts",
|
||||
"umd/package.json",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"devDependencies": {
|
||||
"esm2umd": "^0.3.1",
|
||||
"prettier": "^3.5.0",
|
||||
"typescript": "^5.7.3"
|
||||
}
|
||||
}
|
||||
474
node_modules/long/types.d.ts
generated
vendored
Normal file
474
node_modules/long/types.d.ts
generated
vendored
Normal file
@ -0,0 +1,474 @@
|
||||
// Common type definitions for both the ESM and UMD variants. The ESM variant
|
||||
// reexports the Long class as its default export, whereas the UMD variant makes
|
||||
// the Long class a whole-module export with a global variable fallback.
|
||||
|
||||
type LongLike =
|
||||
| Long
|
||||
| number
|
||||
| bigint
|
||||
| string
|
||||
| { low: number; high: number; unsigned: boolean };
|
||||
|
||||
export declare class Long {
|
||||
/**
|
||||
* Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as signed integers. See the from* functions below for more convenient ways of constructing Longs.
|
||||
*/
|
||||
constructor(low: number, high?: number, unsigned?: boolean);
|
||||
|
||||
/**
|
||||
* Maximum unsigned value.
|
||||
*/
|
||||
static MAX_UNSIGNED_VALUE: Long;
|
||||
|
||||
/**
|
||||
* Maximum signed value.
|
||||
*/
|
||||
static MAX_VALUE: Long;
|
||||
|
||||
/**
|
||||
* Minimum signed value.
|
||||
*/
|
||||
static MIN_VALUE: Long;
|
||||
|
||||
/**
|
||||
* Signed negative one.
|
||||
*/
|
||||
static NEG_ONE: Long;
|
||||
|
||||
/**
|
||||
* Signed one.
|
||||
*/
|
||||
static ONE: Long;
|
||||
|
||||
/**
|
||||
* Unsigned one.
|
||||
*/
|
||||
static UONE: Long;
|
||||
|
||||
/**
|
||||
* Unsigned zero.
|
||||
*/
|
||||
static UZERO: Long;
|
||||
|
||||
/**
|
||||
* Signed zero
|
||||
*/
|
||||
static ZERO: Long;
|
||||
|
||||
/**
|
||||
* The high 32 bits as a signed value.
|
||||
*/
|
||||
high: number;
|
||||
|
||||
/**
|
||||
* The low 32 bits as a signed value.
|
||||
*/
|
||||
low: number;
|
||||
|
||||
/**
|
||||
* Whether unsigned or not.
|
||||
*/
|
||||
unsigned: boolean;
|
||||
|
||||
/**
|
||||
* Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits.
|
||||
*/
|
||||
static fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns a Long representing the given 32 bit integer value.
|
||||
*/
|
||||
static fromInt(value: number, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
|
||||
*/
|
||||
static fromNumber(value: number, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns a Long representing the given big integer value.
|
||||
*/
|
||||
static fromBigInt(value: bigint, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns a Long representation of the given string, written using the specified radix.
|
||||
*/
|
||||
static fromString(
|
||||
str: string,
|
||||
unsigned?: boolean | number,
|
||||
radix?: number,
|
||||
): Long;
|
||||
|
||||
/**
|
||||
* Creates a Long from its byte representation.
|
||||
*/
|
||||
static fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Creates a Long from its little endian byte representation.
|
||||
*/
|
||||
static fromBytesLE(bytes: number[], unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Creates a Long from its big endian byte representation.
|
||||
*/
|
||||
static fromBytesBE(bytes: number[], unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Tests if the specified object is a Long.
|
||||
*/
|
||||
static isLong(obj: any): obj is Long;
|
||||
|
||||
/**
|
||||
* Converts the specified value to a Long.
|
||||
*/
|
||||
static fromValue(val: LongLike, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns the sum of this and the specified Long.
|
||||
*/
|
||||
add(addend: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns the bitwise AND of this Long and the specified.
|
||||
*/
|
||||
and(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Compares this Long's value with the specified's.
|
||||
*/
|
||||
compare(other: LongLike): number;
|
||||
|
||||
/**
|
||||
* Compares this Long's value with the specified's.
|
||||
*/
|
||||
comp(other: LongLike): number;
|
||||
|
||||
/**
|
||||
* Returns this Long divided by the specified.
|
||||
*/
|
||||
divide(divisor: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long divided by the specified.
|
||||
*/
|
||||
div(divisor: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value equals the specified's.
|
||||
*/
|
||||
equals(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value equals the specified's.
|
||||
*/
|
||||
eq(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Gets the high 32 bits as a signed integer.
|
||||
*/
|
||||
getHighBits(): number;
|
||||
|
||||
/**
|
||||
* Gets the high 32 bits as an unsigned integer.
|
||||
*/
|
||||
getHighBitsUnsigned(): number;
|
||||
|
||||
/**
|
||||
* Gets the low 32 bits as a signed integer.
|
||||
*/
|
||||
getLowBits(): number;
|
||||
|
||||
/**
|
||||
* Gets the low 32 bits as an unsigned integer.
|
||||
*/
|
||||
getLowBitsUnsigned(): number;
|
||||
|
||||
/**
|
||||
* Gets the number of bits needed to represent the absolute value of this Long.
|
||||
*/
|
||||
getNumBitsAbs(): number;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than the specified's.
|
||||
*/
|
||||
greaterThan(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than the specified's.
|
||||
*/
|
||||
gt(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than or equal the specified's.
|
||||
*/
|
||||
greaterThanOrEqual(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than or equal the specified's.
|
||||
*/
|
||||
gte(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than or equal the specified's.
|
||||
*/
|
||||
ge(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is even.
|
||||
*/
|
||||
isEven(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is negative.
|
||||
*/
|
||||
isNegative(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is odd.
|
||||
*/
|
||||
isOdd(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is positive or zero.
|
||||
*/
|
||||
isPositive(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long can be safely represented as a JavaScript number.
|
||||
*/
|
||||
isSafeInteger(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value equals zero.
|
||||
*/
|
||||
isZero(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value equals zero.
|
||||
*/
|
||||
eqz(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than the specified's.
|
||||
*/
|
||||
lessThan(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than the specified's.
|
||||
*/
|
||||
lt(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than or equal the specified's.
|
||||
*/
|
||||
lessThanOrEqual(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than or equal the specified's.
|
||||
*/
|
||||
lte(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than or equal the specified's.
|
||||
*/
|
||||
le(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Returns this Long modulo the specified.
|
||||
*/
|
||||
modulo(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long modulo the specified.
|
||||
*/
|
||||
mod(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long modulo the specified.
|
||||
*/
|
||||
rem(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns the product of this and the specified Long.
|
||||
*/
|
||||
multiply(multiplier: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns the product of this and the specified Long.
|
||||
*/
|
||||
mul(multiplier: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Negates this Long's value.
|
||||
*/
|
||||
negate(): Long;
|
||||
|
||||
/**
|
||||
* Negates this Long's value.
|
||||
*/
|
||||
neg(): Long;
|
||||
|
||||
/**
|
||||
* Returns the bitwise NOT of this Long.
|
||||
*/
|
||||
not(): Long;
|
||||
|
||||
/**
|
||||
* Returns count leading zeros of this Long.
|
||||
*/
|
||||
countLeadingZeros(): number;
|
||||
|
||||
/**
|
||||
* Returns count leading zeros of this Long.
|
||||
*/
|
||||
clz(): number;
|
||||
|
||||
/**
|
||||
* Returns count trailing zeros of this Long.
|
||||
*/
|
||||
countTrailingZeros(): number;
|
||||
|
||||
/**
|
||||
* Returns count trailing zeros of this Long.
|
||||
*/
|
||||
ctz(): number;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value differs from the specified's.
|
||||
*/
|
||||
notEquals(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value differs from the specified's.
|
||||
*/
|
||||
neq(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value differs from the specified's.
|
||||
*/
|
||||
ne(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Returns the bitwise OR of this Long and the specified.
|
||||
*/
|
||||
or(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits shifted to the left by the given amount.
|
||||
*/
|
||||
shiftLeft(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits shifted to the left by the given amount.
|
||||
*/
|
||||
shl(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits arithmetically shifted to the right by the given amount.
|
||||
*/
|
||||
shiftRight(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits arithmetically shifted to the right by the given amount.
|
||||
*/
|
||||
shr(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits logically shifted to the right by the given amount.
|
||||
*/
|
||||
shiftRightUnsigned(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits logically shifted to the right by the given amount.
|
||||
*/
|
||||
shru(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits logically shifted to the right by the given amount.
|
||||
*/
|
||||
shr_u(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits rotated to the left by the given amount.
|
||||
*/
|
||||
rotateLeft(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits rotated to the left by the given amount.
|
||||
*/
|
||||
rotl(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits rotated to the right by the given amount.
|
||||
*/
|
||||
rotateRight(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits rotated to the right by the given amount.
|
||||
*/
|
||||
rotr(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns the difference of this and the specified Long.
|
||||
*/
|
||||
subtract(subtrahend: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns the difference of this and the specified Long.
|
||||
*/
|
||||
sub(subtrahend: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Converts the Long to a big integer.
|
||||
*/
|
||||
toBigInt(): bigint;
|
||||
|
||||
/**
|
||||
* Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
|
||||
*/
|
||||
toInt(): number;
|
||||
|
||||
/**
|
||||
* Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
|
||||
*/
|
||||
toNumber(): number;
|
||||
|
||||
/**
|
||||
* Converts this Long to its byte representation.
|
||||
*/
|
||||
|
||||
toBytes(le?: boolean): number[];
|
||||
|
||||
/**
|
||||
* Converts this Long to its little endian byte representation.
|
||||
*/
|
||||
|
||||
toBytesLE(): number[];
|
||||
|
||||
/**
|
||||
* Converts this Long to its big endian byte representation.
|
||||
*/
|
||||
|
||||
toBytesBE(): number[];
|
||||
|
||||
/**
|
||||
* Converts this Long to signed.
|
||||
*/
|
||||
toSigned(): Long;
|
||||
|
||||
/**
|
||||
* Converts the Long to a string written in the specified radix.
|
||||
*/
|
||||
toString(radix?: number): string;
|
||||
|
||||
/**
|
||||
* Converts this Long to unsigned.
|
||||
*/
|
||||
toUnsigned(): Long;
|
||||
|
||||
/**
|
||||
* Returns the bitwise XOR of this Long and the given one.
|
||||
*/
|
||||
xor(other: LongLike): Long;
|
||||
}
|
||||
3
node_modules/long/umd/index.d.ts
generated
vendored
Normal file
3
node_modules/long/umd/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { Long } from "./types.js";
|
||||
export = Long;
|
||||
export as namespace Long;
|
||||
1622
node_modules/long/umd/index.js
generated
vendored
Normal file
1622
node_modules/long/umd/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
node_modules/long/umd/package.json
generated
vendored
Normal file
3
node_modules/long/umd/package.json
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
474
node_modules/long/umd/types.d.ts
generated
vendored
Normal file
474
node_modules/long/umd/types.d.ts
generated
vendored
Normal file
@ -0,0 +1,474 @@
|
||||
// Common type definitions for both the ESM and UMD variants. The ESM variant
|
||||
// reexports the Long class as its default export, whereas the UMD variant makes
|
||||
// the Long class a whole-module export with a global variable fallback.
|
||||
|
||||
type LongLike =
|
||||
| Long
|
||||
| number
|
||||
| bigint
|
||||
| string
|
||||
| { low: number; high: number; unsigned: boolean };
|
||||
|
||||
export declare class Long {
|
||||
/**
|
||||
* Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as signed integers. See the from* functions below for more convenient ways of constructing Longs.
|
||||
*/
|
||||
constructor(low: number, high?: number, unsigned?: boolean);
|
||||
|
||||
/**
|
||||
* Maximum unsigned value.
|
||||
*/
|
||||
static MAX_UNSIGNED_VALUE: Long;
|
||||
|
||||
/**
|
||||
* Maximum signed value.
|
||||
*/
|
||||
static MAX_VALUE: Long;
|
||||
|
||||
/**
|
||||
* Minimum signed value.
|
||||
*/
|
||||
static MIN_VALUE: Long;
|
||||
|
||||
/**
|
||||
* Signed negative one.
|
||||
*/
|
||||
static NEG_ONE: Long;
|
||||
|
||||
/**
|
||||
* Signed one.
|
||||
*/
|
||||
static ONE: Long;
|
||||
|
||||
/**
|
||||
* Unsigned one.
|
||||
*/
|
||||
static UONE: Long;
|
||||
|
||||
/**
|
||||
* Unsigned zero.
|
||||
*/
|
||||
static UZERO: Long;
|
||||
|
||||
/**
|
||||
* Signed zero
|
||||
*/
|
||||
static ZERO: Long;
|
||||
|
||||
/**
|
||||
* The high 32 bits as a signed value.
|
||||
*/
|
||||
high: number;
|
||||
|
||||
/**
|
||||
* The low 32 bits as a signed value.
|
||||
*/
|
||||
low: number;
|
||||
|
||||
/**
|
||||
* Whether unsigned or not.
|
||||
*/
|
||||
unsigned: boolean;
|
||||
|
||||
/**
|
||||
* Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits.
|
||||
*/
|
||||
static fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns a Long representing the given 32 bit integer value.
|
||||
*/
|
||||
static fromInt(value: number, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
|
||||
*/
|
||||
static fromNumber(value: number, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns a Long representing the given big integer value.
|
||||
*/
|
||||
static fromBigInt(value: bigint, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns a Long representation of the given string, written using the specified radix.
|
||||
*/
|
||||
static fromString(
|
||||
str: string,
|
||||
unsigned?: boolean | number,
|
||||
radix?: number,
|
||||
): Long;
|
||||
|
||||
/**
|
||||
* Creates a Long from its byte representation.
|
||||
*/
|
||||
static fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Creates a Long from its little endian byte representation.
|
||||
*/
|
||||
static fromBytesLE(bytes: number[], unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Creates a Long from its big endian byte representation.
|
||||
*/
|
||||
static fromBytesBE(bytes: number[], unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Tests if the specified object is a Long.
|
||||
*/
|
||||
static isLong(obj: any): obj is Long;
|
||||
|
||||
/**
|
||||
* Converts the specified value to a Long.
|
||||
*/
|
||||
static fromValue(val: LongLike, unsigned?: boolean): Long;
|
||||
|
||||
/**
|
||||
* Returns the sum of this and the specified Long.
|
||||
*/
|
||||
add(addend: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns the bitwise AND of this Long and the specified.
|
||||
*/
|
||||
and(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Compares this Long's value with the specified's.
|
||||
*/
|
||||
compare(other: LongLike): number;
|
||||
|
||||
/**
|
||||
* Compares this Long's value with the specified's.
|
||||
*/
|
||||
comp(other: LongLike): number;
|
||||
|
||||
/**
|
||||
* Returns this Long divided by the specified.
|
||||
*/
|
||||
divide(divisor: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long divided by the specified.
|
||||
*/
|
||||
div(divisor: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value equals the specified's.
|
||||
*/
|
||||
equals(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value equals the specified's.
|
||||
*/
|
||||
eq(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Gets the high 32 bits as a signed integer.
|
||||
*/
|
||||
getHighBits(): number;
|
||||
|
||||
/**
|
||||
* Gets the high 32 bits as an unsigned integer.
|
||||
*/
|
||||
getHighBitsUnsigned(): number;
|
||||
|
||||
/**
|
||||
* Gets the low 32 bits as a signed integer.
|
||||
*/
|
||||
getLowBits(): number;
|
||||
|
||||
/**
|
||||
* Gets the low 32 bits as an unsigned integer.
|
||||
*/
|
||||
getLowBitsUnsigned(): number;
|
||||
|
||||
/**
|
||||
* Gets the number of bits needed to represent the absolute value of this Long.
|
||||
*/
|
||||
getNumBitsAbs(): number;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than the specified's.
|
||||
*/
|
||||
greaterThan(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than the specified's.
|
||||
*/
|
||||
gt(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than or equal the specified's.
|
||||
*/
|
||||
greaterThanOrEqual(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than or equal the specified's.
|
||||
*/
|
||||
gte(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is greater than or equal the specified's.
|
||||
*/
|
||||
ge(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is even.
|
||||
*/
|
||||
isEven(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is negative.
|
||||
*/
|
||||
isNegative(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is odd.
|
||||
*/
|
||||
isOdd(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is positive or zero.
|
||||
*/
|
||||
isPositive(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long can be safely represented as a JavaScript number.
|
||||
*/
|
||||
isSafeInteger(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value equals zero.
|
||||
*/
|
||||
isZero(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value equals zero.
|
||||
*/
|
||||
eqz(): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than the specified's.
|
||||
*/
|
||||
lessThan(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than the specified's.
|
||||
*/
|
||||
lt(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than or equal the specified's.
|
||||
*/
|
||||
lessThanOrEqual(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than or equal the specified's.
|
||||
*/
|
||||
lte(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value is less than or equal the specified's.
|
||||
*/
|
||||
le(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Returns this Long modulo the specified.
|
||||
*/
|
||||
modulo(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long modulo the specified.
|
||||
*/
|
||||
mod(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long modulo the specified.
|
||||
*/
|
||||
rem(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns the product of this and the specified Long.
|
||||
*/
|
||||
multiply(multiplier: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns the product of this and the specified Long.
|
||||
*/
|
||||
mul(multiplier: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Negates this Long's value.
|
||||
*/
|
||||
negate(): Long;
|
||||
|
||||
/**
|
||||
* Negates this Long's value.
|
||||
*/
|
||||
neg(): Long;
|
||||
|
||||
/**
|
||||
* Returns the bitwise NOT of this Long.
|
||||
*/
|
||||
not(): Long;
|
||||
|
||||
/**
|
||||
* Returns count leading zeros of this Long.
|
||||
*/
|
||||
countLeadingZeros(): number;
|
||||
|
||||
/**
|
||||
* Returns count leading zeros of this Long.
|
||||
*/
|
||||
clz(): number;
|
||||
|
||||
/**
|
||||
* Returns count trailing zeros of this Long.
|
||||
*/
|
||||
countTrailingZeros(): number;
|
||||
|
||||
/**
|
||||
* Returns count trailing zeros of this Long.
|
||||
*/
|
||||
ctz(): number;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value differs from the specified's.
|
||||
*/
|
||||
notEquals(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value differs from the specified's.
|
||||
*/
|
||||
neq(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Tests if this Long's value differs from the specified's.
|
||||
*/
|
||||
ne(other: LongLike): boolean;
|
||||
|
||||
/**
|
||||
* Returns the bitwise OR of this Long and the specified.
|
||||
*/
|
||||
or(other: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits shifted to the left by the given amount.
|
||||
*/
|
||||
shiftLeft(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits shifted to the left by the given amount.
|
||||
*/
|
||||
shl(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits arithmetically shifted to the right by the given amount.
|
||||
*/
|
||||
shiftRight(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits arithmetically shifted to the right by the given amount.
|
||||
*/
|
||||
shr(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits logically shifted to the right by the given amount.
|
||||
*/
|
||||
shiftRightUnsigned(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits logically shifted to the right by the given amount.
|
||||
*/
|
||||
shru(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits logically shifted to the right by the given amount.
|
||||
*/
|
||||
shr_u(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits rotated to the left by the given amount.
|
||||
*/
|
||||
rotateLeft(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits rotated to the left by the given amount.
|
||||
*/
|
||||
rotl(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits rotated to the right by the given amount.
|
||||
*/
|
||||
rotateRight(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns this Long with bits rotated to the right by the given amount.
|
||||
*/
|
||||
rotr(numBits: number | Long): Long;
|
||||
|
||||
/**
|
||||
* Returns the difference of this and the specified Long.
|
||||
*/
|
||||
subtract(subtrahend: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Returns the difference of this and the specified Long.
|
||||
*/
|
||||
sub(subtrahend: LongLike): Long;
|
||||
|
||||
/**
|
||||
* Converts the Long to a big integer.
|
||||
*/
|
||||
toBigInt(): bigint;
|
||||
|
||||
/**
|
||||
* Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
|
||||
*/
|
||||
toInt(): number;
|
||||
|
||||
/**
|
||||
* Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
|
||||
*/
|
||||
toNumber(): number;
|
||||
|
||||
/**
|
||||
* Converts this Long to its byte representation.
|
||||
*/
|
||||
|
||||
toBytes(le?: boolean): number[];
|
||||
|
||||
/**
|
||||
* Converts this Long to its little endian byte representation.
|
||||
*/
|
||||
|
||||
toBytesLE(): number[];
|
||||
|
||||
/**
|
||||
* Converts this Long to its big endian byte representation.
|
||||
*/
|
||||
|
||||
toBytesBE(): number[];
|
||||
|
||||
/**
|
||||
* Converts this Long to signed.
|
||||
*/
|
||||
toSigned(): Long;
|
||||
|
||||
/**
|
||||
* Converts the Long to a string written in the specified radix.
|
||||
*/
|
||||
toString(radix?: number): string;
|
||||
|
||||
/**
|
||||
* Converts this Long to unsigned.
|
||||
*/
|
||||
toUnsigned(): Long;
|
||||
|
||||
/**
|
||||
* Returns the bitwise XOR of this Long and the given one.
|
||||
*/
|
||||
xor(other: LongLike): Long;
|
||||
}
|
||||
15
node_modules/lru-cache/LICENSE
generated
vendored
Normal file
15
node_modules/lru-cache/LICENSE
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) 2010-2023 Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
1117
node_modules/lru-cache/README.md
generated
vendored
Normal file
1117
node_modules/lru-cache/README.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
869
node_modules/lru-cache/index.d.ts
generated
vendored
Normal file
869
node_modules/lru-cache/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,869 @@
|
||||
// Project: https://github.com/isaacs/node-lru-cache
|
||||
// Based initially on @types/lru-cache
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// used under the terms of the MIT License, shown below.
|
||||
//
|
||||
// DefinitelyTyped license:
|
||||
// ------
|
||||
// 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
|
||||
// ------
|
||||
//
|
||||
// Changes by Isaac Z. Schlueter released under the terms found in the
|
||||
// LICENSE file within this project.
|
||||
|
||||
/**
|
||||
* Integer greater than 0, representing some number of milliseconds, or the
|
||||
* time at which a TTL started counting from.
|
||||
*/
|
||||
declare type LRUMilliseconds = number
|
||||
|
||||
/**
|
||||
* An integer greater than 0, reflecting the calculated size of items
|
||||
*/
|
||||
declare type LRUSize = number
|
||||
|
||||
/**
|
||||
* An integer greater than 0, reflecting a number of items
|
||||
*/
|
||||
declare type LRUCount = number
|
||||
|
||||
declare class LRUCache<K, V> implements Iterable<[K, V]> {
|
||||
constructor(options: LRUCache.Options<K, V>)
|
||||
|
||||
/**
|
||||
* Number of items in the cache.
|
||||
* Alias for {@link size}
|
||||
*
|
||||
* @deprecated since 7.0 use {@link size} instead
|
||||
*/
|
||||
public readonly length: LRUCount
|
||||
|
||||
public readonly max: LRUCount
|
||||
public readonly maxSize: LRUSize
|
||||
public readonly maxEntrySize: LRUSize
|
||||
public readonly sizeCalculation:
|
||||
| LRUCache.SizeCalculator<K, V>
|
||||
| undefined
|
||||
public readonly dispose: LRUCache.Disposer<K, V>
|
||||
/**
|
||||
* @since 7.4.0
|
||||
*/
|
||||
public readonly disposeAfter: LRUCache.Disposer<K, V> | null
|
||||
public readonly noDisposeOnSet: boolean
|
||||
public readonly ttl: LRUMilliseconds
|
||||
public readonly ttlResolution: LRUMilliseconds
|
||||
public readonly ttlAutopurge: boolean
|
||||
public readonly allowStale: boolean
|
||||
public readonly updateAgeOnGet: boolean
|
||||
/**
|
||||
* @since 7.11.0
|
||||
*/
|
||||
public readonly noDeleteOnStaleGet: boolean
|
||||
/**
|
||||
* @since 7.6.0
|
||||
*/
|
||||
public readonly fetchMethod: LRUCache.Fetcher<K, V> | null
|
||||
|
||||
/**
|
||||
* The total number of items held in the cache at the current moment.
|
||||
*/
|
||||
public readonly size: LRUCount
|
||||
|
||||
/**
|
||||
* The total size of items in cache when using size tracking.
|
||||
*/
|
||||
public readonly calculatedSize: LRUSize
|
||||
|
||||
/**
|
||||
* Add a value to the cache.
|
||||
*/
|
||||
public set(
|
||||
key: K,
|
||||
value: V,
|
||||
options?: LRUCache.SetOptions<K, V>
|
||||
): this
|
||||
|
||||
/**
|
||||
* Return a value from the cache. Will update the recency of the cache entry
|
||||
* found.
|
||||
*
|
||||
* If the key is not found, {@link get} will return `undefined`. This can be
|
||||
* confusing when setting values specifically to `undefined`, as in
|
||||
* `cache.set(key, undefined)`. Use {@link has} to determine whether a key is
|
||||
* present in the cache at all.
|
||||
*/
|
||||
public get(key: K, options?: LRUCache.GetOptions<V>): V | undefined
|
||||
|
||||
/**
|
||||
* Like {@link get} but doesn't update recency or delete stale items.
|
||||
* Returns `undefined` if the item is stale, unless {@link allowStale} is set
|
||||
* either on the cache or in the options object.
|
||||
*/
|
||||
public peek(key: K, options?: LRUCache.PeekOptions): V | undefined
|
||||
|
||||
/**
|
||||
* Check if a key is in the cache, without updating the recency of use.
|
||||
* Will return false if the item is stale, even though it is technically
|
||||
* in the cache.
|
||||
*
|
||||
* Will not update item age unless {@link updateAgeOnHas} is set in the
|
||||
* options or constructor.
|
||||
*/
|
||||
public has(key: K, options?: LRUCache.HasOptions<V>): boolean
|
||||
|
||||
/**
|
||||
* Deletes a key out of the cache.
|
||||
* Returns true if the key was deleted, false otherwise.
|
||||
*/
|
||||
public delete(key: K): boolean
|
||||
|
||||
/**
|
||||
* Clear the cache entirely, throwing away all values.
|
||||
*/
|
||||
public clear(): void
|
||||
|
||||
/**
|
||||
* Delete any stale entries. Returns true if anything was removed, false
|
||||
* otherwise.
|
||||
*/
|
||||
public purgeStale(): boolean
|
||||
|
||||
/**
|
||||
* Find a value for which the supplied fn method returns a truthy value,
|
||||
* similar to Array.find(). fn is called as fn(value, key, cache).
|
||||
*/
|
||||
public find(
|
||||
callbackFn: (
|
||||
value: V,
|
||||
key: K,
|
||||
cache: this
|
||||
) => boolean | undefined | void,
|
||||
options?: LRUCache.GetOptions<V>
|
||||
): V | undefined
|
||||
|
||||
/**
|
||||
* Call the supplied function on each item in the cache, in order from
|
||||
* most recently used to least recently used. fn is called as
|
||||
* fn(value, key, cache). Does not update age or recenty of use.
|
||||
*/
|
||||
public forEach<T = this>(
|
||||
callbackFn: (this: T, value: V, key: K, cache: this) => void,
|
||||
thisArg?: T
|
||||
): void
|
||||
|
||||
/**
|
||||
* The same as {@link forEach} but items are iterated over in reverse
|
||||
* order. (ie, less recently used items are iterated over first.)
|
||||
*/
|
||||
public rforEach<T = this>(
|
||||
callbackFn: (this: T, value: V, key: K, cache: this) => void,
|
||||
thisArg?: T
|
||||
): void
|
||||
|
||||
/**
|
||||
* Return a generator yielding the keys in the cache,
|
||||
* in order from most recently used to least recently used.
|
||||
*/
|
||||
public keys(): Generator<K, void, void>
|
||||
|
||||
/**
|
||||
* Inverse order version of {@link keys}
|
||||
*
|
||||
* Return a generator yielding the keys in the cache,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
public rkeys(): Generator<K, void, void>
|
||||
|
||||
/**
|
||||
* Return a generator yielding the values in the cache,
|
||||
* in order from most recently used to least recently used.
|
||||
*/
|
||||
public values(): Generator<V, void, void>
|
||||
|
||||
/**
|
||||
* Inverse order version of {@link values}
|
||||
*
|
||||
* Return a generator yielding the values in the cache,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
public rvalues(): Generator<V, void, void>
|
||||
|
||||
/**
|
||||
* Return a generator yielding `[key, value]` pairs,
|
||||
* in order from most recently used to least recently used.
|
||||
*/
|
||||
public entries(): Generator<[K, V], void, void>
|
||||
|
||||
/**
|
||||
* Inverse order version of {@link entries}
|
||||
*
|
||||
* Return a generator yielding `[key, value]` pairs,
|
||||
* in order from least recently used to most recently used.
|
||||
*/
|
||||
public rentries(): Generator<[K, V], void, void>
|
||||
|
||||
/**
|
||||
* Iterating over the cache itself yields the same results as
|
||||
* {@link entries}
|
||||
*/
|
||||
public [Symbol.iterator](): Generator<[K, V], void, void>
|
||||
|
||||
/**
|
||||
* Return an array of [key, entry] objects which can be passed to
|
||||
* cache.load()
|
||||
*/
|
||||
public dump(): Array<[K, LRUCache.Entry<V>]>
|
||||
|
||||
/**
|
||||
* Reset the cache and load in the items in entries in the order listed.
|
||||
* Note that the shape of the resulting cache may be different if the
|
||||
* same options are not used in both caches.
|
||||
*/
|
||||
public load(
|
||||
cacheEntries: ReadonlyArray<[K, LRUCache.Entry<V>]>
|
||||
): void
|
||||
|
||||
/**
|
||||
* Evict the least recently used item, returning its value or `undefined`
|
||||
* if cache is empty.
|
||||
*/
|
||||
public pop(): V | undefined
|
||||
|
||||
/**
|
||||
* Deletes a key out of the cache.
|
||||
*
|
||||
* @deprecated since 7.0 use delete() instead
|
||||
*/
|
||||
public del(key: K): boolean
|
||||
|
||||
/**
|
||||
* Clear the cache entirely, throwing away all values.
|
||||
*
|
||||
* @deprecated since 7.0 use clear() instead
|
||||
*/
|
||||
public reset(): void
|
||||
|
||||
/**
|
||||
* Manually iterates over the entire cache proactively pruning old entries.
|
||||
*
|
||||
* @deprecated since 7.0 use purgeStale() instead
|
||||
*/
|
||||
public prune(): boolean
|
||||
|
||||
/**
|
||||
* Make an asynchronous cached fetch using the {@link fetchMethod} function.
|
||||
*
|
||||
* If multiple fetches for the same key are issued, then they will all be
|
||||
* coalesced into a single call to fetchMethod.
|
||||
*
|
||||
* Note that this means that handling options such as
|
||||
* {@link allowStaleOnFetchAbort}, {@link signal}, and
|
||||
* {@link allowStaleOnFetchRejection} will be determined by the FIRST fetch()
|
||||
* call for a given key.
|
||||
*
|
||||
* This is a known (fixable) shortcoming which will be addresed on when
|
||||
* someone complains about it, as the fix would involve added complexity and
|
||||
* may not be worth the costs for this edge case.
|
||||
*
|
||||
* since: 7.6.0
|
||||
*/
|
||||
public fetch(
|
||||
key: K,
|
||||
options?: LRUCache.FetchOptions<K, V>
|
||||
): Promise<V>
|
||||
|
||||
/**
|
||||
* since: 7.6.0
|
||||
*/
|
||||
public getRemainingTTL(key: K): LRUMilliseconds
|
||||
}
|
||||
|
||||
declare namespace LRUCache {
|
||||
type DisposeReason = 'evict' | 'set' | 'delete'
|
||||
|
||||
type SizeCalculator<K, V> = (value: V, key: K) => LRUSize
|
||||
type Disposer<K, V> = (
|
||||
value: V,
|
||||
key: K,
|
||||
reason: DisposeReason
|
||||
) => void
|
||||
type Fetcher<K, V> = (
|
||||
key: K,
|
||||
staleValue: V | undefined,
|
||||
options: FetcherOptions<K, V>
|
||||
) => Promise<V | void | undefined> | V | void | undefined
|
||||
|
||||
interface DeprecatedOptions<K, V> {
|
||||
/**
|
||||
* alias for ttl
|
||||
*
|
||||
* @deprecated since 7.0 use options.ttl instead
|
||||
*/
|
||||
maxAge?: LRUMilliseconds
|
||||
|
||||
/**
|
||||
* alias for {@link sizeCalculation}
|
||||
*
|
||||
* @deprecated since 7.0 use {@link sizeCalculation} instead
|
||||
*/
|
||||
length?: SizeCalculator<K, V>
|
||||
|
||||
/**
|
||||
* alias for allowStale
|
||||
*
|
||||
* @deprecated since 7.0 use options.allowStale instead
|
||||
*/
|
||||
stale?: boolean
|
||||
}
|
||||
|
||||
interface LimitedByCount {
|
||||
/**
|
||||
* The number of most recently used items to keep.
|
||||
* Note that we may store fewer items than this if maxSize is hit.
|
||||
*/
|
||||
max: LRUCount
|
||||
}
|
||||
|
||||
type MaybeMaxEntrySizeLimit<K, V> =
|
||||
| {
|
||||
/**
|
||||
* The maximum allowed size for any single item in the cache.
|
||||
*
|
||||
* If a larger item is passed to {@link set} or returned by a
|
||||
* {@link fetchMethod}, then it will not be stored in the cache.
|
||||
*/
|
||||
maxEntrySize: LRUSize
|
||||
sizeCalculation?: SizeCalculator<K, V>
|
||||
}
|
||||
| {}
|
||||
|
||||
interface LimitedBySize<K, V> {
|
||||
/**
|
||||
* If you wish to track item size, you must provide a maxSize
|
||||
* note that we still will only keep up to max *actual items*,
|
||||
* if max is set, so size tracking may cause fewer than max items
|
||||
* to be stored. At the extreme, a single item of maxSize size
|
||||
* will cause everything else in the cache to be dropped when it
|
||||
* is added. Use with caution!
|
||||
*
|
||||
* Note also that size tracking can negatively impact performance,
|
||||
* though for most cases, only minimally.
|
||||
*/
|
||||
maxSize: LRUSize
|
||||
|
||||
/**
|
||||
* Function to calculate size of items. Useful if storing strings or
|
||||
* buffers or other items where memory size depends on the object itself.
|
||||
*
|
||||
* Items larger than {@link maxEntrySize} will not be stored in the cache.
|
||||
*
|
||||
* Note that when {@link maxSize} or {@link maxEntrySize} are set, every
|
||||
* item added MUST have a size specified, either via a `sizeCalculation` in
|
||||
* the constructor, or `sizeCalculation` or {@link size} options to
|
||||
* {@link set}.
|
||||
*/
|
||||
sizeCalculation?: SizeCalculator<K, V>
|
||||
}
|
||||
|
||||
interface LimitedByTTL {
|
||||
/**
|
||||
* Max time in milliseconds for items to live in cache before they are
|
||||
* considered stale. Note that stale items are NOT preemptively removed
|
||||
* by default, and MAY live in the cache, contributing to its LRU max,
|
||||
* long after they have expired.
|
||||
*
|
||||
* Also, as this cache is optimized for LRU/MRU operations, some of
|
||||
* the staleness/TTL checks will reduce performance, as they will incur
|
||||
* overhead by deleting items.
|
||||
*
|
||||
* Must be an integer number of ms, defaults to 0, which means "no TTL"
|
||||
*/
|
||||
ttl: LRUMilliseconds
|
||||
|
||||
/**
|
||||
* Boolean flag to tell the cache to not update the TTL when
|
||||
* setting a new value for an existing key (ie, when updating a value
|
||||
* rather than inserting a new value). Note that the TTL value is
|
||||
* _always_ set (if provided) when adding a new entry into the cache.
|
||||
*
|
||||
* @default false
|
||||
* @since 7.4.0
|
||||
*/
|
||||
noUpdateTTL?: boolean
|
||||
|
||||
/**
|
||||
* Minimum amount of time in ms in which to check for staleness.
|
||||
* Defaults to 1, which means that the current time is checked
|
||||
* at most once per millisecond.
|
||||
*
|
||||
* Set to 0 to check the current time every time staleness is tested.
|
||||
* (This reduces performance, and is theoretically unnecessary.)
|
||||
*
|
||||
* Setting this to a higher value will improve performance somewhat
|
||||
* while using ttl tracking, albeit at the expense of keeping stale
|
||||
* items around a bit longer than their TTLs would indicate.
|
||||
*
|
||||
* @default 1
|
||||
* @since 7.1.0
|
||||
*/
|
||||
ttlResolution?: LRUMilliseconds
|
||||
|
||||
/**
|
||||
* Preemptively remove stale items from the cache.
|
||||
* Note that this may significantly degrade performance,
|
||||
* especially if the cache is storing a large number of items.
|
||||
* It is almost always best to just leave the stale items in
|
||||
* the cache, and let them fall out as new items are added.
|
||||
*
|
||||
* Note that this means that {@link allowStale} is a bit pointless,
|
||||
* as stale items will be deleted almost as soon as they expire.
|
||||
*
|
||||
* Use with caution!
|
||||
*
|
||||
* @default false
|
||||
* @since 7.1.0
|
||||
*/
|
||||
ttlAutopurge?: boolean
|
||||
|
||||
/**
|
||||
* Return stale items from {@link get} before disposing of them.
|
||||
* Return stale values from {@link fetch} while performing a call
|
||||
* to the {@link fetchMethod} in the background.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
allowStale?: boolean
|
||||
|
||||
/**
|
||||
* Update the age of items on {@link get}, renewing their TTL
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
updateAgeOnGet?: boolean
|
||||
|
||||
/**
|
||||
* Do not delete stale items when they are retrieved with {@link get}.
|
||||
* Note that the {@link get} return value will still be `undefined` unless
|
||||
* allowStale is true.
|
||||
*
|
||||
* @default false
|
||||
* @since 7.11.0
|
||||
*/
|
||||
noDeleteOnStaleGet?: boolean
|
||||
|
||||
/**
|
||||
* Update the age of items on {@link has}, renewing their TTL
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
updateAgeOnHas?: boolean
|
||||
}
|
||||
|
||||
type SafetyBounds<K, V> =
|
||||
| LimitedByCount
|
||||
| LimitedBySize<K, V>
|
||||
| LimitedByTTL
|
||||
|
||||
// options shared by all three of the limiting scenarios
|
||||
interface SharedOptions<K, V> {
|
||||
/**
|
||||
* Function that is called on items when they are dropped from the cache.
|
||||
* This can be handy if you want to close file descriptors or do other
|
||||
* cleanup tasks when items are no longer accessible. Called with `key,
|
||||
* value`. It's called before actually removing the item from the
|
||||
* internal cache, so it is *NOT* safe to re-add them.
|
||||
* Use {@link disposeAfter} if you wish to dispose items after they have
|
||||
* been full removed, when it is safe to add them back to the cache.
|
||||
*/
|
||||
dispose?: Disposer<K, V>
|
||||
|
||||
/**
|
||||
* The same as dispose, but called *after* the entry is completely
|
||||
* removed and the cache is once again in a clean state. It is safe to
|
||||
* add an item right back into the cache at this point.
|
||||
* However, note that it is *very* easy to inadvertently create infinite
|
||||
* recursion this way.
|
||||
*
|
||||
* @since 7.3.0
|
||||
*/
|
||||
disposeAfter?: Disposer<K, V>
|
||||
|
||||
/**
|
||||
* Set to true to suppress calling the dispose() function if the entry
|
||||
* key is still accessible within the cache.
|
||||
* This may be overridden by passing an options object to {@link set}.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
noDisposeOnSet?: boolean
|
||||
|
||||
/**
|
||||
* Function that is used to make background asynchronous fetches. Called
|
||||
* with `fetchMethod(key, staleValue, { signal, options, context })`.
|
||||
*
|
||||
* If `fetchMethod` is not provided, then {@link fetch} is
|
||||
* equivalent to `Promise.resolve(cache.get(key))`.
|
||||
*
|
||||
* The `fetchMethod` should ONLY return `undefined` in cases where the
|
||||
* abort controller has sent an abort signal.
|
||||
*
|
||||
* @since 7.6.0
|
||||
*/
|
||||
fetchMethod?: LRUCache.Fetcher<K, V>
|
||||
|
||||
/**
|
||||
* Set to true to suppress the deletion of stale data when a
|
||||
* {@link fetchMethod} throws an error or returns a rejected promise
|
||||
*
|
||||
* This may be overridden in the {@link fetchMethod}.
|
||||
*
|
||||
* @default false
|
||||
* @since 7.10.0
|
||||
*/
|
||||
noDeleteOnFetchRejection?: boolean
|
||||
|
||||
/**
|
||||
* Set to true to allow returning stale data when a {@link fetchMethod}
|
||||
* throws an error or returns a rejected promise. Note that this
|
||||
* differs from using {@link allowStale} in that stale data will
|
||||
* ONLY be returned in the case that the fetch fails, not any other
|
||||
* times.
|
||||
*
|
||||
* This may be overridden in the {@link fetchMethod}.
|
||||
*
|
||||
* @default false
|
||||
* @since 7.16.0
|
||||
*/
|
||||
allowStaleOnFetchRejection?: boolean
|
||||
|
||||
/**
|
||||
*
|
||||
* Set to true to ignore the `abort` event emitted by the `AbortSignal`
|
||||
* object passed to {@link fetchMethod}, and still cache the
|
||||
* resulting resolution value, as long as it is not `undefined`.
|
||||
*
|
||||
* When used on its own, this means aborted {@link fetch} calls are not
|
||||
* immediately resolved or rejected when they are aborted, and instead take
|
||||
* the full time to await.
|
||||
*
|
||||
* When used with {@link allowStaleOnFetchAbort}, aborted {@link fetch}
|
||||
* calls will resolve immediately to their stale cached value or
|
||||
* `undefined`, and will continue to process and eventually update the
|
||||
* cache when they resolve, as long as the resulting value is not
|
||||
* `undefined`, thus supporting a "return stale on timeout while
|
||||
* refreshing" mechanism by passing `AbortSignal.timeout(n)` as the signal.
|
||||
*
|
||||
* **Note**: regardless of this setting, an `abort` event _is still emitted
|
||||
* on the `AbortSignal` object_, so may result in invalid results when
|
||||
* passed to other underlying APIs that use AbortSignals.
|
||||
*
|
||||
* This may be overridden in the {@link fetchMethod} or the call to
|
||||
* {@link fetch}.
|
||||
*
|
||||
* @default false
|
||||
* @since 7.17.0
|
||||
*/
|
||||
ignoreFetchAbort?: boolean
|
||||
|
||||
/**
|
||||
* Set to true to return a stale value from the cache when the
|
||||
* `AbortSignal` passed to the {@link fetchMethod} dispatches an `'abort'`
|
||||
* event, whether user-triggered, or due to internal cache behavior.
|
||||
*
|
||||
* Unless {@link ignoreFetchAbort} is also set, the underlying
|
||||
* {@link fetchMethod} will still be considered canceled, and its return
|
||||
* value will be ignored and not cached.
|
||||
*
|
||||
* This may be overridden in the {@link fetchMethod} or the call to
|
||||
* {@link fetch}.
|
||||
*
|
||||
* @default false
|
||||
* @since 7.17.0
|
||||
*/
|
||||
allowStaleOnFetchAbort?: boolean
|
||||
|
||||
/**
|
||||
* Set to any value in the constructor or {@link fetch} options to
|
||||
* pass arbitrary data to the {@link fetchMethod} in the {@link context}
|
||||
* options field.
|
||||
*
|
||||
* @since 7.12.0
|
||||
*/
|
||||
fetchContext?: any
|
||||
}
|
||||
|
||||
type Options<K, V> = SharedOptions<K, V> &
|
||||
DeprecatedOptions<K, V> &
|
||||
SafetyBounds<K, V> &
|
||||
MaybeMaxEntrySizeLimit<K, V>
|
||||
|
||||
/**
|
||||
* options which override the options set in the LRUCache constructor
|
||||
* when making calling {@link set}.
|
||||
*/
|
||||
interface SetOptions<K, V> {
|
||||
/**
|
||||
* A value for the size of the entry, prevents calls to
|
||||
* {@link sizeCalculation}.
|
||||
*
|
||||
* Items larger than {@link maxEntrySize} will not be stored in the cache.
|
||||
*
|
||||
* Note that when {@link maxSize} or {@link maxEntrySize} are set, every
|
||||
* item added MUST have a size specified, either via a `sizeCalculation` in
|
||||
* the constructor, or {@link sizeCalculation} or `size` options to
|
||||
* {@link set}.
|
||||
*/
|
||||
size?: LRUSize
|
||||
/**
|
||||
* Overrides the {@link sizeCalculation} method set in the constructor.
|
||||
*
|
||||
* Items larger than {@link maxEntrySize} will not be stored in the cache.
|
||||
*
|
||||
* Note that when {@link maxSize} or {@link maxEntrySize} are set, every
|
||||
* item added MUST have a size specified, either via a `sizeCalculation` in
|
||||
* the constructor, or `sizeCalculation` or {@link size} options to
|
||||
* {@link set}.
|
||||
*/
|
||||
sizeCalculation?: SizeCalculator<K, V>
|
||||
ttl?: LRUMilliseconds
|
||||
start?: LRUMilliseconds
|
||||
noDisposeOnSet?: boolean
|
||||
noUpdateTTL?: boolean
|
||||
status?: Status<V>
|
||||
}
|
||||
|
||||
/**
|
||||
* options which override the options set in the LRUCAche constructor
|
||||
* when calling {@link has}.
|
||||
*/
|
||||
interface HasOptions<V> {
|
||||
updateAgeOnHas?: boolean
|
||||
status: Status<V>
|
||||
}
|
||||
|
||||
/**
|
||||
* options which override the options set in the LRUCache constructor
|
||||
* when calling {@link get}.
|
||||
*/
|
||||
interface GetOptions<V> {
|
||||
allowStale?: boolean
|
||||
updateAgeOnGet?: boolean
|
||||
noDeleteOnStaleGet?: boolean
|
||||
status?: Status<V>
|
||||
}
|
||||
|
||||
/**
|
||||
* options which override the options set in the LRUCache constructor
|
||||
* when calling {@link peek}.
|
||||
*/
|
||||
interface PeekOptions {
|
||||
allowStale?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Options object passed to the {@link fetchMethod}
|
||||
*
|
||||
* May be mutated by the {@link fetchMethod} to affect the behavior of the
|
||||
* resulting {@link set} operation on resolution, or in the case of
|
||||
* {@link noDeleteOnFetchRejection}, {@link ignoreFetchAbort}, and
|
||||
* {@link allowStaleOnFetchRejection}, the handling of failure.
|
||||
*/
|
||||
interface FetcherFetchOptions<K, V> {
|
||||
allowStale?: boolean
|
||||
updateAgeOnGet?: boolean
|
||||
noDeleteOnStaleGet?: boolean
|
||||
size?: LRUSize
|
||||
sizeCalculation?: SizeCalculator<K, V>
|
||||
ttl?: LRUMilliseconds
|
||||
noDisposeOnSet?: boolean
|
||||
noUpdateTTL?: boolean
|
||||
noDeleteOnFetchRejection?: boolean
|
||||
allowStaleOnFetchRejection?: boolean
|
||||
ignoreFetchAbort?: boolean
|
||||
allowStaleOnFetchAbort?: boolean
|
||||
status?: Status<V>
|
||||
}
|
||||
|
||||
/**
|
||||
* Status object that may be passed to {@link fetch}, {@link get},
|
||||
* {@link set}, and {@link has}.
|
||||
*/
|
||||
interface Status<V> {
|
||||
/**
|
||||
* The status of a set() operation.
|
||||
*
|
||||
* - add: the item was not found in the cache, and was added
|
||||
* - update: the item was in the cache, with the same value provided
|
||||
* - replace: the item was in the cache, and replaced
|
||||
* - miss: the item was not added to the cache for some reason
|
||||
*/
|
||||
set?: 'add' | 'update' | 'replace' | 'miss'
|
||||
|
||||
/**
|
||||
* the ttl stored for the item, or undefined if ttls are not used.
|
||||
*/
|
||||
ttl?: LRUMilliseconds
|
||||
|
||||
/**
|
||||
* the start time for the item, or undefined if ttls are not used.
|
||||
*/
|
||||
start?: LRUMilliseconds
|
||||
|
||||
/**
|
||||
* The timestamp used for TTL calculation
|
||||
*/
|
||||
now?: LRUMilliseconds
|
||||
|
||||
/**
|
||||
* the remaining ttl for the item, or undefined if ttls are not used.
|
||||
*/
|
||||
remainingTTL?: LRUMilliseconds
|
||||
|
||||
/**
|
||||
* The calculated size for the item, if sizes are used.
|
||||
*/
|
||||
size?: LRUSize
|
||||
|
||||
/**
|
||||
* A flag indicating that the item was not stored, due to exceeding the
|
||||
* {@link maxEntrySize}
|
||||
*/
|
||||
maxEntrySizeExceeded?: true
|
||||
|
||||
/**
|
||||
* The old value, specified in the case of `set:'update'` or
|
||||
* `set:'replace'`
|
||||
*/
|
||||
oldValue?: V
|
||||
|
||||
/**
|
||||
* The results of a {@link has} operation
|
||||
*
|
||||
* - hit: the item was found in the cache
|
||||
* - stale: the item was found in the cache, but is stale
|
||||
* - miss: the item was not found in the cache
|
||||
*/
|
||||
has?: 'hit' | 'stale' | 'miss'
|
||||
|
||||
/**
|
||||
* The status of a {@link fetch} operation.
|
||||
* Note that this can change as the underlying fetch() moves through
|
||||
* various states.
|
||||
*
|
||||
* - inflight: there is another fetch() for this key which is in process
|
||||
* - get: there is no fetchMethod, so {@link get} was called.
|
||||
* - miss: the item is not in cache, and will be fetched.
|
||||
* - hit: the item is in the cache, and was resolved immediately.
|
||||
* - stale: the item is in the cache, but stale.
|
||||
* - refresh: the item is in the cache, and not stale, but
|
||||
* {@link forceRefresh} was specified.
|
||||
*/
|
||||
fetch?: 'get' | 'inflight' | 'miss' | 'hit' | 'stale' | 'refresh'
|
||||
|
||||
/**
|
||||
* The {@link fetchMethod} was called
|
||||
*/
|
||||
fetchDispatched?: true
|
||||
|
||||
/**
|
||||
* The cached value was updated after a successful call to fetchMethod
|
||||
*/
|
||||
fetchUpdated?: true
|
||||
|
||||
/**
|
||||
* The reason for a fetch() rejection. Either the error raised by the
|
||||
* {@link fetchMethod}, or the reason for an AbortSignal.
|
||||
*/
|
||||
fetchError?: Error
|
||||
|
||||
/**
|
||||
* The fetch received an abort signal
|
||||
*/
|
||||
fetchAborted?: true
|
||||
|
||||
/**
|
||||
* The abort signal received was ignored, and the fetch was allowed to
|
||||
* continue.
|
||||
*/
|
||||
fetchAbortIgnored?: true
|
||||
|
||||
/**
|
||||
* The fetchMethod promise resolved successfully
|
||||
*/
|
||||
fetchResolved?: true
|
||||
|
||||
/**
|
||||
* The fetchMethod promise was rejected
|
||||
*/
|
||||
fetchRejected?: true
|
||||
|
||||
/**
|
||||
* The status of a {@link get} operation.
|
||||
*
|
||||
* - fetching: The item is currently being fetched. If a previous value is
|
||||
* present and allowed, that will be returned.
|
||||
* - stale: The item is in the cache, and is stale.
|
||||
* - hit: the item is in the cache
|
||||
* - miss: the item is not in the cache
|
||||
*/
|
||||
get?: 'stale' | 'hit' | 'miss'
|
||||
|
||||
/**
|
||||
* A fetch or get operation returned a stale value.
|
||||
*/
|
||||
returnedStale?: true
|
||||
}
|
||||
|
||||
/**
|
||||
* options which override the options set in the LRUCache constructor
|
||||
* when calling {@link fetch}.
|
||||
*
|
||||
* This is the union of GetOptions and SetOptions, plus
|
||||
* {@link noDeleteOnFetchRejection}, {@link allowStaleOnFetchRejection},
|
||||
* {@link forceRefresh}, and {@link fetchContext}
|
||||
*/
|
||||
interface FetchOptions<K, V> extends FetcherFetchOptions<K, V> {
|
||||
forceRefresh?: boolean
|
||||
fetchContext?: any
|
||||
signal?: AbortSignal
|
||||
status?: Status<V>
|
||||
}
|
||||
|
||||
interface FetcherOptions<K, V> {
|
||||
signal: AbortSignal
|
||||
options: FetcherFetchOptions<K, V>
|
||||
/**
|
||||
* Object provided in the {@link fetchContext} option
|
||||
*/
|
||||
context: any
|
||||
}
|
||||
|
||||
interface Entry<V> {
|
||||
value: V
|
||||
ttl?: LRUMilliseconds
|
||||
size?: LRUSize
|
||||
start?: LRUMilliseconds
|
||||
}
|
||||
}
|
||||
|
||||
export = LRUCache
|
||||
1227
node_modules/lru-cache/index.js
generated
vendored
Normal file
1227
node_modules/lru-cache/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1227
node_modules/lru-cache/index.mjs
generated
vendored
Normal file
1227
node_modules/lru-cache/index.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
96
node_modules/lru-cache/package.json
generated
vendored
Normal file
96
node_modules/lru-cache/package.json
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
{
|
||||
"name": "lru-cache",
|
||||
"description": "A cache object that deletes the least-recently-used items.",
|
||||
"version": "7.18.3",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me>",
|
||||
"keywords": [
|
||||
"mru",
|
||||
"lru",
|
||||
"cache"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"build": "npm run prepare",
|
||||
"pretest": "npm run prepare",
|
||||
"presnap": "npm run prepare",
|
||||
"prepare": "node ./scripts/transpile-to-esm.js",
|
||||
"size": "size-limit",
|
||||
"test": "tap",
|
||||
"snap": "tap",
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags",
|
||||
"format": "prettier --write .",
|
||||
"typedoc": "typedoc ./index.d.ts"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"main": "./index.js",
|
||||
"module": "./index.mjs",
|
||||
"types": "./index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"repository": "git://github.com/isaacs/node-lru-cache.git",
|
||||
"devDependencies": {
|
||||
"@size-limit/preset-small-lib": "^7.0.8",
|
||||
"@types/node": "^17.0.31",
|
||||
"@types/tap": "^15.0.6",
|
||||
"benchmark": "^2.1.4",
|
||||
"c8": "^7.11.2",
|
||||
"clock-mock": "^1.0.6",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"prettier": "^2.6.2",
|
||||
"size-limit": "^7.0.8",
|
||||
"tap": "^16.3.4",
|
||||
"ts-node": "^10.7.0",
|
||||
"tslib": "^2.4.0",
|
||||
"typedoc": "^0.23.24",
|
||||
"typescript": "^4.6.4"
|
||||
},
|
||||
"license": "ISC",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.mjs",
|
||||
"index.d.ts"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"prettier": {
|
||||
"semi": false,
|
||||
"printWidth": 70,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"jsxSingleQuote": false,
|
||||
"bracketSameLine": true,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "lf"
|
||||
},
|
||||
"tap": {
|
||||
"nyc-arg": [
|
||||
"--include=index.js"
|
||||
],
|
||||
"node-arg": [
|
||||
"--expose-gc",
|
||||
"--require",
|
||||
"ts-node/register"
|
||||
],
|
||||
"ts": false
|
||||
},
|
||||
"size-limit": [
|
||||
{
|
||||
"path": "./index.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
21
node_modules/lru.min/LICENSE
generated
vendored
Normal file
21
node_modules/lru.min/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024-current Weslley Araújo (@wellwelwel)
|
||||
|
||||
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.
|
||||
426
node_modules/lru.min/README.md
generated
vendored
Normal file
426
node_modules/lru.min/README.md
generated
vendored
Normal file
@ -0,0 +1,426 @@
|
||||
<h1 align="center">lru.min</h1>
|
||||
<div align="center">
|
||||
|
||||
[](https://www.npmjs.com/package/lru.min)
|
||||
[](https://www.npmjs.com/package/lru.min)
|
||||
[](https://app.codecov.io/gh/wellwelwel/lru.min)<br />
|
||||
[](https://github.com/wellwelwel/lru.min/actions/workflows/ci_node.yml?query=branch%3Amain)
|
||||
[](https://github.com/wellwelwel/lru.min/actions/workflows/ci_bun.yml?query=branch%3Amain)
|
||||
[](https://github.com/wellwelwel/lru.min/actions/workflows/ci_deno.yml?query=branch%3Amain)
|
||||
|
||||
🔥 An extremely fast, efficient, and lightweight <strong><a href="https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29">LRU</a> Cache</strong> for <strong>JavaScript</strong> (<strong>Browser</strong> compatible).
|
||||
|
||||
</div>
|
||||
|
||||
## Why another LRU?
|
||||
|
||||
- 🎖️ **lru.min** is fully compatible with both **Node.js** _(8+)_, **Bun**, **Deno** and, browser environments. All of this, while maintaining the same high performance [_(and a little more)_](https://github.com/wellwelwel/lru.min?tab=readme-ov-file#performance) as the most popular **LRU** packages.
|
||||
|
||||
---
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
# Node.js
|
||||
npm i lru.min
|
||||
```
|
||||
|
||||
```bash
|
||||
# Bun
|
||||
bun add lru.min
|
||||
```
|
||||
|
||||
```bash
|
||||
# Deno
|
||||
deno add npm:lru.min
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
### Quickstart
|
||||
|
||||
```js
|
||||
import { createLRU } from 'lru.min';
|
||||
|
||||
const max = 2;
|
||||
const onEviction = (key, value) => {
|
||||
console.log(`Key "${key}" with value "${value}" has been evicted.`);
|
||||
};
|
||||
|
||||
const LRU = createLRU({
|
||||
max,
|
||||
onEviction,
|
||||
});
|
||||
|
||||
LRU.set('A', 'My Value');
|
||||
LRU.set('B', 'Other Value');
|
||||
LRU.set('C', 'Another Value');
|
||||
|
||||
// => Key "A" with value "My Value" has been evicted.
|
||||
|
||||
LRU.has('B');
|
||||
LRU.get('B');
|
||||
LRU.delete('B');
|
||||
|
||||
// => Key "B" with value "Other Value" has been evicted.
|
||||
|
||||
LRU.peek('C');
|
||||
|
||||
LRU.clear(); // ← recommended | LRU.evict(max) → (slower alternative)
|
||||
|
||||
// => Key "C" with value "Another Value" has been evicted.
|
||||
|
||||
LRU.set('D', "You're amazing 💛");
|
||||
|
||||
LRU.size; // 1
|
||||
LRU.max; // 2
|
||||
LRU.available; // 1
|
||||
|
||||
LRU.resize(10);
|
||||
|
||||
LRU.size; // 1
|
||||
LRU.max; // 10
|
||||
LRU.available; // 9
|
||||
```
|
||||
|
||||
> For _up-to-date_ documentation, always follow the [**README.md**](https://github.com/wellwelwel/lru.min?tab=readme-ov-file#readme) in the **GitHub** repository.
|
||||
|
||||
### Import
|
||||
|
||||
#### ES Modules
|
||||
|
||||
```js
|
||||
import { createLRU } from 'lru.min';
|
||||
```
|
||||
|
||||
#### CommonJS
|
||||
|
||||
```js
|
||||
const { createLRU } = require('lru.min');
|
||||
```
|
||||
|
||||
#### Browser
|
||||
|
||||
> Requires **ES6**.
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/lru.min@1.x.x/browser/lru.min.js"></script>
|
||||
```
|
||||
|
||||
- You can use tools such as [**Babel**](https://github.com/babel/babel) to increase the compatibility rate.
|
||||
|
||||
### Create a new LRU Cache
|
||||
|
||||
> Set maximum size when creating **LRU**.
|
||||
|
||||
```ts
|
||||
const LRU = createLRU({ max: 150_000 });
|
||||
```
|
||||
|
||||
Also, you can set a callback for every deletion/eviction:
|
||||
|
||||
```ts
|
||||
const LRU = createLRU({
|
||||
max: 150_000,
|
||||
onEviction: (key, value) => {
|
||||
// do something
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
### Set a cache
|
||||
|
||||
Adds a key-value pair to the cache. Updates the value if the key already exists
|
||||
|
||||
```ts
|
||||
LRU.set('key', 'value');
|
||||
```
|
||||
|
||||
> `undefined` keys will simply be ignored.
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Get a cache
|
||||
|
||||
Retrieves the value for a given key and moves the key to the most recent position.
|
||||
|
||||
```ts
|
||||
LRU.get('key');
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Peek a cache
|
||||
|
||||
Retrieves the value for a given key without changing its position.
|
||||
|
||||
```ts
|
||||
LRU.peek('key');
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Check if a key exists
|
||||
|
||||
```ts
|
||||
LRU.has('key');
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Delete a cache
|
||||
|
||||
```ts
|
||||
LRU.delete('key');
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Evict from the oldest cache
|
||||
|
||||
Evicts the specified number of the oldest items from the cache.
|
||||
|
||||
```ts
|
||||
LRU.evict(1000);
|
||||
```
|
||||
|
||||
- Complexity: **O(key)** — even if passed a number greater than the number of items, only existing items will be evicted.
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> - Methods that perform eviction(s) when maximum size is reached: `set` and `resize`.
|
||||
> - Methods that always perform eviction(s): `delete`, `clear`, and `evict` itself.
|
||||
|
||||
### Resize the cache
|
||||
|
||||
Resizes the cache to a new maximum size, evicting items if necessary.
|
||||
|
||||
```ts
|
||||
LRU.resize(50_000);
|
||||
```
|
||||
|
||||
- Complexity:
|
||||
- Increasing: **O(newMax - max)**.
|
||||
- Downsizing: **O(n)**.
|
||||
|
||||
### Clear the cache
|
||||
|
||||
Clears and disposes (if used) all key-value pairs from the cache.
|
||||
|
||||
```ts
|
||||
LRU.clear();
|
||||
```
|
||||
|
||||
- Complexity:
|
||||
- Without `onEviction`: **O(1)**.
|
||||
- Using `onEviction`: **O(entries)**.
|
||||
|
||||
### Debugging
|
||||
|
||||
#### Get the max size of the cache
|
||||
|
||||
```ts
|
||||
LRU.max;
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
#### Get the current size of the cache
|
||||
|
||||
```ts
|
||||
LRU.size;
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
#### Get the available slots in the cache
|
||||
|
||||
```ts
|
||||
LRU.available;
|
||||
```
|
||||
|
||||
- Complexity: **O(1)**.
|
||||
|
||||
### Iterating the cache
|
||||
|
||||
#### Get all keys
|
||||
|
||||
Iterates over all keys in the cache, from most recent to least recent.
|
||||
|
||||
```ts
|
||||
const keys = [...LRU.keys()];
|
||||
```
|
||||
|
||||
- Complexity: **O(keys)**.
|
||||
|
||||
#### Get all values
|
||||
|
||||
Iterates over all values in the cache, from most recent to least recent.
|
||||
|
||||
```ts
|
||||
const values = [...LRU.values()];
|
||||
```
|
||||
|
||||
- Complexity: **O(values)**.
|
||||
|
||||
#### Get all entries
|
||||
|
||||
Iterates over `[key, value]` pairs in the cache, from most recent to least recent.
|
||||
|
||||
```ts
|
||||
const entries = [...LRU.entries()];
|
||||
```
|
||||
|
||||
- Complexity: **O(entries)**.
|
||||
|
||||
#### Run a callback for each entry
|
||||
|
||||
Iterates over each value-key pair in the cache, from most recent to least recent.
|
||||
|
||||
```ts
|
||||
LRU.forEach((value, key) => {
|
||||
// do something
|
||||
});
|
||||
```
|
||||
|
||||
- Complexity: **O(entries)**.
|
||||
|
||||
---
|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> - We use `O(keys)`, `O(values)`, `O(entries)`, and `O(newMax - max)` to explicitly indicate what is being iterated over. In traditional complexity notation, this would be represented as `O(n)`.
|
||||
|
||||
---
|
||||
|
||||
### TypeScript
|
||||
|
||||
You can set types for both keys and values. For example:
|
||||
|
||||
```ts
|
||||
import { createLRU } from 'lru.min';
|
||||
|
||||
type Key = number;
|
||||
|
||||
type Value = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
const LRU = createLRU<Key, Value>({ max: 1000 });
|
||||
|
||||
LRU.set(1, { name: 'Peter' });
|
||||
LRU.set(2, { name: 'Mary' });
|
||||
```
|
||||
|
||||
Also:
|
||||
|
||||
```ts
|
||||
import { createLRU, type CacheOptions } from 'lru.min';
|
||||
|
||||
type Key = number;
|
||||
|
||||
type Value = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
const options: CacheOptions<Key, Value> = {
|
||||
max: 10,
|
||||
onEviction(key, value) {
|
||||
console.log(key, value);
|
||||
},
|
||||
};
|
||||
|
||||
// No need to repeat the type params
|
||||
const LRU = createLRU(options);
|
||||
|
||||
LRU.set(1, { name: 'Peter' });
|
||||
LRU.set(2, { name: 'Mary' });
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Performance
|
||||
|
||||
The benchmark is performed by comparing `1,000,000` runs through a maximum cache limit of `100,000`, getting `333,333` caches and deleting `200,000` keys 10 consecutive times, clearing the cache every run.
|
||||
|
||||
> - [**lru-cache**](https://github.com/isaacs/node-lru-cache) `v11.0.0`
|
||||
> - [**quick-lru**](https://github.com/sindresorhus/quick-lru) `v7.0.0`
|
||||
|
||||
```sh
|
||||
# Time:
|
||||
lru.min: 240.45ms
|
||||
lru-cache: 258.32ms
|
||||
quick-lru: 279.89ms
|
||||
|
||||
# CPU:
|
||||
lru.min: 275558.30µs
|
||||
lru-cache: 306858.30µs
|
||||
quick-lru: 401318.80µs
|
||||
```
|
||||
|
||||
- See detailed results and how the tests are run and compared in the [**benchmark**](https://github.com/wellwelwel/lru.min/tree/main/benchmark) directory.
|
||||
|
||||
---
|
||||
|
||||
## Security Policy
|
||||
|
||||
[](https://github.com/wellwelwel/lru.min/actions/workflows/ci_codeql.yml?query=branch%3Amain)
|
||||
|
||||
Please check the [**SECURITY.md**](https://github.com/wellwelwel/lru.min/blob/main/SECURITY.md).
|
||||
|
||||
---
|
||||
|
||||
## Contributing
|
||||
|
||||
See the [**Contributing Guide**](https://github.com/wellwelwel/lru.min/blob/main/CONTRIBUTING.md) and please follow our [**Code of Conduct**](https://github.com/wellwelwel/lru.min/blob/main/CODE_OF_CONDUCT.md) 🚀
|
||||
|
||||
---
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
**lru.min** is based and inspired on the architecture and code of both [**lru-cache**](https://github.com/isaacs/node-lru-cache) and [**quick-lru**](https://github.com/sindresorhus/quick-lru), simplifying their core concepts for enhanced performance and compatibility.
|
||||
|
||||
For more comprehensive features such as **TTL** support, consider using and supporting them 🤝
|
||||
|
||||
- The architecture is mostly based on [@isaacs](https://github.com/isaacs) — [**lru-cache**](https://github.com/isaacs/node-lru-cache/blob/8f51d75351cbb4ac819952eb8e9f95eda00ef800/src/index.ts).
|
||||
- Most of the methods names and its functionalities were inspired by [@sindresorhus](https://github.com/sindresorhus) — [**quick-lru**](https://github.com/sindresorhus/quick-lru/blob/a2262c65e1952539cb4d985a67c46363a780d234/index.js).
|
||||
- [](https://github.com/wellwelwel/lru.min/graphs/contributors)
|
||||
|
||||
---
|
||||
|
||||
#### What comes from [**lru-cache**](https://github.com/isaacs/node-lru-cache)?
|
||||
|
||||
Architecture's essence:
|
||||
|
||||
> _It's not the same code, but majority based on [this](https://github.com/isaacs/node-lru-cache/blob/8f51d75351cbb4ac819952eb8e9f95eda00ef800/src/index.ts#L1385-L1394)._
|
||||
|
||||
```ts
|
||||
let free: number[] = [];
|
||||
|
||||
const keyMap: Map<Key, number> = new Map();
|
||||
const keyList: (Key | undefined)[] = new Array(max).fill(undefined);
|
||||
const valList: (Value | undefined)[] = new Array(max).fill(undefined);
|
||||
const next: number[] = new Array(max).fill(0);
|
||||
const prev: number[] = new Array(max).fill(0);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### What comes from [**quick-lru**](https://github.com/sindresorhus/quick-lru)?
|
||||
|
||||
Name of methods and options _(including their final functionality ideas)_:
|
||||
|
||||
- `resize`
|
||||
- `peek`
|
||||
- `onEviction`
|
||||
- `forEach`
|
||||
- `entriesDescending` as `entries`
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
**lru.min** is under the [**MIT License**](https://github.com/wellwelwel/lru.min/blob/main/LICENSE).<br />
|
||||
Copyright © 2024-present [Weslley Araújo](https://github.com/wellwelwel) and **lru.min** [contributors](https://github.com/wellwelwel/lru.min/graphs/contributors).
|
||||
1
node_modules/lru.min/browser/lru.min.js
generated
vendored
Normal file
1
node_modules/lru.min/browser/lru.min.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
"use strict";window.createLRU=function(e){var r=e.max;if(!(Number.isInteger(r)&&r>0))throw new TypeError("`max` must be a positive integer");var n=0,i=0,t=0,a=[],o=e.onEviction,l=new Map,f=new Array(r).fill(void 0),u=new Array(r).fill(void 0),v=new Array(r).fill(0),s=new Array(r).fill(0),d=function(e,r){if(e!==t){var n=v[e],a=s[e];e===i?i=n:("get"===r||0!==a)&&(v[a]=n),0!==n&&(s[n]=a),v[t]=e,s[e]=t,v[e]=0,t=e}},p=function(){var e=i,r=f[e];return null==o||o(r,u[e]),l.delete(r),f[e]=void 0,u[e]=void 0,0!==(i=v[e])&&(s[i]=0),0===--n&&(i=t=0),a.push(e),e};return{set:function(e,v){if(void 0!==e){var s=l.get(e);void 0===s?(s=n===r?p():a.length>0?a.pop():n,l.set(e,s),f[s]=e,n++):null==o||o(e,u[s]),u[s]=v,1===n?i=t=s:d(s,"set")}},get:function(e){var r=l.get(e);if(void 0!==r)return r!==t&&d(r,"get"),u[r]},peek:function(e){var r=l.get(e);return void 0!==r?u[r]:void 0},has:function(e){return l.has(e)},keys:function*(){for(var e=t,r=0;r<n;r++)yield f[e],e=s[e]},values:function*(){for(var e=t,r=0;r<n;r++)yield u[e],e=s[e]},entries:function*(){for(var e=t,r=0;r<n;r++)yield[f[e],u[e]],e=s[e]},forEach:function(e){for(var r=t,i=0;i<n;i++){var a=f[r];e(u[r],a),r=s[r]}},delete:function(e){var r=l.get(e);if(void 0===r)return!1;null==o||o(e,u[r]),l.delete(e),a.push(r),f[r]=void 0,u[r]=void 0;var d=s[r],p=v[r];return 0!==d&&(v[d]=p),0!==p&&(s[p]=d),r===i&&(i=p),r===t&&(t=d),n--,!0},evict:function(e){for(var r=Math.min(e,n);r>0;)p(),r--},clear:function(){if("function"==typeof o)for(var e=l.values(),r=e.next();!r.done;r=e.next())o(f[r.value],u[r.value]);l.clear(),f.fill(void 0),u.fill(void 0),a=[],n=0,i=t=0},resize:function(e){if(!(Number.isInteger(e)&&e>0))throw new TypeError("`max` must be a positive integer");if(e!==r){if(e<r){for(var d=t,p=Math.min(n,e),c=n-p,y=new Array(e),g=new Array(e),h=new Array(e),w=new Array(e),A=1;A<=c;A++)null==o||o(f[A],u[A]);for(var m=p-1;m>=0;m--)y[m]=f[d],g[m]=u[d],h[m]=m+1,w[m]=m-1,l.set(y[m],m),d=s[d];i=0,t=p-1,n=p,f.length=e,u.length=e,v.length=e,s.length=e;for(var x=0;x<p;x++)f[x]=y[x],u[x]=g[x],v[x]=h[x],s[x]=w[x];a=[];for(var b=p;b<e;b++)a.push(b)}else{var E=e-r;f.push.apply(f,new Array(E).fill(void 0)),u.push.apply(u,new Array(E).fill(void 0)),v.push.apply(v,new Array(E).fill(0)),s.push.apply(s,new Array(E).fill(0))}r=e}},get max(){return r},get size(){return n},get available(){return r-n}}};
|
||||
38
node_modules/lru.min/lib/index.d.ts
generated
vendored
Normal file
38
node_modules/lru.min/lib/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
export type CacheOptions<Key = unknown, Value = unknown> = {
|
||||
/** Maximum number of items the cache can hold. */
|
||||
max: number;
|
||||
/** Function called when an item is evicted from the cache. */
|
||||
onEviction?: (key: Key, value: Value) => unknown;
|
||||
};
|
||||
export declare const createLRU: <Key, Value>(options: CacheOptions<Key, Value>) => {
|
||||
/** Adds a key-value pair to the cache. Updates the value if the key already exists. */
|
||||
set(key: Key, value: Value): undefined;
|
||||
/** Retrieves the value for a given key and moves the key to the most recent position. */
|
||||
get(key: Key): Value | undefined;
|
||||
/** Retrieves the value for a given key without changing its position. */
|
||||
peek: (key: Key) => Value | undefined;
|
||||
/** Checks if a key exists in the cache. */
|
||||
has: (key: Key) => boolean;
|
||||
/** Iterates over all keys in the cache, from most recent to least recent. */
|
||||
keys(): IterableIterator<Key>;
|
||||
/** Iterates over all values in the cache, from most recent to least recent. */
|
||||
values(): IterableIterator<Value>;
|
||||
/** Iterates over `[key, value]` pairs in the cache, from most recent to least recent. */
|
||||
entries(): IterableIterator<[Key, Value]>;
|
||||
/** Iterates over each value-key pair in the cache, from most recent to least recent. */
|
||||
forEach: (callback: (value: Value, key: Key) => unknown) => undefined;
|
||||
/** Deletes a key-value pair from the cache. */
|
||||
delete(key: Key): boolean;
|
||||
/** Evicts the oldest item or the specified number of the oldest items from the cache. */
|
||||
evict: (number: number) => undefined;
|
||||
/** Clears all key-value pairs from the cache. */
|
||||
clear(): undefined;
|
||||
/** Resizes the cache to a new maximum size, evicting items if necessary. */
|
||||
resize: (newMax: number) => undefined;
|
||||
/** Returns the maximum number of items that can be stored in the cache. */
|
||||
readonly max: number;
|
||||
/** Returns the number of items currently stored in the cache. */
|
||||
readonly size: number;
|
||||
/** Returns the number of currently available slots in the cache before reaching the maximum size. */
|
||||
readonly available: number;
|
||||
};
|
||||
229
node_modules/lru.min/lib/index.js
generated
vendored
Normal file
229
node_modules/lru.min/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,229 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createLRU = void 0;
|
||||
const createLRU = (options) => {
|
||||
let { max } = options;
|
||||
if (!(Number.isInteger(max) && max > 0))
|
||||
throw new TypeError('`max` must be a positive integer');
|
||||
let size = 0;
|
||||
let head = 0;
|
||||
let tail = 0;
|
||||
let free = [];
|
||||
const { onEviction } = options;
|
||||
const keyMap = new Map();
|
||||
const keyList = new Array(max).fill(undefined);
|
||||
const valList = new Array(max).fill(undefined);
|
||||
const next = new Array(max).fill(0);
|
||||
const prev = new Array(max).fill(0);
|
||||
const setTail = (index, type) => {
|
||||
if (index === tail)
|
||||
return;
|
||||
const nextIndex = next[index];
|
||||
const prevIndex = prev[index];
|
||||
if (index === head)
|
||||
head = nextIndex;
|
||||
else if (type === 'get' || prevIndex !== 0)
|
||||
next[prevIndex] = nextIndex;
|
||||
if (nextIndex !== 0)
|
||||
prev[nextIndex] = prevIndex;
|
||||
next[tail] = index;
|
||||
prev[index] = tail;
|
||||
next[index] = 0;
|
||||
tail = index;
|
||||
};
|
||||
const _evict = () => {
|
||||
const evictHead = head;
|
||||
const key = keyList[evictHead];
|
||||
onEviction === null || onEviction === void 0 ? void 0 : onEviction(key, valList[evictHead]);
|
||||
keyMap.delete(key);
|
||||
keyList[evictHead] = undefined;
|
||||
valList[evictHead] = undefined;
|
||||
head = next[evictHead];
|
||||
if (head !== 0)
|
||||
prev[head] = 0;
|
||||
size--;
|
||||
if (size === 0)
|
||||
head = tail = 0;
|
||||
free.push(evictHead);
|
||||
return evictHead;
|
||||
};
|
||||
return {
|
||||
/** Adds a key-value pair to the cache. Updates the value if the key already exists. */
|
||||
set(key, value) {
|
||||
if (key === undefined)
|
||||
return;
|
||||
let index = keyMap.get(key);
|
||||
if (index === undefined) {
|
||||
index = size === max ? _evict() : free.length > 0 ? free.pop() : size;
|
||||
keyMap.set(key, index);
|
||||
keyList[index] = key;
|
||||
size++;
|
||||
}
|
||||
else
|
||||
onEviction === null || onEviction === void 0 ? void 0 : onEviction(key, valList[index]);
|
||||
valList[index] = value;
|
||||
if (size === 1)
|
||||
head = tail = index;
|
||||
else
|
||||
setTail(index, 'set');
|
||||
},
|
||||
/** Retrieves the value for a given key and moves the key to the most recent position. */
|
||||
get(key) {
|
||||
const index = keyMap.get(key);
|
||||
if (index === undefined)
|
||||
return;
|
||||
if (index !== tail)
|
||||
setTail(index, 'get');
|
||||
return valList[index];
|
||||
},
|
||||
/** Retrieves the value for a given key without changing its position. */
|
||||
peek: (key) => {
|
||||
const index = keyMap.get(key);
|
||||
return index !== undefined ? valList[index] : undefined;
|
||||
},
|
||||
/** Checks if a key exists in the cache. */
|
||||
has: (key) => keyMap.has(key),
|
||||
/** Iterates over all keys in the cache, from most recent to least recent. */
|
||||
*keys() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield keyList[current];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over all values in the cache, from most recent to least recent. */
|
||||
*values() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield valList[current];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over `[key, value]` pairs in the cache, from most recent to least recent. */
|
||||
*entries() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield [keyList[current], valList[current]];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over each value-key pair in the cache, from most recent to least recent. */
|
||||
forEach: (callback) => {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
const key = keyList[current];
|
||||
const value = valList[current];
|
||||
callback(value, key);
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Deletes a key-value pair from the cache. */
|
||||
delete(key) {
|
||||
const index = keyMap.get(key);
|
||||
if (index === undefined)
|
||||
return false;
|
||||
onEviction === null || onEviction === void 0 ? void 0 : onEviction(key, valList[index]);
|
||||
keyMap.delete(key);
|
||||
free.push(index);
|
||||
keyList[index] = undefined;
|
||||
valList[index] = undefined;
|
||||
const prevIndex = prev[index];
|
||||
const nextIndex = next[index];
|
||||
if (prevIndex !== 0)
|
||||
next[prevIndex] = nextIndex;
|
||||
if (nextIndex !== 0)
|
||||
prev[nextIndex] = prevIndex;
|
||||
if (index === head)
|
||||
head = nextIndex;
|
||||
if (index === tail)
|
||||
tail = prevIndex;
|
||||
size--;
|
||||
return true;
|
||||
},
|
||||
/** Evicts the oldest item or the specified number of the oldest items from the cache. */
|
||||
evict: (number) => {
|
||||
let toPrune = Math.min(number, size);
|
||||
while (toPrune > 0) {
|
||||
_evict();
|
||||
toPrune--;
|
||||
}
|
||||
},
|
||||
/** Clears all key-value pairs from the cache. */
|
||||
clear() {
|
||||
if (typeof onEviction === 'function') {
|
||||
const iterator = keyMap.values();
|
||||
for (let result = iterator.next(); !result.done; result = iterator.next())
|
||||
onEviction(keyList[result.value], valList[result.value]);
|
||||
}
|
||||
keyMap.clear();
|
||||
keyList.fill(undefined);
|
||||
valList.fill(undefined);
|
||||
free = [];
|
||||
size = 0;
|
||||
head = tail = 0;
|
||||
},
|
||||
/** Resizes the cache to a new maximum size, evicting items if necessary. */
|
||||
resize: (newMax) => {
|
||||
if (!(Number.isInteger(newMax) && newMax > 0))
|
||||
throw new TypeError('`max` must be a positive integer');
|
||||
if (newMax === max)
|
||||
return;
|
||||
if (newMax < max) {
|
||||
let current = tail;
|
||||
const preserve = Math.min(size, newMax);
|
||||
const remove = size - preserve;
|
||||
const newKeyList = new Array(newMax);
|
||||
const newValList = new Array(newMax);
|
||||
const newNext = new Array(newMax);
|
||||
const newPrev = new Array(newMax);
|
||||
for (let i = 1; i <= remove; i++)
|
||||
onEviction === null || onEviction === void 0 ? void 0 : onEviction(keyList[i], valList[i]);
|
||||
for (let i = preserve - 1; i >= 0; i--) {
|
||||
newKeyList[i] = keyList[current];
|
||||
newValList[i] = valList[current];
|
||||
newNext[i] = i + 1;
|
||||
newPrev[i] = i - 1;
|
||||
keyMap.set(newKeyList[i], i);
|
||||
current = prev[current];
|
||||
}
|
||||
head = 0;
|
||||
tail = preserve - 1;
|
||||
size = preserve;
|
||||
keyList.length = newMax;
|
||||
valList.length = newMax;
|
||||
next.length = newMax;
|
||||
prev.length = newMax;
|
||||
for (let i = 0; i < preserve; i++) {
|
||||
keyList[i] = newKeyList[i];
|
||||
valList[i] = newValList[i];
|
||||
next[i] = newNext[i];
|
||||
prev[i] = newPrev[i];
|
||||
}
|
||||
free = [];
|
||||
for (let i = preserve; i < newMax; i++)
|
||||
free.push(i);
|
||||
}
|
||||
else {
|
||||
const fill = newMax - max;
|
||||
keyList.push(...new Array(fill).fill(undefined));
|
||||
valList.push(...new Array(fill).fill(undefined));
|
||||
next.push(...new Array(fill).fill(0));
|
||||
prev.push(...new Array(fill).fill(0));
|
||||
}
|
||||
max = newMax;
|
||||
},
|
||||
/** Returns the maximum number of items that can be stored in the cache. */
|
||||
get max() {
|
||||
return max;
|
||||
},
|
||||
/** Returns the number of items currently stored in the cache. */
|
||||
get size() {
|
||||
return size;
|
||||
},
|
||||
/** Returns the number of currently available slots in the cache before reaching the maximum size. */
|
||||
get available() {
|
||||
return max - size;
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.createLRU = createLRU;
|
||||
207
node_modules/lru.min/lib/index.mjs
generated
vendored
Normal file
207
node_modules/lru.min/lib/index.mjs
generated
vendored
Normal file
@ -0,0 +1,207 @@
|
||||
const createLRU = (options) => {
|
||||
let { max } = options;
|
||||
if (!(Number.isInteger(max) && max > 0))
|
||||
throw new TypeError("`max` must be a positive integer");
|
||||
let size = 0;
|
||||
let head = 0;
|
||||
let tail = 0;
|
||||
let free = [];
|
||||
const { onEviction } = options;
|
||||
const keyMap = /* @__PURE__ */ new Map();
|
||||
const keyList = new Array(max).fill(void 0);
|
||||
const valList = new Array(max).fill(void 0);
|
||||
const next = new Array(max).fill(0);
|
||||
const prev = new Array(max).fill(0);
|
||||
const setTail = (index, type) => {
|
||||
if (index === tail) return;
|
||||
const nextIndex = next[index];
|
||||
const prevIndex = prev[index];
|
||||
if (index === head) head = nextIndex;
|
||||
else if (type === "get" || prevIndex !== 0) next[prevIndex] = nextIndex;
|
||||
if (nextIndex !== 0) prev[nextIndex] = prevIndex;
|
||||
next[tail] = index;
|
||||
prev[index] = tail;
|
||||
next[index] = 0;
|
||||
tail = index;
|
||||
};
|
||||
const _evict = () => {
|
||||
const evictHead = head;
|
||||
const key = keyList[evictHead];
|
||||
onEviction == null ? void 0 : onEviction(key, valList[evictHead]);
|
||||
keyMap.delete(key);
|
||||
keyList[evictHead] = void 0;
|
||||
valList[evictHead] = void 0;
|
||||
head = next[evictHead];
|
||||
if (head !== 0) prev[head] = 0;
|
||||
size--;
|
||||
if (size === 0) head = tail = 0;
|
||||
free.push(evictHead);
|
||||
return evictHead;
|
||||
};
|
||||
return {
|
||||
/** Adds a key-value pair to the cache. Updates the value if the key already exists. */
|
||||
set(key, value) {
|
||||
if (key === void 0) return;
|
||||
let index = keyMap.get(key);
|
||||
if (index === void 0) {
|
||||
index = size === max ? _evict() : free.length > 0 ? free.pop() : size;
|
||||
keyMap.set(key, index);
|
||||
keyList[index] = key;
|
||||
size++;
|
||||
} else onEviction == null ? void 0 : onEviction(key, valList[index]);
|
||||
valList[index] = value;
|
||||
if (size === 1) head = tail = index;
|
||||
else setTail(index, "set");
|
||||
},
|
||||
/** Retrieves the value for a given key and moves the key to the most recent position. */
|
||||
get(key) {
|
||||
const index = keyMap.get(key);
|
||||
if (index === void 0) return;
|
||||
if (index !== tail) setTail(index, "get");
|
||||
return valList[index];
|
||||
},
|
||||
/** Retrieves the value for a given key without changing its position. */
|
||||
peek: (key) => {
|
||||
const index = keyMap.get(key);
|
||||
return index !== void 0 ? valList[index] : void 0;
|
||||
},
|
||||
/** Checks if a key exists in the cache. */
|
||||
has: (key) => keyMap.has(key),
|
||||
/** Iterates over all keys in the cache, from most recent to least recent. */
|
||||
*keys() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield keyList[current];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over all values in the cache, from most recent to least recent. */
|
||||
*values() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield valList[current];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over `[key, value]` pairs in the cache, from most recent to least recent. */
|
||||
*entries() {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
yield [keyList[current], valList[current]];
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Iterates over each value-key pair in the cache, from most recent to least recent. */
|
||||
forEach: (callback) => {
|
||||
let current = tail;
|
||||
for (let i = 0; i < size; i++) {
|
||||
const key = keyList[current];
|
||||
const value = valList[current];
|
||||
callback(value, key);
|
||||
current = prev[current];
|
||||
}
|
||||
},
|
||||
/** Deletes a key-value pair from the cache. */
|
||||
delete(key) {
|
||||
const index = keyMap.get(key);
|
||||
if (index === void 0) return false;
|
||||
onEviction == null ? void 0 : onEviction(key, valList[index]);
|
||||
keyMap.delete(key);
|
||||
free.push(index);
|
||||
keyList[index] = void 0;
|
||||
valList[index] = void 0;
|
||||
const prevIndex = prev[index];
|
||||
const nextIndex = next[index];
|
||||
if (prevIndex !== 0) next[prevIndex] = nextIndex;
|
||||
if (nextIndex !== 0) prev[nextIndex] = prevIndex;
|
||||
if (index === head) head = nextIndex;
|
||||
if (index === tail) tail = prevIndex;
|
||||
size--;
|
||||
return true;
|
||||
},
|
||||
/** Evicts the oldest item or the specified number of the oldest items from the cache. */
|
||||
evict: (number) => {
|
||||
let toPrune = Math.min(number, size);
|
||||
while (toPrune > 0) {
|
||||
_evict();
|
||||
toPrune--;
|
||||
}
|
||||
},
|
||||
/** Clears all key-value pairs from the cache. */
|
||||
clear() {
|
||||
if (typeof onEviction === "function") {
|
||||
const iterator = keyMap.values();
|
||||
for (let result = iterator.next(); !result.done; result = iterator.next())
|
||||
onEviction(keyList[result.value], valList[result.value]);
|
||||
}
|
||||
keyMap.clear();
|
||||
keyList.fill(void 0);
|
||||
valList.fill(void 0);
|
||||
free = [];
|
||||
size = 0;
|
||||
head = tail = 0;
|
||||
},
|
||||
/** Resizes the cache to a new maximum size, evicting items if necessary. */
|
||||
resize: (newMax) => {
|
||||
if (!(Number.isInteger(newMax) && newMax > 0))
|
||||
throw new TypeError("`max` must be a positive integer");
|
||||
if (newMax === max) return;
|
||||
if (newMax < max) {
|
||||
let current = tail;
|
||||
const preserve = Math.min(size, newMax);
|
||||
const remove = size - preserve;
|
||||
const newKeyList = new Array(newMax);
|
||||
const newValList = new Array(newMax);
|
||||
const newNext = new Array(newMax);
|
||||
const newPrev = new Array(newMax);
|
||||
for (let i = 1; i <= remove; i++)
|
||||
onEviction == null ? void 0 : onEviction(keyList[i], valList[i]);
|
||||
for (let i = preserve - 1; i >= 0; i--) {
|
||||
newKeyList[i] = keyList[current];
|
||||
newValList[i] = valList[current];
|
||||
newNext[i] = i + 1;
|
||||
newPrev[i] = i - 1;
|
||||
keyMap.set(newKeyList[i], i);
|
||||
current = prev[current];
|
||||
}
|
||||
head = 0;
|
||||
tail = preserve - 1;
|
||||
size = preserve;
|
||||
keyList.length = newMax;
|
||||
valList.length = newMax;
|
||||
next.length = newMax;
|
||||
prev.length = newMax;
|
||||
for (let i = 0; i < preserve; i++) {
|
||||
keyList[i] = newKeyList[i];
|
||||
valList[i] = newValList[i];
|
||||
next[i] = newNext[i];
|
||||
prev[i] = newPrev[i];
|
||||
}
|
||||
free = [];
|
||||
for (let i = preserve; i < newMax; i++) free.push(i);
|
||||
} else {
|
||||
const fill = newMax - max;
|
||||
keyList.push(...new Array(fill).fill(void 0));
|
||||
valList.push(...new Array(fill).fill(void 0));
|
||||
next.push(...new Array(fill).fill(0));
|
||||
prev.push(...new Array(fill).fill(0));
|
||||
}
|
||||
max = newMax;
|
||||
},
|
||||
/** Returns the maximum number of items that can be stored in the cache. */
|
||||
get max() {
|
||||
return max;
|
||||
},
|
||||
/** Returns the number of items currently stored in the cache. */
|
||||
get size() {
|
||||
return size;
|
||||
},
|
||||
/** Returns the number of currently available slots in the cache before reaching the maximum size. */
|
||||
get available() {
|
||||
return max - size;
|
||||
}
|
||||
};
|
||||
};
|
||||
export {
|
||||
createLRU
|
||||
};
|
||||
89
node_modules/lru.min/package.json
generated
vendored
Normal file
89
node_modules/lru.min/package.json
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
{
|
||||
"name": "lru.min",
|
||||
"version": "1.1.2",
|
||||
"description": "🔥 An extremely fast and efficient LRU cache for JavaScript with high compatibility (including Browsers) — 6.8KB.",
|
||||
"main": "./lib/index.js",
|
||||
"module": "./lib/index.mjs",
|
||||
"types": "./lib/index.d.ts",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/wellwelwel/lru.min.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/wellwelwel/lru.min/issues"
|
||||
},
|
||||
"author": "https://github.com/wellwelwel",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wellwelwel"
|
||||
},
|
||||
"files": [
|
||||
"browser",
|
||||
"lib"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=8.0.0",
|
||||
"bun": ">=1.0.0",
|
||||
"deno": ">=1.30.0"
|
||||
},
|
||||
"scripts": {
|
||||
"benchmark:esm": "cd benchmark && npm ci && node index.mjs",
|
||||
"benchmark:cjs": "cd benchmark && npm ci && node index.cjs",
|
||||
"prebuild": "rm -rf ./browser ./lib",
|
||||
"build:browser": "tsx tools/browserfy.ts",
|
||||
"build:esm": "esbuild src/index.ts --outfile=lib/index.mjs --platform=node --target=node12 --format=esm",
|
||||
"build": "tsc && npm run build:esm && npm run build:browser",
|
||||
"test:node": "poku",
|
||||
"test:bun": "bun poku",
|
||||
"test:deno": "deno run -A npm:poku",
|
||||
"test:coverage": "mcr --import tsx --config mcr.config.ts npm run test:node",
|
||||
"lint": "npx @biomejs/biome lint && prettier --check .",
|
||||
"lint:fix": "npx @biomejs/biome lint --write && prettier --write .github/workflows/*.yml .",
|
||||
"update": "pu minor && npm i && npm audit fix",
|
||||
"postupdate": "npm run lint:fix",
|
||||
"size": "ls -lh lib/index.mjs | awk '{print $5}'"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.26.9",
|
||||
"@babel/preset-env": "^7.26.9",
|
||||
"@biomejs/biome": "^1.9.4",
|
||||
"@types/babel__core": "^7.20.5",
|
||||
"@types/node": "^22.13.10",
|
||||
"esbuild": "^0.25.0",
|
||||
"monocart-coverage-reports": "2.12.1",
|
||||
"packages-update": "^2.0.0",
|
||||
"poku": "^3.0.1",
|
||||
"prettier": "^3.5.3",
|
||||
"terser": "^5.39.0",
|
||||
"tsx": "^4.19.3",
|
||||
"typescript": "^5.8.2"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"lru",
|
||||
"cache",
|
||||
"caching",
|
||||
"hash",
|
||||
"node",
|
||||
"nodejs",
|
||||
"bun",
|
||||
"deno",
|
||||
"typescript",
|
||||
"browser",
|
||||
"fast",
|
||||
"lru-cache",
|
||||
"quick-lru"
|
||||
]
|
||||
}
|
||||
569
node_modules/mysql/Changes.md
generated
vendored
Normal file
569
node_modules/mysql/Changes.md
generated
vendored
Normal file
@ -0,0 +1,569 @@
|
||||
# Changes
|
||||
|
||||
This file is a manually maintained list of changes for each release. Feel free
|
||||
to add your changes here when sending pull requests. Also send corrections if
|
||||
you spot any mistakes.
|
||||
|
||||
## v2.18.1 (2020-01-23)
|
||||
|
||||
* Fix Amazon RDS profile for yaSSL MySQL servers with 2019 CA #2292
|
||||
|
||||
## v2.18.0 (2020-01-21)
|
||||
|
||||
* Add `localInfile` option to control `LOAD DATA LOCAL INFILE`
|
||||
* Add new Amazon RDS Root 2019 CA to Amazon RDS SSL profile #2280
|
||||
* Add new error codes up to MySQL 5.7.29
|
||||
* Fix early detection of bad callback to `connection.query`
|
||||
* Support Node.js 12.x #2211
|
||||
* Support Node.js 13.x
|
||||
* Support non-enumerable properties in object argument to `connection.query` #2253
|
||||
* Update `bignumber.js` to 9.0.0
|
||||
* Update `readable-stream` to 2.3.7
|
||||
|
||||
## v2.17.1 (2019-04-18)
|
||||
|
||||
* Update `bignumber.js` to 7.2.1 #2206
|
||||
- Fix npm deprecation warning
|
||||
|
||||
## v2.17.0 (2019-04-17)
|
||||
|
||||
* Add reverse type lookup for small performance gain #2170
|
||||
* Fix `connection.threadId` missing on handshake failure
|
||||
* Fix duplicate packet name in debug output
|
||||
* Fix no password support for old password protocol
|
||||
* Remove special case for handshake in determine packet code
|
||||
* Small performance improvement starting command sequence
|
||||
* Support auth switch in change user flow #1776
|
||||
* Support Node.js 11.x
|
||||
* Update `bignumber.js` to 6.0.0
|
||||
|
||||
## v2.16.0 (2018-07-17)
|
||||
|
||||
* Add Amazon RDS GovCloud SSL certificates #1876
|
||||
* Add new error codes up to MySQL 5.7.21
|
||||
* Include connection ID in debug output
|
||||
* Support Node.js 9.x
|
||||
* Support Node.js 10.x #2003 #2024 #2026 #2034
|
||||
* Update Amazon RDS SSL certificates
|
||||
* Update `bignumber.js` to 4.1.0
|
||||
* Update `readable-stream` to 2.3.6
|
||||
* Update `sqlstring` to 2.3.1
|
||||
- Fix incorrectly replacing non-placeholders in SQL
|
||||
|
||||
## v2.15.0 (2017-10-05)
|
||||
|
||||
* Add new Amazon RDS ca-central-1 certificate CA to Amazon RDS SSL profile #1809
|
||||
* Add new error codes up to MySQL 5.7.19
|
||||
* Add `mysql.raw()` to generate pre-escaped values #877 #1821
|
||||
* Fix "changedRows" to work on non-English servers #1819
|
||||
* Fix error when server sends RST on `QUIT` #1811
|
||||
* Fix typo in insecure auth error message
|
||||
* Support `mysql_native_password` auth switch request for Azure #1396 #1729 #1730
|
||||
* Update `sqlstring` to 2.3.0
|
||||
- Add `.toSqlString()` escape overriding
|
||||
- Small performance improvement on `escapeId`
|
||||
* Update `bignumber.js` to 4.0.4
|
||||
|
||||
## v2.14.1 (2017-08-01)
|
||||
|
||||
* Fix holding first closure for lifetime of connection #1785
|
||||
|
||||
## v2.14.0 (2017-07-25)
|
||||
|
||||
* Add new Amazon RDS ap-south-1 certificate CA to Amazon RDS SSL profile #1780
|
||||
* Add new Amazon RDS eu-west-2 certificate CA to Amazon RDS SSL profile #1770
|
||||
* Add `sql` property to query `Error` objects #1462 #1628 #1629
|
||||
* Add `sqlMessage` property to `Error` objects #1714
|
||||
* Fix the MySQL 5.7.17 error codes
|
||||
* Support Node.js 8.x
|
||||
* Update `bignumber.js` to 4.0.2
|
||||
* Update `readable-stream` to 2.3.3
|
||||
* Use `safe-buffer` for improved Buffer API
|
||||
|
||||
## v2.13.0 (2017-01-24)
|
||||
|
||||
* Accept regular expression as pool cluster pattern #1572
|
||||
* Accept wildcard anywhere in pool cluster pattern #1570
|
||||
* Add `acquire` and `release` events to `Pool` for tracking #1366 #1449 #1528 #1625
|
||||
* Add new error codes up to MySQL 5.7.17
|
||||
* Fix edge cases when determing Query result packets #1547
|
||||
* Fix memory leak when using long-running domains #1619 #1620
|
||||
* Remove unnecessary buffer copies when receiving large packets
|
||||
* Update `bignumber.js` to 3.1.2
|
||||
* Use a simple buffer list to improve performance #566 #1590
|
||||
|
||||
## v2.12.0 (2016-11-02)
|
||||
|
||||
* Accept array of type names to `dateStrings` option #605 #1481
|
||||
* Add `query` method to `PoolNamespace` #1256 #1505 #1506
|
||||
- Used as `cluster.of(...).query(...)`
|
||||
* Add new error codes up to MySQL 5.7.16
|
||||
* Fix edge cases writing certain length coded values
|
||||
* Fix typo in `HANDSHAKE_NO_SSL_SUPPORT` error message #1534
|
||||
* Support Node.js 7.x
|
||||
* Update `bignumber.js` to 2.4.0
|
||||
* Update `sqlstring` to 2.2.0
|
||||
- Accept numbers and other value types in `escapeId`
|
||||
- Escape invalid `Date` objects as `NULL`
|
||||
- Run `buffer.toString()` through escaping
|
||||
|
||||
## v2.11.1 (2016-06-07)
|
||||
|
||||
* Fix writing truncated packets starting with large string/buffer #1438
|
||||
|
||||
## v2.11.0 (2016-06-06)
|
||||
|
||||
* Add `POOL_CLOSED` code to "Pool is closed." error
|
||||
* Add `POOL_CONNLIMIT` code to "No connections available." error #1332
|
||||
* Bind underlying connections in pool to same domain as pool #1242
|
||||
* Bind underlying socket to same domain as connection #1243
|
||||
* Fix allocation errors receiving many result rows #918 #1265 #1324 #1415
|
||||
* Fix edge cases constructing long stack traces #1387
|
||||
* Fix handshake inactivity timeout on Node.js v4.2.0 #1223 #1236 #1239 #1240 #1241 #1252
|
||||
* Fix Query stream to emit close after ending #1349 #1350
|
||||
* Fix type cast for BIGINT columns when number is negative #1376
|
||||
* Performance improvements for array/object escaping in SqlString #1331
|
||||
* Performance improvements for formatting in SqlString #1431
|
||||
* Performance improvements for string escaping in SqlString #1390
|
||||
* Performance improvements for writing packets to network
|
||||
* Support Node.js 6.x
|
||||
* Update `bignumber.js` to 2.3.0
|
||||
* Update `readable-stream` to 1.1.14
|
||||
* Use the `sqlstring` module for SQL escaping and formatting
|
||||
|
||||
## v2.10.2 (2016-01-12)
|
||||
|
||||
* Fix exception/hang from certain SSL connection errors #1153
|
||||
* Update `bignumber.js` to 2.1.4
|
||||
|
||||
## v2.10.1 (2016-01-11)
|
||||
|
||||
* Add new Amazon RDS ap-northeast-2 certificate CA to Amazon RDS SSL profile #1329
|
||||
|
||||
## v2.10.0 (2015-12-15)
|
||||
|
||||
* Add new error codes up to MySQL 5.7.9 #1294
|
||||
* Add new JSON type constant #1295
|
||||
* Add types for fractional seconds support
|
||||
* Fix `connection.destroy()` on pool connection creating sequences #1291
|
||||
* Fix error code 139 `HA_ERR_TO_BIG_ROW` to be `HA_ERR_TOO_BIG_ROW`
|
||||
* Fix error when call site error is missing stack #1179
|
||||
* Fix reading password from MySQL URL that has bare colon #1278
|
||||
* Handle MySQL servers not closing TCP connection after QUIT -> OK exchange #1277
|
||||
* Minor SqlString Date to string performance improvement #1233
|
||||
* Support Node.js 4.x
|
||||
* Support Node.js 5.x
|
||||
* Update `bignumber.js` to 2.1.2
|
||||
|
||||
## v2.9.0 (2015-08-19)
|
||||
|
||||
* Accept the `ciphers` property in connection `ssl` option #1185
|
||||
* Fix bad timezone conversion from `Date` to string for certain times #1045 #1155
|
||||
|
||||
## v2.8.0 (2015-07-13)
|
||||
|
||||
* Add `connect` event to `Connection` #1129
|
||||
* Default `timeout` for `connection.end` to 30 seconds #1057
|
||||
* Fix a sync callback when sequence enqueue fails #1147
|
||||
* Provide static require analysis
|
||||
* Re-use connection from pool after `conn.changeUser` is used #837 #1088
|
||||
|
||||
## v2.7.0 (2015-05-27)
|
||||
|
||||
* Destroy/end connections removed from the pool on error
|
||||
* Delay implied connect until after `.query` argument validation
|
||||
* Do not remove connections with non-fatal errors from the pool
|
||||
* Error early if `callback` argument to `.query` is not a function #1060
|
||||
* Lazy-load modules from many entry point; reduced memory use
|
||||
|
||||
## v2.6.2 (2015-04-14)
|
||||
|
||||
* Fix `Connection.createQuery` for no SQL #1058
|
||||
* Update `bignumber.js` to 2.0.7
|
||||
|
||||
## v2.6.1 (2015-03-26)
|
||||
|
||||
* Update `bignumber.js` to 2.0.5 #1037 #1038
|
||||
|
||||
## v2.6.0 (2015-03-24)
|
||||
|
||||
* Add `poolCluster.remove` to remove pools from the cluster #1006 #1007
|
||||
* Add optional callback to `poolCluster.end`
|
||||
* Add `restoreNodeTimeout` option to `PoolCluster` #880 #906
|
||||
* Fix LOAD DATA INFILE handling in multiple statements #1036
|
||||
* Fix `poolCluster.add` to throw if `PoolCluster` has been closed
|
||||
* Fix `poolCluster.add` to throw if `id` already defined
|
||||
* Fix un-catchable error from `PoolCluster` when MySQL server offline #1033
|
||||
* Improve speed formatting SQL #1019
|
||||
* Support io.js
|
||||
|
||||
## v2.5.5 (2015-02-23)
|
||||
|
||||
* Store SSL presets in JS instead of JSON #959
|
||||
* Support Node.js 0.12
|
||||
* Update Amazon RDS SSL certificates #1001
|
||||
|
||||
## v2.5.4 (2014-12-16)
|
||||
|
||||
* Fix error if falsy error thrown in callback handler #960
|
||||
* Fix various error code strings #954
|
||||
|
||||
## v2.5.3 (2014-11-06)
|
||||
|
||||
* Fix `pool.query` streaming interface not emitting connection errors #941
|
||||
|
||||
## v2.5.2 (2014-10-10)
|
||||
|
||||
* Fix receiving large text fields #922
|
||||
|
||||
## v2.5.1 (2014-09-22)
|
||||
|
||||
* Fix `pool.end` race conditions #915
|
||||
* Fix `pool.getConnection` race conditions
|
||||
|
||||
## v2.5.0 (2014-09-07)
|
||||
|
||||
* Add code `POOL_ENQUEUELIMIT` to error reaching `queueLimit`
|
||||
* Add `enqueue` event to pool #716
|
||||
* Add `enqueue` event to protocol and connection #381
|
||||
* Blacklist unsupported connection flags #881
|
||||
* Make only column names enumerable in `RowDataPacket` #549 #895
|
||||
* Support Node.js 0.6 #718
|
||||
|
||||
## v2.4.3 (2014-08-25)
|
||||
|
||||
* Fix `pool.query` to use `typeCast` configuration
|
||||
|
||||
## v2.4.2 (2014-08-03)
|
||||
|
||||
* Fix incorrect sequence packet errors to be catchable #867
|
||||
* Fix stray protocol packet errors to be catchable #867
|
||||
* Fix timing of fatal protocol errors bubbling to user #879
|
||||
|
||||
## v2.4.1 (2014-07-17)
|
||||
|
||||
* Fix `pool.query` not invoking callback on connection error #872
|
||||
|
||||
## v2.4.0 (2014-07-13)
|
||||
|
||||
* Add code `POOL_NOEXIST` in PoolCluster error #846
|
||||
* Add `acquireTimeout` pool option to specify a timeout for acquiring a connection #821 #854
|
||||
* Add `connection.escapeId`
|
||||
* Add `pool.escapeId`
|
||||
* Add `timeout` option to all sequences #855 #863
|
||||
* Default `connectTimeout` to 10 seconds
|
||||
* Fix domain binding with `conn.connect`
|
||||
* Fix `packet.default` to actually be a string
|
||||
* Fix `PARSER_*` errors to be catchable
|
||||
* Fix `PROTOCOL_PACKETS_OUT_OF_ORDER` error to be catchable #844
|
||||
* Include packets that failed parsing under `debug`
|
||||
* Return `Query` object from `pool.query` like `conn.query` #830
|
||||
* Use `EventEmitter.listenerCount` when possible for faster counting
|
||||
|
||||
## v2.3.2 (2014-05-29)
|
||||
|
||||
* Fix pool leaking connections after `conn.changeUser` #833
|
||||
|
||||
## v2.3.1 (2014-05-26)
|
||||
|
||||
* Add database errors to error constants
|
||||
* Add global errors to error constants
|
||||
* Throw when calling `conn.release` multiple times #824 #827
|
||||
* Update known error codes
|
||||
|
||||
## v2.3.0 (2014-05-16)
|
||||
|
||||
* Accept MySQL charset (like `UTF8` or `UTF8MB4`) in `charset` option #808
|
||||
* Accept pool options in connection string to `mysql.createPool` #811
|
||||
* Clone connection config for new pool connections
|
||||
* Default `connectTimeout` to 2 minutes
|
||||
* Reject unauthorized SSL connections (use `ssl.rejectUnauthorized` to override) #816
|
||||
* Return last error when PoolCluster exhausts connection retries #818
|
||||
* Remove connection from pool after `conn.changeUser` is released #806
|
||||
* Throw on unknown SSL profile name #817
|
||||
* User newer TLS functions when available #809
|
||||
|
||||
## v2.2.0 (2014-04-27)
|
||||
|
||||
* Use indexOf instead of for loops removing conn from pool #611
|
||||
* Make callback to `pool.query` optional like `conn.query` #585
|
||||
* Prevent enqueuing sequences after fatal error #400
|
||||
* Fix geometry parser for empty fields #742
|
||||
* Accept lower-case charset option
|
||||
* Throw on unknown charset option #789
|
||||
* Update known charsets
|
||||
* Remove console.warn from PoolCluster #744
|
||||
* Fix `pool.end` to handle queued connections #797
|
||||
* Fix `pool.releaseConnection` to keep connection queue flowing #797
|
||||
* Fix SSL handshake error to be catchable #800
|
||||
* Add `connection.threadId` to get MySQL connection ID #602
|
||||
* Ensure `pool.getConnection` retrieves good connections #434 #557 #778
|
||||
* Fix pool cluster wildcard matching #627
|
||||
* Pass query values through to `SqlString.format` #590
|
||||
|
||||
## v2.1.1 (2014-03-13)
|
||||
|
||||
* fix authentication w/password failure for node.js 0.10.5 #746 #752
|
||||
* fix authentication w/password TypeError exception for node.js 0.10.0-0.10.4 #747
|
||||
* fix specifying `values` in `conn.query({...}).on(...)` pattern #755
|
||||
* fix long stack trace to include the `pool.query(...)` call #715
|
||||
|
||||
## v2.1.0 (2014-02-20)
|
||||
|
||||
* crypto.createHash fix for node.js < 11 #735
|
||||
* Add `connectTimeout` option to specify a timeout for establishing a connection #726
|
||||
* SSL support #481
|
||||
|
||||
## v2.0.1
|
||||
|
||||
* internal parser speed improvement #702
|
||||
* domains support
|
||||
* 'trace' connection option to control if long stack traces are generated #713 #710 #439
|
||||
|
||||
## v2.0.0 (2014-01-09)
|
||||
|
||||
* stream improvements:
|
||||
- node 0.8 support #692
|
||||
- Emit 'close' events from query streams #688
|
||||
* encoding fix in streaming LOAD DATA LOCAL INFILE #670
|
||||
* Doc improvements
|
||||
|
||||
## v2.0.0-rc2 (2013-12-07)
|
||||
|
||||
* Streaming LOAD DATA LOCAL INFILE #668
|
||||
* Doc improvements
|
||||
|
||||
## v2.0.0-rc1 (2013-11-30)
|
||||
|
||||
* Transaction support
|
||||
* Expose SqlString.format as mysql.format()
|
||||
* Many bug fixes
|
||||
* Better support for dates in local time zone
|
||||
* Doc improvements
|
||||
|
||||
## v2.0.0-alpha9 (2013-08-27)
|
||||
|
||||
* Add query to pool to execute queries directly using the pool
|
||||
* Add `sqlState` property to `Error` objects #556
|
||||
* Pool option to set queue limit
|
||||
* Pool sends 'connection' event when it opens a new connection
|
||||
* Added stringifyObjects option to treat input as strings rather than objects (#501)
|
||||
* Support for poolClusters
|
||||
* Datetime improvements
|
||||
* Bug fixes
|
||||
|
||||
## v2.0.0-alpha8 (2013-04-30)
|
||||
|
||||
* Switch to old mode for Streams 2 (Node.js v 0.10.x)
|
||||
* Add stream method to Query Wraps events from the query object into a node v0.10.x Readable stream
|
||||
* DECIMAL should also be treated as big number
|
||||
* Removed slow unnecessary stack access
|
||||
* Added charsets
|
||||
* Added bigNumberStrings option for forcing BIGINT columns as strings
|
||||
* Changes date parsing to return String if not a valid JS Date
|
||||
* Adds support for ?? escape sequence to escape identifiers
|
||||
* Changes Auth.token() to force password to be in binary, not utf8 (#378)
|
||||
* Restrict debugging by packet types
|
||||
* Add 'multipleStatements' option tracking to ConnectionConfig. Fixes GH-408
|
||||
* Changes Pool to handle 'error' events and dispose connection
|
||||
* Allows db.query({ sql: "..." }, [ val1, ... ], cb); (#390)
|
||||
* Improved documentation
|
||||
* Bug fixes
|
||||
|
||||
## v2.0.0-alpha7 (2013-02-03)
|
||||
|
||||
* Add connection pooling (#351)
|
||||
|
||||
## v2.0.0-alpha6 (2013-01-31)
|
||||
|
||||
* Add supportBigNumbers option (#381, #382)
|
||||
* Accept prebuilt Query object in connection.query
|
||||
* Bug fixes
|
||||
|
||||
## v2.0.0-alpha5 (2012-12-03)
|
||||
|
||||
* Add mysql.escapeId to escape identifiers (closes #342)
|
||||
* Allow custom escaping mode (config.queryFormat)
|
||||
* Convert DATE columns to configured timezone instead of UTC (#332)
|
||||
* Convert LONGLONG and NEWDECIMAL to numbers (#333)
|
||||
* Fix Connection.escape() (fixes #330)
|
||||
* Changed Readme ambiguity about custom type cast fallback
|
||||
* Change typeCast to receive Connection instead of Connection.config.timezone
|
||||
* Fix drain event having useless err parameter
|
||||
* Add Connection.statistics() back from v0.9
|
||||
* Add Connection.ping() back from v0.9
|
||||
|
||||
## v2.0.0-alpha4 (2012-10-03)
|
||||
|
||||
* Fix some OOB errors on resume()
|
||||
* Fix quick pause() / resume() usage
|
||||
* Properly parse host denied / similar errors
|
||||
* Add Connection.ChangeUser functionality
|
||||
* Make sure changeUser errors are fatal
|
||||
* Enable formatting nested arrays for bulk inserts
|
||||
* Add Connection.escape functionality
|
||||
* Renamed 'close' to 'end' event
|
||||
* Return parsed object instead of Buffer for GEOMETRY types
|
||||
* Allow nestTables inline (using a string instead of a boolean)
|
||||
* Check for ZEROFILL_FLAG and format number accordingly
|
||||
* Add timezone support (default: local)
|
||||
* Add custom typeCast functionality
|
||||
* Export mysql column types
|
||||
* Add connection flags functionality (#237)
|
||||
* Exports drain event when queue finishes processing (#272, #271, #306)
|
||||
|
||||
## v2.0.0-alpha3 (2012-06-12)
|
||||
|
||||
* Implement support for `LOAD DATA LOCAL INFILE` queries (#182).
|
||||
* Support OLD\_PASSWORD() accounts like 0.9.x did. You should still upgrade any
|
||||
user accounts in your your MySQL user table that has short (16 byte) Password
|
||||
values. Connecting to those accounts is not secure. (#204)
|
||||
* Ignore function values when escaping objects, allows to use RowDataPacket
|
||||
objects as query arguments. (Alex Gorbatchev, #213)
|
||||
* Handle initial error packets from server such as `ER_HOST_NOT_PRIVILEGED`.
|
||||
* Treat `utf8\_bin` as a String, not Buffer. (#214)
|
||||
* Handle empty strings in first row column value. (#222)
|
||||
* Honor Connection#nestTables setting for queries. (#221)
|
||||
* Remove `CLIENT_INTERACTIVE` flag from config. Improves #225.
|
||||
* Improve docs for connections settings.
|
||||
* Implement url string support for Connection configs.
|
||||
|
||||
## v2.0.0-alpha2 (2012-05-31)
|
||||
|
||||
* Specify escaping before for NaN / Infinity (they are as unquoted constants).
|
||||
* Support for unix domain socket connections (use: {socketPath: '...'}).
|
||||
* Fix type casting for NULL values for Date/Number fields
|
||||
* Add `fields` argument to `query()` as well as `'fields'` event. This is
|
||||
similar to what was available in 0.9.x.
|
||||
* Support connecting to the sphinx searchd daemon as well as MariaDB (#199).
|
||||
* Implement long stack trace support, will be removed / disabled if the node
|
||||
core ever supports it natively.
|
||||
* Implement `nestTables` option for queries, allows fetching JOIN result sets
|
||||
with overlapping column names.
|
||||
* Fix ? placeholder mechanism for values containing '?' characters (#205).
|
||||
* Detect when `connect()` is called more than once on a connection and provide
|
||||
the user with a good error message for it (#204).
|
||||
* Switch to `UTF8_GENERAL_CI` (previously `UTF8_UNICODE_CI`) as the default
|
||||
charset for all connections to avoid strange MySQL performance issues (#200),
|
||||
and also make the charset user configurable.
|
||||
* Fix BLOB type casting for `TINY_BLOB`, `MEDIUM_BLOB` and `LONG_BLOB`.
|
||||
* Add support for sending and receiving large (> 16 MB) packets.
|
||||
|
||||
## v2.0.0-alpha (2012-05-15)
|
||||
|
||||
This release is a rewrite. You should carefully test your application after
|
||||
upgrading to avoid problems. This release features many improvements, most
|
||||
importantly:
|
||||
|
||||
* ~5x faster than v0.9.x for parsing query results
|
||||
* Support for pause() / resume() (for streaming rows)
|
||||
* Support for multiple statement queries
|
||||
* Support for stored procedures
|
||||
* Support for transactions
|
||||
* Support for binary columns (as blobs)
|
||||
* Consistent & well documented error handling
|
||||
* A new Connection class that has well defined semantics (unlike the old Client class).
|
||||
* Convenient escaping of objects / arrays that allows for simpler query construction
|
||||
* A significantly simpler code base
|
||||
* Many bug fixes & other small improvements (Closed 62 out of 66 GitHub issues)
|
||||
|
||||
Below are a few notes on the upgrade process itself:
|
||||
|
||||
The first thing you will run into is that the old `Client` class is gone and
|
||||
has been replaced with a less ambitious `Connection` class. So instead of
|
||||
`mysql.createClient()`, you now have to:
|
||||
|
||||
```js
|
||||
var mysql = require('mysql');
|
||||
var connection = mysql.createConnection({
|
||||
host : 'localhost',
|
||||
user : 'me',
|
||||
password : 'secret',
|
||||
});
|
||||
|
||||
connection.query('SELECT 1', function(err, rows) {
|
||||
if (err) throw err;
|
||||
|
||||
console.log('Query result: ', rows);
|
||||
});
|
||||
|
||||
connection.end();
|
||||
```
|
||||
|
||||
The new `Connection` class does not try to handle re-connects, please study the
|
||||
`Server disconnects` section in the new Readme.
|
||||
|
||||
Other than that, the interface has stayed very similar. Here are a few things
|
||||
to check out so:
|
||||
|
||||
* BIGINT's are now cast into strings
|
||||
* Binary data is now cast to buffers
|
||||
* The `'row'` event on the `Query` object is now called `'result'` and will
|
||||
also be emitted for queries that produce an OK/Error response.
|
||||
* Error handling is consistently defined now, check the Readme
|
||||
* Escaping has become more powerful which may break your code if you are
|
||||
currently using objects to fill query placeholders.
|
||||
* Connections can now be established explicitly again, so you may wish to do so
|
||||
if you want to handle connection errors specifically.
|
||||
|
||||
That should be most of it, if you run into anything else, please send a patch
|
||||
or open an issue to improve this document.
|
||||
|
||||
## v0.9.6 (2012-03-12)
|
||||
|
||||
* Escape array values so they produce sql arrays (Roger Castells, Colin Smith)
|
||||
* docs: mention mysql transaction stop gap solution (Blake Miner)
|
||||
* docs: Mention affectedRows in FAQ (Michael Baldwin)
|
||||
|
||||
## v0.9.5 (2011-11-26)
|
||||
|
||||
* Fix #142 Driver stalls upon reconnect attempt that's immediately closed
|
||||
* Add travis build
|
||||
* Switch to urun as a test runner
|
||||
* Switch to utest for unit tests
|
||||
* Remove fast-or-slow dependency for tests
|
||||
* Split integration tests into individual files again
|
||||
|
||||
## v0.9.4 (2011-08-31)
|
||||
|
||||
* Expose package.json as `mysql.PACKAGE` (#104)
|
||||
|
||||
## v0.9.3 (2011-08-22)
|
||||
|
||||
* Set default `client.user` to root
|
||||
* Fix #91: Client#format should not mutate params array
|
||||
* Fix #94: TypeError in client.js
|
||||
* Parse decimals as string (vadimg)
|
||||
|
||||
## v0.9.2 (2011-08-07)
|
||||
|
||||
* The underlaying socket connection is now managed implicitly rather than explicitly.
|
||||
* Check the [upgrading guide][] for a full list of changes.
|
||||
|
||||
## v0.9.1 (2011-02-20)
|
||||
|
||||
* Fix issue #49 / `client.escape()` throwing exceptions on objects. (Nick Payne)
|
||||
* Drop < v0.4.x compatibility. From now on you need node v0.4.x to use this module.
|
||||
|
||||
## Older releases
|
||||
|
||||
These releases were done before maintaining this file:
|
||||
|
||||
* [v0.9.0](https://github.com/mysqljs/mysql/compare/v0.8.0...v0.9.0)
|
||||
(2011-01-04)
|
||||
* [v0.8.0](https://github.com/mysqljs/mysql/compare/v0.7.0...v0.8.0)
|
||||
(2010-10-30)
|
||||
* [v0.7.0](https://github.com/mysqljs/mysql/compare/v0.6.0...v0.7.0)
|
||||
(2010-10-14)
|
||||
* [v0.6.0](https://github.com/mysqljs/mysql/compare/v0.5.0...v0.6.0)
|
||||
(2010-09-28)
|
||||
* [v0.5.0](https://github.com/mysqljs/mysql/compare/v0.4.0...v0.5.0)
|
||||
(2010-09-17)
|
||||
* [v0.4.0](https://github.com/mysqljs/mysql/compare/v0.3.0...v0.4.0)
|
||||
(2010-09-02)
|
||||
* [v0.3.0](https://github.com/mysqljs/mysql/compare/v0.2.0...v0.3.0)
|
||||
(2010-08-25)
|
||||
* [v0.2.0](https://github.com/mysqljs/mysql/compare/v0.1.0...v0.2.0)
|
||||
(2010-08-22)
|
||||
* [v0.1.0](https://github.com/mysqljs/mysql/commits/v0.1.0)
|
||||
(2010-08-22)
|
||||
19
node_modules/mysql/License
generated
vendored
Normal file
19
node_modules/mysql/License
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors
|
||||
|
||||
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.
|
||||
1548
node_modules/mysql/Readme.md
generated
vendored
Normal file
1548
node_modules/mysql/Readme.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
161
node_modules/mysql/index.js
generated
vendored
Normal file
161
node_modules/mysql/index.js
generated
vendored
Normal file
@ -0,0 +1,161 @@
|
||||
var Classes = Object.create(null);
|
||||
|
||||
/**
|
||||
* Create a new Connection instance.
|
||||
* @param {object|string} config Configuration or connection string for new MySQL connection
|
||||
* @return {Connection} A new MySQL connection
|
||||
* @public
|
||||
*/
|
||||
exports.createConnection = function createConnection(config) {
|
||||
var Connection = loadClass('Connection');
|
||||
var ConnectionConfig = loadClass('ConnectionConfig');
|
||||
|
||||
return new Connection({config: new ConnectionConfig(config)});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Pool instance.
|
||||
* @param {object|string} config Configuration or connection string for new MySQL connections
|
||||
* @return {Pool} A new MySQL pool
|
||||
* @public
|
||||
*/
|
||||
exports.createPool = function createPool(config) {
|
||||
var Pool = loadClass('Pool');
|
||||
var PoolConfig = loadClass('PoolConfig');
|
||||
|
||||
return new Pool({config: new PoolConfig(config)});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new PoolCluster instance.
|
||||
* @param {object} [config] Configuration for pool cluster
|
||||
* @return {PoolCluster} New MySQL pool cluster
|
||||
* @public
|
||||
*/
|
||||
exports.createPoolCluster = function createPoolCluster(config) {
|
||||
var PoolCluster = loadClass('PoolCluster');
|
||||
|
||||
return new PoolCluster(config);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Query instance.
|
||||
* @param {string} sql The SQL for the query
|
||||
* @param {array} [values] Any values to insert into placeholders in sql
|
||||
* @param {function} [callback] The callback to use when query is complete
|
||||
* @return {Query} New query object
|
||||
* @public
|
||||
*/
|
||||
exports.createQuery = function createQuery(sql, values, callback) {
|
||||
var Connection = loadClass('Connection');
|
||||
|
||||
return Connection.createQuery(sql, values, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Escape a value for SQL.
|
||||
* @param {*} value The value to escape
|
||||
* @param {boolean} [stringifyObjects=false] Setting if objects should be stringified
|
||||
* @param {string} [timeZone=local] Setting for time zone to use for Date conversion
|
||||
* @return {string} Escaped string value
|
||||
* @public
|
||||
*/
|
||||
exports.escape = function escape(value, stringifyObjects, timeZone) {
|
||||
var SqlString = loadClass('SqlString');
|
||||
|
||||
return SqlString.escape(value, stringifyObjects, timeZone);
|
||||
};
|
||||
|
||||
/**
|
||||
* Escape an identifier for SQL.
|
||||
* @param {*} value The value to escape
|
||||
* @param {boolean} [forbidQualified=false] Setting to treat '.' as part of identifier
|
||||
* @return {string} Escaped string value
|
||||
* @public
|
||||
*/
|
||||
exports.escapeId = function escapeId(value, forbidQualified) {
|
||||
var SqlString = loadClass('SqlString');
|
||||
|
||||
return SqlString.escapeId(value, forbidQualified);
|
||||
};
|
||||
|
||||
/**
|
||||
* Format SQL and replacement values into a SQL string.
|
||||
* @param {string} sql The SQL for the query
|
||||
* @param {array} [values] Any values to insert into placeholders in sql
|
||||
* @param {boolean} [stringifyObjects=false] Setting if objects should be stringified
|
||||
* @param {string} [timeZone=local] Setting for time zone to use for Date conversion
|
||||
* @return {string} Formatted SQL string
|
||||
* @public
|
||||
*/
|
||||
exports.format = function format(sql, values, stringifyObjects, timeZone) {
|
||||
var SqlString = loadClass('SqlString');
|
||||
|
||||
return SqlString.format(sql, values, stringifyObjects, timeZone);
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrap raw SQL strings from escape overriding.
|
||||
* @param {string} sql The raw SQL
|
||||
* @return {object} Wrapped object
|
||||
* @public
|
||||
*/
|
||||
exports.raw = function raw(sql) {
|
||||
var SqlString = loadClass('SqlString');
|
||||
|
||||
return SqlString.raw(sql);
|
||||
};
|
||||
|
||||
/**
|
||||
* The type constants.
|
||||
* @public
|
||||
*/
|
||||
Object.defineProperty(exports, 'Types', {
|
||||
get: loadClass.bind(null, 'Types')
|
||||
});
|
||||
|
||||
/**
|
||||
* Load the given class.
|
||||
* @param {string} className Name of class to default
|
||||
* @return {function|object} Class constructor or exports
|
||||
* @private
|
||||
*/
|
||||
function loadClass(className) {
|
||||
var Class = Classes[className];
|
||||
|
||||
if (Class !== undefined) {
|
||||
return Class;
|
||||
}
|
||||
|
||||
// This uses a switch for static require analysis
|
||||
switch (className) {
|
||||
case 'Connection':
|
||||
Class = require('./lib/Connection');
|
||||
break;
|
||||
case 'ConnectionConfig':
|
||||
Class = require('./lib/ConnectionConfig');
|
||||
break;
|
||||
case 'Pool':
|
||||
Class = require('./lib/Pool');
|
||||
break;
|
||||
case 'PoolCluster':
|
||||
Class = require('./lib/PoolCluster');
|
||||
break;
|
||||
case 'PoolConfig':
|
||||
Class = require('./lib/PoolConfig');
|
||||
break;
|
||||
case 'SqlString':
|
||||
Class = require('./lib/protocol/SqlString');
|
||||
break;
|
||||
case 'Types':
|
||||
Class = require('./lib/protocol/constants/types');
|
||||
break;
|
||||
default:
|
||||
throw new Error('Cannot find class \'' + className + '\'');
|
||||
}
|
||||
|
||||
// Store to prevent invoking require()
|
||||
Classes[className] = Class;
|
||||
|
||||
return Class;
|
||||
}
|
||||
529
node_modules/mysql/lib/Connection.js
generated
vendored
Normal file
529
node_modules/mysql/lib/Connection.js
generated
vendored
Normal file
@ -0,0 +1,529 @@
|
||||
var Crypto = require('crypto');
|
||||
var Events = require('events');
|
||||
var Net = require('net');
|
||||
var tls = require('tls');
|
||||
var ConnectionConfig = require('./ConnectionConfig');
|
||||
var Protocol = require('./protocol/Protocol');
|
||||
var SqlString = require('./protocol/SqlString');
|
||||
var Query = require('./protocol/sequences/Query');
|
||||
var Util = require('util');
|
||||
|
||||
module.exports = Connection;
|
||||
Util.inherits(Connection, Events.EventEmitter);
|
||||
function Connection(options) {
|
||||
Events.EventEmitter.call(this);
|
||||
|
||||
this.config = options.config;
|
||||
|
||||
this._socket = options.socket;
|
||||
this._protocol = new Protocol({config: this.config, connection: this});
|
||||
this._connectCalled = false;
|
||||
this.state = 'disconnected';
|
||||
this.threadId = null;
|
||||
}
|
||||
|
||||
Connection.createQuery = function createQuery(sql, values, callback) {
|
||||
if (sql instanceof Query) {
|
||||
return sql;
|
||||
}
|
||||
|
||||
var cb = callback;
|
||||
var options = {};
|
||||
|
||||
if (typeof sql === 'function') {
|
||||
cb = sql;
|
||||
} else if (typeof sql === 'object') {
|
||||
options = Object.create(sql);
|
||||
|
||||
if (typeof values === 'function') {
|
||||
cb = values;
|
||||
} else if (values !== undefined) {
|
||||
Object.defineProperty(options, 'values', { value: values });
|
||||
}
|
||||
} else {
|
||||
options.sql = sql;
|
||||
|
||||
if (typeof values === 'function') {
|
||||
cb = values;
|
||||
} else if (values !== undefined) {
|
||||
options.values = values;
|
||||
}
|
||||
}
|
||||
|
||||
if (cb !== undefined) {
|
||||
cb = wrapCallbackInDomain(null, cb);
|
||||
|
||||
if (cb === undefined) {
|
||||
throw new TypeError('argument callback must be a function when provided');
|
||||
}
|
||||
}
|
||||
|
||||
return new Query(options, cb);
|
||||
};
|
||||
|
||||
Connection.prototype.connect = function connect(options, callback) {
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (!this._connectCalled) {
|
||||
this._connectCalled = true;
|
||||
|
||||
// Connect either via a UNIX domain socket or a TCP socket.
|
||||
this._socket = (this.config.socketPath)
|
||||
? Net.createConnection(this.config.socketPath)
|
||||
: Net.createConnection(this.config.port, this.config.host);
|
||||
|
||||
// Connect socket to connection domain
|
||||
if (Events.usingDomains) {
|
||||
this._socket.domain = this.domain;
|
||||
}
|
||||
|
||||
var connection = this;
|
||||
this._protocol.on('data', function(data) {
|
||||
connection._socket.write(data);
|
||||
});
|
||||
this._socket.on('data', wrapToDomain(connection, function (data) {
|
||||
connection._protocol.write(data);
|
||||
}));
|
||||
this._protocol.on('end', function() {
|
||||
connection._socket.end();
|
||||
});
|
||||
this._socket.on('end', wrapToDomain(connection, function () {
|
||||
connection._protocol.end();
|
||||
}));
|
||||
|
||||
this._socket.on('error', this._handleNetworkError.bind(this));
|
||||
this._socket.on('connect', this._handleProtocolConnect.bind(this));
|
||||
this._protocol.on('handshake', this._handleProtocolHandshake.bind(this));
|
||||
this._protocol.on('initialize', this._handleProtocolInitialize.bind(this));
|
||||
this._protocol.on('unhandledError', this._handleProtocolError.bind(this));
|
||||
this._protocol.on('drain', this._handleProtocolDrain.bind(this));
|
||||
this._protocol.on('end', this._handleProtocolEnd.bind(this));
|
||||
this._protocol.on('enqueue', this._handleProtocolEnqueue.bind(this));
|
||||
|
||||
if (this.config.connectTimeout) {
|
||||
var handleConnectTimeout = this._handleConnectTimeout.bind(this);
|
||||
|
||||
this._socket.setTimeout(this.config.connectTimeout, handleConnectTimeout);
|
||||
this._socket.once('connect', function() {
|
||||
this.setTimeout(0, handleConnectTimeout);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this._protocol.handshake(options, wrapCallbackInDomain(this, callback));
|
||||
};
|
||||
|
||||
Connection.prototype.changeUser = function changeUser(options, callback) {
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
this._implyConnect();
|
||||
|
||||
var charsetNumber = (options.charset)
|
||||
? ConnectionConfig.getCharsetNumber(options.charset)
|
||||
: this.config.charsetNumber;
|
||||
|
||||
return this._protocol.changeUser({
|
||||
user : options.user || this.config.user,
|
||||
password : options.password || this.config.password,
|
||||
database : options.database || this.config.database,
|
||||
timeout : options.timeout,
|
||||
charsetNumber : charsetNumber,
|
||||
currentConfig : this.config
|
||||
}, wrapCallbackInDomain(this, callback));
|
||||
};
|
||||
|
||||
Connection.prototype.beginTransaction = function beginTransaction(options, callback) {
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
options.sql = 'START TRANSACTION';
|
||||
options.values = null;
|
||||
|
||||
return this.query(options, callback);
|
||||
};
|
||||
|
||||
Connection.prototype.commit = function commit(options, callback) {
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
options.sql = 'COMMIT';
|
||||
options.values = null;
|
||||
|
||||
return this.query(options, callback);
|
||||
};
|
||||
|
||||
Connection.prototype.rollback = function rollback(options, callback) {
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
options.sql = 'ROLLBACK';
|
||||
options.values = null;
|
||||
|
||||
return this.query(options, callback);
|
||||
};
|
||||
|
||||
Connection.prototype.query = function query(sql, values, cb) {
|
||||
var query = Connection.createQuery(sql, values, cb);
|
||||
query._connection = this;
|
||||
|
||||
if (!(typeof sql === 'object' && 'typeCast' in sql)) {
|
||||
query.typeCast = this.config.typeCast;
|
||||
}
|
||||
|
||||
if (query.sql) {
|
||||
query.sql = this.format(query.sql, query.values);
|
||||
}
|
||||
|
||||
if (query._callback) {
|
||||
query._callback = wrapCallbackInDomain(this, query._callback);
|
||||
}
|
||||
|
||||
this._implyConnect();
|
||||
|
||||
return this._protocol._enqueue(query);
|
||||
};
|
||||
|
||||
Connection.prototype.ping = function ping(options, callback) {
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
this._implyConnect();
|
||||
this._protocol.ping(options, wrapCallbackInDomain(this, callback));
|
||||
};
|
||||
|
||||
Connection.prototype.statistics = function statistics(options, callback) {
|
||||
if (!callback && typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
this._implyConnect();
|
||||
this._protocol.stats(options, wrapCallbackInDomain(this, callback));
|
||||
};
|
||||
|
||||
Connection.prototype.end = function end(options, callback) {
|
||||
var cb = callback;
|
||||
var opts = options;
|
||||
|
||||
if (!callback && typeof options === 'function') {
|
||||
cb = options;
|
||||
opts = null;
|
||||
}
|
||||
|
||||
// create custom options reference
|
||||
opts = Object.create(opts || null);
|
||||
|
||||
if (opts.timeout === undefined) {
|
||||
// default timeout of 30 seconds
|
||||
opts.timeout = 30000;
|
||||
}
|
||||
|
||||
this._implyConnect();
|
||||
this._protocol.quit(opts, wrapCallbackInDomain(this, cb));
|
||||
};
|
||||
|
||||
Connection.prototype.destroy = function() {
|
||||
this.state = 'disconnected';
|
||||
this._implyConnect();
|
||||
this._socket.destroy();
|
||||
this._protocol.destroy();
|
||||
};
|
||||
|
||||
Connection.prototype.pause = function() {
|
||||
this._socket.pause();
|
||||
this._protocol.pause();
|
||||
};
|
||||
|
||||
Connection.prototype.resume = function() {
|
||||
this._socket.resume();
|
||||
this._protocol.resume();
|
||||
};
|
||||
|
||||
Connection.prototype.escape = function(value) {
|
||||
return SqlString.escape(value, false, this.config.timezone);
|
||||
};
|
||||
|
||||
Connection.prototype.escapeId = function escapeId(value) {
|
||||
return SqlString.escapeId(value, false);
|
||||
};
|
||||
|
||||
Connection.prototype.format = function(sql, values) {
|
||||
if (typeof this.config.queryFormat === 'function') {
|
||||
return this.config.queryFormat.call(this, sql, values, this.config.timezone);
|
||||
}
|
||||
return SqlString.format(sql, values, this.config.stringifyObjects, this.config.timezone);
|
||||
};
|
||||
|
||||
if (tls.TLSSocket) {
|
||||
// 0.11+ environment
|
||||
Connection.prototype._startTLS = function _startTLS(onSecure) {
|
||||
var connection = this;
|
||||
|
||||
createSecureContext(this.config, function (err, secureContext) {
|
||||
if (err) {
|
||||
onSecure(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// "unpipe"
|
||||
connection._socket.removeAllListeners('data');
|
||||
connection._protocol.removeAllListeners('data');
|
||||
|
||||
// socket <-> encrypted
|
||||
var rejectUnauthorized = connection.config.ssl.rejectUnauthorized;
|
||||
var secureEstablished = false;
|
||||
var secureSocket = new tls.TLSSocket(connection._socket, {
|
||||
rejectUnauthorized : rejectUnauthorized,
|
||||
requestCert : true,
|
||||
secureContext : secureContext,
|
||||
isServer : false
|
||||
});
|
||||
|
||||
// error handler for secure socket
|
||||
secureSocket.on('_tlsError', function(err) {
|
||||
if (secureEstablished) {
|
||||
connection._handleNetworkError(err);
|
||||
} else {
|
||||
onSecure(err);
|
||||
}
|
||||
});
|
||||
|
||||
// cleartext <-> protocol
|
||||
secureSocket.pipe(connection._protocol);
|
||||
connection._protocol.on('data', function(data) {
|
||||
secureSocket.write(data);
|
||||
});
|
||||
|
||||
secureSocket.on('secure', function() {
|
||||
secureEstablished = true;
|
||||
|
||||
onSecure(rejectUnauthorized ? this.ssl.verifyError() : null);
|
||||
});
|
||||
|
||||
// start TLS communications
|
||||
secureSocket._start();
|
||||
});
|
||||
};
|
||||
} else {
|
||||
// pre-0.11 environment
|
||||
Connection.prototype._startTLS = function _startTLS(onSecure) {
|
||||
// before TLS:
|
||||
// _socket <-> _protocol
|
||||
// after:
|
||||
// _socket <-> securePair.encrypted <-> securePair.cleartext <-> _protocol
|
||||
|
||||
var connection = this;
|
||||
var credentials = Crypto.createCredentials({
|
||||
ca : this.config.ssl.ca,
|
||||
cert : this.config.ssl.cert,
|
||||
ciphers : this.config.ssl.ciphers,
|
||||
key : this.config.ssl.key,
|
||||
passphrase : this.config.ssl.passphrase
|
||||
});
|
||||
|
||||
var rejectUnauthorized = this.config.ssl.rejectUnauthorized;
|
||||
var secureEstablished = false;
|
||||
var securePair = tls.createSecurePair(credentials, false, true, rejectUnauthorized);
|
||||
|
||||
// error handler for secure pair
|
||||
securePair.on('error', function(err) {
|
||||
if (secureEstablished) {
|
||||
connection._handleNetworkError(err);
|
||||
} else {
|
||||
onSecure(err);
|
||||
}
|
||||
});
|
||||
|
||||
// "unpipe"
|
||||
this._socket.removeAllListeners('data');
|
||||
this._protocol.removeAllListeners('data');
|
||||
|
||||
// socket <-> encrypted
|
||||
securePair.encrypted.pipe(this._socket);
|
||||
this._socket.on('data', function(data) {
|
||||
securePair.encrypted.write(data);
|
||||
});
|
||||
|
||||
// cleartext <-> protocol
|
||||
securePair.cleartext.pipe(this._protocol);
|
||||
this._protocol.on('data', function(data) {
|
||||
securePair.cleartext.write(data);
|
||||
});
|
||||
|
||||
// secure established
|
||||
securePair.on('secure', function() {
|
||||
secureEstablished = true;
|
||||
|
||||
if (!rejectUnauthorized) {
|
||||
onSecure();
|
||||
return;
|
||||
}
|
||||
|
||||
var verifyError = this.ssl.verifyError();
|
||||
var err = verifyError;
|
||||
|
||||
// node.js 0.6 support
|
||||
if (typeof err === 'string') {
|
||||
err = new Error(verifyError);
|
||||
err.code = verifyError;
|
||||
}
|
||||
|
||||
onSecure(err);
|
||||
});
|
||||
|
||||
// node.js 0.8 bug
|
||||
securePair._cycle = securePair.cycle;
|
||||
securePair.cycle = function cycle() {
|
||||
if (this.ssl && this.ssl.error) {
|
||||
this.error();
|
||||
}
|
||||
|
||||
return this._cycle.apply(this, arguments);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Connection.prototype._handleConnectTimeout = function() {
|
||||
if (this._socket) {
|
||||
this._socket.setTimeout(0);
|
||||
this._socket.destroy();
|
||||
}
|
||||
|
||||
var err = new Error('connect ETIMEDOUT');
|
||||
err.errorno = 'ETIMEDOUT';
|
||||
err.code = 'ETIMEDOUT';
|
||||
err.syscall = 'connect';
|
||||
|
||||
this._handleNetworkError(err);
|
||||
};
|
||||
|
||||
Connection.prototype._handleNetworkError = function(err) {
|
||||
this._protocol.handleNetworkError(err);
|
||||
};
|
||||
|
||||
Connection.prototype._handleProtocolError = function(err) {
|
||||
this.state = 'protocol_error';
|
||||
this.emit('error', err);
|
||||
};
|
||||
|
||||
Connection.prototype._handleProtocolDrain = function() {
|
||||
this.emit('drain');
|
||||
};
|
||||
|
||||
Connection.prototype._handleProtocolConnect = function() {
|
||||
this.state = 'connected';
|
||||
this.emit('connect');
|
||||
};
|
||||
|
||||
Connection.prototype._handleProtocolHandshake = function _handleProtocolHandshake() {
|
||||
this.state = 'authenticated';
|
||||
};
|
||||
|
||||
Connection.prototype._handleProtocolInitialize = function _handleProtocolInitialize(packet) {
|
||||
this.threadId = packet.threadId;
|
||||
};
|
||||
|
||||
Connection.prototype._handleProtocolEnd = function(err) {
|
||||
this.state = 'disconnected';
|
||||
this.emit('end', err);
|
||||
};
|
||||
|
||||
Connection.prototype._handleProtocolEnqueue = function _handleProtocolEnqueue(sequence) {
|
||||
this.emit('enqueue', sequence);
|
||||
};
|
||||
|
||||
Connection.prototype._implyConnect = function() {
|
||||
if (!this._connectCalled) {
|
||||
this.connect();
|
||||
}
|
||||
};
|
||||
|
||||
function createSecureContext (config, cb) {
|
||||
var context = null;
|
||||
var error = null;
|
||||
|
||||
try {
|
||||
context = tls.createSecureContext({
|
||||
ca : config.ssl.ca,
|
||||
cert : config.ssl.cert,
|
||||
ciphers : config.ssl.ciphers,
|
||||
key : config.ssl.key,
|
||||
passphrase : config.ssl.passphrase
|
||||
});
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
|
||||
cb(error, context);
|
||||
}
|
||||
|
||||
function unwrapFromDomain(fn) {
|
||||
return function () {
|
||||
var domains = [];
|
||||
var ret;
|
||||
|
||||
while (process.domain) {
|
||||
domains.shift(process.domain);
|
||||
process.domain.exit();
|
||||
}
|
||||
|
||||
try {
|
||||
ret = fn.apply(this, arguments);
|
||||
} finally {
|
||||
for (var i = 0; i < domains.length; i++) {
|
||||
domains[i].enter();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
function wrapCallbackInDomain(ee, fn) {
|
||||
if (typeof fn !== 'function') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (fn.domain) {
|
||||
return fn;
|
||||
}
|
||||
|
||||
var domain = process.domain;
|
||||
|
||||
if (domain) {
|
||||
return domain.bind(fn);
|
||||
} else if (ee) {
|
||||
return unwrapFromDomain(wrapToDomain(ee, fn));
|
||||
} else {
|
||||
return fn;
|
||||
}
|
||||
}
|
||||
|
||||
function wrapToDomain(ee, fn) {
|
||||
return function () {
|
||||
if (Events.usingDomains && ee.domain) {
|
||||
ee.domain.enter();
|
||||
fn.apply(this, arguments);
|
||||
ee.domain.exit();
|
||||
} else {
|
||||
fn.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
209
node_modules/mysql/lib/ConnectionConfig.js
generated
vendored
Normal file
209
node_modules/mysql/lib/ConnectionConfig.js
generated
vendored
Normal file
@ -0,0 +1,209 @@
|
||||
var urlParse = require('url').parse;
|
||||
var ClientConstants = require('./protocol/constants/client');
|
||||
var Charsets = require('./protocol/constants/charsets');
|
||||
var SSLProfiles = null;
|
||||
|
||||
module.exports = ConnectionConfig;
|
||||
function ConnectionConfig(options) {
|
||||
if (typeof options === 'string') {
|
||||
options = ConnectionConfig.parseUrl(options);
|
||||
}
|
||||
|
||||
this.host = options.host || 'localhost';
|
||||
this.port = options.port || 3306;
|
||||
this.localAddress = options.localAddress;
|
||||
this.socketPath = options.socketPath;
|
||||
this.user = options.user || undefined;
|
||||
this.password = options.password || undefined;
|
||||
this.database = options.database;
|
||||
this.connectTimeout = (options.connectTimeout === undefined)
|
||||
? (10 * 1000)
|
||||
: options.connectTimeout;
|
||||
this.insecureAuth = options.insecureAuth || false;
|
||||
this.supportBigNumbers = options.supportBigNumbers || false;
|
||||
this.bigNumberStrings = options.bigNumberStrings || false;
|
||||
this.dateStrings = options.dateStrings || false;
|
||||
this.debug = options.debug;
|
||||
this.trace = options.trace !== false;
|
||||
this.stringifyObjects = options.stringifyObjects || false;
|
||||
this.timezone = options.timezone || 'local';
|
||||
this.flags = options.flags || '';
|
||||
this.queryFormat = options.queryFormat;
|
||||
this.pool = options.pool || undefined;
|
||||
this.ssl = (typeof options.ssl === 'string')
|
||||
? ConnectionConfig.getSSLProfile(options.ssl)
|
||||
: (options.ssl || false);
|
||||
this.localInfile = (options.localInfile === undefined)
|
||||
? true
|
||||
: options.localInfile;
|
||||
this.multipleStatements = options.multipleStatements || false;
|
||||
this.typeCast = (options.typeCast === undefined)
|
||||
? true
|
||||
: options.typeCast;
|
||||
|
||||
if (this.timezone[0] === ' ') {
|
||||
// "+" is a url encoded char for space so it
|
||||
// gets translated to space when giving a
|
||||
// connection string..
|
||||
this.timezone = '+' + this.timezone.substr(1);
|
||||
}
|
||||
|
||||
if (this.ssl) {
|
||||
// Default rejectUnauthorized to true
|
||||
this.ssl.rejectUnauthorized = this.ssl.rejectUnauthorized !== false;
|
||||
}
|
||||
|
||||
this.maxPacketSize = 0;
|
||||
this.charsetNumber = (options.charset)
|
||||
? ConnectionConfig.getCharsetNumber(options.charset)
|
||||
: options.charsetNumber || Charsets.UTF8_GENERAL_CI;
|
||||
|
||||
// Set the client flags
|
||||
var defaultFlags = ConnectionConfig.getDefaultFlags(options);
|
||||
this.clientFlags = ConnectionConfig.mergeFlags(defaultFlags, options.flags);
|
||||
}
|
||||
|
||||
ConnectionConfig.mergeFlags = function mergeFlags(defaultFlags, userFlags) {
|
||||
var allFlags = ConnectionConfig.parseFlagList(defaultFlags);
|
||||
var newFlags = ConnectionConfig.parseFlagList(userFlags);
|
||||
|
||||
// Merge the new flags
|
||||
for (var flag in newFlags) {
|
||||
if (allFlags[flag] !== false) {
|
||||
allFlags[flag] = newFlags[flag];
|
||||
}
|
||||
}
|
||||
|
||||
// Build flags
|
||||
var flags = 0x0;
|
||||
for (var flag in allFlags) {
|
||||
if (allFlags[flag]) {
|
||||
// TODO: Throw here on some future release
|
||||
flags |= ClientConstants['CLIENT_' + flag] || 0x0;
|
||||
}
|
||||
}
|
||||
|
||||
return flags;
|
||||
};
|
||||
|
||||
ConnectionConfig.getCharsetNumber = function getCharsetNumber(charset) {
|
||||
var num = Charsets[charset.toUpperCase()];
|
||||
|
||||
if (num === undefined) {
|
||||
throw new TypeError('Unknown charset \'' + charset + '\'');
|
||||
}
|
||||
|
||||
return num;
|
||||
};
|
||||
|
||||
ConnectionConfig.getDefaultFlags = function getDefaultFlags(options) {
|
||||
var defaultFlags = [
|
||||
'-COMPRESS', // Compression protocol *NOT* supported
|
||||
'-CONNECT_ATTRS', // Does *NOT* send connection attributes in Protocol::HandshakeResponse41
|
||||
'+CONNECT_WITH_DB', // One can specify db on connect in Handshake Response Packet
|
||||
'+FOUND_ROWS', // Send found rows instead of affected rows
|
||||
'+IGNORE_SIGPIPE', // Don't issue SIGPIPE if network failures
|
||||
'+IGNORE_SPACE', // Let the parser ignore spaces before '('
|
||||
'+LOCAL_FILES', // Can use LOAD DATA LOCAL
|
||||
'+LONG_FLAG', // Longer flags in Protocol::ColumnDefinition320
|
||||
'+LONG_PASSWORD', // Use the improved version of Old Password Authentication
|
||||
'+MULTI_RESULTS', // Can handle multiple resultsets for COM_QUERY
|
||||
'+ODBC', // Special handling of ODBC behaviour
|
||||
'-PLUGIN_AUTH', // Does *NOT* support auth plugins
|
||||
'+PROTOCOL_41', // Uses the 4.1 protocol
|
||||
'+PS_MULTI_RESULTS', // Can handle multiple resultsets for COM_STMT_EXECUTE
|
||||
'+RESERVED', // Unused
|
||||
'+SECURE_CONNECTION', // Supports Authentication::Native41
|
||||
'+TRANSACTIONS' // Expects status flags
|
||||
];
|
||||
|
||||
if (options && options.localInfile !== undefined && !options.localInfile) {
|
||||
// Disable LOCAL modifier for LOAD DATA INFILE
|
||||
defaultFlags.push('-LOCAL_FILES');
|
||||
}
|
||||
|
||||
if (options && options.multipleStatements) {
|
||||
// May send multiple statements per COM_QUERY and COM_STMT_PREPARE
|
||||
defaultFlags.push('+MULTI_STATEMENTS');
|
||||
}
|
||||
|
||||
return defaultFlags;
|
||||
};
|
||||
|
||||
ConnectionConfig.getSSLProfile = function getSSLProfile(name) {
|
||||
if (!SSLProfiles) {
|
||||
SSLProfiles = require('./protocol/constants/ssl_profiles');
|
||||
}
|
||||
|
||||
var ssl = SSLProfiles[name];
|
||||
|
||||
if (ssl === undefined) {
|
||||
throw new TypeError('Unknown SSL profile \'' + name + '\'');
|
||||
}
|
||||
|
||||
return ssl;
|
||||
};
|
||||
|
||||
ConnectionConfig.parseFlagList = function parseFlagList(flagList) {
|
||||
var allFlags = Object.create(null);
|
||||
|
||||
if (!flagList) {
|
||||
return allFlags;
|
||||
}
|
||||
|
||||
var flags = !Array.isArray(flagList)
|
||||
? String(flagList || '').toUpperCase().split(/\s*,+\s*/)
|
||||
: flagList;
|
||||
|
||||
for (var i = 0; i < flags.length; i++) {
|
||||
var flag = flags[i];
|
||||
var offset = 1;
|
||||
var state = flag[0];
|
||||
|
||||
if (state === undefined) {
|
||||
// TODO: throw here on some future release
|
||||
continue;
|
||||
}
|
||||
|
||||
if (state !== '-' && state !== '+') {
|
||||
offset = 0;
|
||||
state = '+';
|
||||
}
|
||||
|
||||
allFlags[flag.substr(offset)] = state === '+';
|
||||
}
|
||||
|
||||
return allFlags;
|
||||
};
|
||||
|
||||
ConnectionConfig.parseUrl = function(url) {
|
||||
url = urlParse(url, true);
|
||||
|
||||
var options = {
|
||||
host : url.hostname,
|
||||
port : url.port,
|
||||
database : url.pathname.substr(1)
|
||||
};
|
||||
|
||||
if (url.auth) {
|
||||
var auth = url.auth.split(':');
|
||||
options.user = auth.shift();
|
||||
options.password = auth.join(':');
|
||||
}
|
||||
|
||||
if (url.query) {
|
||||
for (var key in url.query) {
|
||||
var value = url.query[key];
|
||||
|
||||
try {
|
||||
// Try to parse this as a JSON expression first
|
||||
options[key] = JSON.parse(value);
|
||||
} catch (err) {
|
||||
// Otherwise assume it is a plain string
|
||||
options[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
};
|
||||
294
node_modules/mysql/lib/Pool.js
generated
vendored
Normal file
294
node_modules/mysql/lib/Pool.js
generated
vendored
Normal file
@ -0,0 +1,294 @@
|
||||
var mysql = require('../');
|
||||
var Connection = require('./Connection');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Util = require('util');
|
||||
var PoolConnection = require('./PoolConnection');
|
||||
|
||||
module.exports = Pool;
|
||||
|
||||
Util.inherits(Pool, EventEmitter);
|
||||
function Pool(options) {
|
||||
EventEmitter.call(this);
|
||||
this.config = options.config;
|
||||
this.config.connectionConfig.pool = this;
|
||||
|
||||
this._acquiringConnections = [];
|
||||
this._allConnections = [];
|
||||
this._freeConnections = [];
|
||||
this._connectionQueue = [];
|
||||
this._closed = false;
|
||||
}
|
||||
|
||||
Pool.prototype.getConnection = function (cb) {
|
||||
|
||||
if (this._closed) {
|
||||
var err = new Error('Pool is closed.');
|
||||
err.code = 'POOL_CLOSED';
|
||||
process.nextTick(function () {
|
||||
cb(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var connection;
|
||||
var pool = this;
|
||||
|
||||
if (this._freeConnections.length > 0) {
|
||||
connection = this._freeConnections.shift();
|
||||
this.acquireConnection(connection, cb);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.config.connectionLimit === 0 || this._allConnections.length < this.config.connectionLimit) {
|
||||
connection = new PoolConnection(this, { config: this.config.newConnectionConfig() });
|
||||
|
||||
this._acquiringConnections.push(connection);
|
||||
this._allConnections.push(connection);
|
||||
|
||||
connection.connect({timeout: this.config.acquireTimeout}, function onConnect(err) {
|
||||
spliceConnection(pool._acquiringConnections, connection);
|
||||
|
||||
if (pool._closed) {
|
||||
err = new Error('Pool is closed.');
|
||||
err.code = 'POOL_CLOSED';
|
||||
}
|
||||
|
||||
if (err) {
|
||||
pool._purgeConnection(connection);
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
pool.emit('connection', connection);
|
||||
pool.emit('acquire', connection);
|
||||
cb(null, connection);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.config.waitForConnections) {
|
||||
process.nextTick(function(){
|
||||
var err = new Error('No connections available.');
|
||||
err.code = 'POOL_CONNLIMIT';
|
||||
cb(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this._enqueueCallback(cb);
|
||||
};
|
||||
|
||||
Pool.prototype.acquireConnection = function acquireConnection(connection, cb) {
|
||||
if (connection._pool !== this) {
|
||||
throw new Error('Connection acquired from wrong pool.');
|
||||
}
|
||||
|
||||
var changeUser = this._needsChangeUser(connection);
|
||||
var pool = this;
|
||||
|
||||
this._acquiringConnections.push(connection);
|
||||
|
||||
function onOperationComplete(err) {
|
||||
spliceConnection(pool._acquiringConnections, connection);
|
||||
|
||||
if (pool._closed) {
|
||||
err = new Error('Pool is closed.');
|
||||
err.code = 'POOL_CLOSED';
|
||||
}
|
||||
|
||||
if (err) {
|
||||
pool._connectionQueue.unshift(cb);
|
||||
pool._purgeConnection(connection);
|
||||
return;
|
||||
}
|
||||
|
||||
if (changeUser) {
|
||||
pool.emit('connection', connection);
|
||||
}
|
||||
|
||||
pool.emit('acquire', connection);
|
||||
cb(null, connection);
|
||||
}
|
||||
|
||||
if (changeUser) {
|
||||
// restore user back to pool configuration
|
||||
connection.config = this.config.newConnectionConfig();
|
||||
connection.changeUser({timeout: this.config.acquireTimeout}, onOperationComplete);
|
||||
} else {
|
||||
// ping connection
|
||||
connection.ping({timeout: this.config.acquireTimeout}, onOperationComplete);
|
||||
}
|
||||
};
|
||||
|
||||
Pool.prototype.releaseConnection = function releaseConnection(connection) {
|
||||
|
||||
if (this._acquiringConnections.indexOf(connection) !== -1) {
|
||||
// connection is being acquired
|
||||
return;
|
||||
}
|
||||
|
||||
if (connection._pool) {
|
||||
if (connection._pool !== this) {
|
||||
throw new Error('Connection released to wrong pool');
|
||||
}
|
||||
|
||||
if (this._freeConnections.indexOf(connection) !== -1) {
|
||||
// connection already in free connection pool
|
||||
// this won't catch all double-release cases
|
||||
throw new Error('Connection already released');
|
||||
} else {
|
||||
// add connection to end of free queue
|
||||
this._freeConnections.push(connection);
|
||||
this.emit('release', connection);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._closed) {
|
||||
// empty the connection queue
|
||||
this._connectionQueue.splice(0).forEach(function (cb) {
|
||||
var err = new Error('Pool is closed.');
|
||||
err.code = 'POOL_CLOSED';
|
||||
process.nextTick(function () {
|
||||
cb(err);
|
||||
});
|
||||
});
|
||||
} else if (this._connectionQueue.length) {
|
||||
// get connection with next waiting callback
|
||||
this.getConnection(this._connectionQueue.shift());
|
||||
}
|
||||
};
|
||||
|
||||
Pool.prototype.end = function (cb) {
|
||||
this._closed = true;
|
||||
|
||||
if (typeof cb !== 'function') {
|
||||
cb = function (err) {
|
||||
if (err) throw err;
|
||||
};
|
||||
}
|
||||
|
||||
var calledBack = false;
|
||||
var waitingClose = 0;
|
||||
|
||||
function onEnd(err) {
|
||||
if (!calledBack && (err || --waitingClose <= 0)) {
|
||||
calledBack = true;
|
||||
cb(err);
|
||||
}
|
||||
}
|
||||
|
||||
while (this._allConnections.length !== 0) {
|
||||
waitingClose++;
|
||||
this._purgeConnection(this._allConnections[0], onEnd);
|
||||
}
|
||||
|
||||
if (waitingClose === 0) {
|
||||
process.nextTick(onEnd);
|
||||
}
|
||||
};
|
||||
|
||||
Pool.prototype.query = function (sql, values, cb) {
|
||||
var query = Connection.createQuery(sql, values, cb);
|
||||
|
||||
if (!(typeof sql === 'object' && 'typeCast' in sql)) {
|
||||
query.typeCast = this.config.connectionConfig.typeCast;
|
||||
}
|
||||
|
||||
if (this.config.connectionConfig.trace) {
|
||||
// Long stack trace support
|
||||
query._callSite = new Error();
|
||||
}
|
||||
|
||||
this.getConnection(function (err, conn) {
|
||||
if (err) {
|
||||
query.on('error', function () {});
|
||||
query.end(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Release connection based off event
|
||||
query.once('end', function() {
|
||||
conn.release();
|
||||
});
|
||||
|
||||
conn.query(query);
|
||||
});
|
||||
|
||||
return query;
|
||||
};
|
||||
|
||||
Pool.prototype._enqueueCallback = function _enqueueCallback(callback) {
|
||||
|
||||
if (this.config.queueLimit && this._connectionQueue.length >= this.config.queueLimit) {
|
||||
process.nextTick(function () {
|
||||
var err = new Error('Queue limit reached.');
|
||||
err.code = 'POOL_ENQUEUELIMIT';
|
||||
callback(err);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind to domain, as dequeue will likely occur in a different domain
|
||||
var cb = process.domain
|
||||
? process.domain.bind(callback)
|
||||
: callback;
|
||||
|
||||
this._connectionQueue.push(cb);
|
||||
this.emit('enqueue');
|
||||
};
|
||||
|
||||
Pool.prototype._needsChangeUser = function _needsChangeUser(connection) {
|
||||
var connConfig = connection.config;
|
||||
var poolConfig = this.config.connectionConfig;
|
||||
|
||||
// check if changeUser values are different
|
||||
return connConfig.user !== poolConfig.user
|
||||
|| connConfig.database !== poolConfig.database
|
||||
|| connConfig.password !== poolConfig.password
|
||||
|| connConfig.charsetNumber !== poolConfig.charsetNumber;
|
||||
};
|
||||
|
||||
Pool.prototype._purgeConnection = function _purgeConnection(connection, callback) {
|
||||
var cb = callback || function () {};
|
||||
|
||||
if (connection.state === 'disconnected') {
|
||||
connection.destroy();
|
||||
}
|
||||
|
||||
this._removeConnection(connection);
|
||||
|
||||
if (connection.state !== 'disconnected' && !connection._protocol._quitSequence) {
|
||||
connection._realEnd(cb);
|
||||
return;
|
||||
}
|
||||
|
||||
process.nextTick(cb);
|
||||
};
|
||||
|
||||
Pool.prototype._removeConnection = function(connection) {
|
||||
connection._pool = null;
|
||||
|
||||
// Remove connection from all connections
|
||||
spliceConnection(this._allConnections, connection);
|
||||
|
||||
// Remove connection from free connections
|
||||
spliceConnection(this._freeConnections, connection);
|
||||
|
||||
this.releaseConnection(connection);
|
||||
};
|
||||
|
||||
Pool.prototype.escape = function(value) {
|
||||
return mysql.escape(value, this.config.connectionConfig.stringifyObjects, this.config.connectionConfig.timezone);
|
||||
};
|
||||
|
||||
Pool.prototype.escapeId = function escapeId(value) {
|
||||
return mysql.escapeId(value, false);
|
||||
};
|
||||
|
||||
function spliceConnection(array, connection) {
|
||||
var index;
|
||||
if ((index = array.indexOf(connection)) !== -1) {
|
||||
// Remove connection from all connections
|
||||
array.splice(index, 1);
|
||||
}
|
||||
}
|
||||
288
node_modules/mysql/lib/PoolCluster.js
generated
vendored
Normal file
288
node_modules/mysql/lib/PoolCluster.js
generated
vendored
Normal file
@ -0,0 +1,288 @@
|
||||
var Pool = require('./Pool');
|
||||
var PoolConfig = require('./PoolConfig');
|
||||
var PoolNamespace = require('./PoolNamespace');
|
||||
var PoolSelector = require('./PoolSelector');
|
||||
var Util = require('util');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
module.exports = PoolCluster;
|
||||
|
||||
/**
|
||||
* PoolCluster
|
||||
* @constructor
|
||||
* @param {object} [config] The pool cluster configuration
|
||||
* @public
|
||||
*/
|
||||
function PoolCluster(config) {
|
||||
EventEmitter.call(this);
|
||||
|
||||
config = config || {};
|
||||
this._canRetry = typeof config.canRetry === 'undefined' ? true : config.canRetry;
|
||||
this._defaultSelector = config.defaultSelector || 'RR';
|
||||
this._removeNodeErrorCount = config.removeNodeErrorCount || 5;
|
||||
this._restoreNodeTimeout = config.restoreNodeTimeout || 0;
|
||||
|
||||
this._closed = false;
|
||||
this._findCaches = Object.create(null);
|
||||
this._lastId = 0;
|
||||
this._namespaces = Object.create(null);
|
||||
this._nodes = Object.create(null);
|
||||
}
|
||||
|
||||
Util.inherits(PoolCluster, EventEmitter);
|
||||
|
||||
PoolCluster.prototype.add = function add(id, config) {
|
||||
if (this._closed) {
|
||||
throw new Error('PoolCluster is closed.');
|
||||
}
|
||||
|
||||
var nodeId = typeof id === 'object'
|
||||
? 'CLUSTER::' + (++this._lastId)
|
||||
: String(id);
|
||||
|
||||
if (this._nodes[nodeId] !== undefined) {
|
||||
throw new Error('Node ID "' + nodeId + '" is already defined in PoolCluster.');
|
||||
}
|
||||
|
||||
var poolConfig = typeof id !== 'object'
|
||||
? new PoolConfig(config)
|
||||
: new PoolConfig(id);
|
||||
|
||||
this._nodes[nodeId] = {
|
||||
id : nodeId,
|
||||
errorCount : 0,
|
||||
pool : new Pool({config: poolConfig}),
|
||||
_offlineUntil : 0
|
||||
};
|
||||
|
||||
this._clearFindCaches();
|
||||
};
|
||||
|
||||
PoolCluster.prototype.end = function end(callback) {
|
||||
var cb = callback !== undefined
|
||||
? callback
|
||||
: _cb;
|
||||
|
||||
if (typeof cb !== 'function') {
|
||||
throw TypeError('callback argument must be a function');
|
||||
}
|
||||
|
||||
if (this._closed) {
|
||||
process.nextTick(cb);
|
||||
return;
|
||||
}
|
||||
|
||||
this._closed = true;
|
||||
|
||||
var calledBack = false;
|
||||
var nodeIds = Object.keys(this._nodes);
|
||||
var waitingClose = 0;
|
||||
|
||||
function onEnd(err) {
|
||||
if (!calledBack && (err || --waitingClose <= 0)) {
|
||||
calledBack = true;
|
||||
cb(err);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < nodeIds.length; i++) {
|
||||
var nodeId = nodeIds[i];
|
||||
var node = this._nodes[nodeId];
|
||||
|
||||
waitingClose++;
|
||||
node.pool.end(onEnd);
|
||||
}
|
||||
|
||||
if (waitingClose === 0) {
|
||||
process.nextTick(onEnd);
|
||||
}
|
||||
};
|
||||
|
||||
PoolCluster.prototype.of = function(pattern, selector) {
|
||||
pattern = pattern || '*';
|
||||
|
||||
selector = selector || this._defaultSelector;
|
||||
selector = selector.toUpperCase();
|
||||
if (typeof PoolSelector[selector] === 'undefined') {
|
||||
selector = this._defaultSelector;
|
||||
}
|
||||
|
||||
var key = pattern + selector;
|
||||
|
||||
if (typeof this._namespaces[key] === 'undefined') {
|
||||
this._namespaces[key] = new PoolNamespace(this, pattern, selector);
|
||||
}
|
||||
|
||||
return this._namespaces[key];
|
||||
};
|
||||
|
||||
PoolCluster.prototype.remove = function remove(pattern) {
|
||||
var foundNodeIds = this._findNodeIds(pattern, true);
|
||||
|
||||
for (var i = 0; i < foundNodeIds.length; i++) {
|
||||
var node = this._getNode(foundNodeIds[i]);
|
||||
|
||||
if (node) {
|
||||
this._removeNode(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PoolCluster.prototype.getConnection = function(pattern, selector, cb) {
|
||||
var namespace;
|
||||
if (typeof pattern === 'function') {
|
||||
cb = pattern;
|
||||
namespace = this.of();
|
||||
} else {
|
||||
if (typeof selector === 'function') {
|
||||
cb = selector;
|
||||
selector = this._defaultSelector;
|
||||
}
|
||||
|
||||
namespace = this.of(pattern, selector);
|
||||
}
|
||||
|
||||
namespace.getConnection(cb);
|
||||
};
|
||||
|
||||
PoolCluster.prototype._clearFindCaches = function _clearFindCaches() {
|
||||
this._findCaches = Object.create(null);
|
||||
};
|
||||
|
||||
PoolCluster.prototype._decreaseErrorCount = function _decreaseErrorCount(node) {
|
||||
var errorCount = node.errorCount;
|
||||
|
||||
if (errorCount > this._removeNodeErrorCount) {
|
||||
errorCount = this._removeNodeErrorCount;
|
||||
}
|
||||
|
||||
if (errorCount < 1) {
|
||||
errorCount = 1;
|
||||
}
|
||||
|
||||
node.errorCount = errorCount - 1;
|
||||
|
||||
if (node._offlineUntil) {
|
||||
node._offlineUntil = 0;
|
||||
this.emit('online', node.id);
|
||||
}
|
||||
};
|
||||
|
||||
PoolCluster.prototype._findNodeIds = function _findNodeIds(pattern, includeOffline) {
|
||||
var currentTime = 0;
|
||||
var foundNodeIds = this._findCaches[pattern];
|
||||
|
||||
if (foundNodeIds === undefined) {
|
||||
var expression = patternRegExp(pattern);
|
||||
var nodeIds = Object.keys(this._nodes);
|
||||
|
||||
foundNodeIds = nodeIds.filter(function (id) {
|
||||
return id.match(expression);
|
||||
});
|
||||
|
||||
this._findCaches[pattern] = foundNodeIds;
|
||||
}
|
||||
|
||||
if (includeOffline) {
|
||||
return foundNodeIds;
|
||||
}
|
||||
|
||||
return foundNodeIds.filter(function (nodeId) {
|
||||
var node = this._getNode(nodeId);
|
||||
|
||||
if (!node._offlineUntil) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!currentTime) {
|
||||
currentTime = getMonotonicMilliseconds();
|
||||
}
|
||||
|
||||
return node._offlineUntil <= currentTime;
|
||||
}, this);
|
||||
};
|
||||
|
||||
PoolCluster.prototype._getNode = function _getNode(id) {
|
||||
return this._nodes[id] || null;
|
||||
};
|
||||
|
||||
PoolCluster.prototype._increaseErrorCount = function _increaseErrorCount(node) {
|
||||
var errorCount = ++node.errorCount;
|
||||
|
||||
if (this._removeNodeErrorCount > errorCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._restoreNodeTimeout > 0) {
|
||||
node._offlineUntil = getMonotonicMilliseconds() + this._restoreNodeTimeout;
|
||||
this.emit('offline', node.id);
|
||||
return;
|
||||
}
|
||||
|
||||
this._removeNode(node);
|
||||
this.emit('remove', node.id);
|
||||
};
|
||||
|
||||
PoolCluster.prototype._getConnection = function(node, cb) {
|
||||
var self = this;
|
||||
|
||||
node.pool.getConnection(function (err, connection) {
|
||||
if (err) {
|
||||
self._increaseErrorCount(node);
|
||||
cb(err);
|
||||
return;
|
||||
} else {
|
||||
self._decreaseErrorCount(node);
|
||||
}
|
||||
|
||||
connection._clusterId = node.id;
|
||||
|
||||
cb(null, connection);
|
||||
});
|
||||
};
|
||||
|
||||
PoolCluster.prototype._removeNode = function _removeNode(node) {
|
||||
delete this._nodes[node.id];
|
||||
|
||||
this._clearFindCaches();
|
||||
|
||||
node.pool.end(_noop);
|
||||
};
|
||||
|
||||
function getMonotonicMilliseconds() {
|
||||
var ms;
|
||||
|
||||
if (typeof process.hrtime === 'function') {
|
||||
ms = process.hrtime();
|
||||
ms = ms[0] * 1e3 + ms[1] * 1e-6;
|
||||
} else {
|
||||
ms = process.uptime() * 1000;
|
||||
}
|
||||
|
||||
return Math.floor(ms);
|
||||
}
|
||||
|
||||
function isRegExp(val) {
|
||||
return typeof val === 'object'
|
||||
&& Object.prototype.toString.call(val) === '[object RegExp]';
|
||||
}
|
||||
|
||||
function patternRegExp(pattern) {
|
||||
if (isRegExp(pattern)) {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
var source = pattern
|
||||
.replace(/([.+?^=!:${}()|\[\]\/\\])/g, '\\$1')
|
||||
.replace(/\*/g, '.*');
|
||||
|
||||
return new RegExp('^' + source + '$');
|
||||
}
|
||||
|
||||
function _cb(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
function _noop() {}
|
||||
32
node_modules/mysql/lib/PoolConfig.js
generated
vendored
Normal file
32
node_modules/mysql/lib/PoolConfig.js
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
var ConnectionConfig = require('./ConnectionConfig');
|
||||
|
||||
module.exports = PoolConfig;
|
||||
function PoolConfig(options) {
|
||||
if (typeof options === 'string') {
|
||||
options = ConnectionConfig.parseUrl(options);
|
||||
}
|
||||
|
||||
this.acquireTimeout = (options.acquireTimeout === undefined)
|
||||
? 10 * 1000
|
||||
: Number(options.acquireTimeout);
|
||||
this.connectionConfig = new ConnectionConfig(options);
|
||||
this.waitForConnections = (options.waitForConnections === undefined)
|
||||
? true
|
||||
: Boolean(options.waitForConnections);
|
||||
this.connectionLimit = (options.connectionLimit === undefined)
|
||||
? 10
|
||||
: Number(options.connectionLimit);
|
||||
this.queueLimit = (options.queueLimit === undefined)
|
||||
? 0
|
||||
: Number(options.queueLimit);
|
||||
}
|
||||
|
||||
PoolConfig.prototype.newConnectionConfig = function newConnectionConfig() {
|
||||
var connectionConfig = new ConnectionConfig(this.connectionConfig);
|
||||
|
||||
connectionConfig.clientFlags = this.connectionConfig.clientFlags;
|
||||
connectionConfig.maxPacketSize = this.connectionConfig.maxPacketSize;
|
||||
|
||||
return connectionConfig;
|
||||
};
|
||||
65
node_modules/mysql/lib/PoolConnection.js
generated
vendored
Normal file
65
node_modules/mysql/lib/PoolConnection.js
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
var inherits = require('util').inherits;
|
||||
var Connection = require('./Connection');
|
||||
var Events = require('events');
|
||||
|
||||
module.exports = PoolConnection;
|
||||
inherits(PoolConnection, Connection);
|
||||
|
||||
function PoolConnection(pool, options) {
|
||||
Connection.call(this, options);
|
||||
this._pool = pool;
|
||||
|
||||
// Bind connection to pool domain
|
||||
if (Events.usingDomains) {
|
||||
this.domain = pool.domain;
|
||||
}
|
||||
|
||||
// When a fatal error occurs the connection's protocol ends, which will cause
|
||||
// the connection to end as well, thus we only need to watch for the end event
|
||||
// and we will be notified of disconnects.
|
||||
this.on('end', this._removeFromPool);
|
||||
this.on('error', function (err) {
|
||||
if (err.fatal) {
|
||||
this._removeFromPool();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
PoolConnection.prototype.release = function release() {
|
||||
var pool = this._pool;
|
||||
|
||||
if (!pool || pool._closed) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return pool.releaseConnection(this);
|
||||
};
|
||||
|
||||
// TODO: Remove this when we are removing PoolConnection#end
|
||||
PoolConnection.prototype._realEnd = Connection.prototype.end;
|
||||
|
||||
PoolConnection.prototype.end = function () {
|
||||
console.warn(
|
||||
'Calling conn.end() to release a pooled connection is ' +
|
||||
'deprecated. In next version calling conn.end() will be ' +
|
||||
'restored to default conn.end() behavior. Use ' +
|
||||
'conn.release() instead.'
|
||||
);
|
||||
this.release();
|
||||
};
|
||||
|
||||
PoolConnection.prototype.destroy = function () {
|
||||
Connection.prototype.destroy.apply(this, arguments);
|
||||
this._removeFromPool(this);
|
||||
};
|
||||
|
||||
PoolConnection.prototype._removeFromPool = function _removeFromPool() {
|
||||
if (!this._pool || this._pool._closed) {
|
||||
return;
|
||||
}
|
||||
|
||||
var pool = this._pool;
|
||||
this._pool = null;
|
||||
|
||||
pool._purgeConnection(this);
|
||||
};
|
||||
136
node_modules/mysql/lib/PoolNamespace.js
generated
vendored
Normal file
136
node_modules/mysql/lib/PoolNamespace.js
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
var Connection = require('./Connection');
|
||||
var PoolSelector = require('./PoolSelector');
|
||||
|
||||
module.exports = PoolNamespace;
|
||||
|
||||
/**
|
||||
* PoolNamespace
|
||||
* @constructor
|
||||
* @param {PoolCluster} cluster The parent cluster for the namespace
|
||||
* @param {string} pattern The selection pattern to use
|
||||
* @param {string} selector The selector name to use
|
||||
* @public
|
||||
*/
|
||||
function PoolNamespace(cluster, pattern, selector) {
|
||||
this._cluster = cluster;
|
||||
this._pattern = pattern;
|
||||
this._selector = new PoolSelector[selector]();
|
||||
}
|
||||
|
||||
PoolNamespace.prototype.getConnection = function(cb) {
|
||||
var clusterNode = this._getClusterNode();
|
||||
var cluster = this._cluster;
|
||||
var namespace = this;
|
||||
|
||||
if (clusterNode === null) {
|
||||
var err = null;
|
||||
|
||||
if (this._cluster._findNodeIds(this._pattern, true).length !== 0) {
|
||||
err = new Error('Pool does not have online node.');
|
||||
err.code = 'POOL_NONEONLINE';
|
||||
} else {
|
||||
err = new Error('Pool does not exist.');
|
||||
err.code = 'POOL_NOEXIST';
|
||||
}
|
||||
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
cluster._getConnection(clusterNode, function(err, connection) {
|
||||
var retry = err && cluster._canRetry
|
||||
&& cluster._findNodeIds(namespace._pattern).length !== 0;
|
||||
|
||||
if (retry) {
|
||||
namespace.getConnection(cb);
|
||||
return;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
cb(null, connection);
|
||||
});
|
||||
};
|
||||
|
||||
PoolNamespace.prototype.query = function (sql, values, cb) {
|
||||
var cluster = this._cluster;
|
||||
var clusterNode = this._getClusterNode();
|
||||
var query = Connection.createQuery(sql, values, cb);
|
||||
var namespace = this;
|
||||
|
||||
if (clusterNode === null) {
|
||||
var err = null;
|
||||
|
||||
if (this._cluster._findNodeIds(this._pattern, true).length !== 0) {
|
||||
err = new Error('Pool does not have online node.');
|
||||
err.code = 'POOL_NONEONLINE';
|
||||
} else {
|
||||
err = new Error('Pool does not exist.');
|
||||
err.code = 'POOL_NOEXIST';
|
||||
}
|
||||
|
||||
process.nextTick(function () {
|
||||
query.on('error', function () {});
|
||||
query.end(err);
|
||||
});
|
||||
return query;
|
||||
}
|
||||
|
||||
if (!(typeof sql === 'object' && 'typeCast' in sql)) {
|
||||
query.typeCast = clusterNode.pool.config.connectionConfig.typeCast;
|
||||
}
|
||||
|
||||
if (clusterNode.pool.config.connectionConfig.trace) {
|
||||
// Long stack trace support
|
||||
query._callSite = new Error();
|
||||
}
|
||||
|
||||
cluster._getConnection(clusterNode, function (err, conn) {
|
||||
var retry = err && cluster._canRetry
|
||||
&& cluster._findNodeIds(namespace._pattern).length !== 0;
|
||||
|
||||
if (retry) {
|
||||
namespace.query(query);
|
||||
return;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
query.on('error', function () {});
|
||||
query.end(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Release connection based off event
|
||||
query.once('end', function() {
|
||||
conn.release();
|
||||
});
|
||||
|
||||
conn.query(query);
|
||||
});
|
||||
|
||||
return query;
|
||||
};
|
||||
|
||||
PoolNamespace.prototype._getClusterNode = function _getClusterNode() {
|
||||
var foundNodeIds = this._cluster._findNodeIds(this._pattern);
|
||||
var nodeId;
|
||||
|
||||
switch (foundNodeIds.length) {
|
||||
case 0:
|
||||
nodeId = null;
|
||||
break;
|
||||
case 1:
|
||||
nodeId = foundNodeIds[0];
|
||||
break;
|
||||
default:
|
||||
nodeId = this._selector(foundNodeIds);
|
||||
break;
|
||||
}
|
||||
|
||||
return nodeId !== null
|
||||
? this._cluster._getNode(nodeId)
|
||||
: null;
|
||||
};
|
||||
31
node_modules/mysql/lib/PoolSelector.js
generated
vendored
Normal file
31
node_modules/mysql/lib/PoolSelector.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
/**
|
||||
* PoolSelector
|
||||
*/
|
||||
var PoolSelector = module.exports = {};
|
||||
|
||||
PoolSelector.RR = function PoolSelectorRoundRobin() {
|
||||
var index = 0;
|
||||
|
||||
return function(clusterIds) {
|
||||
if (index >= clusterIds.length) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
var clusterId = clusterIds[index++];
|
||||
|
||||
return clusterId;
|
||||
};
|
||||
};
|
||||
|
||||
PoolSelector.RANDOM = function PoolSelectorRandom() {
|
||||
return function(clusterIds) {
|
||||
return clusterIds[Math.floor(Math.random() * clusterIds.length)];
|
||||
};
|
||||
};
|
||||
|
||||
PoolSelector.ORDER = function PoolSelectorOrder() {
|
||||
return function(clusterIds) {
|
||||
return clusterIds[0];
|
||||
};
|
||||
};
|
||||
168
node_modules/mysql/lib/protocol/Auth.js
generated
vendored
Normal file
168
node_modules/mysql/lib/protocol/Auth.js
generated
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var Crypto = require('crypto');
|
||||
var Auth = exports;
|
||||
|
||||
function auth(name, data, options) {
|
||||
options = options || {};
|
||||
|
||||
switch (name) {
|
||||
case 'mysql_native_password':
|
||||
return Auth.token(options.password, data.slice(0, 20));
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Auth.auth = auth;
|
||||
|
||||
function sha1(msg) {
|
||||
var hash = Crypto.createHash('sha1');
|
||||
hash.update(msg, 'binary');
|
||||
return hash.digest('binary');
|
||||
}
|
||||
Auth.sha1 = sha1;
|
||||
|
||||
function xor(a, b) {
|
||||
a = Buffer.from(a, 'binary');
|
||||
b = Buffer.from(b, 'binary');
|
||||
var result = Buffer.allocUnsafe(a.length);
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
result[i] = (a[i] ^ b[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Auth.xor = xor;
|
||||
|
||||
Auth.token = function(password, scramble) {
|
||||
if (!password) {
|
||||
return Buffer.alloc(0);
|
||||
}
|
||||
|
||||
// password must be in binary format, not utf8
|
||||
var stage1 = sha1((Buffer.from(password, 'utf8')).toString('binary'));
|
||||
var stage2 = sha1(stage1);
|
||||
var stage3 = sha1(scramble.toString('binary') + stage2);
|
||||
return xor(stage3, stage1);
|
||||
};
|
||||
|
||||
// This is a port of sql/password.c:hash_password which needs to be used for
|
||||
// pre-4.1 passwords.
|
||||
Auth.hashPassword = function(password) {
|
||||
var nr = [0x5030, 0x5735];
|
||||
var add = 7;
|
||||
var nr2 = [0x1234, 0x5671];
|
||||
var result = Buffer.alloc(8);
|
||||
|
||||
if (typeof password === 'string'){
|
||||
password = Buffer.from(password);
|
||||
}
|
||||
|
||||
for (var i = 0; i < password.length; i++) {
|
||||
var c = password[i];
|
||||
if (c === 32 || c === 9) {
|
||||
// skip space in password
|
||||
continue;
|
||||
}
|
||||
|
||||
// nr^= (((nr & 63)+add)*c)+ (nr << 8);
|
||||
// nr = xor(nr, add(mul(add(and(nr, 63), add), c), shl(nr, 8)))
|
||||
nr = this.xor32(nr, this.add32(this.mul32(this.add32(this.and32(nr, [0, 63]), [0, add]), [0, c]), this.shl32(nr, 8)));
|
||||
|
||||
// nr2+=(nr2 << 8) ^ nr;
|
||||
// nr2 = add(nr2, xor(shl(nr2, 8), nr))
|
||||
nr2 = this.add32(nr2, this.xor32(this.shl32(nr2, 8), nr));
|
||||
|
||||
// add+=tmp;
|
||||
add += c;
|
||||
}
|
||||
|
||||
this.int31Write(result, nr, 0);
|
||||
this.int31Write(result, nr2, 4);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
Auth.randomInit = function(seed1, seed2) {
|
||||
return {
|
||||
max_value : 0x3FFFFFFF,
|
||||
max_value_dbl : 0x3FFFFFFF,
|
||||
seed1 : seed1 % 0x3FFFFFFF,
|
||||
seed2 : seed2 % 0x3FFFFFFF
|
||||
};
|
||||
};
|
||||
|
||||
Auth.myRnd = function(r){
|
||||
r.seed1 = (r.seed1 * 3 + r.seed2) % r.max_value;
|
||||
r.seed2 = (r.seed1 + r.seed2 + 33) % r.max_value;
|
||||
|
||||
return r.seed1 / r.max_value_dbl;
|
||||
};
|
||||
|
||||
Auth.scramble323 = function(message, password) {
|
||||
if (!password) {
|
||||
return Buffer.alloc(0);
|
||||
}
|
||||
|
||||
var to = Buffer.allocUnsafe(8);
|
||||
var hashPass = this.hashPassword(password);
|
||||
var hashMessage = this.hashPassword(message.slice(0, 8));
|
||||
var seed1 = this.int32Read(hashPass, 0) ^ this.int32Read(hashMessage, 0);
|
||||
var seed2 = this.int32Read(hashPass, 4) ^ this.int32Read(hashMessage, 4);
|
||||
var r = this.randomInit(seed1, seed2);
|
||||
|
||||
for (var i = 0; i < 8; i++){
|
||||
to[i] = Math.floor(this.myRnd(r) * 31) + 64;
|
||||
}
|
||||
var extra = (Math.floor(this.myRnd(r) * 31));
|
||||
|
||||
for (var i = 0; i < 8; i++){
|
||||
to[i] ^= extra;
|
||||
}
|
||||
|
||||
return to;
|
||||
};
|
||||
|
||||
Auth.xor32 = function(a, b){
|
||||
return [a[0] ^ b[0], a[1] ^ b[1]];
|
||||
};
|
||||
|
||||
Auth.add32 = function(a, b){
|
||||
var w1 = a[1] + b[1];
|
||||
var w2 = a[0] + b[0] + ((w1 & 0xFFFF0000) >> 16);
|
||||
|
||||
return [w2 & 0xFFFF, w1 & 0xFFFF];
|
||||
};
|
||||
|
||||
Auth.mul32 = function(a, b){
|
||||
// based on this example of multiplying 32b ints using 16b
|
||||
// http://www.dsprelated.com/showmessage/89790/1.php
|
||||
var w1 = a[1] * b[1];
|
||||
var w2 = (((a[1] * b[1]) >> 16) & 0xFFFF) + ((a[0] * b[1]) & 0xFFFF) + (a[1] * b[0] & 0xFFFF);
|
||||
|
||||
return [w2 & 0xFFFF, w1 & 0xFFFF];
|
||||
};
|
||||
|
||||
Auth.and32 = function(a, b){
|
||||
return [a[0] & b[0], a[1] & b[1]];
|
||||
};
|
||||
|
||||
Auth.shl32 = function(a, b){
|
||||
// assume b is 16 or less
|
||||
var w1 = a[1] << b;
|
||||
var w2 = (a[0] << b) | ((w1 & 0xFFFF0000) >> 16);
|
||||
|
||||
return [w2 & 0xFFFF, w1 & 0xFFFF];
|
||||
};
|
||||
|
||||
Auth.int31Write = function(buffer, number, offset) {
|
||||
buffer[offset] = (number[0] >> 8) & 0x7F;
|
||||
buffer[offset + 1] = (number[0]) & 0xFF;
|
||||
buffer[offset + 2] = (number[1] >> 8) & 0xFF;
|
||||
buffer[offset + 3] = (number[1]) & 0xFF;
|
||||
};
|
||||
|
||||
Auth.int32Read = function(buffer, offset){
|
||||
return (buffer[offset] << 24)
|
||||
+ (buffer[offset + 1] << 16)
|
||||
+ (buffer[offset + 2] << 8)
|
||||
+ (buffer[offset + 3]);
|
||||
};
|
||||
25
node_modules/mysql/lib/protocol/BufferList.js
generated
vendored
Normal file
25
node_modules/mysql/lib/protocol/BufferList.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
module.exports = BufferList;
|
||||
function BufferList() {
|
||||
this.bufs = [];
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
BufferList.prototype.shift = function shift() {
|
||||
var buf = this.bufs.shift();
|
||||
|
||||
if (buf) {
|
||||
this.size -= buf.length;
|
||||
}
|
||||
|
||||
return buf;
|
||||
};
|
||||
|
||||
BufferList.prototype.push = function push(buf) {
|
||||
if (!buf || !buf.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bufs.push(buf);
|
||||
this.size += buf.length;
|
||||
};
|
||||
5
node_modules/mysql/lib/protocol/PacketHeader.js
generated
vendored
Normal file
5
node_modules/mysql/lib/protocol/PacketHeader.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
module.exports = PacketHeader;
|
||||
function PacketHeader(length, number) {
|
||||
this.length = length;
|
||||
this.number = number;
|
||||
}
|
||||
211
node_modules/mysql/lib/protocol/PacketWriter.js
generated
vendored
Normal file
211
node_modules/mysql/lib/protocol/PacketWriter.js
generated
vendored
Normal file
@ -0,0 +1,211 @@
|
||||
var BIT_16 = Math.pow(2, 16);
|
||||
var BIT_24 = Math.pow(2, 24);
|
||||
var BUFFER_ALLOC_SIZE = Math.pow(2, 8);
|
||||
// The maximum precision JS Numbers can hold precisely
|
||||
// Don't panic: Good enough to represent byte values up to 8192 TB
|
||||
var IEEE_754_BINARY_64_PRECISION = Math.pow(2, 53);
|
||||
var MAX_PACKET_LENGTH = Math.pow(2, 24) - 1;
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
|
||||
module.exports = PacketWriter;
|
||||
function PacketWriter() {
|
||||
this._buffer = null;
|
||||
this._offset = 0;
|
||||
}
|
||||
|
||||
PacketWriter.prototype.toBuffer = function toBuffer(parser) {
|
||||
if (!this._buffer) {
|
||||
this._buffer = Buffer.alloc(0);
|
||||
this._offset = 0;
|
||||
}
|
||||
|
||||
var buffer = this._buffer;
|
||||
var length = this._offset;
|
||||
var packets = Math.floor(length / MAX_PACKET_LENGTH) + 1;
|
||||
|
||||
this._buffer = Buffer.allocUnsafe(length + packets * 4);
|
||||
this._offset = 0;
|
||||
|
||||
for (var packet = 0; packet < packets; packet++) {
|
||||
var isLast = (packet + 1 === packets);
|
||||
var packetLength = (isLast)
|
||||
? length % MAX_PACKET_LENGTH
|
||||
: MAX_PACKET_LENGTH;
|
||||
|
||||
var packetNumber = parser.incrementPacketNumber();
|
||||
|
||||
this.writeUnsignedNumber(3, packetLength);
|
||||
this.writeUnsignedNumber(1, packetNumber);
|
||||
|
||||
var start = packet * MAX_PACKET_LENGTH;
|
||||
var end = start + packetLength;
|
||||
|
||||
this.writeBuffer(buffer.slice(start, end));
|
||||
}
|
||||
|
||||
return this._buffer;
|
||||
};
|
||||
|
||||
PacketWriter.prototype.writeUnsignedNumber = function(bytes, value) {
|
||||
this._allocate(bytes);
|
||||
|
||||
for (var i = 0; i < bytes; i++) {
|
||||
this._buffer[this._offset++] = (value >> (i * 8)) & 0xff;
|
||||
}
|
||||
};
|
||||
|
||||
PacketWriter.prototype.writeFiller = function(bytes) {
|
||||
this._allocate(bytes);
|
||||
|
||||
for (var i = 0; i < bytes; i++) {
|
||||
this._buffer[this._offset++] = 0x00;
|
||||
}
|
||||
};
|
||||
|
||||
PacketWriter.prototype.writeNullTerminatedString = function(value, encoding) {
|
||||
// Typecast undefined into '' and numbers into strings
|
||||
value = value || '';
|
||||
value = value + '';
|
||||
|
||||
var bytes = Buffer.byteLength(value, encoding || 'utf-8') + 1;
|
||||
this._allocate(bytes);
|
||||
|
||||
this._buffer.write(value, this._offset, encoding);
|
||||
this._buffer[this._offset + bytes - 1] = 0x00;
|
||||
|
||||
this._offset += bytes;
|
||||
};
|
||||
|
||||
PacketWriter.prototype.writeString = function(value) {
|
||||
// Typecast undefined into '' and numbers into strings
|
||||
value = value || '';
|
||||
value = value + '';
|
||||
|
||||
var bytes = Buffer.byteLength(value, 'utf-8');
|
||||
this._allocate(bytes);
|
||||
|
||||
this._buffer.write(value, this._offset, 'utf-8');
|
||||
|
||||
this._offset += bytes;
|
||||
};
|
||||
|
||||
PacketWriter.prototype.writeBuffer = function(value) {
|
||||
var bytes = value.length;
|
||||
|
||||
this._allocate(bytes);
|
||||
value.copy(this._buffer, this._offset);
|
||||
this._offset += bytes;
|
||||
};
|
||||
|
||||
PacketWriter.prototype.writeLengthCodedNumber = function(value) {
|
||||
if (value === null) {
|
||||
this._allocate(1);
|
||||
this._buffer[this._offset++] = 251;
|
||||
return;
|
||||
}
|
||||
|
||||
if (value <= 250) {
|
||||
this._allocate(1);
|
||||
this._buffer[this._offset++] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (value > IEEE_754_BINARY_64_PRECISION) {
|
||||
throw new Error(
|
||||
'writeLengthCodedNumber: JS precision range exceeded, your ' +
|
||||
'number is > 53 bit: "' + value + '"'
|
||||
);
|
||||
}
|
||||
|
||||
if (value < BIT_16) {
|
||||
this._allocate(3);
|
||||
this._buffer[this._offset++] = 252;
|
||||
} else if (value < BIT_24) {
|
||||
this._allocate(4);
|
||||
this._buffer[this._offset++] = 253;
|
||||
} else {
|
||||
this._allocate(9);
|
||||
this._buffer[this._offset++] = 254;
|
||||
}
|
||||
|
||||
// 16 Bit
|
||||
this._buffer[this._offset++] = value & 0xff;
|
||||
this._buffer[this._offset++] = (value >> 8) & 0xff;
|
||||
|
||||
if (value < BIT_16) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 24 Bit
|
||||
this._buffer[this._offset++] = (value >> 16) & 0xff;
|
||||
|
||||
if (value < BIT_24) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._buffer[this._offset++] = (value >> 24) & 0xff;
|
||||
|
||||
// Hack: Get the most significant 32 bit (JS bitwise operators are 32 bit)
|
||||
value = value.toString(2);
|
||||
value = value.substr(0, value.length - 32);
|
||||
value = parseInt(value, 2);
|
||||
|
||||
this._buffer[this._offset++] = value & 0xff;
|
||||
this._buffer[this._offset++] = (value >> 8) & 0xff;
|
||||
this._buffer[this._offset++] = (value >> 16) & 0xff;
|
||||
|
||||
// Set last byte to 0, as we can only support 53 bits in JS (see above)
|
||||
this._buffer[this._offset++] = 0;
|
||||
};
|
||||
|
||||
PacketWriter.prototype.writeLengthCodedBuffer = function(value) {
|
||||
var bytes = value.length;
|
||||
this.writeLengthCodedNumber(bytes);
|
||||
this.writeBuffer(value);
|
||||
};
|
||||
|
||||
PacketWriter.prototype.writeNullTerminatedBuffer = function(value) {
|
||||
this.writeBuffer(value);
|
||||
this.writeFiller(1); // 0x00 terminator
|
||||
};
|
||||
|
||||
PacketWriter.prototype.writeLengthCodedString = function(value) {
|
||||
if (value === null) {
|
||||
this.writeLengthCodedNumber(null);
|
||||
return;
|
||||
}
|
||||
|
||||
value = (value === undefined)
|
||||
? ''
|
||||
: String(value);
|
||||
|
||||
var bytes = Buffer.byteLength(value, 'utf-8');
|
||||
this.writeLengthCodedNumber(bytes);
|
||||
|
||||
if (!bytes) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._allocate(bytes);
|
||||
this._buffer.write(value, this._offset, 'utf-8');
|
||||
this._offset += bytes;
|
||||
};
|
||||
|
||||
PacketWriter.prototype._allocate = function _allocate(bytes) {
|
||||
if (!this._buffer) {
|
||||
this._buffer = Buffer.alloc(Math.max(BUFFER_ALLOC_SIZE, bytes));
|
||||
this._offset = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
var bytesRemaining = this._buffer.length - this._offset;
|
||||
if (bytesRemaining >= bytes) {
|
||||
return;
|
||||
}
|
||||
|
||||
var newSize = this._buffer.length + Math.max(BUFFER_ALLOC_SIZE, bytes);
|
||||
var oldBuffer = this._buffer;
|
||||
|
||||
this._buffer = Buffer.alloc(newSize);
|
||||
oldBuffer.copy(this._buffer);
|
||||
};
|
||||
491
node_modules/mysql/lib/protocol/Parser.js
generated
vendored
Normal file
491
node_modules/mysql/lib/protocol/Parser.js
generated
vendored
Normal file
@ -0,0 +1,491 @@
|
||||
var PacketHeader = require('./PacketHeader');
|
||||
var BigNumber = require('bignumber.js');
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
var BufferList = require('./BufferList');
|
||||
|
||||
var MAX_PACKET_LENGTH = Math.pow(2, 24) - 1;
|
||||
var MUL_32BIT = Math.pow(2, 32);
|
||||
var PACKET_HEADER_LENGTH = 4;
|
||||
|
||||
module.exports = Parser;
|
||||
function Parser(options) {
|
||||
options = options || {};
|
||||
|
||||
this._supportBigNumbers = options.config && options.config.supportBigNumbers;
|
||||
this._buffer = Buffer.alloc(0);
|
||||
this._nextBuffers = new BufferList();
|
||||
this._longPacketBuffers = new BufferList();
|
||||
this._offset = 0;
|
||||
this._packetEnd = null;
|
||||
this._packetHeader = null;
|
||||
this._packetOffset = null;
|
||||
this._onError = options.onError || function(err) { throw err; };
|
||||
this._onPacket = options.onPacket || function() {};
|
||||
this._nextPacketNumber = 0;
|
||||
this._encoding = 'utf-8';
|
||||
this._paused = false;
|
||||
}
|
||||
|
||||
Parser.prototype.write = function write(chunk) {
|
||||
this._nextBuffers.push(chunk);
|
||||
|
||||
while (!this._paused) {
|
||||
var packetHeader = this._tryReadPacketHeader();
|
||||
|
||||
if (!packetHeader) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this._combineNextBuffers(packetHeader.length)) {
|
||||
break;
|
||||
}
|
||||
|
||||
this._parsePacket(packetHeader);
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.append = function append(chunk) {
|
||||
if (!chunk || chunk.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate slice ranges
|
||||
var sliceEnd = this._buffer.length;
|
||||
var sliceStart = this._packetOffset === null
|
||||
? this._offset
|
||||
: this._packetOffset;
|
||||
var sliceLength = sliceEnd - sliceStart;
|
||||
|
||||
// Get chunk data
|
||||
var buffer = null;
|
||||
var chunks = !(chunk instanceof Array || Array.isArray(chunk)) ? [chunk] : chunk;
|
||||
var length = 0;
|
||||
var offset = 0;
|
||||
|
||||
for (var i = 0; i < chunks.length; i++) {
|
||||
length += chunks[i].length;
|
||||
}
|
||||
|
||||
if (sliceLength !== 0) {
|
||||
// Create a new Buffer
|
||||
buffer = Buffer.allocUnsafe(sliceLength + length);
|
||||
offset = 0;
|
||||
|
||||
// Copy data slice
|
||||
offset += this._buffer.copy(buffer, 0, sliceStart, sliceEnd);
|
||||
|
||||
// Copy chunks
|
||||
for (var i = 0; i < chunks.length; i++) {
|
||||
offset += chunks[i].copy(buffer, offset);
|
||||
}
|
||||
} else if (chunks.length > 1) {
|
||||
// Create a new Buffer
|
||||
buffer = Buffer.allocUnsafe(length);
|
||||
offset = 0;
|
||||
|
||||
// Copy chunks
|
||||
for (var i = 0; i < chunks.length; i++) {
|
||||
offset += chunks[i].copy(buffer, offset);
|
||||
}
|
||||
} else {
|
||||
// Buffer is the only chunk
|
||||
buffer = chunks[0];
|
||||
}
|
||||
|
||||
// Adjust data-tracking pointers
|
||||
this._buffer = buffer;
|
||||
this._offset = this._offset - sliceStart;
|
||||
this._packetEnd = this._packetEnd !== null
|
||||
? this._packetEnd - sliceStart
|
||||
: null;
|
||||
this._packetOffset = this._packetOffset !== null
|
||||
? this._packetOffset - sliceStart
|
||||
: null;
|
||||
};
|
||||
|
||||
Parser.prototype.pause = function() {
|
||||
this._paused = true;
|
||||
};
|
||||
|
||||
Parser.prototype.resume = function() {
|
||||
this._paused = false;
|
||||
|
||||
// nextTick() to avoid entering write() multiple times within the same stack
|
||||
// which would cause problems as write manipulates the state of the object.
|
||||
process.nextTick(this.write.bind(this));
|
||||
};
|
||||
|
||||
Parser.prototype.peak = function peak(offset) {
|
||||
return this._buffer[this._offset + (offset >>> 0)];
|
||||
};
|
||||
|
||||
Parser.prototype.parseUnsignedNumber = function parseUnsignedNumber(bytes) {
|
||||
if (bytes === 1) {
|
||||
return this._buffer[this._offset++];
|
||||
}
|
||||
|
||||
var buffer = this._buffer;
|
||||
var offset = this._offset + bytes - 1;
|
||||
var value = 0;
|
||||
|
||||
if (bytes > 4) {
|
||||
var err = new Error('parseUnsignedNumber: Supports only up to 4 bytes');
|
||||
err.offset = (this._offset - this._packetOffset - 1);
|
||||
err.code = 'PARSER_UNSIGNED_TOO_LONG';
|
||||
throw err;
|
||||
}
|
||||
|
||||
while (offset >= this._offset) {
|
||||
value = ((value << 8) | buffer[offset]) >>> 0;
|
||||
offset--;
|
||||
}
|
||||
|
||||
this._offset += bytes;
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
Parser.prototype.parseLengthCodedString = function() {
|
||||
var length = this.parseLengthCodedNumber();
|
||||
|
||||
if (length === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.parseString(length);
|
||||
};
|
||||
|
||||
Parser.prototype.parseLengthCodedBuffer = function() {
|
||||
var length = this.parseLengthCodedNumber();
|
||||
|
||||
if (length === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.parseBuffer(length);
|
||||
};
|
||||
|
||||
Parser.prototype.parseLengthCodedNumber = function parseLengthCodedNumber() {
|
||||
if (this._offset >= this._buffer.length) {
|
||||
var err = new Error('Parser: read past end');
|
||||
err.offset = (this._offset - this._packetOffset);
|
||||
err.code = 'PARSER_READ_PAST_END';
|
||||
throw err;
|
||||
}
|
||||
|
||||
var bits = this._buffer[this._offset++];
|
||||
|
||||
if (bits <= 250) {
|
||||
return bits;
|
||||
}
|
||||
|
||||
switch (bits) {
|
||||
case 251:
|
||||
return null;
|
||||
case 252:
|
||||
return this.parseUnsignedNumber(2);
|
||||
case 253:
|
||||
return this.parseUnsignedNumber(3);
|
||||
case 254:
|
||||
break;
|
||||
default:
|
||||
var err = new Error('Unexpected first byte' + (bits ? ': 0x' + bits.toString(16) : ''));
|
||||
err.offset = (this._offset - this._packetOffset - 1);
|
||||
err.code = 'PARSER_BAD_LENGTH_BYTE';
|
||||
throw err;
|
||||
}
|
||||
|
||||
var low = this.parseUnsignedNumber(4);
|
||||
var high = this.parseUnsignedNumber(4);
|
||||
var value;
|
||||
|
||||
if (high >>> 21) {
|
||||
value = BigNumber(MUL_32BIT).times(high).plus(low).toString();
|
||||
|
||||
if (this._supportBigNumbers) {
|
||||
return value;
|
||||
}
|
||||
|
||||
var err = new Error(
|
||||
'parseLengthCodedNumber: JS precision range exceeded, ' +
|
||||
'number is >= 53 bit: "' + value + '"'
|
||||
);
|
||||
err.offset = (this._offset - this._packetOffset - 8);
|
||||
err.code = 'PARSER_JS_PRECISION_RANGE_EXCEEDED';
|
||||
throw err;
|
||||
}
|
||||
|
||||
value = low + (MUL_32BIT * high);
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
Parser.prototype.parseFiller = function(length) {
|
||||
return this.parseBuffer(length);
|
||||
};
|
||||
|
||||
Parser.prototype.parseNullTerminatedBuffer = function() {
|
||||
var end = this._nullByteOffset();
|
||||
var value = this._buffer.slice(this._offset, end);
|
||||
this._offset = end + 1;
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
Parser.prototype.parseNullTerminatedString = function() {
|
||||
var end = this._nullByteOffset();
|
||||
var value = this._buffer.toString(this._encoding, this._offset, end);
|
||||
this._offset = end + 1;
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
Parser.prototype._nullByteOffset = function() {
|
||||
var offset = this._offset;
|
||||
|
||||
while (this._buffer[offset] !== 0x00) {
|
||||
offset++;
|
||||
|
||||
if (offset >= this._buffer.length) {
|
||||
var err = new Error('Offset of null terminated string not found.');
|
||||
err.offset = (this._offset - this._packetOffset);
|
||||
err.code = 'PARSER_MISSING_NULL_BYTE';
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
};
|
||||
|
||||
Parser.prototype.parsePacketTerminatedBuffer = function parsePacketTerminatedBuffer() {
|
||||
var length = this._packetEnd - this._offset;
|
||||
return this.parseBuffer(length);
|
||||
};
|
||||
|
||||
Parser.prototype.parsePacketTerminatedString = function() {
|
||||
var length = this._packetEnd - this._offset;
|
||||
return this.parseString(length);
|
||||
};
|
||||
|
||||
Parser.prototype.parseBuffer = function(length) {
|
||||
var response = Buffer.alloc(length);
|
||||
this._buffer.copy(response, 0, this._offset, this._offset + length);
|
||||
|
||||
this._offset += length;
|
||||
return response;
|
||||
};
|
||||
|
||||
Parser.prototype.parseString = function(length) {
|
||||
var offset = this._offset;
|
||||
var end = offset + length;
|
||||
var value = this._buffer.toString(this._encoding, offset, end);
|
||||
|
||||
this._offset = end;
|
||||
return value;
|
||||
};
|
||||
|
||||
Parser.prototype.parseGeometryValue = function() {
|
||||
var buffer = this.parseLengthCodedBuffer();
|
||||
var offset = 4;
|
||||
|
||||
if (buffer === null || !buffer.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function parseGeometry() {
|
||||
var result = null;
|
||||
var byteOrder = buffer.readUInt8(offset); offset += 1;
|
||||
var wkbType = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
|
||||
switch (wkbType) {
|
||||
case 1: // WKBPoint
|
||||
var x = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
|
||||
var y = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
|
||||
result = {x: x, y: y};
|
||||
break;
|
||||
case 2: // WKBLineString
|
||||
var numPoints = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
|
||||
result = [];
|
||||
for (var i = numPoints; i > 0; i--) {
|
||||
var x = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
|
||||
var y = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
|
||||
result.push({x: x, y: y});
|
||||
}
|
||||
break;
|
||||
case 3: // WKBPolygon
|
||||
var numRings = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
|
||||
result = [];
|
||||
for (var i = numRings; i > 0; i--) {
|
||||
var numPoints = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
|
||||
var line = [];
|
||||
for (var j = numPoints; j > 0; j--) {
|
||||
var x = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
|
||||
var y = byteOrder ? buffer.readDoubleLE(offset) : buffer.readDoubleBE(offset); offset += 8;
|
||||
line.push({x: x, y: y});
|
||||
}
|
||||
result.push(line);
|
||||
}
|
||||
break;
|
||||
case 4: // WKBMultiPoint
|
||||
case 5: // WKBMultiLineString
|
||||
case 6: // WKBMultiPolygon
|
||||
case 7: // WKBGeometryCollection
|
||||
var num = byteOrder ? buffer.readUInt32LE(offset) : buffer.readUInt32BE(offset); offset += 4;
|
||||
var result = [];
|
||||
for (var i = num; i > 0; i--) {
|
||||
result.push(parseGeometry());
|
||||
}
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return parseGeometry();
|
||||
};
|
||||
|
||||
Parser.prototype.reachedPacketEnd = function() {
|
||||
return this._offset === this._packetEnd;
|
||||
};
|
||||
|
||||
Parser.prototype.incrementPacketNumber = function() {
|
||||
var currentPacketNumber = this._nextPacketNumber;
|
||||
this._nextPacketNumber = (this._nextPacketNumber + 1) % 256;
|
||||
|
||||
return currentPacketNumber;
|
||||
};
|
||||
|
||||
Parser.prototype.resetPacketNumber = function() {
|
||||
this._nextPacketNumber = 0;
|
||||
};
|
||||
|
||||
Parser.prototype.packetLength = function packetLength() {
|
||||
if (!this._packetHeader) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this._packetHeader.length + this._longPacketBuffers.size;
|
||||
};
|
||||
|
||||
Parser.prototype._combineNextBuffers = function _combineNextBuffers(bytes) {
|
||||
var length = this._buffer.length - this._offset;
|
||||
|
||||
if (length >= bytes) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((length + this._nextBuffers.size) < bytes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var buffers = [];
|
||||
var bytesNeeded = bytes - length;
|
||||
|
||||
while (bytesNeeded > 0) {
|
||||
var buffer = this._nextBuffers.shift();
|
||||
buffers.push(buffer);
|
||||
bytesNeeded -= buffer.length;
|
||||
}
|
||||
|
||||
this.append(buffers);
|
||||
return true;
|
||||
};
|
||||
|
||||
Parser.prototype._combineLongPacketBuffers = function _combineLongPacketBuffers() {
|
||||
if (!this._longPacketBuffers.size) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate bytes
|
||||
var remainingBytes = this._buffer.length - this._offset;
|
||||
var trailingPacketBytes = this._buffer.length - this._packetEnd;
|
||||
|
||||
// Create buffer
|
||||
var buf = null;
|
||||
var buffer = Buffer.allocUnsafe(remainingBytes + this._longPacketBuffers.size);
|
||||
var offset = 0;
|
||||
|
||||
// Copy long buffers
|
||||
while ((buf = this._longPacketBuffers.shift())) {
|
||||
offset += buf.copy(buffer, offset);
|
||||
}
|
||||
|
||||
// Copy remaining bytes
|
||||
this._buffer.copy(buffer, offset, this._offset);
|
||||
|
||||
this._buffer = buffer;
|
||||
this._offset = 0;
|
||||
this._packetEnd = this._buffer.length - trailingPacketBytes;
|
||||
this._packetOffset = 0;
|
||||
};
|
||||
|
||||
Parser.prototype._parsePacket = function _parsePacket(packetHeader) {
|
||||
this._packetEnd = this._offset + packetHeader.length;
|
||||
this._packetOffset = this._offset;
|
||||
|
||||
if (packetHeader.length === MAX_PACKET_LENGTH) {
|
||||
this._longPacketBuffers.push(this._buffer.slice(this._packetOffset, this._packetEnd));
|
||||
this._advanceToNextPacket();
|
||||
return;
|
||||
}
|
||||
|
||||
this._combineLongPacketBuffers();
|
||||
|
||||
var hadException = true;
|
||||
try {
|
||||
this._onPacket(packetHeader);
|
||||
hadException = false;
|
||||
} catch (err) {
|
||||
if (!err || typeof err.code !== 'string' || err.code.substr(0, 7) !== 'PARSER_') {
|
||||
throw err; // Rethrow non-MySQL errors
|
||||
}
|
||||
|
||||
// Pass down parser errors
|
||||
this._onError(err);
|
||||
hadException = false;
|
||||
} finally {
|
||||
this._advanceToNextPacket();
|
||||
|
||||
// If there was an exception, the parser while loop will be broken out
|
||||
// of after the finally block. So schedule a blank write to re-enter it
|
||||
// to continue parsing any bytes that may already have been received.
|
||||
if (hadException) {
|
||||
process.nextTick(this.write.bind(this));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype._tryReadPacketHeader = function _tryReadPacketHeader() {
|
||||
if (this._packetHeader) {
|
||||
return this._packetHeader;
|
||||
}
|
||||
|
||||
if (!this._combineNextBuffers(PACKET_HEADER_LENGTH)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
this._packetHeader = new PacketHeader(
|
||||
this.parseUnsignedNumber(3),
|
||||
this.parseUnsignedNumber(1)
|
||||
);
|
||||
|
||||
if (this._packetHeader.number !== this._nextPacketNumber) {
|
||||
var err = new Error(
|
||||
'Packets out of order. Got: ' + this._packetHeader.number + ' ' +
|
||||
'Expected: ' + this._nextPacketNumber
|
||||
);
|
||||
|
||||
err.code = 'PROTOCOL_PACKETS_OUT_OF_ORDER';
|
||||
err.fatal = true;
|
||||
|
||||
this._onError(err);
|
||||
}
|
||||
|
||||
this.incrementPacketNumber();
|
||||
|
||||
return this._packetHeader;
|
||||
};
|
||||
|
||||
Parser.prototype._advanceToNextPacket = function() {
|
||||
this._offset = this._packetEnd;
|
||||
this._packetHeader = null;
|
||||
this._packetEnd = null;
|
||||
this._packetOffset = null;
|
||||
};
|
||||
463
node_modules/mysql/lib/protocol/Protocol.js
generated
vendored
Normal file
463
node_modules/mysql/lib/protocol/Protocol.js
generated
vendored
Normal file
@ -0,0 +1,463 @@
|
||||
var Parser = require('./Parser');
|
||||
var Sequences = require('./sequences');
|
||||
var Packets = require('./packets');
|
||||
var Stream = require('stream').Stream;
|
||||
var Util = require('util');
|
||||
var PacketWriter = require('./PacketWriter');
|
||||
|
||||
module.exports = Protocol;
|
||||
Util.inherits(Protocol, Stream);
|
||||
function Protocol(options) {
|
||||
Stream.call(this);
|
||||
|
||||
options = options || {};
|
||||
|
||||
this.readable = true;
|
||||
this.writable = true;
|
||||
|
||||
this._config = options.config || {};
|
||||
this._connection = options.connection;
|
||||
this._callback = null;
|
||||
this._fatalError = null;
|
||||
this._quitSequence = null;
|
||||
this._handshake = false;
|
||||
this._handshaked = false;
|
||||
this._ended = false;
|
||||
this._destroyed = false;
|
||||
this._queue = [];
|
||||
this._handshakeInitializationPacket = null;
|
||||
|
||||
this._parser = new Parser({
|
||||
onError : this.handleParserError.bind(this),
|
||||
onPacket : this._parsePacket.bind(this),
|
||||
config : this._config
|
||||
});
|
||||
}
|
||||
|
||||
Protocol.prototype.write = function(buffer) {
|
||||
this._parser.write(buffer);
|
||||
return true;
|
||||
};
|
||||
|
||||
Protocol.prototype.handshake = function handshake(options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
options.config = this._config;
|
||||
|
||||
var sequence = this._enqueue(new Sequences.Handshake(options, callback));
|
||||
|
||||
this._handshake = true;
|
||||
|
||||
return sequence;
|
||||
};
|
||||
|
||||
Protocol.prototype.query = function query(options, callback) {
|
||||
return this._enqueue(new Sequences.Query(options, callback));
|
||||
};
|
||||
|
||||
Protocol.prototype.changeUser = function changeUser(options, callback) {
|
||||
return this._enqueue(new Sequences.ChangeUser(options, callback));
|
||||
};
|
||||
|
||||
Protocol.prototype.ping = function ping(options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
return this._enqueue(new Sequences.Ping(options, callback));
|
||||
};
|
||||
|
||||
Protocol.prototype.stats = function stats(options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
return this._enqueue(new Sequences.Statistics(options, callback));
|
||||
};
|
||||
|
||||
Protocol.prototype.quit = function quit(options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
var self = this;
|
||||
var sequence = this._enqueue(new Sequences.Quit(options, callback));
|
||||
|
||||
sequence.on('end', function () {
|
||||
self.end();
|
||||
});
|
||||
|
||||
return this._quitSequence = sequence;
|
||||
};
|
||||
|
||||
Protocol.prototype.end = function() {
|
||||
if (this._ended) {
|
||||
return;
|
||||
}
|
||||
this._ended = true;
|
||||
|
||||
if (this._quitSequence && (this._quitSequence._ended || this._queue[0] === this._quitSequence)) {
|
||||
this._quitSequence.end();
|
||||
this.emit('end');
|
||||
return;
|
||||
}
|
||||
|
||||
var err = new Error('Connection lost: The server closed the connection.');
|
||||
err.fatal = true;
|
||||
err.code = 'PROTOCOL_CONNECTION_LOST';
|
||||
|
||||
this._delegateError(err);
|
||||
};
|
||||
|
||||
Protocol.prototype.pause = function() {
|
||||
this._parser.pause();
|
||||
// Since there is a file stream in query, we must transmit pause/resume event to current sequence.
|
||||
var seq = this._queue[0];
|
||||
if (seq && seq.emit) {
|
||||
seq.emit('pause');
|
||||
}
|
||||
};
|
||||
|
||||
Protocol.prototype.resume = function() {
|
||||
this._parser.resume();
|
||||
// Since there is a file stream in query, we must transmit pause/resume event to current sequence.
|
||||
var seq = this._queue[0];
|
||||
if (seq && seq.emit) {
|
||||
seq.emit('resume');
|
||||
}
|
||||
};
|
||||
|
||||
Protocol.prototype._enqueue = function(sequence) {
|
||||
if (!this._validateEnqueue(sequence)) {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
if (this._config.trace) {
|
||||
// Long stack trace support
|
||||
sequence._callSite = sequence._callSite || new Error();
|
||||
}
|
||||
|
||||
this._queue.push(sequence);
|
||||
this.emit('enqueue', sequence);
|
||||
|
||||
var self = this;
|
||||
sequence
|
||||
.on('error', function(err) {
|
||||
self._delegateError(err, sequence);
|
||||
})
|
||||
.on('packet', function(packet) {
|
||||
sequence._timer.active();
|
||||
self._emitPacket(packet);
|
||||
})
|
||||
.on('timeout', function() {
|
||||
var err = new Error(sequence.constructor.name + ' inactivity timeout');
|
||||
|
||||
err.code = 'PROTOCOL_SEQUENCE_TIMEOUT';
|
||||
err.fatal = true;
|
||||
err.timeout = sequence._timeout;
|
||||
|
||||
self._delegateError(err, sequence);
|
||||
});
|
||||
|
||||
if (sequence.constructor === Sequences.Handshake) {
|
||||
sequence.on('start-tls', function () {
|
||||
sequence._timer.active();
|
||||
self._connection._startTLS(function(err) {
|
||||
if (err) {
|
||||
// SSL negotiation error are fatal
|
||||
err.code = 'HANDSHAKE_SSL_ERROR';
|
||||
err.fatal = true;
|
||||
sequence.end(err);
|
||||
return;
|
||||
}
|
||||
|
||||
sequence._timer.active();
|
||||
sequence._tlsUpgradeCompleteHandler();
|
||||
});
|
||||
});
|
||||
|
||||
sequence.on('end', function () {
|
||||
self._handshaked = true;
|
||||
|
||||
if (!self._fatalError) {
|
||||
self.emit('handshake', self._handshakeInitializationPacket);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sequence.on('end', function () {
|
||||
self._dequeue(sequence);
|
||||
});
|
||||
|
||||
if (this._queue.length === 1) {
|
||||
this._parser.resetPacketNumber();
|
||||
this._startSequence(sequence);
|
||||
}
|
||||
|
||||
return sequence;
|
||||
};
|
||||
|
||||
Protocol.prototype._validateEnqueue = function _validateEnqueue(sequence) {
|
||||
var err;
|
||||
var prefix = 'Cannot enqueue ' + sequence.constructor.name;
|
||||
|
||||
if (this._fatalError) {
|
||||
err = new Error(prefix + ' after fatal error.');
|
||||
err.code = 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR';
|
||||
} else if (this._quitSequence) {
|
||||
err = new Error(prefix + ' after invoking quit.');
|
||||
err.code = 'PROTOCOL_ENQUEUE_AFTER_QUIT';
|
||||
} else if (this._destroyed) {
|
||||
err = new Error(prefix + ' after being destroyed.');
|
||||
err.code = 'PROTOCOL_ENQUEUE_AFTER_DESTROY';
|
||||
} else if ((this._handshake || this._handshaked) && sequence.constructor === Sequences.Handshake) {
|
||||
err = new Error(prefix + ' after already enqueuing a Handshake.');
|
||||
err.code = 'PROTOCOL_ENQUEUE_HANDSHAKE_TWICE';
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
err.fatal = false;
|
||||
|
||||
// add error handler
|
||||
sequence.on('error', function (err) {
|
||||
self._delegateError(err, sequence);
|
||||
});
|
||||
|
||||
process.nextTick(function () {
|
||||
sequence.end(err);
|
||||
});
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Protocol.prototype._parsePacket = function() {
|
||||
var sequence = this._queue[0];
|
||||
|
||||
if (!sequence) {
|
||||
var err = new Error('Received packet with no active sequence.');
|
||||
err.code = 'PROTOCOL_STRAY_PACKET';
|
||||
err.fatal = true;
|
||||
|
||||
this._delegateError(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var Packet = this._determinePacket(sequence);
|
||||
var packet = new Packet({protocol41: this._config.protocol41});
|
||||
var packetName = Packet.name;
|
||||
|
||||
// Special case: Faster dispatch, and parsing done inside sequence
|
||||
if (Packet === Packets.RowDataPacket) {
|
||||
sequence.RowDataPacket(packet, this._parser, this._connection);
|
||||
|
||||
if (this._config.debug) {
|
||||
this._debugPacket(true, packet);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._config.debug) {
|
||||
this._parsePacketDebug(packet);
|
||||
} else {
|
||||
packet.parse(this._parser);
|
||||
}
|
||||
|
||||
if (Packet === Packets.HandshakeInitializationPacket) {
|
||||
this._handshakeInitializationPacket = packet;
|
||||
this.emit('initialize', packet);
|
||||
}
|
||||
|
||||
sequence._timer.active();
|
||||
|
||||
if (!sequence[packetName]) {
|
||||
var err = new Error('Received packet in the wrong sequence.');
|
||||
err.code = 'PROTOCOL_INCORRECT_PACKET_SEQUENCE';
|
||||
err.fatal = true;
|
||||
|
||||
this._delegateError(err);
|
||||
return;
|
||||
}
|
||||
|
||||
sequence[packetName](packet);
|
||||
};
|
||||
|
||||
Protocol.prototype._parsePacketDebug = function _parsePacketDebug(packet) {
|
||||
try {
|
||||
packet.parse(this._parser);
|
||||
} finally {
|
||||
this._debugPacket(true, packet);
|
||||
}
|
||||
};
|
||||
|
||||
Protocol.prototype._emitPacket = function(packet) {
|
||||
var packetWriter = new PacketWriter();
|
||||
packet.write(packetWriter);
|
||||
this.emit('data', packetWriter.toBuffer(this._parser));
|
||||
|
||||
if (this._config.debug) {
|
||||
this._debugPacket(false, packet);
|
||||
}
|
||||
};
|
||||
|
||||
Protocol.prototype._determinePacket = function(sequence) {
|
||||
var firstByte = this._parser.peak();
|
||||
|
||||
if (sequence.determinePacket) {
|
||||
var Packet = sequence.determinePacket(firstByte, this._parser);
|
||||
if (Packet) {
|
||||
return Packet;
|
||||
}
|
||||
}
|
||||
|
||||
switch (firstByte) {
|
||||
case 0x00: return Packets.OkPacket;
|
||||
case 0xfe: return Packets.EofPacket;
|
||||
case 0xff: return Packets.ErrorPacket;
|
||||
}
|
||||
|
||||
throw new Error('Could not determine packet, firstByte = ' + firstByte);
|
||||
};
|
||||
|
||||
Protocol.prototype._dequeue = function(sequence) {
|
||||
sequence._timer.stop();
|
||||
|
||||
// No point in advancing the queue, we are dead
|
||||
if (this._fatalError) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._queue.shift();
|
||||
|
||||
var sequence = this._queue[0];
|
||||
if (!sequence) {
|
||||
this.emit('drain');
|
||||
return;
|
||||
}
|
||||
|
||||
this._parser.resetPacketNumber();
|
||||
|
||||
this._startSequence(sequence);
|
||||
};
|
||||
|
||||
Protocol.prototype._startSequence = function(sequence) {
|
||||
if (sequence._timeout > 0 && isFinite(sequence._timeout)) {
|
||||
sequence._timer.start(sequence._timeout);
|
||||
}
|
||||
|
||||
if (sequence.constructor === Sequences.ChangeUser) {
|
||||
sequence.start(this._handshakeInitializationPacket);
|
||||
} else {
|
||||
sequence.start();
|
||||
}
|
||||
};
|
||||
|
||||
Protocol.prototype.handleNetworkError = function(err) {
|
||||
err.fatal = true;
|
||||
|
||||
var sequence = this._queue[0];
|
||||
if (sequence) {
|
||||
sequence.end(err);
|
||||
} else {
|
||||
this._delegateError(err);
|
||||
}
|
||||
};
|
||||
|
||||
Protocol.prototype.handleParserError = function handleParserError(err) {
|
||||
var sequence = this._queue[0];
|
||||
if (sequence) {
|
||||
sequence.end(err);
|
||||
} else {
|
||||
this._delegateError(err);
|
||||
}
|
||||
};
|
||||
|
||||
Protocol.prototype._delegateError = function(err, sequence) {
|
||||
// Stop delegating errors after the first fatal error
|
||||
if (this._fatalError) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err.fatal) {
|
||||
this._fatalError = err;
|
||||
}
|
||||
|
||||
if (this._shouldErrorBubbleUp(err, sequence)) {
|
||||
// Can't use regular 'error' event here as that always destroys the pipe
|
||||
// between socket and protocol which is not what we want (unless the
|
||||
// exception was fatal).
|
||||
this.emit('unhandledError', err);
|
||||
} else if (err.fatal) {
|
||||
// Send fatal error to all sequences in the queue
|
||||
var queue = this._queue;
|
||||
process.nextTick(function () {
|
||||
queue.forEach(function (sequence) {
|
||||
sequence.end(err);
|
||||
});
|
||||
queue.length = 0;
|
||||
});
|
||||
}
|
||||
|
||||
// Make sure the stream we are piping to is getting closed
|
||||
if (err.fatal) {
|
||||
this.emit('end', err);
|
||||
}
|
||||
};
|
||||
|
||||
Protocol.prototype._shouldErrorBubbleUp = function(err, sequence) {
|
||||
if (sequence) {
|
||||
if (sequence.hasErrorHandler()) {
|
||||
return false;
|
||||
} else if (!err.fatal) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return (err.fatal && !this._hasPendingErrorHandlers());
|
||||
};
|
||||
|
||||
Protocol.prototype._hasPendingErrorHandlers = function() {
|
||||
return this._queue.some(function(sequence) {
|
||||
return sequence.hasErrorHandler();
|
||||
});
|
||||
};
|
||||
|
||||
Protocol.prototype.destroy = function() {
|
||||
this._destroyed = true;
|
||||
this._parser.pause();
|
||||
|
||||
if (this._connection.state !== 'disconnected') {
|
||||
if (!this._ended) {
|
||||
this.end();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Protocol.prototype._debugPacket = function(incoming, packet) {
|
||||
var connection = this._connection;
|
||||
var direction = incoming
|
||||
? '<--'
|
||||
: '-->';
|
||||
var packetName = packet.constructor.name;
|
||||
var threadId = connection && connection.threadId !== null
|
||||
? ' (' + connection.threadId + ')'
|
||||
: '';
|
||||
|
||||
// check for debug packet restriction
|
||||
if (Array.isArray(this._config.debug) && this._config.debug.indexOf(packetName) === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var packetPayload = Util.inspect(packet).replace(/^[^{]+/, '');
|
||||
|
||||
console.log('%s%s %s %s\n', direction, threadId, packetName, packetPayload);
|
||||
};
|
||||
7
node_modules/mysql/lib/protocol/ResultSet.js
generated
vendored
Normal file
7
node_modules/mysql/lib/protocol/ResultSet.js
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = ResultSet;
|
||||
function ResultSet(resultSetHeaderPacket) {
|
||||
this.resultSetHeaderPacket = resultSetHeaderPacket;
|
||||
this.fieldPackets = [];
|
||||
this.eofPackets = [];
|
||||
this.rows = [];
|
||||
}
|
||||
1
node_modules/mysql/lib/protocol/SqlString.js
generated
vendored
Normal file
1
node_modules/mysql/lib/protocol/SqlString.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('sqlstring');
|
||||
33
node_modules/mysql/lib/protocol/Timer.js
generated
vendored
Normal file
33
node_modules/mysql/lib/protocol/Timer.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
var Timers = require('timers');
|
||||
|
||||
module.exports = Timer;
|
||||
function Timer(object) {
|
||||
this._object = object;
|
||||
this._timeout = null;
|
||||
}
|
||||
|
||||
Timer.prototype.active = function active() {
|
||||
if (this._timeout) {
|
||||
if (this._timeout.refresh) {
|
||||
this._timeout.refresh();
|
||||
} else {
|
||||
Timers.active(this._timeout);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Timer.prototype.start = function start(msecs) {
|
||||
this.stop();
|
||||
this._timeout = Timers.setTimeout(this._onTimeout.bind(this), msecs);
|
||||
};
|
||||
|
||||
Timer.prototype.stop = function stop() {
|
||||
if (this._timeout) {
|
||||
Timers.clearTimeout(this._timeout);
|
||||
this._timeout = null;
|
||||
}
|
||||
};
|
||||
|
||||
Timer.prototype._onTimeout = function _onTimeout() {
|
||||
return this._object._onTimeout();
|
||||
};
|
||||
262
node_modules/mysql/lib/protocol/constants/charsets.js
generated
vendored
Normal file
262
node_modules/mysql/lib/protocol/constants/charsets.js
generated
vendored
Normal file
@ -0,0 +1,262 @@
|
||||
exports.BIG5_CHINESE_CI = 1;
|
||||
exports.LATIN2_CZECH_CS = 2;
|
||||
exports.DEC8_SWEDISH_CI = 3;
|
||||
exports.CP850_GENERAL_CI = 4;
|
||||
exports.LATIN1_GERMAN1_CI = 5;
|
||||
exports.HP8_ENGLISH_CI = 6;
|
||||
exports.KOI8R_GENERAL_CI = 7;
|
||||
exports.LATIN1_SWEDISH_CI = 8;
|
||||
exports.LATIN2_GENERAL_CI = 9;
|
||||
exports.SWE7_SWEDISH_CI = 10;
|
||||
exports.ASCII_GENERAL_CI = 11;
|
||||
exports.UJIS_JAPANESE_CI = 12;
|
||||
exports.SJIS_JAPANESE_CI = 13;
|
||||
exports.CP1251_BULGARIAN_CI = 14;
|
||||
exports.LATIN1_DANISH_CI = 15;
|
||||
exports.HEBREW_GENERAL_CI = 16;
|
||||
exports.TIS620_THAI_CI = 18;
|
||||
exports.EUCKR_KOREAN_CI = 19;
|
||||
exports.LATIN7_ESTONIAN_CS = 20;
|
||||
exports.LATIN2_HUNGARIAN_CI = 21;
|
||||
exports.KOI8U_GENERAL_CI = 22;
|
||||
exports.CP1251_UKRAINIAN_CI = 23;
|
||||
exports.GB2312_CHINESE_CI = 24;
|
||||
exports.GREEK_GENERAL_CI = 25;
|
||||
exports.CP1250_GENERAL_CI = 26;
|
||||
exports.LATIN2_CROATIAN_CI = 27;
|
||||
exports.GBK_CHINESE_CI = 28;
|
||||
exports.CP1257_LITHUANIAN_CI = 29;
|
||||
exports.LATIN5_TURKISH_CI = 30;
|
||||
exports.LATIN1_GERMAN2_CI = 31;
|
||||
exports.ARMSCII8_GENERAL_CI = 32;
|
||||
exports.UTF8_GENERAL_CI = 33;
|
||||
exports.CP1250_CZECH_CS = 34;
|
||||
exports.UCS2_GENERAL_CI = 35;
|
||||
exports.CP866_GENERAL_CI = 36;
|
||||
exports.KEYBCS2_GENERAL_CI = 37;
|
||||
exports.MACCE_GENERAL_CI = 38;
|
||||
exports.MACROMAN_GENERAL_CI = 39;
|
||||
exports.CP852_GENERAL_CI = 40;
|
||||
exports.LATIN7_GENERAL_CI = 41;
|
||||
exports.LATIN7_GENERAL_CS = 42;
|
||||
exports.MACCE_BIN = 43;
|
||||
exports.CP1250_CROATIAN_CI = 44;
|
||||
exports.UTF8MB4_GENERAL_CI = 45;
|
||||
exports.UTF8MB4_BIN = 46;
|
||||
exports.LATIN1_BIN = 47;
|
||||
exports.LATIN1_GENERAL_CI = 48;
|
||||
exports.LATIN1_GENERAL_CS = 49;
|
||||
exports.CP1251_BIN = 50;
|
||||
exports.CP1251_GENERAL_CI = 51;
|
||||
exports.CP1251_GENERAL_CS = 52;
|
||||
exports.MACROMAN_BIN = 53;
|
||||
exports.UTF16_GENERAL_CI = 54;
|
||||
exports.UTF16_BIN = 55;
|
||||
exports.UTF16LE_GENERAL_CI = 56;
|
||||
exports.CP1256_GENERAL_CI = 57;
|
||||
exports.CP1257_BIN = 58;
|
||||
exports.CP1257_GENERAL_CI = 59;
|
||||
exports.UTF32_GENERAL_CI = 60;
|
||||
exports.UTF32_BIN = 61;
|
||||
exports.UTF16LE_BIN = 62;
|
||||
exports.BINARY = 63;
|
||||
exports.ARMSCII8_BIN = 64;
|
||||
exports.ASCII_BIN = 65;
|
||||
exports.CP1250_BIN = 66;
|
||||
exports.CP1256_BIN = 67;
|
||||
exports.CP866_BIN = 68;
|
||||
exports.DEC8_BIN = 69;
|
||||
exports.GREEK_BIN = 70;
|
||||
exports.HEBREW_BIN = 71;
|
||||
exports.HP8_BIN = 72;
|
||||
exports.KEYBCS2_BIN = 73;
|
||||
exports.KOI8R_BIN = 74;
|
||||
exports.KOI8U_BIN = 75;
|
||||
exports.LATIN2_BIN = 77;
|
||||
exports.LATIN5_BIN = 78;
|
||||
exports.LATIN7_BIN = 79;
|
||||
exports.CP850_BIN = 80;
|
||||
exports.CP852_BIN = 81;
|
||||
exports.SWE7_BIN = 82;
|
||||
exports.UTF8_BIN = 83;
|
||||
exports.BIG5_BIN = 84;
|
||||
exports.EUCKR_BIN = 85;
|
||||
exports.GB2312_BIN = 86;
|
||||
exports.GBK_BIN = 87;
|
||||
exports.SJIS_BIN = 88;
|
||||
exports.TIS620_BIN = 89;
|
||||
exports.UCS2_BIN = 90;
|
||||
exports.UJIS_BIN = 91;
|
||||
exports.GEOSTD8_GENERAL_CI = 92;
|
||||
exports.GEOSTD8_BIN = 93;
|
||||
exports.LATIN1_SPANISH_CI = 94;
|
||||
exports.CP932_JAPANESE_CI = 95;
|
||||
exports.CP932_BIN = 96;
|
||||
exports.EUCJPMS_JAPANESE_CI = 97;
|
||||
exports.EUCJPMS_BIN = 98;
|
||||
exports.CP1250_POLISH_CI = 99;
|
||||
exports.UTF16_UNICODE_CI = 101;
|
||||
exports.UTF16_ICELANDIC_CI = 102;
|
||||
exports.UTF16_LATVIAN_CI = 103;
|
||||
exports.UTF16_ROMANIAN_CI = 104;
|
||||
exports.UTF16_SLOVENIAN_CI = 105;
|
||||
exports.UTF16_POLISH_CI = 106;
|
||||
exports.UTF16_ESTONIAN_CI = 107;
|
||||
exports.UTF16_SPANISH_CI = 108;
|
||||
exports.UTF16_SWEDISH_CI = 109;
|
||||
exports.UTF16_TURKISH_CI = 110;
|
||||
exports.UTF16_CZECH_CI = 111;
|
||||
exports.UTF16_DANISH_CI = 112;
|
||||
exports.UTF16_LITHUANIAN_CI = 113;
|
||||
exports.UTF16_SLOVAK_CI = 114;
|
||||
exports.UTF16_SPANISH2_CI = 115;
|
||||
exports.UTF16_ROMAN_CI = 116;
|
||||
exports.UTF16_PERSIAN_CI = 117;
|
||||
exports.UTF16_ESPERANTO_CI = 118;
|
||||
exports.UTF16_HUNGARIAN_CI = 119;
|
||||
exports.UTF16_SINHALA_CI = 120;
|
||||
exports.UTF16_GERMAN2_CI = 121;
|
||||
exports.UTF16_CROATIAN_MYSQL561_CI = 122;
|
||||
exports.UTF16_UNICODE_520_CI = 123;
|
||||
exports.UTF16_VIETNAMESE_CI = 124;
|
||||
exports.UCS2_UNICODE_CI = 128;
|
||||
exports.UCS2_ICELANDIC_CI = 129;
|
||||
exports.UCS2_LATVIAN_CI = 130;
|
||||
exports.UCS2_ROMANIAN_CI = 131;
|
||||
exports.UCS2_SLOVENIAN_CI = 132;
|
||||
exports.UCS2_POLISH_CI = 133;
|
||||
exports.UCS2_ESTONIAN_CI = 134;
|
||||
exports.UCS2_SPANISH_CI = 135;
|
||||
exports.UCS2_SWEDISH_CI = 136;
|
||||
exports.UCS2_TURKISH_CI = 137;
|
||||
exports.UCS2_CZECH_CI = 138;
|
||||
exports.UCS2_DANISH_CI = 139;
|
||||
exports.UCS2_LITHUANIAN_CI = 140;
|
||||
exports.UCS2_SLOVAK_CI = 141;
|
||||
exports.UCS2_SPANISH2_CI = 142;
|
||||
exports.UCS2_ROMAN_CI = 143;
|
||||
exports.UCS2_PERSIAN_CI = 144;
|
||||
exports.UCS2_ESPERANTO_CI = 145;
|
||||
exports.UCS2_HUNGARIAN_CI = 146;
|
||||
exports.UCS2_SINHALA_CI = 147;
|
||||
exports.UCS2_GERMAN2_CI = 148;
|
||||
exports.UCS2_CROATIAN_MYSQL561_CI = 149;
|
||||
exports.UCS2_UNICODE_520_CI = 150;
|
||||
exports.UCS2_VIETNAMESE_CI = 151;
|
||||
exports.UCS2_GENERAL_MYSQL500_CI = 159;
|
||||
exports.UTF32_UNICODE_CI = 160;
|
||||
exports.UTF32_ICELANDIC_CI = 161;
|
||||
exports.UTF32_LATVIAN_CI = 162;
|
||||
exports.UTF32_ROMANIAN_CI = 163;
|
||||
exports.UTF32_SLOVENIAN_CI = 164;
|
||||
exports.UTF32_POLISH_CI = 165;
|
||||
exports.UTF32_ESTONIAN_CI = 166;
|
||||
exports.UTF32_SPANISH_CI = 167;
|
||||
exports.UTF32_SWEDISH_CI = 168;
|
||||
exports.UTF32_TURKISH_CI = 169;
|
||||
exports.UTF32_CZECH_CI = 170;
|
||||
exports.UTF32_DANISH_CI = 171;
|
||||
exports.UTF32_LITHUANIAN_CI = 172;
|
||||
exports.UTF32_SLOVAK_CI = 173;
|
||||
exports.UTF32_SPANISH2_CI = 174;
|
||||
exports.UTF32_ROMAN_CI = 175;
|
||||
exports.UTF32_PERSIAN_CI = 176;
|
||||
exports.UTF32_ESPERANTO_CI = 177;
|
||||
exports.UTF32_HUNGARIAN_CI = 178;
|
||||
exports.UTF32_SINHALA_CI = 179;
|
||||
exports.UTF32_GERMAN2_CI = 180;
|
||||
exports.UTF32_CROATIAN_MYSQL561_CI = 181;
|
||||
exports.UTF32_UNICODE_520_CI = 182;
|
||||
exports.UTF32_VIETNAMESE_CI = 183;
|
||||
exports.UTF8_UNICODE_CI = 192;
|
||||
exports.UTF8_ICELANDIC_CI = 193;
|
||||
exports.UTF8_LATVIAN_CI = 194;
|
||||
exports.UTF8_ROMANIAN_CI = 195;
|
||||
exports.UTF8_SLOVENIAN_CI = 196;
|
||||
exports.UTF8_POLISH_CI = 197;
|
||||
exports.UTF8_ESTONIAN_CI = 198;
|
||||
exports.UTF8_SPANISH_CI = 199;
|
||||
exports.UTF8_SWEDISH_CI = 200;
|
||||
exports.UTF8_TURKISH_CI = 201;
|
||||
exports.UTF8_CZECH_CI = 202;
|
||||
exports.UTF8_DANISH_CI = 203;
|
||||
exports.UTF8_LITHUANIAN_CI = 204;
|
||||
exports.UTF8_SLOVAK_CI = 205;
|
||||
exports.UTF8_SPANISH2_CI = 206;
|
||||
exports.UTF8_ROMAN_CI = 207;
|
||||
exports.UTF8_PERSIAN_CI = 208;
|
||||
exports.UTF8_ESPERANTO_CI = 209;
|
||||
exports.UTF8_HUNGARIAN_CI = 210;
|
||||
exports.UTF8_SINHALA_CI = 211;
|
||||
exports.UTF8_GERMAN2_CI = 212;
|
||||
exports.UTF8_CROATIAN_MYSQL561_CI = 213;
|
||||
exports.UTF8_UNICODE_520_CI = 214;
|
||||
exports.UTF8_VIETNAMESE_CI = 215;
|
||||
exports.UTF8_GENERAL_MYSQL500_CI = 223;
|
||||
exports.UTF8MB4_UNICODE_CI = 224;
|
||||
exports.UTF8MB4_ICELANDIC_CI = 225;
|
||||
exports.UTF8MB4_LATVIAN_CI = 226;
|
||||
exports.UTF8MB4_ROMANIAN_CI = 227;
|
||||
exports.UTF8MB4_SLOVENIAN_CI = 228;
|
||||
exports.UTF8MB4_POLISH_CI = 229;
|
||||
exports.UTF8MB4_ESTONIAN_CI = 230;
|
||||
exports.UTF8MB4_SPANISH_CI = 231;
|
||||
exports.UTF8MB4_SWEDISH_CI = 232;
|
||||
exports.UTF8MB4_TURKISH_CI = 233;
|
||||
exports.UTF8MB4_CZECH_CI = 234;
|
||||
exports.UTF8MB4_DANISH_CI = 235;
|
||||
exports.UTF8MB4_LITHUANIAN_CI = 236;
|
||||
exports.UTF8MB4_SLOVAK_CI = 237;
|
||||
exports.UTF8MB4_SPANISH2_CI = 238;
|
||||
exports.UTF8MB4_ROMAN_CI = 239;
|
||||
exports.UTF8MB4_PERSIAN_CI = 240;
|
||||
exports.UTF8MB4_ESPERANTO_CI = 241;
|
||||
exports.UTF8MB4_HUNGARIAN_CI = 242;
|
||||
exports.UTF8MB4_SINHALA_CI = 243;
|
||||
exports.UTF8MB4_GERMAN2_CI = 244;
|
||||
exports.UTF8MB4_CROATIAN_MYSQL561_CI = 245;
|
||||
exports.UTF8MB4_UNICODE_520_CI = 246;
|
||||
exports.UTF8MB4_VIETNAMESE_CI = 247;
|
||||
exports.UTF8_GENERAL50_CI = 253;
|
||||
|
||||
// short aliases
|
||||
exports.ARMSCII8 = exports.ARMSCII8_GENERAL_CI;
|
||||
exports.ASCII = exports.ASCII_GENERAL_CI;
|
||||
exports.BIG5 = exports.BIG5_CHINESE_CI;
|
||||
exports.BINARY = exports.BINARY;
|
||||
exports.CP1250 = exports.CP1250_GENERAL_CI;
|
||||
exports.CP1251 = exports.CP1251_GENERAL_CI;
|
||||
exports.CP1256 = exports.CP1256_GENERAL_CI;
|
||||
exports.CP1257 = exports.CP1257_GENERAL_CI;
|
||||
exports.CP866 = exports.CP866_GENERAL_CI;
|
||||
exports.CP850 = exports.CP850_GENERAL_CI;
|
||||
exports.CP852 = exports.CP852_GENERAL_CI;
|
||||
exports.CP932 = exports.CP932_JAPANESE_CI;
|
||||
exports.DEC8 = exports.DEC8_SWEDISH_CI;
|
||||
exports.EUCJPMS = exports.EUCJPMS_JAPANESE_CI;
|
||||
exports.EUCKR = exports.EUCKR_KOREAN_CI;
|
||||
exports.GB2312 = exports.GB2312_CHINESE_CI;
|
||||
exports.GBK = exports.GBK_CHINESE_CI;
|
||||
exports.GEOSTD8 = exports.GEOSTD8_GENERAL_CI;
|
||||
exports.GREEK = exports.GREEK_GENERAL_CI;
|
||||
exports.HEBREW = exports.HEBREW_GENERAL_CI;
|
||||
exports.HP8 = exports.HP8_ENGLISH_CI;
|
||||
exports.KEYBCS2 = exports.KEYBCS2_GENERAL_CI;
|
||||
exports.KOI8R = exports.KOI8R_GENERAL_CI;
|
||||
exports.KOI8U = exports.KOI8U_GENERAL_CI;
|
||||
exports.LATIN1 = exports.LATIN1_SWEDISH_CI;
|
||||
exports.LATIN2 = exports.LATIN2_GENERAL_CI;
|
||||
exports.LATIN5 = exports.LATIN5_TURKISH_CI;
|
||||
exports.LATIN7 = exports.LATIN7_GENERAL_CI;
|
||||
exports.MACCE = exports.MACCE_GENERAL_CI;
|
||||
exports.MACROMAN = exports.MACROMAN_GENERAL_CI;
|
||||
exports.SJIS = exports.SJIS_JAPANESE_CI;
|
||||
exports.SWE7 = exports.SWE7_SWEDISH_CI;
|
||||
exports.TIS620 = exports.TIS620_THAI_CI;
|
||||
exports.UCS2 = exports.UCS2_GENERAL_CI;
|
||||
exports.UJIS = exports.UJIS_JAPANESE_CI;
|
||||
exports.UTF16 = exports.UTF16_GENERAL_CI;
|
||||
exports.UTF16LE = exports.UTF16LE_GENERAL_CI;
|
||||
exports.UTF8 = exports.UTF8_GENERAL_CI;
|
||||
exports.UTF8MB4 = exports.UTF8MB4_GENERAL_CI;
|
||||
exports.UTF32 = exports.UTF32_GENERAL_CI;
|
||||
26
node_modules/mysql/lib/protocol/constants/client.js
generated
vendored
Normal file
26
node_modules/mysql/lib/protocol/constants/client.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
// Manually extracted from mysql-5.5.23/include/mysql_com.h
|
||||
exports.CLIENT_LONG_PASSWORD = 1; /* new more secure passwords */
|
||||
exports.CLIENT_FOUND_ROWS = 2; /* Found instead of affected rows */
|
||||
exports.CLIENT_LONG_FLAG = 4; /* Get all column flags */
|
||||
exports.CLIENT_CONNECT_WITH_DB = 8; /* One can specify db on connect */
|
||||
exports.CLIENT_NO_SCHEMA = 16; /* Don't allow database.table.column */
|
||||
exports.CLIENT_COMPRESS = 32; /* Can use compression protocol */
|
||||
exports.CLIENT_ODBC = 64; /* Odbc client */
|
||||
exports.CLIENT_LOCAL_FILES = 128; /* Can use LOAD DATA LOCAL */
|
||||
exports.CLIENT_IGNORE_SPACE = 256; /* Ignore spaces before '(' */
|
||||
exports.CLIENT_PROTOCOL_41 = 512; /* New 4.1 protocol */
|
||||
exports.CLIENT_INTERACTIVE = 1024; /* This is an interactive client */
|
||||
exports.CLIENT_SSL = 2048; /* Switch to SSL after handshake */
|
||||
exports.CLIENT_IGNORE_SIGPIPE = 4096; /* IGNORE sigpipes */
|
||||
exports.CLIENT_TRANSACTIONS = 8192; /* Client knows about transactions */
|
||||
exports.CLIENT_RESERVED = 16384; /* Old flag for 4.1 protocol */
|
||||
exports.CLIENT_SECURE_CONNECTION = 32768; /* New 4.1 authentication */
|
||||
|
||||
exports.CLIENT_MULTI_STATEMENTS = 65536; /* Enable/disable multi-stmt support */
|
||||
exports.CLIENT_MULTI_RESULTS = 131072; /* Enable/disable multi-results */
|
||||
exports.CLIENT_PS_MULTI_RESULTS = 262144; /* Multi-results in PS-protocol */
|
||||
|
||||
exports.CLIENT_PLUGIN_AUTH = 524288; /* Client supports plugin authentication */
|
||||
|
||||
exports.CLIENT_SSL_VERIFY_SERVER_CERT = 1073741824;
|
||||
exports.CLIENT_REMEMBER_OPTIONS = 2147483648;
|
||||
2476
node_modules/mysql/lib/protocol/constants/errors.js
generated
vendored
Normal file
2476
node_modules/mysql/lib/protocol/constants/errors.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
18
node_modules/mysql/lib/protocol/constants/field_flags.js
generated
vendored
Normal file
18
node_modules/mysql/lib/protocol/constants/field_flags.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Manually extracted from mysql-5.5.23/include/mysql_com.h
|
||||
exports.NOT_NULL_FLAG = 1; /* Field can't be NULL */
|
||||
exports.PRI_KEY_FLAG = 2; /* Field is part of a primary key */
|
||||
exports.UNIQUE_KEY_FLAG = 4; /* Field is part of a unique key */
|
||||
exports.MULTIPLE_KEY_FLAG = 8; /* Field is part of a key */
|
||||
exports.BLOB_FLAG = 16; /* Field is a blob */
|
||||
exports.UNSIGNED_FLAG = 32; /* Field is unsigned */
|
||||
exports.ZEROFILL_FLAG = 64; /* Field is zerofill */
|
||||
exports.BINARY_FLAG = 128; /* Field is binary */
|
||||
|
||||
/* The following are only sent to new clients */
|
||||
exports.ENUM_FLAG = 256; /* field is an enum */
|
||||
exports.AUTO_INCREMENT_FLAG = 512; /* field is a autoincrement field */
|
||||
exports.TIMESTAMP_FLAG = 1024; /* Field is a timestamp */
|
||||
exports.SET_FLAG = 2048; /* field is a set */
|
||||
exports.NO_DEFAULT_VALUE_FLAG = 4096; /* Field doesn't have default value */
|
||||
exports.ON_UPDATE_NOW_FLAG = 8192; /* Field is set to NOW on UPDATE */
|
||||
exports.NUM_FLAG = 32768; /* Field is num (for clients) */
|
||||
39
node_modules/mysql/lib/protocol/constants/server_status.js
generated
vendored
Normal file
39
node_modules/mysql/lib/protocol/constants/server_status.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// Manually extracted from mysql-5.5.23/include/mysql_com.h
|
||||
|
||||
/**
|
||||
Is raised when a multi-statement transaction
|
||||
has been started, either explicitly, by means
|
||||
of BEGIN or COMMIT AND CHAIN, or
|
||||
implicitly, by the first transactional
|
||||
statement, when autocommit=off.
|
||||
*/
|
||||
exports.SERVER_STATUS_IN_TRANS = 1;
|
||||
exports.SERVER_STATUS_AUTOCOMMIT = 2; /* Server in auto_commit mode */
|
||||
exports.SERVER_MORE_RESULTS_EXISTS = 8; /* Multi query - next query exists */
|
||||
exports.SERVER_QUERY_NO_GOOD_INDEX_USED = 16;
|
||||
exports.SERVER_QUERY_NO_INDEX_USED = 32;
|
||||
/**
|
||||
The server was able to fulfill the clients request and opened a
|
||||
read-only non-scrollable cursor for a query. This flag comes
|
||||
in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands.
|
||||
*/
|
||||
exports.SERVER_STATUS_CURSOR_EXISTS = 64;
|
||||
/**
|
||||
This flag is sent when a read-only cursor is exhausted, in reply to
|
||||
COM_STMT_FETCH command.
|
||||
*/
|
||||
exports.SERVER_STATUS_LAST_ROW_SENT = 128;
|
||||
exports.SERVER_STATUS_DB_DROPPED = 256; /* A database was dropped */
|
||||
exports.SERVER_STATUS_NO_BACKSLASH_ESCAPES = 512;
|
||||
/**
|
||||
Sent to the client if after a prepared statement reprepare
|
||||
we discovered that the new statement returns a different
|
||||
number of result set columns.
|
||||
*/
|
||||
exports.SERVER_STATUS_METADATA_CHANGED = 1024;
|
||||
exports.SERVER_QUERY_WAS_SLOW = 2048;
|
||||
|
||||
/**
|
||||
To mark ResultSet containing output parameter values.
|
||||
*/
|
||||
exports.SERVER_PS_OUT_PARAMS = 4096;
|
||||
1480
node_modules/mysql/lib/protocol/constants/ssl_profiles.js
generated
vendored
Normal file
1480
node_modules/mysql/lib/protocol/constants/ssl_profiles.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
72
node_modules/mysql/lib/protocol/constants/types.js
generated
vendored
Normal file
72
node_modules/mysql/lib/protocol/constants/types.js
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* MySQL type constants
|
||||
*
|
||||
* Extracted from version 5.7.29
|
||||
*
|
||||
* !! Generated by generate-type-constants.js, do not modify by hand !!
|
||||
*/
|
||||
|
||||
exports.DECIMAL = 0;
|
||||
exports.TINY = 1;
|
||||
exports.SHORT = 2;
|
||||
exports.LONG = 3;
|
||||
exports.FLOAT = 4;
|
||||
exports.DOUBLE = 5;
|
||||
exports.NULL = 6;
|
||||
exports.TIMESTAMP = 7;
|
||||
exports.LONGLONG = 8;
|
||||
exports.INT24 = 9;
|
||||
exports.DATE = 10;
|
||||
exports.TIME = 11;
|
||||
exports.DATETIME = 12;
|
||||
exports.YEAR = 13;
|
||||
exports.NEWDATE = 14;
|
||||
exports.VARCHAR = 15;
|
||||
exports.BIT = 16;
|
||||
exports.TIMESTAMP2 = 17;
|
||||
exports.DATETIME2 = 18;
|
||||
exports.TIME2 = 19;
|
||||
exports.JSON = 245;
|
||||
exports.NEWDECIMAL = 246;
|
||||
exports.ENUM = 247;
|
||||
exports.SET = 248;
|
||||
exports.TINY_BLOB = 249;
|
||||
exports.MEDIUM_BLOB = 250;
|
||||
exports.LONG_BLOB = 251;
|
||||
exports.BLOB = 252;
|
||||
exports.VAR_STRING = 253;
|
||||
exports.STRING = 254;
|
||||
exports.GEOMETRY = 255;
|
||||
|
||||
// Lookup-by-number table
|
||||
exports[0] = 'DECIMAL';
|
||||
exports[1] = 'TINY';
|
||||
exports[2] = 'SHORT';
|
||||
exports[3] = 'LONG';
|
||||
exports[4] = 'FLOAT';
|
||||
exports[5] = 'DOUBLE';
|
||||
exports[6] = 'NULL';
|
||||
exports[7] = 'TIMESTAMP';
|
||||
exports[8] = 'LONGLONG';
|
||||
exports[9] = 'INT24';
|
||||
exports[10] = 'DATE';
|
||||
exports[11] = 'TIME';
|
||||
exports[12] = 'DATETIME';
|
||||
exports[13] = 'YEAR';
|
||||
exports[14] = 'NEWDATE';
|
||||
exports[15] = 'VARCHAR';
|
||||
exports[16] = 'BIT';
|
||||
exports[17] = 'TIMESTAMP2';
|
||||
exports[18] = 'DATETIME2';
|
||||
exports[19] = 'TIME2';
|
||||
exports[245] = 'JSON';
|
||||
exports[246] = 'NEWDECIMAL';
|
||||
exports[247] = 'ENUM';
|
||||
exports[248] = 'SET';
|
||||
exports[249] = 'TINY_BLOB';
|
||||
exports[250] = 'MEDIUM_BLOB';
|
||||
exports[251] = 'LONG_BLOB';
|
||||
exports[252] = 'BLOB';
|
||||
exports[253] = 'VAR_STRING';
|
||||
exports[254] = 'STRING';
|
||||
exports[255] = 'GEOMETRY';
|
||||
20
node_modules/mysql/lib/protocol/packets/AuthSwitchRequestPacket.js
generated
vendored
Normal file
20
node_modules/mysql/lib/protocol/packets/AuthSwitchRequestPacket.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
module.exports = AuthSwitchRequestPacket;
|
||||
function AuthSwitchRequestPacket(options) {
|
||||
options = options || {};
|
||||
|
||||
this.status = 0xfe;
|
||||
this.authMethodName = options.authMethodName;
|
||||
this.authMethodData = options.authMethodData;
|
||||
}
|
||||
|
||||
AuthSwitchRequestPacket.prototype.parse = function parse(parser) {
|
||||
this.status = parser.parseUnsignedNumber(1);
|
||||
this.authMethodName = parser.parseNullTerminatedString();
|
||||
this.authMethodData = parser.parsePacketTerminatedBuffer();
|
||||
};
|
||||
|
||||
AuthSwitchRequestPacket.prototype.write = function write(writer) {
|
||||
writer.writeUnsignedNumber(1, this.status);
|
||||
writer.writeNullTerminatedString(this.authMethodName);
|
||||
writer.writeBuffer(this.authMethodData);
|
||||
};
|
||||
14
node_modules/mysql/lib/protocol/packets/AuthSwitchResponsePacket.js
generated
vendored
Normal file
14
node_modules/mysql/lib/protocol/packets/AuthSwitchResponsePacket.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
module.exports = AuthSwitchResponsePacket;
|
||||
function AuthSwitchResponsePacket(options) {
|
||||
options = options || {};
|
||||
|
||||
this.data = options.data;
|
||||
}
|
||||
|
||||
AuthSwitchResponsePacket.prototype.parse = function parse(parser) {
|
||||
this.data = parser.parsePacketTerminatedBuffer();
|
||||
};
|
||||
|
||||
AuthSwitchResponsePacket.prototype.write = function write(writer) {
|
||||
writer.writeBuffer(this.data);
|
||||
};
|
||||
54
node_modules/mysql/lib/protocol/packets/ClientAuthenticationPacket.js
generated
vendored
Normal file
54
node_modules/mysql/lib/protocol/packets/ClientAuthenticationPacket.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
|
||||
module.exports = ClientAuthenticationPacket;
|
||||
function ClientAuthenticationPacket(options) {
|
||||
options = options || {};
|
||||
|
||||
this.clientFlags = options.clientFlags;
|
||||
this.maxPacketSize = options.maxPacketSize;
|
||||
this.charsetNumber = options.charsetNumber;
|
||||
this.filler = undefined;
|
||||
this.user = options.user;
|
||||
this.scrambleBuff = options.scrambleBuff;
|
||||
this.database = options.database;
|
||||
this.protocol41 = options.protocol41;
|
||||
}
|
||||
|
||||
ClientAuthenticationPacket.prototype.parse = function(parser) {
|
||||
if (this.protocol41) {
|
||||
this.clientFlags = parser.parseUnsignedNumber(4);
|
||||
this.maxPacketSize = parser.parseUnsignedNumber(4);
|
||||
this.charsetNumber = parser.parseUnsignedNumber(1);
|
||||
this.filler = parser.parseFiller(23);
|
||||
this.user = parser.parseNullTerminatedString();
|
||||
this.scrambleBuff = parser.parseLengthCodedBuffer();
|
||||
this.database = parser.parseNullTerminatedString();
|
||||
} else {
|
||||
this.clientFlags = parser.parseUnsignedNumber(2);
|
||||
this.maxPacketSize = parser.parseUnsignedNumber(3);
|
||||
this.user = parser.parseNullTerminatedString();
|
||||
this.scrambleBuff = parser.parseBuffer(8);
|
||||
this.database = parser.parseLengthCodedBuffer();
|
||||
}
|
||||
};
|
||||
|
||||
ClientAuthenticationPacket.prototype.write = function(writer) {
|
||||
if (this.protocol41) {
|
||||
writer.writeUnsignedNumber(4, this.clientFlags);
|
||||
writer.writeUnsignedNumber(4, this.maxPacketSize);
|
||||
writer.writeUnsignedNumber(1, this.charsetNumber);
|
||||
writer.writeFiller(23);
|
||||
writer.writeNullTerminatedString(this.user);
|
||||
writer.writeLengthCodedBuffer(this.scrambleBuff);
|
||||
writer.writeNullTerminatedString(this.database);
|
||||
} else {
|
||||
writer.writeUnsignedNumber(2, this.clientFlags);
|
||||
writer.writeUnsignedNumber(3, this.maxPacketSize);
|
||||
writer.writeNullTerminatedString(this.user);
|
||||
writer.writeBuffer(this.scrambleBuff);
|
||||
if (this.database && this.database.length) {
|
||||
writer.writeFiller(1);
|
||||
writer.writeBuffer(Buffer.from(this.database));
|
||||
}
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user