jsql-neo 6.6.0 → 6.6.2
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 +21 -1
- package/bin/jsql +14 -0
- package/index.js +1 -1
- package/lib/client.js +4 -0
- package/lib/date-types.js +17 -6
- package/lib/nedb_compat.js +14 -1
- package/lib/network-policy.js +42 -0
- package/lib/plugin.js +10 -6
- package/lib/sql.js +103 -17
- package/lib/star-nag.js +31 -15
- package/lib/table.js +6 -0
- package/lib/updater.js +14 -0
- package/lib/web_ui.js +1 -0
- package/package.json +3 -3
- package/postinstall.js +17 -1
- package/src/cli/plugin.js +13 -0
- package/test/issue-50.test.js +2 -2
- package/test/issue-77-84.test.js +137 -0
- package/test/network-policy.test.js +120 -0
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.6.
|
|
6
|
+
> **v6.6.2** — stable release · [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
|

|
|
@@ -223,6 +223,26 @@ db.xqlIndex('users', 'score', 'range');
|
|
|
223
223
|
|
|
224
224
|
---
|
|
225
225
|
|
|
226
|
+
## Network access
|
|
227
|
+
|
|
228
|
+
The **CLI startup path makes no network requests at all** — queries, scripts and
|
|
229
|
+
`jsql serve` are entirely local. External access is confined to commands you
|
|
230
|
+
invoke explicitly, and every such site carries a `NETWORK:` comment in the
|
|
231
|
+
source stating why it cannot be done locally:
|
|
232
|
+
|
|
233
|
+
| Command / timing | Target | Why it needs the network | How to disable |
|
|
234
|
+
| --- | --- | --- | --- |
|
|
235
|
+
| `jsql star` | `auth.vexify.top` + GitHub | OAuth authorization has to go through the server | `JSQL_OFFLINE=1` |
|
|
236
|
+
| `jsql star --token-check` | `api.github.com` | star status only exists on the GitHub account | `JSQL_OFFLINE=1` |
|
|
237
|
+
| `jsql update` | `registry.npmjs.org` | "is there a newer version" only exists in the registry | `JSQL_OFFLINE=1` |
|
|
238
|
+
| `jsql plugin list\|search\|info\|install` | `registry-beta.vexify.top` | the plugin catalogue only exists remotely | `JSQL_OFFLINE=1` |
|
|
239
|
+
| `npm install` (postinstall) | GitHub releases | the precompiled Rust `.node` is not in the npm tarball | `JSQL_NO_NATIVE_DOWNLOAD=1` or `JSQL_OFFLINE=1` |
|
|
240
|
+
|
|
241
|
+
`JSQL_OFFLINE=1` disables every external request at once; affected commands
|
|
242
|
+
report the reason instead of failing silently. Loopback traffic (the
|
|
243
|
+
`127.0.0.1` links between `jsql serve` and the client / Web UI) is not
|
|
244
|
+
external access and is unaffected.
|
|
245
|
+
|
|
226
246
|
## 📖 Documentation
|
|
227
247
|
|
|
228
248
|
Detailed docs live in `doc/` — click to read.
|
package/bin/jsql
CHANGED
|
@@ -319,9 +319,23 @@ const cli = (yaggs || require('./yaggs-fallback').buildYaggsFallback(_pkg))({
|
|
|
319
319
|
})
|
|
320
320
|
.command('star', 'Confirm whether you starred this repo (opens browser once)', (sub) => {
|
|
321
321
|
sub.option('reset', { type: 'boolean', description: 'Forget the saved star state and re-check' });
|
|
322
|
+
sub.option('token-check', { type: 'boolean', description: 'Check via GitHub API using GITHUB_TOKEN/gh (no browser)' });
|
|
322
323
|
}, async (argv) => {
|
|
323
324
|
const sn = require('../lib/star-nag');
|
|
325
|
+
const { isOffline } = require('../lib/network-policy');
|
|
326
|
+
if (isOffline()) {
|
|
327
|
+
console.log('离线模式(JSQL_OFFLINE=1):无法确认 star。取消该环境变量后重试。');
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
324
330
|
if (argv.reset) sn.setStarred(false);
|
|
331
|
+
// 显式选择的联网路径:用 token 直接查 GitHub API,不开浏览器。
|
|
332
|
+
// 启动路径不会走到这里(nag() 已完全本地化)。
|
|
333
|
+
if (argv['token-check']) {
|
|
334
|
+
const s = sn.checkStarred();
|
|
335
|
+
if (s === true) { sn.setStarred(true); console.log('已确认 star ✓(via GitHub API)'); }
|
|
336
|
+
else console.log('未能确认(无凭据 / 未 star / 网络不通)。去掉 --token-check 可走浏览器授权。');
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
325
339
|
const c = sn.readConfig();
|
|
326
340
|
if (c.starred) {
|
|
327
341
|
console.log(`Already confirmed starred 已确认过: ${sn.configPath()}`);
|
package/index.js
CHANGED
package/lib/client.js
CHANGED
|
@@ -9,6 +9,10 @@ function binPath() {
|
|
|
9
9
|
return path.join(dir, name);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/* LOCAL-ONLY: 这个客户端默认只连 127.0.0.1:3000 的本机 server
|
|
13
|
+
* (下面的 http.get / http.request 都是同机回环,不是外部网络)。
|
|
14
|
+
* 例外:调用方显式传 opts.host 指向别的机器时才会出网 —— 那是用户
|
|
15
|
+
* 主动配置的远程模式,由调用方负责。 */
|
|
12
16
|
class JSQL {
|
|
13
17
|
constructor(opts = {}) {
|
|
14
18
|
this.host = opts.host || '127.0.0.1';
|
package/lib/date-types.js
CHANGED
|
@@ -77,12 +77,20 @@ function toUtcDateString(d) {
|
|
|
77
77
|
return d.getUTCFullYear() + '-' + pad2(d.getUTCMonth() + 1) + '-' + pad2(d.getUTCDate());
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
/** UTC 墙上时间的 'YYYY-MM-DD HH:MM:SS' */
|
|
80
|
+
/** UTC 墙上时间的 'YYYY-MM-DD HH:MM:SS'(整秒) */
|
|
81
81
|
function toUtcDateTimeString(d) {
|
|
82
82
|
return toUtcDateString(d) + ' ' +
|
|
83
83
|
pad2(d.getUTCHours()) + ':' + pad2(d.getUTCMinutes()) + ':' + pad2(d.getUTCSeconds());
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/** 保留亚秒精度(#82):仅当存在非零毫秒时追加 '.sss',整秒输入不变。
|
|
87
|
+
* 用于“字符串里显式携带小数秒”的解析路径;Date 对象/NOW() 走整秒 toUtcDateTimeString。 */
|
|
88
|
+
function toUtcDateTimeStringMs(d) {
|
|
89
|
+
const base = toUtcDateTimeString(d);
|
|
90
|
+
const ms = d.getUTCMilliseconds();
|
|
91
|
+
return ms ? base + '.' + String(ms).padStart(3, '0') : base;
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
/**
|
|
87
95
|
* 把「日期/时间部件 ± 可选时区标记」解析成绝对时刻(毫秒)。
|
|
88
96
|
* 无时区标记 → 按 UTC 墙上时间;带 Z / ±HH:MM → 按标记换算。
|
|
@@ -192,11 +200,14 @@ function validateDateTime(value, fieldName) {
|
|
|
192
200
|
}
|
|
193
201
|
if (typeof value === 'string') {
|
|
194
202
|
// ISO format: 2024-01-15T10:30:00.000Z / +08:00(可能带时区标记)
|
|
195
|
-
|
|
203
|
+
// #82:捕获可选的亚秒 .sss,避免 .500 被静默截断。
|
|
204
|
+
const isoMatch = value.match(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})(?:\.(\d{1,3}))?/);
|
|
196
205
|
if (isoMatch) {
|
|
197
206
|
// P2-35: 验证日期和时间有效性
|
|
198
207
|
const datePart = isoMatch[1];
|
|
199
208
|
const timePart = isoMatch[2];
|
|
209
|
+
const fracPart = isoMatch[3];
|
|
210
|
+
const msPart = fracPart ? parseInt(fracPart.padEnd(3, '0')) : 0;
|
|
200
211
|
const dm = datePart.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
201
212
|
const tm = timePart.match(/^(\d{2}):(\d{2}):(\d{2})$/);
|
|
202
213
|
if (dm && tm) {
|
|
@@ -210,10 +221,10 @@ function validateDateTime(value, fieldName) {
|
|
|
210
221
|
// 二者因此在 UTC 字面量上完全等价(#75 round-trip)。
|
|
211
222
|
const tz = parseIsoTimezone(value.slice(isoMatch[0].length));
|
|
212
223
|
if (tz !== null) {
|
|
213
|
-
const ms = Date.UTC(y, mo - 1, d, h, mi, s) - tz * 60000;
|
|
214
|
-
return
|
|
224
|
+
const ms = Date.UTC(y, mo - 1, d, h, mi, s) + msPart - tz * 60000;
|
|
225
|
+
return toUtcDateTimeStringMs(new Date(ms));
|
|
215
226
|
}
|
|
216
|
-
return datePart + ' ' + timePart;
|
|
227
|
+
return datePart + ' ' + timePart + (msPart ? '.' + String(msPart).padStart(3, '0') : '');
|
|
217
228
|
}
|
|
218
229
|
}
|
|
219
230
|
}
|
|
@@ -237,7 +248,7 @@ function validateDateTime(value, fieldName) {
|
|
|
237
248
|
}
|
|
238
249
|
const ms = parseToUtcMs(value);
|
|
239
250
|
if (ms !== null) {
|
|
240
|
-
return
|
|
251
|
+
return toUtcDateTimeStringMs(new Date(ms));
|
|
241
252
|
}
|
|
242
253
|
// 仅带明确时区标记时允许原生解析兜底
|
|
243
254
|
if (/[Zz]$|[+-]\d{2}:?\d{2}$/.test(value)) {
|
package/lib/nedb_compat.js
CHANGED
|
@@ -110,6 +110,15 @@ function matchFieldValue(value, condition) {
|
|
|
110
110
|
return looseEqual(value, condition);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
// #81:$pull 的“元素是否命中”判定。
|
|
114
|
+
// 数组元素可能是标量('red')或对象({name:'red'});条件 v 可能是
|
|
115
|
+
// 原始值、正则、$op 对象,或普通对象查询(按字段匹配,NeDB 语义)。
|
|
116
|
+
function elementMatch(el, v) {
|
|
117
|
+
const isQueryObject = v && typeof v === 'object' && !Array.isArray(v) &&
|
|
118
|
+
!(v instanceof RegExp) && !Object.keys(v).some(k => k.startsWith('$'));
|
|
119
|
+
return isQueryObject ? match(el, v) : matchFieldValue(el, v);
|
|
120
|
+
}
|
|
121
|
+
|
|
113
122
|
function match(doc, query) {
|
|
114
123
|
if (!query) return true;
|
|
115
124
|
if (typeof query === 'function') return !!query(doc);
|
|
@@ -193,7 +202,11 @@ function applyModifier(doc, update) {
|
|
|
193
202
|
} else if (op === '$pull') {
|
|
194
203
|
for (const [k, v] of Object.entries(payload)) {
|
|
195
204
|
const arr = getPath(doc, k);
|
|
196
|
-
|
|
205
|
+
// #81:$pull 之前把条件包成 { k: v }(硬编码键 "k"),导致永远不匹配、
|
|
206
|
+
// 数组原样保留(no-op)。
|
|
207
|
+
// NeDB 语义:对数组每个元素做 match(element, v) —— 标量元素直接与 v 比较,
|
|
208
|
+
// 对象元素按字段匹配。这里用 elementMatch 统一处理,真正把匹配元素移除。
|
|
209
|
+
if (Array.isArray(arr)) setPath(doc, k, arr.filter(el => !elementMatch(el, v)));
|
|
197
210
|
}
|
|
198
211
|
}
|
|
199
212
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* 统一的网络访问策略 —— 「默认不出网,必须出网的地方写明原因」。
|
|
4
|
+
*
|
|
5
|
+
* 约定:仓库里任何会真正访问**外部网络**的位置,都要在紧邻处写一段
|
|
6
|
+
* `NETWORK:` 注释,四行说清楚:
|
|
7
|
+
*
|
|
8
|
+
* Why: 为什么非联网不可(本地为什么做不到)
|
|
9
|
+
* Trigger: 什么操作才会触发(必须能由用户主动预期)
|
|
10
|
+
* Offline: JSQL_OFFLINE=1 时的行为
|
|
11
|
+
* Scope: 访问的目标主机 / 数据
|
|
12
|
+
*
|
|
13
|
+
* 只连 127.0.0.1 / localhost 的本地回环(各 * _server.js、client.js、
|
|
14
|
+
* web_ui 的同源 fetch)不算外部网络,写 `LOCAL-ONLY:` 一句即可。
|
|
15
|
+
*
|
|
16
|
+
* 环境变量:
|
|
17
|
+
* JSQL_OFFLINE=1|true|yes|on 一键禁用所有外部网络访问。
|
|
18
|
+
* 已有的专用开关(JSQL_NO_NATIVE_DOWNLOAD / JSQL_NATIVE_DOWNLOAD=0 /
|
|
19
|
+
* JSQL_NATIVE_FORCE_REFRESH=0 / JSQL_NO_STAR_NAG=1)继续有效。
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const TRUTHY = /^(1|true|yes|on)$/i;
|
|
23
|
+
|
|
24
|
+
/** 当前进程是否处于离线模式。 */
|
|
25
|
+
function isOffline() {
|
|
26
|
+
return TRUTHY.test(String(process.env.JSQL_OFFLINE || ''));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 构造一个可读的离线错误。带 code,方便调用方区分「用户主动离线」和
|
|
31
|
+
* 「网络真的不通」—— 这两者不该给用户同一句报错。
|
|
32
|
+
*/
|
|
33
|
+
function offlineError(feature, why) {
|
|
34
|
+
const err = new Error(
|
|
35
|
+
`${feature} 需要联网(${why})。当前 JSQL_OFFLINE=1,已跳过;` +
|
|
36
|
+
'取消该环境变量即可恢复。'
|
|
37
|
+
);
|
|
38
|
+
err.code = 'JSQL_OFFLINE';
|
|
39
|
+
return err;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = { isOffline, offlineError, TRUTHY };
|
package/lib/plugin.js
CHANGED
|
@@ -103,12 +103,13 @@ function definePlugin(name, def = {}) {
|
|
|
103
103
|
return new Plugin(name, def).build();
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
/**
|
|
107
|
-
|
|
106
|
+
/** 登记单个钩子;未知钩子名会自动创建,便于插件自定义扩展点。
|
|
107
|
+
* 同时记录登记方的 priority,供 runHooks 按 priority 排序(#84)。 */
|
|
108
|
+
function registerHook(engine, hook, fn, priority = 0) {
|
|
108
109
|
if (typeof fn !== 'function') return engine;
|
|
109
110
|
if (!engine._hooks) engine._hooks = createHookRegistry();
|
|
110
111
|
if (!engine._hooks[hook]) engine._hooks[hook] = [];
|
|
111
|
-
engine._hooks[hook].push(fn);
|
|
112
|
+
engine._hooks[hook].push({ fn, priority: priority || 0 });
|
|
112
113
|
return engine;
|
|
113
114
|
}
|
|
114
115
|
|
|
@@ -117,7 +118,7 @@ function registerHooks(engine, plugin) {
|
|
|
117
118
|
if (!plugin || !plugin.hooks) return engine;
|
|
118
119
|
for (const [hook, val] of Object.entries(plugin.hooks)) {
|
|
119
120
|
const fns = Array.isArray(val) ? val : [val];
|
|
120
|
-
for (const fn of fns) registerHook(engine, hook, fn);
|
|
121
|
+
for (const fn of fns) registerHook(engine, hook, fn, plugin.priority || 0);
|
|
121
122
|
}
|
|
122
123
|
return engine;
|
|
123
124
|
}
|
|
@@ -253,8 +254,11 @@ function runHooks(engine, hookName, args) {
|
|
|
253
254
|
|
|
254
255
|
return (async () => {
|
|
255
256
|
try {
|
|
256
|
-
|
|
257
|
-
|
|
257
|
+
// #84:按插件 priority 降序执行(数值大的先跑)。此前只对 engine._plugins
|
|
258
|
+
// 排序,钩子数组本身保持注册顺序,导致 priority 被完全忽略。
|
|
259
|
+
const ordered = hooks.slice().sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
|
260
|
+
for (const entry of ordered) {
|
|
261
|
+
const result = await entry.fn(...args);
|
|
258
262
|
if (result === false) return false;
|
|
259
263
|
}
|
|
260
264
|
return true;
|
package/lib/sql.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
const { createError } = require('./errors');
|
|
3
3
|
// #75:WHERE 里 DATETIME 字面量要与 INSERT 走同一套规范化规则
|
|
4
4
|
const { validateDateType } = require('./date-types');
|
|
5
|
+
// #78:UNION/INTERSECT/EXCEPT 去重键对 BigInt 安全(JSON.stringify 遇到 BigInt 抛错)
|
|
6
|
+
const bigintJson = require('./bigint_json');
|
|
5
7
|
|
|
6
8
|
const DANGEROUS_SQL = [
|
|
7
9
|
{ re: /^INTO$/, next: /^(OUTFILE|DUMPFILE)$/, name: 'INTO OUTFILE/DUMPFILE' },
|
|
@@ -4979,7 +4981,8 @@ function extractEqualPushdown(expr, schema) {
|
|
|
4979
4981
|
function dedupeRows(rows) {
|
|
4980
4982
|
const seen = new Set();
|
|
4981
4983
|
return rows.filter(r => {
|
|
4982
|
-
|
|
4984
|
+
// #78:去重键用 BigInt 安全序列化,否则 UNION/INTERSECT/EXCEPT 遇 bigint 列抛错
|
|
4985
|
+
const k = bigintJson.stringify(r);
|
|
4983
4986
|
if (seen.has(k)) return false;
|
|
4984
4987
|
seen.add(k);
|
|
4985
4988
|
return true;
|
|
@@ -5006,7 +5009,10 @@ function assertSetOpColumnCount(left, right) {
|
|
|
5006
5009
|
// 避免把 true 与字符串 'true' 的比较悄悄改成 1 与 'true' 的比较。
|
|
5007
5010
|
function normalizeCmpValue(a, other) {
|
|
5008
5011
|
if (typeof a !== 'boolean') return a;
|
|
5009
|
-
|
|
5012
|
+
// #83:MySQL BOOL/TINYINT(1) 语义下,布尔与数值字符串 '1'/'0' 直接可比。
|
|
5013
|
+
// 此前只认 number/boolean,导致 WHERE b = '1'(b 为 BOOLEAN)恒为空。
|
|
5014
|
+
const otherIsNumeric = typeof other === 'number' || typeof other === 'boolean' ||
|
|
5015
|
+
(typeof other === 'string' && /^[0-9]+$/.test(other.trim()));
|
|
5010
5016
|
return otherIsNumeric ? (a ? 1 : 0) : a;
|
|
5011
5017
|
}
|
|
5012
5018
|
|
|
@@ -5025,6 +5031,41 @@ function mysqlNumeric(v) {
|
|
|
5025
5031
|
return NaN;
|
|
5026
5032
|
}
|
|
5027
5033
|
|
|
5034
|
+
// #77:BIGINT 列比较不能用 String(...) 字典序("50" > "1000" 为真,但 50 < 1000)。
|
|
5035
|
+
// 这里提供 bigint/number 混合的精确数值相等与三路比较。
|
|
5036
|
+
// 仅当两个操作数都是整数可无损转换时才用 BigInt 精确比较;
|
|
5037
|
+
// 遇到小数(BigInt 无法表示)则回退到 Number 比较。
|
|
5038
|
+
function numEq(a, b) {
|
|
5039
|
+
if (typeof a === 'bigint' && typeof b === 'bigint') return a === b;
|
|
5040
|
+
if (typeof a === 'bigint') {
|
|
5041
|
+
if (typeof b !== 'number' || !Number.isInteger(b)) return false;
|
|
5042
|
+
return a === BigInt(b);
|
|
5043
|
+
}
|
|
5044
|
+
if (typeof b === 'bigint') {
|
|
5045
|
+
if (typeof a !== 'number' || !Number.isInteger(a)) return false;
|
|
5046
|
+
return BigInt(a) === b;
|
|
5047
|
+
}
|
|
5048
|
+
return a === b;
|
|
5049
|
+
}
|
|
5050
|
+
function numCmp(a, b) {
|
|
5051
|
+
if (typeof a === 'bigint' && typeof b === 'bigint') return a < b ? -1 : a > b ? 1 : 0;
|
|
5052
|
+
if (typeof a === 'bigint') {
|
|
5053
|
+
if (typeof b === 'number' && !Number.isInteger(b)) {
|
|
5054
|
+
const x = Number(a); return x < b ? -1 : x > b ? 1 : 0;
|
|
5055
|
+
}
|
|
5056
|
+
const bb = BigInt(b);
|
|
5057
|
+
return a < bb ? -1 : a > bb ? 1 : 0;
|
|
5058
|
+
}
|
|
5059
|
+
if (typeof b === 'bigint') {
|
|
5060
|
+
if (typeof a === 'number' && !Number.isInteger(a)) {
|
|
5061
|
+
const y = Number(b); return a < y ? -1 : a > y ? 1 : 0;
|
|
5062
|
+
}
|
|
5063
|
+
const aa = BigInt(a);
|
|
5064
|
+
return aa < b ? -1 : aa > b ? 1 : 0;
|
|
5065
|
+
}
|
|
5066
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
5067
|
+
}
|
|
5068
|
+
|
|
5028
5069
|
/** 严格数值解析:只有真正能解析成有限数值时才返回 number,否则 null。
|
|
5029
5070
|
* 用来判断字符串边界是否“看起来像数字”('9' / '0.01' / ' 100 ' 是,'abc' 不是)。
|
|
5030
5071
|
* 与 mysqlNumeric 的区别:非数字字符串返回 null 而不是 0 —— 判断“要不要按数值比较”
|
|
@@ -5084,9 +5125,29 @@ function sqlXor(a, b) {
|
|
|
5084
5125
|
function evaluateExpr(expr, row, ctx) {
|
|
5085
5126
|
if (expr === null || expr === undefined) return false;
|
|
5086
5127
|
switch (expr.type) {
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5128
|
+
// #80:AND/OR/XOR 必须遵循 SQL 三值逻辑,UNKNOWN(null) 要传播,
|
|
5129
|
+
// 不能把 Boolean(null) 塌缩成 false(否则 TRUE XOR UNKNOWN 被误判为真)。
|
|
5130
|
+
// 这里复用 sqlTruthy(返回 true/false/null)与 3VL 真值表,结果统一为 true/false/null。
|
|
5131
|
+
case 'and': {
|
|
5132
|
+
const a = sqlTruthy(evaluateExpr(expr.left, row, ctx));
|
|
5133
|
+
const b = sqlTruthy(evaluateExpr(expr.right, row, ctx));
|
|
5134
|
+
if (a === false || b === false) return false;
|
|
5135
|
+
if (a === null || b === null) return null;
|
|
5136
|
+
return true;
|
|
5137
|
+
}
|
|
5138
|
+
case 'or': {
|
|
5139
|
+
const a = sqlTruthy(evaluateExpr(expr.left, row, ctx));
|
|
5140
|
+
const b = sqlTruthy(evaluateExpr(expr.right, row, ctx));
|
|
5141
|
+
if (a === true || b === true) return true;
|
|
5142
|
+
if (a === null || b === null) return null;
|
|
5143
|
+
return false;
|
|
5144
|
+
}
|
|
5145
|
+
case 'xor': {
|
|
5146
|
+
const a = sqlTruthy(evaluateExpr(expr.left, row, ctx));
|
|
5147
|
+
const b = sqlTruthy(evaluateExpr(expr.right, row, ctx));
|
|
5148
|
+
if (a === null || b === null) return null;
|
|
5149
|
+
return a !== b;
|
|
5150
|
+
}
|
|
5090
5151
|
case 'not': {
|
|
5091
5152
|
// 三值逻辑:NOT UNKNOWN = UNKNOWN(返回 null,在 WHERE/ON/HAVING 中视为不选中)
|
|
5092
5153
|
// 必须用 resolveOperand 取值:evaluateExpr 只认布尔类节点,
|
|
@@ -5116,20 +5177,45 @@ function evaluateExpr(expr, row, ctx) {
|
|
|
5116
5177
|
// 覆盖 0 = '' → 0 = 0 → 1、'a' = 0 → 0 = 0 → 1、'5' = 5 → 5 = 5 → 1(#26)。
|
|
5117
5178
|
// 此前只对「数字 vs 纯数字字符串」生效,'' / 'a' 这类非纯数字字符串
|
|
5118
5179
|
// 会退化成字符串比较而错判为不等。
|
|
5119
|
-
const isNum = (v) => typeof v === 'number';
|
|
5180
|
+
const isNum = (v) => typeof v === 'number' || typeof v === 'bigint';
|
|
5120
5181
|
// MySQL 类型强转(#26):数字 vs 字符串统一走全局 mysqlNum
|
|
5121
5182
|
// (按数值前缀解析,非数字/空串视为 0,对齐 MySQL 宽松转换)。
|
|
5122
5183
|
// 覆盖 '5' = 5、0 = ''、'a' = 0、'09' = 9 等,避免退化成字典序比较。
|
|
5184
|
+
// #77:大整数与纯整数字符串按 BigInt 精确比较,防止丢精度。
|
|
5123
5185
|
const isStr = (v) => typeof v === 'string';
|
|
5124
5186
|
const numVsStr = (isNum(nl) && isStr(nr)) || (isStr(nl) && isNum(nr));
|
|
5125
5187
|
if (numVsStr) {
|
|
5126
|
-
const
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5188
|
+
const toNum = (v) => {
|
|
5189
|
+
if (typeof v === 'bigint') return v;
|
|
5190
|
+
if (typeof v === 'string' && /^-?\d+$/.test(v.trim())) { try { return BigInt(v.trim()); } catch (_) {} }
|
|
5191
|
+
return mysqlNum(v);
|
|
5192
|
+
};
|
|
5193
|
+
const an = toNum(nl), bn = toNum(nr);
|
|
5194
|
+
if (expr.op === '=') return numEq(an, bn);
|
|
5195
|
+
if (expr.op === '!=' || expr.op === '<>') return !numEq(an, bn);
|
|
5196
|
+
const nc = numCmp(an, bn);
|
|
5197
|
+
switch (expr.op) {
|
|
5198
|
+
case '<': return nc < 0;
|
|
5199
|
+
case '<=': return nc <= 0;
|
|
5200
|
+
case '>': return nc > 0;
|
|
5201
|
+
case '>=': return nc >= 0;
|
|
5202
|
+
default: return nc === 0;
|
|
5203
|
+
}
|
|
5204
|
+
}
|
|
5205
|
+
// #77:BIGINT 列 vs 数值(bigint 或 number)必须走数值比较,不能退化成字典序
|
|
5206
|
+
if (isNum(nl) && isNum(nr)) {
|
|
5207
|
+
if (expr.op === '=') return numEq(nl, nr);
|
|
5208
|
+
if (expr.op === '!=' || expr.op === '<>') return !numEq(nl, nr);
|
|
5209
|
+
const nc = numCmp(nl, nr);
|
|
5210
|
+
switch (expr.op) {
|
|
5211
|
+
case '<': return nc < 0;
|
|
5212
|
+
case '<=': return nc <= 0;
|
|
5213
|
+
case '>': return nc > 0;
|
|
5214
|
+
case '>=': return nc >= 0;
|
|
5215
|
+
default: return nc === 0;
|
|
5216
|
+
}
|
|
5130
5217
|
}
|
|
5131
5218
|
if (expr.op === '=') return ciEq(nl, nr, cs);
|
|
5132
|
-
if (typeof nl === 'number' && typeof nr === 'number') { const fn = OPERATORS[expr.op]; return fn(nl, nr); }
|
|
5133
5219
|
const c = ciCompare(nl, nr, cs);
|
|
5134
5220
|
switch (expr.op) {
|
|
5135
5221
|
case '!=': case '<>': return c !== 0;
|
|
@@ -7710,8 +7796,8 @@ class SQLExecutor {
|
|
|
7710
7796
|
});
|
|
7711
7797
|
}
|
|
7712
7798
|
if (!isAll) {
|
|
7713
|
-
const seen = new Set(accumulated.map(r =>
|
|
7714
|
-
next = next.filter(r => !seen.has(
|
|
7799
|
+
const seen = new Set(accumulated.map(r => bigintJson.stringify(r)));
|
|
7800
|
+
next = next.filter(r => !seen.has(bigintJson.stringify(r)));
|
|
7715
7801
|
}
|
|
7716
7802
|
if (next.length === 0) break;
|
|
7717
7803
|
// 超过行数上限说明递归条件写错(恒真),提前收手而不是撑爆内存
|
|
@@ -8058,8 +8144,8 @@ class SQLExecutor {
|
|
|
8058
8144
|
const left = await this.executeSelect(leftStatement);
|
|
8059
8145
|
const right = await this.executeSelect(statement.intersect.select);
|
|
8060
8146
|
assertSetOpColumnCount(left, right);
|
|
8061
|
-
const seen = new Set(right.rows.map(r =>
|
|
8062
|
-
let out = left.rows.filter(r => seen.has(
|
|
8147
|
+
const seen = new Set(right.rows.map(r => bigintJson.stringify(r)));
|
|
8148
|
+
let out = left.rows.filter(r => seen.has(bigintJson.stringify(r)));
|
|
8063
8149
|
if (!statement.intersect.all) out = dedupeRows(out);
|
|
8064
8150
|
out = this._finalizeSetOp(out, left.columns, statement);
|
|
8065
8151
|
return { ok: true, type: 'select', columns: left.columns, rows: out, raw: out };
|
|
@@ -8072,8 +8158,8 @@ class SQLExecutor {
|
|
|
8072
8158
|
const left = await this.executeSelect(leftStatement);
|
|
8073
8159
|
const right = await this.executeSelect(statement.except.select);
|
|
8074
8160
|
assertSetOpColumnCount(left, right);
|
|
8075
|
-
const seen = new Set(right.rows.map(r =>
|
|
8076
|
-
let out = left.rows.filter(r => !seen.has(
|
|
8161
|
+
const seen = new Set(right.rows.map(r => bigintJson.stringify(r)));
|
|
8162
|
+
let out = left.rows.filter(r => !seen.has(bigintJson.stringify(r)));
|
|
8077
8163
|
if (!statement.except.all) out = dedupeRows(out);
|
|
8078
8164
|
out = this._finalizeSetOp(out, left.columns, statement);
|
|
8079
8165
|
return { ok: true, type: 'select', columns: left.columns, rows: out, raw: out };
|
package/lib/star-nag.js
CHANGED
|
@@ -3,23 +3,25 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* CLI 启动时的 star 提示。
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* 行为(启动路径 **零网络访问**):
|
|
7
7
|
* 1. 已确认 star 过 → 什么都不说
|
|
8
|
-
* 2.
|
|
9
|
-
* 3. 否则打印一行提示,并在配置里记下时间
|
|
8
|
+
* 2. 否则打印一行提示,指向 `jsql star`
|
|
10
9
|
*
|
|
11
|
-
* star
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* 是否 star 只以本地 ~/.jsqlmr 为准。此前这里会同步 curl
|
|
11
|
+
* api.github.com(仅为少印一行提示,却让每条 jsql 命令都可能偷偷出网
|
|
12
|
+
* 并阻塞最多 ~9.5 秒),现已移除。需要联网确认时由用户显式跑
|
|
13
|
+
* `jsql star`(OAuth)或 `jsql star --token-check`(GitHub API)。
|
|
14
14
|
*
|
|
15
15
|
* 配置文件:~/.jsqlmr(JSON)。可用 JSQL_MR_PATH 覆盖。
|
|
16
|
-
*
|
|
17
16
|
* 全程不影响命令本身:任何异常都吞掉,绝不因为提示语让 CLI 起不来。
|
|
17
|
+
*
|
|
18
|
+
* 外部网络访问只存在于显式命令路径,见各处 NETWORK: 标注。
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
21
|
const fs = require('fs');
|
|
21
22
|
const os = require('os');
|
|
22
23
|
const path = require('path');
|
|
24
|
+
const { isOffline, offlineError } = require('./network-policy');
|
|
23
25
|
|
|
24
26
|
const REPO = 'vexify-org/JSQL-neo';
|
|
25
27
|
const URL = `https://github.com/${REPO}`;
|
|
@@ -54,7 +56,14 @@ function parseAuthResult(j) {
|
|
|
54
56
|
return { status: st, error: r.error || (st === 'denied' ? 'authorization denied' : 'authorization failed') };
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
/* NETWORK: OAuth 授权(star 确认)
|
|
60
|
+
* Why: 需要 GitHub 登录态与服务端换 token,本地无法完成。
|
|
61
|
+
* Trigger: 仅 `jsql star` 显式执行;启动路径不会走到这里。
|
|
62
|
+
* Offline: JSQL_OFFLINE=1 → 抛 JSQL_OFFLINE 错误,不开浏览器、不轮询。
|
|
63
|
+
* Scope: https://auth.vexify.top/start|result + GitHub 授权页。
|
|
64
|
+
*/
|
|
57
65
|
function startOauthCheck() {
|
|
66
|
+
if (isOffline()) throw offlineError('jsql star', 'OAuth 授权需要访问 GitHub');
|
|
58
67
|
const crypto = require('crypto');
|
|
59
68
|
const nonce = crypto.randomBytes(24).toString('base64url');
|
|
60
69
|
const url = AUTH_START + '?nonce=' + nonce;
|
|
@@ -150,7 +159,15 @@ function findToken() {
|
|
|
150
159
|
*
|
|
151
160
|
* @returns {boolean|null} true=star 过 false=没 star null=无法确认
|
|
152
161
|
*/
|
|
162
|
+
/* NETWORK: GitHub star 状态查询
|
|
163
|
+
* Why: star 状态只存在于 GitHub 账号侧,本地无法判定。
|
|
164
|
+
* Trigger: 仅显式调用(jsql star --token-check / 外部脚本);
|
|
165
|
+
* 已从 CLI 启动路径移除,nag() 不再调用它。
|
|
166
|
+
* Offline: JSQL_OFFLINE=1 → 返回 null(无法确认),不发起任何请求。
|
|
167
|
+
* Scope: https://api.github.com/user/starred/<repo>,带 Bearer token。
|
|
168
|
+
*/
|
|
153
169
|
function checkStarred() {
|
|
170
|
+
if (isOffline()) return null;
|
|
154
171
|
const token = findToken();
|
|
155
172
|
if (!token) return null; // 没有可用凭据 → 无法确认
|
|
156
173
|
// 用同步 API:CLI 启动阶段还没有 event loop 可用
|
|
@@ -199,14 +216,10 @@ function nag(opts = {}) {
|
|
|
199
216
|
// 已确认 star 过 → 永久闭嘴。jsqlmr 就是干这个的。
|
|
200
217
|
if (!opts.force && cfg.starred) return false;
|
|
201
218
|
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
cfg.starredAt = Date.now();
|
|
207
|
-
writeConfig(cfg);
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
219
|
+
// LOCAL-ONLY: 启动路径绝不联网,只按上面的本地配置判定。
|
|
220
|
+
// 不调用 checkStarred()(同步 curl api.github.com,最多 ~9.5s)——
|
|
221
|
+
// 为了少印一行提示而让每条命令偷偷出网,代价不对等。
|
|
222
|
+
// 用户需要确认时显式跑 `jsql star`。
|
|
210
223
|
|
|
211
224
|
out.write(`\n If JSQL-NEO saved you time, a star helps others find it: ${URL}\n`);
|
|
212
225
|
out.write(` 如果帮到了你,点个 star;运行 \`jsql star\` 确认 · JSQL_NO_STAR_NAG=1 关闭提示\n\n`);
|
|
@@ -249,7 +262,10 @@ function setStarred(v) {
|
|
|
249
262
|
* parseAuthResult 一律判为未完成,继续轮询直到超时,而不是打印一段
|
|
250
263
|
* login/repo 全为 undefined 的假失败信息。
|
|
251
264
|
*/
|
|
265
|
+
/* NETWORK: OAuth 结果轮询(同 startOauthCheck 的 NETWORK 标注);
|
|
266
|
+
* 仅由 `jsql star` 前台等待时调用,离线时直接返回 null。 */
|
|
252
267
|
function waitForResult(startUrl, timeoutMs = 180000) {
|
|
268
|
+
if (isOffline()) return null;
|
|
253
269
|
const { execFileSync } = require('child_process');
|
|
254
270
|
// 注意:本模块顶部有 const URL = 'https://github.com/...' 会遮蔽全局 URL 类,
|
|
255
271
|
// 必须显式从 url 模块取,否则 new URL(...) 抛 TypeError
|
package/lib/table.js
CHANGED
|
@@ -729,6 +729,12 @@ class Table {
|
|
|
729
729
|
if (rowIndex === undefined) return 0;
|
|
730
730
|
const row = this._rows[rowIndex];
|
|
731
731
|
if (!row || row._deleted) return 0;
|
|
732
|
+
// #79:按 id 删除也要触发 beforeRemove(与 remove() 一致),返回 false 则中止。
|
|
733
|
+
// 此前 removeById 只触发 afterRemove,beforeRemove 钩子静默失效。
|
|
734
|
+
const removeQuery = { [this._primaryKey]: id };
|
|
735
|
+
for (const hook of this._hooks.beforeRemove) {
|
|
736
|
+
if (hook(removeQuery) === false) return 0;
|
|
737
|
+
}
|
|
732
738
|
this._cascadeForeignKeys(row);
|
|
733
739
|
this._removeFromIndexes(rowIndex, row);
|
|
734
740
|
const lastIdx = this._rows.length - 1;
|
package/lib/updater.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
const path = require('path');
|
|
16
16
|
const https = require('https');
|
|
17
17
|
const { execFileSync, spawnSync } = require('child_process');
|
|
18
|
+
const { isOffline } = require('./network-policy');
|
|
18
19
|
|
|
19
20
|
const PKG_NAME = 'jsql-neo';
|
|
20
21
|
const REGISTRY_LATEST = `https://registry.npmjs.org/${PKG_NAME}/latest`;
|
|
@@ -67,6 +68,12 @@ function isNewer(latest, current) {
|
|
|
67
68
|
|
|
68
69
|
// ─── 网络 ───────────────────────────────────────────────────
|
|
69
70
|
|
|
71
|
+
/* NETWORK: 查询 npm registry 上的最新版本号
|
|
72
|
+
* Why: 「有没有新版本」只存在于 registry,本地包里没有这个信息。
|
|
73
|
+
* Trigger: 仅 `jsql update` / `jsql update --check` 显式调用。
|
|
74
|
+
* Offline: JSQL_OFFLINE=1 → runUpdate 直接返回离线结果,不发请求。
|
|
75
|
+
* Scope: https://registry.npmjs.org/jsql-neo/latest(只读,无认证)。
|
|
76
|
+
*/
|
|
70
77
|
function httpGetText(url, redirects = 0) {
|
|
71
78
|
return new Promise((resolve, reject) => {
|
|
72
79
|
if (redirects > 5) {
|
|
@@ -227,6 +234,13 @@ function installCommand(version) {
|
|
|
227
234
|
*/
|
|
228
235
|
async function runUpdate(opts = {}) {
|
|
229
236
|
const current = currentVersion();
|
|
237
|
+
if (isOffline()) {
|
|
238
|
+
return {
|
|
239
|
+
ok: false, current, latest: null,
|
|
240
|
+
error: '离线模式(JSQL_OFFLINE=1):jsql update 需要访问 npm registry',
|
|
241
|
+
hints: ['取消 JSQL_OFFLINE 后重试;或手动执行 npm install -g jsql-neo@latest'],
|
|
242
|
+
};
|
|
243
|
+
}
|
|
230
244
|
let latestInfo;
|
|
231
245
|
try {
|
|
232
246
|
latestInfo = await fetchLatestVersion({ fetchImpl: opts.fetchImpl, npmView: opts.npmView });
|
package/lib/web_ui.js
CHANGED
|
@@ -68,6 +68,7 @@ tr:nth-child(even) td { background: #0d1117; }
|
|
|
68
68
|
</div>
|
|
69
69
|
<script>
|
|
70
70
|
let dbs = [], cur = null;
|
|
71
|
+
// LOCAL-ONLY: 浏览器同源请求(/api/*),不访问任何外部网络。
|
|
71
72
|
const q = async (u, o) => { const r = await fetch(u, o); return r.json(); };
|
|
72
73
|
function esc(s) { return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); }
|
|
73
74
|
async function load() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsql-neo",
|
|
3
|
-
"version": "6.6.
|
|
3
|
+
"version": "6.6.2",
|
|
4
4
|
"description": "JSQL-NEO — Rust-powered embedded database with WASM, REST API, B-Tree indexes, WAL, crash recovery",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"scripts": {
|
|
51
51
|
"postinstall": "node postinstall.js",
|
|
52
52
|
"build:native": "node scripts/build-native.js",
|
|
53
|
-
"test": "node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/native.test.js && node test/json-functions.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/query-opt.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/dml-constraints.test.js && node test/star-nag.test.js && node test/plugin-xql.test.js && node test/bug-regression-2.test.js && node test/issue-34-35-36.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-73-76.test.js",
|
|
53
|
+
"test": "node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/native.test.js && node test/json-functions.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/query-opt.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/dml-constraints.test.js && node test/star-nag.test.js && node test/plugin-xql.test.js && node test/bug-regression-2.test.js && node test/issue-34-35-36.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-73-76.test.js && node test/issue-77-84.test.js",
|
|
54
54
|
"test:parser": "node test/sql-parser.test.js",
|
|
55
55
|
"test:btree": "node test/btree.test.js",
|
|
56
56
|
"test:native": "node test/native.test.js",
|
|
57
57
|
"test:regress": "node test/regress-5.1.0.js",
|
|
58
|
-
"test:all": "node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/native.test.js && node test/native-multi-instance.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/wasm.test.js && node test/coverage.js && node test/regress-5.1.0.js && node test/join.test.js && node test/btree.test.js && node test/dml-constraints.test.js && node test/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.test.js && node test/issue-34-35-36.test.js && node test/sql-semantics.test.js && node test/extra-coverage.test.js && node test/filter-compile.test.js && node test/recursive-cte.test.js && node test/index-ddl.test.js && node test/mongo-group.test.js && node test/multiprotocol.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js",
|
|
58
|
+
"test:all": "node test/smoke.js && node test/result-raw.test.js && node test/native-install.test.js && node test/native-cli.test.js && node test/finalize-bigint.test.js && node test/sql-parser.test.js && node test/readme-audit.test.js && node test/native.test.js && node test/native-multi-instance.test.js && node test/wal-recovery.test.js && node test/mysql-compat-hijack.test.js && node test/wasm.test.js && node test/coverage.js && node test/regress-5.1.0.js && node test/join.test.js && node test/btree.test.js && node test/dml-constraints.test.js && node test/savepoint.test.js && node test/alter-table.test.js && node test/null-semantics.test.js && node test/identifier-keywords.test.js && node test/issue-34-35-36.test.js && node test/sql-semantics.test.js && node test/extra-coverage.test.js && node test/filter-compile.test.js && node test/recursive-cte.test.js && node test/index-ddl.test.js && node test/mongo-group.test.js && node test/multiprotocol.test.js && node test/issue-g4.test.js && node test/issue-38.test.js && node test/issue-39.test.js && node test/issue-40.test.js && node test/issue-44.test.js && node test/issue-45.test.js && node test/issue-46.test.js && node test/issue-47.test.js && node test/issue-48.test.js && node test/issue-50.test.js && node test/issue-51.test.js && node test/issue-52.test.js && node test/issue-53.test.js && node test/issue-54.test.js && node test/issue-55.test.js && node test/issue-56.test.js && node test/issue-57.test.js && node test/issue-58.test.js && node test/issue-59.test.js && node test/issue-60.test.js && node test/issue-63-68.test.js && node test/network-policy.test.js && node test/issue-69-70.test.js && node test/issue-71-72.test.js && node test/issue-77-84.test.js",
|
|
59
59
|
"test:coverage": "c8 --all --include='lib/**' --exclude='lib/web_ui.js' --reporter=text --reporter=lcov node test/coverage.js",
|
|
60
60
|
"test:orms": "node examples/orms/run-all.js",
|
|
61
61
|
"test:dml": "node test/dml-constraints.test.js",
|
package/postinstall.js
CHANGED
|
@@ -5,10 +5,20 @@ const path = require('path');
|
|
|
5
5
|
const http = require('http');
|
|
6
6
|
const https = require('https');
|
|
7
7
|
const { detectLibc, nativeTargetSuffix, nativeNapiVersion, supportsNativeNapi, MIN_NAPI_VERSION } = require('./lib/native_target');
|
|
8
|
+
const { isOffline } = require('./lib/network-policy');
|
|
8
9
|
|
|
9
10
|
const ROOT = __dirname;
|
|
10
11
|
const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
|
|
11
12
|
|
|
13
|
+
/* NETWORK: 安装期拉取预编译的 native .node 二进制
|
|
14
|
+
* Why: Rust 编译产物不在 npm tarball 里;不下载就只能本地 cargo 编译
|
|
15
|
+
* (要求用户装 Rust toolchain),或直接降级到 WASM/JS 引擎。
|
|
16
|
+
* Trigger: 仅 `npm install` 触发的 postinstall,或手动 `node postinstall.js`。
|
|
17
|
+
* 运行时 / CLI 启动绝不会走到这里。
|
|
18
|
+
* Offline: JSQL_OFFLINE=1 或 JSQL_NO_NATIVE_DOWNLOAD=1 → 完全跳过下载;
|
|
19
|
+
* 有本地 .node 就用,没有则走源码编译 / WASM 降级。
|
|
20
|
+
* Scope: GitHub releases 的固定 tag 资源 + SHA256SUMS(强制校验)。
|
|
21
|
+
*/
|
|
12
22
|
// Server CLI binary (bin/jsql-neo-server)
|
|
13
23
|
const BIN_NAME = process.platform === 'win32' ? 'jsql-neo-server.exe' : 'jsql-neo-server';
|
|
14
24
|
const BP = path.join(ROOT, 'bin', BIN_NAME);
|
|
@@ -53,7 +63,8 @@ const GHPROXY_TOKEN = process.env.JSQL_GHPROXY_TOKEN || '';
|
|
|
53
63
|
//
|
|
54
64
|
// 供应链安全(issue #25):不内置任何加速站/token,代理仍需显式 JSQL_GHPROXY,
|
|
55
65
|
// 且下载必须通过 SHA256SUMS 校验(除非用户显式 JSQL_ALLOW_UNVERIFIED_NATIVE=1)。
|
|
56
|
-
const DOWNLOAD_DISABLED =
|
|
66
|
+
const DOWNLOAD_DISABLED = isOffline()
|
|
67
|
+
|| process.env.JSQL_NO_NATIVE_DOWNLOAD === '1'
|
|
57
68
|
|| process.env.JSQL_NATIVE_DOWNLOAD === '0'
|
|
58
69
|
|| process.env.JSQL_AUTO_DOWNLOAD_NATIVE === '0';
|
|
59
70
|
const FORCE_REFRESH = process.env.JSQL_NATIVE_FORCE_REFRESH !== '0';
|
|
@@ -101,7 +112,12 @@ function sameOrigin(a, b) {
|
|
|
101
112
|
* 解析 JSQL_NATIVE_TAG=latest:跟随 GitHub `/releases/latest` 的 302 跳转,
|
|
102
113
|
* 从 Location 里取出真实 tag(vX.Y.Z)。失败返回 null —— 调用方回退到当前版本 tag。
|
|
103
114
|
*/
|
|
115
|
+
/* NETWORK: 解析 JSQL_NATIVE_TAG=latest(GET GitHub /releases/latest 的 302)
|
|
116
|
+
* Why: "latest" 指向哪个 tag 只有远端知道。
|
|
117
|
+
* Trigger: 仅用户显式设置 JSQL_NATIVE_TAG=latest 时;默认用 v<pkg.version> 不发请求。
|
|
118
|
+
* Offline: JSQL_OFFLINE=1 → 返回 null,调用方回退到当前版本 tag。 */
|
|
104
119
|
function resolveLatestTag() {
|
|
120
|
+
if (isOffline()) return Promise.resolve(null);
|
|
105
121
|
return new Promise((resolve) => {
|
|
106
122
|
const url = `https://github.com/${REPO}/releases/latest`;
|
|
107
123
|
let settled = false;
|
package/src/cli/plugin.js
CHANGED
|
@@ -12,6 +12,7 @@ const fs = require('fs');
|
|
|
12
12
|
const os = require('os');
|
|
13
13
|
const path = require('path');
|
|
14
14
|
const { execFileSync } = require('child_process');
|
|
15
|
+
const { isOffline, offlineError } = require('../../lib/network-policy');
|
|
15
16
|
|
|
16
17
|
const REGISTRY_BASE = 'https://registry-beta.vexify.top';
|
|
17
18
|
const PLUGIN_DIR = path.join(os.homedir(), '.jsql', 'plugins');
|
|
@@ -94,8 +95,15 @@ function extractJson(text) {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
/* NETWORK: 插件 registry 的元数据查询(plugins / search)
|
|
99
|
+
* Why: 可安装插件的目录只在远端,本地只有「已安装」列表。
|
|
100
|
+
* Trigger: 仅 `jsql plugin list|search|info` 显式调用。
|
|
101
|
+
* Offline: JSQL_OFFLINE=1 → 抛 JSQL_OFFLINE 错误,不发起 fetch。
|
|
102
|
+
* Scope: https://registry-beta.vexify.top/?action=...(只读)。
|
|
103
|
+
*/
|
|
97
104
|
/** 发起 registry API 请求,返回解析后的 JSON */
|
|
98
105
|
async function apiRequest(action, params = {}) {
|
|
106
|
+
if (isOffline()) throw offlineError('jsql plugin', '插件目录在远端 registry');
|
|
99
107
|
const url = new URL(REGISTRY_BASE);
|
|
100
108
|
url.searchParams.set('action', action);
|
|
101
109
|
for (const [k, v] of Object.entries(params)) {
|
|
@@ -151,7 +159,12 @@ async function getPluginInfo(name) {
|
|
|
151
159
|
* 带重试的 fetch(P1 修复:install 网络间歇性失败 30-40%)
|
|
152
160
|
* 3 次重试 + 指数退避(500ms, 1s, 2s)
|
|
153
161
|
*/
|
|
162
|
+
/* NETWORK: 下载插件压缩包(同 apiRequest 的 NETWORK 标注)
|
|
163
|
+
* Why: 包体只在远端;Trigger: 仅 `jsql plugin install <name>`;
|
|
164
|
+
* Offline: JSQL_OFFLINE=1 → 抛 JSQL_OFFLINE 错误;
|
|
165
|
+
* Scope: registry-beta.vexify.top 的 download action。 */
|
|
154
166
|
async function fetchWithRetry(url, retries = 3, baseDelay = 500) {
|
|
167
|
+
if (isOffline()) throw offlineError('jsql plugin install', '插件包需要下载');
|
|
155
168
|
for (let i = 0; i < retries; i++) {
|
|
156
169
|
try {
|
|
157
170
|
const res = await fetch(url.toString());
|
package/test/issue-50.test.js
CHANGED
|
@@ -55,10 +55,10 @@ function storedOf(iso) { return utcStr(Date.parse(iso)); }
|
|
|
55
55
|
const expectMinus5 = storedOf('2024-01-15T10:30:00-05:00');
|
|
56
56
|
ok('#50 ISO -05:00 偏移正确换算', r.rows[0][0] === expectMinus5, { got: r.rows[0][0], want: expectMinus5 });
|
|
57
57
|
|
|
58
|
-
// 4) 带毫秒 + Z
|
|
58
|
+
// 4) 带毫秒 + Z(#82:保留亚秒精度,不再静默截断为整秒)
|
|
59
59
|
await q("INSERT INTO t (id, dt) VALUES (4, '2024-01-15T10:30:00.500Z')");
|
|
60
60
|
r = await q('SELECT dt FROM t WHERE id = 4');
|
|
61
|
-
ok('#50 带毫秒的 Z
|
|
61
|
+
ok('#50 带毫秒的 Z 同样换算(保留亚秒 .500)', r.rows[0][0] === '2024-01-15 10:30:00.500', r.rows[0][0]);
|
|
62
62
|
|
|
63
63
|
// 5) 不带时区标记:字面值即 UTC 墙上时间,原样保存(与 Z 等价)
|
|
64
64
|
await q("INSERT INTO t (id, dt) VALUES (5, '2024-01-15T10:30:00')");
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// 回归测试:Issue #77-#84
|
|
2
|
+
// #77 WHERE on BIGINT 用字典序字符串比较导致错误结果
|
|
3
|
+
// #78 UNION/INTERSECT/EXCEPT 遇 BIGINT 列 TypeError
|
|
4
|
+
// #79 BEFORE DELETE trigger 在 removeById() 上不触发
|
|
5
|
+
// #80 XOR 违反 SQL 三值逻辑(UNKNOWN 塌缩成 FALSE)
|
|
6
|
+
// #81 NeDB-compat $pull 是 no-op(硬编码键 "k")
|
|
7
|
+
// #82 DATETIME 静默丢弃亚秒精度
|
|
8
|
+
// #83 BOOLEAN 列与数字字符串字面量 '1' 比较返回空
|
|
9
|
+
// #84 插件 priority 被忽略(钩子按注册顺序执行)
|
|
10
|
+
const { executeSQL } = require('../lib/sql');
|
|
11
|
+
const Database = require('../lib/database');
|
|
12
|
+
const { Datastore } = require('../lib/nedb_compat');
|
|
13
|
+
const dateTypes = require('../lib/date-types');
|
|
14
|
+
|
|
15
|
+
let pass = 0, fail = 0;
|
|
16
|
+
function ok(name, cond, extra) {
|
|
17
|
+
if (cond) { pass++; console.log('[OK] ', name); }
|
|
18
|
+
else { fail++; console.log('[FAIL]', name, extra !== undefined ? ' -> ' + JSON.stringify(extra).slice(0, 300) : ''); }
|
|
19
|
+
}
|
|
20
|
+
const engine = (schema, rows) => ({
|
|
21
|
+
hasTable: () => true,
|
|
22
|
+
find: async () => rows,
|
|
23
|
+
getTableSchema: async () => schema,
|
|
24
|
+
truncate: async () => {}, flush: async () => {},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
(async () => {
|
|
28
|
+
// #77 BIGINT WHERE 比较
|
|
29
|
+
{
|
|
30
|
+
const r = await executeSQL(engine(
|
|
31
|
+
{ id: { type: 'integer', primaryKey: true }, big: { type: 'bigint' } },
|
|
32
|
+
[{ id: 1, big: 50n }, { id: 2, big: 2000n }]
|
|
33
|
+
), 'SELECT id FROM t WHERE big > 1000', { safety: false });
|
|
34
|
+
ok('#77 bigint > 1000 只返回 id=2', r.rows.map(x => x[0]).join(',') === '2', r.rows);
|
|
35
|
+
}
|
|
36
|
+
{
|
|
37
|
+
const r = await executeSQL(engine(
|
|
38
|
+
{ id: { type: 'integer', primaryKey: true }, big: { type: 'bigint' } },
|
|
39
|
+
[{ id: 1, big: 50n }, { id: 2, big: 2000n }]
|
|
40
|
+
), 'SELECT id FROM t WHERE big = 50', { safety: false });
|
|
41
|
+
ok('#77 bigint = 50 数值相等', r.rows.map(x => x[0]).join(',') === '1', r.rows);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// #78 UNION / INTERSECT / EXCEPT on bigint
|
|
45
|
+
{
|
|
46
|
+
const r = await executeSQL(engine(
|
|
47
|
+
{ big: { type: 'bigint' } },
|
|
48
|
+
[{ big: 50n }, { big: 2000n }]
|
|
49
|
+
), 'SELECT big FROM t UNION SELECT big FROM t', { safety: false });
|
|
50
|
+
ok('#78 UNION bigint 不抛错且去重', Array.isArray(r.rows) && r.rows.length === 2, r.rows);
|
|
51
|
+
}
|
|
52
|
+
{
|
|
53
|
+
const r = await executeSQL(engine(
|
|
54
|
+
{ big: { type: 'bigint' } },
|
|
55
|
+
[{ big: 50n }]
|
|
56
|
+
), 'SELECT big FROM t INTERSECT SELECT big FROM t', { safety: false });
|
|
57
|
+
ok('#78 INTERSECT bigint 不抛错', Array.isArray(r.rows) && r.rows.length === 1, r.rows);
|
|
58
|
+
}
|
|
59
|
+
{
|
|
60
|
+
const r = await executeSQL(engine(
|
|
61
|
+
{ big: { type: 'bigint' } },
|
|
62
|
+
[{ big: 50n }, { big: 2000n }]
|
|
63
|
+
), 'SELECT big FROM t EXCEPT SELECT big FROM t WHERE big = 50', { safety: false });
|
|
64
|
+
ok('#78 EXCEPT bigint 不抛错', Array.isArray(r.rows), r.rows);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// #79 BEFORE DELETE on removeById
|
|
68
|
+
{
|
|
69
|
+
const db = new Database(':memory:');
|
|
70
|
+
await db.createTable('t', { id: { type: 'integer', primaryKey: true } });
|
|
71
|
+
let fired = 0;
|
|
72
|
+
db.createTrigger('tr', { event: 'remove', table: 't', timing: 'before' }, () => { fired++; });
|
|
73
|
+
await db.insert('t', { id: 1 });
|
|
74
|
+
await db.removeById('t', 1);
|
|
75
|
+
ok('#79 removeById 触发 before remove', fired === 1, { fired });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// #80 XOR 三值逻辑
|
|
79
|
+
{
|
|
80
|
+
const r = await executeSQL(engine(
|
|
81
|
+
{ id: { type: 'integer', primaryKey: true }, a: { type: 'integer' } },
|
|
82
|
+
[{ id: 1, a: null }, { id: 2, a: 1 }, { id: 3, a: 2 }]
|
|
83
|
+
), 'SELECT id FROM t WHERE TRUE XOR (a = 1)', { safety: false });
|
|
84
|
+
ok('#80 TRUE XOR (a=1) 只返回 id=3(UNKNOWN 不塌缩)', r.rows.map(x => x[0]).join(',') === '3', r.rows);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// #81 $pull
|
|
88
|
+
{
|
|
89
|
+
const ds = new Datastore({ inMemoryOnly: true });
|
|
90
|
+
await ds.loadDatabase();
|
|
91
|
+
const doc = await ds.insert({ tags: ['red', 'green', 'blue'] });
|
|
92
|
+
await ds.update({ _id: doc._id }, { $pull: { tags: 'red' } });
|
|
93
|
+
const after = await ds.findOne({ _id: doc._id });
|
|
94
|
+
ok('#81 $pull 移除匹配元素', after.tags.join(',') === 'green,blue', after.tags);
|
|
95
|
+
}
|
|
96
|
+
{
|
|
97
|
+
const ds = new Datastore({ inMemoryOnly: true });
|
|
98
|
+
await ds.loadDatabase();
|
|
99
|
+
const doc = await ds.insert({ items: [{ n: 1 }, { n: 2 }, { n: 3 }] });
|
|
100
|
+
await ds.update({ _id: doc._id }, { $pull: { items: { n: 2 } } });
|
|
101
|
+
const after = await ds.findOne({ _id: doc._id });
|
|
102
|
+
ok('#81 $pull 对象数组按字段匹配', after.items.length === 2 && after.items[1].n === 3, after.items);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// #82 DATETIME 亚秒
|
|
106
|
+
{
|
|
107
|
+
const out = dateTypes.validateDateType('2024-01-15T10:30:00.500Z', 'datetime', 'f');
|
|
108
|
+
ok('#82 保留 .500 亚秒', out === '2024-01-15 10:30:00.500', out);
|
|
109
|
+
}
|
|
110
|
+
{
|
|
111
|
+
const out = dateTypes.validateDateType('2024-01-15T10:30:00Z', 'datetime', 'f');
|
|
112
|
+
ok('#82 整秒不带 .000', out === '2024-01-15 10:30:00', out);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// #83 BOOLEAN vs '1'
|
|
116
|
+
{
|
|
117
|
+
const r = await executeSQL(engine(
|
|
118
|
+
{ id: { type: 'integer', primaryKey: true }, b: { type: 'boolean' } },
|
|
119
|
+
[{ id: 1, b: true }, { id: 2, b: false }]
|
|
120
|
+
), "SELECT id FROM t WHERE b = '1'", { safety: false });
|
|
121
|
+
ok('#83 b = \'1\' 返回 id=1', r.rows.map(x => x[0]).join(',') === '1', r.rows);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// #84 plugin priority
|
|
125
|
+
{
|
|
126
|
+
const db = new Database(':memory:');
|
|
127
|
+
await db.createTable('t', { id: { type: 'integer', primaryKey: true } });
|
|
128
|
+
const order = [];
|
|
129
|
+
await db.use({ name: 'low', priority: 1, hooks: { beforeInsert: () => order.push('low') } });
|
|
130
|
+
await db.use({ name: 'high', priority: 10, hooks: { beforeInsert: () => order.push('high') } });
|
|
131
|
+
await db.insert('t', { id: 1 });
|
|
132
|
+
ok('#84 高 priority 先执行', order.join(',') === 'high,low', order);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
136
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
137
|
+
})().catch(e => { console.error('FATAL', e); process.exit(1); });
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/* ---- 网络访问策略:启动路径零出网 + JSQL_OFFLINE 统一开关 ---- */
|
|
2
|
+
/*
|
|
3
|
+
* 背景:CLI 启动路径曾会同步 curl api.github.com(只为少印一行 star 提示),
|
|
4
|
+
* 让每条 jsql 命令都可能偷偷出网并阻塞最多 ~9.5 秒。本测试把「启动不联网」
|
|
5
|
+
* 钉死,并验证 JSQL_OFFLINE=1 能拦住所有显式联网入口。
|
|
6
|
+
*
|
|
7
|
+
* 全程用临时目录:JSQL_MR_PATH 指向临时路径,绝不碰真实的 ~/.jsqlmr。
|
|
8
|
+
*/
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
|
|
13
|
+
const ROOT = path.join(__dirname, '..');
|
|
14
|
+
const TMP = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-netpolicy-'));
|
|
15
|
+
process.env.JSQL_MR_PATH = path.join(TMP, 'jsqlmr'); // 必须在 require 之前
|
|
16
|
+
|
|
17
|
+
const { isOffline, offlineError } = require(path.join(ROOT, 'lib', 'network-policy'));
|
|
18
|
+
const sn = require(path.join(ROOT, 'lib', 'star-nag'));
|
|
19
|
+
const updater = require(path.join(ROOT, 'lib', 'updater'));
|
|
20
|
+
const plugin = require(path.join(ROOT, 'src', 'cli', 'plugin'));
|
|
21
|
+
|
|
22
|
+
let pass = 0, fail = 0;
|
|
23
|
+
function ok(name, cond, got) {
|
|
24
|
+
if (cond) { pass++; console.log('[OK] ' + name); }
|
|
25
|
+
else { fail++; console.log('[FAIL] ' + name + ' -> ' + JSON.stringify(got)); }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 记录所有子进程调用(curl / gh / npm),用来证明「没有出网」
|
|
29
|
+
const cp = require('child_process');
|
|
30
|
+
const realExecFileSync = cp.execFileSync;
|
|
31
|
+
const realExecFile = cp.execFile;
|
|
32
|
+
const realSpawn = cp.spawn;
|
|
33
|
+
const calls = [];
|
|
34
|
+
cp.execFileSync = function (cmd, ...rest) { calls.push('execFileSync:' + cmd); return realExecFileSync.call(this, cmd, ...rest); };
|
|
35
|
+
cp.execFile = function (cmd, ...rest) { calls.push('execFile:' + cmd); return realExecFile.call(this, cmd, ...rest); };
|
|
36
|
+
cp.spawn = function (cmd, ...rest) { calls.push('spawn:' + cmd); return realSpawn.call(this, cmd, ...rest); };
|
|
37
|
+
|
|
38
|
+
function resetCalls() { calls.length = 0; }
|
|
39
|
+
|
|
40
|
+
(async () => {
|
|
41
|
+
// ---------- 环境变量解析 ----------
|
|
42
|
+
const saved = process.env.JSQL_OFFLINE;
|
|
43
|
+
delete process.env.JSQL_OFFLINE;
|
|
44
|
+
ok('默认不离线', isOffline() === false, process.env.JSQL_OFFLINE);
|
|
45
|
+
for (const v of ['1', 'true', 'yes', 'on', 'TRUE']) {
|
|
46
|
+
process.env.JSQL_OFFLINE = v;
|
|
47
|
+
ok('JSQL_OFFLINE=' + v + ' → 离线', isOffline() === true, v);
|
|
48
|
+
}
|
|
49
|
+
for (const v of ['0', 'false', '', 'no']) {
|
|
50
|
+
process.env.JSQL_OFFLINE = v;
|
|
51
|
+
ok('JSQL_OFFLINE=' + JSON.stringify(v) + ' → 不离线', isOffline() === false, v);
|
|
52
|
+
}
|
|
53
|
+
process.env.JSQL_OFFLINE = '1';
|
|
54
|
+
const oe = offlineError('jsql update', '需要访问 npm registry');
|
|
55
|
+
ok('offlineError 带 code=JSQL_OFFLINE', oe && oe.code === 'JSQL_OFFLINE', oe && oe.code);
|
|
56
|
+
ok('offlineError 文案含功能名与原因', /jsql update/.test(oe.message) && /npm registry/.test(oe.message), oe && oe.message);
|
|
57
|
+
|
|
58
|
+
// ---------- 启动路径零出网 ----------
|
|
59
|
+
process.env.JSQL_OFFLINE = '';
|
|
60
|
+
delete process.env.JSQL_OFFLINE;
|
|
61
|
+
process.env.GITHUB_TOKEN = 'fake-token-should-never-be-used';
|
|
62
|
+
const out = [];
|
|
63
|
+
resetCalls();
|
|
64
|
+
const printed = sn.nag({ out: { write: (s) => out.push(s) } });
|
|
65
|
+
ok('nag() 正常打印提示', printed === true && out.join('').includes('star helps others find it'), out.join(''));
|
|
66
|
+
ok('nag() 不发起任何子进程网络调用', calls.length === 0, calls);
|
|
67
|
+
ok('nag() 不写 lastNagAt', (() => {
|
|
68
|
+
try { const c = sn.readConfig(); return c.lastNagAt === undefined; } catch (e) { return true; }
|
|
69
|
+
})(), null);
|
|
70
|
+
delete process.env.GITHUB_TOKEN;
|
|
71
|
+
|
|
72
|
+
// 已标记 starred 时应彻底沉默,且同样不出网
|
|
73
|
+
sn.setStarred(true);
|
|
74
|
+
const out2 = [];
|
|
75
|
+
resetCalls();
|
|
76
|
+
const printed2 = sn.nag({ out: { write: (s) => out2.push(s) } });
|
|
77
|
+
ok('已 starred 时不打印', printed2 === false && out2.length === 0, out2.join(''));
|
|
78
|
+
ok('已 starred 时不出网', calls.length === 0, calls);
|
|
79
|
+
sn.setStarred(false);
|
|
80
|
+
|
|
81
|
+
// ---------- 离线时各联网入口都被拦住 ----------
|
|
82
|
+
process.env.JSQL_OFFLINE = '1';
|
|
83
|
+
resetCalls();
|
|
84
|
+
ok('checkStarred() 离线返回 null', sn.checkStarred() === null, null);
|
|
85
|
+
ok('checkStarred() 离线不出网', calls.length === 0, calls);
|
|
86
|
+
resetCalls();
|
|
87
|
+
let threw = null;
|
|
88
|
+
try { sn.startOauthCheck(); } catch (e) { threw = e; }
|
|
89
|
+
ok('startOauthCheck() 离线抛 JSQL_OFFLINE', threw && threw.code === 'JSQL_OFFLINE', threw && threw.code);
|
|
90
|
+
ok('startOauthCheck() 离线不开浏览器', calls.length === 0, calls);
|
|
91
|
+
resetCalls();
|
|
92
|
+
ok('waitForResult() 离线返回 null', sn.waitForResult('https://auth.vexify.top/start?nonce=x') === null, null);
|
|
93
|
+
ok('waitForResult() 离线不轮询', calls.length === 0, calls);
|
|
94
|
+
|
|
95
|
+
resetCalls();
|
|
96
|
+
const up = await updater.runUpdate({ checkOnly: true });
|
|
97
|
+
ok('jsql update 离线返回 ok=false', up && up.ok === false, up);
|
|
98
|
+
ok('jsql update 离线给出可读原因', up && /JSQL_OFFLINE|离线/.test(up.error || ''), up && up.error);
|
|
99
|
+
ok('jsql update 离线不出网', calls.length === 0, calls);
|
|
100
|
+
|
|
101
|
+
resetCalls();
|
|
102
|
+
let perr = null;
|
|
103
|
+
try { await plugin.listPlugins({}); } catch (e) { perr = e; }
|
|
104
|
+
ok('jsql plugin list 离线抛 JSQL_OFFLINE', perr && perr.code === 'JSQL_OFFLINE', perr && perr.code);
|
|
105
|
+
ok('jsql plugin list 离线不出网', calls.length === 0, calls);
|
|
106
|
+
|
|
107
|
+
// ---------- 恢复 ----------
|
|
108
|
+
process.env.JSQL_OFFLINE = saved === undefined ? '' : saved;
|
|
109
|
+
if (saved === undefined) delete process.env.JSQL_OFFLINE;
|
|
110
|
+
cp.execFileSync = realExecFileSync;
|
|
111
|
+
cp.execFile = realExecFile;
|
|
112
|
+
cp.spawn = realSpawn;
|
|
113
|
+
try { fs.rmSync(TMP, { recursive: true, force: true }); } catch (_) {}
|
|
114
|
+
|
|
115
|
+
console.log(`\n${pass} passed, ${fail} failed`);
|
|
116
|
+
process.exit(fail === 0 ? 0 : 1);
|
|
117
|
+
})().catch(e => {
|
|
118
|
+
console.log('[FAIL] unexpected exception: ' + e.stack.split('\n').slice(0, 3).join('\n'));
|
|
119
|
+
process.exit(1);
|
|
120
|
+
});
|