Skip to content

Commit 4e79753

Browse files
author
Taois
committed
feat: drpy2升级
1 parent aaffb1e commit 4e79753

File tree

9 files changed

+1202
-13
lines changed

9 files changed

+1202
-13
lines changed

dist/drpy-core-fast.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

drpy2-fast/drpy-core-fast.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

drpy2-fast/drpy2-fast.min.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
## drpy_webpack
22

3-
drpy2框架的打包项目。所有依赖打包成一个`drpy-core.min.js` `drpy-core-lite.min.js`
3+
drpy2框架的打包项目。所有依赖打包成一个`drpy-core.min.js` `drpy-core-lite.min.js` `drpy-core-fast.min.js`
44

55
[drpyS项目传送门](https://github.com/hjdhnx/drpy-node)
66

77
当前版本号: `3.9.52beta3 20250801`
8+
特殊QJS版本: `3.9.54 20260117`
89

910
注意复制到drpyS项目 `public/drpy` 目录前需要把 init_test里的一些调试日志注释掉
1011

src/drpy-core-fast.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import './libs/jinja.min.js';
1616
// import './libs/polywasm.min.js';
1717
import './libs/xxhash-wasm.min.js';
1818
// export {Buffer} from './libs/buffer.min.js'
19-
19+
import "./libs/url.js";
20+
import "./libs/sqlite.js";
2021

2122
// 确保全局依赖可用
2223
const g = globalThis;
@@ -28,6 +29,7 @@ const CryptoJS = g.CryptoJS;
2829
const JSON5 = g.JSON5;
2930
const JSONPath = g.JSONPath;
3031
const jinja = g.jinja;
32+
const Database = g.Database;
3133
// const WebAssembly = g.WebAssembly;
3234
// const TextEncoder = g.TextEncoder;
3335
// const TextDecoder = g.TextDecoder;
@@ -66,6 +68,7 @@ export {
6668
JSON5,
6769
JSONPath,
6870
jinja,
71+
Database,
6972
// WebAssembly,
7073
// TextEncoder,
7174
// TextDecoder,

src/drpy2-fast.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import {cheerio, 模板} from '../dist/drpy-core-fast.min.js';
22

33
let vercode = typeof (pdfl) === 'function' ? 'drpy2.1' : 'drpy2';
4-
const VERSION = vercode + ' 3.9.53 20251007';
4+
const VERSION = vercode + ' 3.9.54 20260117';
55
const UpdateInfo = [
6+
{
7+
date: '20260117',
8+
title: '爱佬新So测试版,使用drpy-core-fast.min.js',
9+
version: '3.9.54 20260117',
10+
msg: `
11+
drpy-core-fast.min.js内置了url和sqlite模块
12+
`
13+
},
614
{
715
date: '20251007',
816
title: '爱佬新So测试版,使用drpy-core-lite.min.js,内置了Buffer库',
@@ -904,7 +912,7 @@ function gzip(str) {
904912
* @returns {string}
905913
*/
906914
function ungzip(b64Data) {
907-
const binData = Buffer.from(b64Data,'base64');
915+
const binData = Buffer.from(b64Data, 'base64');
908916
const data = zlib.ungzip(binData.buffer);
909917
return Buffer.from(data, 'utf8').toString();
910918
}
@@ -1016,7 +1024,8 @@ const RSA = {
10161024
encryptedData.set(segment, offset);
10171025
offset += segment.length;
10181026
}
1019-
return encryptedData.slice(0, offset);;
1027+
return encryptedData.slice(0, offset);
1028+
;
10201029
}
10211030
return crypto.subtle.encrypt(
10221031
{
@@ -1052,15 +1061,15 @@ const RSA = {
10521061
}
10531062
return decryptedData.slice(0, offset);
10541063
}
1055-
return new Uint8Array(crypto.subtle.decrypt (
1064+
return new Uint8Array(crypto.subtle.decrypt(
10561065
{
10571066
name: "RSA-PKCS1-v1_5",
10581067
},
10591068
privateKey,
10601069
mergedData
10611070
));
10621071
},
1063-
decode: function(data, key) {
1072+
decode: function (data, key) {
10641073
try {
10651074
const mergedDataArray = Uint8Array.from(Buffer.from(data, 'base64'));
10661075
const privateKey = this.importPrivateKey(key);
@@ -1073,7 +1082,7 @@ const RSA = {
10731082
throw error;
10741083
}
10751084
},
1076-
encode: function(plainText, publicKeyPem) {
1085+
encode: function (plainText, publicKeyPem) {
10771086
try {
10781087
const publicKey = this.importPublicKey(publicKeyPem);
10791088
//console.time("RSA加密");
@@ -3464,7 +3473,7 @@ function getOriginalJs(js_code) {
34643473
const key = crypto.subtle.importKey(
34653474
"raw",
34663475
keyArray,
3467-
{ name: "AES-CBC" },
3476+
{name: "AES-CBC"},
34683477
false,
34693478
["decrypt"]
34703479
);

src/drpy2-fast.min.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libs/sqlite.js

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
const sqlite3 = globalThis.sqlite;
2+
3+
const kSqlite3Handle = Symbol('kSqlite3Handle');
4+
let controllers;
5+
6+
class Database {
7+
constructor(dbName = ':memory:', options = { create: true, readOnly: false }) {
8+
let flags = 0;
9+
10+
if (options.create) {
11+
flags |= sqlite3.SQLITE_OPEN_CREATE;
12+
}
13+
14+
if (options.readOnly) {
15+
flags |= sqlite3.SQLITE_OPEN_READONLY;
16+
} else {
17+
flags |= sqlite3.SQLITE_OPEN_READWRITE;
18+
}
19+
20+
this[kSqlite3Handle] = sqlite3.open(dbName, flags);
21+
}
22+
23+
close() {
24+
let ret = false;
25+
if (this[kSqlite3Handle]) {
26+
ret = sqlite3.close(this[kSqlite3Handle]);
27+
this[kSqlite3Handle] = null;
28+
}
29+
return ret;
30+
}
31+
32+
exec(sql) {
33+
if (!this[kSqlite3Handle]) {
34+
throw new Error('Invalid DB');
35+
}
36+
37+
return sqlite3.exec(this[kSqlite3Handle], sql);
38+
}
39+
40+
prepare(sql) {
41+
if (!this[kSqlite3Handle]) {
42+
throw new Error('Invalid DB');
43+
}
44+
45+
return new Statement(sqlite3.prepare(this[kSqlite3Handle], sql));
46+
}
47+
48+
// Code for transactions is largely copied from better-sqlite3 and Bun
49+
// https://github.com/JoshuaWise/better-sqlite3/blob/master/lib/methods/transaction.js
50+
// https://github.com/oven-sh/bun/blob/main/src/js/bun/sqlite.ts
51+
52+
get inTransaction() {
53+
if (!this[kSqlite3Handle]) {
54+
return false;
55+
}
56+
return sqlite3.in_transaction(this[kSqlite3Handle]);
57+
}
58+
59+
transaction(fn) {
60+
if (typeof fn !== 'function') {
61+
throw new TypeError('Expected first argument to be a function');
62+
}
63+
64+
const db = this;
65+
const controller = getController(db);
66+
67+
// Each version of the transaction function has these same properties.
68+
const properties = {
69+
default: { value: wrapTransaction(fn, db, controller.default) },
70+
deferred: { value: wrapTransaction(fn, db, controller.deferred) },
71+
immediate: { value: wrapTransaction(fn, db, controller.immediate) },
72+
exclusive: { value: wrapTransaction(fn, db, controller.exclusive) },
73+
};
74+
75+
Object.defineProperties(properties.default.value, properties);
76+
Object.defineProperties(properties.deferred.value, properties);
77+
Object.defineProperties(properties.immediate.value, properties);
78+
Object.defineProperties(properties.exclusive.value, properties);
79+
80+
// Return the default version of the transaction function.
81+
return properties.default.value;
82+
}
83+
84+
loadExtension(file, entrypoint=undefined) {
85+
return sqlite3.load_extension(this[kSqlite3Handle],file,entrypoint);
86+
}
87+
}
88+
89+
// Return the database's cached transaction controller, or create a new one.
90+
const getController = db => {
91+
let controller = (controllers ||= new WeakMap()).get(db);
92+
93+
if (!controller) {
94+
const shared = {
95+
commit: db.prepare('COMMIT'),
96+
rollback: db.prepare('ROLLBACK'),
97+
savepoint: db.prepare('SAVEPOINT `\t_bs3.\t`'),
98+
release: db.prepare('RELEASE `\t_bs3.\t`'),
99+
rollbackTo: db.prepare('ROLLBACK TO `\t_bs3.\t`'),
100+
};
101+
102+
controller = {
103+
default: Object.assign({ begin: db.prepare('BEGIN') }, shared),
104+
deferred: Object.assign({ begin: db.prepare('BEGIN DEFERRED') }, shared),
105+
immediate: Object.assign({ begin: db.prepare('BEGIN IMMEDIATE') }, shared),
106+
exclusive: Object.assign({ begin: db.prepare('BEGIN EXCLUSIVE') }, shared),
107+
};
108+
109+
controllers.set(db, controller);
110+
}
111+
112+
return controller;
113+
};
114+
115+
// Return a new transaction function by wrapping the given function.
116+
const wrapTransaction = (fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) =>
117+
function transaction() {
118+
let before, after, undo;
119+
120+
if (db.inTransaction) {
121+
before = savepoint;
122+
after = release;
123+
undo = rollbackTo;
124+
} else {
125+
before = begin;
126+
after = commit;
127+
undo = rollback;
128+
}
129+
130+
try {
131+
before.run();
132+
133+
const result = Function.prototype.apply.call(fn, this, arguments);
134+
135+
after.run();
136+
137+
return result;
138+
} catch (ex) {
139+
if (db.inTransaction) {
140+
undo.run();
141+
142+
if (undo !== rollback) {
143+
after.run();
144+
}
145+
}
146+
throw ex;
147+
}
148+
};
149+
150+
const kSqlite3Stmt = Symbol('kSqlite3Stmt');
151+
152+
class Statement {
153+
constructor(stmt) {
154+
this[kSqlite3Stmt] = stmt;
155+
}
156+
157+
finalize() {
158+
return sqlite3.stmt_finalize(this[kSqlite3Stmt]);
159+
}
160+
161+
toString() {
162+
return sqlite3.stmt_expand(this[kSqlite3Stmt]);
163+
}
164+
165+
all(...args) {
166+
if (args && args.length === 1 && typeof args[0] === 'object') {
167+
args = args[0];
168+
}
169+
return sqlite3.stmt_all(this[kSqlite3Stmt], args);
170+
}
171+
172+
run(...args) {
173+
if (args && args.length === 1 && typeof args[0] === 'object') {
174+
args = args[0];
175+
}
176+
return sqlite3.stmt_run(this[kSqlite3Stmt], args);
177+
}
178+
}
179+
180+
Object.defineProperty(globalThis, 'DataBase', {
181+
enumerable: true,
182+
configurable: true,
183+
writable: true,
184+
value: Database
185+
});

0 commit comments

Comments
 (0)