jsql-neo 6.5.0-beta.4 → 6.5.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/jsql +17 -2
- package/index.js +1 -1
- package/lib/star-nag.js +55 -15
- package/native/jsql-neo-native.node +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> **One engine to rule them all** — a Rust-powered embedded database that speaks your language:
|
|
4
4
|
> MySQL, PostgreSQL, MongoDB, Redis, SQL, TypeScript, **and the browser**.
|
|
5
5
|
|
|
6
|
-
> **v6.5.0-beta.
|
|
6
|
+
> **v6.5.0-beta.6** — pre-release build · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
|
|
7
7
|
|
|
8
8
|

|
|
9
9
|

|
package/bin/jsql
CHANGED
|
@@ -8,7 +8,9 @@ const migrate = require('../lib/migrate');
|
|
|
8
8
|
const { nag, setStarred, readConfig } = require('../lib/star-nag');
|
|
9
9
|
|
|
10
10
|
// star 提示:任何异常都不该挡住命令本身
|
|
11
|
-
|
|
11
|
+
// version / --version 只回版本号、star 本身就是干这件事的 —— 这些不提示,其余全部提示
|
|
12
|
+
const NO_NAG_ARGS = new Set(['version', '--version', '-v', 'star']);
|
|
13
|
+
if (!process.env.JSQL_NO_STAR_NAG && !NO_NAG_ARGS.has(process.argv[2])) {
|
|
12
14
|
try { nag(); } catch (e) { /* 提示失败与命令无关 */ }
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -189,7 +191,20 @@ const cli = yaggs({ pkg: require('../package.json') })
|
|
|
189
191
|
const nonceUrl = sn.startOauthCheck(); // 打开浏览器 + 后台轮询写回 ~/.jsqlmr
|
|
190
192
|
if (!process.stdout.isTTY) console.log(' ' + nonceUrl);
|
|
191
193
|
console.log('After you authorize, this config is updated: ' + sn.configPath());
|
|
192
|
-
console.log('
|
|
194
|
+
console.log('Waiting for authorization (up to 3 minutes)…');
|
|
195
|
+
// startOauthCheck 的定时器是 unref 的,命令必须自己前台等,否则接不到结果
|
|
196
|
+
const res = sn.waitForResult(nonceUrl, 180000);
|
|
197
|
+
if (res && res.starred) {
|
|
198
|
+
sn.setStarred(true);
|
|
199
|
+
console.log(`Confirmed: ${res.login} has starred ${res.repo}. Thanks!`);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (res) {
|
|
203
|
+
console.log(`Authorization finished, but ${res.login} has not starred ${res.repo} yet.`);
|
|
204
|
+
console.log(`Star it at https://github.com/${res.repo} then run \`jsql star\` again.`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
console.log('Timed out or the link expired. Run `jsql star` again to retry.');
|
|
193
208
|
})
|
|
194
209
|
.command('bench', 'Insert + query benchmark against a data directory', (sub) => {
|
|
195
210
|
sub.option('n', { type: 'number', description: 'Number of rows (default 10000)' });
|
package/index.js
CHANGED
package/lib/star-nag.js
CHANGED
|
@@ -161,36 +161,37 @@ function checkStarred() {
|
|
|
161
161
|
* @param {boolean} [opts.force] 忽略节流,强制提示一次
|
|
162
162
|
* @returns {boolean} 是否真的打印了
|
|
163
163
|
*/
|
|
164
|
+
/**
|
|
165
|
+
* 在 stdout 上印一行 star 提示。
|
|
166
|
+
*
|
|
167
|
+
* 规则(用户明确要求):
|
|
168
|
+
* 1. **不强制** —— 只印文字,绝不自动弹浏览器。要确认请用户自己跑 `jsql star`。
|
|
169
|
+
* 2. **除 `version` 外的每个命令都印**,没有 30 天节流这类「只提醒一次」的设计。
|
|
170
|
+
* 3. `~/.jsqlmr` 记录是否 star 过 —— `starred: true` 是唯一的闭嘴开关
|
|
171
|
+
* (另外 `JSQL_NO_STAR_NAG=1` 可临时静音)。
|
|
172
|
+
*
|
|
173
|
+
* @returns {boolean} 是否真的印了
|
|
174
|
+
*/
|
|
164
175
|
function nag(opts = {}) {
|
|
165
176
|
const out = opts.out || process.stdout;
|
|
166
177
|
const cfg = readConfig();
|
|
167
178
|
|
|
179
|
+
// 已确认 star 过 → 永久闭嘴。jsqlmr 就是干这个的。
|
|
168
180
|
if (!opts.force && cfg.starred) return false;
|
|
169
181
|
|
|
170
|
-
|
|
171
|
-
if (!opts.force && last && Date.now() - last < NAG_INTERVAL_DAYS * 86400000) {
|
|
172
|
-
// 顺便有机会补记 star 状态(不打印)
|
|
173
|
-
const s = checkStarred();
|
|
174
|
-
if (s) { cfg.starred = true; writeConfig(cfg); }
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// 有 token 就先查,省得对已经 star 的人重复啰嗦
|
|
182
|
+
// 有凭据就先查一下,省得对已经 star 的人反复啰嗦(查不到就当没查,照印)
|
|
179
183
|
const starred = checkStarred();
|
|
180
184
|
if (starred) {
|
|
181
185
|
cfg.starred = true;
|
|
182
186
|
cfg.starredAt = Date.now();
|
|
183
187
|
writeConfig(cfg);
|
|
184
|
-
return false;
|
|
188
|
+
return false;
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
out.write(`\n If JSQL-NEO saved you time, a star helps others find it: ${URL}\n`);
|
|
188
192
|
out.write(` Run \`jsql star\` to confirm and stop seeing this (or set JSQL_NO_STAR_NAG=1 to hide)\n\n`);
|
|
189
|
-
startOauthCheck();
|
|
190
|
-
|
|
191
|
-
cfg.lastNagAt = Date.now();
|
|
192
|
-
writeConfig(cfg);
|
|
193
193
|
|
|
194
|
+
// 只记录「有没有 star」,不再写 lastNagAt —— 没有节流,写它没有意义。
|
|
194
195
|
return true;
|
|
195
196
|
}
|
|
196
197
|
|
|
@@ -203,4 +204,43 @@ function setStarred(v) {
|
|
|
203
204
|
return cfg.starred;
|
|
204
205
|
}
|
|
205
206
|
|
|
206
|
-
|
|
207
|
+
/**
|
|
208
|
+
* 同步阻塞轮询授权结果,直到拿到 done / expired 或超时。
|
|
209
|
+
*
|
|
210
|
+
* `jsql star` 用:startOauthCheck 的定时器是 unref 的(不能拖住别的命令),
|
|
211
|
+
* 所以 star 命令必须自己前台等,否则授权完成后 CLI 早已退出,结果没人接。
|
|
212
|
+
*
|
|
213
|
+
* @param {string} startUrl startOauthCheck 返回的 URL(含 nonce)
|
|
214
|
+
* @param {number} [timeoutMs] 最长等待时间,默认 180 秒
|
|
215
|
+
* @returns {object|null} result 对象(含 login/starred/repo),超时或失败返回 null
|
|
216
|
+
*/
|
|
217
|
+
function waitForResult(startUrl, timeoutMs = 180000) {
|
|
218
|
+
const { execFileSync } = require('child_process');
|
|
219
|
+
// 注意:本模块顶部有 const URL = 'https://github.com/...' 会遮蔽全局 URL 类,
|
|
220
|
+
// 必须显式从 url 模块取,否则 new URL(...) 抛 TypeError
|
|
221
|
+
const { URL: NodeURL } = require('url');
|
|
222
|
+
let nonce = '';
|
|
223
|
+
try {
|
|
224
|
+
nonce = new NodeURL(startUrl).searchParams.get('nonce') || '';
|
|
225
|
+
} catch (e) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
if (!nonce) return null;
|
|
229
|
+
|
|
230
|
+
const deadline = Date.now() + timeoutMs;
|
|
231
|
+
while (Date.now() < deadline) {
|
|
232
|
+
try {
|
|
233
|
+
const out = execFileSync('curl', ['-sS', '-m', '5', AUTH_RESULT + '?nonce=' + nonce],
|
|
234
|
+
{ stdio: ['ignore', 'pipe', 'ignore'], timeout: 8000, encoding: 'utf8' });
|
|
235
|
+
const j = JSON.parse(out);
|
|
236
|
+
if (j && j.state === 'done' && j.result) return j.result;
|
|
237
|
+
if (j && j.state === 'expired') return null;
|
|
238
|
+
} catch (e) {
|
|
239
|
+
// 网络抖动 / 超时 —— 继续等
|
|
240
|
+
}
|
|
241
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 2000);
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
module.exports = { nag, checkStarred, startOauthCheck, waitForResult, readConfig, setStarred, configPath, REPO, URL };
|
|
Binary file
|
package/package.json
CHANGED