@polka-codes/cli-shared 0.9.86 → 0.9.89
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/dist/index.js +1433 -57
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -15363,7 +15363,7 @@ var init_multipart_parser = __esm(() => {
|
|
|
15363
15363
|
|
|
15364
15364
|
// ../../node_modules/node-fetch/src/body.js
|
|
15365
15365
|
import Stream, { PassThrough } from "node:stream";
|
|
15366
|
-
import { types as
|
|
15366
|
+
import { types as types4, deprecate, promisify } from "node:util";
|
|
15367
15367
|
import { Buffer as Buffer4 } from "node:buffer";
|
|
15368
15368
|
|
|
15369
15369
|
class Body {
|
|
@@ -15375,7 +15375,7 @@ class Body {
|
|
|
15375
15375
|
body = null;
|
|
15376
15376
|
} else if (isURLSearchParameters(body)) {
|
|
15377
15377
|
body = Buffer4.from(body.toString());
|
|
15378
|
-
} else if (isBlob(body)) {} else if (Buffer4.isBuffer(body)) {} else if (
|
|
15378
|
+
} else if (isBlob(body)) {} else if (Buffer4.isBuffer(body)) {} else if (types4.isAnyArrayBuffer(body)) {
|
|
15379
15379
|
body = Buffer4.from(body);
|
|
15380
15380
|
} else if (ArrayBuffer.isView(body)) {
|
|
15381
15381
|
body = Buffer4.from(body.buffer, body.byteOffset, body.byteLength);
|
|
@@ -15521,7 +15521,7 @@ var pipeline, INTERNALS, clone2 = (instance, highWaterMark) => {
|
|
|
15521
15521
|
if (isBlob(body)) {
|
|
15522
15522
|
return body.type || null;
|
|
15523
15523
|
}
|
|
15524
|
-
if (Buffer4.isBuffer(body) ||
|
|
15524
|
+
if (Buffer4.isBuffer(body) || types4.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
|
|
15525
15525
|
return null;
|
|
15526
15526
|
}
|
|
15527
15527
|
if (body instanceof FormData2) {
|
|
@@ -15578,7 +15578,7 @@ var init_body = __esm(() => {
|
|
|
15578
15578
|
});
|
|
15579
15579
|
|
|
15580
15580
|
// ../../node_modules/node-fetch/src/headers.js
|
|
15581
|
-
import { types as
|
|
15581
|
+
import { types as types5 } from "node:util";
|
|
15582
15582
|
import http from "node:http";
|
|
15583
15583
|
function fromRawHeaders(headers = []) {
|
|
15584
15584
|
return new Headers2(headers.reduce((result, value, index, array2) => {
|
|
@@ -15620,7 +15620,7 @@ var init_headers = __esm(() => {
|
|
|
15620
15620
|
for (const [name17, values] of Object.entries(raw)) {
|
|
15621
15621
|
result.push(...values.map((value) => [name17, value]));
|
|
15622
15622
|
}
|
|
15623
|
-
} else if (init == null) {} else if (typeof init === "object" && !
|
|
15623
|
+
} else if (init == null) {} else if (typeof init === "object" && !types5.isBoxedPrimitive(init)) {
|
|
15624
15624
|
const method = init[Symbol.iterator];
|
|
15625
15625
|
if (method == null) {
|
|
15626
15626
|
result.push(...Object.entries(init));
|
|
@@ -15629,7 +15629,7 @@ var init_headers = __esm(() => {
|
|
|
15629
15629
|
throw new TypeError("Header pairs must be iterable");
|
|
15630
15630
|
}
|
|
15631
15631
|
result = [...init].map((pair) => {
|
|
15632
|
-
if (typeof pair !== "object" ||
|
|
15632
|
+
if (typeof pair !== "object" || types5.isBoxedPrimitive(pair)) {
|
|
15633
15633
|
throw new TypeError("Each header pair must be an iterable object");
|
|
15634
15634
|
}
|
|
15635
15635
|
return [...pair];
|
|
@@ -35104,6 +35104,771 @@ var require_mimeScore = __commonJS((exports, module) => {
|
|
|
35104
35104
|
};
|
|
35105
35105
|
});
|
|
35106
35106
|
|
|
35107
|
+
// ../../node_modules/better-sqlite3/lib/util.js
|
|
35108
|
+
var require_util3 = __commonJS((exports) => {
|
|
35109
|
+
exports.getBooleanOption = (options, key) => {
|
|
35110
|
+
let value = false;
|
|
35111
|
+
if (key in options && typeof (value = options[key]) !== "boolean") {
|
|
35112
|
+
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
|
35113
|
+
}
|
|
35114
|
+
return value;
|
|
35115
|
+
};
|
|
35116
|
+
exports.cppdb = Symbol();
|
|
35117
|
+
exports.inspect = Symbol.for("nodejs.util.inspect.custom");
|
|
35118
|
+
});
|
|
35119
|
+
|
|
35120
|
+
// ../../node_modules/better-sqlite3/lib/sqlite-error.js
|
|
35121
|
+
var require_sqlite_error = __commonJS((exports, module) => {
|
|
35122
|
+
var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
|
|
35123
|
+
function SqliteError(message, code) {
|
|
35124
|
+
if (new.target !== SqliteError) {
|
|
35125
|
+
return new SqliteError(message, code);
|
|
35126
|
+
}
|
|
35127
|
+
if (typeof code !== "string") {
|
|
35128
|
+
throw new TypeError("Expected second argument to be a string");
|
|
35129
|
+
}
|
|
35130
|
+
Error.call(this, message);
|
|
35131
|
+
descriptor.value = "" + message;
|
|
35132
|
+
Object.defineProperty(this, "message", descriptor);
|
|
35133
|
+
Error.captureStackTrace(this, SqliteError);
|
|
35134
|
+
this.code = code;
|
|
35135
|
+
}
|
|
35136
|
+
Object.setPrototypeOf(SqliteError, Error);
|
|
35137
|
+
Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
|
|
35138
|
+
Object.defineProperty(SqliteError.prototype, "name", descriptor);
|
|
35139
|
+
module.exports = SqliteError;
|
|
35140
|
+
});
|
|
35141
|
+
|
|
35142
|
+
// ../../node_modules/file-uri-to-path/index.js
|
|
35143
|
+
var require_file_uri_to_path = __commonJS((exports, module) => {
|
|
35144
|
+
var sep = __require("path").sep || "/";
|
|
35145
|
+
module.exports = fileUriToPath;
|
|
35146
|
+
function fileUriToPath(uri) {
|
|
35147
|
+
if (typeof uri != "string" || uri.length <= 7 || uri.substring(0, 7) != "file://") {
|
|
35148
|
+
throw new TypeError("must pass in a file:// URI to convert to a file path");
|
|
35149
|
+
}
|
|
35150
|
+
var rest = decodeURI(uri.substring(7));
|
|
35151
|
+
var firstSlash = rest.indexOf("/");
|
|
35152
|
+
var host = rest.substring(0, firstSlash);
|
|
35153
|
+
var path = rest.substring(firstSlash + 1);
|
|
35154
|
+
if (host == "localhost")
|
|
35155
|
+
host = "";
|
|
35156
|
+
if (host) {
|
|
35157
|
+
host = sep + sep + host;
|
|
35158
|
+
}
|
|
35159
|
+
path = path.replace(/^(.+)\|/, "$1:");
|
|
35160
|
+
if (sep == "\\") {
|
|
35161
|
+
path = path.replace(/\//g, "\\");
|
|
35162
|
+
}
|
|
35163
|
+
if (/^.+\:/.test(path)) {} else {
|
|
35164
|
+
path = sep + path;
|
|
35165
|
+
}
|
|
35166
|
+
return host + path;
|
|
35167
|
+
}
|
|
35168
|
+
});
|
|
35169
|
+
|
|
35170
|
+
// ../../node_modules/bindings/bindings.js
|
|
35171
|
+
var require_bindings = __commonJS((exports, module) => {
|
|
35172
|
+
var __filename = "/Users/xiliangchen/projects/polka-codes/node_modules/bindings/bindings.js";
|
|
35173
|
+
var fs4 = __require("fs");
|
|
35174
|
+
var path = __require("path");
|
|
35175
|
+
var fileURLToPath = require_file_uri_to_path();
|
|
35176
|
+
var join3 = path.join;
|
|
35177
|
+
var dirname2 = path.dirname;
|
|
35178
|
+
var exists = fs4.accessSync && function(path2) {
|
|
35179
|
+
try {
|
|
35180
|
+
fs4.accessSync(path2);
|
|
35181
|
+
} catch (e2) {
|
|
35182
|
+
return false;
|
|
35183
|
+
}
|
|
35184
|
+
return true;
|
|
35185
|
+
} || fs4.existsSync || path.existsSync;
|
|
35186
|
+
var defaults = {
|
|
35187
|
+
arrow: process.env.NODE_BINDINGS_ARROW || " → ",
|
|
35188
|
+
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
|
|
35189
|
+
platform: process.platform,
|
|
35190
|
+
arch: process.arch,
|
|
35191
|
+
nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
|
|
35192
|
+
version: process.versions.node,
|
|
35193
|
+
bindings: "bindings.node",
|
|
35194
|
+
try: [
|
|
35195
|
+
["module_root", "build", "bindings"],
|
|
35196
|
+
["module_root", "build", "Debug", "bindings"],
|
|
35197
|
+
["module_root", "build", "Release", "bindings"],
|
|
35198
|
+
["module_root", "out", "Debug", "bindings"],
|
|
35199
|
+
["module_root", "Debug", "bindings"],
|
|
35200
|
+
["module_root", "out", "Release", "bindings"],
|
|
35201
|
+
["module_root", "Release", "bindings"],
|
|
35202
|
+
["module_root", "build", "default", "bindings"],
|
|
35203
|
+
["module_root", "compiled", "version", "platform", "arch", "bindings"],
|
|
35204
|
+
["module_root", "addon-build", "release", "install-root", "bindings"],
|
|
35205
|
+
["module_root", "addon-build", "debug", "install-root", "bindings"],
|
|
35206
|
+
["module_root", "addon-build", "default", "install-root", "bindings"],
|
|
35207
|
+
["module_root", "lib", "binding", "nodePreGyp", "bindings"]
|
|
35208
|
+
]
|
|
35209
|
+
};
|
|
35210
|
+
function bindings(opts) {
|
|
35211
|
+
if (typeof opts == "string") {
|
|
35212
|
+
opts = { bindings: opts };
|
|
35213
|
+
} else if (!opts) {
|
|
35214
|
+
opts = {};
|
|
35215
|
+
}
|
|
35216
|
+
Object.keys(defaults).map(function(i3) {
|
|
35217
|
+
if (!(i3 in opts))
|
|
35218
|
+
opts[i3] = defaults[i3];
|
|
35219
|
+
});
|
|
35220
|
+
if (!opts.module_root) {
|
|
35221
|
+
opts.module_root = exports.getRoot(exports.getFileName());
|
|
35222
|
+
}
|
|
35223
|
+
if (path.extname(opts.bindings) != ".node") {
|
|
35224
|
+
opts.bindings += ".node";
|
|
35225
|
+
}
|
|
35226
|
+
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
35227
|
+
var tries = [], i2 = 0, l = opts.try.length, n, b, err;
|
|
35228
|
+
for (;i2 < l; i2++) {
|
|
35229
|
+
n = join3.apply(null, opts.try[i2].map(function(p) {
|
|
35230
|
+
return opts[p] || p;
|
|
35231
|
+
}));
|
|
35232
|
+
tries.push(n);
|
|
35233
|
+
try {
|
|
35234
|
+
b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
|
|
35235
|
+
if (!opts.path) {
|
|
35236
|
+
b.path = n;
|
|
35237
|
+
}
|
|
35238
|
+
return b;
|
|
35239
|
+
} catch (e2) {
|
|
35240
|
+
if (e2.code !== "MODULE_NOT_FOUND" && e2.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e2.message)) {
|
|
35241
|
+
throw e2;
|
|
35242
|
+
}
|
|
35243
|
+
}
|
|
35244
|
+
}
|
|
35245
|
+
err = new Error(`Could not locate the bindings file. Tried:
|
|
35246
|
+
` + tries.map(function(a) {
|
|
35247
|
+
return opts.arrow + a;
|
|
35248
|
+
}).join(`
|
|
35249
|
+
`));
|
|
35250
|
+
err.tries = tries;
|
|
35251
|
+
throw err;
|
|
35252
|
+
}
|
|
35253
|
+
module.exports = exports = bindings;
|
|
35254
|
+
exports.getFileName = function getFileName(calling_file) {
|
|
35255
|
+
var { prepareStackTrace: origPST, stackTraceLimit: origSTL } = Error, dummy = {}, fileName;
|
|
35256
|
+
Error.stackTraceLimit = 10;
|
|
35257
|
+
Error.prepareStackTrace = function(e2, st) {
|
|
35258
|
+
for (var i2 = 0, l = st.length;i2 < l; i2++) {
|
|
35259
|
+
fileName = st[i2].getFileName();
|
|
35260
|
+
if (fileName !== __filename) {
|
|
35261
|
+
if (calling_file) {
|
|
35262
|
+
if (fileName !== calling_file) {
|
|
35263
|
+
return;
|
|
35264
|
+
}
|
|
35265
|
+
} else {
|
|
35266
|
+
return;
|
|
35267
|
+
}
|
|
35268
|
+
}
|
|
35269
|
+
}
|
|
35270
|
+
};
|
|
35271
|
+
Error.captureStackTrace(dummy);
|
|
35272
|
+
dummy.stack;
|
|
35273
|
+
Error.prepareStackTrace = origPST;
|
|
35274
|
+
Error.stackTraceLimit = origSTL;
|
|
35275
|
+
var fileSchema = "file://";
|
|
35276
|
+
if (fileName.indexOf(fileSchema) === 0) {
|
|
35277
|
+
fileName = fileURLToPath(fileName);
|
|
35278
|
+
}
|
|
35279
|
+
return fileName;
|
|
35280
|
+
};
|
|
35281
|
+
exports.getRoot = function getRoot(file2) {
|
|
35282
|
+
var dir = dirname2(file2), prev;
|
|
35283
|
+
while (true) {
|
|
35284
|
+
if (dir === ".") {
|
|
35285
|
+
dir = process.cwd();
|
|
35286
|
+
}
|
|
35287
|
+
if (exists(join3(dir, "package.json")) || exists(join3(dir, "node_modules"))) {
|
|
35288
|
+
return dir;
|
|
35289
|
+
}
|
|
35290
|
+
if (prev === dir) {
|
|
35291
|
+
throw new Error('Could not find module root given file: "' + file2 + '". Do you have a `package.json` file? ');
|
|
35292
|
+
}
|
|
35293
|
+
prev = dir;
|
|
35294
|
+
dir = join3(dir, "..");
|
|
35295
|
+
}
|
|
35296
|
+
};
|
|
35297
|
+
});
|
|
35298
|
+
|
|
35299
|
+
// ../../node_modules/better-sqlite3/lib/methods/wrappers.js
|
|
35300
|
+
var require_wrappers = __commonJS((exports) => {
|
|
35301
|
+
var { cppdb } = require_util3();
|
|
35302
|
+
exports.prepare = function prepare(sql) {
|
|
35303
|
+
return this[cppdb].prepare(sql, this, false);
|
|
35304
|
+
};
|
|
35305
|
+
exports.exec = function exec(sql) {
|
|
35306
|
+
this[cppdb].exec(sql);
|
|
35307
|
+
return this;
|
|
35308
|
+
};
|
|
35309
|
+
exports.close = function close() {
|
|
35310
|
+
this[cppdb].close();
|
|
35311
|
+
return this;
|
|
35312
|
+
};
|
|
35313
|
+
exports.loadExtension = function loadExtension(...args) {
|
|
35314
|
+
this[cppdb].loadExtension(...args);
|
|
35315
|
+
return this;
|
|
35316
|
+
};
|
|
35317
|
+
exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
|
35318
|
+
this[cppdb].defaultSafeIntegers(...args);
|
|
35319
|
+
return this;
|
|
35320
|
+
};
|
|
35321
|
+
exports.unsafeMode = function unsafeMode(...args) {
|
|
35322
|
+
this[cppdb].unsafeMode(...args);
|
|
35323
|
+
return this;
|
|
35324
|
+
};
|
|
35325
|
+
exports.getters = {
|
|
35326
|
+
name: {
|
|
35327
|
+
get: function name() {
|
|
35328
|
+
return this[cppdb].name;
|
|
35329
|
+
},
|
|
35330
|
+
enumerable: true
|
|
35331
|
+
},
|
|
35332
|
+
open: {
|
|
35333
|
+
get: function open() {
|
|
35334
|
+
return this[cppdb].open;
|
|
35335
|
+
},
|
|
35336
|
+
enumerable: true
|
|
35337
|
+
},
|
|
35338
|
+
inTransaction: {
|
|
35339
|
+
get: function inTransaction() {
|
|
35340
|
+
return this[cppdb].inTransaction;
|
|
35341
|
+
},
|
|
35342
|
+
enumerable: true
|
|
35343
|
+
},
|
|
35344
|
+
readonly: {
|
|
35345
|
+
get: function readonly() {
|
|
35346
|
+
return this[cppdb].readonly;
|
|
35347
|
+
},
|
|
35348
|
+
enumerable: true
|
|
35349
|
+
},
|
|
35350
|
+
memory: {
|
|
35351
|
+
get: function memory() {
|
|
35352
|
+
return this[cppdb].memory;
|
|
35353
|
+
},
|
|
35354
|
+
enumerable: true
|
|
35355
|
+
}
|
|
35356
|
+
};
|
|
35357
|
+
});
|
|
35358
|
+
|
|
35359
|
+
// ../../node_modules/better-sqlite3/lib/methods/transaction.js
|
|
35360
|
+
var require_transaction = __commonJS((exports, module) => {
|
|
35361
|
+
var { cppdb } = require_util3();
|
|
35362
|
+
var controllers = new WeakMap;
|
|
35363
|
+
module.exports = function transaction(fn) {
|
|
35364
|
+
if (typeof fn !== "function")
|
|
35365
|
+
throw new TypeError("Expected first argument to be a function");
|
|
35366
|
+
const db2 = this[cppdb];
|
|
35367
|
+
const controller = getController(db2, this);
|
|
35368
|
+
const { apply: apply2 } = Function.prototype;
|
|
35369
|
+
const properties = {
|
|
35370
|
+
default: { value: wrapTransaction(apply2, fn, db2, controller.default) },
|
|
35371
|
+
deferred: { value: wrapTransaction(apply2, fn, db2, controller.deferred) },
|
|
35372
|
+
immediate: { value: wrapTransaction(apply2, fn, db2, controller.immediate) },
|
|
35373
|
+
exclusive: { value: wrapTransaction(apply2, fn, db2, controller.exclusive) },
|
|
35374
|
+
database: { value: this, enumerable: true }
|
|
35375
|
+
};
|
|
35376
|
+
Object.defineProperties(properties.default.value, properties);
|
|
35377
|
+
Object.defineProperties(properties.deferred.value, properties);
|
|
35378
|
+
Object.defineProperties(properties.immediate.value, properties);
|
|
35379
|
+
Object.defineProperties(properties.exclusive.value, properties);
|
|
35380
|
+
return properties.default.value;
|
|
35381
|
+
};
|
|
35382
|
+
var getController = (db2, self2) => {
|
|
35383
|
+
let controller = controllers.get(db2);
|
|
35384
|
+
if (!controller) {
|
|
35385
|
+
const shared = {
|
|
35386
|
+
commit: db2.prepare("COMMIT", self2, false),
|
|
35387
|
+
rollback: db2.prepare("ROLLBACK", self2, false),
|
|
35388
|
+
savepoint: db2.prepare("SAVEPOINT `\t_bs3.\t`", self2, false),
|
|
35389
|
+
release: db2.prepare("RELEASE `\t_bs3.\t`", self2, false),
|
|
35390
|
+
rollbackTo: db2.prepare("ROLLBACK TO `\t_bs3.\t`", self2, false)
|
|
35391
|
+
};
|
|
35392
|
+
controllers.set(db2, controller = {
|
|
35393
|
+
default: Object.assign({ begin: db2.prepare("BEGIN", self2, false) }, shared),
|
|
35394
|
+
deferred: Object.assign({ begin: db2.prepare("BEGIN DEFERRED", self2, false) }, shared),
|
|
35395
|
+
immediate: Object.assign({ begin: db2.prepare("BEGIN IMMEDIATE", self2, false) }, shared),
|
|
35396
|
+
exclusive: Object.assign({ begin: db2.prepare("BEGIN EXCLUSIVE", self2, false) }, shared)
|
|
35397
|
+
});
|
|
35398
|
+
}
|
|
35399
|
+
return controller;
|
|
35400
|
+
};
|
|
35401
|
+
var wrapTransaction = (apply2, fn, db2, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
|
35402
|
+
let before, after, undo;
|
|
35403
|
+
if (db2.inTransaction) {
|
|
35404
|
+
before = savepoint;
|
|
35405
|
+
after = release;
|
|
35406
|
+
undo = rollbackTo;
|
|
35407
|
+
} else {
|
|
35408
|
+
before = begin;
|
|
35409
|
+
after = commit;
|
|
35410
|
+
undo = rollback;
|
|
35411
|
+
}
|
|
35412
|
+
before.run();
|
|
35413
|
+
try {
|
|
35414
|
+
const result = apply2.call(fn, this, arguments);
|
|
35415
|
+
if (result && typeof result.then === "function") {
|
|
35416
|
+
throw new TypeError("Transaction function cannot return a promise");
|
|
35417
|
+
}
|
|
35418
|
+
after.run();
|
|
35419
|
+
return result;
|
|
35420
|
+
} catch (ex) {
|
|
35421
|
+
if (db2.inTransaction) {
|
|
35422
|
+
undo.run();
|
|
35423
|
+
if (undo !== rollback)
|
|
35424
|
+
after.run();
|
|
35425
|
+
}
|
|
35426
|
+
throw ex;
|
|
35427
|
+
}
|
|
35428
|
+
};
|
|
35429
|
+
});
|
|
35430
|
+
|
|
35431
|
+
// ../../node_modules/better-sqlite3/lib/methods/pragma.js
|
|
35432
|
+
var require_pragma = __commonJS((exports, module) => {
|
|
35433
|
+
var { getBooleanOption, cppdb } = require_util3();
|
|
35434
|
+
module.exports = function pragma(source, options) {
|
|
35435
|
+
if (options == null)
|
|
35436
|
+
options = {};
|
|
35437
|
+
if (typeof source !== "string")
|
|
35438
|
+
throw new TypeError("Expected first argument to be a string");
|
|
35439
|
+
if (typeof options !== "object")
|
|
35440
|
+
throw new TypeError("Expected second argument to be an options object");
|
|
35441
|
+
const simple = getBooleanOption(options, "simple");
|
|
35442
|
+
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
|
|
35443
|
+
return simple ? stmt.pluck().get() : stmt.all();
|
|
35444
|
+
};
|
|
35445
|
+
});
|
|
35446
|
+
|
|
35447
|
+
// ../../node_modules/better-sqlite3/lib/methods/backup.js
|
|
35448
|
+
var require_backup = __commonJS((exports, module) => {
|
|
35449
|
+
var fs4 = __require("fs");
|
|
35450
|
+
var path = __require("path");
|
|
35451
|
+
var { promisify: promisify2 } = __require("util");
|
|
35452
|
+
var { cppdb } = require_util3();
|
|
35453
|
+
var fsAccess = promisify2(fs4.access);
|
|
35454
|
+
module.exports = async function backup(filename, options) {
|
|
35455
|
+
if (options == null)
|
|
35456
|
+
options = {};
|
|
35457
|
+
if (typeof filename !== "string")
|
|
35458
|
+
throw new TypeError("Expected first argument to be a string");
|
|
35459
|
+
if (typeof options !== "object")
|
|
35460
|
+
throw new TypeError("Expected second argument to be an options object");
|
|
35461
|
+
filename = filename.trim();
|
|
35462
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
35463
|
+
const handler13 = "progress" in options ? options.progress : null;
|
|
35464
|
+
if (!filename)
|
|
35465
|
+
throw new TypeError("Backup filename cannot be an empty string");
|
|
35466
|
+
if (filename === ":memory:")
|
|
35467
|
+
throw new TypeError('Invalid backup filename ":memory:"');
|
|
35468
|
+
if (typeof attachedName !== "string")
|
|
35469
|
+
throw new TypeError('Expected the "attached" option to be a string');
|
|
35470
|
+
if (!attachedName)
|
|
35471
|
+
throw new TypeError('The "attached" option cannot be an empty string');
|
|
35472
|
+
if (handler13 != null && typeof handler13 !== "function")
|
|
35473
|
+
throw new TypeError('Expected the "progress" option to be a function');
|
|
35474
|
+
await fsAccess(path.dirname(filename)).catch(() => {
|
|
35475
|
+
throw new TypeError("Cannot save backup because the directory does not exist");
|
|
35476
|
+
});
|
|
35477
|
+
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
|
35478
|
+
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler13 || null);
|
|
35479
|
+
};
|
|
35480
|
+
var runBackup = (backup, handler13) => {
|
|
35481
|
+
let rate = 0;
|
|
35482
|
+
let useDefault = true;
|
|
35483
|
+
return new Promise((resolve4, reject) => {
|
|
35484
|
+
setImmediate(function step() {
|
|
35485
|
+
try {
|
|
35486
|
+
const progress = backup.transfer(rate);
|
|
35487
|
+
if (!progress.remainingPages) {
|
|
35488
|
+
backup.close();
|
|
35489
|
+
resolve4(progress);
|
|
35490
|
+
return;
|
|
35491
|
+
}
|
|
35492
|
+
if (useDefault) {
|
|
35493
|
+
useDefault = false;
|
|
35494
|
+
rate = 100;
|
|
35495
|
+
}
|
|
35496
|
+
if (handler13) {
|
|
35497
|
+
const ret = handler13(progress);
|
|
35498
|
+
if (ret !== undefined) {
|
|
35499
|
+
if (typeof ret === "number" && ret === ret)
|
|
35500
|
+
rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
|
|
35501
|
+
else
|
|
35502
|
+
throw new TypeError("Expected progress callback to return a number or undefined");
|
|
35503
|
+
}
|
|
35504
|
+
}
|
|
35505
|
+
setImmediate(step);
|
|
35506
|
+
} catch (err) {
|
|
35507
|
+
backup.close();
|
|
35508
|
+
reject(err);
|
|
35509
|
+
}
|
|
35510
|
+
});
|
|
35511
|
+
});
|
|
35512
|
+
};
|
|
35513
|
+
});
|
|
35514
|
+
|
|
35515
|
+
// ../../node_modules/better-sqlite3/lib/methods/serialize.js
|
|
35516
|
+
var require_serialize = __commonJS((exports, module) => {
|
|
35517
|
+
var { cppdb } = require_util3();
|
|
35518
|
+
module.exports = function serialize(options) {
|
|
35519
|
+
if (options == null)
|
|
35520
|
+
options = {};
|
|
35521
|
+
if (typeof options !== "object")
|
|
35522
|
+
throw new TypeError("Expected first argument to be an options object");
|
|
35523
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
35524
|
+
if (typeof attachedName !== "string")
|
|
35525
|
+
throw new TypeError('Expected the "attached" option to be a string');
|
|
35526
|
+
if (!attachedName)
|
|
35527
|
+
throw new TypeError('The "attached" option cannot be an empty string');
|
|
35528
|
+
return this[cppdb].serialize(attachedName);
|
|
35529
|
+
};
|
|
35530
|
+
});
|
|
35531
|
+
|
|
35532
|
+
// ../../node_modules/better-sqlite3/lib/methods/function.js
|
|
35533
|
+
var require_function = __commonJS((exports, module) => {
|
|
35534
|
+
var { getBooleanOption, cppdb } = require_util3();
|
|
35535
|
+
module.exports = function defineFunction(name17, options, fn) {
|
|
35536
|
+
if (options == null)
|
|
35537
|
+
options = {};
|
|
35538
|
+
if (typeof options === "function") {
|
|
35539
|
+
fn = options;
|
|
35540
|
+
options = {};
|
|
35541
|
+
}
|
|
35542
|
+
if (typeof name17 !== "string")
|
|
35543
|
+
throw new TypeError("Expected first argument to be a string");
|
|
35544
|
+
if (typeof fn !== "function")
|
|
35545
|
+
throw new TypeError("Expected last argument to be a function");
|
|
35546
|
+
if (typeof options !== "object")
|
|
35547
|
+
throw new TypeError("Expected second argument to be an options object");
|
|
35548
|
+
if (!name17)
|
|
35549
|
+
throw new TypeError("User-defined function name cannot be an empty string");
|
|
35550
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
35551
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
35552
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
35553
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
35554
|
+
let argCount = -1;
|
|
35555
|
+
if (!varargs) {
|
|
35556
|
+
argCount = fn.length;
|
|
35557
|
+
if (!Number.isInteger(argCount) || argCount < 0)
|
|
35558
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
35559
|
+
if (argCount > 100)
|
|
35560
|
+
throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
35561
|
+
}
|
|
35562
|
+
this[cppdb].function(fn, name17, argCount, safeIntegers, deterministic, directOnly);
|
|
35563
|
+
return this;
|
|
35564
|
+
};
|
|
35565
|
+
});
|
|
35566
|
+
|
|
35567
|
+
// ../../node_modules/better-sqlite3/lib/methods/aggregate.js
|
|
35568
|
+
var require_aggregate = __commonJS((exports, module) => {
|
|
35569
|
+
var { getBooleanOption, cppdb } = require_util3();
|
|
35570
|
+
module.exports = function defineAggregate(name17, options) {
|
|
35571
|
+
if (typeof name17 !== "string")
|
|
35572
|
+
throw new TypeError("Expected first argument to be a string");
|
|
35573
|
+
if (typeof options !== "object" || options === null)
|
|
35574
|
+
throw new TypeError("Expected second argument to be an options object");
|
|
35575
|
+
if (!name17)
|
|
35576
|
+
throw new TypeError("User-defined function name cannot be an empty string");
|
|
35577
|
+
const start = "start" in options ? options.start : null;
|
|
35578
|
+
const step = getFunctionOption(options, "step", true);
|
|
35579
|
+
const inverse = getFunctionOption(options, "inverse", false);
|
|
35580
|
+
const result = getFunctionOption(options, "result", false);
|
|
35581
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
35582
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
35583
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
35584
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
35585
|
+
let argCount = -1;
|
|
35586
|
+
if (!varargs) {
|
|
35587
|
+
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
|
35588
|
+
if (argCount > 0)
|
|
35589
|
+
argCount -= 1;
|
|
35590
|
+
if (argCount > 100)
|
|
35591
|
+
throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
35592
|
+
}
|
|
35593
|
+
this[cppdb].aggregate(start, step, inverse, result, name17, argCount, safeIntegers, deterministic, directOnly);
|
|
35594
|
+
return this;
|
|
35595
|
+
};
|
|
35596
|
+
var getFunctionOption = (options, key, required2) => {
|
|
35597
|
+
const value = key in options ? options[key] : null;
|
|
35598
|
+
if (typeof value === "function")
|
|
35599
|
+
return value;
|
|
35600
|
+
if (value != null)
|
|
35601
|
+
throw new TypeError(`Expected the "${key}" option to be a function`);
|
|
35602
|
+
if (required2)
|
|
35603
|
+
throw new TypeError(`Missing required option "${key}"`);
|
|
35604
|
+
return null;
|
|
35605
|
+
};
|
|
35606
|
+
var getLength = ({ length }) => {
|
|
35607
|
+
if (Number.isInteger(length) && length >= 0)
|
|
35608
|
+
return length;
|
|
35609
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
35610
|
+
};
|
|
35611
|
+
});
|
|
35612
|
+
|
|
35613
|
+
// ../../node_modules/better-sqlite3/lib/methods/table.js
|
|
35614
|
+
var require_table = __commonJS((exports, module) => {
|
|
35615
|
+
var { cppdb } = require_util3();
|
|
35616
|
+
module.exports = function defineTable(name17, factory) {
|
|
35617
|
+
if (typeof name17 !== "string")
|
|
35618
|
+
throw new TypeError("Expected first argument to be a string");
|
|
35619
|
+
if (!name17)
|
|
35620
|
+
throw new TypeError("Virtual table module name cannot be an empty string");
|
|
35621
|
+
let eponymous = false;
|
|
35622
|
+
if (typeof factory === "object" && factory !== null) {
|
|
35623
|
+
eponymous = true;
|
|
35624
|
+
factory = defer(parseTableDefinition(factory, "used", name17));
|
|
35625
|
+
} else {
|
|
35626
|
+
if (typeof factory !== "function")
|
|
35627
|
+
throw new TypeError("Expected second argument to be a function or a table definition object");
|
|
35628
|
+
factory = wrapFactory(factory);
|
|
35629
|
+
}
|
|
35630
|
+
this[cppdb].table(factory, name17, eponymous);
|
|
35631
|
+
return this;
|
|
35632
|
+
};
|
|
35633
|
+
function wrapFactory(factory) {
|
|
35634
|
+
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
|
35635
|
+
const thisObject = {
|
|
35636
|
+
module: moduleName,
|
|
35637
|
+
database: databaseName,
|
|
35638
|
+
table: tableName
|
|
35639
|
+
};
|
|
35640
|
+
const def = apply2.call(factory, thisObject, args);
|
|
35641
|
+
if (typeof def !== "object" || def === null) {
|
|
35642
|
+
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
|
35643
|
+
}
|
|
35644
|
+
return parseTableDefinition(def, "returned", moduleName);
|
|
35645
|
+
};
|
|
35646
|
+
}
|
|
35647
|
+
function parseTableDefinition(def, verb, moduleName) {
|
|
35648
|
+
if (!hasOwnProperty10.call(def, "rows")) {
|
|
35649
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
|
35650
|
+
}
|
|
35651
|
+
if (!hasOwnProperty10.call(def, "columns")) {
|
|
35652
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
|
35653
|
+
}
|
|
35654
|
+
const rows = def.rows;
|
|
35655
|
+
if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
|
35656
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
|
35657
|
+
}
|
|
35658
|
+
let columns = def.columns;
|
|
35659
|
+
if (!Array.isArray(columns) || !(columns = [...columns]).every((x2) => typeof x2 === "string")) {
|
|
35660
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
|
35661
|
+
}
|
|
35662
|
+
if (columns.length !== new Set(columns).size) {
|
|
35663
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
|
35664
|
+
}
|
|
35665
|
+
if (!columns.length) {
|
|
35666
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
|
35667
|
+
}
|
|
35668
|
+
let parameters;
|
|
35669
|
+
if (hasOwnProperty10.call(def, "parameters")) {
|
|
35670
|
+
parameters = def.parameters;
|
|
35671
|
+
if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x2) => typeof x2 === "string")) {
|
|
35672
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
|
35673
|
+
}
|
|
35674
|
+
} else {
|
|
35675
|
+
parameters = inferParameters(rows);
|
|
35676
|
+
}
|
|
35677
|
+
if (parameters.length !== new Set(parameters).size) {
|
|
35678
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
|
35679
|
+
}
|
|
35680
|
+
if (parameters.length > 32) {
|
|
35681
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
|
35682
|
+
}
|
|
35683
|
+
for (const parameter of parameters) {
|
|
35684
|
+
if (columns.includes(parameter)) {
|
|
35685
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
|
35686
|
+
}
|
|
35687
|
+
}
|
|
35688
|
+
let safeIntegers = 2;
|
|
35689
|
+
if (hasOwnProperty10.call(def, "safeIntegers")) {
|
|
35690
|
+
const bool = def.safeIntegers;
|
|
35691
|
+
if (typeof bool !== "boolean") {
|
|
35692
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
|
35693
|
+
}
|
|
35694
|
+
safeIntegers = +bool;
|
|
35695
|
+
}
|
|
35696
|
+
let directOnly = false;
|
|
35697
|
+
if (hasOwnProperty10.call(def, "directOnly")) {
|
|
35698
|
+
directOnly = def.directOnly;
|
|
35699
|
+
if (typeof directOnly !== "boolean") {
|
|
35700
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
|
35701
|
+
}
|
|
35702
|
+
}
|
|
35703
|
+
const columnDefinitions = [
|
|
35704
|
+
...parameters.map(identifier).map((str) => `${str} HIDDEN`),
|
|
35705
|
+
...columns.map(identifier)
|
|
35706
|
+
];
|
|
35707
|
+
return [
|
|
35708
|
+
`CREATE TABLE x(${columnDefinitions.join(", ")});`,
|
|
35709
|
+
wrapGenerator(rows, new Map(columns.map((x2, i2) => [x2, parameters.length + i2])), moduleName),
|
|
35710
|
+
parameters,
|
|
35711
|
+
safeIntegers,
|
|
35712
|
+
directOnly
|
|
35713
|
+
];
|
|
35714
|
+
}
|
|
35715
|
+
function wrapGenerator(generator, columnMap, moduleName) {
|
|
35716
|
+
return function* virtualTable(...args) {
|
|
35717
|
+
const output = args.map((x2) => Buffer.isBuffer(x2) ? Buffer.from(x2) : x2);
|
|
35718
|
+
for (let i2 = 0;i2 < columnMap.size; ++i2) {
|
|
35719
|
+
output.push(null);
|
|
35720
|
+
}
|
|
35721
|
+
for (const row of generator(...args)) {
|
|
35722
|
+
if (Array.isArray(row)) {
|
|
35723
|
+
extractRowArray(row, output, columnMap.size, moduleName);
|
|
35724
|
+
yield output;
|
|
35725
|
+
} else if (typeof row === "object" && row !== null) {
|
|
35726
|
+
extractRowObject(row, output, columnMap, moduleName);
|
|
35727
|
+
yield output;
|
|
35728
|
+
} else {
|
|
35729
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
|
35730
|
+
}
|
|
35731
|
+
}
|
|
35732
|
+
};
|
|
35733
|
+
}
|
|
35734
|
+
function extractRowArray(row, output, columnCount, moduleName) {
|
|
35735
|
+
if (row.length !== columnCount) {
|
|
35736
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
|
35737
|
+
}
|
|
35738
|
+
const offset = output.length - columnCount;
|
|
35739
|
+
for (let i2 = 0;i2 < columnCount; ++i2) {
|
|
35740
|
+
output[i2 + offset] = row[i2];
|
|
35741
|
+
}
|
|
35742
|
+
}
|
|
35743
|
+
function extractRowObject(row, output, columnMap, moduleName) {
|
|
35744
|
+
let count = 0;
|
|
35745
|
+
for (const key of Object.keys(row)) {
|
|
35746
|
+
const index = columnMap.get(key);
|
|
35747
|
+
if (index === undefined) {
|
|
35748
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
|
35749
|
+
}
|
|
35750
|
+
output[index] = row[key];
|
|
35751
|
+
count += 1;
|
|
35752
|
+
}
|
|
35753
|
+
if (count !== columnMap.size) {
|
|
35754
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
|
35755
|
+
}
|
|
35756
|
+
}
|
|
35757
|
+
function inferParameters({ length }) {
|
|
35758
|
+
if (!Number.isInteger(length) || length < 0) {
|
|
35759
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
35760
|
+
}
|
|
35761
|
+
const params = [];
|
|
35762
|
+
for (let i2 = 0;i2 < length; ++i2) {
|
|
35763
|
+
params.push(`$${i2 + 1}`);
|
|
35764
|
+
}
|
|
35765
|
+
return params;
|
|
35766
|
+
}
|
|
35767
|
+
var { hasOwnProperty: hasOwnProperty10 } = Object.prototype;
|
|
35768
|
+
var { apply: apply2 } = Function.prototype;
|
|
35769
|
+
var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {});
|
|
35770
|
+
var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
|
|
35771
|
+
var defer = (x2) => () => x2;
|
|
35772
|
+
});
|
|
35773
|
+
|
|
35774
|
+
// ../../node_modules/better-sqlite3/lib/methods/inspect.js
|
|
35775
|
+
var require_inspect = __commonJS((exports, module) => {
|
|
35776
|
+
var DatabaseInspection = function Database() {};
|
|
35777
|
+
module.exports = function inspect(depth, opts) {
|
|
35778
|
+
return Object.assign(new DatabaseInspection, this);
|
|
35779
|
+
};
|
|
35780
|
+
});
|
|
35781
|
+
|
|
35782
|
+
// ../../node_modules/better-sqlite3/lib/database.js
|
|
35783
|
+
var require_database = __commonJS((exports, module) => {
|
|
35784
|
+
var fs4 = __require("fs");
|
|
35785
|
+
var path = __require("path");
|
|
35786
|
+
var util2 = require_util3();
|
|
35787
|
+
var SqliteError = require_sqlite_error();
|
|
35788
|
+
var DEFAULT_ADDON;
|
|
35789
|
+
function Database(filenameGiven, options) {
|
|
35790
|
+
if (new.target == null) {
|
|
35791
|
+
return new Database(filenameGiven, options);
|
|
35792
|
+
}
|
|
35793
|
+
let buffer;
|
|
35794
|
+
if (Buffer.isBuffer(filenameGiven)) {
|
|
35795
|
+
buffer = filenameGiven;
|
|
35796
|
+
filenameGiven = ":memory:";
|
|
35797
|
+
}
|
|
35798
|
+
if (filenameGiven == null)
|
|
35799
|
+
filenameGiven = "";
|
|
35800
|
+
if (options == null)
|
|
35801
|
+
options = {};
|
|
35802
|
+
if (typeof filenameGiven !== "string")
|
|
35803
|
+
throw new TypeError("Expected first argument to be a string");
|
|
35804
|
+
if (typeof options !== "object")
|
|
35805
|
+
throw new TypeError("Expected second argument to be an options object");
|
|
35806
|
+
if ("readOnly" in options)
|
|
35807
|
+
throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
|
35808
|
+
if ("memory" in options)
|
|
35809
|
+
throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
|
35810
|
+
const filename = filenameGiven.trim();
|
|
35811
|
+
const anonymous = filename === "" || filename === ":memory:";
|
|
35812
|
+
const readonly2 = util2.getBooleanOption(options, "readonly");
|
|
35813
|
+
const fileMustExist = util2.getBooleanOption(options, "fileMustExist");
|
|
35814
|
+
const timeout = "timeout" in options ? options.timeout : 5000;
|
|
35815
|
+
const verbose = "verbose" in options ? options.verbose : null;
|
|
35816
|
+
const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
|
|
35817
|
+
if (readonly2 && anonymous && !buffer)
|
|
35818
|
+
throw new TypeError("In-memory/temporary databases cannot be readonly");
|
|
35819
|
+
if (!Number.isInteger(timeout) || timeout < 0)
|
|
35820
|
+
throw new TypeError('Expected the "timeout" option to be a positive integer');
|
|
35821
|
+
if (timeout > 2147483647)
|
|
35822
|
+
throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
|
35823
|
+
if (verbose != null && typeof verbose !== "function")
|
|
35824
|
+
throw new TypeError('Expected the "verbose" option to be a function');
|
|
35825
|
+
if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object")
|
|
35826
|
+
throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
|
|
35827
|
+
let addon;
|
|
35828
|
+
if (nativeBinding == null) {
|
|
35829
|
+
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
|
|
35830
|
+
} else if (typeof nativeBinding === "string") {
|
|
35831
|
+
const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
35832
|
+
addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
|
|
35833
|
+
} else {
|
|
35834
|
+
addon = nativeBinding;
|
|
35835
|
+
}
|
|
35836
|
+
if (!addon.isInitialized) {
|
|
35837
|
+
addon.setErrorConstructor(SqliteError);
|
|
35838
|
+
addon.isInitialized = true;
|
|
35839
|
+
}
|
|
35840
|
+
if (!anonymous && !filename.startsWith("file:") && !fs4.existsSync(path.dirname(filename))) {
|
|
35841
|
+
throw new TypeError("Cannot open database because the directory does not exist");
|
|
35842
|
+
}
|
|
35843
|
+
Object.defineProperties(this, {
|
|
35844
|
+
[util2.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly2, fileMustExist, timeout, verbose || null, buffer || null) },
|
|
35845
|
+
...wrappers.getters
|
|
35846
|
+
});
|
|
35847
|
+
}
|
|
35848
|
+
var wrappers = require_wrappers();
|
|
35849
|
+
Database.prototype.prepare = wrappers.prepare;
|
|
35850
|
+
Database.prototype.transaction = require_transaction();
|
|
35851
|
+
Database.prototype.pragma = require_pragma();
|
|
35852
|
+
Database.prototype.backup = require_backup();
|
|
35853
|
+
Database.prototype.serialize = require_serialize();
|
|
35854
|
+
Database.prototype.function = require_function();
|
|
35855
|
+
Database.prototype.aggregate = require_aggregate();
|
|
35856
|
+
Database.prototype.table = require_table();
|
|
35857
|
+
Database.prototype.loadExtension = wrappers.loadExtension;
|
|
35858
|
+
Database.prototype.exec = wrappers.exec;
|
|
35859
|
+
Database.prototype.close = wrappers.close;
|
|
35860
|
+
Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
|
|
35861
|
+
Database.prototype.unsafeMode = wrappers.unsafeMode;
|
|
35862
|
+
Database.prototype[util2.inspect] = require_inspect();
|
|
35863
|
+
module.exports = Database;
|
|
35864
|
+
});
|
|
35865
|
+
|
|
35866
|
+
// ../../node_modules/better-sqlite3/lib/index.js
|
|
35867
|
+
var require_lib2 = __commonJS((exports, module) => {
|
|
35868
|
+
module.exports = require_database();
|
|
35869
|
+
module.exports.SqliteError = require_sqlite_error();
|
|
35870
|
+
});
|
|
35871
|
+
|
|
35107
35872
|
// src/config.ts
|
|
35108
35873
|
import { existsSync, readFileSync } from "node:fs";
|
|
35109
35874
|
import { readFile } from "node:fs/promises";
|
|
@@ -48641,6 +49406,13 @@ function date4(params) {
|
|
|
48641
49406
|
|
|
48642
49407
|
// ../../node_modules/zod/v4/classic/external.js
|
|
48643
49408
|
config(en_default());
|
|
49409
|
+
// ../core/src/config/memory.ts
|
|
49410
|
+
var memoryConfigSchema = exports_external.object({
|
|
49411
|
+
enabled: exports_external.boolean().optional().default(true),
|
|
49412
|
+
type: exports_external.enum(["sqlite", "memory"]).optional().default("sqlite"),
|
|
49413
|
+
path: exports_external.string().optional().default("~/.config/polka-codes/memory.sqlite")
|
|
49414
|
+
}).strict().optional();
|
|
49415
|
+
|
|
48644
49416
|
// ../core/src/config.ts
|
|
48645
49417
|
var ruleSchema = exports_external.union([
|
|
48646
49418
|
exports_external.string(),
|
|
@@ -48661,7 +49433,8 @@ var providerConfigSchema = exports_external.object({
|
|
|
48661
49433
|
location: exports_external.string().optional(),
|
|
48662
49434
|
project: exports_external.string().optional(),
|
|
48663
49435
|
keyFile: exports_external.string().optional(),
|
|
48664
|
-
baseUrl: exports_external.string().optional()
|
|
49436
|
+
baseUrl: exports_external.string().optional(),
|
|
49437
|
+
name: exports_external.string().optional()
|
|
48665
49438
|
});
|
|
48666
49439
|
var providerModelSchema = exports_external.object({
|
|
48667
49440
|
provider: exports_external.string().optional(),
|
|
@@ -48703,6 +49476,51 @@ var mcpServerConfigSchema = exports_external.object({
|
|
|
48703
49476
|
parameters: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
|
|
48704
49477
|
}).strict())).optional()
|
|
48705
49478
|
}).strict();
|
|
49479
|
+
var agentContinuousImprovementSchema = exports_external.object({
|
|
49480
|
+
sleepTimeOnNoTasks: exports_external.number().int().optional(),
|
|
49481
|
+
sleepTimeBetweenTasks: exports_external.number().int().optional(),
|
|
49482
|
+
maxCycles: exports_external.number().int().optional()
|
|
49483
|
+
}).strict().optional();
|
|
49484
|
+
var agentDiscoverySchema = exports_external.object({
|
|
49485
|
+
enabledStrategies: exports_external.array(exports_external.string()).optional(),
|
|
49486
|
+
cacheTime: exports_external.number().int().optional(),
|
|
49487
|
+
checkChanges: exports_external.boolean().optional()
|
|
49488
|
+
}).strict().optional();
|
|
49489
|
+
var agentSafetySchema = exports_external.object({
|
|
49490
|
+
enabledChecks: exports_external.array(exports_external.string()).optional(),
|
|
49491
|
+
blockDestructive: exports_external.boolean().optional(),
|
|
49492
|
+
maxFileSize: exports_external.number().int().optional()
|
|
49493
|
+
}).strict().optional();
|
|
49494
|
+
var agentHealthCheckSchema = exports_external.object({
|
|
49495
|
+
enabled: exports_external.boolean().optional(),
|
|
49496
|
+
interval: exports_external.number().int().optional()
|
|
49497
|
+
}).strict().optional();
|
|
49498
|
+
var agentApprovalSchema = exports_external.object({
|
|
49499
|
+
level: exports_external.enum(["none", "destructive", "commits", "all"]).optional(),
|
|
49500
|
+
autoApproveSafeTasks: exports_external.boolean().optional(),
|
|
49501
|
+
maxAutoApprovalCost: exports_external.number().optional()
|
|
49502
|
+
}).strict().optional();
|
|
49503
|
+
var agentSchema = exports_external.object({
|
|
49504
|
+
preset: exports_external.string().optional(),
|
|
49505
|
+
strategy: exports_external.enum(["goal-directed", "continuous-improvement"]).optional(),
|
|
49506
|
+
continueOnCompletion: exports_external.boolean().optional(),
|
|
49507
|
+
maxIterations: exports_external.number().int().optional(),
|
|
49508
|
+
timeout: exports_external.number().int().optional(),
|
|
49509
|
+
requireApprovalFor: exports_external.enum(["none", "destructive", "commits", "all"]).optional(),
|
|
49510
|
+
autoApproveSafeTasks: exports_external.boolean().optional(),
|
|
49511
|
+
maxAutoApprovalCost: exports_external.number().optional(),
|
|
49512
|
+
pauseOnError: exports_external.boolean().optional(),
|
|
49513
|
+
workingBranch: exports_external.string().optional(),
|
|
49514
|
+
destructiveOperations: exports_external.array(exports_external.string()).optional(),
|
|
49515
|
+
maxConcurrency: exports_external.number().int().optional(),
|
|
49516
|
+
autoSaveInterval: exports_external.number().int().optional(),
|
|
49517
|
+
workingDir: exports_external.string().optional(),
|
|
49518
|
+
continuousImprovement: agentContinuousImprovementSchema,
|
|
49519
|
+
discovery: agentDiscoverySchema,
|
|
49520
|
+
safety: agentSafetySchema,
|
|
49521
|
+
healthCheck: agentHealthCheckSchema,
|
|
49522
|
+
approval: agentApprovalSchema
|
|
49523
|
+
}).strict().optional();
|
|
48706
49524
|
var configSchema = exports_external.object({
|
|
48707
49525
|
prices: exports_external.record(exports_external.string(), exports_external.record(exports_external.string(), exports_external.object({
|
|
48708
49526
|
inputPrice: exports_external.number().optional(),
|
|
@@ -48726,7 +49544,9 @@ var configSchema = exports_external.object({
|
|
|
48726
49544
|
}).optional(),
|
|
48727
49545
|
mcpServers: exports_external.record(exports_external.string(), mcpServerConfigSchema).optional(),
|
|
48728
49546
|
rules: exports_external.array(ruleSchema).optional().or(exports_external.string()).optional(),
|
|
48729
|
-
excludeFiles: exports_external.array(exports_external.string()).optional()
|
|
49547
|
+
excludeFiles: exports_external.array(exports_external.string()).optional(),
|
|
49548
|
+
agent: agentSchema,
|
|
49549
|
+
memory: memoryConfigSchema
|
|
48730
49550
|
}).strict().nullish();
|
|
48731
49551
|
// ../core/src/skills/constants.ts
|
|
48732
49552
|
var SKILL_LIMITS = {
|
|
@@ -48923,16 +49743,18 @@ var askFollowupQuestion_default = {
|
|
|
48923
49743
|
...toolInfo,
|
|
48924
49744
|
handler
|
|
48925
49745
|
};
|
|
48926
|
-
// ../core/src/tools/
|
|
48927
|
-
function
|
|
49746
|
+
// ../core/src/tools/response-builders.ts
|
|
49747
|
+
function createProviderErrorResponse(capability) {
|
|
48928
49748
|
return {
|
|
48929
49749
|
success: false,
|
|
48930
49750
|
message: {
|
|
48931
49751
|
type: "error-text",
|
|
48932
|
-
value: `Not possible to ${
|
|
49752
|
+
value: `Not possible to ${capability}.`
|
|
48933
49753
|
}
|
|
48934
49754
|
};
|
|
48935
49755
|
}
|
|
49756
|
+
|
|
49757
|
+
// ../core/src/tools/utils.ts
|
|
48936
49758
|
function preprocessBoolean(val) {
|
|
48937
49759
|
return typeof val === "string" ? val.toLowerCase() === "true" : val;
|
|
48938
49760
|
}
|
|
@@ -48970,7 +49792,7 @@ var toolInfo2 = {
|
|
|
48970
49792
|
};
|
|
48971
49793
|
var handler2 = async (provider, args) => {
|
|
48972
49794
|
if (!provider.executeCommand) {
|
|
48973
|
-
return
|
|
49795
|
+
return createProviderErrorResponse("execute command. Abort");
|
|
48974
49796
|
}
|
|
48975
49797
|
const { command, requiresApproval } = toolInfo2.parameters.parse(args);
|
|
48976
49798
|
try {
|
|
@@ -49123,7 +49945,7 @@ var toolInfo4 = {
|
|
|
49123
49945
|
};
|
|
49124
49946
|
var handler4 = async (provider, args) => {
|
|
49125
49947
|
if (!provider.listFiles) {
|
|
49126
|
-
return
|
|
49948
|
+
return createProviderErrorResponse("list files");
|
|
49127
49949
|
}
|
|
49128
49950
|
const { path, maxCount, recursive, includeIgnored } = toolInfo4.parameters.parse(args);
|
|
49129
49951
|
const [files, limitReached] = await provider.listFiles(path, recursive, maxCount, includeIgnored);
|
|
@@ -49197,14 +50019,40 @@ var readBinaryFile_default = {
|
|
|
49197
50019
|
// ../core/src/tools/readFile.ts
|
|
49198
50020
|
var toolInfo6 = {
|
|
49199
50021
|
name: "readFile",
|
|
49200
|
-
description:
|
|
50022
|
+
description: `Request to read the contents of one or multiple files at the specified paths.
|
|
50023
|
+
|
|
50024
|
+
When to use:
|
|
50025
|
+
- Examining file contents you don't know
|
|
50026
|
+
- Analyzing code, reviewing text files, extracting configuration info
|
|
50027
|
+
- Reading multiple files at once (use comma-separated paths)
|
|
50028
|
+
- Understanding file structure before editing
|
|
50029
|
+
|
|
50030
|
+
When NOT to use:
|
|
50031
|
+
- For file existence checks: Use listFiles instead
|
|
50032
|
+
- For searching within files: Use grep instead
|
|
50033
|
+
- For file name searches: Use searchFiles instead
|
|
50034
|
+
- Prefer this tool over executeCommand with cat/head/tail
|
|
50035
|
+
|
|
50036
|
+
Features:
|
|
50037
|
+
- Supports comma-separated paths for multiple files
|
|
50038
|
+
- Line numbers included for easy reference
|
|
50039
|
+
- Optional offset/limit for partial file reading
|
|
50040
|
+
- Automatically handles different file types
|
|
50041
|
+
|
|
50042
|
+
IMPORTANT:
|
|
50043
|
+
- Line numbers are included for easy reference
|
|
50044
|
+
- Use offset/limit for large files to read specific sections`,
|
|
49201
50045
|
parameters: exports_external.object({
|
|
49202
50046
|
path: exports_external.preprocess((val) => {
|
|
49203
50047
|
if (!val)
|
|
49204
50048
|
return [];
|
|
49205
|
-
|
|
49206
|
-
|
|
50049
|
+
if (Array.isArray(val)) {
|
|
50050
|
+
return val.filter((s) => typeof s === "string" && s.length > 0);
|
|
50051
|
+
}
|
|
50052
|
+
return val.split(",").filter((s) => s.length > 0);
|
|
49207
50053
|
}, exports_external.array(exports_external.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" }),
|
|
50054
|
+
offset: exports_external.number().optional().describe("Skip first N lines (for partial file reading)").meta({ usageValue: "100" }),
|
|
50055
|
+
limit: exports_external.number().optional().describe("Read at most N lines (for partial file reading)").meta({ usageValue: "50" }),
|
|
49208
50056
|
includeIgnored: exports_external.preprocess(preprocessBoolean, exports_external.boolean().nullish().default(false)).describe("Whether to include ignored files. Use true to include files ignored by .gitignore.").meta({ usageValue: "true or false (optional)" })
|
|
49209
50057
|
}).meta({
|
|
49210
50058
|
examples: [
|
|
@@ -49219,23 +50067,55 @@ var toolInfo6 = {
|
|
|
49219
50067
|
input: {
|
|
49220
50068
|
path: "src/main.js,src/index.js"
|
|
49221
50069
|
}
|
|
50070
|
+
},
|
|
50071
|
+
{
|
|
50072
|
+
description: "Read partial file (lines 100-150)",
|
|
50073
|
+
input: {
|
|
50074
|
+
path: "src/large-file.ts",
|
|
50075
|
+
offset: 100,
|
|
50076
|
+
limit: 50
|
|
50077
|
+
}
|
|
49222
50078
|
}
|
|
49223
50079
|
]
|
|
49224
50080
|
})
|
|
49225
50081
|
};
|
|
49226
50082
|
var handler6 = async (provider, args) => {
|
|
49227
50083
|
if (!provider.readFile) {
|
|
49228
|
-
return
|
|
50084
|
+
return createProviderErrorResponse("read file");
|
|
50085
|
+
}
|
|
50086
|
+
const parsed = toolInfo6.parameters.safeParse(args);
|
|
50087
|
+
if (!parsed.success) {
|
|
50088
|
+
return {
|
|
50089
|
+
success: false,
|
|
50090
|
+
message: {
|
|
50091
|
+
type: "error-text",
|
|
50092
|
+
value: `Invalid arguments for readFile: ${parsed.error.message}`
|
|
50093
|
+
}
|
|
50094
|
+
};
|
|
49229
50095
|
}
|
|
49230
|
-
const { path: paths, includeIgnored } =
|
|
50096
|
+
const { path: paths, offset, limit, includeIgnored } = parsed.data;
|
|
49231
50097
|
const resp = [];
|
|
49232
50098
|
for (const path of paths) {
|
|
49233
50099
|
const fileContent = await provider.readFile(path, includeIgnored ?? false);
|
|
49234
50100
|
if (!fileContent) {
|
|
49235
50101
|
resp.push(createFileElement("read_file_file_content", path, undefined, { file_not_found: "true" }));
|
|
49236
|
-
|
|
49237
|
-
resp.push(createFileElement("read_file_file_content", path, fileContent));
|
|
50102
|
+
continue;
|
|
49238
50103
|
}
|
|
50104
|
+
let lines = fileContent.split(`
|
|
50105
|
+
`);
|
|
50106
|
+
const start = offset ?? 0;
|
|
50107
|
+
const end = limit ? start + limit : lines.length;
|
|
50108
|
+
if (offset !== undefined || limit !== undefined) {
|
|
50109
|
+
lines = lines.slice(start, end);
|
|
50110
|
+
}
|
|
50111
|
+
const lineOffset = offset ?? 0;
|
|
50112
|
+
const numberedContent = lines.map((line, i) => {
|
|
50113
|
+
const lineNumber = lineOffset + i + 1;
|
|
50114
|
+
const paddedNumber = String(lineNumber).padStart(6, " ");
|
|
50115
|
+
return `${paddedNumber}→${line}`;
|
|
50116
|
+
}).join(`
|
|
50117
|
+
`);
|
|
50118
|
+
resp.push(createFileElement("read_file_file_content", path, numberedContent));
|
|
49239
50119
|
}
|
|
49240
50120
|
return {
|
|
49241
50121
|
success: true,
|
|
@@ -49269,7 +50149,7 @@ var toolInfo7 = {
|
|
|
49269
50149
|
};
|
|
49270
50150
|
var handler7 = async (provider, args) => {
|
|
49271
50151
|
if (!provider.removeFile) {
|
|
49272
|
-
return
|
|
50152
|
+
return createProviderErrorResponse("remove file");
|
|
49273
50153
|
}
|
|
49274
50154
|
const parsed = toolInfo7.parameters.safeParse(args);
|
|
49275
50155
|
if (!parsed.success) {
|
|
@@ -49432,7 +50312,43 @@ var replaceInFile = (fileContent, diff) => {
|
|
|
49432
50312
|
// ../core/src/tools/replaceInFile.ts
|
|
49433
50313
|
var toolInfo9 = {
|
|
49434
50314
|
name: "replaceInFile",
|
|
49435
|
-
description:
|
|
50315
|
+
description: `Request to replace sections of content in an existing file using
|
|
50316
|
+
SEARCH/REPLACE blocks.
|
|
50317
|
+
|
|
50318
|
+
When to use:
|
|
50319
|
+
- Making targeted changes to specific parts of a file
|
|
50320
|
+
- Replacing variable names, function signatures, imports
|
|
50321
|
+
- Fixing bugs in existing code
|
|
50322
|
+
- When you know the exact content to replace
|
|
50323
|
+
|
|
50324
|
+
When NOT to use:
|
|
50325
|
+
- For creating new files: Use writeToFile instead
|
|
50326
|
+
- For completely replacing file contents: Use writeToFile instead
|
|
50327
|
+
- When you don't know the exact content: Read file first
|
|
50328
|
+
|
|
50329
|
+
SEARCH/REPLACE FORMAT:
|
|
50330
|
+
<<<<<<< SEARCH
|
|
50331
|
+
[exact content to find]
|
|
50332
|
+
=======
|
|
50333
|
+
[new content to replace with]
|
|
50334
|
+
>>>>>>> REPLACE
|
|
50335
|
+
|
|
50336
|
+
Critical rules:
|
|
50337
|
+
1. SEARCH content must match EXACTLY (character-for-character including whitespace)
|
|
50338
|
+
2. Each block replaces only first occurrence
|
|
50339
|
+
3. Include just enough lines for uniqueness (not too many, not too few)
|
|
50340
|
+
4. Keep blocks concise (don't include long unchanged sections)
|
|
50341
|
+
5. List blocks in order they appear in file
|
|
50342
|
+
6. Use multiple blocks for multiple independent changes
|
|
50343
|
+
|
|
50344
|
+
Special operations:
|
|
50345
|
+
- Move code: Two blocks (delete from original + insert at new location)
|
|
50346
|
+
- Delete code: Empty REPLACE section
|
|
50347
|
+
|
|
50348
|
+
IMPORTANT CONSTRAINTS:
|
|
50349
|
+
- SEARCH text must match file content exactly
|
|
50350
|
+
- Each block is independent (doesn't affect other blocks)
|
|
50351
|
+
- Cannot use for appending or inserting without SEARCH context`,
|
|
49436
50352
|
parameters: exports_external.object({
|
|
49437
50353
|
path: exports_external.string().describe("The path of the file to modify").meta({ usageValue: "File path here" }),
|
|
49438
50354
|
diff: exports_external.string().describe(`One or more SEARCH/REPLACE blocks following this exact format:
|
|
@@ -49458,7 +50374,7 @@ Critical rules:
|
|
|
49458
50374
|
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
49459
50375
|
4. Special operations:
|
|
49460
50376
|
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
49461
|
-
* To delete code:
|
|
50377
|
+
* To delete code: Empty REPLACE section`).meta({ usageValue: "Search and replace blocks here" })
|
|
49462
50378
|
}).meta({
|
|
49463
50379
|
examples: [
|
|
49464
50380
|
{
|
|
@@ -49786,7 +50702,27 @@ var UpdateTodoItemOutputSchema = exports_external.object({
|
|
|
49786
50702
|
// ../core/src/tools/writeToFile.ts
|
|
49787
50703
|
var toolInfo12 = {
|
|
49788
50704
|
name: "writeToFile",
|
|
49789
|
-
description:
|
|
50705
|
+
description: `Request to write content to a file at the specified path.
|
|
50706
|
+
|
|
50707
|
+
When to use:
|
|
50708
|
+
- Creating new files
|
|
50709
|
+
- Completely replacing file contents
|
|
50710
|
+
- When you have the complete intended content
|
|
50711
|
+
|
|
50712
|
+
When NOT to use:
|
|
50713
|
+
- For modifying existing files: Use replaceInFile instead
|
|
50714
|
+
- For appending content: Use executeCommand with echo >> instead
|
|
50715
|
+
- For targeted edits: Use replaceInFile instead
|
|
50716
|
+
|
|
50717
|
+
Features:
|
|
50718
|
+
- Automatically creates any directories needed
|
|
50719
|
+
- Overwrites existing files completely
|
|
50720
|
+
- Must provide complete file content (no truncation)
|
|
50721
|
+
|
|
50722
|
+
IMPORTANT CONSTRAINT:
|
|
50723
|
+
- Always provide COMPLETE intended content (no omissions)
|
|
50724
|
+
- Ensure no incorrect escape sequences (<, >, &)
|
|
50725
|
+
- Ensure no unwanted CDATA tags in content`,
|
|
49790
50726
|
parameters: exports_external.object({
|
|
49791
50727
|
path: exports_external.string().describe("The path of the file to write to").meta({ usageValue: "File path here" }),
|
|
49792
50728
|
content: exports_external.string().describe("The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified.").meta({ usageValue: "Your file content here" })
|
|
@@ -49815,7 +50751,7 @@ export default App;
|
|
|
49815
50751
|
};
|
|
49816
50752
|
var handler12 = async (provider, args) => {
|
|
49817
50753
|
if (!provider.writeFile) {
|
|
49818
|
-
return
|
|
50754
|
+
return createProviderErrorResponse("write file");
|
|
49819
50755
|
}
|
|
49820
50756
|
const parsed = toolInfo12.parameters.safeParse(args);
|
|
49821
50757
|
if (!parsed.success) {
|
|
@@ -49827,10 +50763,7 @@ var handler12 = async (provider, args) => {
|
|
|
49827
50763
|
}
|
|
49828
50764
|
};
|
|
49829
50765
|
}
|
|
49830
|
-
|
|
49831
|
-
const trimmedContent = content.trim();
|
|
49832
|
-
if (trimmedContent.startsWith("<![CDATA[") && trimmedContent.endsWith("]]>"))
|
|
49833
|
-
content = trimmedContent.slice(9, -3);
|
|
50766
|
+
const { path, content } = parsed.data;
|
|
49834
50767
|
await provider.writeFile(path, content);
|
|
49835
50768
|
return {
|
|
49836
50769
|
success: true,
|
|
@@ -52979,9 +53912,9 @@ class ZodUnion2 extends ZodType2 {
|
|
|
52979
53912
|
return this._def.options;
|
|
52980
53913
|
}
|
|
52981
53914
|
}
|
|
52982
|
-
ZodUnion2.create = (
|
|
53915
|
+
ZodUnion2.create = (types3, params) => {
|
|
52983
53916
|
return new ZodUnion2({
|
|
52984
|
-
options:
|
|
53917
|
+
options: types3,
|
|
52985
53918
|
typeName: ZodFirstPartyTypeKind2.ZodUnion,
|
|
52986
53919
|
...processCreateParams(params)
|
|
52987
53920
|
});
|
|
@@ -55475,15 +56408,15 @@ var primitiveMappings = {
|
|
|
55475
56408
|
function parseUnionDef(def, refs) {
|
|
55476
56409
|
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
55477
56410
|
if (options.every((x) => (x._def.typeName in primitiveMappings) && (!x._def.checks || !x._def.checks.length))) {
|
|
55478
|
-
const
|
|
56411
|
+
const types3 = options.reduce((types22, x) => {
|
|
55479
56412
|
const type = primitiveMappings[x._def.typeName];
|
|
55480
56413
|
return type && !types22.includes(type) ? [...types22, type] : types22;
|
|
55481
56414
|
}, []);
|
|
55482
56415
|
return {
|
|
55483
|
-
type:
|
|
56416
|
+
type: types3.length > 1 ? types3 : types3[0]
|
|
55484
56417
|
};
|
|
55485
56418
|
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
55486
|
-
const
|
|
56419
|
+
const types3 = options.reduce((acc, x) => {
|
|
55487
56420
|
const type = typeof x._def.value;
|
|
55488
56421
|
switch (type) {
|
|
55489
56422
|
case "string":
|
|
@@ -55502,8 +56435,8 @@ function parseUnionDef(def, refs) {
|
|
|
55502
56435
|
return acc;
|
|
55503
56436
|
}
|
|
55504
56437
|
}, []);
|
|
55505
|
-
if (
|
|
55506
|
-
const uniqueTypes =
|
|
56438
|
+
if (types3.length === options.length) {
|
|
56439
|
+
const uniqueTypes = types3.filter((x, i, a) => a.indexOf(x) === i);
|
|
55507
56440
|
return {
|
|
55508
56441
|
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
55509
56442
|
enum: options.reduce((acc, x) => {
|
|
@@ -60241,9 +61174,9 @@ var moduleExports2 = freeModule2 && freeModule2.exports === freeExports2;
|
|
|
60241
61174
|
var freeProcess = moduleExports2 && _freeGlobal_default.process;
|
|
60242
61175
|
var nodeUtil = function() {
|
|
60243
61176
|
try {
|
|
60244
|
-
var
|
|
60245
|
-
if (
|
|
60246
|
-
return
|
|
61177
|
+
var types4 = freeModule2 && freeModule2.require && freeModule2.require("util").types;
|
|
61178
|
+
if (types4) {
|
|
61179
|
+
return types4;
|
|
60247
61180
|
}
|
|
60248
61181
|
return freeProcess && freeProcess.binding && freeProcess.binding("util");
|
|
60249
61182
|
} catch (e) {}
|
|
@@ -60943,6 +61876,37 @@ var readLocalConfig = (path) => {
|
|
|
60943
61876
|
return;
|
|
60944
61877
|
}
|
|
60945
61878
|
};
|
|
61879
|
+
// src/memory-manager.ts
|
|
61880
|
+
class MemoryManager {
|
|
61881
|
+
store;
|
|
61882
|
+
constructor(store, _cwd) {
|
|
61883
|
+
this.store = store;
|
|
61884
|
+
}
|
|
61885
|
+
async readMemory(topic) {
|
|
61886
|
+
return this.store.readMemory(topic);
|
|
61887
|
+
}
|
|
61888
|
+
async updateMemory(operation, topic, content, metadata) {
|
|
61889
|
+
return this.store.updateMemory(operation, topic, content, metadata);
|
|
61890
|
+
}
|
|
61891
|
+
async queryMemory(query = {}, options) {
|
|
61892
|
+
const finalQuery = {
|
|
61893
|
+
...query
|
|
61894
|
+
};
|
|
61895
|
+
if (!options?.operation && !finalQuery.limit) {
|
|
61896
|
+
finalQuery.limit = 1000;
|
|
61897
|
+
}
|
|
61898
|
+
return this.store.queryMemory(finalQuery, options);
|
|
61899
|
+
}
|
|
61900
|
+
async batchUpdateMemory(operations) {
|
|
61901
|
+
return this.store.batchUpdateMemory(operations);
|
|
61902
|
+
}
|
|
61903
|
+
async getStats() {
|
|
61904
|
+
return this.store.getStats();
|
|
61905
|
+
}
|
|
61906
|
+
close() {
|
|
61907
|
+
this.store.close();
|
|
61908
|
+
}
|
|
61909
|
+
}
|
|
60946
61910
|
// src/provider.ts
|
|
60947
61911
|
import { spawn as spawn2 } from "node:child_process";
|
|
60948
61912
|
import { mkdir, readFile as readFile2, rename, unlink, writeFile } from "node:fs/promises";
|
|
@@ -64308,7 +65272,7 @@ function lookup(path) {
|
|
|
64308
65272
|
}
|
|
64309
65273
|
return $types[extension2] || false;
|
|
64310
65274
|
}
|
|
64311
|
-
function populateMaps(extensions,
|
|
65275
|
+
function populateMaps(extensions, types6) {
|
|
64312
65276
|
Object.keys(db).forEach(function forEachMimeType(type) {
|
|
64313
65277
|
var mime = db[type];
|
|
64314
65278
|
var exts = mime.extensions;
|
|
@@ -64318,10 +65282,10 @@ function populateMaps(extensions, types5) {
|
|
|
64318
65282
|
extensions[type] = exts;
|
|
64319
65283
|
for (var i2 = 0;i2 < exts.length; i2++) {
|
|
64320
65284
|
var extension2 = exts[i2];
|
|
64321
|
-
|
|
64322
|
-
const legacyType = _preferredTypeLegacy(extension2,
|
|
64323
|
-
if (legacyType !==
|
|
64324
|
-
$_extensionConflicts.push([extension2, legacyType,
|
|
65285
|
+
types6[extension2] = _preferredType(extension2, types6[extension2], type);
|
|
65286
|
+
const legacyType = _preferredTypeLegacy(extension2, types6[extension2], type);
|
|
65287
|
+
if (legacyType !== types6[extension2]) {
|
|
65288
|
+
$_extensionConflicts.push([extension2, legacyType, types6[extension2]]);
|
|
64325
65289
|
}
|
|
64326
65290
|
}
|
|
64327
65291
|
});
|
|
@@ -64459,10 +65423,17 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includ
|
|
|
64459
65423
|
|
|
64460
65424
|
// src/utils/searchFiles.ts
|
|
64461
65425
|
import { spawn } from "node:child_process";
|
|
65426
|
+
|
|
65427
|
+
// src/utils/search.constants.ts
|
|
65428
|
+
var SEARCH_CONSTANTS = {
|
|
65429
|
+
DEFAULT_CONTEXT_LINES: 5
|
|
65430
|
+
};
|
|
65431
|
+
|
|
65432
|
+
// src/utils/searchFiles.ts
|
|
64462
65433
|
async function searchFiles(path, regex2, filePattern, cwd, excludeFiles) {
|
|
64463
65434
|
const args = [
|
|
64464
65435
|
"--line-number",
|
|
64465
|
-
|
|
65436
|
+
`--context=${SEARCH_CONSTANTS.DEFAULT_CONTEXT_LINES}`,
|
|
64466
65437
|
"--color=never",
|
|
64467
65438
|
"--with-filename",
|
|
64468
65439
|
"--smart-case"
|
|
@@ -64619,35 +65590,35 @@ var getProvider = (options = {}) => {
|
|
|
64619
65590
|
}
|
|
64620
65591
|
},
|
|
64621
65592
|
listMemoryTopics: async () => {
|
|
64622
|
-
const
|
|
64623
|
-
return Object.keys(
|
|
65593
|
+
const memory2 = await memoryStore.read() ?? {};
|
|
65594
|
+
return Object.keys(memory2);
|
|
64624
65595
|
},
|
|
64625
65596
|
readMemory: async (topic = defaultMemoryTopic) => {
|
|
64626
|
-
const
|
|
64627
|
-
return
|
|
65597
|
+
const memory2 = await memoryStore.read() ?? {};
|
|
65598
|
+
return memory2[topic];
|
|
64628
65599
|
},
|
|
64629
65600
|
updateMemory: async (operation, topic, content) => {
|
|
64630
65601
|
const memoryTopic = topic ?? defaultMemoryTopic;
|
|
64631
|
-
const
|
|
65602
|
+
const memory2 = await memoryStore.read() ?? {};
|
|
64632
65603
|
switch (operation) {
|
|
64633
65604
|
case "append":
|
|
64634
65605
|
if (content === undefined) {
|
|
64635
65606
|
throw new Error("Content is required for append operation.");
|
|
64636
65607
|
}
|
|
64637
|
-
|
|
65608
|
+
memory2[memoryTopic] = `${memory2[memoryTopic] || ""}
|
|
64638
65609
|
${content}`;
|
|
64639
65610
|
break;
|
|
64640
65611
|
case "replace":
|
|
64641
65612
|
if (content === undefined) {
|
|
64642
65613
|
throw new Error("Content is required for replace operation.");
|
|
64643
65614
|
}
|
|
64644
|
-
|
|
65615
|
+
memory2[memoryTopic] = content;
|
|
64645
65616
|
break;
|
|
64646
65617
|
case "remove":
|
|
64647
|
-
delete
|
|
65618
|
+
delete memory2[memoryTopic];
|
|
64648
65619
|
break;
|
|
64649
65620
|
}
|
|
64650
|
-
await memoryStore.write(
|
|
65621
|
+
await memoryStore.write(memory2);
|
|
64651
65622
|
},
|
|
64652
65623
|
readFile: async (path, includeIgnored) => {
|
|
64653
65624
|
if (!includeIgnored && ig.ignores(path)) {
|
|
@@ -64814,6 +65785,409 @@ ${content}`;
|
|
|
64814
65785
|
}
|
|
64815
65786
|
return provider2;
|
|
64816
65787
|
};
|
|
65788
|
+
// src/sqlite-memory-store.ts
|
|
65789
|
+
var import_better_sqlite3 = __toESM(require_lib2(), 1);
|
|
65790
|
+
import { randomUUID } from "node:crypto";
|
|
65791
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
65792
|
+
import { mkdir as mkdir2, rename as rename2 } from "node:fs/promises";
|
|
65793
|
+
import { dirname as dirname2, resolve as resolve4 } from "node:path";
|
|
65794
|
+
|
|
65795
|
+
class SQLiteMemoryStore {
|
|
65796
|
+
db = null;
|
|
65797
|
+
dbPromise = null;
|
|
65798
|
+
config;
|
|
65799
|
+
currentScope;
|
|
65800
|
+
maxRetries = 3;
|
|
65801
|
+
retryDelay = 100;
|
|
65802
|
+
static SORT_COLUMNS = {
|
|
65803
|
+
created: "created_at",
|
|
65804
|
+
updated: "updated_at",
|
|
65805
|
+
accessed: "last_accessed",
|
|
65806
|
+
name: "name"
|
|
65807
|
+
};
|
|
65808
|
+
static ALLOWED_SORT_ORDERS = ["asc", "desc"];
|
|
65809
|
+
static ALLOWED_PRIORITIES = ["low", "medium", "high", "critical"];
|
|
65810
|
+
constructor(config3, scope) {
|
|
65811
|
+
this.config = config3;
|
|
65812
|
+
this.currentScope = scope;
|
|
65813
|
+
}
|
|
65814
|
+
async initializeDatabase() {
|
|
65815
|
+
if (this.dbPromise) {
|
|
65816
|
+
return this.dbPromise;
|
|
65817
|
+
}
|
|
65818
|
+
this.dbPromise = (async () => {
|
|
65819
|
+
if (this.db) {
|
|
65820
|
+
return this.db;
|
|
65821
|
+
}
|
|
65822
|
+
const dbPath = this.resolvePath(this.config.path || "~/.config/polka-codes/memory.sqlite");
|
|
65823
|
+
try {
|
|
65824
|
+
const dir = dirname2(dbPath);
|
|
65825
|
+
if (!existsSync2(dir)) {
|
|
65826
|
+
await mkdir2(dir, { recursive: true, mode: 448 });
|
|
65827
|
+
}
|
|
65828
|
+
if (!existsSync2(dbPath)) {
|
|
65829
|
+
const { openSync, closeSync } = await import("node:fs");
|
|
65830
|
+
const fd = openSync(dbPath, "w");
|
|
65831
|
+
closeSync(fd);
|
|
65832
|
+
await import("node:fs/promises").then((fs4) => fs4.chmod(dbPath, 384));
|
|
65833
|
+
}
|
|
65834
|
+
const db2 = new import_better_sqlite3.default(dbPath, {
|
|
65835
|
+
verbose: process.env.SQLITE_DEBUG ? console.log : undefined
|
|
65836
|
+
});
|
|
65837
|
+
this.configurePragmas(db2);
|
|
65838
|
+
this.checkIntegrity(db2);
|
|
65839
|
+
this.initializeSchema(db2);
|
|
65840
|
+
this.db = db2;
|
|
65841
|
+
return db2;
|
|
65842
|
+
} catch (error48) {
|
|
65843
|
+
console.error("[SQLiteMemoryStore] Initialization failed:", error48);
|
|
65844
|
+
if (existsSync2(dbPath)) {
|
|
65845
|
+
const backupPath = `${dbPath}.corrupted.${Date.now()}`;
|
|
65846
|
+
console.warn(`[SQLiteMemoryStore] Backing up corrupted database to: ${backupPath}`);
|
|
65847
|
+
try {
|
|
65848
|
+
await rename2(dbPath, backupPath);
|
|
65849
|
+
} catch (backupError) {
|
|
65850
|
+
console.error("[SQLiteMemoryStore] Failed to backup corrupted database:", backupError);
|
|
65851
|
+
this.dbPromise = null;
|
|
65852
|
+
throw backupError;
|
|
65853
|
+
}
|
|
65854
|
+
this.dbPromise = null;
|
|
65855
|
+
return this.initializeDatabase();
|
|
65856
|
+
}
|
|
65857
|
+
this.dbPromise = null;
|
|
65858
|
+
throw error48;
|
|
65859
|
+
}
|
|
65860
|
+
})();
|
|
65861
|
+
return this.dbPromise;
|
|
65862
|
+
}
|
|
65863
|
+
configurePragmas(db2) {
|
|
65864
|
+
db2.pragma("journal_mode = WAL");
|
|
65865
|
+
db2.pragma("synchronous = NORMAL");
|
|
65866
|
+
db2.pragma("busy_timeout = 5000");
|
|
65867
|
+
db2.pragma("foreign_keys = ON");
|
|
65868
|
+
db2.pragma("temp_store = MEMORY");
|
|
65869
|
+
db2.pragma("mmap_size = 30000000000");
|
|
65870
|
+
db2.pragma("page_size = 4096");
|
|
65871
|
+
}
|
|
65872
|
+
checkIntegrity(db2) {
|
|
65873
|
+
try {
|
|
65874
|
+
const result = db2.pragma("integrity_check", { simple: true });
|
|
65875
|
+
if (result !== "ok") {
|
|
65876
|
+
throw new Error(`Database integrity check failed: ${result}`);
|
|
65877
|
+
}
|
|
65878
|
+
} catch (error48) {
|
|
65879
|
+
console.error("[SQLiteMemoryStore] Integrity check failed:", error48);
|
|
65880
|
+
throw new Error("Database is corrupted");
|
|
65881
|
+
}
|
|
65882
|
+
}
|
|
65883
|
+
initializeSchema(db2) {
|
|
65884
|
+
db2.exec(`
|
|
65885
|
+
CREATE TABLE IF NOT EXISTS memory_entries (
|
|
65886
|
+
id TEXT PRIMARY KEY,
|
|
65887
|
+
name TEXT NOT NULL CHECK(length(name) > 0),
|
|
65888
|
+
scope TEXT NOT NULL CHECK(scope IN ('global') OR scope LIKE 'project:%'),
|
|
65889
|
+
content TEXT NOT NULL CHECK(length(content) > 0),
|
|
65890
|
+
entry_type TEXT NOT NULL CHECK(length(entry_type) > 0),
|
|
65891
|
+
status TEXT CHECK(status IS NULL OR length(status) > 0),
|
|
65892
|
+
priority TEXT CHECK(priority IS NULL OR priority IN ('low', 'medium', 'high', 'critical')),
|
|
65893
|
+
tags TEXT CHECK(tags IS NULL OR length(tags) > 0),
|
|
65894
|
+
metadata TEXT CHECK(metadata IS NULL OR json_valid(metadata)),
|
|
65895
|
+
created_at INTEGER NOT NULL CHECK(created_at > 0),
|
|
65896
|
+
updated_at INTEGER NOT NULL CHECK(updated_at > 0),
|
|
65897
|
+
last_accessed INTEGER NOT NULL CHECK(last_accessed > 0),
|
|
65898
|
+
UNIQUE(name, scope)
|
|
65899
|
+
)
|
|
65900
|
+
`);
|
|
65901
|
+
db2.exec(`
|
|
65902
|
+
CREATE INDEX IF NOT EXISTS idx_memory_entries_scope_type ON memory_entries(scope, entry_type);
|
|
65903
|
+
CREATE INDEX IF NOT EXISTS idx_memory_entries_updated ON memory_entries(updated_at);
|
|
65904
|
+
`);
|
|
65905
|
+
}
|
|
65906
|
+
async getDatabase() {
|
|
65907
|
+
if (!this.db) {
|
|
65908
|
+
this.db = await this.initializeDatabase();
|
|
65909
|
+
}
|
|
65910
|
+
return this.db;
|
|
65911
|
+
}
|
|
65912
|
+
resolvePath(path) {
|
|
65913
|
+
if (path.startsWith("~")) {
|
|
65914
|
+
const home = process.env.HOME || process.env.USERPROFILE || ".";
|
|
65915
|
+
if (home === ".") {
|
|
65916
|
+
throw new Error("Cannot resolve home directory");
|
|
65917
|
+
}
|
|
65918
|
+
const expanded = `${home}${path.slice(1)}`;
|
|
65919
|
+
const resolved = resolve4(expanded);
|
|
65920
|
+
const sep = process.platform === "win32" ? "\\" : "/";
|
|
65921
|
+
if (resolved !== home && !resolved.startsWith(home + sep)) {
|
|
65922
|
+
throw new Error(`Path escapes home directory: ${path}`);
|
|
65923
|
+
}
|
|
65924
|
+
return resolved;
|
|
65925
|
+
}
|
|
65926
|
+
return resolve4(path);
|
|
65927
|
+
}
|
|
65928
|
+
generateUUID() {
|
|
65929
|
+
return randomUUID();
|
|
65930
|
+
}
|
|
65931
|
+
now() {
|
|
65932
|
+
return Date.now();
|
|
65933
|
+
}
|
|
65934
|
+
sleep(ms) {
|
|
65935
|
+
return new Promise((resolve5) => setTimeout(resolve5, ms));
|
|
65936
|
+
}
|
|
65937
|
+
isRetryableError(error48) {
|
|
65938
|
+
if (error48 instanceof Error) {
|
|
65939
|
+
const message = error48.message.toLowerCase();
|
|
65940
|
+
return message.includes("database is locked") || message.includes("database is busy") || message.includes("sqlite_busy") || message.includes("sqlite_locked");
|
|
65941
|
+
}
|
|
65942
|
+
return false;
|
|
65943
|
+
}
|
|
65944
|
+
async transaction(callback, options = {}) {
|
|
65945
|
+
const db2 = await this.getDatabase();
|
|
65946
|
+
const retries = options.retries ?? this.maxRetries;
|
|
65947
|
+
for (let attempt = 0;attempt < retries; attempt++) {
|
|
65948
|
+
try {
|
|
65949
|
+
db2.exec("BEGIN IMMEDIATE");
|
|
65950
|
+
const result = await callback();
|
|
65951
|
+
db2.exec("COMMIT");
|
|
65952
|
+
return result;
|
|
65953
|
+
} catch (error48) {
|
|
65954
|
+
try {
|
|
65955
|
+
db2.exec("ROLLBACK");
|
|
65956
|
+
} catch (rollbackError) {
|
|
65957
|
+
console.error("[SQLiteMemoryStore] Rollback failed:", rollbackError);
|
|
65958
|
+
}
|
|
65959
|
+
const isRetryable = this.isRetryableError(error48);
|
|
65960
|
+
if (isRetryable && attempt < retries - 1) {
|
|
65961
|
+
const delay2 = this.retryDelay * 2 ** attempt;
|
|
65962
|
+
console.warn(`[SQLiteMemoryStore] Retryable error, retrying in ${delay2}ms...`);
|
|
65963
|
+
await this.sleep(delay2);
|
|
65964
|
+
continue;
|
|
65965
|
+
}
|
|
65966
|
+
throw error48;
|
|
65967
|
+
}
|
|
65968
|
+
}
|
|
65969
|
+
throw new Error("Maximum retries exceeded");
|
|
65970
|
+
}
|
|
65971
|
+
async readMemory(topic) {
|
|
65972
|
+
const db2 = await this.getDatabase();
|
|
65973
|
+
const scope = this.currentScope;
|
|
65974
|
+
return this.transaction(async () => {
|
|
65975
|
+
const stmt = db2.prepare("SELECT content FROM memory_entries WHERE name = ? AND scope = ?");
|
|
65976
|
+
const row = stmt.get(topic, scope);
|
|
65977
|
+
if (row) {
|
|
65978
|
+
const updateStmt = db2.prepare("UPDATE memory_entries SET last_accessed = ? WHERE name = ? AND scope = ?");
|
|
65979
|
+
updateStmt.run(this.now(), topic, scope);
|
|
65980
|
+
}
|
|
65981
|
+
return row?.content;
|
|
65982
|
+
});
|
|
65983
|
+
}
|
|
65984
|
+
async updateMemoryInternal(db2, operation, topic, content, metadata) {
|
|
65985
|
+
const scope = this.currentScope;
|
|
65986
|
+
const now = this.now();
|
|
65987
|
+
if (operation === "remove") {
|
|
65988
|
+
const stmt = db2.prepare("DELETE FROM memory_entries WHERE name = ? AND scope = ?");
|
|
65989
|
+
stmt.run(topic, scope);
|
|
65990
|
+
return;
|
|
65991
|
+
}
|
|
65992
|
+
const existingStmt = db2.prepare("SELECT content, entry_type, status, priority, tags FROM memory_entries WHERE name = ? AND scope = ?");
|
|
65993
|
+
const existing = existingStmt.get(topic, scope);
|
|
65994
|
+
let finalContent;
|
|
65995
|
+
let entry_type;
|
|
65996
|
+
let status;
|
|
65997
|
+
let priority;
|
|
65998
|
+
let tags;
|
|
65999
|
+
if (existing) {
|
|
66000
|
+
if (operation === "append") {
|
|
66001
|
+
if (!content) {
|
|
66002
|
+
throw new Error("Content is required for append operation.");
|
|
66003
|
+
}
|
|
66004
|
+
finalContent = `${existing.content}
|
|
66005
|
+
${content}`;
|
|
66006
|
+
} else {
|
|
66007
|
+
if (!content) {
|
|
66008
|
+
throw new Error("Content is required for replace operation.");
|
|
66009
|
+
}
|
|
66010
|
+
finalContent = content;
|
|
66011
|
+
}
|
|
66012
|
+
entry_type = metadata?.entry_type || existing.entry_type;
|
|
66013
|
+
status = metadata?.status || existing.status;
|
|
66014
|
+
priority = metadata?.priority || existing.priority;
|
|
66015
|
+
tags = metadata?.tags || existing.tags;
|
|
66016
|
+
} else {
|
|
66017
|
+
if (!content) {
|
|
66018
|
+
throw new Error("Content is required for new memory entries.");
|
|
66019
|
+
}
|
|
66020
|
+
finalContent = content;
|
|
66021
|
+
entry_type = metadata?.entry_type || "note";
|
|
66022
|
+
status = metadata?.status;
|
|
66023
|
+
priority = metadata?.priority;
|
|
66024
|
+
tags = metadata?.tags;
|
|
66025
|
+
}
|
|
66026
|
+
const upsertStmt = db2.prepare(`
|
|
66027
|
+
INSERT INTO memory_entries (id, name, scope, content, entry_type, status, priority, tags, created_at, updated_at, last_accessed)
|
|
66028
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
66029
|
+
ON CONFLICT(name, scope) DO UPDATE SET
|
|
66030
|
+
content = excluded.content,
|
|
66031
|
+
entry_type = excluded.entry_type,
|
|
66032
|
+
status = excluded.status,
|
|
66033
|
+
priority = excluded.priority,
|
|
66034
|
+
tags = excluded.tags,
|
|
66035
|
+
updated_at = excluded.updated_at,
|
|
66036
|
+
last_accessed = excluded.last_accessed
|
|
66037
|
+
`);
|
|
66038
|
+
upsertStmt.run(this.generateUUID(), topic, scope, finalContent, entry_type, status || null, priority || null, tags || null, now, now, now);
|
|
66039
|
+
}
|
|
66040
|
+
async updateMemory(operation, topic, content, metadata) {
|
|
66041
|
+
return this.transaction(async () => {
|
|
66042
|
+
const db2 = await this.getDatabase();
|
|
66043
|
+
await this.updateMemoryInternal(db2, operation, topic, content, metadata);
|
|
66044
|
+
});
|
|
66045
|
+
}
|
|
66046
|
+
async queryMemory(query = {}, options = {}) {
|
|
66047
|
+
const db2 = await this.getDatabase();
|
|
66048
|
+
const { sql, params } = this.buildQuery(query, options);
|
|
66049
|
+
if (options.operation === "count") {
|
|
66050
|
+
const countStmt = db2.prepare(`SELECT COUNT(*) as count FROM (${sql})`);
|
|
66051
|
+
const result = countStmt.get(...params);
|
|
66052
|
+
return result.count;
|
|
66053
|
+
}
|
|
66054
|
+
if (options.operation === "delete") {
|
|
66055
|
+
const deleteStmt = db2.prepare(`DELETE FROM memory_entries WHERE id IN (SELECT id FROM (${sql}))`);
|
|
66056
|
+
const info = deleteStmt.run(...params);
|
|
66057
|
+
return info.changes;
|
|
66058
|
+
}
|
|
66059
|
+
const stmt = db2.prepare(sql);
|
|
66060
|
+
return stmt.all(...params);
|
|
66061
|
+
}
|
|
66062
|
+
buildQuery(query, _options) {
|
|
66063
|
+
const conditions = [];
|
|
66064
|
+
const params = [];
|
|
66065
|
+
let sql = "SELECT * FROM memory_entries WHERE 1=1";
|
|
66066
|
+
const scope = query.scope === "auto" ? this.currentScope : query.scope;
|
|
66067
|
+
if (scope === "global") {
|
|
66068
|
+
conditions.push("scope = ?");
|
|
66069
|
+
params.push("global");
|
|
66070
|
+
} else if (scope === "project" || !scope && this.currentScope !== "global") {
|
|
66071
|
+
conditions.push("scope = ?");
|
|
66072
|
+
params.push(this.currentScope);
|
|
66073
|
+
}
|
|
66074
|
+
if (query.type) {
|
|
66075
|
+
if (!query.type.trim()) {
|
|
66076
|
+
throw new Error("Type cannot be empty");
|
|
66077
|
+
}
|
|
66078
|
+
conditions.push("entry_type = ?");
|
|
66079
|
+
params.push(query.type.trim());
|
|
66080
|
+
}
|
|
66081
|
+
if (query.status) {
|
|
66082
|
+
conditions.push("status = ?");
|
|
66083
|
+
params.push(query.status);
|
|
66084
|
+
}
|
|
66085
|
+
if (query.priority) {
|
|
66086
|
+
if (!SQLiteMemoryStore.ALLOWED_PRIORITIES.includes(query.priority)) {
|
|
66087
|
+
throw new Error(`Invalid priority: ${query.priority}`);
|
|
66088
|
+
}
|
|
66089
|
+
conditions.push("priority = ?");
|
|
66090
|
+
params.push(query.priority);
|
|
66091
|
+
}
|
|
66092
|
+
if (query.tags) {
|
|
66093
|
+
const tags = Array.isArray(query.tags) ? query.tags : [query.tags];
|
|
66094
|
+
for (const tag of tags) {
|
|
66095
|
+
const trimmed = tag.trim();
|
|
66096
|
+
if (!trimmed) {
|
|
66097
|
+
throw new Error("Tags cannot be empty");
|
|
66098
|
+
}
|
|
66099
|
+
conditions.push("(tags = ? OR tags LIKE ? OR tags LIKE ? OR tags LIKE ?)");
|
|
66100
|
+
params.push(trimmed, `${trimmed},%`, `%,${trimmed}`, `%,${trimmed},%`);
|
|
66101
|
+
}
|
|
66102
|
+
}
|
|
66103
|
+
if (query.search) {
|
|
66104
|
+
const searchTerm = query.search.trim();
|
|
66105
|
+
const sanitized = searchTerm.replace(/[\\_%]/g, "\\$&");
|
|
66106
|
+
conditions.push("(content LIKE ? OR name LIKE ?)");
|
|
66107
|
+
params.push(`%${sanitized}%`, `%${sanitized}%`);
|
|
66108
|
+
}
|
|
66109
|
+
if (query.createdAfter) {
|
|
66110
|
+
conditions.push("created_at >= ?");
|
|
66111
|
+
params.push(query.createdAfter);
|
|
66112
|
+
}
|
|
66113
|
+
if (query.createdBefore) {
|
|
66114
|
+
conditions.push("created_at <= ?");
|
|
66115
|
+
params.push(query.createdBefore);
|
|
66116
|
+
}
|
|
66117
|
+
if (query.updatedAfter) {
|
|
66118
|
+
conditions.push("updated_at >= ?");
|
|
66119
|
+
params.push(query.updatedAfter);
|
|
66120
|
+
}
|
|
66121
|
+
if (query.updatedBefore) {
|
|
66122
|
+
conditions.push("updated_at <= ?");
|
|
66123
|
+
params.push(query.updatedBefore);
|
|
66124
|
+
}
|
|
66125
|
+
if (conditions.length > 0) {
|
|
66126
|
+
sql += ` AND ${conditions.join(" AND ")}`;
|
|
66127
|
+
}
|
|
66128
|
+
if (query.sortBy) {
|
|
66129
|
+
const column = SQLiteMemoryStore.SORT_COLUMNS[query.sortBy];
|
|
66130
|
+
if (!column) {
|
|
66131
|
+
throw new Error(`Invalid sortBy: ${query.sortBy}`);
|
|
66132
|
+
}
|
|
66133
|
+
const order = query.sortOrder || "desc";
|
|
66134
|
+
if (!SQLiteMemoryStore.ALLOWED_SORT_ORDERS.includes(order)) {
|
|
66135
|
+
throw new Error(`Invalid sortOrder: ${order}`);
|
|
66136
|
+
}
|
|
66137
|
+
sql += ` ORDER BY ${column} ${order.toUpperCase()}`;
|
|
66138
|
+
}
|
|
66139
|
+
if (query.limit) {
|
|
66140
|
+
const limit = Number(query.limit);
|
|
66141
|
+
if (Number.isNaN(limit) || limit < 1 || limit > 1e4) {
|
|
66142
|
+
throw new Error("Limit must be between 1 and 10000");
|
|
66143
|
+
}
|
|
66144
|
+
sql += " LIMIT ?";
|
|
66145
|
+
params.push(limit);
|
|
66146
|
+
if (query.offset) {
|
|
66147
|
+
const offset = Number(query.offset);
|
|
66148
|
+
if (Number.isNaN(offset) || offset < 0) {
|
|
66149
|
+
throw new Error("Offset must be >= 0");
|
|
66150
|
+
}
|
|
66151
|
+
sql += " OFFSET ?";
|
|
66152
|
+
params.push(offset);
|
|
66153
|
+
}
|
|
66154
|
+
}
|
|
66155
|
+
return { sql, params };
|
|
66156
|
+
}
|
|
66157
|
+
async batchUpdateMemory(operations) {
|
|
66158
|
+
return this.transaction(async () => {
|
|
66159
|
+
const db2 = await this.getDatabase();
|
|
66160
|
+
for (const op of operations) {
|
|
66161
|
+
await this.updateMemoryInternal(db2, op.operation, op.name, op.content, op.metadata);
|
|
66162
|
+
}
|
|
66163
|
+
});
|
|
66164
|
+
}
|
|
66165
|
+
close() {
|
|
66166
|
+
if (this.db) {
|
|
66167
|
+
this.db.close();
|
|
66168
|
+
this.db = null;
|
|
66169
|
+
}
|
|
66170
|
+
}
|
|
66171
|
+
async getStats() {
|
|
66172
|
+
const db2 = await this.getDatabase();
|
|
66173
|
+
const countStmt = db2.prepare("SELECT COUNT(*) as count FROM memory_entries");
|
|
66174
|
+
const { count: totalEntries } = countStmt.get();
|
|
66175
|
+
const typeStmt = db2.prepare("SELECT entry_type, COUNT(*) as count FROM memory_entries GROUP BY entry_type");
|
|
66176
|
+
const typeRows = typeStmt.all();
|
|
66177
|
+
const entriesByType = Object.fromEntries(typeRows.map((r2) => [r2.entry_type, r2.count]));
|
|
66178
|
+
const dbPath = this.resolvePath(this.config.path || "~/.config/polka-codes/memory.sqlite");
|
|
66179
|
+
let databaseSize = 0;
|
|
66180
|
+
try {
|
|
66181
|
+
const stats = await import("node:fs/promises").then((fs4) => fs4.stat(dbPath));
|
|
66182
|
+
databaseSize = stats.size;
|
|
66183
|
+
} catch {}
|
|
66184
|
+
return {
|
|
66185
|
+
totalEntries,
|
|
66186
|
+
entriesByType,
|
|
66187
|
+
databaseSize
|
|
66188
|
+
};
|
|
66189
|
+
}
|
|
66190
|
+
}
|
|
64817
66191
|
// src/utils/eventHandler.ts
|
|
64818
66192
|
import { Console } from "node:console";
|
|
64819
66193
|
|
|
@@ -65400,7 +66774,7 @@ function logGlobalToolCallStats(stream) {
|
|
|
65400
66774
|
}
|
|
65401
66775
|
var printEvent = (verbose, usageMeter, stream = process.stdout) => {
|
|
65402
66776
|
if (verbose < 0) {
|
|
65403
|
-
return () => {};
|
|
66777
|
+
return (_event) => {};
|
|
65404
66778
|
}
|
|
65405
66779
|
const customConsole = new Console(stream, stream);
|
|
65406
66780
|
let hadReasoning = false;
|
|
@@ -65574,7 +66948,7 @@ Tool error:`, event.tool));
|
|
|
65574
66948
|
// src/utils/readMultiline.ts
|
|
65575
66949
|
import readline3 from "node:readline";
|
|
65576
66950
|
function readMultiline(prompt = "Enter text (Ctrl+D to finish):") {
|
|
65577
|
-
return new Promise((
|
|
66951
|
+
return new Promise((resolve5) => {
|
|
65578
66952
|
console.log(prompt);
|
|
65579
66953
|
const rl = readline3.createInterface({
|
|
65580
66954
|
input: process.stdin,
|
|
@@ -65586,7 +66960,7 @@ function readMultiline(prompt = "Enter text (Ctrl+D to finish):") {
|
|
|
65586
66960
|
lines.push(line);
|
|
65587
66961
|
});
|
|
65588
66962
|
rl.on("close", () => {
|
|
65589
|
-
|
|
66963
|
+
resolve5(lines.join(`
|
|
65590
66964
|
`));
|
|
65591
66965
|
});
|
|
65592
66966
|
});
|
|
@@ -65610,5 +66984,7 @@ export {
|
|
|
65610
66984
|
getGlobalConfigPath,
|
|
65611
66985
|
configSchema,
|
|
65612
66986
|
checkRipgrep,
|
|
66987
|
+
SQLiteMemoryStore,
|
|
66988
|
+
MemoryManager,
|
|
65613
66989
|
InMemoryStore
|
|
65614
66990
|
};
|