database registration
This commit is contained in:
parent
9dd6302c51
commit
6d3d4ef6f6
112
bc.js
112
bc.js
@ -1,10 +1,17 @@
|
|||||||
// server.js
|
// bc.js (или server.js - ваш основной файл сервера)
|
||||||
|
// КОД ОСТАЕТСЯ БЕЗ ИЗМЕНЕНИЙ ОТНОСИТЕЛЬНО ПРЕДЫДУЩЕЙ ВЕРСИИ,
|
||||||
|
// ГДЕ УЖЕ БЫЛА ДОБАВЛЕНА ПЕРЕДАЧА characterKey В GameManager
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const socketIo = require('socket.io');
|
const socketIo = require('socket.io');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const GameManager = require('./server_modules/gameManager');
|
|
||||||
const hostname = '81.177.140.16';
|
// Серверные модули
|
||||||
|
const GameManager = require('./server_modules/gameManager'); // GameManager будет изменен
|
||||||
|
const authController = require('./server_modules/auth');
|
||||||
|
|
||||||
|
const hostname = 'localhost';
|
||||||
const app = express();
|
const app = express();
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
const io = socketIo(server);
|
const io = socketIo(server);
|
||||||
@ -13,10 +20,10 @@ const PORT = process.env.PORT || 3200;
|
|||||||
|
|
||||||
app.use(express.static(path.join(__dirname, 'public')));
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
const gameManager = new GameManager(io);
|
const gameManager = new GameManager(io); // GameManager будет содержать новую логику
|
||||||
|
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
console.log('New client connected:', socket.id);
|
console.log('[Server] New client connected:', socket.id);
|
||||||
|
|
||||||
const availableGames = gameManager.getAvailablePvPGamesListForClient();
|
const availableGames = gameManager.getAvailablePvPGamesListForClient();
|
||||||
socket.emit('availablePvPGamesList', availableGames);
|
socket.emit('availablePvPGamesList', availableGames);
|
||||||
@ -26,44 +33,105 @@ io.on('connection', (socket) => {
|
|||||||
socket.emit('availablePvPGamesList', currentAvailableGames);
|
socket.emit('availablePvPGamesList', currentAvailableGames);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('createGame', (data) => { // data = { mode: 'ai' | 'pvp' }
|
socket.on('register', async (data) => {
|
||||||
gameManager.createGame(socket, data.mode);
|
console.log(`[Server BC.JS] Received 'register' event from ${socket.id} with username: ${data?.username}`);
|
||||||
|
if (!data || typeof data.username !== 'string' || typeof data.password !== 'string') {
|
||||||
|
socket.emit('registerResponse', { success: false, message: 'Некорректные данные запроса.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await authController.registerUser(data.username, data.password);
|
||||||
|
socket.emit('registerResponse', result);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('joinGame', (data) => { // Ожидаем data = { gameId: 'СТРОКА' }
|
socket.on('login', async (data) => {
|
||||||
|
console.log(`[Server BC.JS] Received 'login' event from ${socket.id} with username: ${data?.username}`);
|
||||||
|
if (!data || typeof data.username !== 'string' || typeof data.password !== 'string') {
|
||||||
|
socket.emit('loginResponse', { success: false, message: 'Некорректные данные запроса.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await authController.loginUser(data.username, data.password);
|
||||||
|
if (result.success) {
|
||||||
|
socket.userData = { userId: result.userId, username: result.username }; // Сохраняем userId
|
||||||
|
console.log(`[Server BC.JS] User ${result.username} (ID: ${result.userId}) associated with socket ${socket.id}. Welcome!`);
|
||||||
|
}
|
||||||
|
socket.emit('loginResponse', result);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('logout', () => {
|
||||||
|
const username = socket.userData?.username || socket.id;
|
||||||
|
console.log(`[Server BC.JS] Received 'logout' event from ${username}.`);
|
||||||
|
if (socket.userData) {
|
||||||
|
gameManager.handleDisconnect(socket.id); // Обработает выход из игр
|
||||||
|
delete socket.userData;
|
||||||
|
console.log(`[Server BC.JS] User data cleared for ${username}.`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('createGame', (data) => {
|
||||||
|
if (!socket.userData) {
|
||||||
|
socket.emit('gameError', { message: "Ошибка: Вы не авторизованы для создания игры." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const mode = data?.mode || 'ai';
|
||||||
|
const characterKey = (data?.characterKey === 'almagest') ? 'almagest' : 'elena';
|
||||||
|
console.log(`[Server BC.JS] User ${socket.userData.username} (socket: ${socket.id}) requests createGame. Mode: ${mode}, Character: ${characterKey}`);
|
||||||
|
// Передаем socket.userData.userId в GameManager, если он нужен для идентификации пользователя между сессиями
|
||||||
|
gameManager.createGame(socket, mode, characterKey, socket.userData.userId);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('joinGame', (data) => {
|
||||||
|
if (!socket.userData) {
|
||||||
|
socket.emit('gameError', { message: "Ошибка: Вы не авторизованы для присоединения к игре." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(`[Server BC.JS] User ${socket.userData.username} (socket: ${socket.id}) requests joinGame for ID: ${data?.gameId}`);
|
||||||
if (data && typeof data.gameId === 'string') {
|
if (data && typeof data.gameId === 'string') {
|
||||||
gameManager.joinGame(socket, data.gameId);
|
// Передаем socket.userData.userId
|
||||||
|
gameManager.joinGame(socket, data.gameId, socket.userData.userId);
|
||||||
} else {
|
} else {
|
||||||
console.warn(`[bc.js] Неверный формат данных для joinGame от ${socket.id}:`, data);
|
|
||||||
socket.emit('gameError', { message: 'Ошибка присоединения: неверный формат ID игры.' });
|
socket.emit('gameError', { message: 'Ошибка присоединения: неверный формат ID игры.' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('findRandomGame', () => {
|
socket.on('findRandomGame', (data) => {
|
||||||
gameManager.findAndJoinRandomPvPGame(socket);
|
if (!socket.userData) {
|
||||||
|
socket.emit('gameError', { message: "Ошибка: Вы не авторизованы для поиска игры." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const characterKey = (data?.characterKey === 'almagest') ? 'almagest' : 'elena';
|
||||||
|
console.log(`[Server BC.JS] User ${socket.userData.username} (socket: ${socket.id}) requests findRandomGame. Preferred Character: ${characterKey}`);
|
||||||
|
// Передаем socket.userData.userId
|
||||||
|
gameManager.findAndJoinRandomPvPGame(socket, characterKey, socket.userData.userId);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ИЗМЕНЕНО: Убрана проверка на data.gameId для playerAction
|
|
||||||
socket.on('playerAction', (data) => {
|
socket.on('playerAction', (data) => {
|
||||||
// gameManager.handlePlayerAction определит игру по socket.id
|
if (!socket.userData) return;
|
||||||
// и передаст data в GameInstance.
|
|
||||||
gameManager.handlePlayerAction(socket.id, data);
|
gameManager.handlePlayerAction(socket.id, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('requestRestart', (data) => { // Ожидаем data = { gameId: 'СТРОКА' }
|
socket.on('requestRestart', (data) => {
|
||||||
|
if (!socket.userData) {
|
||||||
|
socket.emit('gameError', { message: "Ошибка: Вы не авторизованы для запроса рестарта." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(`[Server BC.JS] User ${socket.userData.username} (socket: ${socket.id}) requests restart for game ID: ${data?.gameId}`);
|
||||||
if (data && typeof data.gameId === 'string') {
|
if (data && typeof data.gameId === 'string') {
|
||||||
gameManager.requestRestart(socket.id, data.gameId);
|
gameManager.requestRestart(socket.id, data.gameId);
|
||||||
} else {
|
} else {
|
||||||
console.warn(`[bc.js] Неверный формат данных для requestRestart от ${socket.id}:`, data);
|
|
||||||
socket.emit('gameError', { message: 'Ошибка рестарта: неверный формат ID игры.' });
|
socket.emit('gameError', { message: 'Ошибка рестарта: неверный формат ID игры.' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('disconnect', (reason) => {
|
||||||
socket.on('disconnect', () => {
|
const username = socket.userData?.username || socket.id;
|
||||||
console.log('Client disconnected:', socket.id);
|
console.log(`[Server] Client ${username} disconnected. Reason: ${reason}. Socket ID: ${socket.id}`);
|
||||||
gameManager.handleDisconnect(socket.id);
|
// Передаем userId, если он есть, для более точной обработки в GameManager
|
||||||
|
const userId = socket.userData?.userId;
|
||||||
|
gameManager.handleDisconnect(socket.id, userId);
|
||||||
|
// socket.userData автоматически очистится для этого объекта socket
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(PORT, hostname, () => console.log(`Server listening on ${hostname}:${PORT}`));
|
server.listen(PORT, hostname, () => {
|
||||||
|
console.log(`Server listening on http://${hostname}:${PORT}`);
|
||||||
|
});
|
1
node_modules/.bin/bcrypt
generated
vendored
Symbolic link
1
node_modules/.bin/bcrypt
generated
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../bcryptjs/bin/bcrypt
|
118
node_modules/.package-lock.json
generated
vendored
118
node_modules/.package-lock.json
generated
vendored
@ -40,6 +40,15 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/base64id": {
|
"node_modules/base64id": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
||||||
@ -49,6 +58,15 @@
|
|||||||
"node": "^4.5.0 || >= 5.9"
|
"node": "^4.5.0 || >= 5.9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/bcryptjs": {
|
||||||
|
"version": "3.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-3.0.2.tgz",
|
||||||
|
"integrity": "sha512-k38b3XOZKv60C4E2hVsXTolJWfkGRMbILBIe2IBITXciy5bOsTKot5kDrf3ZfufQtQOUN5mXceUEpU1rTl9Uog==",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"bin": {
|
||||||
|
"bcrypt": "bin/bcrypt"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/body-parser": {
|
"node_modules/body-parser": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz",
|
||||||
@ -176,6 +194,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/depd": {
|
"node_modules/depd": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
||||||
@ -434,6 +461,15 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/get-intrinsic": {
|
"node_modules/get-intrinsic": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||||
@ -556,6 +592,42 @@
|
|||||||
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
|
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/math-intrinsics": {
|
"node_modules/math-intrinsics": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||||
@ -613,6 +685,38 @@
|
|||||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||||
"license": "MIT"
|
"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/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"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/negotiator": {
|
"node_modules/negotiator": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz",
|
||||||
@ -798,6 +902,11 @@
|
|||||||
"node": ">= 18"
|
"node": ">= 18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"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=="
|
||||||
|
},
|
||||||
"node_modules/serve-static": {
|
"node_modules/serve-static": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz",
|
||||||
@ -1026,6 +1135,15 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"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/statuses": {
|
"node_modules/statuses": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
"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
Executable file
52
node_modules/aws-ssl-profiles/package.json
generated
vendored
Executable 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"
|
||||||
|
}
|
||||||
|
}
|
27
node_modules/bcryptjs/LICENSE
generated
vendored
Normal file
27
node_modules/bcryptjs/LICENSE
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
bcrypt.js
|
||||||
|
---------
|
||||||
|
Copyright (c) 2012 Nevins Bartolomeo <nevins.bartolomeo@gmail.com>
|
||||||
|
Copyright (c) 2012 Shane Girish <shaneGirish@gmail.com>
|
||||||
|
Copyright (c) 2025 Daniel Wirtz <dcode@dcode.io>
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
201
node_modules/bcryptjs/README.md
generated
vendored
Normal file
201
node_modules/bcryptjs/README.md
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
# bcrypt.js
|
||||||
|
|
||||||
|
Optimized bcrypt in JavaScript with zero dependencies, with TypeScript support. Compatible to the C++
|
||||||
|
[bcrypt](https://npmjs.org/package/bcrypt) binding on Node.js and also working in the browser.
|
||||||
|
|
||||||
|
[](https://github.com/dcodeIO/bcrypt.js/actions/workflows/test.yml) [](https://github.com/dcodeIO/bcrypt.js/actions/workflows/publish.yml) [](https://www.npmjs.com/package/bcryptjs)
|
||||||
|
|
||||||
|
## Security considerations
|
||||||
|
|
||||||
|
Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the
|
||||||
|
iteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with
|
||||||
|
increasing computation power. ([see](http://en.wikipedia.org/wiki/Bcrypt))
|
||||||
|
|
||||||
|
While bcrypt.js is compatible to the C++ bcrypt binding, it is written in pure JavaScript and thus slower ([about 30%](https://github.com/dcodeIO/bcrypt.js/wiki/Benchmark)), effectively reducing the number of iterations that can be
|
||||||
|
processed in an equal time span.
|
||||||
|
|
||||||
|
The maximum input length is 72 bytes (note that UTF-8 encoded characters use up to 4 bytes) and the length of generated
|
||||||
|
hashes is 60 characters. Note that maximum input length is not implicitly checked by the library for compatibility with
|
||||||
|
the C++ binding on Node.js, but should be checked with `bcrypt.truncates(password)` where necessary.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
The package exports an ECMAScript module with an UMD fallback.
|
||||||
|
|
||||||
|
```
|
||||||
|
$> npm install bcryptjs
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import bcrypt from "bcryptjs";
|
||||||
|
```
|
||||||
|
|
||||||
|
### Usage with a CDN
|
||||||
|
|
||||||
|
- From GitHub via [jsDelivr](https://www.jsdelivr.com):<br />
|
||||||
|
`https://cdn.jsdelivr.net/gh/dcodeIO/bcrypt.js@TAG/index.js` (ESM)
|
||||||
|
- From npm via [jsDelivr](https://www.jsdelivr.com):<br />
|
||||||
|
`https://cdn.jsdelivr.net/npm/bcryptjs@VERSION/index.js` (ESM)<br />
|
||||||
|
`https://cdn.jsdelivr.net/npm/bcryptjs@VERSION/umd/index.js` (UMD)
|
||||||
|
- From npm via [unpkg](https://unpkg.com):<br />
|
||||||
|
`https://unpkg.com/bcryptjs@VERSION/index.js` (ESM)<br />
|
||||||
|
`https://unpkg.com/bcryptjs@VERSION/umd/index.js` (UMD)
|
||||||
|
|
||||||
|
Replace `TAG` respectively `VERSION` with a [specific version](https://github.com/dcodeIO/bcrypt.js/releases) or omit it (not recommended in production) to use latest.
|
||||||
|
|
||||||
|
When using the ESM variant in a browser, the `crypto` import needs to be stubbed out, for example using an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap). Bundlers should omit it automatically.
|
||||||
|
|
||||||
|
### Usage - Sync
|
||||||
|
|
||||||
|
To hash a password:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const salt = bcrypt.genSaltSync(10);
|
||||||
|
const hash = bcrypt.hashSync("B4c0/\/", salt);
|
||||||
|
// Store hash in your password DB
|
||||||
|
```
|
||||||
|
|
||||||
|
To check a password:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// Load hash from your password DB
|
||||||
|
bcrypt.compareSync("B4c0/\/", hash); // true
|
||||||
|
bcrypt.compareSync("not_bacon", hash); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
Auto-gen a salt and hash:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const hash = bcrypt.hashSync("bacon", 10);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Usage - Async
|
||||||
|
|
||||||
|
To hash a password:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const salt = await bcrypt.genSalt(10);
|
||||||
|
const hash = await bcrypt.hash("B4c0/\/", salt);
|
||||||
|
// Store hash in your password DB
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
bcrypt.genSalt(10, (err, salt) => {
|
||||||
|
bcrypt.hash("B4c0/\/", salt, function (err, hash) {
|
||||||
|
// Store hash in your password DB
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
To check a password:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// Load hash from your password DB
|
||||||
|
await bcrypt.compare("B4c0/\/", hash); // true
|
||||||
|
await bcrypt.compare("not_bacon", hash); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// Load hash from your password DB
|
||||||
|
bcrypt.compare("B4c0/\/", hash, (err, res) => {
|
||||||
|
// res === true
|
||||||
|
});
|
||||||
|
bcrypt.compare("not_bacon", hash, (err, res) => {
|
||||||
|
// res === false
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Auto-gen a salt and hash:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
await bcrypt.hash("B4c0/\/", 10);
|
||||||
|
// Store hash in your password DB
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
bcrypt.hash("B4c0/\/", 10, (err, hash) => {
|
||||||
|
// Store hash in your password DB
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** Under the hood, asynchronous APIs split an operation into small chunks. After the completion of a chunk, the execution of the next chunk is placed on the back of the [JS event queue](https://developer.mozilla.org/en/docs/Web/JavaScript/EventLoop), efficiently yielding for other computation to execute.
|
||||||
|
|
||||||
|
### Usage - Command Line
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: bcrypt <input> [rounds|salt]
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### Callback types
|
||||||
|
|
||||||
|
- **Callback<`T`>**: `(err: Error | null, result?: T) => void`<br />
|
||||||
|
Called with an error on failure or a value of type `T` upon success.
|
||||||
|
|
||||||
|
- **ProgressCallback**: `(percentage: number) => void`<br />
|
||||||
|
Called with the percentage of rounds completed (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.
|
||||||
|
|
||||||
|
- **RandomFallback**: `(length: number) => number[]`<br />
|
||||||
|
Called to obtain random bytes when both [Web Crypto API](http://www.w3.org/TR/WebCryptoAPI/) and Node.js
|
||||||
|
[crypto](http://nodejs.org/api/crypto.html) are not available.
|
||||||
|
|
||||||
|
### Functions
|
||||||
|
|
||||||
|
- bcrypt.**genSaltSync**(rounds?: `number`): `string`<br />
|
||||||
|
Synchronously generates a salt. Number of rounds defaults to 10 when omitted.
|
||||||
|
|
||||||
|
- bcrypt.**genSalt**(rounds?: `number`): `Promise<string>`<br />
|
||||||
|
Asynchronously generates a salt. Number of rounds defaults to 10 when omitted.
|
||||||
|
|
||||||
|
- bcrypt.**genSalt**([rounds: `number`, ]callback: `Callback<string>`): `void`<br />
|
||||||
|
Asynchronously generates a salt. Number of rounds defaults to 10 when omitted.
|
||||||
|
|
||||||
|
- bcrypt.**truncates**(password: `string`): `boolean`<br />
|
||||||
|
Tests if a password will be truncated when hashed, that is its length is greater than 72 bytes when converted to UTF-8.
|
||||||
|
|
||||||
|
- bcrypt.**hashSync**(password: `string`, salt?: `number | string`): `string`
|
||||||
|
Synchronously generates a hash for the given password. Number of rounds defaults to 10 when omitted.
|
||||||
|
|
||||||
|
- bcrypt.**hash**(password: `string`, salt: `number | string`): `Promise<string>`<br />
|
||||||
|
Asynchronously generates a hash for the given password.
|
||||||
|
|
||||||
|
- bcrypt.**hash**(password: `string`, salt: `number | string`, callback: `Callback<string>`, progressCallback?: `ProgressCallback`): `void`<br />
|
||||||
|
Asynchronously generates a hash for the given password.
|
||||||
|
|
||||||
|
- bcrypt.**compareSync**(password: `string`, hash: `string`): `boolean`<br />
|
||||||
|
Synchronously tests a password against a hash.
|
||||||
|
|
||||||
|
- bcrypt.**compare**(password: `string`, hash: `string`): `Promise<boolean>`<br />
|
||||||
|
Asynchronously compares a password against a hash.
|
||||||
|
|
||||||
|
- bcrypt.**compare**(password: `string`, hash: `string`, callback: `Callback<boolean>`, progressCallback?: `ProgressCallback`)<br />
|
||||||
|
Asynchronously compares a password against a hash.
|
||||||
|
|
||||||
|
- bcrypt.**getRounds**(hash: `string`): `number`<br />
|
||||||
|
Gets the number of rounds used to encrypt the specified hash.
|
||||||
|
|
||||||
|
- bcrypt.**getSalt**(hash: `string`): `string`<br />
|
||||||
|
Gets the salt portion from a hash. Does not validate the hash.
|
||||||
|
|
||||||
|
- bcrypt.**setRandomFallback**(random: `RandomFallback`): `void`<br />
|
||||||
|
Sets the pseudo random number generator to use as a fallback if neither [Web Crypto API](http://www.w3.org/TR/WebCryptoAPI/) nor Node.js [crypto](http://nodejs.org/api/crypto.html) are available. Please note: It is highly important that the PRNG used is cryptographically secure and that it is seeded properly!
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
Building the UMD fallback:
|
||||||
|
|
||||||
|
```
|
||||||
|
$> npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
Running the [tests](./tests):
|
||||||
|
|
||||||
|
```
|
||||||
|
$> npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
Based on work started by Shane Girish at [bcrypt-nodejs](https://github.com/shaneGirish/bcrypt-nodejs), which is itself
|
||||||
|
based on [javascript-bcrypt](http://code.google.com/p/javascript-bcrypt/) (New BSD-licensed).
|
23
node_modules/bcryptjs/bin/bcrypt
generated
vendored
Executable file
23
node_modules/bcryptjs/bin/bcrypt
generated
vendored
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import path from "node:path";
|
||||||
|
import bcrypt from "../index.js";
|
||||||
|
|
||||||
|
if (process.argv.length < 3) {
|
||||||
|
console.log(
|
||||||
|
"Usage: " + path.basename(process.argv[1]) + " <input> [rounds|salt]",
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
var salt;
|
||||||
|
if (process.argv.length > 3) {
|
||||||
|
salt = process.argv[3];
|
||||||
|
var rounds = parseInt(salt, 10);
|
||||||
|
if (rounds == salt) {
|
||||||
|
salt = bcrypt.genSaltSync(rounds);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
salt = bcrypt.genSaltSync();
|
||||||
|
}
|
||||||
|
console.log(bcrypt.hashSync(process.argv[2], salt));
|
||||||
|
}
|
3
node_modules/bcryptjs/index.d.ts
generated
vendored
Normal file
3
node_modules/bcryptjs/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import * as bcrypt from "./types.js";
|
||||||
|
export * from "./types.js";
|
||||||
|
export default bcrypt;
|
1161
node_modules/bcryptjs/index.js
generated
vendored
Normal file
1161
node_modules/bcryptjs/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
76
node_modules/bcryptjs/package.json
generated
vendored
Normal file
76
node_modules/bcryptjs/package.json
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
{
|
||||||
|
"name": "bcryptjs",
|
||||||
|
"description": "Optimized bcrypt in plain JavaScript with zero dependencies, with TypeScript support. Compatible to 'bcrypt'.",
|
||||||
|
"version": "3.0.2",
|
||||||
|
"author": "Daniel Wirtz <dcode@dcode.io>",
|
||||||
|
"contributors": [
|
||||||
|
"Shane Girish <shaneGirish@gmail.com> (https://github.com/shaneGirish)",
|
||||||
|
"Alex Murray <> (https://github.com/alexmurray)",
|
||||||
|
"Nicolas Pelletier <> (https://github.com/NicolasPelletier)",
|
||||||
|
"Josh Rogers <> (https://github.com/geekymole)",
|
||||||
|
"Noah Isaacson <noah@nisaacson.com> (https://github.com/nisaacson)"
|
||||||
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "url",
|
||||||
|
"url": "https://github.com/dcodeIO/bcrypt.js.git"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/dcodeIO/bcrypt.js/issues"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"bcrypt",
|
||||||
|
"password",
|
||||||
|
"auth",
|
||||||
|
"authentication",
|
||||||
|
"encryption",
|
||||||
|
"crypt",
|
||||||
|
"crypto"
|
||||||
|
],
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"bcrypt": "bin/bcrypt"
|
||||||
|
},
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"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"
|
||||||
|
],
|
||||||
|
"browser": {
|
||||||
|
"crypto": false
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"bcrypt": "^5.1.1",
|
||||||
|
"esm2umd": "^0.3.1",
|
||||||
|
"prettier": "^3.5.0",
|
||||||
|
"typescript": "^5.7.3"
|
||||||
|
}
|
||||||
|
}
|
157
node_modules/bcryptjs/types.d.ts
generated
vendored
Normal file
157
node_modules/bcryptjs/types.d.ts
generated
vendored
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
// Originally imported from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8b36dbdf95b624b8a7cd7f8416f06c15d274f9e6/types/bcryptjs/index.d.ts
|
||||||
|
// MIT license.
|
||||||
|
|
||||||
|
/** Called with an error on failure or a value of type `T` upon success. */
|
||||||
|
type Callback<T> = (err: Error | null, result?: T) => void;
|
||||||
|
/** Called with the percentage of rounds completed (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms. */
|
||||||
|
type ProgressCallback = (percentage: number) => void;
|
||||||
|
/** Called to obtain random bytes when both Web Crypto API and Node.js crypto are not available. */
|
||||||
|
type RandomFallback = (length: number) => number[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pseudo random number generator to use as a fallback if neither node's crypto module nor the Web Crypto API is available.
|
||||||
|
* Please note: It is highly important that the PRNG used is cryptographically secure and that it is seeded properly!
|
||||||
|
* @param random Function taking the number of bytes to generate as its sole argument, returning the corresponding array of cryptographically secure random byte values.
|
||||||
|
*/
|
||||||
|
export declare function setRandomFallback(random: RandomFallback): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously generates a salt.
|
||||||
|
* @param rounds Number of rounds to use, defaults to 10 if omitted
|
||||||
|
* @return Resulting salt
|
||||||
|
* @throws If a random fallback is required but not set
|
||||||
|
*/
|
||||||
|
export declare function genSaltSync(rounds?: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a salt.
|
||||||
|
* @param rounds Number of rounds to use, defaults to 10 if omitted
|
||||||
|
* @return Promise with resulting salt, if callback has been omitted
|
||||||
|
*/
|
||||||
|
export declare function genSalt(rounds?: number): Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a salt.
|
||||||
|
* @param callback Callback receiving the error, if any, and the resulting salt
|
||||||
|
*/
|
||||||
|
export declare function genSalt(callback: Callback<string>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a salt.
|
||||||
|
* @param rounds Number of rounds to use, defaults to 10 if omitted
|
||||||
|
* @param callback Callback receiving the error, if any, and the resulting salt
|
||||||
|
*/
|
||||||
|
export declare function genSalt(
|
||||||
|
rounds: number,
|
||||||
|
callback: Callback<string>,
|
||||||
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously generates a hash for the given password.
|
||||||
|
* @param password Password to hash
|
||||||
|
* @param salt Salt length to generate or salt to use, default to 10
|
||||||
|
* @return Resulting hash
|
||||||
|
*/
|
||||||
|
export declare function hashSync(
|
||||||
|
password: string,
|
||||||
|
salt?: number | string,
|
||||||
|
): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a hash for the given password.
|
||||||
|
* @param password Password to hash
|
||||||
|
* @param salt Salt length to generate or salt to use
|
||||||
|
* @return Promise with resulting hash, if callback has been omitted
|
||||||
|
*/
|
||||||
|
export declare function hash(
|
||||||
|
password: string,
|
||||||
|
salt: number | string,
|
||||||
|
): Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a hash for the given password.
|
||||||
|
* @param password Password to hash
|
||||||
|
* @param salt Salt length to generate or salt to use
|
||||||
|
* @param callback Callback receiving the error, if any, and the resulting hash
|
||||||
|
* @param progressCallback Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per MAX_EXECUTION_TIME = 100 ms.
|
||||||
|
*/
|
||||||
|
export declare function hash(
|
||||||
|
password: string,
|
||||||
|
salt: number | string,
|
||||||
|
callback?: Callback<string>,
|
||||||
|
progressCallback?: ProgressCallback,
|
||||||
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously tests a password against a hash.
|
||||||
|
* @param password Password to test
|
||||||
|
* @param hash Hash to test against
|
||||||
|
* @return true if matching, otherwise false
|
||||||
|
*/
|
||||||
|
export declare function compareSync(password: string, hash: string): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously tests a password against a hash.
|
||||||
|
* @param password Password to test
|
||||||
|
* @param hash Hash to test against
|
||||||
|
* @return Promise, if callback has been omitted
|
||||||
|
*/
|
||||||
|
export declare function compare(
|
||||||
|
password: string,
|
||||||
|
hash: string,
|
||||||
|
): Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously tests a password against a hash.
|
||||||
|
* @param password Password to test
|
||||||
|
* @param hash Hash to test against
|
||||||
|
* @param callback Callback receiving the error, if any, otherwise the result
|
||||||
|
* @param progressCallback Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per MAX_EXECUTION_TIME = 100 ms.
|
||||||
|
*/
|
||||||
|
export declare function compare(
|
||||||
|
password: string,
|
||||||
|
hash: string,
|
||||||
|
callback?: Callback<boolean>,
|
||||||
|
progressCallback?: ProgressCallback,
|
||||||
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of rounds used to encrypt the specified hash.
|
||||||
|
* @param hash Hash to extract the used number of rounds from
|
||||||
|
* @return Number of rounds used
|
||||||
|
*/
|
||||||
|
export declare function getRounds(hash: string): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the salt portion from a hash. Does not validate the hash.
|
||||||
|
* @param hash Hash to extract the salt from
|
||||||
|
* @return Extracted salt part
|
||||||
|
*/
|
||||||
|
export declare function getSalt(hash: string): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if a password will be truncated when hashed, that is its length is
|
||||||
|
* greater than 72 bytes when converted to UTF-8.
|
||||||
|
* @param password The password to test
|
||||||
|
* @returns `true` if truncated, otherwise `false`
|
||||||
|
*/
|
||||||
|
export declare function truncates(password: string): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a byte array to base64 with up to len bytes of input, using the custom bcrypt alphabet.
|
||||||
|
* @function
|
||||||
|
* @param b Byte array
|
||||||
|
* @param len Maximum input length
|
||||||
|
*/
|
||||||
|
export declare function encodeBase64(
|
||||||
|
b: Readonly<ArrayLike<number>>,
|
||||||
|
len: number,
|
||||||
|
): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a base64 encoded string to up to len bytes of output, using the custom bcrypt alphabet.
|
||||||
|
* @function
|
||||||
|
* @param s String to decode
|
||||||
|
* @param len Maximum output length
|
||||||
|
*/
|
||||||
|
export declare function decodeBase64(s: string, len: number): number[];
|
3
node_modules/bcryptjs/umd/index.d.ts
generated
vendored
Normal file
3
node_modules/bcryptjs/umd/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import * as bcrypt from "./types.js";
|
||||||
|
export = bcrypt;
|
||||||
|
export as namespace bcrypt;
|
1221
node_modules/bcryptjs/umd/index.js
generated
vendored
Normal file
1221
node_modules/bcryptjs/umd/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
node_modules/bcryptjs/umd/package.json
generated
vendored
Normal file
3
node_modules/bcryptjs/umd/package.json
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "commonjs"
|
||||||
|
}
|
157
node_modules/bcryptjs/umd/types.d.ts
generated
vendored
Normal file
157
node_modules/bcryptjs/umd/types.d.ts
generated
vendored
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
// Originally imported from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8b36dbdf95b624b8a7cd7f8416f06c15d274f9e6/types/bcryptjs/index.d.ts
|
||||||
|
// MIT license.
|
||||||
|
|
||||||
|
/** Called with an error on failure or a value of type `T` upon success. */
|
||||||
|
type Callback<T> = (err: Error | null, result?: T) => void;
|
||||||
|
/** Called with the percentage of rounds completed (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms. */
|
||||||
|
type ProgressCallback = (percentage: number) => void;
|
||||||
|
/** Called to obtain random bytes when both Web Crypto API and Node.js crypto are not available. */
|
||||||
|
type RandomFallback = (length: number) => number[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pseudo random number generator to use as a fallback if neither node's crypto module nor the Web Crypto API is available.
|
||||||
|
* Please note: It is highly important that the PRNG used is cryptographically secure and that it is seeded properly!
|
||||||
|
* @param random Function taking the number of bytes to generate as its sole argument, returning the corresponding array of cryptographically secure random byte values.
|
||||||
|
*/
|
||||||
|
export declare function setRandomFallback(random: RandomFallback): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously generates a salt.
|
||||||
|
* @param rounds Number of rounds to use, defaults to 10 if omitted
|
||||||
|
* @return Resulting salt
|
||||||
|
* @throws If a random fallback is required but not set
|
||||||
|
*/
|
||||||
|
export declare function genSaltSync(rounds?: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a salt.
|
||||||
|
* @param rounds Number of rounds to use, defaults to 10 if omitted
|
||||||
|
* @return Promise with resulting salt, if callback has been omitted
|
||||||
|
*/
|
||||||
|
export declare function genSalt(rounds?: number): Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a salt.
|
||||||
|
* @param callback Callback receiving the error, if any, and the resulting salt
|
||||||
|
*/
|
||||||
|
export declare function genSalt(callback: Callback<string>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a salt.
|
||||||
|
* @param rounds Number of rounds to use, defaults to 10 if omitted
|
||||||
|
* @param callback Callback receiving the error, if any, and the resulting salt
|
||||||
|
*/
|
||||||
|
export declare function genSalt(
|
||||||
|
rounds: number,
|
||||||
|
callback: Callback<string>,
|
||||||
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously generates a hash for the given password.
|
||||||
|
* @param password Password to hash
|
||||||
|
* @param salt Salt length to generate or salt to use, default to 10
|
||||||
|
* @return Resulting hash
|
||||||
|
*/
|
||||||
|
export declare function hashSync(
|
||||||
|
password: string,
|
||||||
|
salt?: number | string,
|
||||||
|
): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a hash for the given password.
|
||||||
|
* @param password Password to hash
|
||||||
|
* @param salt Salt length to generate or salt to use
|
||||||
|
* @return Promise with resulting hash, if callback has been omitted
|
||||||
|
*/
|
||||||
|
export declare function hash(
|
||||||
|
password: string,
|
||||||
|
salt: number | string,
|
||||||
|
): Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously generates a hash for the given password.
|
||||||
|
* @param password Password to hash
|
||||||
|
* @param salt Salt length to generate or salt to use
|
||||||
|
* @param callback Callback receiving the error, if any, and the resulting hash
|
||||||
|
* @param progressCallback Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per MAX_EXECUTION_TIME = 100 ms.
|
||||||
|
*/
|
||||||
|
export declare function hash(
|
||||||
|
password: string,
|
||||||
|
salt: number | string,
|
||||||
|
callback?: Callback<string>,
|
||||||
|
progressCallback?: ProgressCallback,
|
||||||
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously tests a password against a hash.
|
||||||
|
* @param password Password to test
|
||||||
|
* @param hash Hash to test against
|
||||||
|
* @return true if matching, otherwise false
|
||||||
|
*/
|
||||||
|
export declare function compareSync(password: string, hash: string): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously tests a password against a hash.
|
||||||
|
* @param password Password to test
|
||||||
|
* @param hash Hash to test against
|
||||||
|
* @return Promise, if callback has been omitted
|
||||||
|
*/
|
||||||
|
export declare function compare(
|
||||||
|
password: string,
|
||||||
|
hash: string,
|
||||||
|
): Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously tests a password against a hash.
|
||||||
|
* @param password Password to test
|
||||||
|
* @param hash Hash to test against
|
||||||
|
* @param callback Callback receiving the error, if any, otherwise the result
|
||||||
|
* @param progressCallback Callback successively called with the percentage of rounds completed (0.0 - 1.0), maximally once per MAX_EXECUTION_TIME = 100 ms.
|
||||||
|
*/
|
||||||
|
export declare function compare(
|
||||||
|
password: string,
|
||||||
|
hash: string,
|
||||||
|
callback?: Callback<boolean>,
|
||||||
|
progressCallback?: ProgressCallback,
|
||||||
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of rounds used to encrypt the specified hash.
|
||||||
|
* @param hash Hash to extract the used number of rounds from
|
||||||
|
* @return Number of rounds used
|
||||||
|
*/
|
||||||
|
export declare function getRounds(hash: string): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the salt portion from a hash. Does not validate the hash.
|
||||||
|
* @param hash Hash to extract the salt from
|
||||||
|
* @return Extracted salt part
|
||||||
|
*/
|
||||||
|
export declare function getSalt(hash: string): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if a password will be truncated when hashed, that is its length is
|
||||||
|
* greater than 72 bytes when converted to UTF-8.
|
||||||
|
* @param password The password to test
|
||||||
|
* @returns `true` if truncated, otherwise `false`
|
||||||
|
*/
|
||||||
|
export declare function truncates(password: string): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a byte array to base64 with up to len bytes of input, using the custom bcrypt alphabet.
|
||||||
|
* @function
|
||||||
|
* @param b Byte array
|
||||||
|
* @param len Maximum input length
|
||||||
|
*/
|
||||||
|
export declare function encodeBase64(
|
||||||
|
b: Readonly<ArrayLike<number>>,
|
||||||
|
len: number,
|
||||||
|
): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a base64 encoded string to up to len bytes of output, using the custom bcrypt alphabet.
|
||||||
|
* @function
|
||||||
|
* @param s String to decode
|
||||||
|
* @param len Maximum output length
|
||||||
|
*/
|
||||||
|
export declare function decodeBase64(s: string, len: number): number[];
|
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"
|
||||||
|
]
|
||||||
|
}
|
19
node_modules/mysql2/License
generated
vendored
Normal file
19
node_modules/mysql2/License
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2016 Andrey Sidorov (sidorares@yandex.ru) 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.
|
114
node_modules/mysql2/README.md
generated
vendored
Normal file
114
node_modules/mysql2/README.md
generated
vendored
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
[npm-image]: https://img.shields.io/npm/v/mysql2.svg
|
||||||
|
[npm-url]: https://npmjs.com/package/mysql2
|
||||||
|
[node-version-image]: https://img.shields.io/node/v/mysql2.svg
|
||||||
|
[node-version-url]: https://nodejs.org/en/download
|
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/mysql2.svg
|
||||||
|
[downloads-url]: https://npmjs.com/package/mysql2
|
||||||
|
[license-url]: https://github.com/sidorares/node-mysql2/blob/master/License
|
||||||
|
[license-image]: https://img.shields.io/npm/l/mysql2.svg?maxAge=2592000
|
||||||
|
[node-mysql]: https://github.com/mysqljs/mysql
|
||||||
|
[mysqljs]: https://github.com/mysqljs
|
||||||
|
[mysql-native]: https://github.com/sidorares/nodejs-mysql-native
|
||||||
|
[sidorares]: https://github.com/sidorares
|
||||||
|
[TooTallNate]: https://gist.github.com/TooTallNate
|
||||||
|
[starttls.js]: https://gist.github.com/TooTallNate/848444
|
||||||
|
[node-mariasql]: https://github.com/mscdex/node-mariasql
|
||||||
|
[contributors]: https://github.com/sidorares/node-mysql2/graphs/contributors
|
||||||
|
[contributing]: https://github.com/sidorares/node-mysql2/blob/master/Contributing.md
|
||||||
|
[docs-base]: https://sidorares.github.io/node-mysql2/docs
|
||||||
|
[docs-base-zh-CN]: https://sidorares.github.io/node-mysql2/zh-CN/docs
|
||||||
|
[docs-base-pt-BR]: https://sidorares.github.io/node-mysql2/pt-BR/docs
|
||||||
|
[docs-prepared-statements]: https://sidorares.github.io/node-mysql2/docs/documentation/prepared-statements
|
||||||
|
[docs-mysql-server]: https://sidorares.github.io/node-mysql2/docs/documentation/mysql-server
|
||||||
|
[docs-promise-wrapper]: https://sidorares.github.io/node-mysql2/docs/documentation/promise-wrapper
|
||||||
|
[docs-authentication-switch]: https://sidorares.github.io/node-mysql2/docs/documentation/authentication-switch
|
||||||
|
[docs-streams]: https://sidorares.github.io/node-mysql2/docs/documentation/extras
|
||||||
|
[docs-typescript-docs]: https://sidorares.github.io/node-mysql2/docs/documentation/typescript-examples
|
||||||
|
[docs-qs-pooling]: https://sidorares.github.io/node-mysql2/docs#using-connection-pools
|
||||||
|
[docs-qs-first-query]: https://sidorares.github.io/node-mysql2/docs#first-query
|
||||||
|
[docs-qs-using-prepared-statements]: https://sidorares.github.io/node-mysql2/docs#using-prepared-statements
|
||||||
|
[docs-examples]: https://sidorares.github.io/node-mysql2/docs/examples
|
||||||
|
[docs-faq]: https://sidorares.github.io/node-mysql2/docs/faq
|
||||||
|
[docs-documentation]: https://sidorares.github.io/node-mysql2/docs/documentation
|
||||||
|
[docs-contributing]: https://sidorares.github.io/node-mysql2/docs/contributing/website
|
||||||
|
[coverage]: https://img.shields.io/codecov/c/github/sidorares/node-mysql2
|
||||||
|
[coverage-url]: https://app.codecov.io/github/sidorares/node-mysql2
|
||||||
|
[ci-url]: https://github.com/sidorares/node-mysql2/actions/workflows/ci-coverage.yml?query=branch%3Amaster
|
||||||
|
[ci-image]: https://img.shields.io/github/actions/workflow/status/sidorares/node-mysql2/ci-coverage.yml?event=push&style=flat&label=CI&branch=master
|
||||||
|
|
||||||
|
# MySQL2
|
||||||
|
|
||||||
|
[![NPM Version][npm-image]][npm-url]
|
||||||
|
[![NPM Downloads][downloads-image]][downloads-url]
|
||||||
|
[![Node.js Version][node-version-image]][node-version-url]
|
||||||
|
[![GitHub Workflow Status (with event)][ci-image]][ci-url]
|
||||||
|
[![Codecov][coverage]][coverage-url]
|
||||||
|
[![License][license-image]][license-url]
|
||||||
|
|
||||||
|
[English][docs-base] | [简体中文][docs-base-zh-CN] | [Português (BR)][docs-base-pt-BR]
|
||||||
|
|
||||||
|
> MySQL client for Node.js with focus on performance. Supports prepared statements, non-utf8 encodings, binary log protocol, compression, ssl [much more][docs-documentation].
|
||||||
|
|
||||||
|
**Table of Contents**
|
||||||
|
|
||||||
|
- [History and Why MySQL2](#history-and-why-mysql2)
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Documentation](#documentation)
|
||||||
|
- [Acknowledgements](#acknowledgements)
|
||||||
|
- [Contributing](#contributing)
|
||||||
|
|
||||||
|
## History and Why MySQL2
|
||||||
|
|
||||||
|
MySQL2 project is a continuation of [MySQL-Native][mysql-native]. Protocol parser code was rewritten from scratch and api changed to match popular [Node MySQL][node-mysql]. MySQL2 team is working together with [Node MySQL][node-mysql] team to factor out shared code and move it under [mysqljs][mysqljs] organization.
|
||||||
|
|
||||||
|
MySQL2 is mostly API compatible with [Node MySQL][node-mysql] and supports majority of features. MySQL2 also offers these additional features:
|
||||||
|
|
||||||
|
- Faster / Better Performance
|
||||||
|
- [Prepared Statements][docs-prepared-statements]
|
||||||
|
- MySQL Binary Log Protocol
|
||||||
|
- [MySQL Server][docs-mysql-server]
|
||||||
|
- Extended support for Encoding and Collation
|
||||||
|
- [Promise Wrapper][docs-promise-wrapper]
|
||||||
|
- Compression
|
||||||
|
- SSL and [Authentication Switch][docs-authentication-switch]
|
||||||
|
- [Custom Streams][docs-streams]
|
||||||
|
- [Pooling][docs-qs-pooling]
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
MySQL2 is free from native bindings and can be installed on Linux, Mac OS or Windows without any issues.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install --save mysql2
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using TypeScript, you will need to install `@types/node`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install --save-dev @types/node
|
||||||
|
```
|
||||||
|
|
||||||
|
> For TypeScript documentation and examples, see [here][docs-typescript-docs].
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
- [Quickstart][docs-base]
|
||||||
|
- [First Query][docs-qs-first-query], [Using Prepared Statements][docs-qs-using-prepared-statements], [Using Connection Pools][docs-qs-pooling] and more.
|
||||||
|
- [Documentation][docs-documentation]
|
||||||
|
- [Examples][docs-examples]
|
||||||
|
- [FAQ][docs-faq]
|
||||||
|
|
||||||
|
## Acknowledgements
|
||||||
|
|
||||||
|
- Internal protocol is written by [@sidorares][sidorares] [MySQL-Native][mysql-native].
|
||||||
|
- Constants, SQL parameters interpolation, Pooling, `ConnectionConfig` class taken from [Node MySQL][node-mysql].
|
||||||
|
- SSL upgrade code based on [@TooTallNate][TooTallNate] [code][starttls.js].
|
||||||
|
- Secure connection / compressed connection api flags compatible to [MariaSQL][node-mariasql] client.
|
||||||
|
- [Contributors][contributors].
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Want to improve something in **MySQL2**?
|
||||||
|
Please check [Contributing.md][contributing] for detailed instruction on how to get started.
|
||||||
|
|
||||||
|
To contribute in **MySQL2 Documentation**, please visit the [Website Contributing Guidelines][docs-contributing] for detailed instruction on how to get started.
|
1
node_modules/mysql2/index.d.ts
generated
vendored
Normal file
1
node_modules/mysql2/index.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './typings/mysql/index.js';
|
77
node_modules/mysql2/index.js
generated
vendored
Normal file
77
node_modules/mysql2/index.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const SqlString = require('sqlstring');
|
||||||
|
|
||||||
|
const ConnectionConfig = require('./lib/connection_config.js');
|
||||||
|
const parserCache = require('./lib/parsers/parser_cache.js');
|
||||||
|
|
||||||
|
const Connection = require('./lib/connection.js');
|
||||||
|
|
||||||
|
exports.createConnection = require('./lib/create_connection.js');
|
||||||
|
exports.connect = exports.createConnection;
|
||||||
|
exports.Connection = Connection;
|
||||||
|
exports.ConnectionConfig = ConnectionConfig;
|
||||||
|
|
||||||
|
const Pool = require('./lib/pool.js');
|
||||||
|
const PoolCluster = require('./lib/pool_cluster.js');
|
||||||
|
const createPool = require('./lib/create_pool.js');
|
||||||
|
const createPoolCluster = require('./lib/create_pool_cluster.js');
|
||||||
|
|
||||||
|
exports.createPool = createPool;
|
||||||
|
|
||||||
|
exports.createPoolCluster = createPoolCluster;
|
||||||
|
|
||||||
|
exports.createQuery = Connection.createQuery;
|
||||||
|
|
||||||
|
exports.Pool = Pool;
|
||||||
|
|
||||||
|
exports.PoolCluster = PoolCluster;
|
||||||
|
|
||||||
|
exports.createServer = function (handler) {
|
||||||
|
const Server = require('./lib/server.js');
|
||||||
|
const s = new Server();
|
||||||
|
if (handler) {
|
||||||
|
s.on('connection', handler);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.PoolConnection = require('./lib/pool_connection.js');
|
||||||
|
exports.authPlugins = require('./lib/auth_plugins');
|
||||||
|
exports.escape = SqlString.escape;
|
||||||
|
exports.escapeId = SqlString.escapeId;
|
||||||
|
exports.format = SqlString.format;
|
||||||
|
exports.raw = SqlString.raw;
|
||||||
|
|
||||||
|
exports.__defineGetter__(
|
||||||
|
'createConnectionPromise',
|
||||||
|
() => require('./promise.js').createConnection
|
||||||
|
);
|
||||||
|
|
||||||
|
exports.__defineGetter__(
|
||||||
|
'createPoolPromise',
|
||||||
|
() => require('./promise.js').createPool
|
||||||
|
);
|
||||||
|
|
||||||
|
exports.__defineGetter__(
|
||||||
|
'createPoolClusterPromise',
|
||||||
|
() => require('./promise.js').createPoolCluster
|
||||||
|
);
|
||||||
|
|
||||||
|
exports.__defineGetter__('Types', () => require('./lib/constants/types.js'));
|
||||||
|
|
||||||
|
exports.__defineGetter__('Charsets', () =>
|
||||||
|
require('./lib/constants/charsets.js')
|
||||||
|
);
|
||||||
|
|
||||||
|
exports.__defineGetter__('CharsetToEncoding', () =>
|
||||||
|
require('./lib/constants/charset_encodings.js')
|
||||||
|
);
|
||||||
|
|
||||||
|
exports.setMaxParserCache = function (max) {
|
||||||
|
parserCache.setMaxCache(max);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.clearParserCache = function () {
|
||||||
|
parserCache.clearCache();
|
||||||
|
};
|
95
node_modules/mysql2/lib/auth_41.js
generated
vendored
Normal file
95
node_modules/mysql2/lib/auth_41.js
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/*
|
||||||
|
4.1 authentication: (http://bazaar.launchpad.net/~mysql/mysql-server/5.5/view/head:/sql/password.c)
|
||||||
|
|
||||||
|
SERVER: public_seed=create_random_string()
|
||||||
|
send(public_seed)
|
||||||
|
|
||||||
|
CLIENT: recv(public_seed)
|
||||||
|
hash_stage1=sha1("password")
|
||||||
|
hash_stage2=sha1(hash_stage1)
|
||||||
|
reply=xor(hash_stage1, sha1(public_seed,hash_stage2)
|
||||||
|
|
||||||
|
// this three steps are done in scramble()
|
||||||
|
|
||||||
|
send(reply)
|
||||||
|
|
||||||
|
|
||||||
|
SERVER: recv(reply)
|
||||||
|
hash_stage1=xor(reply, sha1(public_seed,hash_stage2))
|
||||||
|
candidate_hash2=sha1(hash_stage1)
|
||||||
|
check(candidate_hash2==hash_stage2)
|
||||||
|
|
||||||
|
server stores sha1(sha1(password)) ( hash_stag2)
|
||||||
|
*/
|
||||||
|
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
function sha1(msg, msg1, msg2) {
|
||||||
|
const hash = crypto.createHash('sha1');
|
||||||
|
hash.update(msg);
|
||||||
|
if (msg1) {
|
||||||
|
hash.update(msg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg2) {
|
||||||
|
hash.update(msg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash.digest();
|
||||||
|
}
|
||||||
|
|
||||||
|
function xor(a, b) {
|
||||||
|
const result = Buffer.allocUnsafe(a.length);
|
||||||
|
for (let i = 0; i < a.length; i++) {
|
||||||
|
result[i] = a[i] ^ b[i];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.xor = xor;
|
||||||
|
|
||||||
|
function token(password, scramble1, scramble2) {
|
||||||
|
if (!password) {
|
||||||
|
return Buffer.alloc(0);
|
||||||
|
}
|
||||||
|
const stage1 = sha1(password);
|
||||||
|
return exports.calculateTokenFromPasswordSha(stage1, scramble1, scramble2);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.calculateTokenFromPasswordSha = function (
|
||||||
|
passwordSha,
|
||||||
|
scramble1,
|
||||||
|
scramble2
|
||||||
|
) {
|
||||||
|
// we use AUTH 41 here, and we need only the bytes we just need.
|
||||||
|
const authPluginData1 = scramble1.slice(0, 8);
|
||||||
|
const authPluginData2 = scramble2.slice(0, 12);
|
||||||
|
const stage2 = sha1(passwordSha);
|
||||||
|
const stage3 = sha1(authPluginData1, authPluginData2, stage2);
|
||||||
|
return xor(stage3, passwordSha);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.calculateToken = token;
|
||||||
|
|
||||||
|
exports.verifyToken = function (publicSeed1, publicSeed2, token, doubleSha) {
|
||||||
|
const hashStage1 = xor(token, sha1(publicSeed1, publicSeed2, doubleSha));
|
||||||
|
const candidateHash2 = sha1(hashStage1);
|
||||||
|
return candidateHash2.compare(doubleSha) === 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.doubleSha1 = function (password) {
|
||||||
|
return sha1(sha1(password));
|
||||||
|
};
|
||||||
|
|
||||||
|
function xorRotating(a, seed) {
|
||||||
|
const result = Buffer.allocUnsafe(a.length);
|
||||||
|
const seedLen = seed.length;
|
||||||
|
|
||||||
|
for (let i = 0; i < a.length; i++) {
|
||||||
|
result[i] = a[i] ^ seed[i % seedLen];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
exports.xorRotating = xorRotating;
|
108
node_modules/mysql2/lib/auth_plugins/caching_sha2_password.js
generated
vendored
Normal file
108
node_modules/mysql2/lib/auth_plugins/caching_sha2_password.js
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// https://mysqlserverteam.com/mysql-8-0-4-new-default-authentication-plugin-caching_sha2_password/
|
||||||
|
|
||||||
|
const PLUGIN_NAME = 'caching_sha2_password';
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const { xor, xorRotating } = require('../auth_41');
|
||||||
|
|
||||||
|
const REQUEST_SERVER_KEY_PACKET = Buffer.from([2]);
|
||||||
|
const FAST_AUTH_SUCCESS_PACKET = Buffer.from([3]);
|
||||||
|
const PERFORM_FULL_AUTHENTICATION_PACKET = Buffer.from([4]);
|
||||||
|
|
||||||
|
const STATE_INITIAL = 0;
|
||||||
|
const STATE_TOKEN_SENT = 1;
|
||||||
|
const STATE_WAIT_SERVER_KEY = 2;
|
||||||
|
const STATE_FINAL = -1;
|
||||||
|
|
||||||
|
function sha256(msg) {
|
||||||
|
const hash = crypto.createHash('sha256');
|
||||||
|
hash.update(msg);
|
||||||
|
return hash.digest();
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateToken(password, scramble) {
|
||||||
|
if (!password) {
|
||||||
|
return Buffer.alloc(0);
|
||||||
|
}
|
||||||
|
const stage1 = sha256(Buffer.from(password));
|
||||||
|
const stage2 = sha256(stage1);
|
||||||
|
const stage3 = sha256(Buffer.concat([stage2, scramble]));
|
||||||
|
return xor(stage1, stage3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function encrypt(password, scramble, key) {
|
||||||
|
const stage1 = xorRotating(Buffer.from(`${password}\0`, 'utf8'), scramble);
|
||||||
|
return crypto.publicEncrypt(
|
||||||
|
{
|
||||||
|
key,
|
||||||
|
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
|
||||||
|
},
|
||||||
|
stage1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports =
|
||||||
|
(pluginOptions = {}) =>
|
||||||
|
({ connection }) => {
|
||||||
|
let state = 0;
|
||||||
|
let scramble = null;
|
||||||
|
|
||||||
|
const password = connection.config.password;
|
||||||
|
|
||||||
|
const authWithKey = (serverKey) => {
|
||||||
|
const _password = encrypt(password, scramble, serverKey);
|
||||||
|
state = STATE_FINAL;
|
||||||
|
return _password;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (data) => {
|
||||||
|
switch (state) {
|
||||||
|
case STATE_INITIAL:
|
||||||
|
scramble = data.slice(0, 20);
|
||||||
|
state = STATE_TOKEN_SENT;
|
||||||
|
return calculateToken(password, scramble);
|
||||||
|
|
||||||
|
case STATE_TOKEN_SENT:
|
||||||
|
if (FAST_AUTH_SUCCESS_PACKET.equals(data)) {
|
||||||
|
state = STATE_FINAL;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PERFORM_FULL_AUTHENTICATION_PACKET.equals(data)) {
|
||||||
|
const isSecureConnection =
|
||||||
|
typeof pluginOptions.overrideIsSecure === 'undefined'
|
||||||
|
? connection.config.ssl || connection.config.socketPath
|
||||||
|
: pluginOptions.overrideIsSecure;
|
||||||
|
if (isSecureConnection) {
|
||||||
|
state = STATE_FINAL;
|
||||||
|
return Buffer.from(`${password}\0`, 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
// if client provides key we can save one extra roundrip on first connection
|
||||||
|
if (pluginOptions.serverPublicKey) {
|
||||||
|
return authWithKey(pluginOptions.serverPublicKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
state = STATE_WAIT_SERVER_KEY;
|
||||||
|
return REQUEST_SERVER_KEY_PACKET;
|
||||||
|
}
|
||||||
|
throw new Error(
|
||||||
|
`Invalid AuthMoreData packet received by ${PLUGIN_NAME} plugin in STATE_TOKEN_SENT state.`
|
||||||
|
);
|
||||||
|
case STATE_WAIT_SERVER_KEY:
|
||||||
|
if (pluginOptions.onServerPublicKey) {
|
||||||
|
pluginOptions.onServerPublicKey(data);
|
||||||
|
}
|
||||||
|
return authWithKey(data);
|
||||||
|
case STATE_FINAL:
|
||||||
|
throw new Error(
|
||||||
|
`Unexpected data in AuthMoreData packet received by ${PLUGIN_NAME} plugin in STATE_FINAL state.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Unexpected data in AuthMoreData packet received by ${PLUGIN_NAME} plugin in state ${state}`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
18
node_modules/mysql2/lib/auth_plugins/caching_sha2_password.md
generated
vendored
Normal file
18
node_modules/mysql2/lib/auth_plugins/caching_sha2_password.md
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
##
|
||||||
|
|
||||||
|
https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html
|
||||||
|
|
||||||
|
```js
|
||||||
|
const mysql = require('mysql');
|
||||||
|
mysql.createConnection({
|
||||||
|
authPlugins: {
|
||||||
|
caching_sha2_password: mysql.authPlugins.caching_sha2_password({
|
||||||
|
onServerPublikKey: function (key) {
|
||||||
|
console.log(key);
|
||||||
|
},
|
||||||
|
serverPublicKey: 'xxxyyy',
|
||||||
|
overrideIsSecure: true, //
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
8
node_modules/mysql2/lib/auth_plugins/index.js
generated
vendored
Normal file
8
node_modules/mysql2/lib/auth_plugins/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
caching_sha2_password: require('./caching_sha2_password'),
|
||||||
|
mysql_clear_password: require('./mysql_clear_password'),
|
||||||
|
mysql_native_password: require('./mysql_native_password'),
|
||||||
|
sha256_password: require('./sha256_password'),
|
||||||
|
};
|
17
node_modules/mysql2/lib/auth_plugins/mysql_clear_password.js
generated
vendored
Normal file
17
node_modules/mysql2/lib/auth_plugins/mysql_clear_password.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
function bufferFromStr(str) {
|
||||||
|
return Buffer.from(`${str}\0`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const create_mysql_clear_password_plugin = (pluginOptions) =>
|
||||||
|
function mysql_clear_password_plugin({ connection, command }) {
|
||||||
|
const password =
|
||||||
|
command.password || pluginOptions.password || connection.config.password;
|
||||||
|
|
||||||
|
return function (/* pluginData */) {
|
||||||
|
return bufferFromStr(password);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = create_mysql_clear_password_plugin;
|
34
node_modules/mysql2/lib/auth_plugins/mysql_native_password.js
generated
vendored
Normal file
34
node_modules/mysql2/lib/auth_plugins/mysql_native_password.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
//const PLUGIN_NAME = 'mysql_native_password';
|
||||||
|
const auth41 = require('../auth_41.js');
|
||||||
|
|
||||||
|
module.exports =
|
||||||
|
(pluginOptions) =>
|
||||||
|
({ connection, command }) => {
|
||||||
|
const password =
|
||||||
|
command.password || pluginOptions.password || connection.config.password;
|
||||||
|
const passwordSha1 =
|
||||||
|
command.passwordSha1 ||
|
||||||
|
pluginOptions.passwordSha1 ||
|
||||||
|
connection.config.passwordSha1;
|
||||||
|
return (data) => {
|
||||||
|
const authPluginData1 = data.slice(0, 8);
|
||||||
|
const authPluginData2 = data.slice(8, 20);
|
||||||
|
let authToken;
|
||||||
|
if (passwordSha1) {
|
||||||
|
authToken = auth41.calculateTokenFromPasswordSha(
|
||||||
|
passwordSha1,
|
||||||
|
authPluginData1,
|
||||||
|
authPluginData2
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
authToken = auth41.calculateToken(
|
||||||
|
password,
|
||||||
|
authPluginData1,
|
||||||
|
authPluginData2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return authToken;
|
||||||
|
};
|
||||||
|
};
|
59
node_modules/mysql2/lib/auth_plugins/sha256_password.js
generated
vendored
Normal file
59
node_modules/mysql2/lib/auth_plugins/sha256_password.js
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const PLUGIN_NAME = 'sha256_password';
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const { xorRotating } = require('../auth_41');
|
||||||
|
|
||||||
|
const REQUEST_SERVER_KEY_PACKET = Buffer.from([1]);
|
||||||
|
|
||||||
|
const STATE_INITIAL = 0;
|
||||||
|
const STATE_WAIT_SERVER_KEY = 1;
|
||||||
|
const STATE_FINAL = -1;
|
||||||
|
|
||||||
|
function encrypt(password, scramble, key) {
|
||||||
|
const stage1 = xorRotating(Buffer.from(`${password}\0`, 'utf8'), scramble);
|
||||||
|
return crypto.publicEncrypt(key, stage1);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports =
|
||||||
|
(pluginOptions = {}) =>
|
||||||
|
({ connection }) => {
|
||||||
|
let state = 0;
|
||||||
|
let scramble = null;
|
||||||
|
|
||||||
|
const password = connection.config.password;
|
||||||
|
|
||||||
|
const authWithKey = (serverKey) => {
|
||||||
|
const _password = encrypt(password, scramble, serverKey);
|
||||||
|
state = STATE_FINAL;
|
||||||
|
return _password;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (data) => {
|
||||||
|
switch (state) {
|
||||||
|
case STATE_INITIAL:
|
||||||
|
scramble = data.slice(0, 20);
|
||||||
|
// if client provides key we can save one extra roundrip on first connection
|
||||||
|
if (pluginOptions.serverPublicKey) {
|
||||||
|
return authWithKey(pluginOptions.serverPublicKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
state = STATE_WAIT_SERVER_KEY;
|
||||||
|
return REQUEST_SERVER_KEY_PACKET;
|
||||||
|
|
||||||
|
case STATE_WAIT_SERVER_KEY:
|
||||||
|
if (pluginOptions.onServerPublicKey) {
|
||||||
|
pluginOptions.onServerPublicKey(data);
|
||||||
|
}
|
||||||
|
return authWithKey(data);
|
||||||
|
case STATE_FINAL:
|
||||||
|
throw new Error(
|
||||||
|
`Unexpected data in AuthMoreData packet received by ${PLUGIN_NAME} plugin in STATE_FINAL state.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Unexpected data in AuthMoreData packet received by ${PLUGIN_NAME} plugin in state ${state}`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
945
node_modules/mysql2/lib/base/connection.js
generated
vendored
Normal file
945
node_modules/mysql2/lib/base/connection.js
generated
vendored
Normal file
@ -0,0 +1,945 @@
|
|||||||
|
// This file was modified by Oracle on June 1, 2021.
|
||||||
|
// The changes involve new logic to handle an additional ERR Packet sent by
|
||||||
|
// the MySQL server when the connection is closed unexpectedly.
|
||||||
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
// This file was modified by Oracle on June 17, 2021.
|
||||||
|
// The changes involve logic to ensure the socket connection is closed when
|
||||||
|
// there is a fatal error.
|
||||||
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
// This file was modified by Oracle on September 21, 2021.
|
||||||
|
// The changes involve passing additional authentication factor passwords
|
||||||
|
// to the ChangeUser Command instance.
|
||||||
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Net = require('net');
|
||||||
|
const Tls = require('tls');
|
||||||
|
const Timers = require('timers');
|
||||||
|
const EventEmitter = require('events').EventEmitter;
|
||||||
|
const Readable = require('stream').Readable;
|
||||||
|
const Queue = require('denque');
|
||||||
|
const SqlString = require('sqlstring');
|
||||||
|
const { createLRU } = require('lru.min');
|
||||||
|
const PacketParser = require('../packet_parser.js');
|
||||||
|
const Packets = require('../packets/index.js');
|
||||||
|
const Commands = require('../commands/index.js');
|
||||||
|
const ConnectionConfig = require('../connection_config.js');
|
||||||
|
const CharsetToEncoding = require('../constants/charset_encodings.js');
|
||||||
|
|
||||||
|
let _connectionId = 0;
|
||||||
|
|
||||||
|
let convertNamedPlaceholders = null;
|
||||||
|
|
||||||
|
class BaseConnection extends EventEmitter {
|
||||||
|
constructor(opts) {
|
||||||
|
super();
|
||||||
|
this.config = opts.config;
|
||||||
|
// TODO: fill defaults
|
||||||
|
// if no params, connect to /var/lib/mysql/mysql.sock ( /tmp/mysql.sock on OSX )
|
||||||
|
// if host is given, connect to host:3306
|
||||||
|
// TODO: use `/usr/local/mysql/bin/mysql_config --socket` output? as default socketPath
|
||||||
|
// if there is no host/port and no socketPath parameters?
|
||||||
|
if (!opts.config.stream) {
|
||||||
|
if (opts.config.socketPath) {
|
||||||
|
this.stream = Net.connect(opts.config.socketPath);
|
||||||
|
} else {
|
||||||
|
this.stream = Net.connect(opts.config.port, opts.config.host);
|
||||||
|
|
||||||
|
// Optionally enable keep-alive on the socket.
|
||||||
|
if (this.config.enableKeepAlive) {
|
||||||
|
this.stream.on('connect', () => {
|
||||||
|
this.stream.setKeepAlive(true, this.config.keepAliveInitialDelay);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable TCP_NODELAY flag. This is needed so that the network packets
|
||||||
|
// are sent immediately to the server
|
||||||
|
this.stream.setNoDelay(true);
|
||||||
|
}
|
||||||
|
// if stream is a function, treat it as "stream agent / factory"
|
||||||
|
} else if (typeof opts.config.stream === 'function') {
|
||||||
|
this.stream = opts.config.stream(opts);
|
||||||
|
} else {
|
||||||
|
this.stream = opts.config.stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._internalId = _connectionId++;
|
||||||
|
this._commands = new Queue();
|
||||||
|
this._command = null;
|
||||||
|
this._paused = false;
|
||||||
|
this._paused_packets = new Queue();
|
||||||
|
this._statements = createLRU({
|
||||||
|
max: this.config.maxPreparedStatements,
|
||||||
|
onEviction: function (_, statement) {
|
||||||
|
statement.close();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
this.serverCapabilityFlags = 0;
|
||||||
|
this.authorized = false;
|
||||||
|
this.sequenceId = 0;
|
||||||
|
this.compressedSequenceId = 0;
|
||||||
|
this.threadId = null;
|
||||||
|
this._handshakePacket = null;
|
||||||
|
this._fatalError = null;
|
||||||
|
this._protocolError = null;
|
||||||
|
this._outOfOrderPackets = [];
|
||||||
|
this.clientEncoding = CharsetToEncoding[this.config.charsetNumber];
|
||||||
|
this.stream.on('error', this._handleNetworkError.bind(this));
|
||||||
|
// see https://gist.github.com/khoomeister/4985691#use-that-instead-of-bind
|
||||||
|
this.packetParser = new PacketParser((p) => {
|
||||||
|
this.handlePacket(p);
|
||||||
|
});
|
||||||
|
this.stream.on('data', (data) => {
|
||||||
|
if (this.connectTimeout) {
|
||||||
|
Timers.clearTimeout(this.connectTimeout);
|
||||||
|
this.connectTimeout = null;
|
||||||
|
}
|
||||||
|
this.packetParser.execute(data);
|
||||||
|
});
|
||||||
|
this.stream.on('end', () => {
|
||||||
|
// emit the end event so that the pooled connection can close the connection
|
||||||
|
this.emit('end');
|
||||||
|
});
|
||||||
|
this.stream.on('close', () => {
|
||||||
|
// we need to set this flag everywhere where we want connection to close
|
||||||
|
if (this._closing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this._protocolError) {
|
||||||
|
// no particular error message before disconnect
|
||||||
|
this._protocolError = new Error(
|
||||||
|
'Connection lost: The server closed the connection.'
|
||||||
|
);
|
||||||
|
this._protocolError.fatal = true;
|
||||||
|
this._protocolError.code = 'PROTOCOL_CONNECTION_LOST';
|
||||||
|
}
|
||||||
|
this._notifyError(this._protocolError);
|
||||||
|
});
|
||||||
|
let handshakeCommand;
|
||||||
|
if (!this.config.isServer) {
|
||||||
|
handshakeCommand = new Commands.ClientHandshake(this.config.clientFlags);
|
||||||
|
handshakeCommand.on('end', () => {
|
||||||
|
// this happens when handshake finishes early either because there was
|
||||||
|
// some fatal error or the server sent an error packet instead of
|
||||||
|
// an hello packet (for example, 'Too many connections' error)
|
||||||
|
if (
|
||||||
|
!handshakeCommand.handshake ||
|
||||||
|
this._fatalError ||
|
||||||
|
this._protocolError
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._handshakePacket = handshakeCommand.handshake;
|
||||||
|
this.threadId = handshakeCommand.handshake.connectionId;
|
||||||
|
this.emit('connect', handshakeCommand.handshake);
|
||||||
|
});
|
||||||
|
handshakeCommand.on('error', (err) => {
|
||||||
|
this._closing = true;
|
||||||
|
this._notifyError(err);
|
||||||
|
});
|
||||||
|
this.addCommand(handshakeCommand);
|
||||||
|
}
|
||||||
|
// in case there was no initial handshake but we need to read sting, assume it utf-8
|
||||||
|
// most common example: "Too many connections" error ( packet is sent immediately on connection attempt, we don't know server encoding yet)
|
||||||
|
// will be overwritten with actual encoding value as soon as server handshake packet is received
|
||||||
|
this.serverEncoding = 'utf8';
|
||||||
|
if (this.config.connectTimeout) {
|
||||||
|
const timeoutHandler = this._handleTimeoutError.bind(this);
|
||||||
|
this.connectTimeout = Timers.setTimeout(
|
||||||
|
timeoutHandler,
|
||||||
|
this.config.connectTimeout
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_addCommandClosedState(cmd) {
|
||||||
|
const err = new Error(
|
||||||
|
"Can't add new command when connection is in closed state"
|
||||||
|
);
|
||||||
|
err.fatal = true;
|
||||||
|
if (cmd.onResult) {
|
||||||
|
cmd.onResult(err);
|
||||||
|
} else {
|
||||||
|
this.emit('error', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleFatalError(err) {
|
||||||
|
err.fatal = true;
|
||||||
|
// stop receiving packets
|
||||||
|
this.stream.removeAllListeners('data');
|
||||||
|
this.addCommand = this._addCommandClosedState;
|
||||||
|
this.write = () => {
|
||||||
|
this.emit('error', new Error("Can't write in closed state"));
|
||||||
|
};
|
||||||
|
this._notifyError(err);
|
||||||
|
this._fatalError = err;
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleNetworkError(err) {
|
||||||
|
if (this.connectTimeout) {
|
||||||
|
Timers.clearTimeout(this.connectTimeout);
|
||||||
|
this.connectTimeout = null;
|
||||||
|
}
|
||||||
|
// Do not throw an error when a connection ends with a RST,ACK packet
|
||||||
|
if (err.code === 'ECONNRESET' && this._closing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._handleFatalError(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleTimeoutError() {
|
||||||
|
if (this.connectTimeout) {
|
||||||
|
Timers.clearTimeout(this.connectTimeout);
|
||||||
|
this.connectTimeout = null;
|
||||||
|
}
|
||||||
|
this.stream.destroy && this.stream.destroy();
|
||||||
|
const err = new Error('connect ETIMEDOUT');
|
||||||
|
err.errorno = 'ETIMEDOUT';
|
||||||
|
err.code = 'ETIMEDOUT';
|
||||||
|
err.syscall = 'connect';
|
||||||
|
this._handleNetworkError(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// notify all commands in the queue and bubble error as connection "error"
|
||||||
|
// called on stream error or unexpected termination
|
||||||
|
_notifyError(err) {
|
||||||
|
if (this.connectTimeout) {
|
||||||
|
Timers.clearTimeout(this.connectTimeout);
|
||||||
|
this.connectTimeout = null;
|
||||||
|
}
|
||||||
|
// prevent from emitting 'PROTOCOL_CONNECTION_LOST' after EPIPE or ECONNRESET
|
||||||
|
if (this._fatalError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let command;
|
||||||
|
// if there is no active command, notify connection
|
||||||
|
// if there are commands and all of them have callbacks, pass error via callback
|
||||||
|
let bubbleErrorToConnection = !this._command;
|
||||||
|
if (this._command && this._command.onResult) {
|
||||||
|
this._command.onResult(err);
|
||||||
|
this._command = null;
|
||||||
|
// connection handshake is special because we allow it to be implicit
|
||||||
|
// if error happened during handshake, but there are others commands in queue
|
||||||
|
// then bubble error to other commands and not to connection
|
||||||
|
} else if (
|
||||||
|
!(
|
||||||
|
this._command &&
|
||||||
|
this._command.constructor === Commands.ClientHandshake &&
|
||||||
|
this._commands.length > 0
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
bubbleErrorToConnection = true;
|
||||||
|
}
|
||||||
|
while ((command = this._commands.shift())) {
|
||||||
|
if (command.onResult) {
|
||||||
|
command.onResult(err);
|
||||||
|
} else {
|
||||||
|
bubbleErrorToConnection = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// notify connection if some comands in the queue did not have callbacks
|
||||||
|
// or if this is pool connection ( so it can be removed from pool )
|
||||||
|
if (bubbleErrorToConnection || this._pool) {
|
||||||
|
this.emit('error', err);
|
||||||
|
}
|
||||||
|
// close connection after emitting the event in case of a fatal error
|
||||||
|
if (err.fatal) {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
write(buffer) {
|
||||||
|
const result = this.stream.write(buffer, (err) => {
|
||||||
|
if (err) {
|
||||||
|
this._handleNetworkError(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
this.stream.emit('pause');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// http://dev.mysql.com/doc/internals/en/sequence-id.html
|
||||||
|
//
|
||||||
|
// The sequence-id is incremented with each packet and may wrap around.
|
||||||
|
// It starts at 0 and is reset to 0 when a new command
|
||||||
|
// begins in the Command Phase.
|
||||||
|
// http://dev.mysql.com/doc/internals/en/example-several-mysql-packets.html
|
||||||
|
_resetSequenceId() {
|
||||||
|
this.sequenceId = 0;
|
||||||
|
this.compressedSequenceId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_bumpCompressedSequenceId(numPackets) {
|
||||||
|
this.compressedSequenceId += numPackets;
|
||||||
|
this.compressedSequenceId %= 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
_bumpSequenceId(numPackets) {
|
||||||
|
this.sequenceId += numPackets;
|
||||||
|
this.sequenceId %= 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
writePacket(packet) {
|
||||||
|
const MAX_PACKET_LENGTH = 16777215;
|
||||||
|
const length = packet.length();
|
||||||
|
let chunk, offset, header;
|
||||||
|
if (length < MAX_PACKET_LENGTH) {
|
||||||
|
packet.writeHeader(this.sequenceId);
|
||||||
|
if (this.config.debug) {
|
||||||
|
console.log(
|
||||||
|
`${this._internalId} ${this.connectionId} <== ${this._command._commandName}#${this._command.stateName()}(${[this.sequenceId, packet._name, packet.length()].join(',')})`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${this._internalId} ${this.connectionId} <== ${packet.buffer.toString('hex')}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this._bumpSequenceId(1);
|
||||||
|
this.write(packet.buffer);
|
||||||
|
} else {
|
||||||
|
if (this.config.debug) {
|
||||||
|
console.log(
|
||||||
|
`${this._internalId} ${this.connectionId} <== Writing large packet, raw content not written:`
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${this._internalId} ${this.connectionId} <== ${this._command._commandName}#${this._command.stateName()}(${[this.sequenceId, packet._name, packet.length()].join(',')})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (offset = 4; offset < 4 + length; offset += MAX_PACKET_LENGTH) {
|
||||||
|
chunk = packet.buffer.slice(offset, offset + MAX_PACKET_LENGTH);
|
||||||
|
if (chunk.length === MAX_PACKET_LENGTH) {
|
||||||
|
header = Buffer.from([0xff, 0xff, 0xff, this.sequenceId]);
|
||||||
|
} else {
|
||||||
|
header = Buffer.from([
|
||||||
|
chunk.length & 0xff,
|
||||||
|
(chunk.length >> 8) & 0xff,
|
||||||
|
(chunk.length >> 16) & 0xff,
|
||||||
|
this.sequenceId,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
this._bumpSequenceId(1);
|
||||||
|
this.write(header);
|
||||||
|
this.write(chunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0.11+ environment
|
||||||
|
startTLS(onSecure) {
|
||||||
|
if (this.config.debug) {
|
||||||
|
console.log('Upgrading connection to TLS');
|
||||||
|
}
|
||||||
|
const secureContext = Tls.createSecureContext({
|
||||||
|
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,
|
||||||
|
minVersion: this.config.ssl.minVersion,
|
||||||
|
maxVersion: this.config.ssl.maxVersion,
|
||||||
|
});
|
||||||
|
const rejectUnauthorized = this.config.ssl.rejectUnauthorized;
|
||||||
|
const verifyIdentity = this.config.ssl.verifyIdentity;
|
||||||
|
const servername = this.config.host;
|
||||||
|
|
||||||
|
let secureEstablished = false;
|
||||||
|
this.stream.removeAllListeners('data');
|
||||||
|
const secureSocket = Tls.connect(
|
||||||
|
{
|
||||||
|
rejectUnauthorized,
|
||||||
|
requestCert: rejectUnauthorized,
|
||||||
|
checkServerIdentity: verifyIdentity
|
||||||
|
? Tls.checkServerIdentity
|
||||||
|
: function () {
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
secureContext,
|
||||||
|
isServer: false,
|
||||||
|
socket: this.stream,
|
||||||
|
servername,
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
secureEstablished = true;
|
||||||
|
if (rejectUnauthorized) {
|
||||||
|
if (typeof servername === 'string' && verifyIdentity) {
|
||||||
|
const cert = secureSocket.getPeerCertificate(true);
|
||||||
|
const serverIdentityCheckError = Tls.checkServerIdentity(
|
||||||
|
servername,
|
||||||
|
cert
|
||||||
|
);
|
||||||
|
if (serverIdentityCheckError) {
|
||||||
|
onSecure(serverIdentityCheckError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onSecure();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// error handler for secure socket
|
||||||
|
secureSocket.on('error', (err) => {
|
||||||
|
if (secureEstablished) {
|
||||||
|
this._handleNetworkError(err);
|
||||||
|
} else {
|
||||||
|
onSecure(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
secureSocket.on('data', (data) => {
|
||||||
|
this.packetParser.execute(data);
|
||||||
|
});
|
||||||
|
this.write = (buffer) => secureSocket.write(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
protocolError(message, code) {
|
||||||
|
// Starting with MySQL 8.0.24, if the client closes the connection
|
||||||
|
// unexpectedly, the server will send a last ERR Packet, which we can
|
||||||
|
// safely ignore.
|
||||||
|
// https://dev.mysql.com/worklog/task/?id=12999
|
||||||
|
if (this._closing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const err = new Error(message);
|
||||||
|
err.fatal = true;
|
||||||
|
err.code = code || 'PROTOCOL_ERROR';
|
||||||
|
this.emit('error', err);
|
||||||
|
}
|
||||||
|
|
||||||
|
get fatalError() {
|
||||||
|
return this._fatalError;
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePacket(packet) {
|
||||||
|
if (this._paused) {
|
||||||
|
this._paused_packets.push(packet);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.config.debug) {
|
||||||
|
if (packet) {
|
||||||
|
console.log(
|
||||||
|
` raw: ${packet.buffer
|
||||||
|
.slice(packet.offset, packet.offset + packet.length())
|
||||||
|
.toString('hex')}`
|
||||||
|
);
|
||||||
|
console.trace();
|
||||||
|
const commandName = this._command
|
||||||
|
? this._command._commandName
|
||||||
|
: '(no command)';
|
||||||
|
const stateName = this._command
|
||||||
|
? this._command.stateName()
|
||||||
|
: '(no command)';
|
||||||
|
console.log(
|
||||||
|
`${this._internalId} ${this.connectionId} ==> ${commandName}#${stateName}(${[packet.sequenceId, packet.type(), packet.length()].join(',')})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this._command) {
|
||||||
|
const marker = packet.peekByte();
|
||||||
|
// If it's an Err Packet, we should use it.
|
||||||
|
if (marker === 0xff) {
|
||||||
|
const error = Packets.Error.fromPacket(packet);
|
||||||
|
this.protocolError(error.message, error.code);
|
||||||
|
} else {
|
||||||
|
// Otherwise, it means it's some other unexpected packet.
|
||||||
|
this.protocolError(
|
||||||
|
'Unexpected packet while no commands in the queue',
|
||||||
|
'PROTOCOL_UNEXPECTED_PACKET'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (packet) {
|
||||||
|
// Note: when server closes connection due to inactivity, Err packet ER_CLIENT_INTERACTION_TIMEOUT from MySQL 8.0.24, sequenceId will be 0
|
||||||
|
if (this.sequenceId !== packet.sequenceId) {
|
||||||
|
const err = new Error(
|
||||||
|
`Warning: got packets out of order. Expected ${this.sequenceId} but received ${packet.sequenceId}`
|
||||||
|
);
|
||||||
|
err.expected = this.sequenceId;
|
||||||
|
err.received = packet.sequenceId;
|
||||||
|
this.emit('warn', err); // REVIEW
|
||||||
|
console.error(err.message);
|
||||||
|
}
|
||||||
|
this._bumpSequenceId(packet.numPackets);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (this._fatalError) {
|
||||||
|
// skip remaining packets after client is in the error state
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const done = this._command.execute(packet, this);
|
||||||
|
if (done) {
|
||||||
|
this._command = this._commands.shift();
|
||||||
|
if (this._command) {
|
||||||
|
this.sequenceId = 0;
|
||||||
|
this.compressedSequenceId = 0;
|
||||||
|
this.handlePacket();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
this._handleFatalError(err);
|
||||||
|
this.stream.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addCommand(cmd) {
|
||||||
|
// this.compressedSequenceId = 0;
|
||||||
|
// this.sequenceId = 0;
|
||||||
|
if (this.config.debug) {
|
||||||
|
const commandName = cmd.constructor.name;
|
||||||
|
console.log(`Add command: ${commandName}`);
|
||||||
|
cmd._commandName = commandName;
|
||||||
|
}
|
||||||
|
if (!this._command) {
|
||||||
|
this._command = cmd;
|
||||||
|
this.handlePacket();
|
||||||
|
} else {
|
||||||
|
this._commands.push(cmd);
|
||||||
|
}
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
format(sql, values) {
|
||||||
|
if (typeof this.config.queryFormat === 'function') {
|
||||||
|
return this.config.queryFormat.call(
|
||||||
|
this,
|
||||||
|
sql,
|
||||||
|
values,
|
||||||
|
this.config.timezone
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const opts = {
|
||||||
|
sql: sql,
|
||||||
|
values: values,
|
||||||
|
};
|
||||||
|
this._resolveNamedPlaceholders(opts);
|
||||||
|
return SqlString.format(
|
||||||
|
opts.sql,
|
||||||
|
opts.values,
|
||||||
|
this.config.stringifyObjects,
|
||||||
|
this.config.timezone
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
escape(value) {
|
||||||
|
return SqlString.escape(value, false, this.config.timezone);
|
||||||
|
}
|
||||||
|
|
||||||
|
escapeId(value) {
|
||||||
|
return SqlString.escapeId(value, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
raw(sql) {
|
||||||
|
return SqlString.raw(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
_resolveNamedPlaceholders(options) {
|
||||||
|
let unnamed;
|
||||||
|
if (this.config.namedPlaceholders || options.namedPlaceholders) {
|
||||||
|
if (Array.isArray(options.values)) {
|
||||||
|
// if an array is provided as the values, assume the conversion is not necessary.
|
||||||
|
// this allows the usage of unnamed placeholders even if the namedPlaceholders flag is enabled.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (convertNamedPlaceholders === null) {
|
||||||
|
convertNamedPlaceholders = require('named-placeholders')();
|
||||||
|
}
|
||||||
|
unnamed = convertNamedPlaceholders(options.sql, options.values);
|
||||||
|
options.sql = unnamed[0];
|
||||||
|
options.values = unnamed[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query(sql, values, cb) {
|
||||||
|
let cmdQuery;
|
||||||
|
if (sql.constructor === Commands.Query) {
|
||||||
|
cmdQuery = sql;
|
||||||
|
} else {
|
||||||
|
cmdQuery = BaseConnection.createQuery(sql, values, cb, this.config);
|
||||||
|
}
|
||||||
|
this._resolveNamedPlaceholders(cmdQuery);
|
||||||
|
const rawSql = this.format(
|
||||||
|
cmdQuery.sql,
|
||||||
|
cmdQuery.values !== undefined ? cmdQuery.values : []
|
||||||
|
);
|
||||||
|
cmdQuery.sql = rawSql;
|
||||||
|
return this.addCommand(cmdQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
pause() {
|
||||||
|
this._paused = true;
|
||||||
|
this.stream.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
resume() {
|
||||||
|
let packet;
|
||||||
|
this._paused = false;
|
||||||
|
while ((packet = this._paused_packets.shift())) {
|
||||||
|
this.handlePacket(packet);
|
||||||
|
// don't resume if packet handler paused connection
|
||||||
|
if (this._paused) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.stream.resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: named placeholders support
|
||||||
|
prepare(options, cb) {
|
||||||
|
if (typeof options === 'string') {
|
||||||
|
options = { sql: options };
|
||||||
|
}
|
||||||
|
return this.addCommand(new Commands.Prepare(options, cb));
|
||||||
|
}
|
||||||
|
|
||||||
|
unprepare(sql) {
|
||||||
|
let options = {};
|
||||||
|
if (typeof sql === 'object') {
|
||||||
|
options = sql;
|
||||||
|
} else {
|
||||||
|
options.sql = sql;
|
||||||
|
}
|
||||||
|
const key = BaseConnection.statementKey(options);
|
||||||
|
const stmt = this._statements.get(key);
|
||||||
|
if (stmt) {
|
||||||
|
this._statements.delete(key);
|
||||||
|
stmt.close();
|
||||||
|
}
|
||||||
|
return stmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
execute(sql, values, cb) {
|
||||||
|
let options = {
|
||||||
|
infileStreamFactory: this.config.infileStreamFactory,
|
||||||
|
};
|
||||||
|
if (typeof sql === 'object') {
|
||||||
|
// execute(options, cb)
|
||||||
|
options = {
|
||||||
|
...options,
|
||||||
|
...sql,
|
||||||
|
sql: sql.sql,
|
||||||
|
values: sql.values,
|
||||||
|
};
|
||||||
|
if (typeof values === 'function') {
|
||||||
|
cb = values;
|
||||||
|
} else {
|
||||||
|
options.values = options.values || values;
|
||||||
|
}
|
||||||
|
} else if (typeof values === 'function') {
|
||||||
|
// execute(sql, cb)
|
||||||
|
cb = values;
|
||||||
|
options.sql = sql;
|
||||||
|
options.values = undefined;
|
||||||
|
} else {
|
||||||
|
// execute(sql, values, cb)
|
||||||
|
options.sql = sql;
|
||||||
|
options.values = values;
|
||||||
|
}
|
||||||
|
this._resolveNamedPlaceholders(options);
|
||||||
|
// check for values containing undefined
|
||||||
|
if (options.values) {
|
||||||
|
//If namedPlaceholder is not enabled and object is passed as bind parameters
|
||||||
|
if (!Array.isArray(options.values)) {
|
||||||
|
throw new TypeError(
|
||||||
|
'Bind parameters must be array if namedPlaceholders parameter is not enabled'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
options.values.forEach((val) => {
|
||||||
|
//If namedPlaceholder is not enabled and object is passed as bind parameters
|
||||||
|
if (!Array.isArray(options.values)) {
|
||||||
|
throw new TypeError(
|
||||||
|
'Bind parameters must be array if namedPlaceholders parameter is not enabled'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (val === undefined) {
|
||||||
|
throw new TypeError(
|
||||||
|
'Bind parameters must not contain undefined. To pass SQL NULL specify JS null'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (typeof val === 'function') {
|
||||||
|
throw new TypeError(
|
||||||
|
'Bind parameters must not contain function(s). To pass the body of a function as a string call .toString() first'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const executeCommand = new Commands.Execute(options, cb);
|
||||||
|
const prepareCommand = new Commands.Prepare(options, (err, stmt) => {
|
||||||
|
if (err) {
|
||||||
|
// skip execute command if prepare failed, we have main
|
||||||
|
// combined callback here
|
||||||
|
executeCommand.start = function () {
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
if (cb) {
|
||||||
|
cb(err);
|
||||||
|
} else {
|
||||||
|
executeCommand.emit('error', err);
|
||||||
|
}
|
||||||
|
executeCommand.emit('end');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
executeCommand.statement = stmt;
|
||||||
|
});
|
||||||
|
this.addCommand(prepareCommand);
|
||||||
|
this.addCommand(executeCommand);
|
||||||
|
return executeCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
changeUser(options, callback) {
|
||||||
|
if (!callback && typeof options === 'function') {
|
||||||
|
callback = options;
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
|
const charsetNumber = options.charset
|
||||||
|
? ConnectionConfig.getCharsetNumber(options.charset)
|
||||||
|
: this.config.charsetNumber;
|
||||||
|
return this.addCommand(
|
||||||
|
new Commands.ChangeUser(
|
||||||
|
{
|
||||||
|
user: options.user || this.config.user,
|
||||||
|
// for the purpose of multi-factor authentication, or not, the main
|
||||||
|
// password (used for the 1st authentication factor) can also be
|
||||||
|
// provided via the "password1" option
|
||||||
|
password:
|
||||||
|
options.password ||
|
||||||
|
options.password1 ||
|
||||||
|
this.config.password ||
|
||||||
|
this.config.password1,
|
||||||
|
password2: options.password2 || this.config.password2,
|
||||||
|
password3: options.password3 || this.config.password3,
|
||||||
|
passwordSha1: options.passwordSha1 || this.config.passwordSha1,
|
||||||
|
database: options.database || this.config.database,
|
||||||
|
timeout: options.timeout,
|
||||||
|
charsetNumber: charsetNumber,
|
||||||
|
currentConfig: this.config,
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
if (err) {
|
||||||
|
err.fatal = true;
|
||||||
|
}
|
||||||
|
if (callback) {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// transaction helpers
|
||||||
|
beginTransaction(cb) {
|
||||||
|
return this.query('START TRANSACTION', cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
commit(cb) {
|
||||||
|
return this.query('COMMIT', cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
rollback(cb) {
|
||||||
|
return this.query('ROLLBACK', cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
ping(cb) {
|
||||||
|
return this.addCommand(new Commands.Ping(cb));
|
||||||
|
}
|
||||||
|
|
||||||
|
_registerSlave(opts, cb) {
|
||||||
|
return this.addCommand(new Commands.RegisterSlave(opts, cb));
|
||||||
|
}
|
||||||
|
|
||||||
|
_binlogDump(opts, cb) {
|
||||||
|
return this.addCommand(new Commands.BinlogDump(opts, cb));
|
||||||
|
}
|
||||||
|
|
||||||
|
// currently just alias to close
|
||||||
|
destroy() {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
if (this.connectTimeout) {
|
||||||
|
Timers.clearTimeout(this.connectTimeout);
|
||||||
|
this.connectTimeout = null;
|
||||||
|
}
|
||||||
|
this._closing = true;
|
||||||
|
this.stream.end();
|
||||||
|
this.addCommand = this._addCommandClosedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
createBinlogStream(opts) {
|
||||||
|
// TODO: create proper stream class
|
||||||
|
// TODO: use through2
|
||||||
|
let test = 1;
|
||||||
|
const stream = new Readable({ objectMode: true });
|
||||||
|
stream._read = function () {
|
||||||
|
return {
|
||||||
|
data: test++,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
this._registerSlave(opts, () => {
|
||||||
|
const dumpCmd = this._binlogDump(opts);
|
||||||
|
dumpCmd.on('event', (ev) => {
|
||||||
|
stream.push(ev);
|
||||||
|
});
|
||||||
|
dumpCmd.on('eof', () => {
|
||||||
|
stream.push(null);
|
||||||
|
// if non-blocking, then close stream to prevent errors
|
||||||
|
if (opts.flags && opts.flags & 0x01) {
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// TODO: pipe errors as well
|
||||||
|
});
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(cb) {
|
||||||
|
if (!cb) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this._fatalError || this._protocolError) {
|
||||||
|
return cb(this._fatalError || this._protocolError);
|
||||||
|
}
|
||||||
|
if (this._handshakePacket) {
|
||||||
|
return cb(null, this);
|
||||||
|
}
|
||||||
|
let connectCalled = 0;
|
||||||
|
function callbackOnce(isErrorHandler) {
|
||||||
|
return function (param) {
|
||||||
|
if (!connectCalled) {
|
||||||
|
if (isErrorHandler) {
|
||||||
|
cb(param);
|
||||||
|
} else {
|
||||||
|
cb(null, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connectCalled = 1;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.once('error', callbackOnce(true));
|
||||||
|
this.once('connect', callbackOnce(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===================================
|
||||||
|
// outgoing server connection methods
|
||||||
|
// ===================================
|
||||||
|
writeColumns(columns) {
|
||||||
|
this.writePacket(Packets.ResultSetHeader.toPacket(columns.length));
|
||||||
|
columns.forEach((column) => {
|
||||||
|
this.writePacket(
|
||||||
|
Packets.ColumnDefinition.toPacket(column, this.serverConfig.encoding)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
this.writeEof();
|
||||||
|
}
|
||||||
|
|
||||||
|
// row is array of columns, not hash
|
||||||
|
writeTextRow(column) {
|
||||||
|
this.writePacket(
|
||||||
|
Packets.TextRow.toPacket(column, this.serverConfig.encoding)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeBinaryRow(column) {
|
||||||
|
this.writePacket(
|
||||||
|
Packets.BinaryRow.toPacket(column, this.serverConfig.encoding)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeTextResult(rows, columns, binary = false) {
|
||||||
|
this.writeColumns(columns);
|
||||||
|
rows.forEach((row) => {
|
||||||
|
const arrayRow = new Array(columns.length);
|
||||||
|
columns.forEach((column) => {
|
||||||
|
arrayRow.push(row[column.name]);
|
||||||
|
});
|
||||||
|
if (binary) {
|
||||||
|
this.writeBinaryRow(arrayRow);
|
||||||
|
} else this.writeTextRow(arrayRow);
|
||||||
|
});
|
||||||
|
this.writeEof();
|
||||||
|
}
|
||||||
|
|
||||||
|
writeEof(warnings, statusFlags) {
|
||||||
|
this.writePacket(Packets.EOF.toPacket(warnings, statusFlags));
|
||||||
|
}
|
||||||
|
|
||||||
|
writeOk(args) {
|
||||||
|
if (!args) {
|
||||||
|
args = { affectedRows: 0 };
|
||||||
|
}
|
||||||
|
this.writePacket(Packets.OK.toPacket(args, this.serverConfig.encoding));
|
||||||
|
}
|
||||||
|
|
||||||
|
writeError(args) {
|
||||||
|
// if we want to send error before initial hello was sent, use default encoding
|
||||||
|
const encoding = this.serverConfig ? this.serverConfig.encoding : 'cesu8';
|
||||||
|
this.writePacket(Packets.Error.toPacket(args, encoding));
|
||||||
|
}
|
||||||
|
|
||||||
|
serverHandshake(args) {
|
||||||
|
this.serverConfig = args;
|
||||||
|
this.serverConfig.encoding =
|
||||||
|
CharsetToEncoding[this.serverConfig.characterSet];
|
||||||
|
return this.addCommand(new Commands.ServerHandshake(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===============================================================
|
||||||
|
end(callback) {
|
||||||
|
if (this.config.isServer) {
|
||||||
|
this._closing = true;
|
||||||
|
const quitCmd = new EventEmitter();
|
||||||
|
setImmediate(() => {
|
||||||
|
this.stream.end();
|
||||||
|
quitCmd.emit('end');
|
||||||
|
});
|
||||||
|
return quitCmd;
|
||||||
|
}
|
||||||
|
// trigger error if more commands enqueued after end command
|
||||||
|
const quitCmd = this.addCommand(new Commands.Quit(callback));
|
||||||
|
this.addCommand = this._addCommandClosedState;
|
||||||
|
return quitCmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static createQuery(sql, values, cb, config) {
|
||||||
|
let options = {
|
||||||
|
rowsAsArray: config.rowsAsArray,
|
||||||
|
infileStreamFactory: config.infileStreamFactory,
|
||||||
|
};
|
||||||
|
if (typeof sql === 'object') {
|
||||||
|
// query(options, cb)
|
||||||
|
options = {
|
||||||
|
...options,
|
||||||
|
...sql,
|
||||||
|
sql: sql.sql,
|
||||||
|
values: sql.values,
|
||||||
|
};
|
||||||
|
if (typeof values === 'function') {
|
||||||
|
cb = values;
|
||||||
|
} else if (values !== undefined) {
|
||||||
|
options.values = values;
|
||||||
|
}
|
||||||
|
} else if (typeof values === 'function') {
|
||||||
|
// query(sql, cb)
|
||||||
|
cb = values;
|
||||||
|
options.sql = sql;
|
||||||
|
options.values = undefined;
|
||||||
|
} else {
|
||||||
|
// query(sql, values, cb)
|
||||||
|
options.sql = sql;
|
||||||
|
options.values = values;
|
||||||
|
}
|
||||||
|
return new Commands.Query(options, cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
static statementKey(options) {
|
||||||
|
return `${typeof options.nestTables}/${options.nestTables}/${options.rowsAsArray}${options.sql}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = BaseConnection;
|
233
node_modules/mysql2/lib/base/pool.js
generated
vendored
Normal file
233
node_modules/mysql2/lib/base/pool.js
generated
vendored
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const process = require('process');
|
||||||
|
const SqlString = require('sqlstring');
|
||||||
|
const EventEmitter = require('events').EventEmitter;
|
||||||
|
const PoolConnection = require('../pool_connection.js');
|
||||||
|
const Queue = require('denque');
|
||||||
|
const BaseConnection = require('./connection.js');
|
||||||
|
|
||||||
|
function spliceConnection(queue, connection) {
|
||||||
|
const len = queue.length;
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
if (queue.get(i) === connection) {
|
||||||
|
queue.removeOne(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BasePool extends EventEmitter {
|
||||||
|
constructor(options) {
|
||||||
|
super();
|
||||||
|
this.config = options.config;
|
||||||
|
this.config.connectionConfig.pool = this;
|
||||||
|
this._allConnections = new Queue();
|
||||||
|
this._freeConnections = new Queue();
|
||||||
|
this._connectionQueue = new Queue();
|
||||||
|
this._closed = false;
|
||||||
|
if (this.config.maxIdle < this.config.connectionLimit) {
|
||||||
|
// create idle connection timeout automatically release job
|
||||||
|
this._removeIdleTimeoutConnections();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getConnection(cb) {
|
||||||
|
if (this._closed) {
|
||||||
|
return process.nextTick(() => cb(new Error('Pool is closed.')));
|
||||||
|
}
|
||||||
|
let connection;
|
||||||
|
if (this._freeConnections.length > 0) {
|
||||||
|
connection = this._freeConnections.pop();
|
||||||
|
this.emit('acquire', connection);
|
||||||
|
return process.nextTick(() => cb(null, connection));
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
this.config.connectionLimit === 0 ||
|
||||||
|
this._allConnections.length < this.config.connectionLimit
|
||||||
|
) {
|
||||||
|
connection = new PoolConnection(this, {
|
||||||
|
config: this.config.connectionConfig,
|
||||||
|
});
|
||||||
|
this._allConnections.push(connection);
|
||||||
|
return connection.connect((err) => {
|
||||||
|
if (this._closed) {
|
||||||
|
return cb(new Error('Pool is closed.'));
|
||||||
|
}
|
||||||
|
if (err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
this.emit('connection', connection);
|
||||||
|
this.emit('acquire', connection);
|
||||||
|
return cb(null, connection);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!this.config.waitForConnections) {
|
||||||
|
return process.nextTick(() => cb(new Error('No connections available.')));
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
this.config.queueLimit &&
|
||||||
|
this._connectionQueue.length >= this.config.queueLimit
|
||||||
|
) {
|
||||||
|
return cb(new Error('Queue limit reached.'));
|
||||||
|
}
|
||||||
|
this.emit('enqueue');
|
||||||
|
return this._connectionQueue.push(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseConnection(connection) {
|
||||||
|
let cb;
|
||||||
|
if (!connection._pool) {
|
||||||
|
// The connection has been removed from the pool and is no longer good.
|
||||||
|
if (this._connectionQueue.length) {
|
||||||
|
cb = this._connectionQueue.shift();
|
||||||
|
process.nextTick(this.getConnection.bind(this, cb));
|
||||||
|
}
|
||||||
|
} else if (this._connectionQueue.length) {
|
||||||
|
cb = this._connectionQueue.shift();
|
||||||
|
process.nextTick(cb.bind(null, null, connection));
|
||||||
|
} else {
|
||||||
|
this._freeConnections.push(connection);
|
||||||
|
this.emit('release', connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end(cb) {
|
||||||
|
this._closed = true;
|
||||||
|
clearTimeout(this._removeIdleTimeoutConnectionsTimer);
|
||||||
|
if (typeof cb !== 'function') {
|
||||||
|
cb = function (err) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let calledBack = false;
|
||||||
|
let closedConnections = 0;
|
||||||
|
let connection;
|
||||||
|
const endCB = function (err) {
|
||||||
|
if (calledBack) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (err || ++closedConnections >= this._allConnections.length) {
|
||||||
|
calledBack = true;
|
||||||
|
cb(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}.bind(this);
|
||||||
|
if (this._allConnections.length === 0) {
|
||||||
|
endCB();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < this._allConnections.length; i++) {
|
||||||
|
connection = this._allConnections.get(i);
|
||||||
|
connection._realEnd(endCB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query(sql, values, cb) {
|
||||||
|
const cmdQuery = BaseConnection.createQuery(
|
||||||
|
sql,
|
||||||
|
values,
|
||||||
|
cb,
|
||||||
|
this.config.connectionConfig
|
||||||
|
);
|
||||||
|
if (typeof cmdQuery.namedPlaceholders === 'undefined') {
|
||||||
|
cmdQuery.namedPlaceholders =
|
||||||
|
this.config.connectionConfig.namedPlaceholders;
|
||||||
|
}
|
||||||
|
this.getConnection((err, conn) => {
|
||||||
|
if (err) {
|
||||||
|
if (typeof cmdQuery.onResult === 'function') {
|
||||||
|
cmdQuery.onResult(err);
|
||||||
|
} else {
|
||||||
|
cmdQuery.emit('error', err);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
conn.query(cmdQuery).once('end', () => {
|
||||||
|
conn.release();
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
conn.release();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cmdQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
execute(sql, values, cb) {
|
||||||
|
// TODO construct execute command first here and pass it to connection.execute
|
||||||
|
// so that polymorphic arguments logic is there in one place
|
||||||
|
if (typeof values === 'function') {
|
||||||
|
cb = values;
|
||||||
|
values = [];
|
||||||
|
}
|
||||||
|
this.getConnection((err, conn) => {
|
||||||
|
if (err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
conn.execute(sql, values, cb).once('end', () => {
|
||||||
|
conn.release();
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
conn.release();
|
||||||
|
return cb(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_removeConnection(connection) {
|
||||||
|
// Remove connection from all connections
|
||||||
|
spliceConnection(this._allConnections, connection);
|
||||||
|
// Remove connection from free connections
|
||||||
|
spliceConnection(this._freeConnections, connection);
|
||||||
|
this.releaseConnection(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
_removeIdleTimeoutConnections() {
|
||||||
|
if (this._removeIdleTimeoutConnectionsTimer) {
|
||||||
|
clearTimeout(this._removeIdleTimeoutConnectionsTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._removeIdleTimeoutConnectionsTimer = setTimeout(() => {
|
||||||
|
try {
|
||||||
|
while (
|
||||||
|
this._freeConnections.length > this.config.maxIdle ||
|
||||||
|
(this._freeConnections.length > 0 &&
|
||||||
|
Date.now() - this._freeConnections.get(0).lastActiveTime >
|
||||||
|
this.config.idleTimeout)
|
||||||
|
) {
|
||||||
|
this._freeConnections.get(0).destroy();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this._removeIdleTimeoutConnections();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
format(sql, values) {
|
||||||
|
return SqlString.format(
|
||||||
|
sql,
|
||||||
|
values,
|
||||||
|
this.config.connectionConfig.stringifyObjects,
|
||||||
|
this.config.connectionConfig.timezone
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
escape(value) {
|
||||||
|
return SqlString.escape(
|
||||||
|
value,
|
||||||
|
this.config.connectionConfig.stringifyObjects,
|
||||||
|
this.config.connectionConfig.timezone
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
escapeId(value) {
|
||||||
|
return SqlString.escapeId(value, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = BasePool;
|
63
node_modules/mysql2/lib/base/pool_connection.js
generated
vendored
Normal file
63
node_modules/mysql2/lib/base/pool_connection.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const BaseConnection = require('./connection.js');
|
||||||
|
|
||||||
|
class BasePoolConnection extends BaseConnection {
|
||||||
|
constructor(pool, options) {
|
||||||
|
super(options);
|
||||||
|
this._pool = pool;
|
||||||
|
// The last active time of this connection
|
||||||
|
this.lastActiveTime = Date.now();
|
||||||
|
// 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.
|
||||||
|
// REVIEW: Moved to `once`
|
||||||
|
this.once('end', () => {
|
||||||
|
this._removeFromPool();
|
||||||
|
});
|
||||||
|
this.once('error', () => {
|
||||||
|
this._removeFromPool();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
release() {
|
||||||
|
if (!this._pool || this._pool._closed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// update last active time
|
||||||
|
this.lastActiveTime = Date.now();
|
||||||
|
this._pool.releaseConnection(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
end() {
|
||||||
|
const err = new Error(
|
||||||
|
'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.emit('warn', err);
|
||||||
|
console.warn(err.message);
|
||||||
|
this.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this._removeFromPool();
|
||||||
|
super.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
_removeFromPool() {
|
||||||
|
if (!this._pool || this._pool._closed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const pool = this._pool;
|
||||||
|
this._pool = null;
|
||||||
|
pool._removeConnection(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BasePoolConnection.statementKey = BaseConnection.statementKey;
|
||||||
|
module.exports = BasePoolConnection;
|
||||||
|
|
||||||
|
// TODO: Remove this when we are removing PoolConnection#end
|
||||||
|
BasePoolConnection.prototype._realEnd = BaseConnection.prototype.end;
|
111
node_modules/mysql2/lib/commands/auth_switch.js
generated
vendored
Normal file
111
node_modules/mysql2/lib/commands/auth_switch.js
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// This file was modified by Oracle on July 5, 2021.
|
||||||
|
// Errors generated by asynchronous authentication plugins are now being
|
||||||
|
// handled and subsequently emitted at the command level.
|
||||||
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Packets = require('../packets/index.js');
|
||||||
|
const sha256_password = require('../auth_plugins/sha256_password');
|
||||||
|
const caching_sha2_password = require('../auth_plugins/caching_sha2_password.js');
|
||||||
|
const mysql_native_password = require('../auth_plugins/mysql_native_password.js');
|
||||||
|
const mysql_clear_password = require('../auth_plugins/mysql_clear_password.js');
|
||||||
|
|
||||||
|
const standardAuthPlugins = {
|
||||||
|
sha256_password: sha256_password({}),
|
||||||
|
caching_sha2_password: caching_sha2_password({}),
|
||||||
|
mysql_native_password: mysql_native_password({}),
|
||||||
|
mysql_clear_password: mysql_clear_password({}),
|
||||||
|
};
|
||||||
|
|
||||||
|
function warnLegacyAuthSwitch() {
|
||||||
|
console.warn(
|
||||||
|
'WARNING! authSwitchHandler api is deprecated, please use new authPlugins api'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function authSwitchPluginError(error, command) {
|
||||||
|
// Authentication errors are fatal
|
||||||
|
error.code = 'AUTH_SWITCH_PLUGIN_ERROR';
|
||||||
|
error.fatal = true;
|
||||||
|
|
||||||
|
command.emit('error', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function authSwitchRequest(packet, connection, command) {
|
||||||
|
const { pluginName, pluginData } =
|
||||||
|
Packets.AuthSwitchRequest.fromPacket(packet);
|
||||||
|
let authPlugin =
|
||||||
|
connection.config.authPlugins && connection.config.authPlugins[pluginName];
|
||||||
|
|
||||||
|
// legacy plugin api don't allow to override mysql_native_password
|
||||||
|
// if pluginName is mysql_native_password it's using standard auth4.1 auth
|
||||||
|
if (
|
||||||
|
connection.config.authSwitchHandler &&
|
||||||
|
pluginName !== 'mysql_native_password'
|
||||||
|
) {
|
||||||
|
const legacySwitchHandler = connection.config.authSwitchHandler;
|
||||||
|
warnLegacyAuthSwitch();
|
||||||
|
legacySwitchHandler({ pluginName, pluginData }, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
return authSwitchPluginError(err, command);
|
||||||
|
}
|
||||||
|
connection.writePacket(new Packets.AuthSwitchResponse(data).toPacket());
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!authPlugin) {
|
||||||
|
authPlugin = standardAuthPlugins[pluginName];
|
||||||
|
}
|
||||||
|
if (!authPlugin) {
|
||||||
|
throw new Error(
|
||||||
|
`Server requests authentication using unknown plugin ${pluginName}. See ${'TODO: add plugins doco here'} on how to configure or author authentication plugins.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
connection._authPlugin = authPlugin({ connection, command });
|
||||||
|
Promise.resolve(connection._authPlugin(pluginData))
|
||||||
|
.then((data) => {
|
||||||
|
if (data) {
|
||||||
|
connection.writePacket(new Packets.AuthSwitchResponse(data).toPacket());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
authSwitchPluginError(err, command);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function authSwitchRequestMoreData(packet, connection, command) {
|
||||||
|
const { data } = Packets.AuthSwitchRequestMoreData.fromPacket(packet);
|
||||||
|
|
||||||
|
if (connection.config.authSwitchHandler) {
|
||||||
|
const legacySwitchHandler = connection.config.authSwitchHandler;
|
||||||
|
warnLegacyAuthSwitch();
|
||||||
|
legacySwitchHandler({ pluginData: data }, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
return authSwitchPluginError(err, command);
|
||||||
|
}
|
||||||
|
connection.writePacket(new Packets.AuthSwitchResponse(data).toPacket());
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connection._authPlugin) {
|
||||||
|
throw new Error(
|
||||||
|
'AuthPluginMoreData received but no auth plugin instance found'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Promise.resolve(connection._authPlugin(data))
|
||||||
|
.then((data) => {
|
||||||
|
if (data) {
|
||||||
|
connection.writePacket(new Packets.AuthSwitchResponse(data).toPacket());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
authSwitchPluginError(err, command);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
authSwitchRequest,
|
||||||
|
authSwitchRequestMoreData,
|
||||||
|
};
|
109
node_modules/mysql2/lib/commands/binlog_dump.js
generated
vendored
Normal file
109
node_modules/mysql2/lib/commands/binlog_dump.js
generated
vendored
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Command = require('./command');
|
||||||
|
const Packets = require('../packets');
|
||||||
|
|
||||||
|
const eventParsers = [];
|
||||||
|
|
||||||
|
class BinlogEventHeader {
|
||||||
|
constructor(packet) {
|
||||||
|
this.timestamp = packet.readInt32();
|
||||||
|
this.eventType = packet.readInt8();
|
||||||
|
this.serverId = packet.readInt32();
|
||||||
|
this.eventSize = packet.readInt32();
|
||||||
|
this.logPos = packet.readInt32();
|
||||||
|
this.flags = packet.readInt16();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BinlogDump extends Command {
|
||||||
|
constructor(opts) {
|
||||||
|
super();
|
||||||
|
// this.onResult = callback;
|
||||||
|
this.opts = opts;
|
||||||
|
}
|
||||||
|
|
||||||
|
start(packet, connection) {
|
||||||
|
const newPacket = new Packets.BinlogDump(this.opts);
|
||||||
|
connection.writePacket(newPacket.toPacket(1));
|
||||||
|
return BinlogDump.prototype.binlogData;
|
||||||
|
}
|
||||||
|
|
||||||
|
binlogData(packet) {
|
||||||
|
// ok - continue consuming events
|
||||||
|
// error - error
|
||||||
|
// eof - end of binlog
|
||||||
|
if (packet.isEOF()) {
|
||||||
|
this.emit('eof');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// binlog event header
|
||||||
|
packet.readInt8();
|
||||||
|
const header = new BinlogEventHeader(packet);
|
||||||
|
const EventParser = eventParsers[header.eventType];
|
||||||
|
let event;
|
||||||
|
if (EventParser) {
|
||||||
|
event = new EventParser(packet);
|
||||||
|
} else {
|
||||||
|
event = {
|
||||||
|
name: 'UNKNOWN',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
event.header = header;
|
||||||
|
this.emit('event', event);
|
||||||
|
return BinlogDump.prototype.binlogData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RotateEvent {
|
||||||
|
constructor(packet) {
|
||||||
|
this.pposition = packet.readInt32();
|
||||||
|
// TODO: read uint64 here
|
||||||
|
packet.readInt32(); // positionDword2
|
||||||
|
this.nextBinlog = packet.readString();
|
||||||
|
this.name = 'RotateEvent';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FormatDescriptionEvent {
|
||||||
|
constructor(packet) {
|
||||||
|
this.binlogVersion = packet.readInt16();
|
||||||
|
this.serverVersion = packet.readString(50).replace(/\u0000.*/, ''); // eslint-disable-line no-control-regex
|
||||||
|
this.createTimestamp = packet.readInt32();
|
||||||
|
this.eventHeaderLength = packet.readInt8(); // should be 19
|
||||||
|
this.eventsLength = packet.readBuffer();
|
||||||
|
this.name = 'FormatDescriptionEvent';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class QueryEvent {
|
||||||
|
constructor(packet) {
|
||||||
|
const parseStatusVars = require('../packets/binlog_query_statusvars.js');
|
||||||
|
this.slaveProxyId = packet.readInt32();
|
||||||
|
this.executionTime = packet.readInt32();
|
||||||
|
const schemaLength = packet.readInt8();
|
||||||
|
this.errorCode = packet.readInt16();
|
||||||
|
const statusVarsLength = packet.readInt16();
|
||||||
|
const statusVars = packet.readBuffer(statusVarsLength);
|
||||||
|
this.schema = packet.readString(schemaLength);
|
||||||
|
packet.readInt8(); // should be zero
|
||||||
|
this.statusVars = parseStatusVars(statusVars);
|
||||||
|
this.query = packet.readString();
|
||||||
|
this.name = 'QueryEvent';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class XidEvent {
|
||||||
|
constructor(packet) {
|
||||||
|
this.binlogVersion = packet.readInt16();
|
||||||
|
this.xid = packet.readInt64();
|
||||||
|
this.name = 'XidEvent';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eventParsers[2] = QueryEvent;
|
||||||
|
eventParsers[4] = RotateEvent;
|
||||||
|
eventParsers[15] = FormatDescriptionEvent;
|
||||||
|
eventParsers[16] = XidEvent;
|
||||||
|
|
||||||
|
module.exports = BinlogDump;
|
68
node_modules/mysql2/lib/commands/change_user.js
generated
vendored
Normal file
68
node_modules/mysql2/lib/commands/change_user.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// This file was modified by Oracle on September 21, 2021.
|
||||||
|
// The changes involve saving additional authentication factor passwords
|
||||||
|
// in the command scope and enabling multi-factor authentication in the
|
||||||
|
// client-side when the server supports it.
|
||||||
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Command = require('./command.js');
|
||||||
|
const Packets = require('../packets/index.js');
|
||||||
|
const ClientConstants = require('../constants/client');
|
||||||
|
const ClientHandshake = require('./client_handshake.js');
|
||||||
|
const CharsetToEncoding = require('../constants/charset_encodings.js');
|
||||||
|
|
||||||
|
class ChangeUser extends Command {
|
||||||
|
constructor(options, callback) {
|
||||||
|
super();
|
||||||
|
this.onResult = callback;
|
||||||
|
this.user = options.user;
|
||||||
|
this.password = options.password;
|
||||||
|
// "password1" is an alias of "password"
|
||||||
|
this.password1 = options.password;
|
||||||
|
this.password2 = options.password2;
|
||||||
|
this.password3 = options.password3;
|
||||||
|
this.database = options.database;
|
||||||
|
this.passwordSha1 = options.passwordSha1;
|
||||||
|
this.charsetNumber = options.charsetNumber;
|
||||||
|
this.currentConfig = options.currentConfig;
|
||||||
|
this.authenticationFactor = 0;
|
||||||
|
}
|
||||||
|
start(packet, connection) {
|
||||||
|
const newPacket = new Packets.ChangeUser({
|
||||||
|
flags: connection.config.clientFlags,
|
||||||
|
user: this.user,
|
||||||
|
database: this.database,
|
||||||
|
charsetNumber: this.charsetNumber,
|
||||||
|
password: this.password,
|
||||||
|
passwordSha1: this.passwordSha1,
|
||||||
|
authPluginData1: connection._handshakePacket.authPluginData1,
|
||||||
|
authPluginData2: connection._handshakePacket.authPluginData2,
|
||||||
|
});
|
||||||
|
this.currentConfig.user = this.user;
|
||||||
|
this.currentConfig.password = this.password;
|
||||||
|
this.currentConfig.database = this.database;
|
||||||
|
this.currentConfig.charsetNumber = this.charsetNumber;
|
||||||
|
connection.clientEncoding = CharsetToEncoding[this.charsetNumber];
|
||||||
|
// clear prepared statements cache as all statements become invalid after changeUser
|
||||||
|
connection._statements.clear();
|
||||||
|
connection.writePacket(newPacket.toPacket());
|
||||||
|
// check if the server supports multi-factor authentication
|
||||||
|
const multiFactorAuthentication =
|
||||||
|
connection.serverCapabilityFlags &
|
||||||
|
ClientConstants.MULTI_FACTOR_AUTHENTICATION;
|
||||||
|
if (multiFactorAuthentication) {
|
||||||
|
// if the server supports multi-factor authentication, we enable it in
|
||||||
|
// the client
|
||||||
|
this.authenticationFactor = 1;
|
||||||
|
}
|
||||||
|
return ChangeUser.prototype.handshakeResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeUser.prototype.handshakeResult =
|
||||||
|
ClientHandshake.prototype.handshakeResult;
|
||||||
|
ChangeUser.prototype.calculateNativePasswordAuthToken =
|
||||||
|
ClientHandshake.prototype.calculateNativePasswordAuthToken;
|
||||||
|
|
||||||
|
module.exports = ChangeUser;
|
241
node_modules/mysql2/lib/commands/client_handshake.js
generated
vendored
Normal file
241
node_modules/mysql2/lib/commands/client_handshake.js
generated
vendored
Normal file
@ -0,0 +1,241 @@
|
|||||||
|
// This file was modified by Oracle on June 17, 2021.
|
||||||
|
// Handshake errors are now maked as fatal and the corresponding events are
|
||||||
|
// emitted in the command instance itself.
|
||||||
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
// This file was modified by Oracle on September 21, 2021.
|
||||||
|
// Handshake workflow now supports additional authentication factors requested
|
||||||
|
// by the server.
|
||||||
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Command = require('./command.js');
|
||||||
|
const Packets = require('../packets/index.js');
|
||||||
|
const ClientConstants = require('../constants/client.js');
|
||||||
|
const CharsetToEncoding = require('../constants/charset_encodings.js');
|
||||||
|
const auth41 = require('../auth_41.js');
|
||||||
|
|
||||||
|
function flagNames(flags) {
|
||||||
|
const res = [];
|
||||||
|
for (const c in ClientConstants) {
|
||||||
|
if (flags & ClientConstants[c]) {
|
||||||
|
res.push(c.replace(/_/g, ' ').toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ClientHandshake extends Command {
|
||||||
|
constructor(clientFlags) {
|
||||||
|
super();
|
||||||
|
this.handshake = null;
|
||||||
|
this.clientFlags = clientFlags;
|
||||||
|
this.authenticationFactor = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
return ClientHandshake.prototype.handshakeInit;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendSSLRequest(connection) {
|
||||||
|
const sslRequest = new Packets.SSLRequest(
|
||||||
|
this.clientFlags,
|
||||||
|
connection.config.charsetNumber
|
||||||
|
);
|
||||||
|
connection.writePacket(sslRequest.toPacket());
|
||||||
|
}
|
||||||
|
|
||||||
|
sendCredentials(connection) {
|
||||||
|
if (connection.config.debug) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.log(
|
||||||
|
'Sending handshake packet: flags:%d=(%s)',
|
||||||
|
this.clientFlags,
|
||||||
|
flagNames(this.clientFlags).join(', ')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.user = connection.config.user;
|
||||||
|
this.password = connection.config.password;
|
||||||
|
// "password1" is an alias to the original "password" value
|
||||||
|
// to make it easier to integrate multi-factor authentication
|
||||||
|
this.password1 = connection.config.password;
|
||||||
|
// "password2" and "password3" are the 2nd and 3rd factor authentication
|
||||||
|
// passwords, which can be undefined depending on the authentication
|
||||||
|
// plugin being used
|
||||||
|
this.password2 = connection.config.password2;
|
||||||
|
this.password3 = connection.config.password3;
|
||||||
|
this.passwordSha1 = connection.config.passwordSha1;
|
||||||
|
this.database = connection.config.database;
|
||||||
|
this.authPluginName = this.handshake.authPluginName;
|
||||||
|
const handshakeResponse = new Packets.HandshakeResponse({
|
||||||
|
flags: this.clientFlags,
|
||||||
|
user: this.user,
|
||||||
|
database: this.database,
|
||||||
|
password: this.password,
|
||||||
|
passwordSha1: this.passwordSha1,
|
||||||
|
charsetNumber: connection.config.charsetNumber,
|
||||||
|
authPluginData1: this.handshake.authPluginData1,
|
||||||
|
authPluginData2: this.handshake.authPluginData2,
|
||||||
|
compress: connection.config.compress,
|
||||||
|
connectAttributes: connection.config.connectAttributes,
|
||||||
|
});
|
||||||
|
connection.writePacket(handshakeResponse.toPacket());
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateNativePasswordAuthToken(authPluginData) {
|
||||||
|
// TODO: dont split into authPluginData1 and authPluginData2, instead join when 1 & 2 received
|
||||||
|
const authPluginData1 = authPluginData.slice(0, 8);
|
||||||
|
const authPluginData2 = authPluginData.slice(8, 20);
|
||||||
|
let authToken;
|
||||||
|
if (this.passwordSha1) {
|
||||||
|
authToken = auth41.calculateTokenFromPasswordSha(
|
||||||
|
this.passwordSha1,
|
||||||
|
authPluginData1,
|
||||||
|
authPluginData2
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
authToken = auth41.calculateToken(
|
||||||
|
this.password,
|
||||||
|
authPluginData1,
|
||||||
|
authPluginData2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return authToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
handshakeInit(helloPacket, connection) {
|
||||||
|
this.on('error', (e) => {
|
||||||
|
connection._fatalError = e;
|
||||||
|
connection._protocolError = e;
|
||||||
|
});
|
||||||
|
this.handshake = Packets.Handshake.fromPacket(helloPacket);
|
||||||
|
if (connection.config.debug) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.log(
|
||||||
|
'Server hello packet: capability flags:%d=(%s)',
|
||||||
|
this.handshake.capabilityFlags,
|
||||||
|
flagNames(this.handshake.capabilityFlags).join(', ')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
connection.serverCapabilityFlags = this.handshake.capabilityFlags;
|
||||||
|
connection.serverEncoding = CharsetToEncoding[this.handshake.characterSet];
|
||||||
|
connection.connectionId = this.handshake.connectionId;
|
||||||
|
const serverSSLSupport =
|
||||||
|
this.handshake.capabilityFlags & ClientConstants.SSL;
|
||||||
|
// multi factor authentication is enabled with the
|
||||||
|
// "MULTI_FACTOR_AUTHENTICATION" capability and should only be used if it
|
||||||
|
// is supported by the server
|
||||||
|
const multiFactorAuthentication =
|
||||||
|
this.handshake.capabilityFlags &
|
||||||
|
ClientConstants.MULTI_FACTOR_AUTHENTICATION;
|
||||||
|
this.clientFlags = this.clientFlags | multiFactorAuthentication;
|
||||||
|
// use compression only if requested by client and supported by server
|
||||||
|
connection.config.compress =
|
||||||
|
connection.config.compress &&
|
||||||
|
this.handshake.capabilityFlags & ClientConstants.COMPRESS;
|
||||||
|
this.clientFlags = this.clientFlags | connection.config.compress;
|
||||||
|
if (connection.config.ssl) {
|
||||||
|
// client requires SSL but server does not support it
|
||||||
|
if (!serverSSLSupport) {
|
||||||
|
const err = new Error('Server does not support secure connection');
|
||||||
|
err.code = 'HANDSHAKE_NO_SSL_SUPPORT';
|
||||||
|
err.fatal = true;
|
||||||
|
this.emit('error', err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// send ssl upgrade request and immediately upgrade connection to secure
|
||||||
|
this.clientFlags |= ClientConstants.SSL;
|
||||||
|
this.sendSSLRequest(connection);
|
||||||
|
connection.startTLS((err) => {
|
||||||
|
// after connection is secure
|
||||||
|
if (err) {
|
||||||
|
// SSL negotiation error are fatal
|
||||||
|
err.code = 'HANDSHAKE_SSL_ERROR';
|
||||||
|
err.fatal = true;
|
||||||
|
this.emit('error', err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// rest of communication is encrypted
|
||||||
|
this.sendCredentials(connection);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.sendCredentials(connection);
|
||||||
|
}
|
||||||
|
if (multiFactorAuthentication) {
|
||||||
|
// if the server supports multi-factor authentication, we enable it in
|
||||||
|
// the client
|
||||||
|
this.authenticationFactor = 1;
|
||||||
|
}
|
||||||
|
return ClientHandshake.prototype.handshakeResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
handshakeResult(packet, connection) {
|
||||||
|
const marker = packet.peekByte();
|
||||||
|
// packet can be OK_Packet, ERR_Packet, AuthSwitchRequest, AuthNextFactor
|
||||||
|
// or AuthMoreData
|
||||||
|
if (marker === 0xfe || marker === 1 || marker === 0x02) {
|
||||||
|
const authSwitch = require('./auth_switch');
|
||||||
|
try {
|
||||||
|
if (marker === 1) {
|
||||||
|
authSwitch.authSwitchRequestMoreData(packet, connection, this);
|
||||||
|
} else {
|
||||||
|
// if authenticationFactor === 0, it means the server does not support
|
||||||
|
// the multi-factor authentication capability
|
||||||
|
if (this.authenticationFactor !== 0) {
|
||||||
|
// if we are past the first authentication factor, we should use the
|
||||||
|
// corresponding password (if there is one)
|
||||||
|
connection.config.password =
|
||||||
|
this[`password${this.authenticationFactor}`];
|
||||||
|
// update the current authentication factor
|
||||||
|
this.authenticationFactor += 1;
|
||||||
|
}
|
||||||
|
// if marker === 0x02, it means it is an AuthNextFactor packet,
|
||||||
|
// which is similar in structure to an AuthSwitchRequest packet,
|
||||||
|
// so, we can use it directly
|
||||||
|
authSwitch.authSwitchRequest(packet, connection, this);
|
||||||
|
}
|
||||||
|
return ClientHandshake.prototype.handshakeResult;
|
||||||
|
} catch (err) {
|
||||||
|
// Authentication errors are fatal
|
||||||
|
err.code = 'AUTH_SWITCH_PLUGIN_ERROR';
|
||||||
|
err.fatal = true;
|
||||||
|
|
||||||
|
if (this.onResult) {
|
||||||
|
this.onResult(err);
|
||||||
|
} else {
|
||||||
|
this.emit('error', err);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (marker !== 0) {
|
||||||
|
const err = new Error('Unexpected packet during handshake phase');
|
||||||
|
// Unknown handshake errors are fatal
|
||||||
|
err.code = 'HANDSHAKE_UNKNOWN_ERROR';
|
||||||
|
err.fatal = true;
|
||||||
|
|
||||||
|
if (this.onResult) {
|
||||||
|
this.onResult(err);
|
||||||
|
} else {
|
||||||
|
this.emit('error', err);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// this should be called from ClientHandshake command only
|
||||||
|
// and skipped when called from ChangeUser command
|
||||||
|
if (!connection.authorized) {
|
||||||
|
connection.authorized = true;
|
||||||
|
if (connection.config.compress) {
|
||||||
|
const enableCompression =
|
||||||
|
require('../compressed_protocol.js').enableCompression;
|
||||||
|
enableCompression(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.onResult) {
|
||||||
|
this.onResult(null);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = ClientHandshake;
|
18
node_modules/mysql2/lib/commands/close_statement.js
generated
vendored
Normal file
18
node_modules/mysql2/lib/commands/close_statement.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Command = require('./command');
|
||||||
|
const Packets = require('../packets/index.js');
|
||||||
|
|
||||||
|
class CloseStatement extends Command {
|
||||||
|
constructor(id) {
|
||||||
|
super();
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
start(packet, connection) {
|
||||||
|
connection.writePacket(new Packets.CloseStatement(this.id).toPacket(1));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CloseStatement;
|
54
node_modules/mysql2/lib/commands/command.js
generated
vendored
Normal file
54
node_modules/mysql2/lib/commands/command.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const EventEmitter = require('events').EventEmitter;
|
||||||
|
const Timers = require('timers');
|
||||||
|
|
||||||
|
class Command extends EventEmitter {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.next = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// slow. debug only
|
||||||
|
stateName() {
|
||||||
|
const state = this.next;
|
||||||
|
for (const i in this) {
|
||||||
|
if (this[i] === state && i !== 'next') {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'unknown name';
|
||||||
|
}
|
||||||
|
|
||||||
|
execute(packet, connection) {
|
||||||
|
if (!this.next) {
|
||||||
|
this.next = this.start;
|
||||||
|
connection._resetSequenceId();
|
||||||
|
}
|
||||||
|
if (packet && packet.isError()) {
|
||||||
|
const err = packet.asError(connection.clientEncoding);
|
||||||
|
err.sql = this.sql || this.query;
|
||||||
|
if (this.queryTimeout) {
|
||||||
|
Timers.clearTimeout(this.queryTimeout);
|
||||||
|
this.queryTimeout = null;
|
||||||
|
}
|
||||||
|
if (this.onResult) {
|
||||||
|
this.onResult(err);
|
||||||
|
this.emit('end');
|
||||||
|
} else {
|
||||||
|
this.emit('error', err);
|
||||||
|
this.emit('end');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// TODO: don't return anything from execute, it's ugly and error-prone. Listen for 'end' event in connection
|
||||||
|
this.next = this.next(packet, connection);
|
||||||
|
if (this.next) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.emit('end');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Command;
|
112
node_modules/mysql2/lib/commands/execute.js
generated
vendored
Normal file
112
node_modules/mysql2/lib/commands/execute.js
generated
vendored
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Command = require('./command.js');
|
||||||
|
const Query = require('./query.js');
|
||||||
|
const Packets = require('../packets/index.js');
|
||||||
|
|
||||||
|
const getBinaryParser = require('../parsers/binary_parser.js');
|
||||||
|
const getStaticBinaryParser = require('../parsers/static_binary_parser.js');
|
||||||
|
|
||||||
|
class Execute extends Command {
|
||||||
|
constructor(options, callback) {
|
||||||
|
super();
|
||||||
|
this.statement = options.statement;
|
||||||
|
this.sql = options.sql;
|
||||||
|
this.values = options.values;
|
||||||
|
this.onResult = callback;
|
||||||
|
this.parameters = options.values;
|
||||||
|
this.insertId = 0;
|
||||||
|
this.timeout = options.timeout;
|
||||||
|
this.queryTimeout = null;
|
||||||
|
this._rows = [];
|
||||||
|
this._fields = [];
|
||||||
|
this._result = [];
|
||||||
|
this._fieldCount = 0;
|
||||||
|
this._rowParser = null;
|
||||||
|
this._executeOptions = options;
|
||||||
|
this._resultIndex = 0;
|
||||||
|
this._localStream = null;
|
||||||
|
this._unpipeStream = function () {};
|
||||||
|
this._streamFactory = options.infileStreamFactory;
|
||||||
|
this._connection = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildParserFromFields(fields, connection) {
|
||||||
|
if (this.options.disableEval) {
|
||||||
|
return getStaticBinaryParser(fields, this.options, connection.config);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getBinaryParser(fields, this.options, connection.config);
|
||||||
|
}
|
||||||
|
|
||||||
|
start(packet, connection) {
|
||||||
|
this._connection = connection;
|
||||||
|
this.options = Object.assign({}, connection.config, this._executeOptions);
|
||||||
|
this._setTimeout();
|
||||||
|
const executePacket = new Packets.Execute(
|
||||||
|
this.statement.id,
|
||||||
|
this.parameters,
|
||||||
|
connection.config.charsetNumber,
|
||||||
|
connection.config.timezone
|
||||||
|
);
|
||||||
|
//For reasons why this try-catch is here, please see
|
||||||
|
// https://github.com/sidorares/node-mysql2/pull/689
|
||||||
|
//For additional discussion, see
|
||||||
|
// 1. https://github.com/sidorares/node-mysql2/issues/493
|
||||||
|
// 2. https://github.com/sidorares/node-mysql2/issues/187
|
||||||
|
// 3. https://github.com/sidorares/node-mysql2/issues/480
|
||||||
|
try {
|
||||||
|
connection.writePacket(executePacket.toPacket(1));
|
||||||
|
} catch (error) {
|
||||||
|
this.onResult(error);
|
||||||
|
}
|
||||||
|
return Execute.prototype.resultsetHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
readField(packet, connection) {
|
||||||
|
let fields;
|
||||||
|
// disabling for now, but would be great to find reliable way to parse fields only once
|
||||||
|
// fields reported by prepare can be empty at all or just incorrect - see #169
|
||||||
|
//
|
||||||
|
// perfomance optimisation: if we already have this field parsed in statement header, use one from header
|
||||||
|
// const field = this.statement.columns.length == this._fieldCount ?
|
||||||
|
// this.statement.columns[this._receivedFieldsCount] : new Packets.ColumnDefinition(packet);
|
||||||
|
const field = new Packets.ColumnDefinition(
|
||||||
|
packet,
|
||||||
|
connection.clientEncoding
|
||||||
|
);
|
||||||
|
this._receivedFieldsCount++;
|
||||||
|
this._fields[this._resultIndex].push(field);
|
||||||
|
if (this._receivedFieldsCount === this._fieldCount) {
|
||||||
|
fields = this._fields[this._resultIndex];
|
||||||
|
this.emit('fields', fields, this._resultIndex);
|
||||||
|
return Execute.prototype.fieldsEOF;
|
||||||
|
}
|
||||||
|
return Execute.prototype.readField;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldsEOF(packet, connection) {
|
||||||
|
// check EOF
|
||||||
|
if (!packet.isEOF()) {
|
||||||
|
return connection.protocolError('Expected EOF packet');
|
||||||
|
}
|
||||||
|
this._rowParser = new (this.buildParserFromFields(
|
||||||
|
this._fields[this._resultIndex],
|
||||||
|
connection
|
||||||
|
))();
|
||||||
|
return Execute.prototype.row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Execute.prototype.done = Query.prototype.done;
|
||||||
|
Execute.prototype.doneInsert = Query.prototype.doneInsert;
|
||||||
|
Execute.prototype.resultsetHeader = Query.prototype.resultsetHeader;
|
||||||
|
Execute.prototype._findOrCreateReadStream =
|
||||||
|
Query.prototype._findOrCreateReadStream;
|
||||||
|
Execute.prototype._streamLocalInfile = Query.prototype._streamLocalInfile;
|
||||||
|
Execute.prototype._setTimeout = Query.prototype._setTimeout;
|
||||||
|
Execute.prototype._handleTimeoutError = Query.prototype._handleTimeoutError;
|
||||||
|
Execute.prototype.row = Query.prototype.row;
|
||||||
|
Execute.prototype.stream = Query.prototype.stream;
|
||||||
|
|
||||||
|
module.exports = Execute;
|
27
node_modules/mysql2/lib/commands/index.js
generated
vendored
Normal file
27
node_modules/mysql2/lib/commands/index.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const ClientHandshake = require('./client_handshake.js');
|
||||||
|
const ServerHandshake = require('./server_handshake.js');
|
||||||
|
const Query = require('./query.js');
|
||||||
|
const Prepare = require('./prepare.js');
|
||||||
|
const CloseStatement = require('./close_statement.js');
|
||||||
|
const Execute = require('./execute.js');
|
||||||
|
const Ping = require('./ping.js');
|
||||||
|
const RegisterSlave = require('./register_slave.js');
|
||||||
|
const BinlogDump = require('./binlog_dump.js');
|
||||||
|
const ChangeUser = require('./change_user.js');
|
||||||
|
const Quit = require('./quit.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ClientHandshake,
|
||||||
|
ServerHandshake,
|
||||||
|
Query,
|
||||||
|
Prepare,
|
||||||
|
CloseStatement,
|
||||||
|
Execute,
|
||||||
|
Ping,
|
||||||
|
RegisterSlave,
|
||||||
|
BinlogDump,
|
||||||
|
ChangeUser,
|
||||||
|
Quit,
|
||||||
|
};
|
36
node_modules/mysql2/lib/commands/ping.js
generated
vendored
Normal file
36
node_modules/mysql2/lib/commands/ping.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Command = require('./command');
|
||||||
|
const CommandCode = require('../constants/commands');
|
||||||
|
const Packet = require('../packets/packet');
|
||||||
|
|
||||||
|
// TODO: time statistics?
|
||||||
|
// usefull for queue size and network latency monitoring
|
||||||
|
// store created,sent,reply timestamps
|
||||||
|
class Ping extends Command {
|
||||||
|
constructor(callback) {
|
||||||
|
super();
|
||||||
|
this.onResult = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
start(packet, connection) {
|
||||||
|
const ping = new Packet(
|
||||||
|
0,
|
||||||
|
Buffer.from([1, 0, 0, 0, CommandCode.PING]),
|
||||||
|
0,
|
||||||
|
5
|
||||||
|
);
|
||||||
|
connection.writePacket(ping);
|
||||||
|
return Ping.prototype.pingResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
pingResponse() {
|
||||||
|
// TODO: check it's OK packet. error check already done in caller
|
||||||
|
if (this.onResult) {
|
||||||
|
process.nextTick(this.onResult.bind(this));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Ping;
|
143
node_modules/mysql2/lib/commands/prepare.js
generated
vendored
Normal file
143
node_modules/mysql2/lib/commands/prepare.js
generated
vendored
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Packets = require('../packets/index.js');
|
||||||
|
const Command = require('./command.js');
|
||||||
|
const CloseStatement = require('./close_statement.js');
|
||||||
|
const Execute = require('./execute.js');
|
||||||
|
|
||||||
|
class PreparedStatementInfo {
|
||||||
|
constructor(query, id, columns, parameters, connection) {
|
||||||
|
this.query = query;
|
||||||
|
this.id = id;
|
||||||
|
this.columns = columns;
|
||||||
|
this.parameters = parameters;
|
||||||
|
this.rowParser = null;
|
||||||
|
this._connection = connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
return this._connection.addCommand(new CloseStatement(this.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
execute(parameters, callback) {
|
||||||
|
if (typeof parameters === 'function') {
|
||||||
|
callback = parameters;
|
||||||
|
parameters = [];
|
||||||
|
}
|
||||||
|
return this._connection.addCommand(
|
||||||
|
new Execute({ statement: this, values: parameters }, callback)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Prepare extends Command {
|
||||||
|
constructor(options, callback) {
|
||||||
|
super();
|
||||||
|
this.query = options.sql;
|
||||||
|
this.onResult = callback;
|
||||||
|
this.id = 0;
|
||||||
|
this.fieldCount = 0;
|
||||||
|
this.parameterCount = 0;
|
||||||
|
this.fields = [];
|
||||||
|
this.parameterDefinitions = [];
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
start(packet, connection) {
|
||||||
|
const Connection = connection.constructor;
|
||||||
|
this.key = Connection.statementKey(this.options);
|
||||||
|
const statement = connection._statements.get(this.key);
|
||||||
|
if (statement) {
|
||||||
|
if (this.onResult) {
|
||||||
|
this.onResult(null, statement);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const cmdPacket = new Packets.PrepareStatement(
|
||||||
|
this.query,
|
||||||
|
connection.config.charsetNumber,
|
||||||
|
this.options.values
|
||||||
|
);
|
||||||
|
connection.writePacket(cmdPacket.toPacket(1));
|
||||||
|
return Prepare.prototype.prepareHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareHeader(packet, connection) {
|
||||||
|
const header = new Packets.PreparedStatementHeader(packet);
|
||||||
|
this.id = header.id;
|
||||||
|
this.fieldCount = header.fieldCount;
|
||||||
|
this.parameterCount = header.parameterCount;
|
||||||
|
if (this.parameterCount > 0) {
|
||||||
|
return Prepare.prototype.readParameter;
|
||||||
|
}
|
||||||
|
if (this.fieldCount > 0) {
|
||||||
|
return Prepare.prototype.readField;
|
||||||
|
}
|
||||||
|
return this.prepareDone(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
readParameter(packet, connection) {
|
||||||
|
// there might be scenarios when mysql server reports more parameters than
|
||||||
|
// are actually present in the array of parameter definitions.
|
||||||
|
// if EOF packet is received we switch to "read fields" state if there are
|
||||||
|
// any fields reported by the server, otherwise we finish the command.
|
||||||
|
if (packet.isEOF()) {
|
||||||
|
if (this.fieldCount > 0) {
|
||||||
|
return Prepare.prototype.readField;
|
||||||
|
}
|
||||||
|
return this.prepareDone(connection);
|
||||||
|
}
|
||||||
|
const def = new Packets.ColumnDefinition(packet, connection.clientEncoding);
|
||||||
|
this.parameterDefinitions.push(def);
|
||||||
|
if (this.parameterDefinitions.length === this.parameterCount) {
|
||||||
|
return Prepare.prototype.parametersEOF;
|
||||||
|
}
|
||||||
|
return this.readParameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
readField(packet, connection) {
|
||||||
|
if (packet.isEOF()) {
|
||||||
|
return this.prepareDone(connection);
|
||||||
|
}
|
||||||
|
const def = new Packets.ColumnDefinition(packet, connection.clientEncoding);
|
||||||
|
this.fields.push(def);
|
||||||
|
if (this.fields.length === this.fieldCount) {
|
||||||
|
return Prepare.prototype.fieldsEOF;
|
||||||
|
}
|
||||||
|
return Prepare.prototype.readField;
|
||||||
|
}
|
||||||
|
|
||||||
|
parametersEOF(packet, connection) {
|
||||||
|
if (!packet.isEOF()) {
|
||||||
|
return connection.protocolError('Expected EOF packet after parameters');
|
||||||
|
}
|
||||||
|
if (this.fieldCount > 0) {
|
||||||
|
return Prepare.prototype.readField;
|
||||||
|
}
|
||||||
|
return this.prepareDone(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldsEOF(packet, connection) {
|
||||||
|
if (!packet.isEOF()) {
|
||||||
|
return connection.protocolError('Expected EOF packet after fields');
|
||||||
|
}
|
||||||
|
return this.prepareDone(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareDone(connection) {
|
||||||
|
const statement = new PreparedStatementInfo(
|
||||||
|
this.query,
|
||||||
|
this.id,
|
||||||
|
this.fields,
|
||||||
|
this.parameterDefinitions,
|
||||||
|
connection
|
||||||
|
);
|
||||||
|
connection._statements.set(this.key, statement);
|
||||||
|
if (this.onResult) {
|
||||||
|
this.onResult(null, statement);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Prepare;
|
329
node_modules/mysql2/lib/commands/query.js
generated
vendored
Normal file
329
node_modules/mysql2/lib/commands/query.js
generated
vendored
Normal file
@ -0,0 +1,329 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const process = require('process');
|
||||||
|
const Timers = require('timers');
|
||||||
|
|
||||||
|
const Readable = require('stream').Readable;
|
||||||
|
|
||||||
|
const Command = require('./command.js');
|
||||||
|
const Packets = require('../packets/index.js');
|
||||||
|
const getTextParser = require('../parsers/text_parser.js');
|
||||||
|
const staticParser = require('../parsers/static_text_parser.js');
|
||||||
|
const ServerStatus = require('../constants/server_status.js');
|
||||||
|
|
||||||
|
const EmptyPacket = new Packets.Packet(0, Buffer.allocUnsafe(4), 0, 4);
|
||||||
|
|
||||||
|
// http://dev.mysql.com/doc/internals/en/com-query.html
|
||||||
|
class Query extends Command {
|
||||||
|
constructor(options, callback) {
|
||||||
|
super();
|
||||||
|
this.sql = options.sql;
|
||||||
|
this.values = options.values;
|
||||||
|
this._queryOptions = options;
|
||||||
|
this.namedPlaceholders = options.namedPlaceholders || false;
|
||||||
|
this.onResult = callback;
|
||||||
|
this.timeout = options.timeout;
|
||||||
|
this.queryTimeout = null;
|
||||||
|
this._fieldCount = 0;
|
||||||
|
this._rowParser = null;
|
||||||
|
this._fields = [];
|
||||||
|
this._rows = [];
|
||||||
|
this._receivedFieldsCount = 0;
|
||||||
|
this._resultIndex = 0;
|
||||||
|
this._localStream = null;
|
||||||
|
this._unpipeStream = function () {};
|
||||||
|
this._streamFactory = options.infileStreamFactory;
|
||||||
|
this._connection = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
then() {
|
||||||
|
const err =
|
||||||
|
"You have tried to call .then(), .catch(), or invoked await on the result of query that is not a promise, which is a programming error. Try calling con.promise().query(), or require('mysql2/promise') instead of 'mysql2' for a promise-compatible version of the query interface. To learn how to use async/await or Promises check out documentation at https://sidorares.github.io/node-mysql2/docs#using-promise-wrapper, or the mysql2 documentation at https://sidorares.github.io/node-mysql2/docs/documentation/promise-wrapper";
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.log(err);
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
|
||||||
|
start(_packet, connection) {
|
||||||
|
if (connection.config.debug) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.log(' Sending query command: %s', this.sql);
|
||||||
|
}
|
||||||
|
this._connection = connection;
|
||||||
|
this.options = Object.assign({}, connection.config, this._queryOptions);
|
||||||
|
this._setTimeout();
|
||||||
|
|
||||||
|
const cmdPacket = new Packets.Query(
|
||||||
|
this.sql,
|
||||||
|
connection.config.charsetNumber
|
||||||
|
);
|
||||||
|
connection.writePacket(cmdPacket.toPacket(1));
|
||||||
|
return Query.prototype.resultsetHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
done() {
|
||||||
|
this._unpipeStream();
|
||||||
|
// if all ready timeout, return null directly
|
||||||
|
if (this.timeout && !this.queryTimeout) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// else clear timer
|
||||||
|
if (this.queryTimeout) {
|
||||||
|
Timers.clearTimeout(this.queryTimeout);
|
||||||
|
this.queryTimeout = null;
|
||||||
|
}
|
||||||
|
if (this.onResult) {
|
||||||
|
let rows, fields;
|
||||||
|
if (this._resultIndex === 0) {
|
||||||
|
rows = this._rows[0];
|
||||||
|
fields = this._fields[0];
|
||||||
|
} else {
|
||||||
|
rows = this._rows;
|
||||||
|
fields = this._fields;
|
||||||
|
}
|
||||||
|
if (fields) {
|
||||||
|
process.nextTick(() => {
|
||||||
|
this.onResult(null, rows, fields);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
process.nextTick(() => {
|
||||||
|
this.onResult(null, rows);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
doneInsert(rs) {
|
||||||
|
if (this._localStreamError) {
|
||||||
|
if (this.onResult) {
|
||||||
|
this.onResult(this._localStreamError, rs);
|
||||||
|
} else {
|
||||||
|
this.emit('error', this._localStreamError);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
this._rows.push(rs);
|
||||||
|
this._fields.push(void 0);
|
||||||
|
this.emit('fields', void 0);
|
||||||
|
this.emit('result', rs);
|
||||||
|
if (rs.serverStatus & ServerStatus.SERVER_MORE_RESULTS_EXISTS) {
|
||||||
|
this._resultIndex++;
|
||||||
|
return this.resultsetHeader;
|
||||||
|
}
|
||||||
|
return this.done();
|
||||||
|
}
|
||||||
|
|
||||||
|
resultsetHeader(packet, connection) {
|
||||||
|
const rs = new Packets.ResultSetHeader(packet, connection);
|
||||||
|
this._fieldCount = rs.fieldCount;
|
||||||
|
if (connection.config.debug) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.log(
|
||||||
|
` Resultset header received, expecting ${rs.fieldCount} column definition packets`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (this._fieldCount === 0) {
|
||||||
|
return this.doneInsert(rs);
|
||||||
|
}
|
||||||
|
if (this._fieldCount === null) {
|
||||||
|
return this._streamLocalInfile(connection, rs.infileName);
|
||||||
|
}
|
||||||
|
this._receivedFieldsCount = 0;
|
||||||
|
this._rows.push([]);
|
||||||
|
this._fields.push([]);
|
||||||
|
return this.readField;
|
||||||
|
}
|
||||||
|
|
||||||
|
_streamLocalInfile(connection, path) {
|
||||||
|
if (this._streamFactory) {
|
||||||
|
this._localStream = this._streamFactory(path);
|
||||||
|
} else {
|
||||||
|
this._localStreamError = new Error(
|
||||||
|
`As a result of LOCAL INFILE command server wants to read ${path} file, but as of v2.0 you must provide streamFactory option returning ReadStream.`
|
||||||
|
);
|
||||||
|
connection.writePacket(EmptyPacket);
|
||||||
|
return this.infileOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onConnectionError = () => {
|
||||||
|
this._unpipeStream();
|
||||||
|
};
|
||||||
|
const onDrain = () => {
|
||||||
|
this._localStream.resume();
|
||||||
|
};
|
||||||
|
const onPause = () => {
|
||||||
|
this._localStream.pause();
|
||||||
|
};
|
||||||
|
const onData = function (data) {
|
||||||
|
const dataWithHeader = Buffer.allocUnsafe(data.length + 4);
|
||||||
|
data.copy(dataWithHeader, 4);
|
||||||
|
connection.writePacket(
|
||||||
|
new Packets.Packet(0, dataWithHeader, 0, dataWithHeader.length)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const onEnd = () => {
|
||||||
|
connection.removeListener('error', onConnectionError);
|
||||||
|
connection.writePacket(EmptyPacket);
|
||||||
|
};
|
||||||
|
const onError = (err) => {
|
||||||
|
this._localStreamError = err;
|
||||||
|
connection.removeListener('error', onConnectionError);
|
||||||
|
connection.writePacket(EmptyPacket);
|
||||||
|
};
|
||||||
|
this._unpipeStream = () => {
|
||||||
|
connection.stream.removeListener('pause', onPause);
|
||||||
|
connection.stream.removeListener('drain', onDrain);
|
||||||
|
this._localStream.removeListener('data', onData);
|
||||||
|
this._localStream.removeListener('end', onEnd);
|
||||||
|
this._localStream.removeListener('error', onError);
|
||||||
|
};
|
||||||
|
connection.stream.on('pause', onPause);
|
||||||
|
connection.stream.on('drain', onDrain);
|
||||||
|
this._localStream.on('data', onData);
|
||||||
|
this._localStream.on('end', onEnd);
|
||||||
|
this._localStream.on('error', onError);
|
||||||
|
connection.once('error', onConnectionError);
|
||||||
|
return this.infileOk;
|
||||||
|
}
|
||||||
|
|
||||||
|
readField(packet, connection) {
|
||||||
|
this._receivedFieldsCount++;
|
||||||
|
// Often there is much more data in the column definition than in the row itself
|
||||||
|
// If you set manually _fields[0] to array of ColumnDefinition's (from previous call)
|
||||||
|
// you can 'cache' result of parsing. Field packets still received, but ignored in that case
|
||||||
|
// this is the reason _receivedFieldsCount exist (otherwise we could just use current length of fields array)
|
||||||
|
if (this._fields[this._resultIndex].length !== this._fieldCount) {
|
||||||
|
const field = new Packets.ColumnDefinition(
|
||||||
|
packet,
|
||||||
|
connection.clientEncoding
|
||||||
|
);
|
||||||
|
this._fields[this._resultIndex].push(field);
|
||||||
|
if (connection.config.debug) {
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.log(' Column definition:');
|
||||||
|
console.log(` name: ${field.name}`);
|
||||||
|
console.log(` type: ${field.columnType}`);
|
||||||
|
console.log(` flags: ${field.flags}`);
|
||||||
|
/* eslint-enable no-console */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// last field received
|
||||||
|
if (this._receivedFieldsCount === this._fieldCount) {
|
||||||
|
const fields = this._fields[this._resultIndex];
|
||||||
|
this.emit('fields', fields);
|
||||||
|
if (this.options.disableEval) {
|
||||||
|
this._rowParser = staticParser(fields, this.options, connection.config);
|
||||||
|
} else {
|
||||||
|
this._rowParser = new (getTextParser(
|
||||||
|
fields,
|
||||||
|
this.options,
|
||||||
|
connection.config
|
||||||
|
))(fields);
|
||||||
|
}
|
||||||
|
return Query.prototype.fieldsEOF;
|
||||||
|
}
|
||||||
|
return Query.prototype.readField;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldsEOF(packet, connection) {
|
||||||
|
// check EOF
|
||||||
|
if (!packet.isEOF()) {
|
||||||
|
return connection.protocolError('Expected EOF packet');
|
||||||
|
}
|
||||||
|
return this.row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
|
||||||
|
row(packet, _connection) {
|
||||||
|
if (packet.isEOF()) {
|
||||||
|
const status = packet.eofStatusFlags();
|
||||||
|
const moreResults = status & ServerStatus.SERVER_MORE_RESULTS_EXISTS;
|
||||||
|
if (moreResults) {
|
||||||
|
this._resultIndex++;
|
||||||
|
return Query.prototype.resultsetHeader;
|
||||||
|
}
|
||||||
|
return this.done();
|
||||||
|
}
|
||||||
|
let row;
|
||||||
|
try {
|
||||||
|
row = this._rowParser.next(
|
||||||
|
packet,
|
||||||
|
this._fields[this._resultIndex],
|
||||||
|
this.options
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
this._localStreamError = err;
|
||||||
|
return this.doneInsert(null);
|
||||||
|
}
|
||||||
|
if (this.onResult) {
|
||||||
|
this._rows[this._resultIndex].push(row);
|
||||||
|
} else {
|
||||||
|
this.emit('result', row, this._resultIndex);
|
||||||
|
}
|
||||||
|
return Query.prototype.row;
|
||||||
|
}
|
||||||
|
|
||||||
|
infileOk(packet, connection) {
|
||||||
|
const rs = new Packets.ResultSetHeader(packet, connection);
|
||||||
|
return this.doneInsert(rs);
|
||||||
|
}
|
||||||
|
|
||||||
|
stream(options) {
|
||||||
|
options = options || {};
|
||||||
|
options.objectMode = true;
|
||||||
|
const stream = new Readable(options);
|
||||||
|
stream._read = () => {
|
||||||
|
this._connection && this._connection.resume();
|
||||||
|
};
|
||||||
|
this.on('result', (row, resultSetIndex) => {
|
||||||
|
if (!stream.push(row)) {
|
||||||
|
this._connection.pause();
|
||||||
|
}
|
||||||
|
stream.emit('result', row, resultSetIndex); // replicate old emitter
|
||||||
|
});
|
||||||
|
this.on('error', (err) => {
|
||||||
|
stream.emit('error', err); // Pass on any errors
|
||||||
|
});
|
||||||
|
this.on('end', () => {
|
||||||
|
stream.push(null); // pushing null, indicating EOF
|
||||||
|
});
|
||||||
|
this.on('fields', (fields) => {
|
||||||
|
stream.emit('fields', fields); // replicate old emitter
|
||||||
|
});
|
||||||
|
stream.on('end', () => {
|
||||||
|
stream.emit('close');
|
||||||
|
});
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
_setTimeout() {
|
||||||
|
if (this.timeout) {
|
||||||
|
const timeoutHandler = this._handleTimeoutError.bind(this);
|
||||||
|
this.queryTimeout = Timers.setTimeout(timeoutHandler, this.timeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleTimeoutError() {
|
||||||
|
if (this.queryTimeout) {
|
||||||
|
Timers.clearTimeout(this.queryTimeout);
|
||||||
|
this.queryTimeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const err = new Error('Query inactivity timeout');
|
||||||
|
err.errorno = 'PROTOCOL_SEQUENCE_TIMEOUT';
|
||||||
|
err.code = 'PROTOCOL_SEQUENCE_TIMEOUT';
|
||||||
|
err.syscall = 'query';
|
||||||
|
|
||||||
|
if (this.onResult) {
|
||||||
|
this.onResult(err);
|
||||||
|
} else {
|
||||||
|
this.emit('error', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Query.prototype.catch = Query.prototype.then;
|
||||||
|
|
||||||
|
module.exports = Query;
|
29
node_modules/mysql2/lib/commands/quit.js
generated
vendored
Normal file
29
node_modules/mysql2/lib/commands/quit.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Command = require('./command.js');
|
||||||
|
const CommandCode = require('../constants/commands.js');
|
||||||
|
const Packet = require('../packets/packet.js');
|
||||||
|
|
||||||
|
class Quit extends Command {
|
||||||
|
constructor(callback) {
|
||||||
|
super();
|
||||||
|
this.onResult = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
start(packet, connection) {
|
||||||
|
connection._closing = true;
|
||||||
|
const quit = new Packet(
|
||||||
|
0,
|
||||||
|
Buffer.from([1, 0, 0, 0, CommandCode.QUIT]),
|
||||||
|
0,
|
||||||
|
5
|
||||||
|
);
|
||||||
|
if (this.onResult) {
|
||||||
|
this.onResult();
|
||||||
|
}
|
||||||
|
connection.writePacket(quit);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Quit;
|
27
node_modules/mysql2/lib/commands/register_slave.js
generated
vendored
Normal file
27
node_modules/mysql2/lib/commands/register_slave.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Command = require('./command');
|
||||||
|
const Packets = require('../packets');
|
||||||
|
|
||||||
|
class RegisterSlave extends Command {
|
||||||
|
constructor(opts, callback) {
|
||||||
|
super();
|
||||||
|
this.onResult = callback;
|
||||||
|
this.opts = opts;
|
||||||
|
}
|
||||||
|
|
||||||
|
start(packet, connection) {
|
||||||
|
const newPacket = new Packets.RegisterSlave(this.opts);
|
||||||
|
connection.writePacket(newPacket.toPacket(1));
|
||||||
|
return RegisterSlave.prototype.registerResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
registerResponse() {
|
||||||
|
if (this.onResult) {
|
||||||
|
process.nextTick(this.onResult.bind(this));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = RegisterSlave;
|
203
node_modules/mysql2/lib/commands/server_handshake.js
generated
vendored
Normal file
203
node_modules/mysql2/lib/commands/server_handshake.js
generated
vendored
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const CommandCode = require('../constants/commands.js');
|
||||||
|
const Errors = require('../constants/errors.js');
|
||||||
|
|
||||||
|
const Command = require('./command.js');
|
||||||
|
const Packets = require('../packets/index.js');
|
||||||
|
|
||||||
|
class ServerHandshake extends Command {
|
||||||
|
constructor(args) {
|
||||||
|
super();
|
||||||
|
this.args = args;
|
||||||
|
/*
|
||||||
|
this.protocolVersion = args.protocolVersion || 10;
|
||||||
|
this.serverVersion = args.serverVersion;
|
||||||
|
this.connectionId = args.connectionId,
|
||||||
|
this.statusFlags = args.statusFlags,
|
||||||
|
this.characterSet = args.characterSet,
|
||||||
|
this.capabilityFlags = args.capabilityFlags || 512;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
start(packet, connection) {
|
||||||
|
const serverHelloPacket = new Packets.Handshake(this.args);
|
||||||
|
this.serverHello = serverHelloPacket;
|
||||||
|
serverHelloPacket.setScrambleData((err) => {
|
||||||
|
if (err) {
|
||||||
|
connection.emit('error', new Error('Error generating random bytes'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
connection.writePacket(serverHelloPacket.toPacket(0));
|
||||||
|
});
|
||||||
|
return ServerHandshake.prototype.readClientReply;
|
||||||
|
}
|
||||||
|
|
||||||
|
readClientReply(packet, connection) {
|
||||||
|
// check auth here
|
||||||
|
const clientHelloReply = Packets.HandshakeResponse.fromPacket(packet);
|
||||||
|
// TODO check we don't have something similar already
|
||||||
|
connection.clientHelloReply = clientHelloReply;
|
||||||
|
if (this.args.authCallback) {
|
||||||
|
this.args.authCallback(
|
||||||
|
{
|
||||||
|
user: clientHelloReply.user,
|
||||||
|
database: clientHelloReply.database,
|
||||||
|
address: connection.stream.remoteAddress,
|
||||||
|
authPluginData1: this.serverHello.authPluginData1,
|
||||||
|
authPluginData2: this.serverHello.authPluginData2,
|
||||||
|
authToken: clientHelloReply.authToken,
|
||||||
|
},
|
||||||
|
(err, mysqlError) => {
|
||||||
|
// if (err)
|
||||||
|
if (!mysqlError) {
|
||||||
|
connection.writeOk();
|
||||||
|
} else {
|
||||||
|
// TODO create constants / errorToCode
|
||||||
|
// 1045 = ER_ACCESS_DENIED_ERROR
|
||||||
|
connection.writeError({
|
||||||
|
message: mysqlError.message || '',
|
||||||
|
code: mysqlError.code || 1045,
|
||||||
|
});
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
connection.writeOk();
|
||||||
|
}
|
||||||
|
return ServerHandshake.prototype.dispatchCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
_isStatement(query, name) {
|
||||||
|
const firstWord = query.split(' ')[0].toUpperCase();
|
||||||
|
return firstWord === name;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatchCommands(packet, connection) {
|
||||||
|
// command from client to server
|
||||||
|
let knownCommand = true;
|
||||||
|
const encoding = connection.clientHelloReply.encoding;
|
||||||
|
const commandCode = packet.readInt8();
|
||||||
|
switch (commandCode) {
|
||||||
|
case CommandCode.STMT_PREPARE:
|
||||||
|
if (connection.listeners('stmt_prepare').length) {
|
||||||
|
const query = packet.readString(undefined, encoding);
|
||||||
|
connection.emit('stmt_prepare', query);
|
||||||
|
} else {
|
||||||
|
connection.writeError({
|
||||||
|
code: Errors.HA_ERR_INTERNAL_ERROR,
|
||||||
|
message: 'No query handler for prepared statements.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CommandCode.STMT_EXECUTE:
|
||||||
|
if (connection.listeners('stmt_execute').length) {
|
||||||
|
const { stmtId, flags, iterationCount, values } =
|
||||||
|
Packets.Execute.fromPacket(packet, encoding);
|
||||||
|
connection.emit(
|
||||||
|
'stmt_execute',
|
||||||
|
stmtId,
|
||||||
|
flags,
|
||||||
|
iterationCount,
|
||||||
|
values
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
connection.writeError({
|
||||||
|
code: Errors.HA_ERR_INTERNAL_ERROR,
|
||||||
|
message: 'No query handler for execute statements.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CommandCode.QUIT:
|
||||||
|
if (connection.listeners('quit').length) {
|
||||||
|
connection.emit('quit');
|
||||||
|
} else {
|
||||||
|
connection.stream.end();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CommandCode.INIT_DB:
|
||||||
|
if (connection.listeners('init_db').length) {
|
||||||
|
const schemaName = packet.readString(undefined, encoding);
|
||||||
|
connection.emit('init_db', schemaName);
|
||||||
|
} else {
|
||||||
|
connection.writeOk();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CommandCode.QUERY:
|
||||||
|
if (connection.listeners('query').length) {
|
||||||
|
const query = packet.readString(undefined, encoding);
|
||||||
|
if (
|
||||||
|
this._isStatement(query, 'PREPARE') ||
|
||||||
|
this._isStatement(query, 'SET')
|
||||||
|
) {
|
||||||
|
connection.emit('stmt_prepare', query);
|
||||||
|
} else if (this._isStatement(query, 'EXECUTE')) {
|
||||||
|
connection.emit('stmt_execute', null, null, null, null, query);
|
||||||
|
} else connection.emit('query', query);
|
||||||
|
} else {
|
||||||
|
connection.writeError({
|
||||||
|
code: Errors.HA_ERR_INTERNAL_ERROR,
|
||||||
|
message: 'No query handler',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CommandCode.FIELD_LIST:
|
||||||
|
if (connection.listeners('field_list').length) {
|
||||||
|
const table = packet.readNullTerminatedString(encoding);
|
||||||
|
const fields = packet.readString(undefined, encoding);
|
||||||
|
connection.emit('field_list', table, fields);
|
||||||
|
} else {
|
||||||
|
connection.writeError({
|
||||||
|
code: Errors.ER_WARN_DEPRECATED_SYNTAX,
|
||||||
|
message:
|
||||||
|
'As of MySQL 5.7.11, COM_FIELD_LIST is deprecated and will be removed in a future version of MySQL.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CommandCode.PING:
|
||||||
|
if (connection.listeners('ping').length) {
|
||||||
|
connection.emit('ping');
|
||||||
|
} else {
|
||||||
|
connection.writeOk();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
knownCommand = false;
|
||||||
|
}
|
||||||
|
if (connection.listeners('packet').length) {
|
||||||
|
connection.emit('packet', packet.clone(), knownCommand, commandCode);
|
||||||
|
} else if (!knownCommand) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Unknown command:', commandCode);
|
||||||
|
}
|
||||||
|
return ServerHandshake.prototype.dispatchCommands;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ServerHandshake;
|
||||||
|
|
||||||
|
// TODO: implement server-side 4.1 authentication
|
||||||
|
/*
|
||||||
|
4.1 authentication: (http://bazaar.launchpad.net/~mysql/mysql-server/5.5/view/head:/sql/password.c)
|
||||||
|
|
||||||
|
SERVER: public_seed=create_random_string()
|
||||||
|
send(public_seed)
|
||||||
|
|
||||||
|
CLIENT: recv(public_seed)
|
||||||
|
hash_stage1=sha1("password")
|
||||||
|
hash_stage2=sha1(hash_stage1)
|
||||||
|
reply=xor(hash_stage1, sha1(public_seed,hash_stage2)
|
||||||
|
|
||||||
|
// this three steps are done in scramble()
|
||||||
|
|
||||||
|
send(reply)
|
||||||
|
|
||||||
|
|
||||||
|
SERVER: recv(reply)
|
||||||
|
hash_stage1=xor(reply, sha1(public_seed,hash_stage2))
|
||||||
|
candidate_hash2=sha1(hash_stage1)
|
||||||
|
check(candidate_hash2==hash_stage2)
|
||||||
|
|
||||||
|
server stores sha1(sha1(password)) ( hash_stag2)
|
||||||
|
*/
|
127
node_modules/mysql2/lib/compressed_protocol.js
generated
vendored
Normal file
127
node_modules/mysql2/lib/compressed_protocol.js
generated
vendored
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// connection mixins
|
||||||
|
// implementation of http://dev.mysql.com/doc/internals/en/compression.html
|
||||||
|
|
||||||
|
const zlib = require('zlib');
|
||||||
|
const PacketParser = require('./packet_parser.js');
|
||||||
|
|
||||||
|
function handleCompressedPacket(packet) {
|
||||||
|
// eslint-disable-next-line consistent-this, no-invalid-this
|
||||||
|
const connection = this;
|
||||||
|
const deflatedLength = packet.readInt24();
|
||||||
|
const body = packet.readBuffer();
|
||||||
|
|
||||||
|
if (deflatedLength !== 0) {
|
||||||
|
connection.inflateQueue.push((task) => {
|
||||||
|
zlib.inflate(body, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
connection._handleNetworkError(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
connection._bumpCompressedSequenceId(packet.numPackets);
|
||||||
|
connection._inflatedPacketsParser.execute(data);
|
||||||
|
task.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
connection.inflateQueue.push((task) => {
|
||||||
|
connection._bumpCompressedSequenceId(packet.numPackets);
|
||||||
|
connection._inflatedPacketsParser.execute(body);
|
||||||
|
task.done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeCompressed(buffer) {
|
||||||
|
// http://dev.mysql.com/doc/internals/en/example-several-mysql-packets.html
|
||||||
|
// note: sending a MySQL Packet of the size 2^24−5 to 2^24−1 via compression
|
||||||
|
// leads to at least one extra compressed packet.
|
||||||
|
// (this is because "length of the packet before compression" need to fit
|
||||||
|
// into 3 byte unsigned int. "length of the packet before compression" includes
|
||||||
|
// 4 byte packet header, hence 2^24−5)
|
||||||
|
const MAX_COMPRESSED_LENGTH = 16777210;
|
||||||
|
let start;
|
||||||
|
if (buffer.length > MAX_COMPRESSED_LENGTH) {
|
||||||
|
for (start = 0; start < buffer.length; start += MAX_COMPRESSED_LENGTH) {
|
||||||
|
writeCompressed.call(
|
||||||
|
// eslint-disable-next-line no-invalid-this
|
||||||
|
this,
|
||||||
|
buffer.slice(start, start + MAX_COMPRESSED_LENGTH)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-invalid-this, consistent-this
|
||||||
|
const connection = this;
|
||||||
|
|
||||||
|
let packetLen = buffer.length;
|
||||||
|
const compressHeader = Buffer.allocUnsafe(7);
|
||||||
|
|
||||||
|
// seqqueue is used here because zlib async execution is routed via thread pool
|
||||||
|
// internally and when we have multiple compressed packets arriving we need
|
||||||
|
// to assemble uncompressed result sequentially
|
||||||
|
(function (seqId) {
|
||||||
|
connection.deflateQueue.push((task) => {
|
||||||
|
zlib.deflate(buffer, (err, compressed) => {
|
||||||
|
if (err) {
|
||||||
|
connection._handleFatalError(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let compressedLength = compressed.length;
|
||||||
|
|
||||||
|
if (compressedLength < packetLen) {
|
||||||
|
compressHeader.writeUInt8(compressedLength & 0xff, 0);
|
||||||
|
compressHeader.writeUInt16LE(compressedLength >> 8, 1);
|
||||||
|
compressHeader.writeUInt8(seqId, 3);
|
||||||
|
compressHeader.writeUInt8(packetLen & 0xff, 4);
|
||||||
|
compressHeader.writeUInt16LE(packetLen >> 8, 5);
|
||||||
|
connection.writeUncompressed(compressHeader);
|
||||||
|
connection.writeUncompressed(compressed);
|
||||||
|
} else {
|
||||||
|
// http://dev.mysql.com/doc/internals/en/uncompressed-payload.html
|
||||||
|
// To send an uncompressed payload:
|
||||||
|
// - set length of payload before compression to 0
|
||||||
|
// - the compressed payload contains the uncompressed payload instead.
|
||||||
|
compressedLength = packetLen;
|
||||||
|
packetLen = 0;
|
||||||
|
compressHeader.writeUInt8(compressedLength & 0xff, 0);
|
||||||
|
compressHeader.writeUInt16LE(compressedLength >> 8, 1);
|
||||||
|
compressHeader.writeUInt8(seqId, 3);
|
||||||
|
compressHeader.writeUInt8(packetLen & 0xff, 4);
|
||||||
|
compressHeader.writeUInt16LE(packetLen >> 8, 5);
|
||||||
|
connection.writeUncompressed(compressHeader);
|
||||||
|
connection.writeUncompressed(buffer);
|
||||||
|
}
|
||||||
|
task.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})(connection.compressedSequenceId);
|
||||||
|
connection._bumpCompressedSequenceId(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function enableCompression(connection) {
|
||||||
|
connection._lastWrittenPacketId = 0;
|
||||||
|
connection._lastReceivedPacketId = 0;
|
||||||
|
|
||||||
|
connection._handleCompressedPacket = handleCompressedPacket;
|
||||||
|
connection._inflatedPacketsParser = new PacketParser((p) => {
|
||||||
|
connection.handlePacket(p);
|
||||||
|
}, 4);
|
||||||
|
connection._inflatedPacketsParser._lastPacket = 0;
|
||||||
|
connection.packetParser = new PacketParser((packet) => {
|
||||||
|
connection._handleCompressedPacket(packet);
|
||||||
|
}, 7);
|
||||||
|
|
||||||
|
connection.writeUncompressed = connection.write;
|
||||||
|
connection.write = writeCompressed;
|
||||||
|
|
||||||
|
const seqqueue = require('seq-queue');
|
||||||
|
connection.inflateQueue = seqqueue.createQueue();
|
||||||
|
connection.deflateQueue = seqqueue.createQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
enableCompression: enableCompression,
|
||||||
|
};
|
12
node_modules/mysql2/lib/connection.js
generated
vendored
Normal file
12
node_modules/mysql2/lib/connection.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const BaseConnection = require('./base/connection.js');
|
||||||
|
|
||||||
|
class Connection extends BaseConnection {
|
||||||
|
promise(promiseImpl) {
|
||||||
|
const PromiseConnection = require('./promise/connection.js');
|
||||||
|
return new PromiseConnection(this, promiseImpl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Connection;
|
292
node_modules/mysql2/lib/connection_config.js
generated
vendored
Normal file
292
node_modules/mysql2/lib/connection_config.js
generated
vendored
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
// This file was modified by Oracle on September 21, 2021.
|
||||||
|
// New connection options for additional authentication factors were
|
||||||
|
// introduced.
|
||||||
|
// Multi-factor authentication capability is now enabled if one of these
|
||||||
|
// options is used.
|
||||||
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { URL } = require('url');
|
||||||
|
const ClientConstants = require('./constants/client');
|
||||||
|
const Charsets = require('./constants/charsets');
|
||||||
|
const { version } = require('../package.json');
|
||||||
|
let SSLProfiles = null;
|
||||||
|
|
||||||
|
const validOptions = {
|
||||||
|
authPlugins: 1,
|
||||||
|
authSwitchHandler: 1,
|
||||||
|
bigNumberStrings: 1,
|
||||||
|
charset: 1,
|
||||||
|
charsetNumber: 1,
|
||||||
|
compress: 1,
|
||||||
|
connectAttributes: 1,
|
||||||
|
connectTimeout: 1,
|
||||||
|
database: 1,
|
||||||
|
dateStrings: 1,
|
||||||
|
debug: 1,
|
||||||
|
decimalNumbers: 1,
|
||||||
|
enableKeepAlive: 1,
|
||||||
|
flags: 1,
|
||||||
|
host: 1,
|
||||||
|
insecureAuth: 1,
|
||||||
|
infileStreamFactory: 1,
|
||||||
|
isServer: 1,
|
||||||
|
keepAliveInitialDelay: 1,
|
||||||
|
localAddress: 1,
|
||||||
|
maxPreparedStatements: 1,
|
||||||
|
multipleStatements: 1,
|
||||||
|
namedPlaceholders: 1,
|
||||||
|
nestTables: 1,
|
||||||
|
password: 1,
|
||||||
|
// with multi-factor authentication, the main password (used for the first
|
||||||
|
// authentication factor) can be provided via password1
|
||||||
|
password1: 1,
|
||||||
|
password2: 1,
|
||||||
|
password3: 1,
|
||||||
|
passwordSha1: 1,
|
||||||
|
pool: 1,
|
||||||
|
port: 1,
|
||||||
|
queryFormat: 1,
|
||||||
|
rowsAsArray: 1,
|
||||||
|
socketPath: 1,
|
||||||
|
ssl: 1,
|
||||||
|
stream: 1,
|
||||||
|
stringifyObjects: 1,
|
||||||
|
supportBigNumbers: 1,
|
||||||
|
timezone: 1,
|
||||||
|
trace: 1,
|
||||||
|
typeCast: 1,
|
||||||
|
uri: 1,
|
||||||
|
user: 1,
|
||||||
|
disableEval: 1,
|
||||||
|
// These options are used for Pool
|
||||||
|
connectionLimit: 1,
|
||||||
|
maxIdle: 1,
|
||||||
|
idleTimeout: 1,
|
||||||
|
Promise: 1,
|
||||||
|
queueLimit: 1,
|
||||||
|
waitForConnections: 1,
|
||||||
|
jsonStrings: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
class ConnectionConfig {
|
||||||
|
constructor(options) {
|
||||||
|
if (typeof options === 'string') {
|
||||||
|
options = ConnectionConfig.parseUrl(options);
|
||||||
|
} else if (options && options.uri) {
|
||||||
|
const uriOptions = ConnectionConfig.parseUrl(options.uri);
|
||||||
|
for (const key in uriOptions) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(uriOptions, key)) continue;
|
||||||
|
if (options[key]) continue;
|
||||||
|
options[key] = uriOptions[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const key in options) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(options, key)) continue;
|
||||||
|
if (validOptions[key] !== 1) {
|
||||||
|
// REVIEW: Should this be emitted somehow?
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(
|
||||||
|
`Ignoring invalid configuration option passed to Connection: ${key}. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.isServer = options.isServer;
|
||||||
|
this.stream = options.stream;
|
||||||
|
this.host = options.host || 'localhost';
|
||||||
|
this.port =
|
||||||
|
(typeof options.port === 'string'
|
||||||
|
? parseInt(options.port, 10)
|
||||||
|
: options.port) || 3306;
|
||||||
|
this.localAddress = options.localAddress;
|
||||||
|
this.socketPath = options.socketPath;
|
||||||
|
this.user = options.user || undefined;
|
||||||
|
// for the purpose of multi-factor authentication, or not, the main
|
||||||
|
// password (used for the 1st authentication factor) can also be
|
||||||
|
// provided via the "password1" option
|
||||||
|
this.password = options.password || options.password1 || undefined;
|
||||||
|
this.password2 = options.password2 || undefined;
|
||||||
|
this.password3 = options.password3 || undefined;
|
||||||
|
this.passwordSha1 = options.passwordSha1 || undefined;
|
||||||
|
this.database = options.database;
|
||||||
|
this.connectTimeout = isNaN(options.connectTimeout)
|
||||||
|
? 10 * 1000
|
||||||
|
: options.connectTimeout;
|
||||||
|
this.insecureAuth = options.insecureAuth || false;
|
||||||
|
this.infileStreamFactory = options.infileStreamFactory || undefined;
|
||||||
|
this.supportBigNumbers = options.supportBigNumbers || false;
|
||||||
|
this.bigNumberStrings = options.bigNumberStrings || false;
|
||||||
|
this.decimalNumbers = options.decimalNumbers || false;
|
||||||
|
this.dateStrings = options.dateStrings || false;
|
||||||
|
this.debug = options.debug;
|
||||||
|
this.trace = options.trace !== false;
|
||||||
|
this.stringifyObjects = options.stringifyObjects || false;
|
||||||
|
this.enableKeepAlive = options.enableKeepAlive !== false;
|
||||||
|
this.keepAliveInitialDelay = options.keepAliveInitialDelay;
|
||||||
|
if (
|
||||||
|
options.timezone &&
|
||||||
|
!/^(?:local|Z|[ +-]\d\d:\d\d)$/.test(options.timezone)
|
||||||
|
) {
|
||||||
|
// strictly supports timezones specified by mysqljs/mysql:
|
||||||
|
// https://github.com/mysqljs/mysql#user-content-connection-options
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(
|
||||||
|
`Ignoring invalid timezone passed to Connection: ${options.timezone}. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection`
|
||||||
|
);
|
||||||
|
// SqlStrings falls back to UTC on invalid timezone
|
||||||
|
this.timezone = 'Z';
|
||||||
|
} else {
|
||||||
|
this.timezone = options.timezone || 'local';
|
||||||
|
}
|
||||||
|
this.queryFormat = options.queryFormat;
|
||||||
|
this.pool = options.pool || undefined;
|
||||||
|
this.ssl =
|
||||||
|
typeof options.ssl === 'string'
|
||||||
|
? ConnectionConfig.getSSLProfile(options.ssl)
|
||||||
|
: options.ssl || false;
|
||||||
|
this.multipleStatements = options.multipleStatements || false;
|
||||||
|
this.rowsAsArray = options.rowsAsArray || false;
|
||||||
|
this.namedPlaceholders = options.namedPlaceholders || false;
|
||||||
|
this.nestTables =
|
||||||
|
options.nestTables === undefined ? undefined : options.nestTables;
|
||||||
|
this.typeCast = options.typeCast === undefined ? true : options.typeCast;
|
||||||
|
this.disableEval = Boolean(options.disableEval);
|
||||||
|
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.slice(1)}`;
|
||||||
|
}
|
||||||
|
if (this.ssl) {
|
||||||
|
if (typeof this.ssl !== 'object') {
|
||||||
|
throw new TypeError(
|
||||||
|
`SSL profile must be an object, instead it's a ${typeof 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.UTF8MB4_UNICODE_CI;
|
||||||
|
this.compress = options.compress || false;
|
||||||
|
this.authPlugins = options.authPlugins;
|
||||||
|
this.authSwitchHandler = options.authSwitchHandler;
|
||||||
|
this.clientFlags = ConnectionConfig.mergeFlags(
|
||||||
|
ConnectionConfig.getDefaultFlags(options),
|
||||||
|
options.flags || ''
|
||||||
|
);
|
||||||
|
// Default connection attributes
|
||||||
|
// https://dev.mysql.com/doc/refman/8.0/en/performance-schema-connection-attribute-tables.html
|
||||||
|
const defaultConnectAttributes = {
|
||||||
|
_client_name: 'Node-MySQL-2',
|
||||||
|
_client_version: version,
|
||||||
|
};
|
||||||
|
this.connectAttributes = {
|
||||||
|
...defaultConnectAttributes,
|
||||||
|
...(options.connectAttributes || {}),
|
||||||
|
};
|
||||||
|
this.maxPreparedStatements = options.maxPreparedStatements || 16000;
|
||||||
|
this.jsonStrings = options.jsonStrings || false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static mergeFlags(default_flags, user_flags) {
|
||||||
|
let flags = 0x0,
|
||||||
|
i;
|
||||||
|
if (!Array.isArray(user_flags)) {
|
||||||
|
user_flags = String(user_flags || '')
|
||||||
|
.toUpperCase()
|
||||||
|
.split(/\s*,+\s*/);
|
||||||
|
}
|
||||||
|
// add default flags unless "blacklisted"
|
||||||
|
for (i in default_flags) {
|
||||||
|
if (user_flags.indexOf(`-${default_flags[i]}`) >= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
flags |= ClientConstants[default_flags[i]] || 0x0;
|
||||||
|
}
|
||||||
|
// add user flags unless already already added
|
||||||
|
for (i in user_flags) {
|
||||||
|
if (user_flags[i][0] === '-') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (default_flags.indexOf(user_flags[i]) >= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
flags |= ClientConstants[user_flags[i]] || 0x0;
|
||||||
|
}
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDefaultFlags(options) {
|
||||||
|
const defaultFlags = [
|
||||||
|
'LONG_PASSWORD',
|
||||||
|
'FOUND_ROWS',
|
||||||
|
'LONG_FLAG',
|
||||||
|
'CONNECT_WITH_DB',
|
||||||
|
'ODBC',
|
||||||
|
'LOCAL_FILES',
|
||||||
|
'IGNORE_SPACE',
|
||||||
|
'PROTOCOL_41',
|
||||||
|
'IGNORE_SIGPIPE',
|
||||||
|
'TRANSACTIONS',
|
||||||
|
'RESERVED',
|
||||||
|
'SECURE_CONNECTION',
|
||||||
|
'MULTI_RESULTS',
|
||||||
|
'TRANSACTIONS',
|
||||||
|
'SESSION_TRACK',
|
||||||
|
'CONNECT_ATTRS',
|
||||||
|
];
|
||||||
|
if (options && options.multipleStatements) {
|
||||||
|
defaultFlags.push('MULTI_STATEMENTS');
|
||||||
|
}
|
||||||
|
defaultFlags.push('PLUGIN_AUTH');
|
||||||
|
defaultFlags.push('PLUGIN_AUTH_LENENC_CLIENT_DATA');
|
||||||
|
|
||||||
|
return defaultFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getCharsetNumber(charset) {
|
||||||
|
const num = Charsets[charset.toUpperCase()];
|
||||||
|
if (num === undefined) {
|
||||||
|
throw new TypeError(`Unknown charset '${charset}'`);
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getSSLProfile(name) {
|
||||||
|
if (!SSLProfiles) {
|
||||||
|
SSLProfiles = require('./constants/ssl_profiles.js');
|
||||||
|
}
|
||||||
|
const ssl = SSLProfiles[name];
|
||||||
|
if (ssl === undefined) {
|
||||||
|
throw new TypeError(`Unknown SSL profile '${name}'`);
|
||||||
|
}
|
||||||
|
return ssl;
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseUrl(url) {
|
||||||
|
const parsedUrl = new URL(url);
|
||||||
|
const options = {
|
||||||
|
host: decodeURIComponent(parsedUrl.hostname),
|
||||||
|
port: parseInt(parsedUrl.port, 10),
|
||||||
|
database: decodeURIComponent(parsedUrl.pathname.slice(1)),
|
||||||
|
user: decodeURIComponent(parsedUrl.username),
|
||||||
|
password: decodeURIComponent(parsedUrl.password),
|
||||||
|
};
|
||||||
|
parsedUrl.searchParams.forEach((value, 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConnectionConfig;
|
316
node_modules/mysql2/lib/constants/charset_encodings.js
generated
vendored
Normal file
316
node_modules/mysql2/lib/constants/charset_encodings.js
generated
vendored
Normal file
@ -0,0 +1,316 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// see tools/generate-charset-mapping.js
|
||||||
|
// basicalliy result of "SHOW COLLATION" query
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
'utf8',
|
||||||
|
'big5',
|
||||||
|
'latin2',
|
||||||
|
'dec8',
|
||||||
|
'cp850',
|
||||||
|
'latin1',
|
||||||
|
'hp8',
|
||||||
|
'koi8r',
|
||||||
|
'latin1',
|
||||||
|
'latin2',
|
||||||
|
'swe7',
|
||||||
|
'ascii',
|
||||||
|
'eucjp',
|
||||||
|
'sjis',
|
||||||
|
'cp1251',
|
||||||
|
'latin1',
|
||||||
|
'hebrew',
|
||||||
|
'utf8',
|
||||||
|
'tis620',
|
||||||
|
'euckr',
|
||||||
|
'latin7',
|
||||||
|
'latin2',
|
||||||
|
'koi8u',
|
||||||
|
'cp1251',
|
||||||
|
'gb2312',
|
||||||
|
'greek',
|
||||||
|
'cp1250',
|
||||||
|
'latin2',
|
||||||
|
'gbk',
|
||||||
|
'cp1257',
|
||||||
|
'latin5',
|
||||||
|
'latin1',
|
||||||
|
'armscii8',
|
||||||
|
'cesu8',
|
||||||
|
'cp1250',
|
||||||
|
'ucs2',
|
||||||
|
'cp866',
|
||||||
|
'keybcs2',
|
||||||
|
'macintosh',
|
||||||
|
'macroman',
|
||||||
|
'cp852',
|
||||||
|
'latin7',
|
||||||
|
'latin7',
|
||||||
|
'macintosh',
|
||||||
|
'cp1250',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'latin1',
|
||||||
|
'latin1',
|
||||||
|
'latin1',
|
||||||
|
'cp1251',
|
||||||
|
'cp1251',
|
||||||
|
'cp1251',
|
||||||
|
'macroman',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16-le',
|
||||||
|
'cp1256',
|
||||||
|
'cp1257',
|
||||||
|
'cp1257',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf16-le',
|
||||||
|
'binary',
|
||||||
|
'armscii8',
|
||||||
|
'ascii',
|
||||||
|
'cp1250',
|
||||||
|
'cp1256',
|
||||||
|
'cp866',
|
||||||
|
'dec8',
|
||||||
|
'greek',
|
||||||
|
'hebrew',
|
||||||
|
'hp8',
|
||||||
|
'keybcs2',
|
||||||
|
'koi8r',
|
||||||
|
'koi8u',
|
||||||
|
'cesu8',
|
||||||
|
'latin2',
|
||||||
|
'latin5',
|
||||||
|
'latin7',
|
||||||
|
'cp850',
|
||||||
|
'cp852',
|
||||||
|
'swe7',
|
||||||
|
'cesu8',
|
||||||
|
'big5',
|
||||||
|
'euckr',
|
||||||
|
'gb2312',
|
||||||
|
'gbk',
|
||||||
|
'sjis',
|
||||||
|
'tis620',
|
||||||
|
'ucs2',
|
||||||
|
'eucjp',
|
||||||
|
'geostd8',
|
||||||
|
'geostd8',
|
||||||
|
'latin1',
|
||||||
|
'cp932',
|
||||||
|
'cp932',
|
||||||
|
'eucjpms',
|
||||||
|
'eucjpms',
|
||||||
|
'cp1250',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf16',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'ucs2',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'ucs2',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf32',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'cesu8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'cesu8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'gb18030',
|
||||||
|
'gb18030',
|
||||||
|
'gb18030',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
'utf8',
|
||||||
|
];
|
317
node_modules/mysql2/lib/constants/charsets.js
generated
vendored
Normal file
317
node_modules/mysql2/lib/constants/charsets.js
generated
vendored
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
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.UTF8_TOLOWER_CI = 76;
|
||||||
|
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_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_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_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_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_CI = 245;
|
||||||
|
exports.UTF8MB4_UNICODE_520_CI = 246;
|
||||||
|
exports.UTF8MB4_VIETNAMESE_CI = 247;
|
||||||
|
exports.GB18030_CHINESE_CI = 248;
|
||||||
|
exports.GB18030_BIN = 249;
|
||||||
|
exports.GB18030_UNICODE_520_CI = 250;
|
||||||
|
exports.UTF8_GENERAL50_CI = 253; // deprecated
|
||||||
|
exports.UTF8MB4_0900_AI_CI = 255;
|
||||||
|
exports.UTF8MB4_DE_PB_0900_AI_CI = 256;
|
||||||
|
exports.UTF8MB4_IS_0900_AI_CI = 257;
|
||||||
|
exports.UTF8MB4_LV_0900_AI_CI = 258;
|
||||||
|
exports.UTF8MB4_RO_0900_AI_CI = 259;
|
||||||
|
exports.UTF8MB4_SL_0900_AI_CI = 260;
|
||||||
|
exports.UTF8MB4_PL_0900_AI_CI = 261;
|
||||||
|
exports.UTF8MB4_ET_0900_AI_CI = 262;
|
||||||
|
exports.UTF8MB4_ES_0900_AI_CI = 263;
|
||||||
|
exports.UTF8MB4_SV_0900_AI_CI = 264;
|
||||||
|
exports.UTF8MB4_TR_0900_AI_CI = 265;
|
||||||
|
exports.UTF8MB4_CS_0900_AI_CI = 266;
|
||||||
|
exports.UTF8MB4_DA_0900_AI_CI = 267;
|
||||||
|
exports.UTF8MB4_LT_0900_AI_CI = 268;
|
||||||
|
exports.UTF8MB4_SK_0900_AI_CI = 269;
|
||||||
|
exports.UTF8MB4_ES_TRAD_0900_AI_CI = 270;
|
||||||
|
exports.UTF8MB4_LA_0900_AI_CI = 271;
|
||||||
|
exports.UTF8MB4_EO_0900_AI_CI = 273;
|
||||||
|
exports.UTF8MB4_HU_0900_AI_CI = 274;
|
||||||
|
exports.UTF8MB4_HR_0900_AI_CI = 275;
|
||||||
|
exports.UTF8MB4_VI_0900_AI_CI = 277;
|
||||||
|
exports.UTF8MB4_0900_AS_CS = 278;
|
||||||
|
exports.UTF8MB4_DE_PB_0900_AS_CS = 279;
|
||||||
|
exports.UTF8MB4_IS_0900_AS_CS = 280;
|
||||||
|
exports.UTF8MB4_LV_0900_AS_CS = 281;
|
||||||
|
exports.UTF8MB4_RO_0900_AS_CS = 282;
|
||||||
|
exports.UTF8MB4_SL_0900_AS_CS = 283;
|
||||||
|
exports.UTF8MB4_PL_0900_AS_CS = 284;
|
||||||
|
exports.UTF8MB4_ET_0900_AS_CS = 285;
|
||||||
|
exports.UTF8MB4_ES_0900_AS_CS = 286;
|
||||||
|
exports.UTF8MB4_SV_0900_AS_CS = 287;
|
||||||
|
exports.UTF8MB4_TR_0900_AS_CS = 288;
|
||||||
|
exports.UTF8MB4_CS_0900_AS_CS = 289;
|
||||||
|
exports.UTF8MB4_DA_0900_AS_CS = 290;
|
||||||
|
exports.UTF8MB4_LT_0900_AS_CS = 291;
|
||||||
|
exports.UTF8MB4_SK_0900_AS_CS = 292;
|
||||||
|
exports.UTF8MB4_ES_TRAD_0900_AS_CS = 293;
|
||||||
|
exports.UTF8MB4_LA_0900_AS_CS = 294;
|
||||||
|
exports.UTF8MB4_EO_0900_AS_CS = 296;
|
||||||
|
exports.UTF8MB4_HU_0900_AS_CS = 297;
|
||||||
|
exports.UTF8MB4_HR_0900_AS_CS = 298;
|
||||||
|
exports.UTF8MB4_VI_0900_AS_CS = 300;
|
||||||
|
exports.UTF8MB4_JA_0900_AS_CS = 303;
|
||||||
|
exports.UTF8MB4_JA_0900_AS_CS_KS = 304;
|
||||||
|
exports.UTF8MB4_0900_AS_CI = 305;
|
||||||
|
exports.UTF8MB4_RU_0900_AI_CI = 306;
|
||||||
|
exports.UTF8MB4_RU_0900_AS_CS = 307;
|
||||||
|
exports.UTF8MB4_ZH_0900_AS_CS = 308;
|
||||||
|
exports.UTF8MB4_0900_BIN = 309;
|
||||||
|
|
||||||
|
// short aliases
|
||||||
|
exports.BIG5 = exports.BIG5_CHINESE_CI;
|
||||||
|
exports.DEC8 = exports.DEC8_SWEDISH_CI;
|
||||||
|
exports.CP850 = exports.CP850_GENERAL_CI;
|
||||||
|
exports.HP8 = exports.HP8_ENGLISH_CI;
|
||||||
|
exports.KOI8R = exports.KOI8R_GENERAL_CI;
|
||||||
|
exports.LATIN1 = exports.LATIN1_SWEDISH_CI;
|
||||||
|
exports.LATIN2 = exports.LATIN2_GENERAL_CI;
|
||||||
|
exports.SWE7 = exports.SWE7_SWEDISH_CI;
|
||||||
|
exports.ASCII = exports.ASCII_GENERAL_CI;
|
||||||
|
exports.UJIS = exports.UJIS_JAPANESE_CI;
|
||||||
|
exports.SJIS = exports.SJIS_JAPANESE_CI;
|
||||||
|
exports.HEBREW = exports.HEBREW_GENERAL_CI;
|
||||||
|
exports.TIS620 = exports.TIS620_THAI_CI;
|
||||||
|
exports.EUCKR = exports.EUCKR_KOREAN_CI;
|
||||||
|
exports.KOI8U = exports.KOI8U_GENERAL_CI;
|
||||||
|
exports.GB2312 = exports.GB2312_CHINESE_CI;
|
||||||
|
exports.GREEK = exports.GREEK_GENERAL_CI;
|
||||||
|
exports.CP1250 = exports.CP1250_GENERAL_CI;
|
||||||
|
exports.GBK = exports.GBK_CHINESE_CI;
|
||||||
|
exports.LATIN5 = exports.LATIN5_TURKISH_CI;
|
||||||
|
exports.ARMSCII8 = exports.ARMSCII8_GENERAL_CI;
|
||||||
|
exports.UTF8 = exports.UTF8_GENERAL_CI;
|
||||||
|
exports.UCS2 = exports.UCS2_GENERAL_CI;
|
||||||
|
exports.CP866 = exports.CP866_GENERAL_CI;
|
||||||
|
exports.KEYBCS2 = exports.KEYBCS2_GENERAL_CI;
|
||||||
|
exports.MACCE = exports.MACCE_GENERAL_CI;
|
||||||
|
exports.MACROMAN = exports.MACROMAN_GENERAL_CI;
|
||||||
|
exports.CP852 = exports.CP852_GENERAL_CI;
|
||||||
|
exports.LATIN7 = exports.LATIN7_GENERAL_CI;
|
||||||
|
exports.UTF8MB4 = exports.UTF8MB4_GENERAL_CI;
|
||||||
|
exports.CP1251 = exports.CP1251_GENERAL_CI;
|
||||||
|
exports.UTF16 = exports.UTF16_GENERAL_CI;
|
||||||
|
exports.UTF16LE = exports.UTF16LE_GENERAL_CI;
|
||||||
|
exports.CP1256 = exports.CP1256_GENERAL_CI;
|
||||||
|
exports.CP1257 = exports.CP1257_GENERAL_CI;
|
||||||
|
exports.UTF32 = exports.UTF32_GENERAL_CI;
|
||||||
|
exports.CP932 = exports.CP932_JAPANESE_CI;
|
||||||
|
exports.EUCJPMS = exports.EUCJPMS_JAPANESE_CI;
|
||||||
|
exports.GB18030 = exports.GB18030_CHINESE_CI;
|
||||||
|
exports.GEOSTD8 = exports.GEOSTD8_GENERAL_CI;
|
39
node_modules/mysql2/lib/constants/client.js
generated
vendored
Normal file
39
node_modules/mysql2/lib/constants/client.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// This file was modified by Oracle on September 21, 2021.
|
||||||
|
// New capability for multi-factor authentication based on mandatory session
|
||||||
|
// trackers, that are signaled with an extra single-byte prefix on new
|
||||||
|
// versions of the MySQL server.
|
||||||
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Manually extracted from mysql-5.5.23/include/mysql_com.h
|
||||||
|
exports.LONG_PASSWORD = 0x00000001; /* new more secure passwords */
|
||||||
|
exports.FOUND_ROWS = 0x00000002; /* found instead of affected rows */
|
||||||
|
exports.LONG_FLAG = 0x00000004; /* get all column flags */
|
||||||
|
exports.CONNECT_WITH_DB = 0x00000008; /* one can specify db on connect */
|
||||||
|
exports.NO_SCHEMA = 0x00000010; /* don't allow database.table.column */
|
||||||
|
exports.COMPRESS = 0x00000020; /* can use compression protocol */
|
||||||
|
exports.ODBC = 0x00000040; /* odbc client */
|
||||||
|
exports.LOCAL_FILES = 0x00000080; /* can use LOAD DATA LOCAL */
|
||||||
|
exports.IGNORE_SPACE = 0x00000100; /* ignore spaces before '' */
|
||||||
|
exports.PROTOCOL_41 = 0x00000200; /* new 4.1 protocol */
|
||||||
|
exports.INTERACTIVE = 0x00000400; /* this is an interactive client */
|
||||||
|
exports.SSL = 0x00000800; /* switch to ssl after handshake */
|
||||||
|
exports.IGNORE_SIGPIPE = 0x00001000; /* IGNORE sigpipes */
|
||||||
|
exports.TRANSACTIONS = 0x00002000; /* client knows about transactions */
|
||||||
|
exports.RESERVED = 0x00004000; /* old flag for 4.1 protocol */
|
||||||
|
exports.SECURE_CONNECTION = 0x00008000; /* new 4.1 authentication */
|
||||||
|
exports.MULTI_STATEMENTS = 0x00010000; /* enable/disable multi-stmt support */
|
||||||
|
exports.MULTI_RESULTS = 0x00020000; /* enable/disable multi-results */
|
||||||
|
exports.PS_MULTI_RESULTS = 0x00040000; /* multi-results in ps-protocol */
|
||||||
|
exports.PLUGIN_AUTH = 0x00080000; /* client supports plugin authentication */
|
||||||
|
exports.CONNECT_ATTRS = 0x00100000; /* permits connection attributes */
|
||||||
|
exports.PLUGIN_AUTH_LENENC_CLIENT_DATA = 0x00200000; /* Understands length-encoded integer for auth response data in Protocol::HandshakeResponse41. */
|
||||||
|
exports.CAN_HANDLE_EXPIRED_PASSWORDS = 0x00400000; /* Announces support for expired password extension. */
|
||||||
|
exports.SESSION_TRACK = 0x00800000; /* Can set SERVER_SESSION_STATE_CHANGED in the Status Flags and send session-state change data after a OK packet. */
|
||||||
|
exports.DEPRECATE_EOF = 0x01000000; /* Can send OK after a Text Resultset. */
|
||||||
|
|
||||||
|
exports.SSL_VERIFY_SERVER_CERT = 0x40000000;
|
||||||
|
exports.REMEMBER_OPTIONS = 0x80000000;
|
||||||
|
|
||||||
|
exports.MULTI_FACTOR_AUTHENTICATION = 0x10000000; /* multi-factor authentication */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user