cursor-history-mcp 0.1.3 → 0.1.5

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.
@@ -1,20 +1,12 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
- }) : x)(function(x) {
11
- if (typeof require !== "undefined") return require.apply(this, arguments);
12
- throw Error('Dynamic require of "' + x + '" is not supported');
13
- });
14
- var __esm = (fn, res) => function __init() {
15
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
16
- };
17
- var __commonJS = (cb, mod) => function __require2() {
9
+ var __commonJS = (cb, mod) => function __require() {
18
10
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
19
11
  };
20
12
  var __copyProps = (to, from, except, desc) => {
@@ -34,1459 +26,652 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
26
  mod
35
27
  ));
36
28
 
37
- // node_modules/tsup/assets/esm_shims.js
38
- import { fileURLToPath } from "url";
39
- var getFilename, __filename;
40
- var init_esm_shims = __esm({
41
- "node_modules/tsup/assets/esm_shims.js"() {
42
- "use strict";
43
- getFilename = () => fileURLToPath(import.meta.url);
44
- __filename = /* @__PURE__ */ getFilename();
45
- }
46
- });
47
-
48
- // node_modules/better-sqlite3/lib/util.js
49
- var require_util = __commonJS({
50
- "node_modules/better-sqlite3/lib/util.js"(exports) {
29
+ // node_modules/adm-zip/util/constants.js
30
+ var require_constants = __commonJS({
31
+ "node_modules/adm-zip/util/constants.js"(exports2, module2) {
51
32
  "use strict";
52
- init_esm_shims();
53
- exports.getBooleanOption = (options, key) => {
54
- let value = false;
55
- if (key in options && typeof (value = options[key]) !== "boolean") {
56
- throw new TypeError(`Expected the "${key}" option to be a boolean`);
57
- }
58
- return value;
33
+ module2.exports = {
34
+ /* The local file header */
35
+ LOCHDR: 30,
36
+ // LOC header size
37
+ LOCSIG: 67324752,
38
+ // "PK\003\004"
39
+ LOCVER: 4,
40
+ // version needed to extract
41
+ LOCFLG: 6,
42
+ // general purpose bit flag
43
+ LOCHOW: 8,
44
+ // compression method
45
+ LOCTIM: 10,
46
+ // modification time (2 bytes time, 2 bytes date)
47
+ LOCCRC: 14,
48
+ // uncompressed file crc-32 value
49
+ LOCSIZ: 18,
50
+ // compressed size
51
+ LOCLEN: 22,
52
+ // uncompressed size
53
+ LOCNAM: 26,
54
+ // filename length
55
+ LOCEXT: 28,
56
+ // extra field length
57
+ /* The Data descriptor */
58
+ EXTSIG: 134695760,
59
+ // "PK\007\008"
60
+ EXTHDR: 16,
61
+ // EXT header size
62
+ EXTCRC: 4,
63
+ // uncompressed file crc-32 value
64
+ EXTSIZ: 8,
65
+ // compressed size
66
+ EXTLEN: 12,
67
+ // uncompressed size
68
+ /* The central directory file header */
69
+ CENHDR: 46,
70
+ // CEN header size
71
+ CENSIG: 33639248,
72
+ // "PK\001\002"
73
+ CENVEM: 4,
74
+ // version made by
75
+ CENVER: 6,
76
+ // version needed to extract
77
+ CENFLG: 8,
78
+ // encrypt, decrypt flags
79
+ CENHOW: 10,
80
+ // compression method
81
+ CENTIM: 12,
82
+ // modification time (2 bytes time, 2 bytes date)
83
+ CENCRC: 16,
84
+ // uncompressed file crc-32 value
85
+ CENSIZ: 20,
86
+ // compressed size
87
+ CENLEN: 24,
88
+ // uncompressed size
89
+ CENNAM: 28,
90
+ // filename length
91
+ CENEXT: 30,
92
+ // extra field length
93
+ CENCOM: 32,
94
+ // file comment length
95
+ CENDSK: 34,
96
+ // volume number start
97
+ CENATT: 36,
98
+ // internal file attributes
99
+ CENATX: 38,
100
+ // external file attributes (host system dependent)
101
+ CENOFF: 42,
102
+ // LOC header offset
103
+ /* The entries in the end of central directory */
104
+ ENDHDR: 22,
105
+ // END header size
106
+ ENDSIG: 101010256,
107
+ // "PK\005\006"
108
+ ENDSUB: 8,
109
+ // number of entries on this disk
110
+ ENDTOT: 10,
111
+ // total number of entries
112
+ ENDSIZ: 12,
113
+ // central directory size in bytes
114
+ ENDOFF: 16,
115
+ // offset of first CEN header
116
+ ENDCOM: 20,
117
+ // zip file comment length
118
+ END64HDR: 20,
119
+ // zip64 END header size
120
+ END64SIG: 117853008,
121
+ // zip64 Locator signature, "PK\006\007"
122
+ END64START: 4,
123
+ // number of the disk with the start of the zip64
124
+ END64OFF: 8,
125
+ // relative offset of the zip64 end of central directory
126
+ END64NUMDISKS: 16,
127
+ // total number of disks
128
+ ZIP64SIG: 101075792,
129
+ // zip64 signature, "PK\006\006"
130
+ ZIP64HDR: 56,
131
+ // zip64 record minimum size
132
+ ZIP64LEAD: 12,
133
+ // leading bytes at the start of the record, not counted by the value stored in ZIP64SIZE
134
+ ZIP64SIZE: 4,
135
+ // zip64 size of the central directory record
136
+ ZIP64VEM: 12,
137
+ // zip64 version made by
138
+ ZIP64VER: 14,
139
+ // zip64 version needed to extract
140
+ ZIP64DSK: 16,
141
+ // zip64 number of this disk
142
+ ZIP64DSKDIR: 20,
143
+ // number of the disk with the start of the record directory
144
+ ZIP64SUB: 24,
145
+ // number of entries on this disk
146
+ ZIP64TOT: 32,
147
+ // total number of entries
148
+ ZIP64SIZB: 40,
149
+ // zip64 central directory size in bytes
150
+ ZIP64OFF: 48,
151
+ // offset of start of central directory with respect to the starting disk number
152
+ ZIP64EXTRA: 56,
153
+ // extensible data sector
154
+ /* Compression methods */
155
+ STORED: 0,
156
+ // no compression
157
+ SHRUNK: 1,
158
+ // shrunk
159
+ REDUCED1: 2,
160
+ // reduced with compression factor 1
161
+ REDUCED2: 3,
162
+ // reduced with compression factor 2
163
+ REDUCED3: 4,
164
+ // reduced with compression factor 3
165
+ REDUCED4: 5,
166
+ // reduced with compression factor 4
167
+ IMPLODED: 6,
168
+ // imploded
169
+ // 7 reserved for Tokenizing compression algorithm
170
+ DEFLATED: 8,
171
+ // deflated
172
+ ENHANCED_DEFLATED: 9,
173
+ // enhanced deflated
174
+ PKWARE: 10,
175
+ // PKWare DCL imploded
176
+ // 11 reserved by PKWARE
177
+ BZIP2: 12,
178
+ // compressed using BZIP2
179
+ // 13 reserved by PKWARE
180
+ LZMA: 14,
181
+ // LZMA
182
+ // 15-17 reserved by PKWARE
183
+ IBM_TERSE: 18,
184
+ // compressed using IBM TERSE
185
+ IBM_LZ77: 19,
186
+ // IBM LZ77 z
187
+ AES_ENCRYPT: 99,
188
+ // WinZIP AES encryption method
189
+ /* General purpose bit flag */
190
+ // values can obtained with expression 2**bitnr
191
+ FLG_ENC: 1,
192
+ // Bit 0: encrypted file
193
+ FLG_COMP1: 2,
194
+ // Bit 1, compression option
195
+ FLG_COMP2: 4,
196
+ // Bit 2, compression option
197
+ FLG_DESC: 8,
198
+ // Bit 3, data descriptor
199
+ FLG_ENH: 16,
200
+ // Bit 4, enhanced deflating
201
+ FLG_PATCH: 32,
202
+ // Bit 5, indicates that the file is compressed patched data.
203
+ FLG_STR: 64,
204
+ // Bit 6, strong encryption (patented)
205
+ // Bits 7-10: Currently unused.
206
+ FLG_EFS: 2048,
207
+ // Bit 11: Language encoding flag (EFS)
208
+ // Bit 12: Reserved by PKWARE for enhanced compression.
209
+ // Bit 13: encrypted the Central Directory (patented).
210
+ // Bits 14-15: Reserved by PKWARE.
211
+ FLG_MSK: 4096,
212
+ // mask header values
213
+ /* Load type */
214
+ FILE: 2,
215
+ BUFFER: 1,
216
+ NONE: 0,
217
+ /* 4.5 Extensible data fields */
218
+ EF_ID: 0,
219
+ EF_SIZE: 2,
220
+ /* Header IDs */
221
+ ID_ZIP64: 1,
222
+ ID_AVINFO: 7,
223
+ ID_PFS: 8,
224
+ ID_OS2: 9,
225
+ ID_NTFS: 10,
226
+ ID_OPENVMS: 12,
227
+ ID_UNIX: 13,
228
+ ID_FORK: 14,
229
+ ID_PATCH: 15,
230
+ ID_X509_PKCS7: 20,
231
+ ID_X509_CERTID_F: 21,
232
+ ID_X509_CERTID_C: 22,
233
+ ID_STRONGENC: 23,
234
+ ID_RECORD_MGT: 24,
235
+ ID_X509_PKCS7_RL: 25,
236
+ ID_IBM1: 101,
237
+ ID_IBM2: 102,
238
+ ID_POSZIP: 18064,
239
+ EF_ZIP64_OR_32: 4294967295,
240
+ EF_ZIP64_OR_16: 65535,
241
+ EF_ZIP64_SUNCOMP: 0,
242
+ EF_ZIP64_SCOMP: 8,
243
+ EF_ZIP64_RHO: 16,
244
+ EF_ZIP64_DSN: 24
59
245
  };
60
- exports.cppdb = Symbol();
61
- exports.inspect = Symbol.for("nodejs.util.inspect.custom");
62
- }
63
- });
64
-
65
- // node_modules/better-sqlite3/lib/sqlite-error.js
66
- var require_sqlite_error = __commonJS({
67
- "node_modules/better-sqlite3/lib/sqlite-error.js"(exports, module) {
68
- "use strict";
69
- init_esm_shims();
70
- var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
71
- function SqliteError(message, code) {
72
- if (new.target !== SqliteError) {
73
- return new SqliteError(message, code);
74
- }
75
- if (typeof code !== "string") {
76
- throw new TypeError("Expected second argument to be a string");
77
- }
78
- Error.call(this, message);
79
- descriptor.value = "" + message;
80
- Object.defineProperty(this, "message", descriptor);
81
- Error.captureStackTrace(this, SqliteError);
82
- this.code = code;
83
- }
84
- Object.setPrototypeOf(SqliteError, Error);
85
- Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
86
- Object.defineProperty(SqliteError.prototype, "name", descriptor);
87
- module.exports = SqliteError;
88
246
  }
89
247
  });
90
248
 
91
- // node_modules/file-uri-to-path/index.js
92
- var require_file_uri_to_path = __commonJS({
93
- "node_modules/file-uri-to-path/index.js"(exports, module) {
249
+ // node_modules/adm-zip/util/errors.js
250
+ var require_errors = __commonJS({
251
+ "node_modules/adm-zip/util/errors.js"(exports2) {
94
252
  "use strict";
95
- init_esm_shims();
96
- var sep2 = __require("path").sep || "/";
97
- module.exports = fileUriToPath;
98
- function fileUriToPath(uri) {
99
- if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) {
100
- throw new TypeError("must pass in a file:// URI to convert to a file path");
101
- }
102
- var rest = decodeURI(uri.substring(7));
103
- var firstSlash = rest.indexOf("/");
104
- var host = rest.substring(0, firstSlash);
105
- var path = rest.substring(firstSlash + 1);
106
- if ("localhost" == host) host = "";
107
- if (host) {
108
- host = sep2 + sep2 + host;
109
- }
110
- path = path.replace(/^(.+)\|/, "$1:");
111
- if (sep2 == "\\") {
112
- path = path.replace(/\//g, "\\");
113
- }
114
- if (/^.+\:/.test(path)) {
115
- } else {
116
- path = sep2 + path;
117
- }
118
- return host + path;
253
+ var errors = {
254
+ /* Header error messages */
255
+ INVALID_LOC: "Invalid LOC header (bad signature)",
256
+ INVALID_CEN: "Invalid CEN header (bad signature)",
257
+ INVALID_END: "Invalid END header (bad signature)",
258
+ /* Descriptor */
259
+ DESCRIPTOR_NOT_EXIST: "No descriptor present",
260
+ DESCRIPTOR_UNKNOWN: "Unknown descriptor format",
261
+ DESCRIPTOR_FAULTY: "Descriptor data is malformed",
262
+ /* ZipEntry error messages*/
263
+ NO_DATA: "Nothing to decompress",
264
+ BAD_CRC: "CRC32 checksum failed {0}",
265
+ FILE_IN_THE_WAY: "There is a file in the way: {0}",
266
+ UNKNOWN_METHOD: "Invalid/unsupported compression method",
267
+ /* Inflater error messages */
268
+ AVAIL_DATA: "inflate::Available inflate data did not terminate",
269
+ INVALID_DISTANCE: "inflate::Invalid literal/length or distance code in fixed or dynamic block",
270
+ TO_MANY_CODES: "inflate::Dynamic block code description: too many length or distance codes",
271
+ INVALID_REPEAT_LEN: "inflate::Dynamic block code description: repeat more than specified lengths",
272
+ INVALID_REPEAT_FIRST: "inflate::Dynamic block code description: repeat lengths with no first length",
273
+ INCOMPLETE_CODES: "inflate::Dynamic block code description: code lengths codes incomplete",
274
+ INVALID_DYN_DISTANCE: "inflate::Dynamic block code description: invalid distance code lengths",
275
+ INVALID_CODES_LEN: "inflate::Dynamic block code description: invalid literal/length code lengths",
276
+ INVALID_STORE_BLOCK: "inflate::Stored block length did not match one's complement",
277
+ INVALID_BLOCK_TYPE: "inflate::Invalid block type (type == 3)",
278
+ /* ADM-ZIP error messages */
279
+ CANT_EXTRACT_FILE: "Could not extract the file",
280
+ CANT_OVERRIDE: "Target file already exists",
281
+ DISK_ENTRY_TOO_LARGE: "Number of disk entries is too large",
282
+ NO_ZIP: "No zip file was loaded",
283
+ NO_ENTRY: "Entry doesn't exist",
284
+ DIRECTORY_CONTENT_ERROR: "A directory cannot have content",
285
+ FILE_NOT_FOUND: 'File not found: "{0}"',
286
+ NOT_IMPLEMENTED: "Not implemented",
287
+ INVALID_FILENAME: "Invalid filename",
288
+ INVALID_FORMAT: "Invalid or unsupported zip format. No END header found",
289
+ INVALID_PASS_PARAM: "Incompatible password parameter",
290
+ WRONG_PASSWORD: "Wrong Password",
291
+ /* ADM-ZIP */
292
+ COMMENT_TOO_LONG: "Comment is too long",
293
+ // Comment can be max 65535 bytes long (NOTE: some non-US characters may take more space)
294
+ EXTRA_FIELD_PARSE_ERROR: "Extra field parsing error"
295
+ };
296
+ function E(message) {
297
+ return function(...args) {
298
+ if (args.length) {
299
+ message = message.replace(/\{(\d)\}/g, (_, n) => args[n] || "");
300
+ }
301
+ return new Error("ADM-ZIP: " + message);
302
+ };
303
+ }
304
+ for (const msg of Object.keys(errors)) {
305
+ exports2[msg] = E(errors[msg]);
119
306
  }
120
307
  }
121
308
  });
122
309
 
123
- // node_modules/bindings/bindings.js
124
- var require_bindings = __commonJS({
125
- "node_modules/bindings/bindings.js"(exports, module) {
310
+ // node_modules/adm-zip/util/utils.js
311
+ var require_utils = __commonJS({
312
+ "node_modules/adm-zip/util/utils.js"(exports2, module2) {
126
313
  "use strict";
127
- init_esm_shims();
128
- var fs = __require("fs");
129
- var path = __require("path");
130
- var fileURLToPath2 = require_file_uri_to_path();
131
- var join5 = path.join;
132
- var dirname2 = path.dirname;
133
- var exists = fs.accessSync && function(path2) {
134
- try {
135
- fs.accessSync(path2);
136
- } catch (e) {
137
- return false;
138
- }
139
- return true;
140
- } || fs.existsSync || path.existsSync;
141
- var defaults = {
142
- arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ",
143
- compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
144
- platform: process.platform,
145
- arch: process.arch,
146
- nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
147
- version: process.versions.node,
148
- bindings: "bindings.node",
149
- try: [
150
- // node-gyp's linked version in the "build" dir
151
- ["module_root", "build", "bindings"],
152
- // node-waf and gyp_addon (a.k.a node-gyp)
153
- ["module_root", "build", "Debug", "bindings"],
154
- ["module_root", "build", "Release", "bindings"],
155
- // Debug files, for development (legacy behavior, remove for node v0.9)
156
- ["module_root", "out", "Debug", "bindings"],
157
- ["module_root", "Debug", "bindings"],
158
- // Release files, but manually compiled (legacy behavior, remove for node v0.9)
159
- ["module_root", "out", "Release", "bindings"],
160
- ["module_root", "Release", "bindings"],
161
- // Legacy from node-waf, node <= 0.4.x
162
- ["module_root", "build", "default", "bindings"],
163
- // Production "Release" buildtype binary (meh...)
164
- ["module_root", "compiled", "version", "platform", "arch", "bindings"],
165
- // node-qbs builds
166
- ["module_root", "addon-build", "release", "install-root", "bindings"],
167
- ["module_root", "addon-build", "debug", "install-root", "bindings"],
168
- ["module_root", "addon-build", "default", "install-root", "bindings"],
169
- // node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
170
- ["module_root", "lib", "binding", "nodePreGyp", "bindings"]
171
- ]
172
- };
173
- function bindings(opts) {
174
- if (typeof opts == "string") {
175
- opts = { bindings: opts };
176
- } else if (!opts) {
177
- opts = {};
178
- }
179
- Object.keys(defaults).map(function(i2) {
180
- if (!(i2 in opts)) opts[i2] = defaults[i2];
181
- });
182
- if (!opts.module_root) {
183
- opts.module_root = exports.getRoot(exports.getFileName());
184
- }
185
- if (path.extname(opts.bindings) != ".node") {
186
- opts.bindings += ".node";
314
+ var fsystem = require("fs");
315
+ var pth = require("path");
316
+ var Constants = require_constants();
317
+ var Errors = require_errors();
318
+ var isWin = typeof process === "object" && "win32" === process.platform;
319
+ var is_Obj = (obj) => typeof obj === "object" && obj !== null;
320
+ var crcTable = new Uint32Array(256).map((t, c) => {
321
+ for (let k = 0; k < 8; k++) {
322
+ if ((c & 1) !== 0) {
323
+ c = 3988292384 ^ c >>> 1;
324
+ } else {
325
+ c >>>= 1;
326
+ }
187
327
  }
188
- var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
189
- var tries = [], i = 0, l = opts.try.length, n, b, err;
190
- for (; i < l; i++) {
191
- n = join5.apply(
192
- null,
193
- opts.try[i].map(function(p) {
194
- return opts[p] || p;
195
- })
196
- );
197
- tries.push(n);
198
- try {
199
- b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
200
- if (!opts.path) {
201
- b.path = n;
202
- }
203
- return b;
204
- } catch (e) {
205
- if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
206
- throw e;
207
- }
328
+ return c >>> 0;
329
+ });
330
+ function Utils(opts) {
331
+ this.sep = pth.sep;
332
+ this.fs = fsystem;
333
+ if (is_Obj(opts)) {
334
+ if (is_Obj(opts.fs) && typeof opts.fs.statSync === "function") {
335
+ this.fs = opts.fs;
208
336
  }
209
337
  }
210
- err = new Error(
211
- "Could not locate the bindings file. Tried:\n" + tries.map(function(a) {
212
- return opts.arrow + a;
213
- }).join("\n")
214
- );
215
- err.tries = tries;
216
- throw err;
217
338
  }
218
- module.exports = exports = bindings;
219
- exports.getFileName = function getFileName(calling_file) {
220
- var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName;
221
- Error.stackTraceLimit = 10;
222
- Error.prepareStackTrace = function(e, st) {
223
- for (var i = 0, l = st.length; i < l; i++) {
224
- fileName = st[i].getFileName();
225
- if (fileName !== __filename) {
226
- if (calling_file) {
227
- if (fileName !== calling_file) {
228
- return;
229
- }
230
- } else {
231
- return;
232
- }
339
+ module2.exports = Utils;
340
+ Utils.prototype.makeDir = function(folder) {
341
+ const self = this;
342
+ function mkdirSync2(fpath) {
343
+ let resolvedPath = fpath.split(self.sep)[0];
344
+ fpath.split(self.sep).forEach(function(name) {
345
+ if (!name || name.substr(-1, 1) === ":") return;
346
+ resolvedPath += self.sep + name;
347
+ var stat;
348
+ try {
349
+ stat = self.fs.statSync(resolvedPath);
350
+ } catch (e) {
351
+ self.fs.mkdirSync(resolvedPath);
233
352
  }
234
- }
235
- };
236
- Error.captureStackTrace(dummy);
237
- dummy.stack;
238
- Error.prepareStackTrace = origPST;
239
- Error.stackTraceLimit = origSTL;
240
- var fileSchema = "file://";
241
- if (fileName.indexOf(fileSchema) === 0) {
242
- fileName = fileURLToPath2(fileName);
353
+ if (stat && stat.isFile()) throw Errors.FILE_IN_THE_WAY(`"${resolvedPath}"`);
354
+ });
243
355
  }
244
- return fileName;
356
+ mkdirSync2(folder);
245
357
  };
246
- exports.getRoot = function getRoot(file) {
247
- var dir = dirname2(file), prev;
248
- while (true) {
249
- if (dir === ".") {
250
- dir = process.cwd();
251
- }
252
- if (exists(join5(dir, "package.json")) || exists(join5(dir, "node_modules"))) {
253
- return dir;
358
+ Utils.prototype.writeFileTo = function(path, content, overwrite, attr) {
359
+ const self = this;
360
+ if (self.fs.existsSync(path)) {
361
+ if (!overwrite) return false;
362
+ var stat = self.fs.statSync(path);
363
+ if (stat.isDirectory()) {
364
+ return false;
254
365
  }
255
- if (prev === dir) {
256
- throw new Error(
257
- 'Could not find module root given file: "' + file + '". Do you have a `package.json` file? '
258
- );
366
+ }
367
+ var folder = pth.dirname(path);
368
+ if (!self.fs.existsSync(folder)) {
369
+ self.makeDir(folder);
370
+ }
371
+ var fd;
372
+ try {
373
+ fd = self.fs.openSync(path, "w", 438);
374
+ } catch (e) {
375
+ self.fs.chmodSync(path, 438);
376
+ fd = self.fs.openSync(path, "w", 438);
377
+ }
378
+ if (fd) {
379
+ try {
380
+ self.fs.writeSync(fd, content, 0, content.length, 0);
381
+ } finally {
382
+ self.fs.closeSync(fd);
259
383
  }
260
- prev = dir;
261
- dir = join5(dir, "..");
262
384
  }
385
+ self.fs.chmodSync(path, attr || 438);
386
+ return true;
263
387
  };
264
- }
265
- });
266
-
267
- // node_modules/better-sqlite3/lib/methods/wrappers.js
268
- var require_wrappers = __commonJS({
269
- "node_modules/better-sqlite3/lib/methods/wrappers.js"(exports) {
270
- "use strict";
271
- init_esm_shims();
272
- var { cppdb } = require_util();
273
- exports.prepare = function prepare(sql) {
274
- return this[cppdb].prepare(sql, this, false);
388
+ Utils.prototype.writeFileToAsync = function(path, content, overwrite, attr, callback) {
389
+ if (typeof attr === "function") {
390
+ callback = attr;
391
+ attr = void 0;
392
+ }
393
+ const self = this;
394
+ self.fs.exists(path, function(exist) {
395
+ if (exist && !overwrite) return callback(false);
396
+ self.fs.stat(path, function(err, stat) {
397
+ if (exist && stat.isDirectory()) {
398
+ return callback(false);
399
+ }
400
+ var folder = pth.dirname(path);
401
+ self.fs.exists(folder, function(exists) {
402
+ if (!exists) self.makeDir(folder);
403
+ self.fs.open(path, "w", 438, function(err2, fd) {
404
+ if (err2) {
405
+ self.fs.chmod(path, 438, function() {
406
+ self.fs.open(path, "w", 438, function(err3, fd2) {
407
+ self.fs.write(fd2, content, 0, content.length, 0, function() {
408
+ self.fs.close(fd2, function() {
409
+ self.fs.chmod(path, attr || 438, function() {
410
+ callback(true);
411
+ });
412
+ });
413
+ });
414
+ });
415
+ });
416
+ } else if (fd) {
417
+ self.fs.write(fd, content, 0, content.length, 0, function() {
418
+ self.fs.close(fd, function() {
419
+ self.fs.chmod(path, attr || 438, function() {
420
+ callback(true);
421
+ });
422
+ });
423
+ });
424
+ } else {
425
+ self.fs.chmod(path, attr || 438, function() {
426
+ callback(true);
427
+ });
428
+ }
429
+ });
430
+ });
431
+ });
432
+ });
275
433
  };
276
- exports.exec = function exec(sql) {
277
- this[cppdb].exec(sql);
278
- return this;
434
+ Utils.prototype.findFiles = function(path) {
435
+ const self = this;
436
+ function findSync(dir, pattern, recursive) {
437
+ if (typeof pattern === "boolean") {
438
+ recursive = pattern;
439
+ pattern = void 0;
440
+ }
441
+ let files = [];
442
+ self.fs.readdirSync(dir).forEach(function(file) {
443
+ const path2 = pth.join(dir, file);
444
+ const stat = self.fs.statSync(path2);
445
+ if (!pattern || pattern.test(path2)) {
446
+ files.push(pth.normalize(path2) + (stat.isDirectory() ? self.sep : ""));
447
+ }
448
+ if (stat.isDirectory() && recursive) files = files.concat(findSync(path2, pattern, recursive));
449
+ });
450
+ return files;
451
+ }
452
+ return findSync(path, void 0, true);
279
453
  };
280
- exports.close = function close() {
281
- this[cppdb].close();
282
- return this;
454
+ Utils.prototype.findFilesAsync = function(dir, cb) {
455
+ const self = this;
456
+ let results = [];
457
+ self.fs.readdir(dir, function(err, list) {
458
+ if (err) return cb(err);
459
+ let list_length = list.length;
460
+ if (!list_length) return cb(null, results);
461
+ list.forEach(function(file) {
462
+ file = pth.join(dir, file);
463
+ self.fs.stat(file, function(err2, stat) {
464
+ if (err2) return cb(err2);
465
+ if (stat) {
466
+ results.push(pth.normalize(file) + (stat.isDirectory() ? self.sep : ""));
467
+ if (stat.isDirectory()) {
468
+ self.findFilesAsync(file, function(err3, res) {
469
+ if (err3) return cb(err3);
470
+ results = results.concat(res);
471
+ if (!--list_length) cb(null, results);
472
+ });
473
+ } else {
474
+ if (!--list_length) cb(null, results);
475
+ }
476
+ }
477
+ });
478
+ });
479
+ });
283
480
  };
284
- exports.loadExtension = function loadExtension(...args) {
285
- this[cppdb].loadExtension(...args);
286
- return this;
481
+ Utils.prototype.getAttributes = function() {
287
482
  };
288
- exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
289
- this[cppdb].defaultSafeIntegers(...args);
290
- return this;
483
+ Utils.prototype.setAttributes = function() {
291
484
  };
292
- exports.unsafeMode = function unsafeMode(...args) {
293
- this[cppdb].unsafeMode(...args);
294
- return this;
485
+ Utils.crc32update = function(crc, byte) {
486
+ return crcTable[(crc ^ byte) & 255] ^ crc >>> 8;
295
487
  };
296
- exports.getters = {
297
- name: {
298
- get: function name() {
299
- return this[cppdb].name;
300
- },
301
- enumerable: true
302
- },
303
- open: {
304
- get: function open() {
305
- return this[cppdb].open;
306
- },
307
- enumerable: true
308
- },
309
- inTransaction: {
310
- get: function inTransaction() {
311
- return this[cppdb].inTransaction;
312
- },
313
- enumerable: true
314
- },
315
- readonly: {
316
- get: function readonly() {
317
- return this[cppdb].readonly;
318
- },
319
- enumerable: true
320
- },
321
- memory: {
322
- get: function memory() {
323
- return this[cppdb].memory;
324
- },
325
- enumerable: true
488
+ Utils.crc32 = function(buf) {
489
+ if (typeof buf === "string") {
490
+ buf = Buffer.from(buf, "utf8");
326
491
  }
492
+ let len = buf.length;
493
+ let crc = ~0;
494
+ for (let off = 0; off < len; ) crc = Utils.crc32update(crc, buf[off++]);
495
+ return ~crc >>> 0;
327
496
  };
328
- }
329
- });
330
-
331
- // node_modules/better-sqlite3/lib/methods/transaction.js
332
- var require_transaction = __commonJS({
333
- "node_modules/better-sqlite3/lib/methods/transaction.js"(exports, module) {
334
- "use strict";
335
- init_esm_shims();
336
- var { cppdb } = require_util();
337
- var controllers = /* @__PURE__ */ new WeakMap();
338
- module.exports = function transaction(fn) {
339
- if (typeof fn !== "function") throw new TypeError("Expected first argument to be a function");
340
- const db = this[cppdb];
341
- const controller = getController(db, this);
342
- const { apply } = Function.prototype;
343
- const properties = {
344
- default: { value: wrapTransaction(apply, fn, db, controller.default) },
345
- deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
346
- immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
347
- exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
348
- database: { value: this, enumerable: true }
349
- };
350
- Object.defineProperties(properties.default.value, properties);
351
- Object.defineProperties(properties.deferred.value, properties);
352
- Object.defineProperties(properties.immediate.value, properties);
353
- Object.defineProperties(properties.exclusive.value, properties);
354
- return properties.default.value;
355
- };
356
- var getController = (db, self) => {
357
- let controller = controllers.get(db);
358
- if (!controller) {
359
- const shared = {
360
- commit: db.prepare("COMMIT", self, false),
361
- rollback: db.prepare("ROLLBACK", self, false),
362
- savepoint: db.prepare("SAVEPOINT ` _bs3. `", self, false),
363
- release: db.prepare("RELEASE ` _bs3. `", self, false),
364
- rollbackTo: db.prepare("ROLLBACK TO ` _bs3. `", self, false)
365
- };
366
- controllers.set(db, controller = {
367
- default: Object.assign({ begin: db.prepare("BEGIN", self, false) }, shared),
368
- deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self, false) }, shared),
369
- immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self, false) }, shared),
370
- exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self, false) }, shared)
371
- });
497
+ Utils.methodToString = function(method) {
498
+ switch (method) {
499
+ case Constants.STORED:
500
+ return "STORED (" + method + ")";
501
+ case Constants.DEFLATED:
502
+ return "DEFLATED (" + method + ")";
503
+ default:
504
+ return "UNSUPPORTED (" + method + ")";
372
505
  }
373
- return controller;
374
506
  };
375
- var wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
376
- let before, after, undo;
377
- if (db.inTransaction) {
378
- before = savepoint;
379
- after = release;
380
- undo = rollbackTo;
381
- } else {
382
- before = begin;
383
- after = commit;
384
- undo = rollback;
385
- }
386
- before.run();
387
- try {
388
- const result = apply.call(fn, this, arguments);
389
- if (result && typeof result.then === "function") {
390
- throw new TypeError("Transaction function cannot return a promise");
391
- }
392
- after.run();
393
- return result;
394
- } catch (ex) {
395
- if (db.inTransaction) {
396
- undo.run();
397
- if (undo !== rollback) after.run();
507
+ Utils.canonical = function(path) {
508
+ if (!path) return "";
509
+ const safeSuffix = pth.posix.normalize("/" + path.split("\\").join("/"));
510
+ return pth.join(".", safeSuffix);
511
+ };
512
+ Utils.zipnamefix = function(path) {
513
+ if (!path) return "";
514
+ const safeSuffix = pth.posix.normalize("/" + path.split("\\").join("/"));
515
+ return pth.posix.join(".", safeSuffix);
516
+ };
517
+ Utils.findLast = function(arr, callback) {
518
+ if (!Array.isArray(arr)) throw new TypeError("arr is not array");
519
+ const len = arr.length >>> 0;
520
+ for (let i = len - 1; i >= 0; i--) {
521
+ if (callback(arr[i], i, arr)) {
522
+ return arr[i];
398
523
  }
399
- throw ex;
400
524
  }
525
+ return void 0;
401
526
  };
402
- }
403
- });
404
-
405
- // node_modules/better-sqlite3/lib/methods/pragma.js
406
- var require_pragma = __commonJS({
407
- "node_modules/better-sqlite3/lib/methods/pragma.js"(exports, module) {
408
- "use strict";
409
- init_esm_shims();
410
- var { getBooleanOption, cppdb } = require_util();
411
- module.exports = function pragma(source, options) {
412
- if (options == null) options = {};
413
- if (typeof source !== "string") throw new TypeError("Expected first argument to be a string");
414
- if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
415
- const simple = getBooleanOption(options, "simple");
416
- const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
417
- return simple ? stmt.pluck().get() : stmt.all();
527
+ Utils.sanitize = function(prefix, name) {
528
+ prefix = pth.resolve(pth.normalize(prefix));
529
+ var parts = name.split("/");
530
+ for (var i = 0, l = parts.length; i < l; i++) {
531
+ var path = pth.normalize(pth.join(prefix, parts.slice(i, l).join(pth.sep)));
532
+ if (path.indexOf(prefix) === 0) {
533
+ return path;
534
+ }
535
+ }
536
+ return pth.normalize(pth.join(prefix, pth.basename(name)));
418
537
  };
419
- }
420
- });
421
-
422
- // node_modules/better-sqlite3/lib/methods/backup.js
423
- var require_backup = __commonJS({
424
- "node_modules/better-sqlite3/lib/methods/backup.js"(exports, module) {
425
- "use strict";
426
- init_esm_shims();
427
- var fs = __require("fs");
428
- var path = __require("path");
429
- var { promisify } = __require("util");
430
- var { cppdb } = require_util();
431
- var fsAccess = promisify(fs.access);
432
- module.exports = async function backup(filename, options) {
433
- if (options == null) options = {};
434
- if (typeof filename !== "string") throw new TypeError("Expected first argument to be a string");
435
- if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
436
- filename = filename.trim();
437
- const attachedName = "attached" in options ? options.attached : "main";
438
- const handler = "progress" in options ? options.progress : null;
439
- if (!filename) throw new TypeError("Backup filename cannot be an empty string");
440
- if (filename === ":memory:") throw new TypeError('Invalid backup filename ":memory:"');
441
- if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
442
- if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
443
- if (handler != null && typeof handler !== "function") throw new TypeError('Expected the "progress" option to be a function');
444
- await fsAccess(path.dirname(filename)).catch(() => {
445
- throw new TypeError("Cannot save backup because the directory does not exist");
446
- });
447
- const isNewFile = await fsAccess(filename).then(() => false, () => true);
448
- return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
538
+ Utils.toBuffer = function toBuffer(input, encoder) {
539
+ if (Buffer.isBuffer(input)) {
540
+ return input;
541
+ } else if (input instanceof Uint8Array) {
542
+ return Buffer.from(input);
543
+ } else {
544
+ return typeof input === "string" ? encoder(input) : Buffer.alloc(0);
545
+ }
449
546
  };
450
- var runBackup = (backup, handler) => {
451
- let rate = 0;
452
- let useDefault = true;
453
- return new Promise((resolve2, reject) => {
454
- setImmediate(function step() {
455
- try {
456
- const progress = backup.transfer(rate);
457
- if (!progress.remainingPages) {
458
- backup.close();
459
- resolve2(progress);
460
- return;
461
- }
462
- if (useDefault) {
463
- useDefault = false;
464
- rate = 100;
465
- }
466
- if (handler) {
467
- const ret = handler(progress);
468
- if (ret !== void 0) {
469
- if (typeof ret === "number" && ret === ret) rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
470
- else throw new TypeError("Expected progress callback to return a number or undefined");
471
- }
472
- }
473
- setImmediate(step);
474
- } catch (err) {
475
- backup.close();
476
- reject(err);
477
- }
478
- });
479
- });
547
+ Utils.readBigUInt64LE = function(buffer, index) {
548
+ var slice = Buffer.from(buffer.slice(index, index + 8));
549
+ slice.swap64();
550
+ return parseInt(`0x${slice.toString("hex")}`);
551
+ };
552
+ Utils.fromDOS2Date = function(val) {
553
+ return new Date((val >> 25 & 127) + 1980, Math.max((val >> 21 & 15) - 1, 0), Math.max(val >> 16 & 31, 1), val >> 11 & 31, val >> 5 & 63, (val & 31) << 1);
554
+ };
555
+ Utils.fromDate2DOS = function(val) {
556
+ let date = 0;
557
+ let time = 0;
558
+ if (val.getFullYear() > 1979) {
559
+ date = (val.getFullYear() - 1980 & 127) << 9 | val.getMonth() + 1 << 5 | val.getDate();
560
+ time = val.getHours() << 11 | val.getMinutes() << 5 | val.getSeconds() >> 1;
561
+ }
562
+ return date << 16 | time;
480
563
  };
564
+ Utils.isWin = isWin;
565
+ Utils.crcTable = crcTable;
481
566
  }
482
567
  });
483
568
 
484
- // node_modules/better-sqlite3/lib/methods/serialize.js
485
- var require_serialize = __commonJS({
486
- "node_modules/better-sqlite3/lib/methods/serialize.js"(exports, module) {
569
+ // node_modules/adm-zip/util/fattr.js
570
+ var require_fattr = __commonJS({
571
+ "node_modules/adm-zip/util/fattr.js"(exports2, module2) {
487
572
  "use strict";
488
- init_esm_shims();
489
- var { cppdb } = require_util();
490
- module.exports = function serialize(options) {
491
- if (options == null) options = {};
492
- if (typeof options !== "object") throw new TypeError("Expected first argument to be an options object");
493
- const attachedName = "attached" in options ? options.attached : "main";
494
- if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
495
- if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
496
- return this[cppdb].serialize(attachedName);
573
+ var pth = require("path");
574
+ module2.exports = function(path, { fs }) {
575
+ var _path = path || "", _obj = newAttr(), _stat = null;
576
+ function newAttr() {
577
+ return {
578
+ directory: false,
579
+ readonly: false,
580
+ hidden: false,
581
+ executable: false,
582
+ mtime: 0,
583
+ atime: 0
584
+ };
585
+ }
586
+ if (_path && fs.existsSync(_path)) {
587
+ _stat = fs.statSync(_path);
588
+ _obj.directory = _stat.isDirectory();
589
+ _obj.mtime = _stat.mtime;
590
+ _obj.atime = _stat.atime;
591
+ _obj.executable = (73 & _stat.mode) !== 0;
592
+ _obj.readonly = (128 & _stat.mode) === 0;
593
+ _obj.hidden = pth.basename(_path)[0] === ".";
594
+ } else {
595
+ console.warn("Invalid path: " + _path);
596
+ }
597
+ return {
598
+ get directory() {
599
+ return _obj.directory;
600
+ },
601
+ get readOnly() {
602
+ return _obj.readonly;
603
+ },
604
+ get hidden() {
605
+ return _obj.hidden;
606
+ },
607
+ get mtime() {
608
+ return _obj.mtime;
609
+ },
610
+ get atime() {
611
+ return _obj.atime;
612
+ },
613
+ get executable() {
614
+ return _obj.executable;
615
+ },
616
+ decodeAttributes: function() {
617
+ },
618
+ encodeAttributes: function() {
619
+ },
620
+ toJSON: function() {
621
+ return {
622
+ path: _path,
623
+ isDirectory: _obj.directory,
624
+ isReadOnly: _obj.readonly,
625
+ isHidden: _obj.hidden,
626
+ isExecutable: _obj.executable,
627
+ mTime: _obj.mtime,
628
+ aTime: _obj.atime
629
+ };
630
+ },
631
+ toString: function() {
632
+ return JSON.stringify(this.toJSON(), null, " ");
633
+ }
634
+ };
497
635
  };
498
636
  }
499
637
  });
500
638
 
501
- // node_modules/better-sqlite3/lib/methods/function.js
502
- var require_function = __commonJS({
503
- "node_modules/better-sqlite3/lib/methods/function.js"(exports, module) {
639
+ // node_modules/adm-zip/util/decoder.js
640
+ var require_decoder = __commonJS({
641
+ "node_modules/adm-zip/util/decoder.js"(exports2, module2) {
504
642
  "use strict";
505
- init_esm_shims();
506
- var { getBooleanOption, cppdb } = require_util();
507
- module.exports = function defineFunction(name, options, fn) {
508
- if (options == null) options = {};
509
- if (typeof options === "function") {
510
- fn = options;
511
- options = {};
512
- }
513
- if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
514
- if (typeof fn !== "function") throw new TypeError("Expected last argument to be a function");
515
- if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
516
- if (!name) throw new TypeError("User-defined function name cannot be an empty string");
517
- const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
518
- const deterministic = getBooleanOption(options, "deterministic");
519
- const directOnly = getBooleanOption(options, "directOnly");
520
- const varargs = getBooleanOption(options, "varargs");
521
- let argCount = -1;
522
- if (!varargs) {
523
- argCount = fn.length;
524
- if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError("Expected function.length to be a positive integer");
525
- if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
526
- }
527
- this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
528
- return this;
643
+ module2.exports = {
644
+ efs: true,
645
+ encode: (data) => Buffer.from(data, "utf8"),
646
+ decode: (data) => data.toString("utf8")
529
647
  };
530
648
  }
531
649
  });
532
650
 
533
- // node_modules/better-sqlite3/lib/methods/aggregate.js
534
- var require_aggregate = __commonJS({
535
- "node_modules/better-sqlite3/lib/methods/aggregate.js"(exports, module) {
651
+ // node_modules/adm-zip/util/index.js
652
+ var require_util = __commonJS({
653
+ "node_modules/adm-zip/util/index.js"(exports2, module2) {
536
654
  "use strict";
537
- init_esm_shims();
538
- var { getBooleanOption, cppdb } = require_util();
539
- module.exports = function defineAggregate(name, options) {
540
- if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
541
- if (typeof options !== "object" || options === null) throw new TypeError("Expected second argument to be an options object");
542
- if (!name) throw new TypeError("User-defined function name cannot be an empty string");
543
- const start = "start" in options ? options.start : null;
544
- const step = getFunctionOption(options, "step", true);
545
- const inverse = getFunctionOption(options, "inverse", false);
546
- const result = getFunctionOption(options, "result", false);
547
- const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
548
- const deterministic = getBooleanOption(options, "deterministic");
549
- const directOnly = getBooleanOption(options, "directOnly");
550
- const varargs = getBooleanOption(options, "varargs");
551
- let argCount = -1;
552
- if (!varargs) {
553
- argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
554
- if (argCount > 0) argCount -= 1;
555
- if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
556
- }
557
- this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
558
- return this;
559
- };
560
- var getFunctionOption = (options, key, required) => {
561
- const value = key in options ? options[key] : null;
562
- if (typeof value === "function") return value;
563
- if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
564
- if (required) throw new TypeError(`Missing required option "${key}"`);
565
- return null;
566
- };
567
- var getLength = ({ length }) => {
568
- if (Number.isInteger(length) && length >= 0) return length;
569
- throw new TypeError("Expected function.length to be a positive integer");
570
- };
655
+ module2.exports = require_utils();
656
+ module2.exports.Constants = require_constants();
657
+ module2.exports.Errors = require_errors();
658
+ module2.exports.FileAttr = require_fattr();
659
+ module2.exports.decoder = require_decoder();
571
660
  }
572
661
  });
573
662
 
574
- // node_modules/better-sqlite3/lib/methods/table.js
575
- var require_table = __commonJS({
576
- "node_modules/better-sqlite3/lib/methods/table.js"(exports, module) {
663
+ // node_modules/adm-zip/headers/entryHeader.js
664
+ var require_entryHeader = __commonJS({
665
+ "node_modules/adm-zip/headers/entryHeader.js"(exports2, module2) {
577
666
  "use strict";
578
- init_esm_shims();
579
- var { cppdb } = require_util();
580
- module.exports = function defineTable(name, factory) {
581
- if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
582
- if (!name) throw new TypeError("Virtual table module name cannot be an empty string");
583
- let eponymous = false;
584
- if (typeof factory === "object" && factory !== null) {
585
- eponymous = true;
586
- factory = defer(parseTableDefinition(factory, "used", name));
587
- } else {
588
- if (typeof factory !== "function") throw new TypeError("Expected second argument to be a function or a table definition object");
589
- factory = wrapFactory(factory);
590
- }
591
- this[cppdb].table(factory, name, eponymous);
592
- return this;
593
- };
594
- function wrapFactory(factory) {
595
- return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
596
- const thisObject = {
597
- module: moduleName,
598
- database: databaseName,
599
- table: tableName
600
- };
601
- const def = apply.call(factory, thisObject, args);
602
- if (typeof def !== "object" || def === null) {
603
- throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
604
- }
605
- return parseTableDefinition(def, "returned", moduleName);
606
- };
607
- }
608
- function parseTableDefinition(def, verb, moduleName) {
609
- if (!hasOwnProperty.call(def, "rows")) {
610
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
611
- }
612
- if (!hasOwnProperty.call(def, "columns")) {
613
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
614
- }
615
- const rows = def.rows;
616
- if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
617
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
618
- }
619
- let columns = def.columns;
620
- if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
621
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
622
- }
623
- if (columns.length !== new Set(columns).size) {
624
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
625
- }
626
- if (!columns.length) {
627
- throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
628
- }
629
- let parameters;
630
- if (hasOwnProperty.call(def, "parameters")) {
631
- parameters = def.parameters;
632
- if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
633
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
634
- }
635
- } else {
636
- parameters = inferParameters(rows);
637
- }
638
- if (parameters.length !== new Set(parameters).size) {
639
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
640
- }
641
- if (parameters.length > 32) {
642
- throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
643
- }
644
- for (const parameter of parameters) {
645
- if (columns.includes(parameter)) {
646
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
647
- }
648
- }
649
- let safeIntegers = 2;
650
- if (hasOwnProperty.call(def, "safeIntegers")) {
651
- const bool = def.safeIntegers;
652
- if (typeof bool !== "boolean") {
653
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
654
- }
655
- safeIntegers = +bool;
656
- }
657
- let directOnly = false;
658
- if (hasOwnProperty.call(def, "directOnly")) {
659
- directOnly = def.directOnly;
660
- if (typeof directOnly !== "boolean") {
661
- throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
662
- }
663
- }
664
- const columnDefinitions = [
665
- ...parameters.map(identifier).map((str) => `${str} HIDDEN`),
666
- ...columns.map(identifier)
667
- ];
668
- return [
669
- `CREATE TABLE x(${columnDefinitions.join(", ")});`,
670
- wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
671
- parameters,
672
- safeIntegers,
673
- directOnly
674
- ];
675
- }
676
- function wrapGenerator(generator, columnMap, moduleName) {
677
- return function* virtualTable(...args) {
678
- const output = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
679
- for (let i = 0; i < columnMap.size; ++i) {
680
- output.push(null);
681
- }
682
- for (const row of generator(...args)) {
683
- if (Array.isArray(row)) {
684
- extractRowArray(row, output, columnMap.size, moduleName);
685
- yield output;
686
- } else if (typeof row === "object" && row !== null) {
687
- extractRowObject(row, output, columnMap, moduleName);
688
- yield output;
689
- } else {
690
- throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
691
- }
692
- }
693
- };
694
- }
695
- function extractRowArray(row, output, columnCount, moduleName) {
696
- if (row.length !== columnCount) {
697
- throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
698
- }
699
- const offset = output.length - columnCount;
700
- for (let i = 0; i < columnCount; ++i) {
701
- output[i + offset] = row[i];
702
- }
703
- }
704
- function extractRowObject(row, output, columnMap, moduleName) {
705
- let count = 0;
706
- for (const key of Object.keys(row)) {
707
- const index = columnMap.get(key);
708
- if (index === void 0) {
709
- throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
710
- }
711
- output[index] = row[key];
712
- count += 1;
713
- }
714
- if (count !== columnMap.size) {
715
- throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
716
- }
717
- }
718
- function inferParameters({ length }) {
719
- if (!Number.isInteger(length) || length < 0) {
720
- throw new TypeError("Expected function.length to be a positive integer");
721
- }
722
- const params = [];
723
- for (let i = 0; i < length; ++i) {
724
- params.push(`$${i + 1}`);
725
- }
726
- return params;
727
- }
728
- var { hasOwnProperty } = Object.prototype;
729
- var { apply } = Function.prototype;
730
- var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {
731
- });
732
- var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
733
- var defer = (x) => () => x;
734
- }
735
- });
736
-
737
- // node_modules/better-sqlite3/lib/methods/inspect.js
738
- var require_inspect = __commonJS({
739
- "node_modules/better-sqlite3/lib/methods/inspect.js"(exports, module) {
740
- "use strict";
741
- init_esm_shims();
742
- var DatabaseInspection = function Database4() {
743
- };
744
- module.exports = function inspect(depth, opts) {
745
- return Object.assign(new DatabaseInspection(), this);
746
- };
747
- }
748
- });
749
-
750
- // node_modules/better-sqlite3/lib/database.js
751
- var require_database = __commonJS({
752
- "node_modules/better-sqlite3/lib/database.js"(exports, module) {
753
- "use strict";
754
- init_esm_shims();
755
- var fs = __require("fs");
756
- var path = __require("path");
757
- var util2 = require_util();
758
- var SqliteError = require_sqlite_error();
759
- var DEFAULT_ADDON;
760
- function Database4(filenameGiven, options) {
761
- if (new.target == null) {
762
- return new Database4(filenameGiven, options);
763
- }
764
- let buffer;
765
- if (Buffer.isBuffer(filenameGiven)) {
766
- buffer = filenameGiven;
767
- filenameGiven = ":memory:";
768
- }
769
- if (filenameGiven == null) filenameGiven = "";
770
- if (options == null) options = {};
771
- if (typeof filenameGiven !== "string") throw new TypeError("Expected first argument to be a string");
772
- if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
773
- if ("readOnly" in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
774
- if ("memory" in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
775
- const filename = filenameGiven.trim();
776
- const anonymous = filename === "" || filename === ":memory:";
777
- const readonly = util2.getBooleanOption(options, "readonly");
778
- const fileMustExist = util2.getBooleanOption(options, "fileMustExist");
779
- const timeout = "timeout" in options ? options.timeout : 5e3;
780
- const verbose = "verbose" in options ? options.verbose : null;
781
- const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
782
- if (readonly && anonymous && !buffer) throw new TypeError("In-memory/temporary databases cannot be readonly");
783
- if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
784
- if (timeout > 2147483647) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
785
- if (verbose != null && typeof verbose !== "function") throw new TypeError('Expected the "verbose" option to be a function');
786
- if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object") throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
787
- let addon;
788
- if (nativeBinding == null) {
789
- addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
790
- } else if (typeof nativeBinding === "string") {
791
- const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : __require;
792
- addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
793
- } else {
794
- addon = nativeBinding;
795
- }
796
- if (!addon.isInitialized) {
797
- addon.setErrorConstructor(SqliteError);
798
- addon.isInitialized = true;
799
- }
800
- if (!anonymous && !filename.startsWith("file:") && !fs.existsSync(path.dirname(filename))) {
801
- throw new TypeError("Cannot open database because the directory does not exist");
802
- }
803
- Object.defineProperties(this, {
804
- [util2.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
805
- ...wrappers.getters
806
- });
807
- }
808
- var wrappers = require_wrappers();
809
- Database4.prototype.prepare = wrappers.prepare;
810
- Database4.prototype.transaction = require_transaction();
811
- Database4.prototype.pragma = require_pragma();
812
- Database4.prototype.backup = require_backup();
813
- Database4.prototype.serialize = require_serialize();
814
- Database4.prototype.function = require_function();
815
- Database4.prototype.aggregate = require_aggregate();
816
- Database4.prototype.table = require_table();
817
- Database4.prototype.loadExtension = wrappers.loadExtension;
818
- Database4.prototype.exec = wrappers.exec;
819
- Database4.prototype.close = wrappers.close;
820
- Database4.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
821
- Database4.prototype.unsafeMode = wrappers.unsafeMode;
822
- Database4.prototype[util2.inspect] = require_inspect();
823
- module.exports = Database4;
824
- }
825
- });
826
-
827
- // node_modules/better-sqlite3/lib/index.js
828
- var require_lib = __commonJS({
829
- "node_modules/better-sqlite3/lib/index.js"(exports, module) {
830
- "use strict";
831
- init_esm_shims();
832
- module.exports = require_database();
833
- module.exports.SqliteError = require_sqlite_error();
834
- }
835
- });
836
-
837
- // node_modules/adm-zip/util/constants.js
838
- var require_constants = __commonJS({
839
- "node_modules/adm-zip/util/constants.js"(exports, module) {
840
- "use strict";
841
- init_esm_shims();
842
- module.exports = {
843
- /* The local file header */
844
- LOCHDR: 30,
845
- // LOC header size
846
- LOCSIG: 67324752,
847
- // "PK\003\004"
848
- LOCVER: 4,
849
- // version needed to extract
850
- LOCFLG: 6,
851
- // general purpose bit flag
852
- LOCHOW: 8,
853
- // compression method
854
- LOCTIM: 10,
855
- // modification time (2 bytes time, 2 bytes date)
856
- LOCCRC: 14,
857
- // uncompressed file crc-32 value
858
- LOCSIZ: 18,
859
- // compressed size
860
- LOCLEN: 22,
861
- // uncompressed size
862
- LOCNAM: 26,
863
- // filename length
864
- LOCEXT: 28,
865
- // extra field length
866
- /* The Data descriptor */
867
- EXTSIG: 134695760,
868
- // "PK\007\008"
869
- EXTHDR: 16,
870
- // EXT header size
871
- EXTCRC: 4,
872
- // uncompressed file crc-32 value
873
- EXTSIZ: 8,
874
- // compressed size
875
- EXTLEN: 12,
876
- // uncompressed size
877
- /* The central directory file header */
878
- CENHDR: 46,
879
- // CEN header size
880
- CENSIG: 33639248,
881
- // "PK\001\002"
882
- CENVEM: 4,
883
- // version made by
884
- CENVER: 6,
885
- // version needed to extract
886
- CENFLG: 8,
887
- // encrypt, decrypt flags
888
- CENHOW: 10,
889
- // compression method
890
- CENTIM: 12,
891
- // modification time (2 bytes time, 2 bytes date)
892
- CENCRC: 16,
893
- // uncompressed file crc-32 value
894
- CENSIZ: 20,
895
- // compressed size
896
- CENLEN: 24,
897
- // uncompressed size
898
- CENNAM: 28,
899
- // filename length
900
- CENEXT: 30,
901
- // extra field length
902
- CENCOM: 32,
903
- // file comment length
904
- CENDSK: 34,
905
- // volume number start
906
- CENATT: 36,
907
- // internal file attributes
908
- CENATX: 38,
909
- // external file attributes (host system dependent)
910
- CENOFF: 42,
911
- // LOC header offset
912
- /* The entries in the end of central directory */
913
- ENDHDR: 22,
914
- // END header size
915
- ENDSIG: 101010256,
916
- // "PK\005\006"
917
- ENDSUB: 8,
918
- // number of entries on this disk
919
- ENDTOT: 10,
920
- // total number of entries
921
- ENDSIZ: 12,
922
- // central directory size in bytes
923
- ENDOFF: 16,
924
- // offset of first CEN header
925
- ENDCOM: 20,
926
- // zip file comment length
927
- END64HDR: 20,
928
- // zip64 END header size
929
- END64SIG: 117853008,
930
- // zip64 Locator signature, "PK\006\007"
931
- END64START: 4,
932
- // number of the disk with the start of the zip64
933
- END64OFF: 8,
934
- // relative offset of the zip64 end of central directory
935
- END64NUMDISKS: 16,
936
- // total number of disks
937
- ZIP64SIG: 101075792,
938
- // zip64 signature, "PK\006\006"
939
- ZIP64HDR: 56,
940
- // zip64 record minimum size
941
- ZIP64LEAD: 12,
942
- // leading bytes at the start of the record, not counted by the value stored in ZIP64SIZE
943
- ZIP64SIZE: 4,
944
- // zip64 size of the central directory record
945
- ZIP64VEM: 12,
946
- // zip64 version made by
947
- ZIP64VER: 14,
948
- // zip64 version needed to extract
949
- ZIP64DSK: 16,
950
- // zip64 number of this disk
951
- ZIP64DSKDIR: 20,
952
- // number of the disk with the start of the record directory
953
- ZIP64SUB: 24,
954
- // number of entries on this disk
955
- ZIP64TOT: 32,
956
- // total number of entries
957
- ZIP64SIZB: 40,
958
- // zip64 central directory size in bytes
959
- ZIP64OFF: 48,
960
- // offset of start of central directory with respect to the starting disk number
961
- ZIP64EXTRA: 56,
962
- // extensible data sector
963
- /* Compression methods */
964
- STORED: 0,
965
- // no compression
966
- SHRUNK: 1,
967
- // shrunk
968
- REDUCED1: 2,
969
- // reduced with compression factor 1
970
- REDUCED2: 3,
971
- // reduced with compression factor 2
972
- REDUCED3: 4,
973
- // reduced with compression factor 3
974
- REDUCED4: 5,
975
- // reduced with compression factor 4
976
- IMPLODED: 6,
977
- // imploded
978
- // 7 reserved for Tokenizing compression algorithm
979
- DEFLATED: 8,
980
- // deflated
981
- ENHANCED_DEFLATED: 9,
982
- // enhanced deflated
983
- PKWARE: 10,
984
- // PKWare DCL imploded
985
- // 11 reserved by PKWARE
986
- BZIP2: 12,
987
- // compressed using BZIP2
988
- // 13 reserved by PKWARE
989
- LZMA: 14,
990
- // LZMA
991
- // 15-17 reserved by PKWARE
992
- IBM_TERSE: 18,
993
- // compressed using IBM TERSE
994
- IBM_LZ77: 19,
995
- // IBM LZ77 z
996
- AES_ENCRYPT: 99,
997
- // WinZIP AES encryption method
998
- /* General purpose bit flag */
999
- // values can obtained with expression 2**bitnr
1000
- FLG_ENC: 1,
1001
- // Bit 0: encrypted file
1002
- FLG_COMP1: 2,
1003
- // Bit 1, compression option
1004
- FLG_COMP2: 4,
1005
- // Bit 2, compression option
1006
- FLG_DESC: 8,
1007
- // Bit 3, data descriptor
1008
- FLG_ENH: 16,
1009
- // Bit 4, enhanced deflating
1010
- FLG_PATCH: 32,
1011
- // Bit 5, indicates that the file is compressed patched data.
1012
- FLG_STR: 64,
1013
- // Bit 6, strong encryption (patented)
1014
- // Bits 7-10: Currently unused.
1015
- FLG_EFS: 2048,
1016
- // Bit 11: Language encoding flag (EFS)
1017
- // Bit 12: Reserved by PKWARE for enhanced compression.
1018
- // Bit 13: encrypted the Central Directory (patented).
1019
- // Bits 14-15: Reserved by PKWARE.
1020
- FLG_MSK: 4096,
1021
- // mask header values
1022
- /* Load type */
1023
- FILE: 2,
1024
- BUFFER: 1,
1025
- NONE: 0,
1026
- /* 4.5 Extensible data fields */
1027
- EF_ID: 0,
1028
- EF_SIZE: 2,
1029
- /* Header IDs */
1030
- ID_ZIP64: 1,
1031
- ID_AVINFO: 7,
1032
- ID_PFS: 8,
1033
- ID_OS2: 9,
1034
- ID_NTFS: 10,
1035
- ID_OPENVMS: 12,
1036
- ID_UNIX: 13,
1037
- ID_FORK: 14,
1038
- ID_PATCH: 15,
1039
- ID_X509_PKCS7: 20,
1040
- ID_X509_CERTID_F: 21,
1041
- ID_X509_CERTID_C: 22,
1042
- ID_STRONGENC: 23,
1043
- ID_RECORD_MGT: 24,
1044
- ID_X509_PKCS7_RL: 25,
1045
- ID_IBM1: 101,
1046
- ID_IBM2: 102,
1047
- ID_POSZIP: 18064,
1048
- EF_ZIP64_OR_32: 4294967295,
1049
- EF_ZIP64_OR_16: 65535,
1050
- EF_ZIP64_SUNCOMP: 0,
1051
- EF_ZIP64_SCOMP: 8,
1052
- EF_ZIP64_RHO: 16,
1053
- EF_ZIP64_DSN: 24
1054
- };
1055
- }
1056
- });
1057
-
1058
- // node_modules/adm-zip/util/errors.js
1059
- var require_errors = __commonJS({
1060
- "node_modules/adm-zip/util/errors.js"(exports) {
1061
- "use strict";
1062
- init_esm_shims();
1063
- var errors = {
1064
- /* Header error messages */
1065
- INVALID_LOC: "Invalid LOC header (bad signature)",
1066
- INVALID_CEN: "Invalid CEN header (bad signature)",
1067
- INVALID_END: "Invalid END header (bad signature)",
1068
- /* Descriptor */
1069
- DESCRIPTOR_NOT_EXIST: "No descriptor present",
1070
- DESCRIPTOR_UNKNOWN: "Unknown descriptor format",
1071
- DESCRIPTOR_FAULTY: "Descriptor data is malformed",
1072
- /* ZipEntry error messages*/
1073
- NO_DATA: "Nothing to decompress",
1074
- BAD_CRC: "CRC32 checksum failed {0}",
1075
- FILE_IN_THE_WAY: "There is a file in the way: {0}",
1076
- UNKNOWN_METHOD: "Invalid/unsupported compression method",
1077
- /* Inflater error messages */
1078
- AVAIL_DATA: "inflate::Available inflate data did not terminate",
1079
- INVALID_DISTANCE: "inflate::Invalid literal/length or distance code in fixed or dynamic block",
1080
- TO_MANY_CODES: "inflate::Dynamic block code description: too many length or distance codes",
1081
- INVALID_REPEAT_LEN: "inflate::Dynamic block code description: repeat more than specified lengths",
1082
- INVALID_REPEAT_FIRST: "inflate::Dynamic block code description: repeat lengths with no first length",
1083
- INCOMPLETE_CODES: "inflate::Dynamic block code description: code lengths codes incomplete",
1084
- INVALID_DYN_DISTANCE: "inflate::Dynamic block code description: invalid distance code lengths",
1085
- INVALID_CODES_LEN: "inflate::Dynamic block code description: invalid literal/length code lengths",
1086
- INVALID_STORE_BLOCK: "inflate::Stored block length did not match one's complement",
1087
- INVALID_BLOCK_TYPE: "inflate::Invalid block type (type == 3)",
1088
- /* ADM-ZIP error messages */
1089
- CANT_EXTRACT_FILE: "Could not extract the file",
1090
- CANT_OVERRIDE: "Target file already exists",
1091
- DISK_ENTRY_TOO_LARGE: "Number of disk entries is too large",
1092
- NO_ZIP: "No zip file was loaded",
1093
- NO_ENTRY: "Entry doesn't exist",
1094
- DIRECTORY_CONTENT_ERROR: "A directory cannot have content",
1095
- FILE_NOT_FOUND: 'File not found: "{0}"',
1096
- NOT_IMPLEMENTED: "Not implemented",
1097
- INVALID_FILENAME: "Invalid filename",
1098
- INVALID_FORMAT: "Invalid or unsupported zip format. No END header found",
1099
- INVALID_PASS_PARAM: "Incompatible password parameter",
1100
- WRONG_PASSWORD: "Wrong Password",
1101
- /* ADM-ZIP */
1102
- COMMENT_TOO_LONG: "Comment is too long",
1103
- // Comment can be max 65535 bytes long (NOTE: some non-US characters may take more space)
1104
- EXTRA_FIELD_PARSE_ERROR: "Extra field parsing error"
1105
- };
1106
- function E(message) {
1107
- return function(...args) {
1108
- if (args.length) {
1109
- message = message.replace(/\{(\d)\}/g, (_, n) => args[n] || "");
1110
- }
1111
- return new Error("ADM-ZIP: " + message);
1112
- };
1113
- }
1114
- for (const msg of Object.keys(errors)) {
1115
- exports[msg] = E(errors[msg]);
1116
- }
1117
- }
1118
- });
1119
-
1120
- // node_modules/adm-zip/util/utils.js
1121
- var require_utils = __commonJS({
1122
- "node_modules/adm-zip/util/utils.js"(exports, module) {
1123
- "use strict";
1124
- init_esm_shims();
1125
- var fsystem = __require("fs");
1126
- var pth = __require("path");
1127
- var Constants = require_constants();
1128
- var Errors = require_errors();
1129
- var isWin = typeof process === "object" && "win32" === process.platform;
1130
- var is_Obj = (obj) => typeof obj === "object" && obj !== null;
1131
- var crcTable = new Uint32Array(256).map((t, c) => {
1132
- for (let k = 0; k < 8; k++) {
1133
- if ((c & 1) !== 0) {
1134
- c = 3988292384 ^ c >>> 1;
1135
- } else {
1136
- c >>>= 1;
1137
- }
1138
- }
1139
- return c >>> 0;
1140
- });
1141
- function Utils(opts) {
1142
- this.sep = pth.sep;
1143
- this.fs = fsystem;
1144
- if (is_Obj(opts)) {
1145
- if (is_Obj(opts.fs) && typeof opts.fs.statSync === "function") {
1146
- this.fs = opts.fs;
1147
- }
1148
- }
1149
- }
1150
- module.exports = Utils;
1151
- Utils.prototype.makeDir = function(folder) {
1152
- const self = this;
1153
- function mkdirSync2(fpath) {
1154
- let resolvedPath = fpath.split(self.sep)[0];
1155
- fpath.split(self.sep).forEach(function(name) {
1156
- if (!name || name.substr(-1, 1) === ":") return;
1157
- resolvedPath += self.sep + name;
1158
- var stat;
1159
- try {
1160
- stat = self.fs.statSync(resolvedPath);
1161
- } catch (e) {
1162
- self.fs.mkdirSync(resolvedPath);
1163
- }
1164
- if (stat && stat.isFile()) throw Errors.FILE_IN_THE_WAY(`"${resolvedPath}"`);
1165
- });
1166
- }
1167
- mkdirSync2(folder);
1168
- };
1169
- Utils.prototype.writeFileTo = function(path, content, overwrite, attr) {
1170
- const self = this;
1171
- if (self.fs.existsSync(path)) {
1172
- if (!overwrite) return false;
1173
- var stat = self.fs.statSync(path);
1174
- if (stat.isDirectory()) {
1175
- return false;
1176
- }
1177
- }
1178
- var folder = pth.dirname(path);
1179
- if (!self.fs.existsSync(folder)) {
1180
- self.makeDir(folder);
1181
- }
1182
- var fd;
1183
- try {
1184
- fd = self.fs.openSync(path, "w", 438);
1185
- } catch (e) {
1186
- self.fs.chmodSync(path, 438);
1187
- fd = self.fs.openSync(path, "w", 438);
1188
- }
1189
- if (fd) {
1190
- try {
1191
- self.fs.writeSync(fd, content, 0, content.length, 0);
1192
- } finally {
1193
- self.fs.closeSync(fd);
1194
- }
1195
- }
1196
- self.fs.chmodSync(path, attr || 438);
1197
- return true;
1198
- };
1199
- Utils.prototype.writeFileToAsync = function(path, content, overwrite, attr, callback) {
1200
- if (typeof attr === "function") {
1201
- callback = attr;
1202
- attr = void 0;
1203
- }
1204
- const self = this;
1205
- self.fs.exists(path, function(exist) {
1206
- if (exist && !overwrite) return callback(false);
1207
- self.fs.stat(path, function(err, stat) {
1208
- if (exist && stat.isDirectory()) {
1209
- return callback(false);
1210
- }
1211
- var folder = pth.dirname(path);
1212
- self.fs.exists(folder, function(exists) {
1213
- if (!exists) self.makeDir(folder);
1214
- self.fs.open(path, "w", 438, function(err2, fd) {
1215
- if (err2) {
1216
- self.fs.chmod(path, 438, function() {
1217
- self.fs.open(path, "w", 438, function(err3, fd2) {
1218
- self.fs.write(fd2, content, 0, content.length, 0, function() {
1219
- self.fs.close(fd2, function() {
1220
- self.fs.chmod(path, attr || 438, function() {
1221
- callback(true);
1222
- });
1223
- });
1224
- });
1225
- });
1226
- });
1227
- } else if (fd) {
1228
- self.fs.write(fd, content, 0, content.length, 0, function() {
1229
- self.fs.close(fd, function() {
1230
- self.fs.chmod(path, attr || 438, function() {
1231
- callback(true);
1232
- });
1233
- });
1234
- });
1235
- } else {
1236
- self.fs.chmod(path, attr || 438, function() {
1237
- callback(true);
1238
- });
1239
- }
1240
- });
1241
- });
1242
- });
1243
- });
1244
- };
1245
- Utils.prototype.findFiles = function(path) {
1246
- const self = this;
1247
- function findSync(dir, pattern, recursive) {
1248
- if (typeof pattern === "boolean") {
1249
- recursive = pattern;
1250
- pattern = void 0;
1251
- }
1252
- let files = [];
1253
- self.fs.readdirSync(dir).forEach(function(file) {
1254
- const path2 = pth.join(dir, file);
1255
- const stat = self.fs.statSync(path2);
1256
- if (!pattern || pattern.test(path2)) {
1257
- files.push(pth.normalize(path2) + (stat.isDirectory() ? self.sep : ""));
1258
- }
1259
- if (stat.isDirectory() && recursive) files = files.concat(findSync(path2, pattern, recursive));
1260
- });
1261
- return files;
1262
- }
1263
- return findSync(path, void 0, true);
1264
- };
1265
- Utils.prototype.findFilesAsync = function(dir, cb) {
1266
- const self = this;
1267
- let results = [];
1268
- self.fs.readdir(dir, function(err, list) {
1269
- if (err) return cb(err);
1270
- let list_length = list.length;
1271
- if (!list_length) return cb(null, results);
1272
- list.forEach(function(file) {
1273
- file = pth.join(dir, file);
1274
- self.fs.stat(file, function(err2, stat) {
1275
- if (err2) return cb(err2);
1276
- if (stat) {
1277
- results.push(pth.normalize(file) + (stat.isDirectory() ? self.sep : ""));
1278
- if (stat.isDirectory()) {
1279
- self.findFilesAsync(file, function(err3, res) {
1280
- if (err3) return cb(err3);
1281
- results = results.concat(res);
1282
- if (!--list_length) cb(null, results);
1283
- });
1284
- } else {
1285
- if (!--list_length) cb(null, results);
1286
- }
1287
- }
1288
- });
1289
- });
1290
- });
1291
- };
1292
- Utils.prototype.getAttributes = function() {
1293
- };
1294
- Utils.prototype.setAttributes = function() {
1295
- };
1296
- Utils.crc32update = function(crc, byte) {
1297
- return crcTable[(crc ^ byte) & 255] ^ crc >>> 8;
1298
- };
1299
- Utils.crc32 = function(buf) {
1300
- if (typeof buf === "string") {
1301
- buf = Buffer.from(buf, "utf8");
1302
- }
1303
- let len = buf.length;
1304
- let crc = ~0;
1305
- for (let off = 0; off < len; ) crc = Utils.crc32update(crc, buf[off++]);
1306
- return ~crc >>> 0;
1307
- };
1308
- Utils.methodToString = function(method) {
1309
- switch (method) {
1310
- case Constants.STORED:
1311
- return "STORED (" + method + ")";
1312
- case Constants.DEFLATED:
1313
- return "DEFLATED (" + method + ")";
1314
- default:
1315
- return "UNSUPPORTED (" + method + ")";
1316
- }
1317
- };
1318
- Utils.canonical = function(path) {
1319
- if (!path) return "";
1320
- const safeSuffix = pth.posix.normalize("/" + path.split("\\").join("/"));
1321
- return pth.join(".", safeSuffix);
1322
- };
1323
- Utils.zipnamefix = function(path) {
1324
- if (!path) return "";
1325
- const safeSuffix = pth.posix.normalize("/" + path.split("\\").join("/"));
1326
- return pth.posix.join(".", safeSuffix);
1327
- };
1328
- Utils.findLast = function(arr, callback) {
1329
- if (!Array.isArray(arr)) throw new TypeError("arr is not array");
1330
- const len = arr.length >>> 0;
1331
- for (let i = len - 1; i >= 0; i--) {
1332
- if (callback(arr[i], i, arr)) {
1333
- return arr[i];
1334
- }
1335
- }
1336
- return void 0;
1337
- };
1338
- Utils.sanitize = function(prefix, name) {
1339
- prefix = pth.resolve(pth.normalize(prefix));
1340
- var parts = name.split("/");
1341
- for (var i = 0, l = parts.length; i < l; i++) {
1342
- var path = pth.normalize(pth.join(prefix, parts.slice(i, l).join(pth.sep)));
1343
- if (path.indexOf(prefix) === 0) {
1344
- return path;
1345
- }
1346
- }
1347
- return pth.normalize(pth.join(prefix, pth.basename(name)));
1348
- };
1349
- Utils.toBuffer = function toBuffer(input, encoder) {
1350
- if (Buffer.isBuffer(input)) {
1351
- return input;
1352
- } else if (input instanceof Uint8Array) {
1353
- return Buffer.from(input);
1354
- } else {
1355
- return typeof input === "string" ? encoder(input) : Buffer.alloc(0);
1356
- }
1357
- };
1358
- Utils.readBigUInt64LE = function(buffer, index) {
1359
- var slice = Buffer.from(buffer.slice(index, index + 8));
1360
- slice.swap64();
1361
- return parseInt(`0x${slice.toString("hex")}`);
1362
- };
1363
- Utils.fromDOS2Date = function(val) {
1364
- return new Date((val >> 25 & 127) + 1980, Math.max((val >> 21 & 15) - 1, 0), Math.max(val >> 16 & 31, 1), val >> 11 & 31, val >> 5 & 63, (val & 31) << 1);
1365
- };
1366
- Utils.fromDate2DOS = function(val) {
1367
- let date = 0;
1368
- let time = 0;
1369
- if (val.getFullYear() > 1979) {
1370
- date = (val.getFullYear() - 1980 & 127) << 9 | val.getMonth() + 1 << 5 | val.getDate();
1371
- time = val.getHours() << 11 | val.getMinutes() << 5 | val.getSeconds() >> 1;
1372
- }
1373
- return date << 16 | time;
1374
- };
1375
- Utils.isWin = isWin;
1376
- Utils.crcTable = crcTable;
1377
- }
1378
- });
1379
-
1380
- // node_modules/adm-zip/util/fattr.js
1381
- var require_fattr = __commonJS({
1382
- "node_modules/adm-zip/util/fattr.js"(exports, module) {
1383
- "use strict";
1384
- init_esm_shims();
1385
- var pth = __require("path");
1386
- module.exports = function(path, { fs }) {
1387
- var _path = path || "", _obj = newAttr(), _stat = null;
1388
- function newAttr() {
1389
- return {
1390
- directory: false,
1391
- readonly: false,
1392
- hidden: false,
1393
- executable: false,
1394
- mtime: 0,
1395
- atime: 0
1396
- };
1397
- }
1398
- if (_path && fs.existsSync(_path)) {
1399
- _stat = fs.statSync(_path);
1400
- _obj.directory = _stat.isDirectory();
1401
- _obj.mtime = _stat.mtime;
1402
- _obj.atime = _stat.atime;
1403
- _obj.executable = (73 & _stat.mode) !== 0;
1404
- _obj.readonly = (128 & _stat.mode) === 0;
1405
- _obj.hidden = pth.basename(_path)[0] === ".";
1406
- } else {
1407
- console.warn("Invalid path: " + _path);
1408
- }
1409
- return {
1410
- get directory() {
1411
- return _obj.directory;
1412
- },
1413
- get readOnly() {
1414
- return _obj.readonly;
1415
- },
1416
- get hidden() {
1417
- return _obj.hidden;
1418
- },
1419
- get mtime() {
1420
- return _obj.mtime;
1421
- },
1422
- get atime() {
1423
- return _obj.atime;
1424
- },
1425
- get executable() {
1426
- return _obj.executable;
1427
- },
1428
- decodeAttributes: function() {
1429
- },
1430
- encodeAttributes: function() {
1431
- },
1432
- toJSON: function() {
1433
- return {
1434
- path: _path,
1435
- isDirectory: _obj.directory,
1436
- isReadOnly: _obj.readonly,
1437
- isHidden: _obj.hidden,
1438
- isExecutable: _obj.executable,
1439
- mTime: _obj.mtime,
1440
- aTime: _obj.atime
1441
- };
1442
- },
1443
- toString: function() {
1444
- return JSON.stringify(this.toJSON(), null, " ");
1445
- }
1446
- };
1447
- };
1448
- }
1449
- });
1450
-
1451
- // node_modules/adm-zip/util/decoder.js
1452
- var require_decoder = __commonJS({
1453
- "node_modules/adm-zip/util/decoder.js"(exports, module) {
1454
- "use strict";
1455
- init_esm_shims();
1456
- module.exports = {
1457
- efs: true,
1458
- encode: (data) => Buffer.from(data, "utf8"),
1459
- decode: (data) => data.toString("utf8")
1460
- };
1461
- }
1462
- });
1463
-
1464
- // node_modules/adm-zip/util/index.js
1465
- var require_util2 = __commonJS({
1466
- "node_modules/adm-zip/util/index.js"(exports, module) {
1467
- "use strict";
1468
- init_esm_shims();
1469
- module.exports = require_utils();
1470
- module.exports.Constants = require_constants();
1471
- module.exports.Errors = require_errors();
1472
- module.exports.FileAttr = require_fattr();
1473
- module.exports.decoder = require_decoder();
1474
- }
1475
- });
1476
-
1477
- // node_modules/adm-zip/headers/entryHeader.js
1478
- var require_entryHeader = __commonJS({
1479
- "node_modules/adm-zip/headers/entryHeader.js"(exports, module) {
1480
- "use strict";
1481
- init_esm_shims();
1482
- var Utils = require_util2();
1483
- var Constants = Utils.Constants;
1484
- module.exports = function() {
1485
- var _verMade = 20, _version = 10, _flags = 0, _method = 0, _time = 0, _crc = 0, _compressedSize = 0, _size = 0, _fnameLen = 0, _extraLen = 0, _comLen = 0, _diskStart = 0, _inattr = 0, _attr = 0, _offset = 0;
1486
- _verMade |= Utils.isWin ? 2560 : 768;
1487
- _flags |= Constants.FLG_EFS;
1488
- const _localHeader = {
1489
- extraLen: 0
667
+ var Utils = require_util();
668
+ var Constants = Utils.Constants;
669
+ module2.exports = function() {
670
+ var _verMade = 20, _version = 10, _flags = 0, _method = 0, _time = 0, _crc = 0, _compressedSize = 0, _size = 0, _fnameLen = 0, _extraLen = 0, _comLen = 0, _diskStart = 0, _inattr = 0, _attr = 0, _offset = 0;
671
+ _verMade |= Utils.isWin ? 2560 : 768;
672
+ _flags |= Constants.FLG_EFS;
673
+ const _localHeader = {
674
+ extraLen: 0
1490
675
  };
1491
676
  const uint32 = (val) => Math.max(0, val) >>> 0;
1492
677
  const uint16 = (val) => Math.max(0, val) & 65535;
@@ -1746,12 +931,11 @@ var require_entryHeader = __commonJS({
1746
931
 
1747
932
  // node_modules/adm-zip/headers/mainHeader.js
1748
933
  var require_mainHeader = __commonJS({
1749
- "node_modules/adm-zip/headers/mainHeader.js"(exports, module) {
934
+ "node_modules/adm-zip/headers/mainHeader.js"(exports2, module2) {
1750
935
  "use strict";
1751
- init_esm_shims();
1752
- var Utils = require_util2();
936
+ var Utils = require_util();
1753
937
  var Constants = Utils.Constants;
1754
- module.exports = function() {
938
+ module2.exports = function() {
1755
939
  var _volumeEntries = 0, _totalEntries = 0, _size = 0, _offset = 0, _commentLength = 0;
1756
940
  return {
1757
941
  get diskEntries() {
@@ -1841,21 +1025,19 @@ var require_mainHeader = __commonJS({
1841
1025
 
1842
1026
  // node_modules/adm-zip/headers/index.js
1843
1027
  var require_headers = __commonJS({
1844
- "node_modules/adm-zip/headers/index.js"(exports) {
1028
+ "node_modules/adm-zip/headers/index.js"(exports2) {
1845
1029
  "use strict";
1846
- init_esm_shims();
1847
- exports.EntryHeader = require_entryHeader();
1848
- exports.MainHeader = require_mainHeader();
1030
+ exports2.EntryHeader = require_entryHeader();
1031
+ exports2.MainHeader = require_mainHeader();
1849
1032
  }
1850
1033
  });
1851
1034
 
1852
1035
  // node_modules/adm-zip/methods/deflater.js
1853
1036
  var require_deflater = __commonJS({
1854
- "node_modules/adm-zip/methods/deflater.js"(exports, module) {
1037
+ "node_modules/adm-zip/methods/deflater.js"(exports2, module2) {
1855
1038
  "use strict";
1856
- init_esm_shims();
1857
- module.exports = function(inbuf) {
1858
- var zlib = __require("zlib");
1039
+ module2.exports = function(inbuf) {
1040
+ var zlib = require("zlib");
1859
1041
  var opts = { chunkSize: (parseInt(inbuf.length / 1024) + 1) * 1024 };
1860
1042
  return {
1861
1043
  deflate: function() {
@@ -1886,12 +1068,11 @@ var require_deflater = __commonJS({
1886
1068
 
1887
1069
  // node_modules/adm-zip/methods/inflater.js
1888
1070
  var require_inflater = __commonJS({
1889
- "node_modules/adm-zip/methods/inflater.js"(exports, module) {
1071
+ "node_modules/adm-zip/methods/inflater.js"(exports2, module2) {
1890
1072
  "use strict";
1891
- init_esm_shims();
1892
1073
  var version = +(process.versions ? process.versions.node : "").split(".")[0] || 0;
1893
- module.exports = function(inbuf, expectedLength) {
1894
- var zlib = __require("zlib");
1074
+ module2.exports = function(inbuf, expectedLength) {
1075
+ var zlib = require("zlib");
1895
1076
  const option = version >= 15 && expectedLength > 0 ? { maxOutputLength: expectedLength } : {};
1896
1077
  return {
1897
1078
  inflate: function() {
@@ -1922,10 +1103,9 @@ var require_inflater = __commonJS({
1922
1103
 
1923
1104
  // node_modules/adm-zip/methods/zipcrypto.js
1924
1105
  var require_zipcrypto = __commonJS({
1925
- "node_modules/adm-zip/methods/zipcrypto.js"(exports, module) {
1106
+ "node_modules/adm-zip/methods/zipcrypto.js"(exports2, module2) {
1926
1107
  "use strict";
1927
- init_esm_shims();
1928
- var { randomFillSync } = __require("crypto");
1108
+ var { randomFillSync } = require("crypto");
1929
1109
  var Errors = require_errors();
1930
1110
  var crctable = new Uint32Array(256).map((t, crc) => {
1931
1111
  for (let j = 0; j < 8; j++) {
@@ -2033,31 +1213,29 @@ var require_zipcrypto = __commonJS({
2033
1213
  encrypter(salt, result);
2034
1214
  return encrypter(data, result, 12);
2035
1215
  }
2036
- module.exports = { decrypt, encrypt, _salter };
1216
+ module2.exports = { decrypt, encrypt, _salter };
2037
1217
  }
2038
1218
  });
2039
1219
 
2040
1220
  // node_modules/adm-zip/methods/index.js
2041
1221
  var require_methods = __commonJS({
2042
- "node_modules/adm-zip/methods/index.js"(exports) {
1222
+ "node_modules/adm-zip/methods/index.js"(exports2) {
2043
1223
  "use strict";
2044
- init_esm_shims();
2045
- exports.Deflater = require_deflater();
2046
- exports.Inflater = require_inflater();
2047
- exports.ZipCrypto = require_zipcrypto();
1224
+ exports2.Deflater = require_deflater();
1225
+ exports2.Inflater = require_inflater();
1226
+ exports2.ZipCrypto = require_zipcrypto();
2048
1227
  }
2049
1228
  });
2050
1229
 
2051
1230
  // node_modules/adm-zip/zipEntry.js
2052
1231
  var require_zipEntry = __commonJS({
2053
- "node_modules/adm-zip/zipEntry.js"(exports, module) {
1232
+ "node_modules/adm-zip/zipEntry.js"(exports2, module2) {
2054
1233
  "use strict";
2055
- init_esm_shims();
2056
- var Utils = require_util2();
1234
+ var Utils = require_util();
2057
1235
  var Headers = require_headers();
2058
1236
  var Constants = Utils.Constants;
2059
1237
  var Methods = require_methods();
2060
- module.exports = function(options, input) {
1238
+ module2.exports = function(options, input) {
2061
1239
  var _centralHeader = new Headers.EntryHeader(), _entryName = Buffer.alloc(0), _comment = Buffer.alloc(0), _isDirectory = false, uncompressedData = null, _extra = Buffer.alloc(0), _extralocal = Buffer.alloc(0), _efs = true;
2062
1240
  const opts = options;
2063
1241
  const decoder = typeof opts.decoder === "object" ? opts.decoder : Utils.decoder;
@@ -2383,13 +1561,12 @@ var require_zipEntry = __commonJS({
2383
1561
 
2384
1562
  // node_modules/adm-zip/zipFile.js
2385
1563
  var require_zipFile = __commonJS({
2386
- "node_modules/adm-zip/zipFile.js"(exports, module) {
1564
+ "node_modules/adm-zip/zipFile.js"(exports2, module2) {
2387
1565
  "use strict";
2388
- init_esm_shims();
2389
1566
  var ZipEntry = require_zipEntry();
2390
1567
  var Headers = require_headers();
2391
- var Utils = require_util2();
2392
- module.exports = function(inBuffer, options) {
1568
+ var Utils = require_util();
1569
+ module2.exports = function(inBuffer, options) {
2393
1570
  var entryList = [], entryTable = {}, _comment = Buffer.alloc(0), mainHeader = new Headers.MainHeader(), loadedEntries = false;
2394
1571
  var password = null;
2395
1572
  const temporary = /* @__PURE__ */ new Set();
@@ -2731,11 +1908,10 @@ var require_zipFile = __commonJS({
2731
1908
 
2732
1909
  // node_modules/adm-zip/adm-zip.js
2733
1910
  var require_adm_zip = __commonJS({
2734
- "node_modules/adm-zip/adm-zip.js"(exports, module) {
1911
+ "node_modules/adm-zip/adm-zip.js"(exports2, module2) {
2735
1912
  "use strict";
2736
- init_esm_shims();
2737
- var Utils = require_util2();
2738
- var pth = __require("path");
1913
+ var Utils = require_util();
1914
+ var pth = require("path");
2739
1915
  var ZipEntry = require_zipEntry();
2740
1916
  var ZipFile = require_zipFile();
2741
1917
  var get_Bool = (...val) => Utils.findLast(val, (c) => typeof c === "boolean");
@@ -2751,7 +1927,7 @@ var require_adm_zip = __commonJS({
2751
1927
  // file system
2752
1928
  fs: null
2753
1929
  };
2754
- module.exports = function(input, options) {
1930
+ module2.exports = function(input, options) {
2755
1931
  let inBuffer = null;
2756
1932
  const opts = Object.assign(/* @__PURE__ */ Object.create(null), defaultOptions);
2757
1933
  if (input && "object" === typeof input) {
@@ -3462,79 +2638,840 @@ var require_adm_zip = __commonJS({
3462
2638
  targetFileName = "";
3463
2639
  }
3464
2640
  }
3465
- if (!targetFileName && opts.filename) {
3466
- targetFileName = opts.filename;
2641
+ if (!targetFileName && opts.filename) {
2642
+ targetFileName = opts.filename;
2643
+ }
2644
+ if (!targetFileName) return;
2645
+ var zipData = _zip.compressToBuffer();
2646
+ if (zipData) {
2647
+ var ok = filetools.writeFileTo(targetFileName, zipData, true);
2648
+ if (typeof callback === "function") callback(!ok ? new Error("failed") : null, "");
2649
+ }
2650
+ },
2651
+ /**
2652
+ *
2653
+ * @param {string} targetFileName
2654
+ * @param {object} [props]
2655
+ * @param {boolean} [props.overwrite=true] If the file already exists at the target path, the file will be overwriten if this is true.
2656
+ * @param {boolean} [props.perm] The file will be set as the permission from the entry if this is true.
2657
+
2658
+ * @returns {Promise<void>}
2659
+ */
2660
+ writeZipPromise: function(targetFileName, props) {
2661
+ const { overwrite, perm } = Object.assign({ overwrite: true }, props);
2662
+ return new Promise((resolve2, reject) => {
2663
+ if (!targetFileName && opts.filename) targetFileName = opts.filename;
2664
+ if (!targetFileName) reject("ADM-ZIP: ZIP File Name Missing");
2665
+ this.toBufferPromise().then((zipData) => {
2666
+ const ret = (done) => done ? resolve2(done) : reject("ADM-ZIP: Wasn't able to write zip file");
2667
+ filetools.writeFileToAsync(targetFileName, zipData, overwrite, perm, ret);
2668
+ }, reject);
2669
+ });
2670
+ },
2671
+ /**
2672
+ * @returns {Promise<Buffer>} A promise to the Buffer.
2673
+ */
2674
+ toBufferPromise: function() {
2675
+ return new Promise((resolve2, reject) => {
2676
+ _zip.toAsyncBuffer(resolve2, reject);
2677
+ });
2678
+ },
2679
+ /**
2680
+ * Returns the content of the entire zip file as a Buffer object
2681
+ *
2682
+ * @prop {function} [onSuccess]
2683
+ * @prop {function} [onFail]
2684
+ * @prop {function} [onItemStart]
2685
+ * @prop {function} [onItemEnd]
2686
+ * @returns {Buffer}
2687
+ */
2688
+ toBuffer: function(onSuccess, onFail, onItemStart, onItemEnd) {
2689
+ if (typeof onSuccess === "function") {
2690
+ _zip.toAsyncBuffer(onSuccess, onFail, onItemStart, onItemEnd);
2691
+ return null;
2692
+ }
2693
+ return _zip.compressToBuffer();
2694
+ }
2695
+ };
2696
+ };
2697
+ }
2698
+ });
2699
+
2700
+ // node_modules/better-sqlite3/lib/util.js
2701
+ var require_util2 = __commonJS({
2702
+ "node_modules/better-sqlite3/lib/util.js"(exports2) {
2703
+ "use strict";
2704
+ exports2.getBooleanOption = (options, key) => {
2705
+ let value = false;
2706
+ if (key in options && typeof (value = options[key]) !== "boolean") {
2707
+ throw new TypeError(`Expected the "${key}" option to be a boolean`);
2708
+ }
2709
+ return value;
2710
+ };
2711
+ exports2.cppdb = Symbol();
2712
+ exports2.inspect = Symbol.for("nodejs.util.inspect.custom");
2713
+ }
2714
+ });
2715
+
2716
+ // node_modules/better-sqlite3/lib/sqlite-error.js
2717
+ var require_sqlite_error = __commonJS({
2718
+ "node_modules/better-sqlite3/lib/sqlite-error.js"(exports2, module2) {
2719
+ "use strict";
2720
+ var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
2721
+ function SqliteError(message, code) {
2722
+ if (new.target !== SqliteError) {
2723
+ return new SqliteError(message, code);
2724
+ }
2725
+ if (typeof code !== "string") {
2726
+ throw new TypeError("Expected second argument to be a string");
2727
+ }
2728
+ Error.call(this, message);
2729
+ descriptor.value = "" + message;
2730
+ Object.defineProperty(this, "message", descriptor);
2731
+ Error.captureStackTrace(this, SqliteError);
2732
+ this.code = code;
2733
+ }
2734
+ Object.setPrototypeOf(SqliteError, Error);
2735
+ Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
2736
+ Object.defineProperty(SqliteError.prototype, "name", descriptor);
2737
+ module2.exports = SqliteError;
2738
+ }
2739
+ });
2740
+
2741
+ // node_modules/file-uri-to-path/index.js
2742
+ var require_file_uri_to_path = __commonJS({
2743
+ "node_modules/file-uri-to-path/index.js"(exports2, module2) {
2744
+ "use strict";
2745
+ var sep2 = require("path").sep || "/";
2746
+ module2.exports = fileUriToPath;
2747
+ function fileUriToPath(uri) {
2748
+ if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) {
2749
+ throw new TypeError("must pass in a file:// URI to convert to a file path");
2750
+ }
2751
+ var rest = decodeURI(uri.substring(7));
2752
+ var firstSlash = rest.indexOf("/");
2753
+ var host = rest.substring(0, firstSlash);
2754
+ var path = rest.substring(firstSlash + 1);
2755
+ if ("localhost" == host) host = "";
2756
+ if (host) {
2757
+ host = sep2 + sep2 + host;
2758
+ }
2759
+ path = path.replace(/^(.+)\|/, "$1:");
2760
+ if (sep2 == "\\") {
2761
+ path = path.replace(/\//g, "\\");
2762
+ }
2763
+ if (/^.+\:/.test(path)) {
2764
+ } else {
2765
+ path = sep2 + path;
2766
+ }
2767
+ return host + path;
2768
+ }
2769
+ }
2770
+ });
2771
+
2772
+ // node_modules/bindings/bindings.js
2773
+ var require_bindings = __commonJS({
2774
+ "node_modules/bindings/bindings.js"(exports2, module2) {
2775
+ "use strict";
2776
+ var fs = require("fs");
2777
+ var path = require("path");
2778
+ var fileURLToPath = require_file_uri_to_path();
2779
+ var join5 = path.join;
2780
+ var dirname2 = path.dirname;
2781
+ var exists = fs.accessSync && function(path2) {
2782
+ try {
2783
+ fs.accessSync(path2);
2784
+ } catch (e) {
2785
+ return false;
2786
+ }
2787
+ return true;
2788
+ } || fs.existsSync || path.existsSync;
2789
+ var defaults = {
2790
+ arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ",
2791
+ compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
2792
+ platform: process.platform,
2793
+ arch: process.arch,
2794
+ nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
2795
+ version: process.versions.node,
2796
+ bindings: "bindings.node",
2797
+ try: [
2798
+ // node-gyp's linked version in the "build" dir
2799
+ ["module_root", "build", "bindings"],
2800
+ // node-waf and gyp_addon (a.k.a node-gyp)
2801
+ ["module_root", "build", "Debug", "bindings"],
2802
+ ["module_root", "build", "Release", "bindings"],
2803
+ // Debug files, for development (legacy behavior, remove for node v0.9)
2804
+ ["module_root", "out", "Debug", "bindings"],
2805
+ ["module_root", "Debug", "bindings"],
2806
+ // Release files, but manually compiled (legacy behavior, remove for node v0.9)
2807
+ ["module_root", "out", "Release", "bindings"],
2808
+ ["module_root", "Release", "bindings"],
2809
+ // Legacy from node-waf, node <= 0.4.x
2810
+ ["module_root", "build", "default", "bindings"],
2811
+ // Production "Release" buildtype binary (meh...)
2812
+ ["module_root", "compiled", "version", "platform", "arch", "bindings"],
2813
+ // node-qbs builds
2814
+ ["module_root", "addon-build", "release", "install-root", "bindings"],
2815
+ ["module_root", "addon-build", "debug", "install-root", "bindings"],
2816
+ ["module_root", "addon-build", "default", "install-root", "bindings"],
2817
+ // node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
2818
+ ["module_root", "lib", "binding", "nodePreGyp", "bindings"]
2819
+ ]
2820
+ };
2821
+ function bindings(opts) {
2822
+ if (typeof opts == "string") {
2823
+ opts = { bindings: opts };
2824
+ } else if (!opts) {
2825
+ opts = {};
2826
+ }
2827
+ Object.keys(defaults).map(function(i2) {
2828
+ if (!(i2 in opts)) opts[i2] = defaults[i2];
2829
+ });
2830
+ if (!opts.module_root) {
2831
+ opts.module_root = exports2.getRoot(exports2.getFileName());
2832
+ }
2833
+ if (path.extname(opts.bindings) != ".node") {
2834
+ opts.bindings += ".node";
2835
+ }
2836
+ var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
2837
+ var tries = [], i = 0, l = opts.try.length, n, b, err;
2838
+ for (; i < l; i++) {
2839
+ n = join5.apply(
2840
+ null,
2841
+ opts.try[i].map(function(p) {
2842
+ return opts[p] || p;
2843
+ })
2844
+ );
2845
+ tries.push(n);
2846
+ try {
2847
+ b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
2848
+ if (!opts.path) {
2849
+ b.path = n;
2850
+ }
2851
+ return b;
2852
+ } catch (e) {
2853
+ if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
2854
+ throw e;
3467
2855
  }
3468
- if (!targetFileName) return;
3469
- var zipData = _zip.compressToBuffer();
3470
- if (zipData) {
3471
- var ok = filetools.writeFileTo(targetFileName, zipData, true);
3472
- if (typeof callback === "function") callback(!ok ? new Error("failed") : null, "");
2856
+ }
2857
+ }
2858
+ err = new Error(
2859
+ "Could not locate the bindings file. Tried:\n" + tries.map(function(a) {
2860
+ return opts.arrow + a;
2861
+ }).join("\n")
2862
+ );
2863
+ err.tries = tries;
2864
+ throw err;
2865
+ }
2866
+ module2.exports = exports2 = bindings;
2867
+ exports2.getFileName = function getFileName(calling_file) {
2868
+ var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName;
2869
+ Error.stackTraceLimit = 10;
2870
+ Error.prepareStackTrace = function(e, st) {
2871
+ for (var i = 0, l = st.length; i < l; i++) {
2872
+ fileName = st[i].getFileName();
2873
+ if (fileName !== __filename) {
2874
+ if (calling_file) {
2875
+ if (fileName !== calling_file) {
2876
+ return;
2877
+ }
2878
+ } else {
2879
+ return;
2880
+ }
3473
2881
  }
2882
+ }
2883
+ };
2884
+ Error.captureStackTrace(dummy);
2885
+ dummy.stack;
2886
+ Error.prepareStackTrace = origPST;
2887
+ Error.stackTraceLimit = origSTL;
2888
+ var fileSchema = "file://";
2889
+ if (fileName.indexOf(fileSchema) === 0) {
2890
+ fileName = fileURLToPath(fileName);
2891
+ }
2892
+ return fileName;
2893
+ };
2894
+ exports2.getRoot = function getRoot(file) {
2895
+ var dir = dirname2(file), prev;
2896
+ while (true) {
2897
+ if (dir === ".") {
2898
+ dir = process.cwd();
2899
+ }
2900
+ if (exists(join5(dir, "package.json")) || exists(join5(dir, "node_modules"))) {
2901
+ return dir;
2902
+ }
2903
+ if (prev === dir) {
2904
+ throw new Error(
2905
+ 'Could not find module root given file: "' + file + '". Do you have a `package.json` file? '
2906
+ );
2907
+ }
2908
+ prev = dir;
2909
+ dir = join5(dir, "..");
2910
+ }
2911
+ };
2912
+ }
2913
+ });
2914
+
2915
+ // node_modules/better-sqlite3/lib/methods/wrappers.js
2916
+ var require_wrappers = __commonJS({
2917
+ "node_modules/better-sqlite3/lib/methods/wrappers.js"(exports2) {
2918
+ "use strict";
2919
+ var { cppdb } = require_util2();
2920
+ exports2.prepare = function prepare(sql) {
2921
+ return this[cppdb].prepare(sql, this, false);
2922
+ };
2923
+ exports2.exec = function exec(sql) {
2924
+ this[cppdb].exec(sql);
2925
+ return this;
2926
+ };
2927
+ exports2.close = function close() {
2928
+ this[cppdb].close();
2929
+ return this;
2930
+ };
2931
+ exports2.loadExtension = function loadExtension(...args) {
2932
+ this[cppdb].loadExtension(...args);
2933
+ return this;
2934
+ };
2935
+ exports2.defaultSafeIntegers = function defaultSafeIntegers(...args) {
2936
+ this[cppdb].defaultSafeIntegers(...args);
2937
+ return this;
2938
+ };
2939
+ exports2.unsafeMode = function unsafeMode(...args) {
2940
+ this[cppdb].unsafeMode(...args);
2941
+ return this;
2942
+ };
2943
+ exports2.getters = {
2944
+ name: {
2945
+ get: function name() {
2946
+ return this[cppdb].name;
3474
2947
  },
3475
- /**
3476
- *
3477
- * @param {string} targetFileName
3478
- * @param {object} [props]
3479
- * @param {boolean} [props.overwrite=true] If the file already exists at the target path, the file will be overwriten if this is true.
3480
- * @param {boolean} [props.perm] The file will be set as the permission from the entry if this is true.
3481
-
3482
- * @returns {Promise<void>}
3483
- */
3484
- writeZipPromise: function(targetFileName, props) {
3485
- const { overwrite, perm } = Object.assign({ overwrite: true }, props);
3486
- return new Promise((resolve2, reject) => {
3487
- if (!targetFileName && opts.filename) targetFileName = opts.filename;
3488
- if (!targetFileName) reject("ADM-ZIP: ZIP File Name Missing");
3489
- this.toBufferPromise().then((zipData) => {
3490
- const ret = (done) => done ? resolve2(done) : reject("ADM-ZIP: Wasn't able to write zip file");
3491
- filetools.writeFileToAsync(targetFileName, zipData, overwrite, perm, ret);
3492
- }, reject);
3493
- });
2948
+ enumerable: true
2949
+ },
2950
+ open: {
2951
+ get: function open() {
2952
+ return this[cppdb].open;
3494
2953
  },
3495
- /**
3496
- * @returns {Promise<Buffer>} A promise to the Buffer.
3497
- */
3498
- toBufferPromise: function() {
3499
- return new Promise((resolve2, reject) => {
3500
- _zip.toAsyncBuffer(resolve2, reject);
3501
- });
2954
+ enumerable: true
2955
+ },
2956
+ inTransaction: {
2957
+ get: function inTransaction() {
2958
+ return this[cppdb].inTransaction;
3502
2959
  },
3503
- /**
3504
- * Returns the content of the entire zip file as a Buffer object
3505
- *
3506
- * @prop {function} [onSuccess]
3507
- * @prop {function} [onFail]
3508
- * @prop {function} [onItemStart]
3509
- * @prop {function} [onItemEnd]
3510
- * @returns {Buffer}
3511
- */
3512
- toBuffer: function(onSuccess, onFail, onItemStart, onItemEnd) {
3513
- if (typeof onSuccess === "function") {
3514
- _zip.toAsyncBuffer(onSuccess, onFail, onItemStart, onItemEnd);
3515
- return null;
2960
+ enumerable: true
2961
+ },
2962
+ readonly: {
2963
+ get: function readonly() {
2964
+ return this[cppdb].readonly;
2965
+ },
2966
+ enumerable: true
2967
+ },
2968
+ memory: {
2969
+ get: function memory() {
2970
+ return this[cppdb].memory;
2971
+ },
2972
+ enumerable: true
2973
+ }
2974
+ };
2975
+ }
2976
+ });
2977
+
2978
+ // node_modules/better-sqlite3/lib/methods/transaction.js
2979
+ var require_transaction = __commonJS({
2980
+ "node_modules/better-sqlite3/lib/methods/transaction.js"(exports2, module2) {
2981
+ "use strict";
2982
+ var { cppdb } = require_util2();
2983
+ var controllers = /* @__PURE__ */ new WeakMap();
2984
+ module2.exports = function transaction(fn) {
2985
+ if (typeof fn !== "function") throw new TypeError("Expected first argument to be a function");
2986
+ const db = this[cppdb];
2987
+ const controller = getController(db, this);
2988
+ const { apply } = Function.prototype;
2989
+ const properties = {
2990
+ default: { value: wrapTransaction(apply, fn, db, controller.default) },
2991
+ deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
2992
+ immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
2993
+ exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
2994
+ database: { value: this, enumerable: true }
2995
+ };
2996
+ Object.defineProperties(properties.default.value, properties);
2997
+ Object.defineProperties(properties.deferred.value, properties);
2998
+ Object.defineProperties(properties.immediate.value, properties);
2999
+ Object.defineProperties(properties.exclusive.value, properties);
3000
+ return properties.default.value;
3001
+ };
3002
+ var getController = (db, self) => {
3003
+ let controller = controllers.get(db);
3004
+ if (!controller) {
3005
+ const shared = {
3006
+ commit: db.prepare("COMMIT", self, false),
3007
+ rollback: db.prepare("ROLLBACK", self, false),
3008
+ savepoint: db.prepare("SAVEPOINT ` _bs3. `", self, false),
3009
+ release: db.prepare("RELEASE ` _bs3. `", self, false),
3010
+ rollbackTo: db.prepare("ROLLBACK TO ` _bs3. `", self, false)
3011
+ };
3012
+ controllers.set(db, controller = {
3013
+ default: Object.assign({ begin: db.prepare("BEGIN", self, false) }, shared),
3014
+ deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self, false) }, shared),
3015
+ immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self, false) }, shared),
3016
+ exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self, false) }, shared)
3017
+ });
3018
+ }
3019
+ return controller;
3020
+ };
3021
+ var wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
3022
+ let before, after, undo;
3023
+ if (db.inTransaction) {
3024
+ before = savepoint;
3025
+ after = release;
3026
+ undo = rollbackTo;
3027
+ } else {
3028
+ before = begin;
3029
+ after = commit;
3030
+ undo = rollback;
3031
+ }
3032
+ before.run();
3033
+ try {
3034
+ const result = apply.call(fn, this, arguments);
3035
+ if (result && typeof result.then === "function") {
3036
+ throw new TypeError("Transaction function cannot return a promise");
3037
+ }
3038
+ after.run();
3039
+ return result;
3040
+ } catch (ex) {
3041
+ if (db.inTransaction) {
3042
+ undo.run();
3043
+ if (undo !== rollback) after.run();
3044
+ }
3045
+ throw ex;
3046
+ }
3047
+ };
3048
+ }
3049
+ });
3050
+
3051
+ // node_modules/better-sqlite3/lib/methods/pragma.js
3052
+ var require_pragma = __commonJS({
3053
+ "node_modules/better-sqlite3/lib/methods/pragma.js"(exports2, module2) {
3054
+ "use strict";
3055
+ var { getBooleanOption, cppdb } = require_util2();
3056
+ module2.exports = function pragma(source, options) {
3057
+ if (options == null) options = {};
3058
+ if (typeof source !== "string") throw new TypeError("Expected first argument to be a string");
3059
+ if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
3060
+ const simple = getBooleanOption(options, "simple");
3061
+ const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
3062
+ return simple ? stmt.pluck().get() : stmt.all();
3063
+ };
3064
+ }
3065
+ });
3066
+
3067
+ // node_modules/better-sqlite3/lib/methods/backup.js
3068
+ var require_backup = __commonJS({
3069
+ "node_modules/better-sqlite3/lib/methods/backup.js"(exports2, module2) {
3070
+ "use strict";
3071
+ var fs = require("fs");
3072
+ var path = require("path");
3073
+ var { promisify } = require("util");
3074
+ var { cppdb } = require_util2();
3075
+ var fsAccess = promisify(fs.access);
3076
+ module2.exports = async function backup(filename, options) {
3077
+ if (options == null) options = {};
3078
+ if (typeof filename !== "string") throw new TypeError("Expected first argument to be a string");
3079
+ if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
3080
+ filename = filename.trim();
3081
+ const attachedName = "attached" in options ? options.attached : "main";
3082
+ const handler = "progress" in options ? options.progress : null;
3083
+ if (!filename) throw new TypeError("Backup filename cannot be an empty string");
3084
+ if (filename === ":memory:") throw new TypeError('Invalid backup filename ":memory:"');
3085
+ if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
3086
+ if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
3087
+ if (handler != null && typeof handler !== "function") throw new TypeError('Expected the "progress" option to be a function');
3088
+ await fsAccess(path.dirname(filename)).catch(() => {
3089
+ throw new TypeError("Cannot save backup because the directory does not exist");
3090
+ });
3091
+ const isNewFile = await fsAccess(filename).then(() => false, () => true);
3092
+ return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
3093
+ };
3094
+ var runBackup = (backup, handler) => {
3095
+ let rate = 0;
3096
+ let useDefault = true;
3097
+ return new Promise((resolve2, reject) => {
3098
+ setImmediate(function step() {
3099
+ try {
3100
+ const progress = backup.transfer(rate);
3101
+ if (!progress.remainingPages) {
3102
+ backup.close();
3103
+ resolve2(progress);
3104
+ return;
3105
+ }
3106
+ if (useDefault) {
3107
+ useDefault = false;
3108
+ rate = 100;
3109
+ }
3110
+ if (handler) {
3111
+ const ret = handler(progress);
3112
+ if (ret !== void 0) {
3113
+ if (typeof ret === "number" && ret === ret) rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
3114
+ else throw new TypeError("Expected progress callback to return a number or undefined");
3115
+ }
3116
+ }
3117
+ setImmediate(step);
3118
+ } catch (err) {
3119
+ backup.close();
3120
+ reject(err);
3516
3121
  }
3517
- return _zip.compressToBuffer();
3122
+ });
3123
+ });
3124
+ };
3125
+ }
3126
+ });
3127
+
3128
+ // node_modules/better-sqlite3/lib/methods/serialize.js
3129
+ var require_serialize = __commonJS({
3130
+ "node_modules/better-sqlite3/lib/methods/serialize.js"(exports2, module2) {
3131
+ "use strict";
3132
+ var { cppdb } = require_util2();
3133
+ module2.exports = function serialize(options) {
3134
+ if (options == null) options = {};
3135
+ if (typeof options !== "object") throw new TypeError("Expected first argument to be an options object");
3136
+ const attachedName = "attached" in options ? options.attached : "main";
3137
+ if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
3138
+ if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
3139
+ return this[cppdb].serialize(attachedName);
3140
+ };
3141
+ }
3142
+ });
3143
+
3144
+ // node_modules/better-sqlite3/lib/methods/function.js
3145
+ var require_function = __commonJS({
3146
+ "node_modules/better-sqlite3/lib/methods/function.js"(exports2, module2) {
3147
+ "use strict";
3148
+ var { getBooleanOption, cppdb } = require_util2();
3149
+ module2.exports = function defineFunction(name, options, fn) {
3150
+ if (options == null) options = {};
3151
+ if (typeof options === "function") {
3152
+ fn = options;
3153
+ options = {};
3154
+ }
3155
+ if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
3156
+ if (typeof fn !== "function") throw new TypeError("Expected last argument to be a function");
3157
+ if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
3158
+ if (!name) throw new TypeError("User-defined function name cannot be an empty string");
3159
+ const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
3160
+ const deterministic = getBooleanOption(options, "deterministic");
3161
+ const directOnly = getBooleanOption(options, "directOnly");
3162
+ const varargs = getBooleanOption(options, "varargs");
3163
+ let argCount = -1;
3164
+ if (!varargs) {
3165
+ argCount = fn.length;
3166
+ if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError("Expected function.length to be a positive integer");
3167
+ if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
3168
+ }
3169
+ this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
3170
+ return this;
3171
+ };
3172
+ }
3173
+ });
3174
+
3175
+ // node_modules/better-sqlite3/lib/methods/aggregate.js
3176
+ var require_aggregate = __commonJS({
3177
+ "node_modules/better-sqlite3/lib/methods/aggregate.js"(exports2, module2) {
3178
+ "use strict";
3179
+ var { getBooleanOption, cppdb } = require_util2();
3180
+ module2.exports = function defineAggregate(name, options) {
3181
+ if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
3182
+ if (typeof options !== "object" || options === null) throw new TypeError("Expected second argument to be an options object");
3183
+ if (!name) throw new TypeError("User-defined function name cannot be an empty string");
3184
+ const start = "start" in options ? options.start : null;
3185
+ const step = getFunctionOption(options, "step", true);
3186
+ const inverse = getFunctionOption(options, "inverse", false);
3187
+ const result = getFunctionOption(options, "result", false);
3188
+ const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
3189
+ const deterministic = getBooleanOption(options, "deterministic");
3190
+ const directOnly = getBooleanOption(options, "directOnly");
3191
+ const varargs = getBooleanOption(options, "varargs");
3192
+ let argCount = -1;
3193
+ if (!varargs) {
3194
+ argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
3195
+ if (argCount > 0) argCount -= 1;
3196
+ if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
3197
+ }
3198
+ this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
3199
+ return this;
3200
+ };
3201
+ var getFunctionOption = (options, key, required) => {
3202
+ const value = key in options ? options[key] : null;
3203
+ if (typeof value === "function") return value;
3204
+ if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
3205
+ if (required) throw new TypeError(`Missing required option "${key}"`);
3206
+ return null;
3207
+ };
3208
+ var getLength = ({ length }) => {
3209
+ if (Number.isInteger(length) && length >= 0) return length;
3210
+ throw new TypeError("Expected function.length to be a positive integer");
3211
+ };
3212
+ }
3213
+ });
3214
+
3215
+ // node_modules/better-sqlite3/lib/methods/table.js
3216
+ var require_table = __commonJS({
3217
+ "node_modules/better-sqlite3/lib/methods/table.js"(exports2, module2) {
3218
+ "use strict";
3219
+ var { cppdb } = require_util2();
3220
+ module2.exports = function defineTable(name, factory) {
3221
+ if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
3222
+ if (!name) throw new TypeError("Virtual table module name cannot be an empty string");
3223
+ let eponymous = false;
3224
+ if (typeof factory === "object" && factory !== null) {
3225
+ eponymous = true;
3226
+ factory = defer(parseTableDefinition(factory, "used", name));
3227
+ } else {
3228
+ if (typeof factory !== "function") throw new TypeError("Expected second argument to be a function or a table definition object");
3229
+ factory = wrapFactory(factory);
3230
+ }
3231
+ this[cppdb].table(factory, name, eponymous);
3232
+ return this;
3233
+ };
3234
+ function wrapFactory(factory) {
3235
+ return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
3236
+ const thisObject = {
3237
+ module: moduleName,
3238
+ database: databaseName,
3239
+ table: tableName
3240
+ };
3241
+ const def = apply.call(factory, thisObject, args);
3242
+ if (typeof def !== "object" || def === null) {
3243
+ throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
3518
3244
  }
3245
+ return parseTableDefinition(def, "returned", moduleName);
3519
3246
  };
3520
- };
3247
+ }
3248
+ function parseTableDefinition(def, verb, moduleName) {
3249
+ if (!hasOwnProperty.call(def, "rows")) {
3250
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
3251
+ }
3252
+ if (!hasOwnProperty.call(def, "columns")) {
3253
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
3254
+ }
3255
+ const rows = def.rows;
3256
+ if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
3257
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
3258
+ }
3259
+ let columns = def.columns;
3260
+ if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
3261
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
3262
+ }
3263
+ if (columns.length !== new Set(columns).size) {
3264
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
3265
+ }
3266
+ if (!columns.length) {
3267
+ throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
3268
+ }
3269
+ let parameters;
3270
+ if (hasOwnProperty.call(def, "parameters")) {
3271
+ parameters = def.parameters;
3272
+ if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
3273
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
3274
+ }
3275
+ } else {
3276
+ parameters = inferParameters(rows);
3277
+ }
3278
+ if (parameters.length !== new Set(parameters).size) {
3279
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
3280
+ }
3281
+ if (parameters.length > 32) {
3282
+ throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
3283
+ }
3284
+ for (const parameter of parameters) {
3285
+ if (columns.includes(parameter)) {
3286
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
3287
+ }
3288
+ }
3289
+ let safeIntegers = 2;
3290
+ if (hasOwnProperty.call(def, "safeIntegers")) {
3291
+ const bool = def.safeIntegers;
3292
+ if (typeof bool !== "boolean") {
3293
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
3294
+ }
3295
+ safeIntegers = +bool;
3296
+ }
3297
+ let directOnly = false;
3298
+ if (hasOwnProperty.call(def, "directOnly")) {
3299
+ directOnly = def.directOnly;
3300
+ if (typeof directOnly !== "boolean") {
3301
+ throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
3302
+ }
3303
+ }
3304
+ const columnDefinitions = [
3305
+ ...parameters.map(identifier).map((str) => `${str} HIDDEN`),
3306
+ ...columns.map(identifier)
3307
+ ];
3308
+ return [
3309
+ `CREATE TABLE x(${columnDefinitions.join(", ")});`,
3310
+ wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
3311
+ parameters,
3312
+ safeIntegers,
3313
+ directOnly
3314
+ ];
3315
+ }
3316
+ function wrapGenerator(generator, columnMap, moduleName) {
3317
+ return function* virtualTable(...args) {
3318
+ const output = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
3319
+ for (let i = 0; i < columnMap.size; ++i) {
3320
+ output.push(null);
3321
+ }
3322
+ for (const row of generator(...args)) {
3323
+ if (Array.isArray(row)) {
3324
+ extractRowArray(row, output, columnMap.size, moduleName);
3325
+ yield output;
3326
+ } else if (typeof row === "object" && row !== null) {
3327
+ extractRowObject(row, output, columnMap, moduleName);
3328
+ yield output;
3329
+ } else {
3330
+ throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
3331
+ }
3332
+ }
3333
+ };
3334
+ }
3335
+ function extractRowArray(row, output, columnCount, moduleName) {
3336
+ if (row.length !== columnCount) {
3337
+ throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
3338
+ }
3339
+ const offset = output.length - columnCount;
3340
+ for (let i = 0; i < columnCount; ++i) {
3341
+ output[i + offset] = row[i];
3342
+ }
3343
+ }
3344
+ function extractRowObject(row, output, columnMap, moduleName) {
3345
+ let count = 0;
3346
+ for (const key of Object.keys(row)) {
3347
+ const index = columnMap.get(key);
3348
+ if (index === void 0) {
3349
+ throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
3350
+ }
3351
+ output[index] = row[key];
3352
+ count += 1;
3353
+ }
3354
+ if (count !== columnMap.size) {
3355
+ throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
3356
+ }
3357
+ }
3358
+ function inferParameters({ length }) {
3359
+ if (!Number.isInteger(length) || length < 0) {
3360
+ throw new TypeError("Expected function.length to be a positive integer");
3361
+ }
3362
+ const params = [];
3363
+ for (let i = 0; i < length; ++i) {
3364
+ params.push(`$${i + 1}`);
3365
+ }
3366
+ return params;
3367
+ }
3368
+ var { hasOwnProperty } = Object.prototype;
3369
+ var { apply } = Function.prototype;
3370
+ var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {
3371
+ });
3372
+ var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
3373
+ var defer = (x) => () => x;
3521
3374
  }
3522
3375
  });
3523
3376
 
3524
- // src/index.ts
3525
- init_esm_shims();
3526
-
3527
- // node_modules/@modelcontextprotocol/sdk/dist/server/index.js
3528
- init_esm_shims();
3377
+ // node_modules/better-sqlite3/lib/methods/inspect.js
3378
+ var require_inspect = __commonJS({
3379
+ "node_modules/better-sqlite3/lib/methods/inspect.js"(exports2, module2) {
3380
+ "use strict";
3381
+ var DatabaseInspection = function Database() {
3382
+ };
3383
+ module2.exports = function inspect(depth, opts) {
3384
+ return Object.assign(new DatabaseInspection(), this);
3385
+ };
3386
+ }
3387
+ });
3529
3388
 
3530
- // node_modules/@modelcontextprotocol/sdk/dist/shared/protocol.js
3531
- init_esm_shims();
3389
+ // node_modules/better-sqlite3/lib/database.js
3390
+ var require_database = __commonJS({
3391
+ "node_modules/better-sqlite3/lib/database.js"(exports2, module2) {
3392
+ "use strict";
3393
+ var fs = require("fs");
3394
+ var path = require("path");
3395
+ var util2 = require_util2();
3396
+ var SqliteError = require_sqlite_error();
3397
+ var DEFAULT_ADDON;
3398
+ function Database(filenameGiven, options) {
3399
+ if (new.target == null) {
3400
+ return new Database(filenameGiven, options);
3401
+ }
3402
+ let buffer;
3403
+ if (Buffer.isBuffer(filenameGiven)) {
3404
+ buffer = filenameGiven;
3405
+ filenameGiven = ":memory:";
3406
+ }
3407
+ if (filenameGiven == null) filenameGiven = "";
3408
+ if (options == null) options = {};
3409
+ if (typeof filenameGiven !== "string") throw new TypeError("Expected first argument to be a string");
3410
+ if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
3411
+ if ("readOnly" in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
3412
+ if ("memory" in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
3413
+ const filename = filenameGiven.trim();
3414
+ const anonymous = filename === "" || filename === ":memory:";
3415
+ const readonly = util2.getBooleanOption(options, "readonly");
3416
+ const fileMustExist = util2.getBooleanOption(options, "fileMustExist");
3417
+ const timeout = "timeout" in options ? options.timeout : 5e3;
3418
+ const verbose = "verbose" in options ? options.verbose : null;
3419
+ const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
3420
+ if (readonly && anonymous && !buffer) throw new TypeError("In-memory/temporary databases cannot be readonly");
3421
+ if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
3422
+ if (timeout > 2147483647) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
3423
+ if (verbose != null && typeof verbose !== "function") throw new TypeError('Expected the "verbose" option to be a function');
3424
+ if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object") throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
3425
+ let addon;
3426
+ if (nativeBinding == null) {
3427
+ addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
3428
+ } else if (typeof nativeBinding === "string") {
3429
+ const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : require;
3430
+ addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
3431
+ } else {
3432
+ addon = nativeBinding;
3433
+ }
3434
+ if (!addon.isInitialized) {
3435
+ addon.setErrorConstructor(SqliteError);
3436
+ addon.isInitialized = true;
3437
+ }
3438
+ if (!anonymous && !filename.startsWith("file:") && !fs.existsSync(path.dirname(filename))) {
3439
+ throw new TypeError("Cannot open database because the directory does not exist");
3440
+ }
3441
+ Object.defineProperties(this, {
3442
+ [util2.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
3443
+ ...wrappers.getters
3444
+ });
3445
+ }
3446
+ var wrappers = require_wrappers();
3447
+ Database.prototype.prepare = wrappers.prepare;
3448
+ Database.prototype.transaction = require_transaction();
3449
+ Database.prototype.pragma = require_pragma();
3450
+ Database.prototype.backup = require_backup();
3451
+ Database.prototype.serialize = require_serialize();
3452
+ Database.prototype.function = require_function();
3453
+ Database.prototype.aggregate = require_aggregate();
3454
+ Database.prototype.table = require_table();
3455
+ Database.prototype.loadExtension = wrappers.loadExtension;
3456
+ Database.prototype.exec = wrappers.exec;
3457
+ Database.prototype.close = wrappers.close;
3458
+ Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
3459
+ Database.prototype.unsafeMode = wrappers.unsafeMode;
3460
+ Database.prototype[util2.inspect] = require_inspect();
3461
+ module2.exports = Database;
3462
+ }
3463
+ });
3532
3464
 
3533
- // node_modules/@modelcontextprotocol/sdk/dist/types.js
3534
- init_esm_shims();
3465
+ // node_modules/better-sqlite3/lib/index.js
3466
+ var require_lib = __commonJS({
3467
+ "node_modules/better-sqlite3/lib/index.js"(exports2, module2) {
3468
+ "use strict";
3469
+ module2.exports = require_database();
3470
+ module2.exports.SqliteError = require_sqlite_error();
3471
+ }
3472
+ });
3535
3473
 
3536
3474
  // node_modules/zod/lib/index.mjs
3537
- init_esm_shims();
3538
3475
  var util;
3539
3476
  (function(util2) {
3540
3477
  util2.assertEqual = (val) => val;
@@ -8715,11 +8652,9 @@ var Server = class extends Protocol {
8715
8652
  };
8716
8653
 
8717
8654
  // node_modules/@modelcontextprotocol/sdk/dist/server/stdio.js
8718
- init_esm_shims();
8719
- import process2 from "node:process";
8655
+ var import_node_process = __toESM(require("process"), 1);
8720
8656
 
8721
8657
  // node_modules/@modelcontextprotocol/sdk/dist/shared/stdio.js
8722
- init_esm_shims();
8723
8658
  var ReadBuffer = class {
8724
8659
  append(chunk) {
8725
8660
  this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
@@ -8749,7 +8684,7 @@ function serializeMessage(message) {
8749
8684
 
8750
8685
  // node_modules/@modelcontextprotocol/sdk/dist/server/stdio.js
8751
8686
  var StdioServerTransport = class {
8752
- constructor(_stdin = process2.stdin, _stdout = process2.stdout) {
8687
+ constructor(_stdin = import_node_process.default.stdin, _stdout = import_node_process.default.stdout) {
8753
8688
  this._stdin = _stdin;
8754
8689
  this._stdout = _stdout;
8755
8690
  this._readBuffer = new ReadBuffer();
@@ -8807,14 +8742,7 @@ var StdioServerTransport = class {
8807
8742
  }
8808
8743
  };
8809
8744
 
8810
- // src/tools/list-sessions.ts
8811
- init_esm_shims();
8812
-
8813
- // node_modules/cursor-history/dist/lib/index.js
8814
- init_esm_shims();
8815
-
8816
8745
  // node_modules/cursor-history/dist/lib/errors.js
8817
- init_esm_shims();
8818
8746
  var DatabaseLockedError = class _DatabaseLockedError extends Error {
8819
8747
  name = "DatabaseLockedError";
8820
8748
  /** Path to locked database file */
@@ -8960,13 +8888,9 @@ function isInvalidBackupError(error) {
8960
8888
  return error instanceof InvalidBackupError;
8961
8889
  }
8962
8890
 
8963
- // node_modules/cursor-history/dist/lib/utils.js
8964
- init_esm_shims();
8965
-
8966
8891
  // node_modules/cursor-history/dist/lib/platform.js
8967
- init_esm_shims();
8968
- import { homedir } from "node:os";
8969
- import { join } from "node:path";
8892
+ var import_node_os = require("os");
8893
+ var import_node_path = require("path");
8970
8894
  function detectPlatform() {
8971
8895
  switch (process.platform) {
8972
8896
  case "win32":
@@ -8981,11 +8905,11 @@ function getDefaultCursorDataPath(platform) {
8981
8905
  const p = platform ?? detectPlatform();
8982
8906
  switch (p) {
8983
8907
  case "windows":
8984
- return join(process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming"), "Cursor", "User", "workspaceStorage");
8908
+ return (0, import_node_path.join)(process.env["APPDATA"] ?? (0, import_node_path.join)((0, import_node_os.homedir)(), "AppData", "Roaming"), "Cursor", "User", "workspaceStorage");
8985
8909
  case "macos":
8986
- return join(homedir(), "Library", "Application Support", "Cursor", "User", "workspaceStorage");
8910
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), "Library", "Application Support", "Cursor", "User", "workspaceStorage");
8987
8911
  case "linux":
8988
- return join(homedir(), ".config", "Cursor", "User", "workspaceStorage");
8912
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), ".config", "Cursor", "User", "workspaceStorage");
8989
8913
  }
8990
8914
  }
8991
8915
  function getCursorDataPath(customPath) {
@@ -9000,12 +8924,12 @@ function getCursorDataPath(customPath) {
9000
8924
  }
9001
8925
  function expandPath(path) {
9002
8926
  if (path.startsWith("~")) {
9003
- return join(homedir(), path.slice(1));
8927
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), path.slice(1));
9004
8928
  }
9005
8929
  return path;
9006
8930
  }
9007
8931
  function contractPath(path) {
9008
- const home = homedir();
8932
+ const home = (0, import_node_os.homedir)();
9009
8933
  if (path.startsWith(home)) {
9010
8934
  return "~" + path.slice(home.length);
9011
8935
  }
@@ -9014,7 +8938,7 @@ function contractPath(path) {
9014
8938
  function normalizePath(filePath) {
9015
8939
  let normalized = filePath;
9016
8940
  if (normalized.startsWith("~")) {
9017
- normalized = join(homedir(), normalized.slice(1));
8941
+ normalized = (0, import_node_path.join)((0, import_node_os.homedir)(), normalized.slice(1));
9018
8942
  }
9019
8943
  while (normalized.length > 1 && normalized.endsWith("/")) {
9020
8944
  normalized = normalized.slice(0, -1);
@@ -9034,8 +8958,9 @@ function pathsEqual(path1, path2) {
9034
8958
  }
9035
8959
 
9036
8960
  // node_modules/cursor-history/dist/lib/config.js
9037
- init_esm_shims();
9038
- import { resolve, normalize, isAbsolute } from "node:path";
8961
+ var import_node_fs = require("fs");
8962
+ var import_node_path2 = require("path");
8963
+ var VALID_SQLITE_DRIVERS = ["better-sqlite3", "node:sqlite"];
9039
8964
  function validateConfig(config) {
9040
8965
  if (!config)
9041
8966
  return;
@@ -9058,13 +8983,18 @@ function validateConfig(config) {
9058
8983
  if (typeof config.workspace !== "string") {
9059
8984
  throw new InvalidConfigError("workspace", config.workspace, "must be a string");
9060
8985
  }
9061
- if (!isAbsolute(config.workspace)) {
8986
+ if (!(0, import_node_path2.isAbsolute)(config.workspace)) {
9062
8987
  throw new InvalidConfigError("workspace", config.workspace, "must be an absolute path");
9063
8988
  }
9064
8989
  }
9065
8990
  if (config.dataPath !== void 0 && typeof config.dataPath !== "string") {
9066
8991
  throw new InvalidConfigError("dataPath", config.dataPath, "must be a string");
9067
8992
  }
8993
+ if (config.sqliteDriver !== void 0) {
8994
+ if (!VALID_SQLITE_DRIVERS.includes(config.sqliteDriver)) {
8995
+ throw new InvalidConfigError("sqliteDriver", config.sqliteDriver, `must be one of: ${VALID_SQLITE_DRIVERS.join(", ")}`);
8996
+ }
8997
+ }
9068
8998
  }
9069
8999
  function mergeWithDefaults(config) {
9070
9000
  validateConfig(config);
@@ -9075,20 +9005,387 @@ function mergeWithDefaults(config) {
9075
9005
  limit: config?.limit ?? Number.MAX_SAFE_INTEGER,
9076
9006
  offset: config?.offset ?? 0,
9077
9007
  context: config?.context ?? 0,
9078
- backupPath: config?.backupPath
9008
+ backupPath: config?.backupPath,
9009
+ sqliteDriver: config?.sqliteDriver
9079
9010
  };
9080
9011
  }
9081
9012
 
9082
9013
  // node_modules/cursor-history/dist/core/storage.js
9083
- init_esm_shims();
9084
- var import_better_sqlite32 = __toESM(require_lib(), 1);
9014
+ var import_node_fs3 = require("fs");
9015
+ var import_node_path4 = require("path");
9016
+ var import_node_os3 = require("os");
9085
9017
  var import_adm_zip2 = __toESM(require_adm_zip(), 1);
9086
- import { existsSync as existsSync2, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
9087
- import { join as join3 } from "node:path";
9088
- import { homedir as homedir3 } from "node:os";
9018
+
9019
+ // node_modules/cursor-history/dist/core/database/errors.js
9020
+ var NoDriverAvailableError = class extends Error {
9021
+ constructor() {
9022
+ super("No SQLite driver available. Either install better-sqlite3 (npm install better-sqlite3) or use Node.js 22.5+ with --experimental-sqlite flag.");
9023
+ this.name = "NoDriverAvailableError";
9024
+ }
9025
+ };
9026
+ var DriverNotAvailableError = class extends Error {
9027
+ constructor(driverName, availableDrivers) {
9028
+ const available = availableDrivers.length > 0 ? `Available drivers: ${availableDrivers.join(", ")}` : "No drivers are currently available.";
9029
+ super(`Driver "${driverName}" is not available. ${available}`);
9030
+ this.name = "DriverNotAvailableError";
9031
+ }
9032
+ };
9033
+ var ReadonlyDatabaseError = class extends Error {
9034
+ constructor() {
9035
+ super("Cannot write to a read-only database connection.");
9036
+ this.name = "ReadonlyDatabaseError";
9037
+ }
9038
+ };
9039
+
9040
+ // node_modules/cursor-history/dist/core/database/debug.js
9041
+ function debugLog(message) {
9042
+ if (process.env["DEBUG"] || process.env["CURSOR_HISTORY_DEBUG"]) {
9043
+ console.error(`[cursor-history:sqlite] ${message}`);
9044
+ }
9045
+ }
9046
+
9047
+ // node_modules/cursor-history/dist/core/database/registry.js
9048
+ var DriverRegistry = class {
9049
+ drivers = /* @__PURE__ */ new Map();
9050
+ currentDriver = null;
9051
+ initialized = false;
9052
+ /**
9053
+ * Register a driver with the registry
9054
+ */
9055
+ register(driver) {
9056
+ this.drivers.set(driver.name, driver);
9057
+ debugLog(`Registered driver: ${driver.name}`);
9058
+ }
9059
+ /**
9060
+ * Get all registered driver names
9061
+ */
9062
+ getRegisteredDrivers() {
9063
+ return Array.from(this.drivers.keys());
9064
+ }
9065
+ /**
9066
+ * Check which drivers are currently available
9067
+ */
9068
+ async getAvailableDrivers() {
9069
+ const available = [];
9070
+ for (const [name, driver] of this.drivers) {
9071
+ if (await driver.isAvailable()) {
9072
+ available.push(name);
9073
+ }
9074
+ }
9075
+ return available;
9076
+ }
9077
+ /**
9078
+ * Auto-detect and select the best available driver
9079
+ *
9080
+ * Priority:
9081
+ * 1. User-specified via CURSOR_HISTORY_SQLITE_DRIVER env var
9082
+ * 2. node:sqlite (no native bindings, ESM compatible)
9083
+ * 3. better-sqlite3 (fallback)
9084
+ */
9085
+ async autoSelect() {
9086
+ const envDriver = process.env["CURSOR_HISTORY_SQLITE_DRIVER"];
9087
+ if (envDriver) {
9088
+ debugLog(`Environment override: CURSOR_HISTORY_SQLITE_DRIVER=${envDriver}`);
9089
+ const driver = this.drivers.get(envDriver);
9090
+ if (driver && await driver.isAvailable()) {
9091
+ this.currentDriver = driver;
9092
+ this.initialized = true;
9093
+ debugLog(`Using driver from env var: ${driver.name}`);
9094
+ return driver;
9095
+ }
9096
+ const available = await this.getAvailableDrivers();
9097
+ throw new DriverNotAvailableError(envDriver, available);
9098
+ }
9099
+ const nodeSqlite = this.drivers.get("node:sqlite");
9100
+ if (nodeSqlite && await nodeSqlite.isAvailable()) {
9101
+ this.currentDriver = nodeSqlite;
9102
+ this.initialized = true;
9103
+ debugLog(`Auto-selected driver: node:sqlite`);
9104
+ return nodeSqlite;
9105
+ }
9106
+ const betterSqlite = this.drivers.get("better-sqlite3");
9107
+ if (betterSqlite && await betterSqlite.isAvailable()) {
9108
+ this.currentDriver = betterSqlite;
9109
+ this.initialized = true;
9110
+ debugLog(`Auto-selected driver: better-sqlite3`);
9111
+ return betterSqlite;
9112
+ }
9113
+ throw new NoDriverAvailableError();
9114
+ }
9115
+ /**
9116
+ * Manually set the active driver by name
9117
+ */
9118
+ async setDriver(name) {
9119
+ const driver = this.drivers.get(name);
9120
+ if (!driver) {
9121
+ const available = await this.getAvailableDrivers();
9122
+ throw new DriverNotAvailableError(name, available);
9123
+ }
9124
+ if (!await driver.isAvailable()) {
9125
+ const available = await this.getAvailableDrivers();
9126
+ throw new DriverNotAvailableError(name, available);
9127
+ }
9128
+ this.currentDriver = driver;
9129
+ this.initialized = true;
9130
+ debugLog(`Manually set driver: ${name}`);
9131
+ }
9132
+ /**
9133
+ * Get the name of the currently active driver
9134
+ */
9135
+ getActiveDriver() {
9136
+ if (!this.currentDriver) {
9137
+ throw new Error("No driver is currently active. Call autoSelect() or setDriver() first.");
9138
+ }
9139
+ return this.currentDriver.name;
9140
+ }
9141
+ /**
9142
+ * Check if a driver has been selected
9143
+ */
9144
+ hasActiveDriver() {
9145
+ return this.currentDriver !== null;
9146
+ }
9147
+ /**
9148
+ * Get the current driver, auto-selecting if needed
9149
+ */
9150
+ async ensureDriver() {
9151
+ if (!this.initialized || !this.currentDriver) {
9152
+ return this.autoSelect();
9153
+ }
9154
+ return this.currentDriver;
9155
+ }
9156
+ /**
9157
+ * Open a database in read-only mode
9158
+ */
9159
+ async openDatabase(path) {
9160
+ const driver = await this.ensureDriver();
9161
+ return driver.open(path, { readonly: true });
9162
+ }
9163
+ /**
9164
+ * Open a database in read-write mode
9165
+ */
9166
+ async openDatabaseReadWrite(path) {
9167
+ const driver = await this.ensureDriver();
9168
+ return driver.open(path, { readonly: false });
9169
+ }
9170
+ /**
9171
+ * Synchronous database open (requires driver to already be selected)
9172
+ *
9173
+ * This is used by backup module which needs synchronous access.
9174
+ * Auto-selection must have happened before calling this.
9175
+ */
9176
+ openSync(path, options) {
9177
+ if (!this.currentDriver) {
9178
+ throw new Error("No driver is currently active. Auto-selection must complete before using openSync(). Call a database operation first to trigger auto-selection.");
9179
+ }
9180
+ return this.currentDriver.open(path, options);
9181
+ }
9182
+ /**
9183
+ * Backup a database file to another location
9184
+ *
9185
+ * Uses the native SQLite backup API for consistent snapshots.
9186
+ */
9187
+ async backupDatabase(sourcePath, destPath) {
9188
+ const driver = await this.ensureDriver();
9189
+ return driver.backup(sourcePath, destPath);
9190
+ }
9191
+ /**
9192
+ * Reset the registry (mainly for testing)
9193
+ */
9194
+ reset() {
9195
+ this.currentDriver = null;
9196
+ this.initialized = false;
9197
+ debugLog("Registry reset");
9198
+ }
9199
+ };
9200
+ var registry = new DriverRegistry();
9201
+
9202
+ // node_modules/cursor-history/dist/core/database/drivers/better-sqlite3.js
9203
+ var BetterSqlite3 = null;
9204
+ var BetterSqlite3Statement = class {
9205
+ stmt;
9206
+ constructor(stmt) {
9207
+ this.stmt = stmt;
9208
+ }
9209
+ get(...params) {
9210
+ return this.stmt.get(...params);
9211
+ }
9212
+ all(...params) {
9213
+ return this.stmt.all(...params);
9214
+ }
9215
+ run(...params) {
9216
+ const result = this.stmt.run(...params);
9217
+ return {
9218
+ changes: result.changes,
9219
+ lastInsertRowid: result.lastInsertRowid
9220
+ };
9221
+ }
9222
+ };
9223
+ var BetterSqlite3Database = class {
9224
+ nativeDb;
9225
+ constructor(db) {
9226
+ this.nativeDb = db;
9227
+ }
9228
+ prepare(sql) {
9229
+ return new BetterSqlite3Statement(this.nativeDb.prepare(sql));
9230
+ }
9231
+ runSQL(sql) {
9232
+ this.nativeDb.exec(sql);
9233
+ }
9234
+ close() {
9235
+ this.nativeDb.close();
9236
+ }
9237
+ };
9238
+ var betterSqlite3Driver = {
9239
+ name: "better-sqlite3",
9240
+ async isAvailable() {
9241
+ try {
9242
+ if (!BetterSqlite3) {
9243
+ const module2 = await Promise.resolve().then(() => __toESM(require_lib(), 1));
9244
+ BetterSqlite3 = module2.default;
9245
+ }
9246
+ debugLog("better-sqlite3 is available");
9247
+ return true;
9248
+ } catch {
9249
+ debugLog("better-sqlite3 is not available");
9250
+ return false;
9251
+ }
9252
+ },
9253
+ open(path, options) {
9254
+ if (!BetterSqlite3) {
9255
+ throw new Error("better-sqlite3 is not loaded. Call isAvailable() first.");
9256
+ }
9257
+ const db = new BetterSqlite3(path, { readonly: options.readonly });
9258
+ debugLog(`Opened database with better-sqlite3: ${path} (readonly: ${options.readonly})`);
9259
+ return new BetterSqlite3Database(db);
9260
+ },
9261
+ async backup(sourcePath, destPath) {
9262
+ if (!BetterSqlite3) {
9263
+ throw new Error("better-sqlite3 is not loaded. Call isAvailable() first.");
9264
+ }
9265
+ const sourceDb = new BetterSqlite3(sourcePath, { readonly: true });
9266
+ try {
9267
+ debugLog(`Backing up database with better-sqlite3: ${sourcePath} -> ${destPath}`);
9268
+ await sourceDb.backup(destPath);
9269
+ debugLog(`Backup completed: ${destPath}`);
9270
+ } finally {
9271
+ sourceDb.close();
9272
+ }
9273
+ }
9274
+ };
9275
+
9276
+ // node_modules/cursor-history/dist/core/database/drivers/node-sqlite.js
9277
+ var nodeSqliteModule = null;
9278
+ var NodeSqliteStatementWrapper = class {
9279
+ stmt;
9280
+ isReadonly;
9281
+ constructor(stmt, isReadonly) {
9282
+ this.stmt = stmt;
9283
+ this.isReadonly = isReadonly;
9284
+ }
9285
+ get(...params) {
9286
+ return this.stmt.get(...params);
9287
+ }
9288
+ all(...params) {
9289
+ return this.stmt.all(...params);
9290
+ }
9291
+ run(...params) {
9292
+ if (this.isReadonly) {
9293
+ throw new ReadonlyDatabaseError();
9294
+ }
9295
+ const result = this.stmt.run(...params);
9296
+ return {
9297
+ changes: Number(result.changes),
9298
+ lastInsertRowid: result.lastInsertRowid
9299
+ };
9300
+ }
9301
+ };
9302
+ var NodeSqliteDatabaseWrapper = class {
9303
+ nativeDb;
9304
+ isReadonly;
9305
+ constructor(db, readonly) {
9306
+ this.nativeDb = db;
9307
+ this.isReadonly = readonly;
9308
+ }
9309
+ prepare(sql) {
9310
+ if (this.isReadonly) {
9311
+ const upperSql = sql.trim().toUpperCase();
9312
+ if (upperSql.startsWith("INSERT") || upperSql.startsWith("UPDATE") || upperSql.startsWith("DELETE") || upperSql.startsWith("DROP") || upperSql.startsWith("CREATE") || upperSql.startsWith("ALTER")) {
9313
+ throw new ReadonlyDatabaseError();
9314
+ }
9315
+ }
9316
+ return new NodeSqliteStatementWrapper(this.nativeDb.prepare(sql), this.isReadonly);
9317
+ }
9318
+ runSQL(sql) {
9319
+ if (this.isReadonly) {
9320
+ throw new ReadonlyDatabaseError();
9321
+ }
9322
+ const nativeMethod = "exec";
9323
+ const db = this.nativeDb;
9324
+ if (typeof db[nativeMethod] === "function") {
9325
+ db[nativeMethod](sql);
9326
+ } else {
9327
+ this.nativeDb.prepare(sql).run();
9328
+ }
9329
+ }
9330
+ close() {
9331
+ this.nativeDb.close();
9332
+ }
9333
+ };
9334
+ var nodeSqliteDriver = {
9335
+ name: "node:sqlite",
9336
+ async isAvailable() {
9337
+ try {
9338
+ if (!nodeSqliteModule) {
9339
+ const module2 = await import("sqlite");
9340
+ nodeSqliteModule = module2;
9341
+ }
9342
+ debugLog("node:sqlite is available");
9343
+ return true;
9344
+ } catch {
9345
+ debugLog("node:sqlite is not available");
9346
+ return false;
9347
+ }
9348
+ },
9349
+ open(path, options) {
9350
+ if (!nodeSqliteModule) {
9351
+ throw new Error("node:sqlite is not loaded. Call isAvailable() first.");
9352
+ }
9353
+ const db = new nodeSqliteModule.DatabaseSync(path);
9354
+ debugLog(`Opened database with node:sqlite: ${path} (readonly: ${options.readonly})`);
9355
+ return new NodeSqliteDatabaseWrapper(db, options.readonly);
9356
+ },
9357
+ async backup(sourcePath, destPath) {
9358
+ if (!nodeSqliteModule) {
9359
+ throw new Error("node:sqlite is not loaded. Call isAvailable() first.");
9360
+ }
9361
+ const sourceDb = new nodeSqliteModule.DatabaseSync(sourcePath);
9362
+ try {
9363
+ debugLog(`Backing up database with node:sqlite: ${sourcePath} -> ${destPath}`);
9364
+ await nodeSqliteModule.backup(sourceDb, destPath);
9365
+ debugLog(`Backup completed: ${destPath}`);
9366
+ } finally {
9367
+ sourceDb.close();
9368
+ }
9369
+ }
9370
+ };
9371
+
9372
+ // node_modules/cursor-history/dist/core/database/index.js
9373
+ registry.register(nodeSqliteDriver);
9374
+ registry.register(betterSqlite3Driver);
9375
+ async function openDatabase(path) {
9376
+ return registry.openDatabase(path);
9377
+ }
9378
+ async function openDatabaseReadWrite(path) {
9379
+ return registry.openDatabaseReadWrite(path);
9380
+ }
9381
+ async function ensureDriver() {
9382
+ await registry.ensureDriver();
9383
+ }
9384
+ async function backupDatabase(sourcePath, destPath) {
9385
+ return registry.backupDatabase(sourcePath, destPath);
9386
+ }
9089
9387
 
9090
9388
  // node_modules/cursor-history/dist/core/parser.js
9091
- init_esm_shims();
9092
9389
  function parseChatData(jsonString, bundle) {
9093
9390
  let data;
9094
9391
  try {
@@ -9326,20 +9623,18 @@ function exportToJson(session, workspacePath) {
9326
9623
  }
9327
9624
 
9328
9625
  // node_modules/cursor-history/dist/core/backup.js
9329
- init_esm_shims();
9330
- var import_better_sqlite3 = __toESM(require_lib(), 1);
9626
+ var import_node_crypto = require("crypto");
9627
+ var import_node_fs2 = require("fs");
9628
+ var import_node_os2 = require("os");
9629
+ var import_node_path3 = require("path");
9331
9630
  var import_adm_zip = __toESM(require_adm_zip(), 1);
9332
- import { createHash } from "node:crypto";
9333
- import { existsSync, mkdirSync, readdirSync, statSync, unlinkSync, readFileSync, writeFileSync, rmdirSync } from "node:fs";
9334
- import { homedir as homedir2, tmpdir } from "node:os";
9335
- import { join as join2, basename, dirname, sep } from "node:path";
9336
- var CURSOR_HISTORY_VERSION = "0.8.0";
9631
+ var CURSOR_HISTORY_VERSION = "0.9.1";
9337
9632
  var MANIFEST_VERSION = "1.0.0";
9338
9633
  function getDefaultBackupDir() {
9339
- return join2(homedir2(), "cursor-history-backups");
9634
+ return (0, import_node_path3.join)((0, import_node_os2.homedir)(), "cursor-history-backups");
9340
9635
  }
9341
9636
  function computeChecksum(buffer) {
9342
- return `sha256:${createHash("sha256").update(buffer).digest("hex")}`;
9637
+ return `sha256:${(0, import_node_crypto.createHash)("sha256").update(buffer).digest("hex")}`;
9343
9638
  }
9344
9639
  function generateBackupFilename() {
9345
9640
  const now = /* @__PURE__ */ new Date();
@@ -9353,10 +9648,10 @@ function generateBackupFilename() {
9353
9648
  }
9354
9649
  function scanDatabaseFiles(dataPath) {
9355
9650
  const files = [];
9356
- const userDir = dirname(dataPath);
9357
- const globalDbPath = join2(userDir, "globalStorage", "state.vscdb");
9358
- if (existsSync(globalDbPath)) {
9359
- const stat = statSync(globalDbPath);
9651
+ const userDir = (0, import_node_path3.dirname)(dataPath);
9652
+ const globalDbPath = (0, import_node_path3.join)(userDir, "globalStorage", "state.vscdb");
9653
+ if ((0, import_node_fs2.existsSync)(globalDbPath)) {
9654
+ const stat = (0, import_node_fs2.statSync)(globalDbPath);
9360
9655
  files.push({
9361
9656
  absolutePath: globalDbPath,
9362
9657
  relativePath: "globalStorage/state.vscdb",
@@ -9365,15 +9660,15 @@ function scanDatabaseFiles(dataPath) {
9365
9660
  });
9366
9661
  }
9367
9662
  const workspaceStorageDir = dataPath;
9368
- if (existsSync(workspaceStorageDir)) {
9663
+ if ((0, import_node_fs2.existsSync)(workspaceStorageDir)) {
9369
9664
  try {
9370
- const entries = readdirSync(workspaceStorageDir, { withFileTypes: true });
9665
+ const entries = (0, import_node_fs2.readdirSync)(workspaceStorageDir, { withFileTypes: true });
9371
9666
  for (const entry of entries) {
9372
9667
  if (entry.isDirectory()) {
9373
- const workspaceDir = join2(workspaceStorageDir, entry.name);
9374
- const workspaceDbPath = join2(workspaceDir, "state.vscdb");
9375
- if (existsSync(workspaceDbPath)) {
9376
- const stat = statSync(workspaceDbPath);
9668
+ const workspaceDir = (0, import_node_path3.join)(workspaceStorageDir, entry.name);
9669
+ const workspaceDbPath = (0, import_node_path3.join)(workspaceDir, "state.vscdb");
9670
+ if ((0, import_node_fs2.existsSync)(workspaceDbPath)) {
9671
+ const stat = (0, import_node_fs2.statSync)(workspaceDbPath);
9377
9672
  files.push({
9378
9673
  absolutePath: workspaceDbPath,
9379
9674
  relativePath: `workspaceStorage/${entry.name}/state.vscdb`,
@@ -9382,9 +9677,9 @@ function scanDatabaseFiles(dataPath) {
9382
9677
  workspaceId: entry.name
9383
9678
  });
9384
9679
  }
9385
- const workspaceJsonPath = join2(workspaceDir, "workspace.json");
9386
- if (existsSync(workspaceJsonPath)) {
9387
- const stat = statSync(workspaceJsonPath);
9680
+ const workspaceJsonPath = (0, import_node_path3.join)(workspaceDir, "workspace.json");
9681
+ if ((0, import_node_fs2.existsSync)(workspaceJsonPath)) {
9682
+ const stat = (0, import_node_fs2.statSync)(workspaceJsonPath);
9388
9683
  files.push({
9389
9684
  absolutePath: workspaceJsonPath,
9390
9685
  relativePath: `workspaceStorage/${entry.name}/workspace.json`,
@@ -9413,7 +9708,7 @@ function createManifest(files, stats) {
9413
9708
  }
9414
9709
  function countSessions(dbPath) {
9415
9710
  try {
9416
- const db = new import_better_sqlite3.default(dbPath, { readonly: true });
9711
+ const db = registry.openSync(dbPath, { readonly: true });
9417
9712
  try {
9418
9713
  const row = db.prepare("SELECT value FROM ItemTable WHERE key = 'composer.composerData'").get();
9419
9714
  if (row) {
@@ -9433,19 +9728,11 @@ function countSessions(dbPath) {
9433
9728
  return 0;
9434
9729
  }
9435
9730
  }
9436
- async function backupDatabase(sourcePath, destPath) {
9437
- const sourceDb = new import_better_sqlite3.default(sourcePath, { readonly: true });
9438
- try {
9439
- await sourceDb.backup(destPath);
9440
- } finally {
9441
- sourceDb.close();
9442
- }
9443
- }
9444
9731
  function checkDiskSpace(outputPath, requiredBytes) {
9445
- const dir = dirname(outputPath);
9732
+ const dir = (0, import_node_path3.dirname)(outputPath);
9446
9733
  try {
9447
- if (!existsSync(dir)) {
9448
- mkdirSync(dir, { recursive: true });
9734
+ if (!(0, import_node_fs2.existsSync)(dir)) {
9735
+ (0, import_node_fs2.mkdirSync)(dir, { recursive: true });
9449
9736
  }
9450
9737
  return {
9451
9738
  available: Number.MAX_SAFE_INTEGER,
@@ -9463,14 +9750,14 @@ function checkDiskSpace(outputPath, requiredBytes) {
9463
9750
  async function createBackup(config) {
9464
9751
  const startTime = Date.now();
9465
9752
  const sourcePath = config?.sourcePath ?? getDefaultCursorDataPath2();
9466
- const outputDir = config?.outputPath ? dirname(config.outputPath) : getDefaultBackupDir();
9467
- const outputPath = config?.outputPath ?? join2(outputDir, generateBackupFilename());
9753
+ const outputDir = config?.outputPath ? (0, import_node_path3.dirname)(config.outputPath) : getDefaultBackupDir();
9754
+ const outputPath = config?.outputPath ?? (0, import_node_path3.join)(outputDir, generateBackupFilename());
9468
9755
  const force = config?.force ?? false;
9469
9756
  const onProgress = config?.onProgress;
9470
- if (!existsSync(outputDir)) {
9471
- mkdirSync(outputDir, { recursive: true });
9757
+ if (!(0, import_node_fs2.existsSync)(outputDir)) {
9758
+ (0, import_node_fs2.mkdirSync)(outputDir, { recursive: true });
9472
9759
  }
9473
- if (existsSync(outputPath) && !force) {
9760
+ if ((0, import_node_fs2.existsSync)(outputPath) && !force) {
9474
9761
  return {
9475
9762
  success: false,
9476
9763
  backupPath: outputPath,
@@ -9507,8 +9794,8 @@ async function createBackup(config) {
9507
9794
  error: `Insufficient disk space`
9508
9795
  };
9509
9796
  }
9510
- const tempDir = join2(outputDir, `.backup_temp_${Date.now()}`);
9511
- mkdirSync(tempDir, { recursive: true });
9797
+ const tempDir = (0, import_node_path3.join)(outputDir, `.backup_temp_${Date.now()}`);
9798
+ (0, import_node_fs2.mkdirSync)(tempDir, { recursive: true });
9512
9799
  try {
9513
9800
  const fileEntries = [];
9514
9801
  let bytesCompleted = 0;
@@ -9524,15 +9811,15 @@ async function createBackup(config) {
9524
9811
  bytesCompleted,
9525
9812
  totalBytes
9526
9813
  });
9527
- const tempFilePath = join2(tempDir, dbFile.relativePath);
9528
- mkdirSync(dirname(tempFilePath), { recursive: true });
9814
+ const tempFilePath = (0, import_node_path3.join)(tempDir, dbFile.relativePath);
9815
+ (0, import_node_fs2.mkdirSync)((0, import_node_path3.dirname)(tempFilePath), { recursive: true });
9529
9816
  if (dbFile.type === "global-db" || dbFile.type === "workspace-db") {
9530
9817
  await backupDatabase(dbFile.absolutePath, tempFilePath);
9531
9818
  } else {
9532
- const content = readFileSync(dbFile.absolutePath);
9533
- writeFileSync(tempFilePath, content);
9819
+ const content = (0, import_node_fs2.readFileSync)(dbFile.absolutePath);
9820
+ (0, import_node_fs2.writeFileSync)(tempFilePath, content);
9534
9821
  }
9535
- const buffer = readFileSync(tempFilePath);
9822
+ const buffer = (0, import_node_fs2.readFileSync)(tempFilePath);
9536
9823
  const checksum = computeChecksum(buffer);
9537
9824
  fileEntries.push({
9538
9825
  path: dbFile.relativePath,
@@ -9557,9 +9844,9 @@ async function createBackup(config) {
9557
9844
  });
9558
9845
  const zip = new import_adm_zip.default();
9559
9846
  for (const entry of fileEntries) {
9560
- const filePath = join2(tempDir, entry.path);
9561
- const zipPath = entry.path.split(sep).join("/");
9562
- zip.addLocalFile(filePath, dirname(zipPath), basename(zipPath));
9847
+ const filePath = (0, import_node_path3.join)(tempDir, entry.path);
9848
+ const zipPath = entry.path.split(import_node_path3.sep).join("/");
9849
+ zip.addLocalFile(filePath, (0, import_node_path3.dirname)(zipPath), (0, import_node_path3.basename)(zipPath));
9563
9850
  }
9564
9851
  const stats = {
9565
9852
  totalSize: fileEntries.reduce((sum, f) => sum + f.size, 0),
@@ -9575,8 +9862,8 @@ async function createBackup(config) {
9575
9862
  bytesCompleted: totalBytes,
9576
9863
  totalBytes
9577
9864
  });
9578
- if (existsSync(outputPath)) {
9579
- unlinkSync(outputPath);
9865
+ if ((0, import_node_fs2.existsSync)(outputPath)) {
9866
+ (0, import_node_fs2.unlinkSync)(outputPath);
9580
9867
  }
9581
9868
  zip.writeZip(outputPath);
9582
9869
  return {
@@ -9588,47 +9875,67 @@ async function createBackup(config) {
9588
9875
  } finally {
9589
9876
  try {
9590
9877
  const cleanupDir = (dir) => {
9591
- const entries = readdirSync(dir, { withFileTypes: true });
9878
+ const entries = (0, import_node_fs2.readdirSync)(dir, { withFileTypes: true });
9592
9879
  for (const entry of entries) {
9593
- const fullPath = join2(dir, entry.name);
9880
+ const fullPath = (0, import_node_path3.join)(dir, entry.name);
9594
9881
  if (entry.isDirectory()) {
9595
9882
  cleanupDir(fullPath);
9596
9883
  } else {
9597
- unlinkSync(fullPath);
9884
+ (0, import_node_fs2.unlinkSync)(fullPath);
9598
9885
  }
9599
9886
  }
9600
9887
  try {
9601
- rmdirSync(dir);
9888
+ (0, import_node_fs2.rmdirSync)(dir);
9602
9889
  } catch {
9603
9890
  }
9604
9891
  };
9605
- if (existsSync(tempDir)) {
9892
+ if ((0, import_node_fs2.existsSync)(tempDir)) {
9606
9893
  cleanupDir(tempDir);
9607
9894
  }
9608
9895
  } catch {
9609
9896
  }
9610
9897
  }
9611
9898
  }
9899
+ var TempFileCleanupWrapper = class {
9900
+ innerDb;
9901
+ tempFilePath;
9902
+ constructor(innerDb, tempFilePath) {
9903
+ this.innerDb = innerDb;
9904
+ this.tempFilePath = tempFilePath;
9905
+ }
9906
+ prepare(sql) {
9907
+ return this.innerDb.prepare(sql);
9908
+ }
9909
+ runSQL(sql) {
9910
+ this.innerDb.runSQL(sql);
9911
+ }
9912
+ close() {
9913
+ this.innerDb.close();
9914
+ try {
9915
+ (0, import_node_fs2.unlinkSync)(this.tempFilePath);
9916
+ } catch {
9917
+ }
9918
+ }
9919
+ };
9612
9920
  function openBackupDatabase(backupPath, dbPath) {
9613
9921
  const zip = new import_adm_zip.default(backupPath);
9614
9922
  const buffer = zip.readFile(dbPath);
9615
9923
  if (!buffer) {
9616
9924
  throw new Error(`Database not found in backup: ${dbPath}`);
9617
9925
  }
9618
- const tempFile = join2(tmpdir(), `cursor_history_backup_${Date.now()}_${Math.random().toString(36).slice(2)}.vscdb`);
9619
- writeFileSync(tempFile, buffer);
9620
- const db = new import_better_sqlite3.default(tempFile, { readonly: true });
9621
- db._tempFile = tempFile;
9622
- const originalClose = db.close.bind(db);
9623
- db.close = () => {
9624
- const result = originalClose();
9926
+ const tempFile = (0, import_node_path3.join)((0, import_node_os2.tmpdir)(), `cursor_history_backup_${Date.now()}_${Math.random().toString(36).slice(2)}.vscdb`);
9927
+ (0, import_node_fs2.writeFileSync)(tempFile, buffer);
9928
+ let db = null;
9929
+ try {
9930
+ db = registry.openSync(tempFile, { readonly: true });
9931
+ } catch (err) {
9625
9932
  try {
9626
- unlinkSync(tempFile);
9933
+ (0, import_node_fs2.unlinkSync)(tempFile);
9627
9934
  } catch {
9628
9935
  }
9629
- return result;
9630
- };
9631
- return db;
9936
+ throw err;
9937
+ }
9938
+ return new TempFileCleanupWrapper(db, tempFile);
9632
9939
  }
9633
9940
  function readBackupManifest(backupPath) {
9634
9941
  try {
@@ -9647,7 +9954,7 @@ function validateBackup(backupPath) {
9647
9954
  const validFiles = [];
9648
9955
  const corruptedFiles = [];
9649
9956
  const missingFiles = [];
9650
- if (!existsSync(backupPath)) {
9957
+ if (!(0, import_node_fs2.existsSync)(backupPath)) {
9651
9958
  return {
9652
9959
  status: "invalid",
9653
9960
  validFiles: [],
@@ -9750,9 +10057,9 @@ function restoreBackup(config) {
9750
10057
  };
9751
10058
  }
9752
10059
  const manifest = validation.manifest;
9753
- const userDir = dirname(targetPath);
9754
- const globalDbPath = join2(userDir, "globalStorage", "state.vscdb");
9755
- if (!force && existsSync(globalDbPath)) {
10060
+ const userDir = (0, import_node_path3.dirname)(targetPath);
10061
+ const globalDbPath = (0, import_node_path3.join)(userDir, "globalStorage", "state.vscdb");
10062
+ if (!force && (0, import_node_fs2.existsSync)(globalDbPath)) {
9756
10063
  return {
9757
10064
  success: false,
9758
10065
  targetPath,
@@ -9787,10 +10094,10 @@ function restoreBackup(config) {
9787
10094
  if (!buffer) {
9788
10095
  continue;
9789
10096
  }
9790
- const platformPath = fileEntry.path.split("/").join(sep);
9791
- const destPath = join2(userDir, platformPath);
9792
- mkdirSync(dirname(destPath), { recursive: true });
9793
- writeFileSync(destPath, buffer);
10097
+ const platformPath = fileEntry.path.split("/").join(import_node_path3.sep);
10098
+ const destPath = (0, import_node_path3.join)(userDir, platformPath);
10099
+ (0, import_node_fs2.mkdirSync)((0, import_node_path3.dirname)(destPath), { recursive: true });
10100
+ (0, import_node_fs2.writeFileSync)(destPath, buffer);
9794
10101
  restoredFiles.push(fileEntry.path);
9795
10102
  }
9796
10103
  onProgress?.({
@@ -9809,10 +10116,10 @@ function restoreBackup(config) {
9809
10116
  } catch (e) {
9810
10117
  for (const filePath of restoredFiles) {
9811
10118
  try {
9812
- const platformPath = filePath.split("/").join(sep);
9813
- const destPath = join2(userDir, platformPath);
9814
- if (existsSync(destPath)) {
9815
- unlinkSync(destPath);
10119
+ const platformPath = filePath.split("/").join(import_node_path3.sep);
10120
+ const destPath = (0, import_node_path3.join)(userDir, platformPath);
10121
+ if ((0, import_node_fs2.existsSync)(destPath)) {
10122
+ (0, import_node_fs2.unlinkSync)(destPath);
9816
10123
  }
9817
10124
  } catch {
9818
10125
  }
@@ -9828,14 +10135,14 @@ function restoreBackup(config) {
9828
10135
  }
9829
10136
  }
9830
10137
  function getDefaultCursorDataPath2() {
9831
- const home = homedir2();
10138
+ const home = (0, import_node_os2.homedir)();
9832
10139
  switch (process.platform) {
9833
10140
  case "win32":
9834
- return join2(process.env["APPDATA"] ?? join2(home, "AppData", "Roaming"), "Cursor", "User", "workspaceStorage");
10141
+ return (0, import_node_path3.join)(process.env["APPDATA"] ?? (0, import_node_path3.join)(home, "AppData", "Roaming"), "Cursor", "User", "workspaceStorage");
9835
10142
  case "darwin":
9836
- return join2(home, "Library", "Application Support", "Cursor", "User", "workspaceStorage");
10143
+ return (0, import_node_path3.join)(home, "Library", "Application Support", "Cursor", "User", "workspaceStorage");
9837
10144
  default:
9838
- return join2(home, ".config", "Cursor", "User", "workspaceStorage");
10145
+ return (0, import_node_path3.join)(home, ".config", "Cursor", "User", "workspaceStorage");
9839
10146
  }
9840
10147
  }
9841
10148
 
@@ -9852,20 +10159,20 @@ var PROMPTS_KEY = "aiService.prompts";
9852
10159
  var GENERATIONS_KEY = "aiService.generations";
9853
10160
  function getGlobalStoragePath() {
9854
10161
  const platform = process.platform;
9855
- const home = homedir3();
10162
+ const home = (0, import_node_os3.homedir)();
9856
10163
  if (platform === "win32") {
9857
- return join3(process.env["APPDATA"] ?? join3(home, "AppData", "Roaming"), "Cursor", "User", "globalStorage");
10164
+ return (0, import_node_path4.join)(process.env["APPDATA"] ?? (0, import_node_path4.join)(home, "AppData", "Roaming"), "Cursor", "User", "globalStorage");
9858
10165
  } else if (platform === "darwin") {
9859
- return join3(home, "Library", "Application Support", "Cursor", "User", "globalStorage");
10166
+ return (0, import_node_path4.join)(home, "Library", "Application Support", "Cursor", "User", "globalStorage");
9860
10167
  } else {
9861
- return join3(home, ".config", "Cursor", "User", "globalStorage");
10168
+ return (0, import_node_path4.join)(home, ".config", "Cursor", "User", "globalStorage");
9862
10169
  }
9863
10170
  }
9864
- function openDatabase(dbPath) {
9865
- return new import_better_sqlite32.default(dbPath, { readonly: true });
10171
+ async function openDatabase2(dbPath) {
10172
+ return openDatabase(dbPath);
9866
10173
  }
9867
- function openDatabaseReadWrite(dbPath) {
9868
- return new import_better_sqlite32.default(dbPath, { readonly: false });
10174
+ async function openDatabaseReadWrite2(dbPath) {
10175
+ return openDatabaseReadWrite(dbPath);
9869
10176
  }
9870
10177
  function readWorkspaceJsonFromBackup(backupPath, workspaceId) {
9871
10178
  try {
@@ -9885,11 +10192,12 @@ function readWorkspaceJsonFromBackup(backupPath, workspaceId) {
9885
10192
  return null;
9886
10193
  }
9887
10194
  }
9888
- function findWorkspacesFromBackup(backupPath) {
10195
+ async function findWorkspacesFromBackup(backupPath) {
9889
10196
  const manifest = readBackupManifest(backupPath);
9890
10197
  if (!manifest) {
9891
10198
  return [];
9892
10199
  }
10200
+ await ensureDriver();
9893
10201
  const workspaces = [];
9894
10202
  for (const file of manifest.files) {
9895
10203
  if (file.type !== "workspace-db")
@@ -9924,12 +10232,12 @@ function findWorkspacesFromBackup(backupPath) {
9924
10232
  return workspaces;
9925
10233
  }
9926
10234
  function readWorkspaceJson(workspaceDir) {
9927
- const jsonPath = join3(workspaceDir, "workspace.json");
9928
- if (!existsSync2(jsonPath)) {
10235
+ const jsonPath = (0, import_node_path4.join)(workspaceDir, "workspace.json");
10236
+ if (!(0, import_node_fs3.existsSync)(jsonPath)) {
9929
10237
  return null;
9930
10238
  }
9931
10239
  try {
9932
- const content = readFileSync2(jsonPath, "utf-8");
10240
+ const content = (0, import_node_fs3.readFileSync)(jsonPath, "utf-8");
9933
10241
  const data = JSON.parse(content);
9934
10242
  if (data.folder) {
9935
10243
  return data.folder.replace(/^file:\/\//, "").replace(/%20/g, " ");
@@ -9939,30 +10247,30 @@ function readWorkspaceJson(workspaceDir) {
9939
10247
  return null;
9940
10248
  }
9941
10249
  }
9942
- function findWorkspaces(customDataPath, backupPath) {
10250
+ async function findWorkspaces(customDataPath, backupPath) {
9943
10251
  if (backupPath) {
9944
- return findWorkspacesFromBackup(backupPath);
10252
+ return await findWorkspacesFromBackup(backupPath);
9945
10253
  }
9946
10254
  const basePath = getCursorDataPath(customDataPath);
9947
- if (!existsSync2(basePath)) {
10255
+ if (!(0, import_node_fs3.existsSync)(basePath)) {
9948
10256
  return [];
9949
10257
  }
9950
10258
  const workspaces = [];
9951
10259
  try {
9952
- const entries = readdirSync2(basePath, { withFileTypes: true });
10260
+ const entries = (0, import_node_fs3.readdirSync)(basePath, { withFileTypes: true });
9953
10261
  for (const entry of entries) {
9954
10262
  if (!entry.isDirectory())
9955
10263
  continue;
9956
- const workspaceDir = join3(basePath, entry.name);
9957
- const dbPath = join3(workspaceDir, "state.vscdb");
9958
- if (!existsSync2(dbPath))
10264
+ const workspaceDir = (0, import_node_path4.join)(basePath, entry.name);
10265
+ const dbPath = (0, import_node_path4.join)(workspaceDir, "state.vscdb");
10266
+ if (!(0, import_node_fs3.existsSync)(dbPath))
9959
10267
  continue;
9960
10268
  const workspacePath = readWorkspaceJson(workspaceDir);
9961
10269
  if (!workspacePath)
9962
10270
  continue;
9963
10271
  let sessionCount = 0;
9964
10272
  try {
9965
- const db = openDatabase(dbPath);
10273
+ const db = await openDatabase2(dbPath);
9966
10274
  const result = getChatDataFromDb(db);
9967
10275
  if (result) {
9968
10276
  const parsed = parseChatData(result.data, result.bundle);
@@ -10022,13 +10330,13 @@ function getChatDataFromDb(db) {
10022
10330
  }
10023
10331
  return { data: mainData, bundle };
10024
10332
  }
10025
- function listSessions(options, customDataPath, backupPath) {
10026
- const workspaces = findWorkspaces(customDataPath, backupPath);
10333
+ async function listSessions(options, customDataPath, backupPath) {
10334
+ const workspaces = await findWorkspaces(customDataPath, backupPath);
10027
10335
  const filteredWorkspaces = options.workspacePath ? workspaces.filter((w) => w.path === options.workspacePath || w.path.endsWith(options.workspacePath ?? "")) : workspaces;
10028
10336
  const allSessions = [];
10029
10337
  for (const workspace of filteredWorkspaces) {
10030
10338
  try {
10031
- const db = backupPath ? openBackupDatabase(backupPath, workspace.dbPath) : openDatabase(workspace.dbPath);
10339
+ const db = backupPath ? openBackupDatabase(backupPath, workspace.dbPath) : await openDatabase2(workspace.dbPath);
10032
10340
  const result = getChatDataFromDb(db);
10033
10341
  db.close();
10034
10342
  if (!result)
@@ -10061,8 +10369,8 @@ function listSessions(options, customDataPath, backupPath) {
10061
10369
  }
10062
10370
  return allSessions;
10063
10371
  }
10064
- function getSession(index, customDataPath, backupPath) {
10065
- const summaries = listSessions({ limit: 0, all: true }, customDataPath, backupPath);
10372
+ async function getSession(index, customDataPath, backupPath) {
10373
+ const summaries = await listSessions({ limit: 0, all: true }, customDataPath, backupPath);
10066
10374
  const summary = summaries.find((s) => s.index === index);
10067
10375
  if (!summary) {
10068
10376
  return null;
@@ -10077,9 +10385,9 @@ function getSession(index, customDataPath, backupPath) {
10077
10385
  }
10078
10386
  } else {
10079
10387
  const globalPath = getGlobalStoragePath();
10080
- const globalDbPath = join3(globalPath, "state.vscdb");
10081
- if (existsSync2(globalDbPath)) {
10082
- db = openDatabase(globalDbPath);
10388
+ const globalDbPath = (0, import_node_path4.join)(globalPath, "state.vscdb");
10389
+ if ((0, import_node_fs3.existsSync)(globalDbPath)) {
10390
+ db = await openDatabase2(globalDbPath);
10083
10391
  }
10084
10392
  }
10085
10393
  if (db) {
@@ -10124,13 +10432,13 @@ function getSession(index, customDataPath, backupPath) {
10124
10432
  }
10125
10433
  } catch {
10126
10434
  }
10127
- const workspaces = findWorkspaces(customDataPath, backupPath);
10435
+ const workspaces = await findWorkspaces(customDataPath, backupPath);
10128
10436
  const workspace = workspaces.find((w) => w.id === summary.workspaceId);
10129
10437
  if (!workspace) {
10130
10438
  return null;
10131
10439
  }
10132
10440
  try {
10133
- const db = backupPath ? openBackupDatabase(backupPath, workspace.dbPath) : openDatabase(workspace.dbPath);
10441
+ const db = backupPath ? openBackupDatabase(backupPath, workspace.dbPath) : await openDatabase2(workspace.dbPath);
10134
10442
  const result = getChatDataFromDb(db);
10135
10443
  db.close();
10136
10444
  if (!result)
@@ -10149,12 +10457,12 @@ function getSession(index, customDataPath, backupPath) {
10149
10457
  return null;
10150
10458
  }
10151
10459
  }
10152
- function searchSessions(query, options, customDataPath, backupPath) {
10153
- const summaries = listSessions({ limit: 0, all: true, workspacePath: options.workspacePath }, customDataPath, backupPath);
10460
+ async function searchSessions(query, options, customDataPath, backupPath) {
10461
+ const summaries = await listSessions({ limit: 0, all: true, workspacePath: options.workspacePath }, customDataPath, backupPath);
10154
10462
  const results = [];
10155
10463
  const lowerQuery = query.toLowerCase();
10156
10464
  for (const summary of summaries) {
10157
- const session = getSession(summary.index, customDataPath, backupPath);
10465
+ const session = await getSession(summary.index, customDataPath, backupPath);
10158
10466
  if (!session)
10159
10467
  continue;
10160
10468
  const snippets = getSearchSnippets(session.messages, lowerQuery, options.contextChars);
@@ -10484,11 +10792,11 @@ ${best}`;
10484
10792
  }
10485
10793
  return best;
10486
10794
  }
10487
- function findWorkspaceForSession(sessionId, customDataPath) {
10488
- const workspaces = findWorkspaces(customDataPath);
10795
+ async function findWorkspaceForSession(sessionId, customDataPath) {
10796
+ const workspaces = await findWorkspaces(customDataPath);
10489
10797
  for (const workspace of workspaces) {
10490
10798
  try {
10491
- const db = openDatabase(workspace.dbPath);
10799
+ const db = await openDatabase2(workspace.dbPath);
10492
10800
  const result = getChatDataFromDb(db);
10493
10801
  db.close();
10494
10802
  if (!result)
@@ -10512,8 +10820,8 @@ function findWorkspaceForSession(sessionId, customDataPath) {
10512
10820
  }
10513
10821
  return null;
10514
10822
  }
10515
- function findWorkspaceByPath(workspacePath, customDataPath) {
10516
- const workspaces = findWorkspaces(customDataPath);
10823
+ async function findWorkspaceByPath(workspacePath, customDataPath) {
10824
+ const workspaces = await findWorkspaces(customDataPath);
10517
10825
  const normalizedPath = normalizePath(workspacePath);
10518
10826
  for (const workspace of workspaces) {
10519
10827
  if (pathsEqual(workspace.path, normalizedPath)) {
@@ -10563,7 +10871,7 @@ function updateComposerData(db, composers, isNewFormat, originalRawData) {
10563
10871
  const jsonValue = JSON.stringify(dataToWrite);
10564
10872
  db.prepare("UPDATE ItemTable SET value = ? WHERE key = ?").run(jsonValue, "composer.composerData");
10565
10873
  }
10566
- function resolveSessionIdentifiers(input, customDataPath) {
10874
+ async function resolveSessionIdentifiers(input, customDataPath) {
10567
10875
  let identifiers;
10568
10876
  if (Array.isArray(input)) {
10569
10877
  identifiers = input;
@@ -10572,7 +10880,7 @@ function resolveSessionIdentifiers(input, customDataPath) {
10572
10880
  } else {
10573
10881
  identifiers = [input];
10574
10882
  }
10575
- const summaries = listSessions({ limit: 0, all: true }, customDataPath);
10883
+ const summaries = await listSessions({ limit: 0, all: true }, customDataPath);
10576
10884
  const resolvedIds = [];
10577
10885
  for (const identifier of identifiers) {
10578
10886
  let sessionId;
@@ -10593,11 +10901,10 @@ function resolveSessionIdentifiers(input, customDataPath) {
10593
10901
  }
10594
10902
 
10595
10903
  // node_modules/cursor-history/dist/core/migrate.js
10596
- init_esm_shims();
10597
- var import_better_sqlite33 = __toESM(require_lib(), 1);
10598
- import { existsSync as existsSync3 } from "node:fs";
10599
- import { join as join4 } from "node:path";
10600
- import { homedir as homedir4 } from "node:os";
10904
+ var import_node_fs4 = require("fs");
10905
+ var import_node_path5 = require("path");
10906
+ var import_node_os4 = require("os");
10907
+ var import_better_sqlite32 = __toESM(require_lib(), 1);
10601
10908
  function generateSessionId() {
10602
10909
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
10603
10910
  const r = Math.random() * 16 | 0;
@@ -10607,13 +10914,13 @@ function generateSessionId() {
10607
10914
  }
10608
10915
  function getGlobalStoragePath2() {
10609
10916
  const platform = process.platform;
10610
- const home = homedir4();
10917
+ const home = (0, import_node_os4.homedir)();
10611
10918
  if (platform === "win32") {
10612
- return join4(process.env["APPDATA"] ?? join4(home, "AppData", "Roaming"), "Cursor", "User", "globalStorage");
10919
+ return (0, import_node_path5.join)(process.env["APPDATA"] ?? (0, import_node_path5.join)(home, "AppData", "Roaming"), "Cursor", "User", "globalStorage");
10613
10920
  } else if (platform === "darwin") {
10614
- return join4(home, "Library", "Application Support", "Cursor", "User", "globalStorage");
10921
+ return (0, import_node_path5.join)(home, "Library", "Application Support", "Cursor", "User", "globalStorage");
10615
10922
  } else {
10616
- return join4(home, ".config", "Cursor", "User", "globalStorage");
10923
+ return (0, import_node_path5.join)(home, ".config", "Cursor", "User", "globalStorage");
10617
10924
  }
10618
10925
  }
10619
10926
  function transformPath(path, sourcePrefix, destPrefix) {
@@ -10735,12 +11042,12 @@ function isNestedPath(source, destination) {
10735
11042
  return normalizedDest.startsWith(normalizedSource + "/");
10736
11043
  }
10737
11044
  function copyBubbleDataInGlobalStorage(oldComposerId, newComposerId, sourceWorkspace, destWorkspace, debug = false) {
10738
- const globalDbPath = join4(getGlobalStoragePath2(), "state.vscdb");
10739
- if (!existsSync3(globalDbPath)) {
11045
+ const globalDbPath = (0, import_node_path5.join)(getGlobalStoragePath2(), "state.vscdb");
11046
+ if (!(0, import_node_fs4.existsSync)(globalDbPath)) {
10740
11047
  return /* @__PURE__ */ new Map();
10741
11048
  }
10742
11049
  const bubbleIdMap = /* @__PURE__ */ new Map();
10743
- const db = new import_better_sqlite33.default(globalDbPath, { readonly: false });
11050
+ const db = new import_better_sqlite32.default(globalDbPath, { readonly: false });
10744
11051
  const sourcePrefix = normalizePath(sourceWorkspace).replace(/\/+$/, "");
10745
11052
  const destPrefix = normalizePath(destWorkspace).replace(/\/+$/, "");
10746
11053
  try {
@@ -10789,11 +11096,11 @@ function copyBubbleDataInGlobalStorage(oldComposerId, newComposerId, sourceWorks
10789
11096
  }
10790
11097
  }
10791
11098
  function updateBubblePathsInGlobalStorage(composerId, sourceWorkspace, destWorkspace, debug = false) {
10792
- const globalDbPath = join4(getGlobalStoragePath2(), "state.vscdb");
10793
- if (!existsSync3(globalDbPath)) {
11099
+ const globalDbPath = (0, import_node_path5.join)(getGlobalStoragePath2(), "state.vscdb");
11100
+ if (!(0, import_node_fs4.existsSync)(globalDbPath)) {
10794
11101
  return;
10795
11102
  }
10796
- const db = new import_better_sqlite33.default(globalDbPath, { readonly: false });
11103
+ const db = new import_better_sqlite32.default(globalDbPath, { readonly: false });
10797
11104
  const sourcePrefix = normalizePath(sourceWorkspace).replace(/\/+$/, "");
10798
11105
  const destPrefix = normalizePath(destWorkspace).replace(/\/+$/, "");
10799
11106
  try {
@@ -10813,10 +11120,10 @@ function updateBubblePathsInGlobalStorage(composerId, sourceWorkspace, destWorks
10813
11120
  db.close();
10814
11121
  }
10815
11122
  }
10816
- function migrateSession(sessionId, options) {
11123
+ async function migrateSession(sessionId, options) {
10817
11124
  const { destination, mode, dryRun, dataPath, debug = false } = options;
10818
11125
  const normalizedDest = normalizePath(destination);
10819
- const sourceInfo = findWorkspaceForSession(sessionId, dataPath);
11126
+ const sourceInfo = await findWorkspaceForSession(sessionId, dataPath);
10820
11127
  if (!sourceInfo) {
10821
11128
  throw new SessionNotFoundError(sessionId);
10822
11129
  }
@@ -10827,7 +11134,7 @@ function migrateSession(sessionId, options) {
10827
11134
  if (isNestedPath(sourceWorkspace, normalizedDest)) {
10828
11135
  throw new NestedPathError(sourceWorkspace, normalizedDest);
10829
11136
  }
10830
- const destInfo = findWorkspaceByPath(normalizedDest, dataPath);
11137
+ const destInfo = await findWorkspaceByPath(normalizedDest, dataPath);
10831
11138
  if (!destInfo) {
10832
11139
  throw new WorkspaceNotFoundError(normalizedDest);
10833
11140
  }
@@ -10843,8 +11150,8 @@ function migrateSession(sessionId, options) {
10843
11150
  };
10844
11151
  }
10845
11152
  try {
10846
- const sourceDb = openDatabaseReadWrite(sourceInfo.dbPath);
10847
- const destDb = openDatabaseReadWrite(destInfo.dbPath);
11153
+ const sourceDb = await openDatabaseReadWrite2(sourceInfo.dbPath);
11154
+ const destDb = await openDatabaseReadWrite2(destInfo.dbPath);
10848
11155
  try {
10849
11156
  const sourceResult = getComposerData(sourceDb);
10850
11157
  const destResult = getComposerData(destDb);
@@ -10905,12 +11212,12 @@ function migrateSession(sessionId, options) {
10905
11212
  };
10906
11213
  }
10907
11214
  }
10908
- function migrateSessions(options) {
11215
+ async function migrateSessions(options) {
10909
11216
  const { sessionIds, ...sessionOptions } = options;
10910
11217
  const results = [];
10911
11218
  for (const sessionId of sessionIds) {
10912
11219
  try {
10913
- const result = migrateSession(sessionId, sessionOptions);
11220
+ const result = await migrateSession(sessionId, sessionOptions);
10914
11221
  results.push(result);
10915
11222
  } catch (error) {
10916
11223
  results.push({
@@ -10928,7 +11235,6 @@ function migrateSessions(options) {
10928
11235
  }
10929
11236
 
10930
11237
  // node_modules/cursor-history/dist/lib/backup.js
10931
- init_esm_shims();
10932
11238
  async function createBackup2(config) {
10933
11239
  return createBackup(config);
10934
11240
  }
@@ -10956,10 +11262,10 @@ function convertToLibrarySession(coreSession) {
10956
11262
  }
10957
11263
  };
10958
11264
  }
10959
- function listSessions2(config) {
11265
+ async function listSessions2(config) {
10960
11266
  try {
10961
11267
  const resolved = mergeWithDefaults(config);
10962
- const coreSessions = listSessions({
11268
+ const coreSessions = await listSessions({
10963
11269
  limit: -1,
10964
11270
  // Get all, we'll paginate ourselves
10965
11271
  all: true,
@@ -10969,13 +11275,14 @@ function listSessions2(config) {
10969
11275
  const start = resolved.offset;
10970
11276
  const end = Math.min(start + resolved.limit, total);
10971
11277
  const paginatedSessions = coreSessions.slice(start, end);
10972
- const sessions = paginatedSessions.map((summary) => {
10973
- const fullSession = getSession(summary.index, resolved.dataPath, resolved.backupPath);
11278
+ const sessions = [];
11279
+ for (const summary of paginatedSessions) {
11280
+ const fullSession = await getSession(summary.index, resolved.dataPath, resolved.backupPath);
10974
11281
  if (!fullSession) {
10975
11282
  throw new DatabaseNotFoundError(`Session ${summary.index} not found`);
10976
11283
  }
10977
- return convertToLibrarySession(fullSession);
10978
- });
11284
+ sessions.push(convertToLibrarySession(fullSession));
11285
+ }
10979
11286
  return {
10980
11287
  data: sessions,
10981
11288
  pagination: {
@@ -10998,11 +11305,11 @@ function listSessions2(config) {
10998
11305
  throw new Error(`Failed to list sessions: ${err instanceof Error ? err.message : String(err)}`);
10999
11306
  }
11000
11307
  }
11001
- function getSession2(index, config) {
11308
+ async function getSession2(index, config) {
11002
11309
  try {
11003
11310
  const resolved = mergeWithDefaults(config);
11004
11311
  const coreIndex = index + 1;
11005
- const coreSession = getSession(coreIndex, resolved.dataPath, resolved.backupPath);
11312
+ const coreSession = await getSession(coreIndex, resolved.dataPath, resolved.backupPath);
11006
11313
  if (!coreSession) {
11007
11314
  throw new DatabaseNotFoundError(`Session at index ${index} not found`);
11008
11315
  }
@@ -11020,17 +11327,18 @@ function getSession2(index, config) {
11020
11327
  throw new Error(`Failed to get session: ${err instanceof Error ? err.message : String(err)}`);
11021
11328
  }
11022
11329
  }
11023
- function searchSessions2(query, config) {
11330
+ async function searchSessions2(query, config) {
11024
11331
  try {
11025
11332
  const resolved = mergeWithDefaults(config);
11026
- const coreResults = searchSessions(query, {
11333
+ const coreResults = await searchSessions(query, {
11027
11334
  limit: resolved.limit === Number.MAX_SAFE_INTEGER ? 0 : resolved.limit,
11028
11335
  contextChars: resolved.context * 80,
11029
11336
  // Rough estimate: 1 line = 80 chars
11030
11337
  workspacePath: resolved.workspace
11031
11338
  }, resolved.dataPath, resolved.backupPath);
11032
- return coreResults.map((coreResult) => {
11033
- const fullSession = getSession(coreResult.index, resolved.dataPath, resolved.backupPath);
11339
+ const results = [];
11340
+ for (const coreResult of coreResults) {
11341
+ const fullSession = await getSession(coreResult.index, resolved.dataPath, resolved.backupPath);
11034
11342
  if (!fullSession) {
11035
11343
  throw new DatabaseNotFoundError(`Session ${coreResult.index} not found`);
11036
11344
  }
@@ -11062,7 +11370,7 @@ function searchSessions2(query, config) {
11062
11370
  contextAfter.push(line);
11063
11371
  }
11064
11372
  }
11065
- return {
11373
+ results.push({
11066
11374
  session: convertToLibrarySession(fullSession),
11067
11375
  match: lines[matchLineIndex] ?? match,
11068
11376
  messageIndex: 0,
@@ -11070,8 +11378,9 @@ function searchSessions2(query, config) {
11070
11378
  offset,
11071
11379
  contextBefore: contextBefore.length > 0 ? contextBefore : void 0,
11072
11380
  contextAfter: contextAfter.length > 0 ? contextAfter : void 0
11073
- };
11074
- });
11381
+ });
11382
+ }
11383
+ return results;
11075
11384
  } catch (err) {
11076
11385
  if (err instanceof Error && err.message.includes("SQLITE_BUSY")) {
11077
11386
  throw new DatabaseLockedError(config?.dataPath ?? "default path");
@@ -11085,11 +11394,11 @@ function searchSessions2(query, config) {
11085
11394
  throw new Error(`Failed to search sessions: ${err instanceof Error ? err.message : String(err)}`);
11086
11395
  }
11087
11396
  }
11088
- function exportSessionToJson(index, config) {
11397
+ async function exportSessionToJson(index, config) {
11089
11398
  try {
11090
11399
  const resolved = mergeWithDefaults(config);
11091
11400
  const coreIndex = index + 1;
11092
- const coreSession = getSession(coreIndex, resolved.dataPath, resolved.backupPath);
11401
+ const coreSession = await getSession(coreIndex, resolved.dataPath, resolved.backupPath);
11093
11402
  if (!coreSession) {
11094
11403
  throw new DatabaseNotFoundError(`Session at index ${index} not found`);
11095
11404
  }
@@ -11101,11 +11410,11 @@ function exportSessionToJson(index, config) {
11101
11410
  throw new Error(`Failed to export session to JSON: ${err instanceof Error ? err.message : String(err)}`);
11102
11411
  }
11103
11412
  }
11104
- function exportSessionToMarkdown(index, config) {
11413
+ async function exportSessionToMarkdown(index, config) {
11105
11414
  try {
11106
11415
  const resolved = mergeWithDefaults(config);
11107
11416
  const coreIndex = index + 1;
11108
- const coreSession = getSession(coreIndex, resolved.dataPath, resolved.backupPath);
11417
+ const coreSession = await getSession(coreIndex, resolved.dataPath, resolved.backupPath);
11109
11418
  if (!coreSession) {
11110
11419
  throw new DatabaseNotFoundError(`Session at index ${index} not found`);
11111
11420
  }
@@ -11117,10 +11426,10 @@ function exportSessionToMarkdown(index, config) {
11117
11426
  throw new Error(`Failed to export session to Markdown: ${err instanceof Error ? err.message : String(err)}`);
11118
11427
  }
11119
11428
  }
11120
- function migrateSession2(config) {
11121
- const sessionIds = resolveSessionIdentifiers(config.sessions, config.dataPath);
11429
+ async function migrateSession2(config) {
11430
+ const sessionIds = await resolveSessionIdentifiers(config.sessions, config.dataPath);
11122
11431
  const destination = expandPath(config.destination);
11123
- return migrateSessions({
11432
+ return await migrateSessions({
11124
11433
  sessionIds,
11125
11434
  destination,
11126
11435
  mode: config.mode ?? "move",
@@ -11130,11 +11439,7 @@ function migrateSession2(config) {
11130
11439
  });
11131
11440
  }
11132
11441
 
11133
- // src/errors.ts
11134
- init_esm_shims();
11135
-
11136
11442
  // src/types.ts
11137
- init_esm_shims();
11138
11443
  var MCP_ERROR_CODES = {
11139
11444
  DATABASE_NOT_FOUND: -32001,
11140
11445
  DATABASE_LOCKED: -32002,
@@ -11248,7 +11553,7 @@ var listSessionsTool = {
11248
11553
  async function handleListSessions(args) {
11249
11554
  try {
11250
11555
  const parsed = ListInputSchema.parse(args);
11251
- const result = listSessions2({
11556
+ const result = await listSessions2({
11252
11557
  limit: parsed.limit,
11253
11558
  offset: parsed.offset,
11254
11559
  workspace: parsed.workspace
@@ -11292,7 +11597,6 @@ async function handleListSessions(args) {
11292
11597
  }
11293
11598
 
11294
11599
  // src/tools/show-session.ts
11295
- init_esm_shims();
11296
11600
  var ShowInputSchema = z.object({
11297
11601
  sessionIndex: z.number().int().min(1)
11298
11602
  });
@@ -11315,7 +11619,7 @@ var showSessionTool = {
11315
11619
  async function handleShowSession(args) {
11316
11620
  try {
11317
11621
  const parsed = ShowInputSchema.parse(args);
11318
- const session = getSession2(parsed.sessionIndex - 1);
11622
+ const session = await getSession2(parsed.sessionIndex - 1);
11319
11623
  const workspaceName = session.workspace ? session.workspace.split("/").pop() ?? session.workspace : "No workspace";
11320
11624
  const date = new Date(session.timestamp).toLocaleString();
11321
11625
  const lines = [
@@ -11361,7 +11665,6 @@ async function handleShowSession(args) {
11361
11665
  }
11362
11666
 
11363
11667
  // src/tools/search.ts
11364
- init_esm_shims();
11365
11668
  var SearchInputSchema = z.object({
11366
11669
  query: z.string().min(1),
11367
11670
  limit: z.number().int().min(1).max(100).default(10).optional(),
@@ -11400,7 +11703,7 @@ var searchTool = {
11400
11703
  async function handleSearch(args) {
11401
11704
  try {
11402
11705
  const parsed = SearchInputSchema.parse(args);
11403
- const results = searchSessions2(parsed.query, {
11706
+ const results = await searchSessions2(parsed.query, {
11404
11707
  limit: parsed.limit,
11405
11708
  context: parsed.context
11406
11709
  });
@@ -11430,7 +11733,6 @@ async function handleSearch(args) {
11430
11733
  }
11431
11734
 
11432
11735
  // src/tools/export.ts
11433
- init_esm_shims();
11434
11736
  var ExportInputSchema = z.object({
11435
11737
  sessionIndex: z.number().int().min(1),
11436
11738
  format: z.enum(["markdown", "json"]).default("markdown").optional()
@@ -11463,10 +11765,10 @@ async function handleExport(args) {
11463
11765
  const format = parsed.format ?? "markdown";
11464
11766
  const index = parsed.sessionIndex - 1;
11465
11767
  if (format === "json") {
11466
- const result = exportSessionToJson(index);
11768
+ const result = await exportSessionToJson(index);
11467
11769
  return JSON.stringify(result, null, 2);
11468
11770
  } else {
11469
- const result = exportSessionToMarkdown(index);
11771
+ const result = await exportSessionToMarkdown(index);
11470
11772
  return result;
11471
11773
  }
11472
11774
  } catch (error) {
@@ -11479,7 +11781,6 @@ async function handleExport(args) {
11479
11781
  }
11480
11782
 
11481
11783
  // src/tools/backup.ts
11482
- init_esm_shims();
11483
11784
  var BackupInputSchema = z.object({
11484
11785
  outputPath: z.string().optional(),
11485
11786
  force: z.boolean().default(false).optional()
@@ -11539,7 +11840,6 @@ function formatBytes(bytes) {
11539
11840
  }
11540
11841
 
11541
11842
  // src/tools/restore.ts
11542
- init_esm_shims();
11543
11843
  var RestoreInputSchema = z.object({
11544
11844
  backupPath: z.string(),
11545
11845
  force: z.boolean().default(false).optional()
@@ -11597,7 +11897,6 @@ async function handleRestore(args) {
11597
11897
  }
11598
11898
 
11599
11899
  // src/tools/migrate.ts
11600
- init_esm_shims();
11601
11900
  var MigrateInputSchema = z.object({
11602
11901
  sessionIndexes: z.array(z.number().int().min(1)).min(1),
11603
11902
  destination: z.string(),
@@ -11638,7 +11937,7 @@ async function handleMigrate(args) {
11638
11937
  const parsed = MigrateInputSchema.parse(args);
11639
11938
  const mode = parsed.mode ?? "move";
11640
11939
  const zeroBasedIndexes = parsed.sessionIndexes.map((i) => i - 1);
11641
- const results = migrateSession2({
11940
+ const results = await migrateSession2({
11642
11941
  sessions: zeroBasedIndexes,
11643
11942
  destination: parsed.destination,
11644
11943
  mode
@@ -11764,4 +12063,4 @@ main().catch((error) => {
11764
12063
  console.error("Fatal error:", error);
11765
12064
  process.exit(1);
11766
12065
  });
11767
- //# sourceMappingURL=index.js.map
12066
+ //# sourceMappingURL=index.cjs.map