anycodex 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +2769 -17366
- package/dist/chunk-47OV6PTE.js +54289 -0
- package/dist/{chunk-2X6YJUFL.js → chunk-LDC53EZT.js} +911 -532
- package/dist/chunk-RKAEZ54R.js +12565 -0
- package/dist/registry-QKGWHOWL-MO5OSMIR.js +11 -0
- package/dist/{schema-2CACIKZR-3CAWV3IP.js → schema-5YFIZCUA-MSI3TUIK.js} +1 -2
- package/dist/{session-3H7MDN6G-ILPE3VAH.js → session-636PXOZA-R22RGDNY.js} +2 -6
- package/package.json +3 -3
- package/dist/chunk-4SPBQLA5.js +0 -17249
- package/dist/chunk-6Q6QFZOB.js +0 -109
- package/dist/chunk-M6C7CWX3.js +0 -34058
- package/dist/chunk-NRFXEZ7N.js +0 -4479
- package/dist/registry-N6XVTLPC-H2PNFK4G.js +0 -13
- package/dist/storage-INCDH2MS-6PJQASBT.js +0 -27
package/dist/chunk-NRFXEZ7N.js
DELETED
|
@@ -1,4479 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
Schema_exports,
|
|
4
|
-
__callDispose,
|
|
5
|
-
__using,
|
|
6
|
-
withStatics,
|
|
7
|
-
zod_default
|
|
8
|
-
} from "./chunk-M6C7CWX3.js";
|
|
9
|
-
|
|
10
|
-
// ../utils/dist/index.js
|
|
11
|
-
import fs from "fs/promises";
|
|
12
|
-
import { existsSync, statSync, readdirSync } from "fs";
|
|
13
|
-
import path from "path";
|
|
14
|
-
import { spawn } from "child_process";
|
|
15
|
-
import { spawn as spawn2 } from "child_process";
|
|
16
|
-
import fs2 from "fs/promises";
|
|
17
|
-
import path2 from "path";
|
|
18
|
-
import fs3 from "fs";
|
|
19
|
-
import nodePath from "path";
|
|
20
|
-
var consoleLogger = {
|
|
21
|
-
debug: console.debug.bind(console),
|
|
22
|
-
info: console.info.bind(console),
|
|
23
|
-
warn: console.warn.bind(console),
|
|
24
|
-
error: console.error.bind(console)
|
|
25
|
-
};
|
|
26
|
-
var SqliteNoSqlDb = class {
|
|
27
|
-
constructor(raw) {
|
|
28
|
-
this.raw = raw;
|
|
29
|
-
}
|
|
30
|
-
insert(table, row) {
|
|
31
|
-
const cols = Object.keys(row);
|
|
32
|
-
const placeholders = cols.map(() => "?").join(", ");
|
|
33
|
-
const sql2 = `INSERT INTO "${table}" (${cols.map((c) => `"${c}"`).join(", ")}) VALUES (${placeholders})`;
|
|
34
|
-
this.raw.run(sql2, cols.map((c) => serialize(row[c])));
|
|
35
|
-
}
|
|
36
|
-
upsert(table, row, conflictKeys, updateFields) {
|
|
37
|
-
const cols = Object.keys(row);
|
|
38
|
-
const placeholders = cols.map(() => "?").join(", ");
|
|
39
|
-
const conflict = conflictKeys.map((k) => `"${k}"`).join(", ");
|
|
40
|
-
const updates = Object.keys(updateFields).map((k) => `"${k}" = ?`).join(", ");
|
|
41
|
-
const sql2 = `INSERT INTO "${table}" (${cols.map((c) => `"${c}"`).join(", ")}) VALUES (${placeholders}) ON CONFLICT (${conflict}) DO UPDATE SET ${updates}`;
|
|
42
|
-
const params = [
|
|
43
|
-
...cols.map((c) => serialize(row[c])),
|
|
44
|
-
...Object.keys(updateFields).map((k) => serialize(updateFields[k]))
|
|
45
|
-
];
|
|
46
|
-
this.raw.run(sql2, params);
|
|
47
|
-
}
|
|
48
|
-
findOne(table, filter2, options) {
|
|
49
|
-
const fields = options?.select?.map((f) => `"${f}"`).join(", ") ?? "*";
|
|
50
|
-
const { clause, params } = filter2 ? buildWhere(filter2) : { clause: "", params: [] };
|
|
51
|
-
const where = clause ? ` WHERE ${clause}` : "";
|
|
52
|
-
const sql2 = `SELECT ${fields} FROM "${table}"${where} LIMIT 1`;
|
|
53
|
-
const row = this.raw.get(sql2, params);
|
|
54
|
-
return row ? deserializeRow(row) : void 0;
|
|
55
|
-
}
|
|
56
|
-
findMany(table, options) {
|
|
57
|
-
const fields = options?.select?.map((f) => `"${f}"`).join(", ") ?? "*";
|
|
58
|
-
const { clause, params } = options?.filter ? buildWhere(options.filter) : { clause: "", params: [] };
|
|
59
|
-
const where = clause ? ` WHERE ${clause}` : "";
|
|
60
|
-
let orderClause = "";
|
|
61
|
-
if (options?.orderBy?.length) {
|
|
62
|
-
const parts = options.orderBy.map(
|
|
63
|
-
(o) => `"${o.field}" ${o.direction === "desc" ? "DESC" : "ASC"}`
|
|
64
|
-
);
|
|
65
|
-
orderClause = ` ORDER BY ${parts.join(", ")}`;
|
|
66
|
-
}
|
|
67
|
-
const limitClause = options?.limit != null ? ` LIMIT ${options.limit}` : "";
|
|
68
|
-
const sql2 = `SELECT ${fields} FROM "${table}"${where}${orderClause}${limitClause}`;
|
|
69
|
-
return this.raw.all(sql2, params).map(deserializeRow);
|
|
70
|
-
}
|
|
71
|
-
update(table, filter2, set) {
|
|
72
|
-
const setCols = Object.keys(set);
|
|
73
|
-
const setClause = setCols.map((k) => `"${k}" = ?`).join(", ");
|
|
74
|
-
const { clause, params } = buildWhere(filter2);
|
|
75
|
-
const sql2 = `UPDATE "${table}" SET ${setClause} WHERE ${clause} RETURNING *`;
|
|
76
|
-
const setParams = setCols.map((k) => serialize(set[k]));
|
|
77
|
-
const row = this.raw.get(sql2, [...setParams, ...params]);
|
|
78
|
-
return row ? deserializeRow(row) : void 0;
|
|
79
|
-
}
|
|
80
|
-
remove(table, filter2) {
|
|
81
|
-
const { clause, params } = buildWhere(filter2);
|
|
82
|
-
this.raw.run(`DELETE FROM "${table}" WHERE ${clause}`, params);
|
|
83
|
-
}
|
|
84
|
-
transaction(fn) {
|
|
85
|
-
this.raw.transaction(() => {
|
|
86
|
-
fn(this);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
function buildWhere(filter2) {
|
|
91
|
-
switch (filter2.op) {
|
|
92
|
-
case "eq":
|
|
93
|
-
return { clause: `"${filter2.field}" = ?`, params: [serialize(filter2.value)] };
|
|
94
|
-
case "ne":
|
|
95
|
-
return { clause: `"${filter2.field}" != ?`, params: [serialize(filter2.value)] };
|
|
96
|
-
case "gt":
|
|
97
|
-
return { clause: `"${filter2.field}" > ?`, params: [serialize(filter2.value)] };
|
|
98
|
-
case "gte":
|
|
99
|
-
return { clause: `"${filter2.field}" >= ?`, params: [serialize(filter2.value)] };
|
|
100
|
-
case "lt":
|
|
101
|
-
return { clause: `"${filter2.field}" < ?`, params: [serialize(filter2.value)] };
|
|
102
|
-
case "like":
|
|
103
|
-
return { clause: `"${filter2.field}" LIKE ?`, params: [filter2.value] };
|
|
104
|
-
case "isNull":
|
|
105
|
-
return { clause: `"${filter2.field}" IS NULL`, params: [] };
|
|
106
|
-
case "in": {
|
|
107
|
-
const placeholders = filter2.values.map(() => "?").join(", ");
|
|
108
|
-
return { clause: `"${filter2.field}" IN (${placeholders})`, params: filter2.values.map(serialize) };
|
|
109
|
-
}
|
|
110
|
-
case "and": {
|
|
111
|
-
const parts = filter2.conditions.map(buildWhere);
|
|
112
|
-
return {
|
|
113
|
-
clause: parts.map((p) => `(${p.clause})`).join(" AND "),
|
|
114
|
-
params: parts.flatMap((p) => p.params)
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
case "or": {
|
|
118
|
-
const parts = filter2.conditions.map(buildWhere);
|
|
119
|
-
return {
|
|
120
|
-
clause: parts.map((p) => `(${p.clause})`).join(" OR "),
|
|
121
|
-
params: parts.flatMap((p) => p.params)
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function serialize(value) {
|
|
127
|
-
if (value === void 0) return null;
|
|
128
|
-
if (value === null) return null;
|
|
129
|
-
if (typeof value === "object" && !(value instanceof Buffer) && !(value instanceof Uint8Array)) {
|
|
130
|
-
return JSON.stringify(value);
|
|
131
|
-
}
|
|
132
|
-
return value;
|
|
133
|
-
}
|
|
134
|
-
function deserializeRow(row) {
|
|
135
|
-
const result = {};
|
|
136
|
-
for (const [key, value] of Object.entries(row)) {
|
|
137
|
-
if (typeof value === "string" && (value.startsWith("{") || value.startsWith("["))) {
|
|
138
|
-
try {
|
|
139
|
-
result[key] = JSON.parse(value);
|
|
140
|
-
} catch {
|
|
141
|
-
result[key] = value;
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
result[key] = value;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return result;
|
|
148
|
-
}
|
|
149
|
-
var NodeFS = class {
|
|
150
|
-
async exists(p) {
|
|
151
|
-
return existsSync(p);
|
|
152
|
-
}
|
|
153
|
-
async stat(p) {
|
|
154
|
-
try {
|
|
155
|
-
const s = statSync(p);
|
|
156
|
-
return {
|
|
157
|
-
size: typeof s.size === "bigint" ? Number(s.size) : s.size,
|
|
158
|
-
isDirectory: s.isDirectory(),
|
|
159
|
-
isFile: s.isFile(),
|
|
160
|
-
mtimeMs: s.mtimeMs
|
|
161
|
-
};
|
|
162
|
-
} catch {
|
|
163
|
-
return void 0;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
async isDir(p) {
|
|
167
|
-
const s = await this.stat(p);
|
|
168
|
-
return s?.isDirectory ?? false;
|
|
169
|
-
}
|
|
170
|
-
async readText(p) {
|
|
171
|
-
return fs.readFile(p, "utf-8");
|
|
172
|
-
}
|
|
173
|
-
async readBytes(p) {
|
|
174
|
-
return fs.readFile(p);
|
|
175
|
-
}
|
|
176
|
-
async readJson(p) {
|
|
177
|
-
return JSON.parse(await this.readText(p));
|
|
178
|
-
}
|
|
179
|
-
async readDir(p) {
|
|
180
|
-
const entries = readdirSync(p, { withFileTypes: true });
|
|
181
|
-
return entries.map((e) => ({
|
|
182
|
-
name: e.name,
|
|
183
|
-
isDirectory: e.isDirectory(),
|
|
184
|
-
isFile: e.isFile()
|
|
185
|
-
}));
|
|
186
|
-
}
|
|
187
|
-
async write(p, content) {
|
|
188
|
-
try {
|
|
189
|
-
await fs.writeFile(p, content);
|
|
190
|
-
} catch (e) {
|
|
191
|
-
if (e?.code === "ENOENT") {
|
|
192
|
-
await fs.mkdir(path.dirname(p), { recursive: true });
|
|
193
|
-
await fs.writeFile(p, content);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
throw e;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async writeJson(p, data) {
|
|
200
|
-
await this.write(p, JSON.stringify(data, null, 2));
|
|
201
|
-
}
|
|
202
|
-
async mkdir(p) {
|
|
203
|
-
await fs.mkdir(p, { recursive: true });
|
|
204
|
-
}
|
|
205
|
-
async remove(p) {
|
|
206
|
-
await fs.unlink(p).catch(() => {
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
async grep(pattern, searchPath, options) {
|
|
210
|
-
return new Promise((resolve2) => {
|
|
211
|
-
const args = [
|
|
212
|
-
"--json",
|
|
213
|
-
"--line-number",
|
|
214
|
-
"--column",
|
|
215
|
-
"--no-heading",
|
|
216
|
-
...options?.maxResults ? ["--max-count", String(options.maxResults)] : [],
|
|
217
|
-
...options?.include?.flatMap((g) => ["--glob", g]) ?? [],
|
|
218
|
-
pattern,
|
|
219
|
-
searchPath
|
|
220
|
-
];
|
|
221
|
-
const rg = spawn("rg", args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
222
|
-
let output = "";
|
|
223
|
-
rg.stdout.on("data", (data) => {
|
|
224
|
-
output += data.toString();
|
|
225
|
-
});
|
|
226
|
-
rg.on("close", () => {
|
|
227
|
-
const results = [];
|
|
228
|
-
for (const line of output.split("\n")) {
|
|
229
|
-
if (!line.trim()) continue;
|
|
230
|
-
try {
|
|
231
|
-
const parsed = JSON.parse(line);
|
|
232
|
-
if (parsed.type === "match") {
|
|
233
|
-
results.push({
|
|
234
|
-
file: parsed.data.path.text,
|
|
235
|
-
line: parsed.data.line_number,
|
|
236
|
-
column: parsed.data.submatches?.[0]?.start ?? 0,
|
|
237
|
-
content: parsed.data.lines.text.trimEnd()
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
} catch {
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
resolve2(results);
|
|
244
|
-
});
|
|
245
|
-
rg.on("error", () => resolve2([]));
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
async glob(pattern, options = {}) {
|
|
249
|
-
const searchPath = options.cwd ?? process.cwd();
|
|
250
|
-
const { glob: fsGlob } = await import("fs/promises").catch(() => ({ glob: void 0 }));
|
|
251
|
-
if (fsGlob) {
|
|
252
|
-
try {
|
|
253
|
-
const results = [];
|
|
254
|
-
for await (const entry of fsGlob(pattern, { cwd: searchPath })) {
|
|
255
|
-
if (options.absolute) {
|
|
256
|
-
results.push(path.resolve(searchPath, entry));
|
|
257
|
-
} else {
|
|
258
|
-
results.push(entry);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return results;
|
|
262
|
-
} catch {
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return new Promise((resolve2) => {
|
|
266
|
-
const rg = spawn("rg", ["--files", "--glob", pattern, searchPath], {
|
|
267
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
268
|
-
});
|
|
269
|
-
let output = "";
|
|
270
|
-
rg.stdout.on("data", (data) => {
|
|
271
|
-
output += data.toString();
|
|
272
|
-
});
|
|
273
|
-
rg.on("close", () => {
|
|
274
|
-
resolve2(
|
|
275
|
-
output.split("\n").map((l) => l.trim()).filter(Boolean)
|
|
276
|
-
);
|
|
277
|
-
});
|
|
278
|
-
rg.on("error", () => resolve2([]));
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
var NodeSearchProvider = class {
|
|
283
|
-
async grep(options) {
|
|
284
|
-
options.signal?.throwIfAborted();
|
|
285
|
-
return new Promise((resolve2, reject) => {
|
|
286
|
-
const args = ["-rnH", "--color=never"];
|
|
287
|
-
if (options.include) {
|
|
288
|
-
args.push(`--include=${options.include}`);
|
|
289
|
-
}
|
|
290
|
-
args.push("--exclude-dir=.git");
|
|
291
|
-
args.push("-E");
|
|
292
|
-
args.push("--", options.pattern, options.path);
|
|
293
|
-
const proc = spawn2("grep", args, {
|
|
294
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
295
|
-
signal: options.signal
|
|
296
|
-
});
|
|
297
|
-
let output = "";
|
|
298
|
-
proc.stdout.on("data", (data) => {
|
|
299
|
-
output += data.toString();
|
|
300
|
-
});
|
|
301
|
-
proc.on("close", () => {
|
|
302
|
-
const results = [];
|
|
303
|
-
for (const line of output.split("\n")) {
|
|
304
|
-
if (!line.trim()) continue;
|
|
305
|
-
const match2 = line.match(/^(.+?):(\d+):(.*)$/);
|
|
306
|
-
if (match2) {
|
|
307
|
-
let content = match2[3];
|
|
308
|
-
if (options.maxLineLength !== void 0 && content.length > options.maxLineLength) {
|
|
309
|
-
content = content.slice(0, options.maxLineLength) + "...";
|
|
310
|
-
}
|
|
311
|
-
results.push({
|
|
312
|
-
file: match2[1],
|
|
313
|
-
line: parseInt(match2[2], 10),
|
|
314
|
-
column: 0,
|
|
315
|
-
content
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
resolve2(results);
|
|
320
|
-
});
|
|
321
|
-
proc.on("error", (error) => {
|
|
322
|
-
reject(error);
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
async listFiles(options) {
|
|
327
|
-
options.signal?.throwIfAborted();
|
|
328
|
-
const showHidden = options.hidden === true;
|
|
329
|
-
const results = [];
|
|
330
|
-
const limit = options.limit ?? Infinity;
|
|
331
|
-
const excludePatterns = [".git"];
|
|
332
|
-
const includePatterns = [];
|
|
333
|
-
for (const g of options.glob ?? []) {
|
|
334
|
-
if (g.startsWith("!")) {
|
|
335
|
-
excludePatterns.push(g.slice(1).replace(/[/*]+$/, ""));
|
|
336
|
-
} else {
|
|
337
|
-
includePatterns.push(g);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
const walk = async (dir, depth) => {
|
|
341
|
-
if (results.length >= limit) return;
|
|
342
|
-
if (options.maxDepth !== void 0 && depth > options.maxDepth) return;
|
|
343
|
-
options.signal?.throwIfAborted();
|
|
344
|
-
let entries;
|
|
345
|
-
try {
|
|
346
|
-
entries = await fs2.readdir(dir, { withFileTypes: true });
|
|
347
|
-
} catch {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
for (const entry of entries) {
|
|
351
|
-
if (results.length >= limit) return;
|
|
352
|
-
const name = entry.name;
|
|
353
|
-
if (!showHidden && name.startsWith(".")) continue;
|
|
354
|
-
const fullPath = path2.join(dir, name);
|
|
355
|
-
const relativePath = path2.relative(options.cwd, fullPath);
|
|
356
|
-
if (excludePatterns.some((p) => relativePath.startsWith(p) || name === p)) continue;
|
|
357
|
-
const isDir = entry.isDirectory() || options.follow && entry.isSymbolicLink();
|
|
358
|
-
if (isDir) {
|
|
359
|
-
await walk(fullPath, depth + 1);
|
|
360
|
-
} else if (entry.isFile()) {
|
|
361
|
-
if (includePatterns.length > 0) {
|
|
362
|
-
const matches = includePatterns.some((p) => simpleGlobMatch(name, p));
|
|
363
|
-
if (!matches) continue;
|
|
364
|
-
}
|
|
365
|
-
results.push(relativePath);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
await walk(options.cwd, 0);
|
|
370
|
-
return results;
|
|
371
|
-
}
|
|
372
|
-
async tree(options) {
|
|
373
|
-
const limit = options.limit ?? 50;
|
|
374
|
-
const files = await this.listFiles({ cwd: options.cwd, signal: options.signal });
|
|
375
|
-
function dir(node, name) {
|
|
376
|
-
const existing = node.children.get(name);
|
|
377
|
-
if (existing) return existing;
|
|
378
|
-
const next = { name, children: /* @__PURE__ */ new Map() };
|
|
379
|
-
node.children.set(name, next);
|
|
380
|
-
return next;
|
|
381
|
-
}
|
|
382
|
-
const root = { name: "", children: /* @__PURE__ */ new Map() };
|
|
383
|
-
for (const file of files) {
|
|
384
|
-
if (file.includes(".opencode")) continue;
|
|
385
|
-
const parts = file.split(/[\/\\]/);
|
|
386
|
-
if (parts.length < 2) continue;
|
|
387
|
-
let node = root;
|
|
388
|
-
for (const part of parts.slice(0, -1)) {
|
|
389
|
-
node = dir(node, part);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
function count(node) {
|
|
393
|
-
let total2 = 0;
|
|
394
|
-
for (const child of node.children.values()) {
|
|
395
|
-
total2 += 1 + count(child);
|
|
396
|
-
}
|
|
397
|
-
return total2;
|
|
398
|
-
}
|
|
399
|
-
const total = count(root);
|
|
400
|
-
const lines = [];
|
|
401
|
-
const queue = [];
|
|
402
|
-
for (const child of Array.from(root.children.values()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
403
|
-
queue.push({ node: child, path: child.name });
|
|
404
|
-
}
|
|
405
|
-
let used = 0;
|
|
406
|
-
for (let i = 0; i < queue.length && used < limit; i++) {
|
|
407
|
-
const { node, path: p } = queue[i];
|
|
408
|
-
lines.push(p);
|
|
409
|
-
used++;
|
|
410
|
-
for (const child of Array.from(node.children.values()).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
411
|
-
queue.push({ node: child, path: `${p}/${child.name}` });
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
if (total > used) lines.push(`[${total - used} truncated]`);
|
|
415
|
-
return lines.join("\n");
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
function simpleGlobMatch(filename, pattern) {
|
|
419
|
-
if (pattern === "*") return true;
|
|
420
|
-
if (pattern.startsWith("*.")) {
|
|
421
|
-
const ext2 = pattern.slice(1);
|
|
422
|
-
if (ext2.startsWith(".{") && ext2.endsWith("}")) {
|
|
423
|
-
const exts = ext2.slice(2, -1).split(",");
|
|
424
|
-
return exts.some((e) => filename.endsWith(`.${e}`));
|
|
425
|
-
}
|
|
426
|
-
return filename.endsWith(ext2);
|
|
427
|
-
}
|
|
428
|
-
return filename === pattern;
|
|
429
|
-
}
|
|
430
|
-
var SqlJsStorage = class {
|
|
431
|
-
db = null;
|
|
432
|
-
noSqlDb = null;
|
|
433
|
-
dbPath;
|
|
434
|
-
flushTimer = null;
|
|
435
|
-
constructor(dbPath) {
|
|
436
|
-
this.dbPath = dbPath ?? null;
|
|
437
|
-
}
|
|
438
|
-
async connect(migrations) {
|
|
439
|
-
if (this.noSqlDb) return this.noSqlDb;
|
|
440
|
-
const initSqlJs = (await import("sql.js")).default;
|
|
441
|
-
const SQL3 = await initSqlJs();
|
|
442
|
-
if (this.dbPath && fs3.existsSync(this.dbPath)) {
|
|
443
|
-
const buffer = fs3.readFileSync(this.dbPath);
|
|
444
|
-
this.db = new SQL3.Database(new Uint8Array(buffer));
|
|
445
|
-
} else {
|
|
446
|
-
this.db = new SQL3.Database();
|
|
447
|
-
}
|
|
448
|
-
this.db.run("PRAGMA foreign_keys = ON");
|
|
449
|
-
this.applyMigrations(migrations);
|
|
450
|
-
this.flushSync();
|
|
451
|
-
const raw = this.createRawDb();
|
|
452
|
-
this.noSqlDb = new SqliteNoSqlDb(raw);
|
|
453
|
-
return this.noSqlDb;
|
|
454
|
-
}
|
|
455
|
-
// ── Flush to disk ──────────────────────────────────────────────
|
|
456
|
-
/** Schedule an async flush (debounced 100ms). */
|
|
457
|
-
scheduleFlush() {
|
|
458
|
-
if (!this.dbPath) return;
|
|
459
|
-
if (this.flushTimer) return;
|
|
460
|
-
this.flushTimer = setTimeout(() => {
|
|
461
|
-
this.flushTimer = null;
|
|
462
|
-
this.flushSync();
|
|
463
|
-
}, 100);
|
|
464
|
-
}
|
|
465
|
-
/** Synchronously write the entire database to disk. */
|
|
466
|
-
flushSync() {
|
|
467
|
-
if (!this.dbPath || !this.db) return;
|
|
468
|
-
const dir = nodePath.dirname(this.dbPath);
|
|
469
|
-
fs3.mkdirSync(dir, { recursive: true });
|
|
470
|
-
const data = this.db.export();
|
|
471
|
-
fs3.writeFileSync(this.dbPath, Buffer.from(data));
|
|
472
|
-
}
|
|
473
|
-
// ── RawSqliteDb wrapper ────────────────────────────────────────
|
|
474
|
-
createRawDb() {
|
|
475
|
-
const db = this.db;
|
|
476
|
-
const self = this;
|
|
477
|
-
return {
|
|
478
|
-
run(sql2, params) {
|
|
479
|
-
db.run(sql2, params);
|
|
480
|
-
self.scheduleFlush();
|
|
481
|
-
},
|
|
482
|
-
get(sql2, params) {
|
|
483
|
-
const stmt = db.prepare(sql2);
|
|
484
|
-
if (params) stmt.bind(params);
|
|
485
|
-
if (!stmt.step()) {
|
|
486
|
-
stmt.free();
|
|
487
|
-
return void 0;
|
|
488
|
-
}
|
|
489
|
-
const result = stmt.getAsObject();
|
|
490
|
-
stmt.free();
|
|
491
|
-
return result;
|
|
492
|
-
},
|
|
493
|
-
all(sql2, params) {
|
|
494
|
-
const stmt = db.prepare(sql2);
|
|
495
|
-
if (params) stmt.bind(params);
|
|
496
|
-
const results = [];
|
|
497
|
-
while (stmt.step()) {
|
|
498
|
-
results.push(stmt.getAsObject());
|
|
499
|
-
}
|
|
500
|
-
stmt.free();
|
|
501
|
-
return results;
|
|
502
|
-
},
|
|
503
|
-
transaction(fn) {
|
|
504
|
-
db.run("BEGIN TRANSACTION");
|
|
505
|
-
try {
|
|
506
|
-
fn();
|
|
507
|
-
db.run("COMMIT");
|
|
508
|
-
self.scheduleFlush();
|
|
509
|
-
} catch (e) {
|
|
510
|
-
db.run("ROLLBACK");
|
|
511
|
-
throw e;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
// ── Migrations ─────────────────────────────────────────────────
|
|
517
|
-
applyMigrations(entries) {
|
|
518
|
-
if (!this.db) throw new Error("SqlJsStorage: db not initialized");
|
|
519
|
-
this.db.run(`
|
|
520
|
-
CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
|
|
521
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
522
|
-
hash TEXT NOT NULL,
|
|
523
|
-
created_at INTEGER
|
|
524
|
-
)
|
|
525
|
-
`);
|
|
526
|
-
const applied = /* @__PURE__ */ new Set();
|
|
527
|
-
const rows = this.db.exec(`SELECT hash FROM "__drizzle_migrations"`);
|
|
528
|
-
if (rows.length > 0) {
|
|
529
|
-
for (const row of rows[0].values) {
|
|
530
|
-
applied.add(row[0]);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
for (const entry of entries) {
|
|
534
|
-
const hash = entry.name;
|
|
535
|
-
if (applied.has(hash)) continue;
|
|
536
|
-
this.db.run(entry.sql);
|
|
537
|
-
this.db.run(
|
|
538
|
-
`INSERT INTO "__drizzle_migrations" (hash, created_at) VALUES (?, ?)`,
|
|
539
|
-
[hash, entry.timestamp]
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
/** Run raw SQL (for server-specific DDL like extra tables). */
|
|
544
|
-
exec(sql2) {
|
|
545
|
-
if (!this.db) throw new Error("SqlJsStorage: db not initialized");
|
|
546
|
-
this.db.run(sql2);
|
|
547
|
-
this.scheduleFlush();
|
|
548
|
-
}
|
|
549
|
-
/** Run a SELECT query and return rows as objects. */
|
|
550
|
-
query(sql2, params) {
|
|
551
|
-
if (!this.db) throw new Error("SqlJsStorage: db not initialized");
|
|
552
|
-
const stmt = this.db.prepare(sql2);
|
|
553
|
-
if (params) stmt.bind(params);
|
|
554
|
-
const results = [];
|
|
555
|
-
while (stmt.step()) {
|
|
556
|
-
results.push(stmt.getAsObject());
|
|
557
|
-
}
|
|
558
|
-
stmt.free();
|
|
559
|
-
return results;
|
|
560
|
-
}
|
|
561
|
-
close() {
|
|
562
|
-
if (this.flushTimer) {
|
|
563
|
-
clearTimeout(this.flushTimer);
|
|
564
|
-
this.flushTimer = null;
|
|
565
|
-
}
|
|
566
|
-
this.flushSync();
|
|
567
|
-
if (this.db) {
|
|
568
|
-
this.db.close();
|
|
569
|
-
this.db = null;
|
|
570
|
-
}
|
|
571
|
-
this.noSqlDb = null;
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/column-common.js
|
|
576
|
-
var OriginalColumn = /* @__PURE__ */ Symbol.for("drizzle:OriginalColumn");
|
|
577
|
-
|
|
578
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/entity.js
|
|
579
|
-
var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
580
|
-
function is(value, type) {
|
|
581
|
-
if (!value || typeof value !== "object") return false;
|
|
582
|
-
if (value instanceof type) return true;
|
|
583
|
-
if (!Object.prototype.hasOwnProperty.call(type, entityKind)) throw new Error(`Class "${type.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);
|
|
584
|
-
let cls = Object.getPrototypeOf(value).constructor;
|
|
585
|
-
if (cls) while (cls) {
|
|
586
|
-
if (entityKind in cls && cls[entityKind] === type[entityKind]) return true;
|
|
587
|
-
cls = Object.getPrototypeOf(cls);
|
|
588
|
-
}
|
|
589
|
-
return false;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/column.js
|
|
593
|
-
var Column = class {
|
|
594
|
-
static [entityKind] = "Column";
|
|
595
|
-
name;
|
|
596
|
-
keyAsName;
|
|
597
|
-
primary;
|
|
598
|
-
notNull;
|
|
599
|
-
default;
|
|
600
|
-
defaultFn;
|
|
601
|
-
onUpdateFn;
|
|
602
|
-
hasDefault;
|
|
603
|
-
isUnique;
|
|
604
|
-
uniqueName;
|
|
605
|
-
uniqueType;
|
|
606
|
-
dataType;
|
|
607
|
-
columnType;
|
|
608
|
-
enumValues = void 0;
|
|
609
|
-
generated = void 0;
|
|
610
|
-
generatedIdentity = void 0;
|
|
611
|
-
length;
|
|
612
|
-
isLengthExact;
|
|
613
|
-
isAlias;
|
|
614
|
-
/** @internal */
|
|
615
|
-
config;
|
|
616
|
-
/** @internal */
|
|
617
|
-
table;
|
|
618
|
-
/** @internal */
|
|
619
|
-
onInit() {
|
|
620
|
-
}
|
|
621
|
-
constructor(table, config) {
|
|
622
|
-
this.config = config;
|
|
623
|
-
this.onInit();
|
|
624
|
-
this.table = table;
|
|
625
|
-
this.name = config.name;
|
|
626
|
-
this.isAlias = false;
|
|
627
|
-
this.keyAsName = config.keyAsName;
|
|
628
|
-
this.notNull = config.notNull;
|
|
629
|
-
this.default = config.default;
|
|
630
|
-
this.defaultFn = config.defaultFn;
|
|
631
|
-
this.onUpdateFn = config.onUpdateFn;
|
|
632
|
-
this.hasDefault = config.hasDefault;
|
|
633
|
-
this.primary = config.primaryKey;
|
|
634
|
-
this.isUnique = config.isUnique;
|
|
635
|
-
this.uniqueName = config.uniqueName;
|
|
636
|
-
this.uniqueType = config.uniqueType;
|
|
637
|
-
this.dataType = config.dataType;
|
|
638
|
-
this.columnType = config.columnType;
|
|
639
|
-
this.generated = config.generated;
|
|
640
|
-
this.generatedIdentity = config.generatedIdentity;
|
|
641
|
-
this.length = config["length"];
|
|
642
|
-
this.isLengthExact = config["isLengthExact"];
|
|
643
|
-
}
|
|
644
|
-
mapFromDriverValue(value) {
|
|
645
|
-
return value;
|
|
646
|
-
}
|
|
647
|
-
mapToDriverValue(value) {
|
|
648
|
-
return value;
|
|
649
|
-
}
|
|
650
|
-
shouldDisableInsert() {
|
|
651
|
-
return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
|
|
652
|
-
}
|
|
653
|
-
/** @internal */
|
|
654
|
-
[OriginalColumn]() {
|
|
655
|
-
return this;
|
|
656
|
-
}
|
|
657
|
-
};
|
|
658
|
-
|
|
659
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/table.utils.js
|
|
660
|
-
var TableName = /* @__PURE__ */ Symbol.for("drizzle:Name");
|
|
661
|
-
|
|
662
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/table.js
|
|
663
|
-
var TableSchema = /* @__PURE__ */ Symbol.for("drizzle:Schema");
|
|
664
|
-
var TableColumns = /* @__PURE__ */ Symbol.for("drizzle:Columns");
|
|
665
|
-
var ExtraConfigColumns = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns");
|
|
666
|
-
var OriginalName = /* @__PURE__ */ Symbol.for("drizzle:OriginalName");
|
|
667
|
-
var BaseName = /* @__PURE__ */ Symbol.for("drizzle:BaseName");
|
|
668
|
-
var IsAlias = /* @__PURE__ */ Symbol.for("drizzle:IsAlias");
|
|
669
|
-
var ExtraConfigBuilder = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder");
|
|
670
|
-
var IsDrizzleTable = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
|
|
671
|
-
var Table = class {
|
|
672
|
-
static [entityKind] = "Table";
|
|
673
|
-
/** @internal */
|
|
674
|
-
static Symbol = {
|
|
675
|
-
Name: TableName,
|
|
676
|
-
Schema: TableSchema,
|
|
677
|
-
OriginalName,
|
|
678
|
-
Columns: TableColumns,
|
|
679
|
-
ExtraConfigColumns,
|
|
680
|
-
BaseName,
|
|
681
|
-
IsAlias,
|
|
682
|
-
ExtraConfigBuilder
|
|
683
|
-
};
|
|
684
|
-
/**
|
|
685
|
-
* @internal
|
|
686
|
-
* Can be changed if the table is aliased.
|
|
687
|
-
*/
|
|
688
|
-
[TableName];
|
|
689
|
-
/**
|
|
690
|
-
* @internal
|
|
691
|
-
* Used to store the original name of the table, before any aliasing.
|
|
692
|
-
*/
|
|
693
|
-
[OriginalName];
|
|
694
|
-
/** @internal */
|
|
695
|
-
[TableSchema];
|
|
696
|
-
/** @internal */
|
|
697
|
-
[TableColumns];
|
|
698
|
-
/** @internal */
|
|
699
|
-
[ExtraConfigColumns];
|
|
700
|
-
/**
|
|
701
|
-
* @internal
|
|
702
|
-
* Used to store the table name before the transformation via the `tableCreator` functions.
|
|
703
|
-
*/
|
|
704
|
-
[BaseName];
|
|
705
|
-
/** @internal */
|
|
706
|
-
[IsAlias] = false;
|
|
707
|
-
/** @internal */
|
|
708
|
-
[IsDrizzleTable] = true;
|
|
709
|
-
/** @internal */
|
|
710
|
-
[ExtraConfigBuilder] = void 0;
|
|
711
|
-
constructor(name, schema, baseName) {
|
|
712
|
-
this[TableName] = this[OriginalName] = name;
|
|
713
|
-
this[TableSchema] = schema;
|
|
714
|
-
this[BaseName] = baseName;
|
|
715
|
-
}
|
|
716
|
-
};
|
|
717
|
-
|
|
718
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/subquery.js
|
|
719
|
-
var Subquery = class {
|
|
720
|
-
static [entityKind] = "Subquery";
|
|
721
|
-
constructor(sql2, fields, alias, isWith = false, usedTables = []) {
|
|
722
|
-
this._ = {
|
|
723
|
-
brand: "Subquery",
|
|
724
|
-
sql: sql2,
|
|
725
|
-
selectedFields: fields,
|
|
726
|
-
alias,
|
|
727
|
-
isWith,
|
|
728
|
-
usedTables
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
|
-
};
|
|
732
|
-
var WithSubquery = class extends Subquery {
|
|
733
|
-
static [entityKind] = "WithSubquery";
|
|
734
|
-
};
|
|
735
|
-
|
|
736
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/tracing.js
|
|
737
|
-
var tracer = { startActiveSpan(name, fn) {
|
|
738
|
-
return fn();
|
|
739
|
-
} };
|
|
740
|
-
|
|
741
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/view-common.js
|
|
742
|
-
var ViewBaseConfig = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig");
|
|
743
|
-
|
|
744
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sql/sql.js
|
|
745
|
-
var FakePrimitiveParam = class {
|
|
746
|
-
static [entityKind] = "FakePrimitiveParam";
|
|
747
|
-
};
|
|
748
|
-
function isSQLWrapper(value) {
|
|
749
|
-
return value !== null && value !== void 0 && typeof value.getSQL === "function";
|
|
750
|
-
}
|
|
751
|
-
function mergeQueries(queries) {
|
|
752
|
-
const result = {
|
|
753
|
-
sql: "",
|
|
754
|
-
params: []
|
|
755
|
-
};
|
|
756
|
-
for (const query of queries) {
|
|
757
|
-
result.sql += query.sql;
|
|
758
|
-
result.params.push(...query.params);
|
|
759
|
-
if (query.typings?.length) {
|
|
760
|
-
if (!result.typings) result.typings = [];
|
|
761
|
-
result.typings.push(...query.typings);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
return result;
|
|
765
|
-
}
|
|
766
|
-
var StringChunk = class {
|
|
767
|
-
static [entityKind] = "StringChunk";
|
|
768
|
-
value;
|
|
769
|
-
constructor(value) {
|
|
770
|
-
this.value = Array.isArray(value) ? value : [value];
|
|
771
|
-
}
|
|
772
|
-
getSQL() {
|
|
773
|
-
return new SQL([this]);
|
|
774
|
-
}
|
|
775
|
-
};
|
|
776
|
-
var SQL = class SQL2 {
|
|
777
|
-
static [entityKind] = "SQL";
|
|
778
|
-
/** @internal */
|
|
779
|
-
decoder = noopDecoder;
|
|
780
|
-
/** @internal */
|
|
781
|
-
shouldInlineParams = false;
|
|
782
|
-
/** @internal */
|
|
783
|
-
usedTables = [];
|
|
784
|
-
constructor(queryChunks) {
|
|
785
|
-
this.queryChunks = queryChunks;
|
|
786
|
-
for (const chunk of queryChunks) if (is(chunk, Table)) {
|
|
787
|
-
const schemaName = chunk[Table.Symbol.Schema];
|
|
788
|
-
this.usedTables.push(schemaName === void 0 ? chunk[Table.Symbol.Name] : schemaName + "." + chunk[Table.Symbol.Name]);
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
append(query) {
|
|
792
|
-
this.queryChunks.push(...query.queryChunks);
|
|
793
|
-
return this;
|
|
794
|
-
}
|
|
795
|
-
toQuery(config) {
|
|
796
|
-
return tracer.startActiveSpan("drizzle.buildSQL", (span) => {
|
|
797
|
-
const query = this.buildQueryFromSourceParams(this.queryChunks, config);
|
|
798
|
-
span?.setAttributes({
|
|
799
|
-
"drizzle.query.text": query.sql,
|
|
800
|
-
"drizzle.query.params": JSON.stringify(query.params)
|
|
801
|
-
});
|
|
802
|
-
return query;
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
buildQueryFromSourceParams(chunks, _config) {
|
|
806
|
-
const config = Object.assign({}, _config, {
|
|
807
|
-
inlineParams: _config.inlineParams || this.shouldInlineParams,
|
|
808
|
-
paramStartIndex: _config.paramStartIndex || { value: 0 }
|
|
809
|
-
});
|
|
810
|
-
const { casing, escapeName, escapeParam, prepareTyping, inlineParams, paramStartIndex, invokeSource } = config;
|
|
811
|
-
return mergeQueries(chunks.map((chunk) => {
|
|
812
|
-
if (is(chunk, StringChunk)) return {
|
|
813
|
-
sql: chunk.value.join(""),
|
|
814
|
-
params: []
|
|
815
|
-
};
|
|
816
|
-
if (is(chunk, Name)) return {
|
|
817
|
-
sql: escapeName(chunk.value),
|
|
818
|
-
params: []
|
|
819
|
-
};
|
|
820
|
-
if (chunk === void 0) return {
|
|
821
|
-
sql: "",
|
|
822
|
-
params: []
|
|
823
|
-
};
|
|
824
|
-
if (Array.isArray(chunk)) {
|
|
825
|
-
const result = [new StringChunk("(")];
|
|
826
|
-
for (const [i, p] of chunk.entries()) {
|
|
827
|
-
result.push(p);
|
|
828
|
-
if (i < chunk.length - 1) result.push(new StringChunk(", "));
|
|
829
|
-
}
|
|
830
|
-
result.push(new StringChunk(")"));
|
|
831
|
-
return this.buildQueryFromSourceParams(result, config);
|
|
832
|
-
}
|
|
833
|
-
if (is(chunk, SQL2)) return this.buildQueryFromSourceParams(chunk.queryChunks, {
|
|
834
|
-
...config,
|
|
835
|
-
inlineParams: inlineParams || chunk.shouldInlineParams
|
|
836
|
-
});
|
|
837
|
-
if (is(chunk, Table)) {
|
|
838
|
-
const schemaName = chunk[Table.Symbol.Schema];
|
|
839
|
-
const tableName = chunk[Table.Symbol.Name];
|
|
840
|
-
if (invokeSource === "mssql-view-with-schemabinding") return {
|
|
841
|
-
sql: (schemaName === void 0 ? escapeName("dbo") : escapeName(schemaName)) + "." + escapeName(tableName),
|
|
842
|
-
params: []
|
|
843
|
-
};
|
|
844
|
-
return {
|
|
845
|
-
sql: schemaName === void 0 || chunk[IsAlias] ? escapeName(tableName) : escapeName(schemaName) + "." + escapeName(tableName),
|
|
846
|
-
params: []
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
if (is(chunk, Column)) {
|
|
850
|
-
const columnName = casing.getColumnCasing(chunk);
|
|
851
|
-
if (_config.invokeSource === "indexes") return {
|
|
852
|
-
sql: escapeName(columnName),
|
|
853
|
-
params: []
|
|
854
|
-
};
|
|
855
|
-
const schemaName = invokeSource === "mssql-check" ? void 0 : chunk.table[Table.Symbol.Schema];
|
|
856
|
-
return {
|
|
857
|
-
sql: chunk.isAlias ? escapeName(chunk.name) : chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table.Symbol.Name]) + "." + escapeName(columnName),
|
|
858
|
-
params: []
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
if (is(chunk, View)) {
|
|
862
|
-
const schemaName = chunk[ViewBaseConfig].schema;
|
|
863
|
-
const viewName = chunk[ViewBaseConfig].name;
|
|
864
|
-
return {
|
|
865
|
-
sql: schemaName === void 0 || chunk[ViewBaseConfig].isAlias ? escapeName(viewName) : escapeName(schemaName) + "." + escapeName(viewName),
|
|
866
|
-
params: []
|
|
867
|
-
};
|
|
868
|
-
}
|
|
869
|
-
if (is(chunk, Param)) {
|
|
870
|
-
if (is(chunk.value, Placeholder)) return {
|
|
871
|
-
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
872
|
-
params: [chunk],
|
|
873
|
-
typings: ["none"]
|
|
874
|
-
};
|
|
875
|
-
const mappedValue = chunk.value === null ? null : chunk.encoder.mapToDriverValue(chunk.value);
|
|
876
|
-
if (is(mappedValue, SQL2)) return this.buildQueryFromSourceParams([mappedValue], config);
|
|
877
|
-
if (inlineParams) return {
|
|
878
|
-
sql: this.mapInlineParam(mappedValue, config),
|
|
879
|
-
params: []
|
|
880
|
-
};
|
|
881
|
-
let typings = ["none"];
|
|
882
|
-
if (prepareTyping) typings = [prepareTyping(chunk.encoder)];
|
|
883
|
-
return {
|
|
884
|
-
sql: escapeParam(paramStartIndex.value++, mappedValue),
|
|
885
|
-
params: [mappedValue],
|
|
886
|
-
typings
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
if (is(chunk, Placeholder)) return {
|
|
890
|
-
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
891
|
-
params: [chunk],
|
|
892
|
-
typings: ["none"]
|
|
893
|
-
};
|
|
894
|
-
if (is(chunk, SQL2.Aliased) && chunk.fieldAlias !== void 0) return {
|
|
895
|
-
sql: (chunk.origin !== void 0 ? escapeName(chunk.origin) + "." : "") + escapeName(chunk.fieldAlias),
|
|
896
|
-
params: []
|
|
897
|
-
};
|
|
898
|
-
if (is(chunk, Subquery)) {
|
|
899
|
-
if (chunk._.isWith) return {
|
|
900
|
-
sql: escapeName(chunk._.alias),
|
|
901
|
-
params: []
|
|
902
|
-
};
|
|
903
|
-
return this.buildQueryFromSourceParams([
|
|
904
|
-
new StringChunk("("),
|
|
905
|
-
chunk._.sql,
|
|
906
|
-
new StringChunk(") "),
|
|
907
|
-
new Name(chunk._.alias)
|
|
908
|
-
], config);
|
|
909
|
-
}
|
|
910
|
-
if (typeof chunk === "function" && "enumName" in chunk) {
|
|
911
|
-
if ("schema" in chunk && chunk.schema) return {
|
|
912
|
-
sql: escapeName(chunk.schema) + "." + escapeName(chunk.enumName),
|
|
913
|
-
params: []
|
|
914
|
-
};
|
|
915
|
-
return {
|
|
916
|
-
sql: escapeName(chunk.enumName),
|
|
917
|
-
params: []
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
if (isSQLWrapper(chunk)) {
|
|
921
|
-
if (chunk.shouldOmitSQLParens?.()) return this.buildQueryFromSourceParams([chunk.getSQL()], config);
|
|
922
|
-
return this.buildQueryFromSourceParams([
|
|
923
|
-
new StringChunk("("),
|
|
924
|
-
chunk.getSQL(),
|
|
925
|
-
new StringChunk(")")
|
|
926
|
-
], config);
|
|
927
|
-
}
|
|
928
|
-
if (inlineParams) return {
|
|
929
|
-
sql: this.mapInlineParam(chunk, config),
|
|
930
|
-
params: []
|
|
931
|
-
};
|
|
932
|
-
return {
|
|
933
|
-
sql: escapeParam(paramStartIndex.value++, chunk),
|
|
934
|
-
params: [chunk],
|
|
935
|
-
typings: ["none"]
|
|
936
|
-
};
|
|
937
|
-
}));
|
|
938
|
-
}
|
|
939
|
-
mapInlineParam(chunk, { escapeString }) {
|
|
940
|
-
if (chunk === null) return "null";
|
|
941
|
-
if (typeof chunk === "number" || typeof chunk === "boolean" || typeof chunk === "bigint") return chunk.toString();
|
|
942
|
-
if (typeof chunk === "string") return escapeString(chunk);
|
|
943
|
-
if (typeof chunk === "object") {
|
|
944
|
-
const mappedValueAsString = chunk.toString();
|
|
945
|
-
if (mappedValueAsString === "[object Object]") return escapeString(JSON.stringify(chunk));
|
|
946
|
-
return escapeString(mappedValueAsString);
|
|
947
|
-
}
|
|
948
|
-
throw new Error("Unexpected param value: " + chunk);
|
|
949
|
-
}
|
|
950
|
-
getSQL() {
|
|
951
|
-
return this;
|
|
952
|
-
}
|
|
953
|
-
as(alias) {
|
|
954
|
-
if (alias === void 0) return this;
|
|
955
|
-
return new SQL2.Aliased(this, alias);
|
|
956
|
-
}
|
|
957
|
-
mapWith(decoder) {
|
|
958
|
-
this.decoder = typeof decoder === "function" ? { mapFromDriverValue: decoder } : decoder;
|
|
959
|
-
return this;
|
|
960
|
-
}
|
|
961
|
-
inlineParams() {
|
|
962
|
-
this.shouldInlineParams = true;
|
|
963
|
-
return this;
|
|
964
|
-
}
|
|
965
|
-
/**
|
|
966
|
-
* This method is used to conditionally include a part of the query.
|
|
967
|
-
*
|
|
968
|
-
* @param condition - Condition to check
|
|
969
|
-
* @returns itself if the condition is `true`, otherwise `undefined`
|
|
970
|
-
*/
|
|
971
|
-
if(condition) {
|
|
972
|
-
return condition ? this : void 0;
|
|
973
|
-
}
|
|
974
|
-
};
|
|
975
|
-
var Name = class {
|
|
976
|
-
static [entityKind] = "Name";
|
|
977
|
-
brand;
|
|
978
|
-
constructor(value) {
|
|
979
|
-
this.value = value;
|
|
980
|
-
}
|
|
981
|
-
getSQL() {
|
|
982
|
-
return new SQL([this]);
|
|
983
|
-
}
|
|
984
|
-
};
|
|
985
|
-
var noopDecoder = { mapFromDriverValue: (value) => value };
|
|
986
|
-
var noopEncoder = { mapToDriverValue: (value) => value };
|
|
987
|
-
var noopMapper = {
|
|
988
|
-
...noopDecoder,
|
|
989
|
-
...noopEncoder
|
|
990
|
-
};
|
|
991
|
-
var Param = class {
|
|
992
|
-
static [entityKind] = "Param";
|
|
993
|
-
brand;
|
|
994
|
-
/**
|
|
995
|
-
* @param value - Parameter value
|
|
996
|
-
* @param encoder - Encoder to convert the value to a driver parameter
|
|
997
|
-
*/
|
|
998
|
-
constructor(value, encoder = noopEncoder) {
|
|
999
|
-
this.value = value;
|
|
1000
|
-
this.encoder = encoder;
|
|
1001
|
-
}
|
|
1002
|
-
getSQL() {
|
|
1003
|
-
return new SQL([this]);
|
|
1004
|
-
}
|
|
1005
|
-
};
|
|
1006
|
-
function sql(strings, ...params) {
|
|
1007
|
-
const queryChunks = [];
|
|
1008
|
-
if (params.length > 0 || strings.length > 0 && strings[0] !== "") queryChunks.push(new StringChunk(strings[0]));
|
|
1009
|
-
for (const [paramIndex, param$1] of params.entries()) queryChunks.push(param$1, new StringChunk(strings[paramIndex + 1]));
|
|
1010
|
-
return new SQL(queryChunks);
|
|
1011
|
-
}
|
|
1012
|
-
(function(_sql) {
|
|
1013
|
-
function empty() {
|
|
1014
|
-
return new SQL([]);
|
|
1015
|
-
}
|
|
1016
|
-
_sql.empty = empty;
|
|
1017
|
-
function fromList(list) {
|
|
1018
|
-
return new SQL(list);
|
|
1019
|
-
}
|
|
1020
|
-
_sql.fromList = fromList;
|
|
1021
|
-
function raw(str) {
|
|
1022
|
-
return new SQL([new StringChunk(str)]);
|
|
1023
|
-
}
|
|
1024
|
-
_sql.raw = raw;
|
|
1025
|
-
function join2(chunks, separator) {
|
|
1026
|
-
const result = [];
|
|
1027
|
-
for (const [i, chunk] of chunks.entries()) {
|
|
1028
|
-
if (i > 0 && separator !== void 0) result.push(separator);
|
|
1029
|
-
result.push(chunk);
|
|
1030
|
-
}
|
|
1031
|
-
return new SQL(result);
|
|
1032
|
-
}
|
|
1033
|
-
_sql.join = join2;
|
|
1034
|
-
function identifier(value) {
|
|
1035
|
-
return new Name(value);
|
|
1036
|
-
}
|
|
1037
|
-
_sql.identifier = identifier;
|
|
1038
|
-
function placeholder$1(name$1) {
|
|
1039
|
-
return new Placeholder(name$1);
|
|
1040
|
-
}
|
|
1041
|
-
_sql.placeholder = placeholder$1;
|
|
1042
|
-
function param$1(value, encoder) {
|
|
1043
|
-
return new Param(value, encoder);
|
|
1044
|
-
}
|
|
1045
|
-
_sql.param = param$1;
|
|
1046
|
-
})(sql || (sql = {}));
|
|
1047
|
-
(function(_SQL) {
|
|
1048
|
-
class Aliased {
|
|
1049
|
-
static [entityKind] = "SQL.Aliased";
|
|
1050
|
-
/** @internal */
|
|
1051
|
-
isSelectionField = false;
|
|
1052
|
-
/** @internal */
|
|
1053
|
-
origin;
|
|
1054
|
-
constructor(sql$1, fieldAlias) {
|
|
1055
|
-
this.sql = sql$1;
|
|
1056
|
-
this.fieldAlias = fieldAlias;
|
|
1057
|
-
}
|
|
1058
|
-
getSQL() {
|
|
1059
|
-
return this.sql;
|
|
1060
|
-
}
|
|
1061
|
-
/** @internal */
|
|
1062
|
-
clone() {
|
|
1063
|
-
return new Aliased(this.sql, this.fieldAlias);
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
_SQL.Aliased = Aliased;
|
|
1067
|
-
})(SQL || (SQL = {}));
|
|
1068
|
-
var Placeholder = class {
|
|
1069
|
-
static [entityKind] = "Placeholder";
|
|
1070
|
-
constructor(name$1) {
|
|
1071
|
-
this.name = name$1;
|
|
1072
|
-
}
|
|
1073
|
-
getSQL() {
|
|
1074
|
-
return new SQL([this]);
|
|
1075
|
-
}
|
|
1076
|
-
};
|
|
1077
|
-
var IsDrizzleView = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
|
|
1078
|
-
var View = class {
|
|
1079
|
-
static [entityKind] = "View";
|
|
1080
|
-
/** @internal */
|
|
1081
|
-
[ViewBaseConfig];
|
|
1082
|
-
/** @internal */
|
|
1083
|
-
[IsDrizzleView] = true;
|
|
1084
|
-
/** @internal */
|
|
1085
|
-
get [TableName]() {
|
|
1086
|
-
return this[ViewBaseConfig].name;
|
|
1087
|
-
}
|
|
1088
|
-
/** @internal */
|
|
1089
|
-
get [TableSchema]() {
|
|
1090
|
-
return this[ViewBaseConfig].schema;
|
|
1091
|
-
}
|
|
1092
|
-
/** @internal */
|
|
1093
|
-
get [IsAlias]() {
|
|
1094
|
-
return this[ViewBaseConfig].isAlias;
|
|
1095
|
-
}
|
|
1096
|
-
/** @internal */
|
|
1097
|
-
get [OriginalName]() {
|
|
1098
|
-
return this[ViewBaseConfig].originalName;
|
|
1099
|
-
}
|
|
1100
|
-
/** @internal */
|
|
1101
|
-
get [TableColumns]() {
|
|
1102
|
-
return this[ViewBaseConfig].selectedFields;
|
|
1103
|
-
}
|
|
1104
|
-
constructor({ name: name$1, schema, selectedFields, query }) {
|
|
1105
|
-
this[ViewBaseConfig] = {
|
|
1106
|
-
name: name$1,
|
|
1107
|
-
originalName: name$1,
|
|
1108
|
-
schema,
|
|
1109
|
-
selectedFields,
|
|
1110
|
-
query,
|
|
1111
|
-
isExisting: !query,
|
|
1112
|
-
isAlias: false
|
|
1113
|
-
};
|
|
1114
|
-
}
|
|
1115
|
-
};
|
|
1116
|
-
Column.prototype.getSQL = function() {
|
|
1117
|
-
return new SQL([this]);
|
|
1118
|
-
};
|
|
1119
|
-
Subquery.prototype.getSQL = function() {
|
|
1120
|
-
return new SQL([this]);
|
|
1121
|
-
};
|
|
1122
|
-
|
|
1123
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/column-builder.js
|
|
1124
|
-
var ColumnBuilder = class {
|
|
1125
|
-
static [entityKind] = "ColumnBuilder";
|
|
1126
|
-
/** @internal */
|
|
1127
|
-
config;
|
|
1128
|
-
constructor(name, dataType, columnType) {
|
|
1129
|
-
this.config = {
|
|
1130
|
-
name,
|
|
1131
|
-
keyAsName: name === "",
|
|
1132
|
-
notNull: false,
|
|
1133
|
-
default: void 0,
|
|
1134
|
-
hasDefault: false,
|
|
1135
|
-
primaryKey: false,
|
|
1136
|
-
isUnique: false,
|
|
1137
|
-
uniqueName: void 0,
|
|
1138
|
-
uniqueType: void 0,
|
|
1139
|
-
dataType,
|
|
1140
|
-
columnType,
|
|
1141
|
-
generated: void 0
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
|
|
1146
|
-
*
|
|
1147
|
-
* @example
|
|
1148
|
-
* ```ts
|
|
1149
|
-
* const users = pgTable('users', {
|
|
1150
|
-
* id: integer('id').$type<UserId>().primaryKey(),
|
|
1151
|
-
* details: json('details').$type<UserDetails>().notNull(),
|
|
1152
|
-
* });
|
|
1153
|
-
* ```
|
|
1154
|
-
*/
|
|
1155
|
-
$type() {
|
|
1156
|
-
return this;
|
|
1157
|
-
}
|
|
1158
|
-
/**
|
|
1159
|
-
* Adds a `not null` clause to the column definition.
|
|
1160
|
-
*
|
|
1161
|
-
* Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
|
|
1162
|
-
*/
|
|
1163
|
-
notNull() {
|
|
1164
|
-
this.config.notNull = true;
|
|
1165
|
-
return this;
|
|
1166
|
-
}
|
|
1167
|
-
/**
|
|
1168
|
-
* Adds a `default <value>` clause to the column definition.
|
|
1169
|
-
*
|
|
1170
|
-
* Affects the `insert` model of the table - columns *with* `default` are optional on insert.
|
|
1171
|
-
*
|
|
1172
|
-
* If you need to set a dynamic default value, use {@link $defaultFn} instead.
|
|
1173
|
-
*/
|
|
1174
|
-
default(value) {
|
|
1175
|
-
this.config.default = value;
|
|
1176
|
-
this.config.hasDefault = true;
|
|
1177
|
-
return this;
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
* Adds a dynamic default value to the column.
|
|
1181
|
-
* The function will be called when the row is inserted, and the returned value will be used as the column value.
|
|
1182
|
-
*
|
|
1183
|
-
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
1184
|
-
*/
|
|
1185
|
-
$defaultFn(fn) {
|
|
1186
|
-
this.config.defaultFn = fn;
|
|
1187
|
-
this.config.hasDefault = true;
|
|
1188
|
-
return this;
|
|
1189
|
-
}
|
|
1190
|
-
/**
|
|
1191
|
-
* Alias for {@link $defaultFn}.
|
|
1192
|
-
*/
|
|
1193
|
-
$default = this.$defaultFn;
|
|
1194
|
-
/**
|
|
1195
|
-
* Adds a dynamic update value to the column.
|
|
1196
|
-
* The function will be called when the row is updated, and the returned value will be used as the column value if none is provided.
|
|
1197
|
-
* If no `default` (or `$defaultFn`) value is provided, the function will be called when the row is inserted as well, and the returned value will be used as the column value.
|
|
1198
|
-
*
|
|
1199
|
-
* **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
|
|
1200
|
-
*/
|
|
1201
|
-
$onUpdateFn(fn) {
|
|
1202
|
-
this.config.onUpdateFn = fn;
|
|
1203
|
-
this.config.hasDefault = true;
|
|
1204
|
-
return this;
|
|
1205
|
-
}
|
|
1206
|
-
/**
|
|
1207
|
-
* Alias for {@link $onUpdateFn}.
|
|
1208
|
-
*/
|
|
1209
|
-
$onUpdate = this.$onUpdateFn;
|
|
1210
|
-
/**
|
|
1211
|
-
* Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
|
|
1212
|
-
*
|
|
1213
|
-
* In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
|
|
1214
|
-
*/
|
|
1215
|
-
primaryKey() {
|
|
1216
|
-
this.config.primaryKey = true;
|
|
1217
|
-
this.config.notNull = true;
|
|
1218
|
-
return this;
|
|
1219
|
-
}
|
|
1220
|
-
/** @internal Sets the name of the column to the key within the table definition if a name was not given. */
|
|
1221
|
-
setName(name) {
|
|
1222
|
-
if (this.config.name !== "") return;
|
|
1223
|
-
this.config.name = name;
|
|
1224
|
-
}
|
|
1225
|
-
};
|
|
1226
|
-
|
|
1227
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
|
|
1228
|
-
var ForeignKeyBuilder = class {
|
|
1229
|
-
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
1230
|
-
/** @internal */
|
|
1231
|
-
reference;
|
|
1232
|
-
/** @internal */
|
|
1233
|
-
_onUpdate;
|
|
1234
|
-
/** @internal */
|
|
1235
|
-
_onDelete;
|
|
1236
|
-
constructor(config, actions) {
|
|
1237
|
-
this.reference = () => {
|
|
1238
|
-
const { name, columns, foreignColumns } = config();
|
|
1239
|
-
return {
|
|
1240
|
-
name,
|
|
1241
|
-
columns,
|
|
1242
|
-
foreignTable: foreignColumns[0].table,
|
|
1243
|
-
foreignColumns
|
|
1244
|
-
};
|
|
1245
|
-
};
|
|
1246
|
-
if (actions) {
|
|
1247
|
-
this._onUpdate = actions.onUpdate;
|
|
1248
|
-
this._onDelete = actions.onDelete;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
onUpdate(action) {
|
|
1252
|
-
this._onUpdate = action;
|
|
1253
|
-
return this;
|
|
1254
|
-
}
|
|
1255
|
-
onDelete(action) {
|
|
1256
|
-
this._onDelete = action;
|
|
1257
|
-
return this;
|
|
1258
|
-
}
|
|
1259
|
-
/** @internal */
|
|
1260
|
-
build(table) {
|
|
1261
|
-
return new ForeignKey(table, this);
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
var ForeignKey = class {
|
|
1265
|
-
static [entityKind] = "SQLiteForeignKey";
|
|
1266
|
-
reference;
|
|
1267
|
-
onUpdate;
|
|
1268
|
-
onDelete;
|
|
1269
|
-
constructor(table, builder) {
|
|
1270
|
-
this.table = table;
|
|
1271
|
-
this.reference = builder.reference;
|
|
1272
|
-
this.onUpdate = builder._onUpdate;
|
|
1273
|
-
this.onDelete = builder._onDelete;
|
|
1274
|
-
}
|
|
1275
|
-
getName() {
|
|
1276
|
-
const { name, columns, foreignColumns } = this.reference();
|
|
1277
|
-
const columnNames = columns.map((column) => column.name);
|
|
1278
|
-
const foreignColumnNames = foreignColumns.map((column) => column.name);
|
|
1279
|
-
const chunks = [
|
|
1280
|
-
this.table[TableName],
|
|
1281
|
-
...columnNames,
|
|
1282
|
-
foreignColumns[0].table[TableName],
|
|
1283
|
-
...foreignColumnNames
|
|
1284
|
-
];
|
|
1285
|
-
return name ?? `${chunks.join("_")}_fk`;
|
|
1286
|
-
}
|
|
1287
|
-
isNameExplicit() {
|
|
1288
|
-
return !!this.reference().name;
|
|
1289
|
-
}
|
|
1290
|
-
};
|
|
1291
|
-
|
|
1292
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/columns/common.js
|
|
1293
|
-
var SQLiteColumnBuilder = class extends ColumnBuilder {
|
|
1294
|
-
static [entityKind] = "SQLiteColumnBuilder";
|
|
1295
|
-
foreignKeyConfigs = [];
|
|
1296
|
-
references(ref, actions = {}) {
|
|
1297
|
-
this.foreignKeyConfigs.push({
|
|
1298
|
-
ref,
|
|
1299
|
-
actions
|
|
1300
|
-
});
|
|
1301
|
-
return this;
|
|
1302
|
-
}
|
|
1303
|
-
unique(name) {
|
|
1304
|
-
this.config.isUnique = true;
|
|
1305
|
-
this.config.uniqueName = name;
|
|
1306
|
-
return this;
|
|
1307
|
-
}
|
|
1308
|
-
generatedAlwaysAs(as, config) {
|
|
1309
|
-
this.config.generated = {
|
|
1310
|
-
as,
|
|
1311
|
-
type: "always",
|
|
1312
|
-
mode: config?.mode ?? "virtual"
|
|
1313
|
-
};
|
|
1314
|
-
return this;
|
|
1315
|
-
}
|
|
1316
|
-
/** @internal */
|
|
1317
|
-
buildForeignKeys(column, table) {
|
|
1318
|
-
return this.foreignKeyConfigs.map(({ ref, actions }) => {
|
|
1319
|
-
return ((ref$1, actions$1) => {
|
|
1320
|
-
const builder = new ForeignKeyBuilder(() => {
|
|
1321
|
-
const foreignColumn = ref$1();
|
|
1322
|
-
return {
|
|
1323
|
-
columns: [column],
|
|
1324
|
-
foreignColumns: [foreignColumn]
|
|
1325
|
-
};
|
|
1326
|
-
});
|
|
1327
|
-
if (actions$1.onUpdate) builder.onUpdate(actions$1.onUpdate);
|
|
1328
|
-
if (actions$1.onDelete) builder.onDelete(actions$1.onDelete);
|
|
1329
|
-
return builder.build(table);
|
|
1330
|
-
})(ref, actions);
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
};
|
|
1334
|
-
var SQLiteColumn = class extends Column {
|
|
1335
|
-
static [entityKind] = "SQLiteColumn";
|
|
1336
|
-
/** @internal */
|
|
1337
|
-
table;
|
|
1338
|
-
constructor(table, config) {
|
|
1339
|
-
super(table, config);
|
|
1340
|
-
this.table = table;
|
|
1341
|
-
}
|
|
1342
|
-
};
|
|
1343
|
-
|
|
1344
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/utils.js
|
|
1345
|
-
function getColumnNameAndConfig(a, b) {
|
|
1346
|
-
return {
|
|
1347
|
-
name: typeof a === "string" && a.length > 0 ? a : "",
|
|
1348
|
-
config: typeof a === "object" ? a : b
|
|
1349
|
-
};
|
|
1350
|
-
}
|
|
1351
|
-
var textDecoder = typeof TextDecoder === "undefined" ? null : new TextDecoder();
|
|
1352
|
-
|
|
1353
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/columns/blob.js
|
|
1354
|
-
function hexToText(hexString) {
|
|
1355
|
-
let result = "";
|
|
1356
|
-
for (let i = 0; i < hexString.length; i += 2) {
|
|
1357
|
-
const hexPair = hexString.slice(i, i + 2);
|
|
1358
|
-
const decimalValue = Number.parseInt(hexPair, 16);
|
|
1359
|
-
result += String.fromCodePoint(decimalValue);
|
|
1360
|
-
}
|
|
1361
|
-
return result;
|
|
1362
|
-
}
|
|
1363
|
-
var SQLiteBigIntBuilder = class extends SQLiteColumnBuilder {
|
|
1364
|
-
static [entityKind] = "SQLiteBigIntBuilder";
|
|
1365
|
-
constructor(name) {
|
|
1366
|
-
super(name, "bigint int64", "SQLiteBigInt");
|
|
1367
|
-
}
|
|
1368
|
-
/** @internal */
|
|
1369
|
-
build(table) {
|
|
1370
|
-
return new SQLiteBigInt(table, this.config);
|
|
1371
|
-
}
|
|
1372
|
-
};
|
|
1373
|
-
var SQLiteBigInt = class extends SQLiteColumn {
|
|
1374
|
-
static [entityKind] = "SQLiteBigInt";
|
|
1375
|
-
getSQLType() {
|
|
1376
|
-
return "blob";
|
|
1377
|
-
}
|
|
1378
|
-
mapFromDriverValue(value) {
|
|
1379
|
-
if (typeof value === "string") return BigInt(hexToText(value));
|
|
1380
|
-
if (typeof Buffer !== "undefined" && Buffer.from) {
|
|
1381
|
-
const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
|
|
1382
|
-
return BigInt(buf.toString("utf8"));
|
|
1383
|
-
}
|
|
1384
|
-
return BigInt(textDecoder.decode(value));
|
|
1385
|
-
}
|
|
1386
|
-
mapToDriverValue(value) {
|
|
1387
|
-
return Buffer.from(value.toString());
|
|
1388
|
-
}
|
|
1389
|
-
};
|
|
1390
|
-
var SQLiteBlobJsonBuilder = class extends SQLiteColumnBuilder {
|
|
1391
|
-
static [entityKind] = "SQLiteBlobJsonBuilder";
|
|
1392
|
-
constructor(name) {
|
|
1393
|
-
super(name, "object json", "SQLiteBlobJson");
|
|
1394
|
-
}
|
|
1395
|
-
/** @internal */
|
|
1396
|
-
build(table) {
|
|
1397
|
-
return new SQLiteBlobJson(table, this.config);
|
|
1398
|
-
}
|
|
1399
|
-
};
|
|
1400
|
-
var SQLiteBlobJson = class extends SQLiteColumn {
|
|
1401
|
-
static [entityKind] = "SQLiteBlobJson";
|
|
1402
|
-
getSQLType() {
|
|
1403
|
-
return "blob";
|
|
1404
|
-
}
|
|
1405
|
-
mapFromDriverValue(value) {
|
|
1406
|
-
if (typeof value === "string") return JSON.parse(hexToText(value));
|
|
1407
|
-
if (typeof Buffer !== "undefined" && Buffer.from) {
|
|
1408
|
-
const buf = Buffer.isBuffer(value) ? value : value instanceof ArrayBuffer ? Buffer.from(value) : value.buffer ? Buffer.from(value.buffer, value.byteOffset, value.byteLength) : Buffer.from(value);
|
|
1409
|
-
return JSON.parse(buf.toString("utf8"));
|
|
1410
|
-
}
|
|
1411
|
-
return JSON.parse(textDecoder.decode(value));
|
|
1412
|
-
}
|
|
1413
|
-
mapToDriverValue(value) {
|
|
1414
|
-
return Buffer.from(JSON.stringify(value));
|
|
1415
|
-
}
|
|
1416
|
-
};
|
|
1417
|
-
var SQLiteBlobBufferBuilder = class extends SQLiteColumnBuilder {
|
|
1418
|
-
static [entityKind] = "SQLiteBlobBufferBuilder";
|
|
1419
|
-
constructor(name) {
|
|
1420
|
-
super(name, "object buffer", "SQLiteBlobBuffer");
|
|
1421
|
-
}
|
|
1422
|
-
/** @internal */
|
|
1423
|
-
build(table) {
|
|
1424
|
-
return new SQLiteBlobBuffer(table, this.config);
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
var SQLiteBlobBuffer = class extends SQLiteColumn {
|
|
1428
|
-
static [entityKind] = "SQLiteBlobBuffer";
|
|
1429
|
-
mapFromDriverValue(value) {
|
|
1430
|
-
if (Buffer.isBuffer(value)) return value;
|
|
1431
|
-
if (typeof value === "string") return Buffer.from(value, "hex");
|
|
1432
|
-
return Buffer.from(value);
|
|
1433
|
-
}
|
|
1434
|
-
getSQLType() {
|
|
1435
|
-
return "blob";
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
function blob(a, b) {
|
|
1439
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1440
|
-
if (config?.mode === "json") return new SQLiteBlobJsonBuilder(name);
|
|
1441
|
-
if (config?.mode === "bigint") return new SQLiteBigIntBuilder(name);
|
|
1442
|
-
return new SQLiteBlobBufferBuilder(name);
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/columns/custom.js
|
|
1446
|
-
var SQLiteCustomColumnBuilder = class extends SQLiteColumnBuilder {
|
|
1447
|
-
static [entityKind] = "SQLiteCustomColumnBuilder";
|
|
1448
|
-
constructor(name, fieldConfig, customTypeParams) {
|
|
1449
|
-
super(name, "custom", "SQLiteCustomColumn");
|
|
1450
|
-
this.config.fieldConfig = fieldConfig;
|
|
1451
|
-
this.config.customTypeParams = customTypeParams;
|
|
1452
|
-
}
|
|
1453
|
-
/** @internal */
|
|
1454
|
-
build(table) {
|
|
1455
|
-
return new SQLiteCustomColumn(table, this.config);
|
|
1456
|
-
}
|
|
1457
|
-
};
|
|
1458
|
-
var SQLiteCustomColumn = class extends SQLiteColumn {
|
|
1459
|
-
static [entityKind] = "SQLiteCustomColumn";
|
|
1460
|
-
sqlName;
|
|
1461
|
-
mapTo;
|
|
1462
|
-
mapFrom;
|
|
1463
|
-
mapJson;
|
|
1464
|
-
forJsonSelect;
|
|
1465
|
-
constructor(table, config) {
|
|
1466
|
-
super(table, config);
|
|
1467
|
-
this.sqlName = config.customTypeParams.dataType(config.fieldConfig);
|
|
1468
|
-
this.mapTo = config.customTypeParams.toDriver;
|
|
1469
|
-
this.mapFrom = config.customTypeParams.fromDriver;
|
|
1470
|
-
this.mapJson = config.customTypeParams.fromJson;
|
|
1471
|
-
this.forJsonSelect = config.customTypeParams.forJsonSelect;
|
|
1472
|
-
}
|
|
1473
|
-
getSQLType() {
|
|
1474
|
-
return this.sqlName;
|
|
1475
|
-
}
|
|
1476
|
-
mapFromDriverValue(value) {
|
|
1477
|
-
return typeof this.mapFrom === "function" ? this.mapFrom(value) : value;
|
|
1478
|
-
}
|
|
1479
|
-
mapFromJsonValue(value) {
|
|
1480
|
-
return typeof this.mapJson === "function" ? this.mapJson(value) : this.mapFromDriverValue(value);
|
|
1481
|
-
}
|
|
1482
|
-
jsonSelectIdentifier(identifier, sql2) {
|
|
1483
|
-
if (typeof this.forJsonSelect === "function") return this.forJsonSelect(identifier, sql2);
|
|
1484
|
-
const rawType = this.getSQLType().toLowerCase();
|
|
1485
|
-
const parenPos = rawType.indexOf("(");
|
|
1486
|
-
switch (parenPos + 1 ? rawType.slice(0, parenPos) : rawType) {
|
|
1487
|
-
case "numeric":
|
|
1488
|
-
case "decimal":
|
|
1489
|
-
case "bigint":
|
|
1490
|
-
return sql2`cast(${identifier} as text)`;
|
|
1491
|
-
case "blob":
|
|
1492
|
-
return sql2`hex(${identifier})`;
|
|
1493
|
-
default:
|
|
1494
|
-
return identifier;
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
mapToDriverValue(value) {
|
|
1498
|
-
return typeof this.mapTo === "function" ? this.mapTo(value) : value;
|
|
1499
|
-
}
|
|
1500
|
-
};
|
|
1501
|
-
function customType(customTypeParams) {
|
|
1502
|
-
return (a, b) => {
|
|
1503
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1504
|
-
return new SQLiteCustomColumnBuilder(name, config, customTypeParams);
|
|
1505
|
-
};
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/columns/integer.js
|
|
1509
|
-
var SQLiteBaseIntegerBuilder = class extends SQLiteColumnBuilder {
|
|
1510
|
-
static [entityKind] = "SQLiteBaseIntegerBuilder";
|
|
1511
|
-
constructor(name, dataType, columnType) {
|
|
1512
|
-
super(name, dataType, columnType);
|
|
1513
|
-
this.config.autoIncrement = false;
|
|
1514
|
-
}
|
|
1515
|
-
primaryKey(config) {
|
|
1516
|
-
if (config?.autoIncrement) this.config.autoIncrement = true;
|
|
1517
|
-
this.config.hasDefault = true;
|
|
1518
|
-
return super.primaryKey();
|
|
1519
|
-
}
|
|
1520
|
-
};
|
|
1521
|
-
var SQLiteBaseInteger = class extends SQLiteColumn {
|
|
1522
|
-
static [entityKind] = "SQLiteBaseInteger";
|
|
1523
|
-
autoIncrement = this.config.autoIncrement;
|
|
1524
|
-
getSQLType() {
|
|
1525
|
-
return "integer";
|
|
1526
|
-
}
|
|
1527
|
-
};
|
|
1528
|
-
var SQLiteIntegerBuilder = class extends SQLiteBaseIntegerBuilder {
|
|
1529
|
-
static [entityKind] = "SQLiteIntegerBuilder";
|
|
1530
|
-
constructor(name) {
|
|
1531
|
-
super(name, "number int53", "SQLiteInteger");
|
|
1532
|
-
}
|
|
1533
|
-
build(table) {
|
|
1534
|
-
return new SQLiteInteger(table, this.config);
|
|
1535
|
-
}
|
|
1536
|
-
};
|
|
1537
|
-
var SQLiteInteger = class extends SQLiteBaseInteger {
|
|
1538
|
-
static [entityKind] = "SQLiteInteger";
|
|
1539
|
-
};
|
|
1540
|
-
var SQLiteTimestampBuilder = class extends SQLiteBaseIntegerBuilder {
|
|
1541
|
-
static [entityKind] = "SQLiteTimestampBuilder";
|
|
1542
|
-
constructor(name, mode) {
|
|
1543
|
-
super(name, "object date", "SQLiteTimestamp");
|
|
1544
|
-
this.config.mode = mode;
|
|
1545
|
-
}
|
|
1546
|
-
/**
|
|
1547
|
-
* @deprecated Use `default()` with your own expression instead.
|
|
1548
|
-
*
|
|
1549
|
-
* Adds `DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer))` to the column, which is the current epoch timestamp in milliseconds.
|
|
1550
|
-
*/
|
|
1551
|
-
defaultNow() {
|
|
1552
|
-
return this.default(sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
|
|
1553
|
-
}
|
|
1554
|
-
build(table) {
|
|
1555
|
-
return new SQLiteTimestamp(table, this.config);
|
|
1556
|
-
}
|
|
1557
|
-
};
|
|
1558
|
-
var SQLiteTimestamp = class extends SQLiteBaseInteger {
|
|
1559
|
-
static [entityKind] = "SQLiteTimestamp";
|
|
1560
|
-
mode = this.config.mode;
|
|
1561
|
-
mapFromDriverValue(value) {
|
|
1562
|
-
if (typeof value === "string") return new Date(value.replaceAll('"', ""));
|
|
1563
|
-
if (this.config.mode === "timestamp") return /* @__PURE__ */ new Date(value * 1e3);
|
|
1564
|
-
return new Date(value);
|
|
1565
|
-
}
|
|
1566
|
-
mapToDriverValue(value) {
|
|
1567
|
-
if (typeof value === "number") return value;
|
|
1568
|
-
const unix = value.getTime();
|
|
1569
|
-
if (this.config.mode === "timestamp") return Math.floor(unix / 1e3);
|
|
1570
|
-
return unix;
|
|
1571
|
-
}
|
|
1572
|
-
};
|
|
1573
|
-
var SQLiteBooleanBuilder = class extends SQLiteBaseIntegerBuilder {
|
|
1574
|
-
static [entityKind] = "SQLiteBooleanBuilder";
|
|
1575
|
-
constructor(name, mode) {
|
|
1576
|
-
super(name, "boolean", "SQLiteBoolean");
|
|
1577
|
-
this.config.mode = mode;
|
|
1578
|
-
}
|
|
1579
|
-
build(table) {
|
|
1580
|
-
return new SQLiteBoolean(table, this.config);
|
|
1581
|
-
}
|
|
1582
|
-
};
|
|
1583
|
-
var SQLiteBoolean = class extends SQLiteBaseInteger {
|
|
1584
|
-
static [entityKind] = "SQLiteBoolean";
|
|
1585
|
-
mode = this.config.mode;
|
|
1586
|
-
mapFromDriverValue(value) {
|
|
1587
|
-
return Number(value) === 1;
|
|
1588
|
-
}
|
|
1589
|
-
mapToDriverValue(value) {
|
|
1590
|
-
return value ? 1 : 0;
|
|
1591
|
-
}
|
|
1592
|
-
};
|
|
1593
|
-
function integer(a, b) {
|
|
1594
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1595
|
-
if (config?.mode === "timestamp" || config?.mode === "timestamp_ms") return new SQLiteTimestampBuilder(name, config.mode);
|
|
1596
|
-
if (config?.mode === "boolean") return new SQLiteBooleanBuilder(name, config.mode);
|
|
1597
|
-
return new SQLiteIntegerBuilder(name);
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/columns/numeric.js
|
|
1601
|
-
var SQLiteNumericBuilder = class extends SQLiteColumnBuilder {
|
|
1602
|
-
static [entityKind] = "SQLiteNumericBuilder";
|
|
1603
|
-
constructor(name) {
|
|
1604
|
-
super(name, "string numeric", "SQLiteNumeric");
|
|
1605
|
-
}
|
|
1606
|
-
/** @internal */
|
|
1607
|
-
build(table) {
|
|
1608
|
-
return new SQLiteNumeric(table, this.config);
|
|
1609
|
-
}
|
|
1610
|
-
};
|
|
1611
|
-
var SQLiteNumeric = class extends SQLiteColumn {
|
|
1612
|
-
static [entityKind] = "SQLiteNumeric";
|
|
1613
|
-
mapFromDriverValue(value) {
|
|
1614
|
-
if (typeof value === "string") return value;
|
|
1615
|
-
return String(value);
|
|
1616
|
-
}
|
|
1617
|
-
getSQLType() {
|
|
1618
|
-
return "numeric";
|
|
1619
|
-
}
|
|
1620
|
-
};
|
|
1621
|
-
var SQLiteNumericNumberBuilder = class extends SQLiteColumnBuilder {
|
|
1622
|
-
static [entityKind] = "SQLiteNumericNumberBuilder";
|
|
1623
|
-
constructor(name) {
|
|
1624
|
-
super(name, "number", "SQLiteNumericNumber");
|
|
1625
|
-
}
|
|
1626
|
-
/** @internal */
|
|
1627
|
-
build(table) {
|
|
1628
|
-
return new SQLiteNumericNumber(table, this.config);
|
|
1629
|
-
}
|
|
1630
|
-
};
|
|
1631
|
-
var SQLiteNumericNumber = class extends SQLiteColumn {
|
|
1632
|
-
static [entityKind] = "SQLiteNumericNumber";
|
|
1633
|
-
mapFromDriverValue(value) {
|
|
1634
|
-
if (typeof value === "number") return value;
|
|
1635
|
-
return Number(value);
|
|
1636
|
-
}
|
|
1637
|
-
mapToDriverValue = String;
|
|
1638
|
-
getSQLType() {
|
|
1639
|
-
return "numeric";
|
|
1640
|
-
}
|
|
1641
|
-
};
|
|
1642
|
-
var SQLiteNumericBigIntBuilder = class extends SQLiteColumnBuilder {
|
|
1643
|
-
static [entityKind] = "SQLiteNumericBigIntBuilder";
|
|
1644
|
-
constructor(name) {
|
|
1645
|
-
super(name, "bigint int64", "SQLiteNumericBigInt");
|
|
1646
|
-
}
|
|
1647
|
-
/** @internal */
|
|
1648
|
-
build(table) {
|
|
1649
|
-
return new SQLiteNumericBigInt(table, this.config);
|
|
1650
|
-
}
|
|
1651
|
-
};
|
|
1652
|
-
var SQLiteNumericBigInt = class extends SQLiteColumn {
|
|
1653
|
-
static [entityKind] = "SQLiteNumericBigInt";
|
|
1654
|
-
mapFromDriverValue = BigInt;
|
|
1655
|
-
mapToDriverValue = String;
|
|
1656
|
-
getSQLType() {
|
|
1657
|
-
return "numeric";
|
|
1658
|
-
}
|
|
1659
|
-
};
|
|
1660
|
-
function numeric(a, b) {
|
|
1661
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1662
|
-
const mode = config?.mode;
|
|
1663
|
-
return mode === "number" ? new SQLiteNumericNumberBuilder(name) : mode === "bigint" ? new SQLiteNumericBigIntBuilder(name) : new SQLiteNumericBuilder(name);
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/columns/real.js
|
|
1667
|
-
var SQLiteRealBuilder = class extends SQLiteColumnBuilder {
|
|
1668
|
-
static [entityKind] = "SQLiteRealBuilder";
|
|
1669
|
-
constructor(name) {
|
|
1670
|
-
super(name, "number double", "SQLiteReal");
|
|
1671
|
-
}
|
|
1672
|
-
/** @internal */
|
|
1673
|
-
build(table) {
|
|
1674
|
-
return new SQLiteReal(table, this.config);
|
|
1675
|
-
}
|
|
1676
|
-
};
|
|
1677
|
-
var SQLiteReal = class extends SQLiteColumn {
|
|
1678
|
-
static [entityKind] = "SQLiteReal";
|
|
1679
|
-
getSQLType() {
|
|
1680
|
-
return "real";
|
|
1681
|
-
}
|
|
1682
|
-
};
|
|
1683
|
-
function real(name) {
|
|
1684
|
-
return new SQLiteRealBuilder(name ?? "");
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/columns/text.js
|
|
1688
|
-
var SQLiteTextBuilder = class extends SQLiteColumnBuilder {
|
|
1689
|
-
static [entityKind] = "SQLiteTextBuilder";
|
|
1690
|
-
constructor(name, config) {
|
|
1691
|
-
super(name, config.enum?.length ? "string enum" : "string", "SQLiteText");
|
|
1692
|
-
this.config.enumValues = config.enum;
|
|
1693
|
-
this.config.length = config.length;
|
|
1694
|
-
}
|
|
1695
|
-
/** @internal */
|
|
1696
|
-
build(table) {
|
|
1697
|
-
return new SQLiteText(table, this.config);
|
|
1698
|
-
}
|
|
1699
|
-
};
|
|
1700
|
-
var SQLiteText = class extends SQLiteColumn {
|
|
1701
|
-
static [entityKind] = "SQLiteText";
|
|
1702
|
-
enumValues = this.config.enumValues;
|
|
1703
|
-
constructor(table, config) {
|
|
1704
|
-
super(table, config);
|
|
1705
|
-
}
|
|
1706
|
-
getSQLType() {
|
|
1707
|
-
return `text${this.config.length ? `(${this.config.length})` : ""}`;
|
|
1708
|
-
}
|
|
1709
|
-
};
|
|
1710
|
-
var SQLiteTextJsonBuilder = class extends SQLiteColumnBuilder {
|
|
1711
|
-
static [entityKind] = "SQLiteTextJsonBuilder";
|
|
1712
|
-
constructor(name) {
|
|
1713
|
-
super(name, "object json", "SQLiteTextJson");
|
|
1714
|
-
}
|
|
1715
|
-
/** @internal */
|
|
1716
|
-
build(table) {
|
|
1717
|
-
return new SQLiteTextJson(table, this.config);
|
|
1718
|
-
}
|
|
1719
|
-
};
|
|
1720
|
-
var SQLiteTextJson = class extends SQLiteColumn {
|
|
1721
|
-
static [entityKind] = "SQLiteTextJson";
|
|
1722
|
-
getSQLType() {
|
|
1723
|
-
return "text";
|
|
1724
|
-
}
|
|
1725
|
-
mapFromDriverValue(value) {
|
|
1726
|
-
return JSON.parse(value);
|
|
1727
|
-
}
|
|
1728
|
-
mapToDriverValue(value) {
|
|
1729
|
-
return JSON.stringify(value);
|
|
1730
|
-
}
|
|
1731
|
-
};
|
|
1732
|
-
function text(a, b = {}) {
|
|
1733
|
-
const { name, config } = getColumnNameAndConfig(a, b);
|
|
1734
|
-
if (config.mode === "json") return new SQLiteTextJsonBuilder(name);
|
|
1735
|
-
return new SQLiteTextBuilder(name, config);
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/indexes.js
|
|
1739
|
-
var IndexBuilderOn = class {
|
|
1740
|
-
static [entityKind] = "SQLiteIndexBuilderOn";
|
|
1741
|
-
constructor(name, unique) {
|
|
1742
|
-
this.name = name;
|
|
1743
|
-
this.unique = unique;
|
|
1744
|
-
}
|
|
1745
|
-
on(...columns) {
|
|
1746
|
-
return new IndexBuilder(this.name, columns, this.unique);
|
|
1747
|
-
}
|
|
1748
|
-
};
|
|
1749
|
-
var IndexBuilder = class {
|
|
1750
|
-
static [entityKind] = "SQLiteIndexBuilder";
|
|
1751
|
-
/** @internal */
|
|
1752
|
-
config;
|
|
1753
|
-
constructor(name, columns, unique) {
|
|
1754
|
-
this.config = {
|
|
1755
|
-
name,
|
|
1756
|
-
columns,
|
|
1757
|
-
unique,
|
|
1758
|
-
where: void 0
|
|
1759
|
-
};
|
|
1760
|
-
}
|
|
1761
|
-
/**
|
|
1762
|
-
* Condition for partial index.
|
|
1763
|
-
*/
|
|
1764
|
-
where(condition) {
|
|
1765
|
-
this.config.where = condition;
|
|
1766
|
-
return this;
|
|
1767
|
-
}
|
|
1768
|
-
/** @internal */
|
|
1769
|
-
build(table) {
|
|
1770
|
-
return new Index(this.config, table);
|
|
1771
|
-
}
|
|
1772
|
-
};
|
|
1773
|
-
var Index = class {
|
|
1774
|
-
static [entityKind] = "SQLiteIndex";
|
|
1775
|
-
config;
|
|
1776
|
-
isNameExplicit;
|
|
1777
|
-
constructor(config, table) {
|
|
1778
|
-
this.config = {
|
|
1779
|
-
...config,
|
|
1780
|
-
table
|
|
1781
|
-
};
|
|
1782
|
-
this.isNameExplicit = !!config.name;
|
|
1783
|
-
}
|
|
1784
|
-
};
|
|
1785
|
-
function index(name) {
|
|
1786
|
-
return new IndexBuilderOn(name, false);
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/columns/all.js
|
|
1790
|
-
function getSQLiteColumnBuilders() {
|
|
1791
|
-
return {
|
|
1792
|
-
blob,
|
|
1793
|
-
customType,
|
|
1794
|
-
integer,
|
|
1795
|
-
numeric,
|
|
1796
|
-
real,
|
|
1797
|
-
text
|
|
1798
|
-
};
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/table.js
|
|
1802
|
-
var InlineForeignKeys = /* @__PURE__ */ Symbol.for("drizzle:SQLiteInlineForeignKeys");
|
|
1803
|
-
var SQLiteTable = class extends Table {
|
|
1804
|
-
static [entityKind] = "SQLiteTable";
|
|
1805
|
-
/** @internal */
|
|
1806
|
-
static Symbol = Object.assign({}, Table.Symbol, { InlineForeignKeys });
|
|
1807
|
-
/** @internal */
|
|
1808
|
-
[Table.Symbol.Columns];
|
|
1809
|
-
/** @internal */
|
|
1810
|
-
[InlineForeignKeys] = [];
|
|
1811
|
-
/** @internal */
|
|
1812
|
-
[Table.Symbol.ExtraConfigBuilder] = void 0;
|
|
1813
|
-
};
|
|
1814
|
-
function sqliteTableBase(name, columns, extraConfig, schema, baseName = name) {
|
|
1815
|
-
const rawTable = new SQLiteTable(name, schema, baseName);
|
|
1816
|
-
const parsedColumns = typeof columns === "function" ? columns(getSQLiteColumnBuilders()) : columns;
|
|
1817
|
-
const builtColumns = Object.fromEntries(Object.entries(parsedColumns).map(([name$1, colBuilderBase]) => {
|
|
1818
|
-
const colBuilder = colBuilderBase;
|
|
1819
|
-
colBuilder.setName(name$1);
|
|
1820
|
-
const column = colBuilder.build(rawTable);
|
|
1821
|
-
rawTable[InlineForeignKeys].push(...colBuilder.buildForeignKeys(column, rawTable));
|
|
1822
|
-
return [name$1, column];
|
|
1823
|
-
}));
|
|
1824
|
-
const table = Object.assign(rawTable, builtColumns);
|
|
1825
|
-
table[Table.Symbol.Columns] = builtColumns;
|
|
1826
|
-
table[Table.Symbol.ExtraConfigColumns] = builtColumns;
|
|
1827
|
-
if (extraConfig) table[SQLiteTable.Symbol.ExtraConfigBuilder] = extraConfig;
|
|
1828
|
-
return table;
|
|
1829
|
-
}
|
|
1830
|
-
var sqliteTable = (name, columns, extraConfig) => {
|
|
1831
|
-
return sqliteTableBase(name, columns, extraConfig);
|
|
1832
|
-
};
|
|
1833
|
-
|
|
1834
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-beta.16-ea816b6_@opentelemetry+api@1.9.0_@types+better-sqlite3@7.6.13_0f21266a0de314c39cfb891f27e2ae25/node_modules/drizzle-orm/sqlite-core/primary-keys.js
|
|
1835
|
-
function primaryKey(...config) {
|
|
1836
|
-
if (config[0].columns) return new PrimaryKeyBuilder(config[0].columns, config[0].name);
|
|
1837
|
-
return new PrimaryKeyBuilder(config);
|
|
1838
|
-
}
|
|
1839
|
-
var PrimaryKeyBuilder = class {
|
|
1840
|
-
static [entityKind] = "SQLitePrimaryKeyBuilder";
|
|
1841
|
-
/** @internal */
|
|
1842
|
-
columns;
|
|
1843
|
-
/** @internal */
|
|
1844
|
-
name;
|
|
1845
|
-
constructor(columns, name) {
|
|
1846
|
-
this.columns = columns;
|
|
1847
|
-
this.name = name;
|
|
1848
|
-
}
|
|
1849
|
-
/** @internal */
|
|
1850
|
-
build(table) {
|
|
1851
|
-
return new PrimaryKey(table, this.columns, this.name);
|
|
1852
|
-
}
|
|
1853
|
-
};
|
|
1854
|
-
var PrimaryKey = class {
|
|
1855
|
-
static [entityKind] = "SQLitePrimaryKey";
|
|
1856
|
-
columns;
|
|
1857
|
-
name;
|
|
1858
|
-
isNameExplicit;
|
|
1859
|
-
constructor(table, columns, name) {
|
|
1860
|
-
this.table = table;
|
|
1861
|
-
this.columns = columns;
|
|
1862
|
-
this.name = name;
|
|
1863
|
-
this.isNameExplicit = !!name;
|
|
1864
|
-
}
|
|
1865
|
-
getName() {
|
|
1866
|
-
return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
1867
|
-
}
|
|
1868
|
-
};
|
|
1869
|
-
|
|
1870
|
-
// ../../node_modules/.pnpm/@isaacs+balanced-match@4.0.1/node_modules/@isaacs/balanced-match/dist/esm/index.js
|
|
1871
|
-
var balanced = (a, b, str) => {
|
|
1872
|
-
const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
|
|
1873
|
-
const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
|
|
1874
|
-
const r = ma !== null && mb != null && range(ma, mb, str);
|
|
1875
|
-
return r && {
|
|
1876
|
-
start: r[0],
|
|
1877
|
-
end: r[1],
|
|
1878
|
-
pre: str.slice(0, r[0]),
|
|
1879
|
-
body: str.slice(r[0] + ma.length, r[1]),
|
|
1880
|
-
post: str.slice(r[1] + mb.length)
|
|
1881
|
-
};
|
|
1882
|
-
};
|
|
1883
|
-
var maybeMatch = (reg, str) => {
|
|
1884
|
-
const m = str.match(reg);
|
|
1885
|
-
return m ? m[0] : null;
|
|
1886
|
-
};
|
|
1887
|
-
var range = (a, b, str) => {
|
|
1888
|
-
let begs, beg, left, right = void 0, result;
|
|
1889
|
-
let ai = str.indexOf(a);
|
|
1890
|
-
let bi = str.indexOf(b, ai + 1);
|
|
1891
|
-
let i = ai;
|
|
1892
|
-
if (ai >= 0 && bi > 0) {
|
|
1893
|
-
if (a === b) {
|
|
1894
|
-
return [ai, bi];
|
|
1895
|
-
}
|
|
1896
|
-
begs = [];
|
|
1897
|
-
left = str.length;
|
|
1898
|
-
while (i >= 0 && !result) {
|
|
1899
|
-
if (i === ai) {
|
|
1900
|
-
begs.push(i);
|
|
1901
|
-
ai = str.indexOf(a, i + 1);
|
|
1902
|
-
} else if (begs.length === 1) {
|
|
1903
|
-
const r = begs.pop();
|
|
1904
|
-
if (r !== void 0)
|
|
1905
|
-
result = [r, bi];
|
|
1906
|
-
} else {
|
|
1907
|
-
beg = begs.pop();
|
|
1908
|
-
if (beg !== void 0 && beg < left) {
|
|
1909
|
-
left = beg;
|
|
1910
|
-
right = bi;
|
|
1911
|
-
}
|
|
1912
|
-
bi = str.indexOf(b, i + 1);
|
|
1913
|
-
}
|
|
1914
|
-
i = ai < bi && ai >= 0 ? ai : bi;
|
|
1915
|
-
}
|
|
1916
|
-
if (begs.length && right !== void 0) {
|
|
1917
|
-
result = [left, right];
|
|
1918
|
-
}
|
|
1919
|
-
}
|
|
1920
|
-
return result;
|
|
1921
|
-
};
|
|
1922
|
-
|
|
1923
|
-
// ../../node_modules/.pnpm/@isaacs+brace-expansion@5.0.1/node_modules/@isaacs/brace-expansion/dist/esm/index.js
|
|
1924
|
-
var escSlash = "\0SLASH" + Math.random() + "\0";
|
|
1925
|
-
var escOpen = "\0OPEN" + Math.random() + "\0";
|
|
1926
|
-
var escClose = "\0CLOSE" + Math.random() + "\0";
|
|
1927
|
-
var escComma = "\0COMMA" + Math.random() + "\0";
|
|
1928
|
-
var escPeriod = "\0PERIOD" + Math.random() + "\0";
|
|
1929
|
-
var escSlashPattern = new RegExp(escSlash, "g");
|
|
1930
|
-
var escOpenPattern = new RegExp(escOpen, "g");
|
|
1931
|
-
var escClosePattern = new RegExp(escClose, "g");
|
|
1932
|
-
var escCommaPattern = new RegExp(escComma, "g");
|
|
1933
|
-
var escPeriodPattern = new RegExp(escPeriod, "g");
|
|
1934
|
-
var slashPattern = /\\\\/g;
|
|
1935
|
-
var openPattern = /\\{/g;
|
|
1936
|
-
var closePattern = /\\}/g;
|
|
1937
|
-
var commaPattern = /\\,/g;
|
|
1938
|
-
var periodPattern = /\\./g;
|
|
1939
|
-
var EXPANSION_MAX = 1e5;
|
|
1940
|
-
function numeric2(str) {
|
|
1941
|
-
return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
|
|
1942
|
-
}
|
|
1943
|
-
function escapeBraces(str) {
|
|
1944
|
-
return str.replace(slashPattern, escSlash).replace(openPattern, escOpen).replace(closePattern, escClose).replace(commaPattern, escComma).replace(periodPattern, escPeriod);
|
|
1945
|
-
}
|
|
1946
|
-
function unescapeBraces(str) {
|
|
1947
|
-
return str.replace(escSlashPattern, "\\").replace(escOpenPattern, "{").replace(escClosePattern, "}").replace(escCommaPattern, ",").replace(escPeriodPattern, ".");
|
|
1948
|
-
}
|
|
1949
|
-
function parseCommaParts(str) {
|
|
1950
|
-
if (!str) {
|
|
1951
|
-
return [""];
|
|
1952
|
-
}
|
|
1953
|
-
const parts = [];
|
|
1954
|
-
const m = balanced("{", "}", str);
|
|
1955
|
-
if (!m) {
|
|
1956
|
-
return str.split(",");
|
|
1957
|
-
}
|
|
1958
|
-
const { pre, body, post } = m;
|
|
1959
|
-
const p = pre.split(",");
|
|
1960
|
-
p[p.length - 1] += "{" + body + "}";
|
|
1961
|
-
const postParts = parseCommaParts(post);
|
|
1962
|
-
if (post.length) {
|
|
1963
|
-
;
|
|
1964
|
-
p[p.length - 1] += postParts.shift();
|
|
1965
|
-
p.push.apply(p, postParts);
|
|
1966
|
-
}
|
|
1967
|
-
parts.push.apply(parts, p);
|
|
1968
|
-
return parts;
|
|
1969
|
-
}
|
|
1970
|
-
function expand(str, options = {}) {
|
|
1971
|
-
if (!str) {
|
|
1972
|
-
return [];
|
|
1973
|
-
}
|
|
1974
|
-
const { max = EXPANSION_MAX } = options;
|
|
1975
|
-
if (str.slice(0, 2) === "{}") {
|
|
1976
|
-
str = "\\{\\}" + str.slice(2);
|
|
1977
|
-
}
|
|
1978
|
-
return expand_(escapeBraces(str), max, true).map(unescapeBraces);
|
|
1979
|
-
}
|
|
1980
|
-
function embrace(str) {
|
|
1981
|
-
return "{" + str + "}";
|
|
1982
|
-
}
|
|
1983
|
-
function isPadded(el) {
|
|
1984
|
-
return /^-?0\d/.test(el);
|
|
1985
|
-
}
|
|
1986
|
-
function lte(i, y) {
|
|
1987
|
-
return i <= y;
|
|
1988
|
-
}
|
|
1989
|
-
function gte(i, y) {
|
|
1990
|
-
return i >= y;
|
|
1991
|
-
}
|
|
1992
|
-
function expand_(str, max, isTop) {
|
|
1993
|
-
const expansions = [];
|
|
1994
|
-
const m = balanced("{", "}", str);
|
|
1995
|
-
if (!m)
|
|
1996
|
-
return [str];
|
|
1997
|
-
const pre = m.pre;
|
|
1998
|
-
const post = m.post.length ? expand_(m.post, max, false) : [""];
|
|
1999
|
-
if (/\$$/.test(m.pre)) {
|
|
2000
|
-
for (let k = 0; k < post.length && k < max; k++) {
|
|
2001
|
-
const expansion = pre + "{" + m.body + "}" + post[k];
|
|
2002
|
-
expansions.push(expansion);
|
|
2003
|
-
}
|
|
2004
|
-
} else {
|
|
2005
|
-
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
2006
|
-
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
2007
|
-
const isSequence = isNumericSequence || isAlphaSequence;
|
|
2008
|
-
const isOptions = m.body.indexOf(",") >= 0;
|
|
2009
|
-
if (!isSequence && !isOptions) {
|
|
2010
|
-
if (m.post.match(/,(?!,).*\}/)) {
|
|
2011
|
-
str = m.pre + "{" + m.body + escClose + m.post;
|
|
2012
|
-
return expand_(str, max, true);
|
|
2013
|
-
}
|
|
2014
|
-
return [str];
|
|
2015
|
-
}
|
|
2016
|
-
let n;
|
|
2017
|
-
if (isSequence) {
|
|
2018
|
-
n = m.body.split(/\.\./);
|
|
2019
|
-
} else {
|
|
2020
|
-
n = parseCommaParts(m.body);
|
|
2021
|
-
if (n.length === 1 && n[0] !== void 0) {
|
|
2022
|
-
n = expand_(n[0], max, false).map(embrace);
|
|
2023
|
-
if (n.length === 1) {
|
|
2024
|
-
return post.map((p) => m.pre + n[0] + p);
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
}
|
|
2028
|
-
let N;
|
|
2029
|
-
if (isSequence && n[0] !== void 0 && n[1] !== void 0) {
|
|
2030
|
-
const x = numeric2(n[0]);
|
|
2031
|
-
const y = numeric2(n[1]);
|
|
2032
|
-
const width = Math.max(n[0].length, n[1].length);
|
|
2033
|
-
let incr = n.length === 3 && n[2] !== void 0 ? Math.abs(numeric2(n[2])) : 1;
|
|
2034
|
-
let test = lte;
|
|
2035
|
-
const reverse = y < x;
|
|
2036
|
-
if (reverse) {
|
|
2037
|
-
incr *= -1;
|
|
2038
|
-
test = gte;
|
|
2039
|
-
}
|
|
2040
|
-
const pad = n.some(isPadded);
|
|
2041
|
-
N = [];
|
|
2042
|
-
for (let i = x; test(i, y); i += incr) {
|
|
2043
|
-
let c;
|
|
2044
|
-
if (isAlphaSequence) {
|
|
2045
|
-
c = String.fromCharCode(i);
|
|
2046
|
-
if (c === "\\") {
|
|
2047
|
-
c = "";
|
|
2048
|
-
}
|
|
2049
|
-
} else {
|
|
2050
|
-
c = String(i);
|
|
2051
|
-
if (pad) {
|
|
2052
|
-
const need = width - c.length;
|
|
2053
|
-
if (need > 0) {
|
|
2054
|
-
const z = new Array(need + 1).join("0");
|
|
2055
|
-
if (i < 0) {
|
|
2056
|
-
c = "-" + z + c.slice(1);
|
|
2057
|
-
} else {
|
|
2058
|
-
c = z + c;
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
N.push(c);
|
|
2064
|
-
}
|
|
2065
|
-
} else {
|
|
2066
|
-
N = [];
|
|
2067
|
-
for (let j = 0; j < n.length; j++) {
|
|
2068
|
-
N.push.apply(N, expand_(n[j], max, false));
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
for (let j = 0; j < N.length; j++) {
|
|
2072
|
-
for (let k = 0; k < post.length && expansions.length < max; k++) {
|
|
2073
|
-
const expansion = pre + N[j] + post[k];
|
|
2074
|
-
if (!isTop || isSequence || expansion) {
|
|
2075
|
-
expansions.push(expansion);
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
return expansions;
|
|
2081
|
-
}
|
|
2082
|
-
|
|
2083
|
-
// ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
2084
|
-
var MAX_PATTERN_LENGTH = 1024 * 64;
|
|
2085
|
-
var assertValidPattern = (pattern) => {
|
|
2086
|
-
if (typeof pattern !== "string") {
|
|
2087
|
-
throw new TypeError("invalid pattern");
|
|
2088
|
-
}
|
|
2089
|
-
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
2090
|
-
throw new TypeError("pattern is too long");
|
|
2091
|
-
}
|
|
2092
|
-
};
|
|
2093
|
-
|
|
2094
|
-
// ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/brace-expressions.js
|
|
2095
|
-
var posixClasses = {
|
|
2096
|
-
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
|
|
2097
|
-
"[:alpha:]": ["\\p{L}\\p{Nl}", true],
|
|
2098
|
-
"[:ascii:]": ["\\x00-\\x7f", false],
|
|
2099
|
-
"[:blank:]": ["\\p{Zs}\\t", true],
|
|
2100
|
-
"[:cntrl:]": ["\\p{Cc}", true],
|
|
2101
|
-
"[:digit:]": ["\\p{Nd}", true],
|
|
2102
|
-
"[:graph:]": ["\\p{Z}\\p{C}", true, true],
|
|
2103
|
-
"[:lower:]": ["\\p{Ll}", true],
|
|
2104
|
-
"[:print:]": ["\\p{C}", true],
|
|
2105
|
-
"[:punct:]": ["\\p{P}", true],
|
|
2106
|
-
"[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
|
|
2107
|
-
"[:upper:]": ["\\p{Lu}", true],
|
|
2108
|
-
"[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
|
|
2109
|
-
"[:xdigit:]": ["A-Fa-f0-9", false]
|
|
2110
|
-
};
|
|
2111
|
-
var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
|
|
2112
|
-
var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
2113
|
-
var rangesToString = (ranges) => ranges.join("");
|
|
2114
|
-
var parseClass = (glob, position) => {
|
|
2115
|
-
const pos = position;
|
|
2116
|
-
if (glob.charAt(pos) !== "[") {
|
|
2117
|
-
throw new Error("not in a brace expression");
|
|
2118
|
-
}
|
|
2119
|
-
const ranges = [];
|
|
2120
|
-
const negs = [];
|
|
2121
|
-
let i = pos + 1;
|
|
2122
|
-
let sawStart = false;
|
|
2123
|
-
let uflag = false;
|
|
2124
|
-
let escaping = false;
|
|
2125
|
-
let negate = false;
|
|
2126
|
-
let endPos = pos;
|
|
2127
|
-
let rangeStart = "";
|
|
2128
|
-
WHILE: while (i < glob.length) {
|
|
2129
|
-
const c = glob.charAt(i);
|
|
2130
|
-
if ((c === "!" || c === "^") && i === pos + 1) {
|
|
2131
|
-
negate = true;
|
|
2132
|
-
i++;
|
|
2133
|
-
continue;
|
|
2134
|
-
}
|
|
2135
|
-
if (c === "]" && sawStart && !escaping) {
|
|
2136
|
-
endPos = i + 1;
|
|
2137
|
-
break;
|
|
2138
|
-
}
|
|
2139
|
-
sawStart = true;
|
|
2140
|
-
if (c === "\\") {
|
|
2141
|
-
if (!escaping) {
|
|
2142
|
-
escaping = true;
|
|
2143
|
-
i++;
|
|
2144
|
-
continue;
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
if (c === "[" && !escaping) {
|
|
2148
|
-
for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
|
|
2149
|
-
if (glob.startsWith(cls, i)) {
|
|
2150
|
-
if (rangeStart) {
|
|
2151
|
-
return ["$.", false, glob.length - pos, true];
|
|
2152
|
-
}
|
|
2153
|
-
i += cls.length;
|
|
2154
|
-
if (neg)
|
|
2155
|
-
negs.push(unip);
|
|
2156
|
-
else
|
|
2157
|
-
ranges.push(unip);
|
|
2158
|
-
uflag = uflag || u;
|
|
2159
|
-
continue WHILE;
|
|
2160
|
-
}
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
escaping = false;
|
|
2164
|
-
if (rangeStart) {
|
|
2165
|
-
if (c > rangeStart) {
|
|
2166
|
-
ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
|
|
2167
|
-
} else if (c === rangeStart) {
|
|
2168
|
-
ranges.push(braceEscape(c));
|
|
2169
|
-
}
|
|
2170
|
-
rangeStart = "";
|
|
2171
|
-
i++;
|
|
2172
|
-
continue;
|
|
2173
|
-
}
|
|
2174
|
-
if (glob.startsWith("-]", i + 1)) {
|
|
2175
|
-
ranges.push(braceEscape(c + "-"));
|
|
2176
|
-
i += 2;
|
|
2177
|
-
continue;
|
|
2178
|
-
}
|
|
2179
|
-
if (glob.startsWith("-", i + 1)) {
|
|
2180
|
-
rangeStart = c;
|
|
2181
|
-
i += 2;
|
|
2182
|
-
continue;
|
|
2183
|
-
}
|
|
2184
|
-
ranges.push(braceEscape(c));
|
|
2185
|
-
i++;
|
|
2186
|
-
}
|
|
2187
|
-
if (endPos < i) {
|
|
2188
|
-
return ["", false, 0, false];
|
|
2189
|
-
}
|
|
2190
|
-
if (!ranges.length && !negs.length) {
|
|
2191
|
-
return ["$.", false, glob.length - pos, true];
|
|
2192
|
-
}
|
|
2193
|
-
if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
|
|
2194
|
-
const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
|
|
2195
|
-
return [regexpEscape(r), false, endPos - pos, false];
|
|
2196
|
-
}
|
|
2197
|
-
const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
|
|
2198
|
-
const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
|
|
2199
|
-
const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
|
|
2200
|
-
return [comb, uflag, endPos - pos, true];
|
|
2201
|
-
};
|
|
2202
|
-
|
|
2203
|
-
// ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/unescape.js
|
|
2204
|
-
var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
2205
|
-
return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
|
|
2206
|
-
};
|
|
2207
|
-
|
|
2208
|
-
// ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/ast.js
|
|
2209
|
-
var types = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]);
|
|
2210
|
-
var isExtglobType = (c) => types.has(c);
|
|
2211
|
-
var startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))";
|
|
2212
|
-
var startNoDot = "(?!\\.)";
|
|
2213
|
-
var addPatternStart = /* @__PURE__ */ new Set(["[", "."]);
|
|
2214
|
-
var justDots = /* @__PURE__ */ new Set(["..", "."]);
|
|
2215
|
-
var reSpecials = new Set("().*{}+?[]^$\\!");
|
|
2216
|
-
var regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
2217
|
-
var qmark = "[^/]";
|
|
2218
|
-
var star = qmark + "*?";
|
|
2219
|
-
var starNoEmpty = qmark + "+?";
|
|
2220
|
-
var AST = class _AST {
|
|
2221
|
-
type;
|
|
2222
|
-
#root;
|
|
2223
|
-
#hasMagic;
|
|
2224
|
-
#uflag = false;
|
|
2225
|
-
#parts = [];
|
|
2226
|
-
#parent;
|
|
2227
|
-
#parentIndex;
|
|
2228
|
-
#negs;
|
|
2229
|
-
#filledNegs = false;
|
|
2230
|
-
#options;
|
|
2231
|
-
#toString;
|
|
2232
|
-
// set to true if it's an extglob with no children
|
|
2233
|
-
// (which really means one child of '')
|
|
2234
|
-
#emptyExt = false;
|
|
2235
|
-
constructor(type, parent, options = {}) {
|
|
2236
|
-
this.type = type;
|
|
2237
|
-
if (type)
|
|
2238
|
-
this.#hasMagic = true;
|
|
2239
|
-
this.#parent = parent;
|
|
2240
|
-
this.#root = this.#parent ? this.#parent.#root : this;
|
|
2241
|
-
this.#options = this.#root === this ? options : this.#root.#options;
|
|
2242
|
-
this.#negs = this.#root === this ? [] : this.#root.#negs;
|
|
2243
|
-
if (type === "!" && !this.#root.#filledNegs)
|
|
2244
|
-
this.#negs.push(this);
|
|
2245
|
-
this.#parentIndex = this.#parent ? this.#parent.#parts.length : 0;
|
|
2246
|
-
}
|
|
2247
|
-
get hasMagic() {
|
|
2248
|
-
if (this.#hasMagic !== void 0)
|
|
2249
|
-
return this.#hasMagic;
|
|
2250
|
-
for (const p of this.#parts) {
|
|
2251
|
-
if (typeof p === "string")
|
|
2252
|
-
continue;
|
|
2253
|
-
if (p.type || p.hasMagic)
|
|
2254
|
-
return this.#hasMagic = true;
|
|
2255
|
-
}
|
|
2256
|
-
return this.#hasMagic;
|
|
2257
|
-
}
|
|
2258
|
-
// reconstructs the pattern
|
|
2259
|
-
toString() {
|
|
2260
|
-
if (this.#toString !== void 0)
|
|
2261
|
-
return this.#toString;
|
|
2262
|
-
if (!this.type) {
|
|
2263
|
-
return this.#toString = this.#parts.map((p) => String(p)).join("");
|
|
2264
|
-
} else {
|
|
2265
|
-
return this.#toString = this.type + "(" + this.#parts.map((p) => String(p)).join("|") + ")";
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
#fillNegs() {
|
|
2269
|
-
if (this !== this.#root)
|
|
2270
|
-
throw new Error("should only call on root");
|
|
2271
|
-
if (this.#filledNegs)
|
|
2272
|
-
return this;
|
|
2273
|
-
this.toString();
|
|
2274
|
-
this.#filledNegs = true;
|
|
2275
|
-
let n;
|
|
2276
|
-
while (n = this.#negs.pop()) {
|
|
2277
|
-
if (n.type !== "!")
|
|
2278
|
-
continue;
|
|
2279
|
-
let p = n;
|
|
2280
|
-
let pp = p.#parent;
|
|
2281
|
-
while (pp) {
|
|
2282
|
-
for (let i = p.#parentIndex + 1; !pp.type && i < pp.#parts.length; i++) {
|
|
2283
|
-
for (const part of n.#parts) {
|
|
2284
|
-
if (typeof part === "string") {
|
|
2285
|
-
throw new Error("string part in extglob AST??");
|
|
2286
|
-
}
|
|
2287
|
-
part.copyIn(pp.#parts[i]);
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2290
|
-
p = pp;
|
|
2291
|
-
pp = p.#parent;
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
return this;
|
|
2295
|
-
}
|
|
2296
|
-
push(...parts) {
|
|
2297
|
-
for (const p of parts) {
|
|
2298
|
-
if (p === "")
|
|
2299
|
-
continue;
|
|
2300
|
-
if (typeof p !== "string" && !(p instanceof _AST && p.#parent === this)) {
|
|
2301
|
-
throw new Error("invalid part: " + p);
|
|
2302
|
-
}
|
|
2303
|
-
this.#parts.push(p);
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
toJSON() {
|
|
2307
|
-
const ret = this.type === null ? this.#parts.slice().map((p) => typeof p === "string" ? p : p.toJSON()) : [this.type, ...this.#parts.map((p) => p.toJSON())];
|
|
2308
|
-
if (this.isStart() && !this.type)
|
|
2309
|
-
ret.unshift([]);
|
|
2310
|
-
if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && this.#parent?.type === "!")) {
|
|
2311
|
-
ret.push({});
|
|
2312
|
-
}
|
|
2313
|
-
return ret;
|
|
2314
|
-
}
|
|
2315
|
-
isStart() {
|
|
2316
|
-
if (this.#root === this)
|
|
2317
|
-
return true;
|
|
2318
|
-
if (!this.#parent?.isStart())
|
|
2319
|
-
return false;
|
|
2320
|
-
if (this.#parentIndex === 0)
|
|
2321
|
-
return true;
|
|
2322
|
-
const p = this.#parent;
|
|
2323
|
-
for (let i = 0; i < this.#parentIndex; i++) {
|
|
2324
|
-
const pp = p.#parts[i];
|
|
2325
|
-
if (!(pp instanceof _AST && pp.type === "!")) {
|
|
2326
|
-
return false;
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
return true;
|
|
2330
|
-
}
|
|
2331
|
-
isEnd() {
|
|
2332
|
-
if (this.#root === this)
|
|
2333
|
-
return true;
|
|
2334
|
-
if (this.#parent?.type === "!")
|
|
2335
|
-
return true;
|
|
2336
|
-
if (!this.#parent?.isEnd())
|
|
2337
|
-
return false;
|
|
2338
|
-
if (!this.type)
|
|
2339
|
-
return this.#parent?.isEnd();
|
|
2340
|
-
const pl = this.#parent ? this.#parent.#parts.length : 0;
|
|
2341
|
-
return this.#parentIndex === pl - 1;
|
|
2342
|
-
}
|
|
2343
|
-
copyIn(part) {
|
|
2344
|
-
if (typeof part === "string")
|
|
2345
|
-
this.push(part);
|
|
2346
|
-
else
|
|
2347
|
-
this.push(part.clone(this));
|
|
2348
|
-
}
|
|
2349
|
-
clone(parent) {
|
|
2350
|
-
const c = new _AST(this.type, parent);
|
|
2351
|
-
for (const p of this.#parts) {
|
|
2352
|
-
c.copyIn(p);
|
|
2353
|
-
}
|
|
2354
|
-
return c;
|
|
2355
|
-
}
|
|
2356
|
-
static #parseAST(str, ast, pos, opt) {
|
|
2357
|
-
let escaping = false;
|
|
2358
|
-
let inBrace = false;
|
|
2359
|
-
let braceStart = -1;
|
|
2360
|
-
let braceNeg = false;
|
|
2361
|
-
if (ast.type === null) {
|
|
2362
|
-
let i2 = pos;
|
|
2363
|
-
let acc2 = "";
|
|
2364
|
-
while (i2 < str.length) {
|
|
2365
|
-
const c = str.charAt(i2++);
|
|
2366
|
-
if (escaping || c === "\\") {
|
|
2367
|
-
escaping = !escaping;
|
|
2368
|
-
acc2 += c;
|
|
2369
|
-
continue;
|
|
2370
|
-
}
|
|
2371
|
-
if (inBrace) {
|
|
2372
|
-
if (i2 === braceStart + 1) {
|
|
2373
|
-
if (c === "^" || c === "!") {
|
|
2374
|
-
braceNeg = true;
|
|
2375
|
-
}
|
|
2376
|
-
} else if (c === "]" && !(i2 === braceStart + 2 && braceNeg)) {
|
|
2377
|
-
inBrace = false;
|
|
2378
|
-
}
|
|
2379
|
-
acc2 += c;
|
|
2380
|
-
continue;
|
|
2381
|
-
} else if (c === "[") {
|
|
2382
|
-
inBrace = true;
|
|
2383
|
-
braceStart = i2;
|
|
2384
|
-
braceNeg = false;
|
|
2385
|
-
acc2 += c;
|
|
2386
|
-
continue;
|
|
2387
|
-
}
|
|
2388
|
-
if (!opt.noext && isExtglobType(c) && str.charAt(i2) === "(") {
|
|
2389
|
-
ast.push(acc2);
|
|
2390
|
-
acc2 = "";
|
|
2391
|
-
const ext2 = new _AST(c, ast);
|
|
2392
|
-
i2 = _AST.#parseAST(str, ext2, i2, opt);
|
|
2393
|
-
ast.push(ext2);
|
|
2394
|
-
continue;
|
|
2395
|
-
}
|
|
2396
|
-
acc2 += c;
|
|
2397
|
-
}
|
|
2398
|
-
ast.push(acc2);
|
|
2399
|
-
return i2;
|
|
2400
|
-
}
|
|
2401
|
-
let i = pos + 1;
|
|
2402
|
-
let part = new _AST(null, ast);
|
|
2403
|
-
const parts = [];
|
|
2404
|
-
let acc = "";
|
|
2405
|
-
while (i < str.length) {
|
|
2406
|
-
const c = str.charAt(i++);
|
|
2407
|
-
if (escaping || c === "\\") {
|
|
2408
|
-
escaping = !escaping;
|
|
2409
|
-
acc += c;
|
|
2410
|
-
continue;
|
|
2411
|
-
}
|
|
2412
|
-
if (inBrace) {
|
|
2413
|
-
if (i === braceStart + 1) {
|
|
2414
|
-
if (c === "^" || c === "!") {
|
|
2415
|
-
braceNeg = true;
|
|
2416
|
-
}
|
|
2417
|
-
} else if (c === "]" && !(i === braceStart + 2 && braceNeg)) {
|
|
2418
|
-
inBrace = false;
|
|
2419
|
-
}
|
|
2420
|
-
acc += c;
|
|
2421
|
-
continue;
|
|
2422
|
-
} else if (c === "[") {
|
|
2423
|
-
inBrace = true;
|
|
2424
|
-
braceStart = i;
|
|
2425
|
-
braceNeg = false;
|
|
2426
|
-
acc += c;
|
|
2427
|
-
continue;
|
|
2428
|
-
}
|
|
2429
|
-
if (isExtglobType(c) && str.charAt(i) === "(") {
|
|
2430
|
-
part.push(acc);
|
|
2431
|
-
acc = "";
|
|
2432
|
-
const ext2 = new _AST(c, part);
|
|
2433
|
-
part.push(ext2);
|
|
2434
|
-
i = _AST.#parseAST(str, ext2, i, opt);
|
|
2435
|
-
continue;
|
|
2436
|
-
}
|
|
2437
|
-
if (c === "|") {
|
|
2438
|
-
part.push(acc);
|
|
2439
|
-
acc = "";
|
|
2440
|
-
parts.push(part);
|
|
2441
|
-
part = new _AST(null, ast);
|
|
2442
|
-
continue;
|
|
2443
|
-
}
|
|
2444
|
-
if (c === ")") {
|
|
2445
|
-
if (acc === "" && ast.#parts.length === 0) {
|
|
2446
|
-
ast.#emptyExt = true;
|
|
2447
|
-
}
|
|
2448
|
-
part.push(acc);
|
|
2449
|
-
acc = "";
|
|
2450
|
-
ast.push(...parts, part);
|
|
2451
|
-
return i;
|
|
2452
|
-
}
|
|
2453
|
-
acc += c;
|
|
2454
|
-
}
|
|
2455
|
-
ast.type = null;
|
|
2456
|
-
ast.#hasMagic = void 0;
|
|
2457
|
-
ast.#parts = [str.substring(pos - 1)];
|
|
2458
|
-
return i;
|
|
2459
|
-
}
|
|
2460
|
-
static fromGlob(pattern, options = {}) {
|
|
2461
|
-
const ast = new _AST(null, void 0, options);
|
|
2462
|
-
_AST.#parseAST(pattern, ast, 0, options);
|
|
2463
|
-
return ast;
|
|
2464
|
-
}
|
|
2465
|
-
// returns the regular expression if there's magic, or the unescaped
|
|
2466
|
-
// string if not.
|
|
2467
|
-
toMMPattern() {
|
|
2468
|
-
if (this !== this.#root)
|
|
2469
|
-
return this.#root.toMMPattern();
|
|
2470
|
-
const glob = this.toString();
|
|
2471
|
-
const [re, body, hasMagic, uflag] = this.toRegExpSource();
|
|
2472
|
-
const anyMagic = hasMagic || this.#hasMagic || this.#options.nocase && !this.#options.nocaseMagicOnly && glob.toUpperCase() !== glob.toLowerCase();
|
|
2473
|
-
if (!anyMagic) {
|
|
2474
|
-
return body;
|
|
2475
|
-
}
|
|
2476
|
-
const flags = (this.#options.nocase ? "i" : "") + (uflag ? "u" : "");
|
|
2477
|
-
return Object.assign(new RegExp(`^${re}$`, flags), {
|
|
2478
|
-
_src: re,
|
|
2479
|
-
_glob: glob
|
|
2480
|
-
});
|
|
2481
|
-
}
|
|
2482
|
-
get options() {
|
|
2483
|
-
return this.#options;
|
|
2484
|
-
}
|
|
2485
|
-
// returns the string match, the regexp source, whether there's magic
|
|
2486
|
-
// in the regexp (so a regular expression is required) and whether or
|
|
2487
|
-
// not the uflag is needed for the regular expression (for posix classes)
|
|
2488
|
-
// TODO: instead of injecting the start/end at this point, just return
|
|
2489
|
-
// the BODY of the regexp, along with the start/end portions suitable
|
|
2490
|
-
// for binding the start/end in either a joined full-path makeRe context
|
|
2491
|
-
// (where we bind to (^|/), or a standalone matchPart context (where
|
|
2492
|
-
// we bind to ^, and not /). Otherwise slashes get duped!
|
|
2493
|
-
//
|
|
2494
|
-
// In part-matching mode, the start is:
|
|
2495
|
-
// - if not isStart: nothing
|
|
2496
|
-
// - if traversal possible, but not allowed: ^(?!\.\.?$)
|
|
2497
|
-
// - if dots allowed or not possible: ^
|
|
2498
|
-
// - if dots possible and not allowed: ^(?!\.)
|
|
2499
|
-
// end is:
|
|
2500
|
-
// - if not isEnd(): nothing
|
|
2501
|
-
// - else: $
|
|
2502
|
-
//
|
|
2503
|
-
// In full-path matching mode, we put the slash at the START of the
|
|
2504
|
-
// pattern, so start is:
|
|
2505
|
-
// - if first pattern: same as part-matching mode
|
|
2506
|
-
// - if not isStart(): nothing
|
|
2507
|
-
// - if traversal possible, but not allowed: /(?!\.\.?(?:$|/))
|
|
2508
|
-
// - if dots allowed or not possible: /
|
|
2509
|
-
// - if dots possible and not allowed: /(?!\.)
|
|
2510
|
-
// end is:
|
|
2511
|
-
// - if last pattern, same as part-matching mode
|
|
2512
|
-
// - else nothing
|
|
2513
|
-
//
|
|
2514
|
-
// Always put the (?:$|/) on negated tails, though, because that has to be
|
|
2515
|
-
// there to bind the end of the negated pattern portion, and it's easier to
|
|
2516
|
-
// just stick it in now rather than try to inject it later in the middle of
|
|
2517
|
-
// the pattern.
|
|
2518
|
-
//
|
|
2519
|
-
// We can just always return the same end, and leave it up to the caller
|
|
2520
|
-
// to know whether it's going to be used joined or in parts.
|
|
2521
|
-
// And, if the start is adjusted slightly, can do the same there:
|
|
2522
|
-
// - if not isStart: nothing
|
|
2523
|
-
// - if traversal possible, but not allowed: (?:/|^)(?!\.\.?$)
|
|
2524
|
-
// - if dots allowed or not possible: (?:/|^)
|
|
2525
|
-
// - if dots possible and not allowed: (?:/|^)(?!\.)
|
|
2526
|
-
//
|
|
2527
|
-
// But it's better to have a simpler binding without a conditional, for
|
|
2528
|
-
// performance, so probably better to return both start options.
|
|
2529
|
-
//
|
|
2530
|
-
// Then the caller just ignores the end if it's not the first pattern,
|
|
2531
|
-
// and the start always gets applied.
|
|
2532
|
-
//
|
|
2533
|
-
// But that's always going to be $ if it's the ending pattern, or nothing,
|
|
2534
|
-
// so the caller can just attach $ at the end of the pattern when building.
|
|
2535
|
-
//
|
|
2536
|
-
// So the todo is:
|
|
2537
|
-
// - better detect what kind of start is needed
|
|
2538
|
-
// - return both flavors of starting pattern
|
|
2539
|
-
// - attach $ at the end of the pattern when creating the actual RegExp
|
|
2540
|
-
//
|
|
2541
|
-
// Ah, but wait, no, that all only applies to the root when the first pattern
|
|
2542
|
-
// is not an extglob. If the first pattern IS an extglob, then we need all
|
|
2543
|
-
// that dot prevention biz to live in the extglob portions, because eg
|
|
2544
|
-
// +(*|.x*) can match .xy but not .yx.
|
|
2545
|
-
//
|
|
2546
|
-
// So, return the two flavors if it's #root and the first child is not an
|
|
2547
|
-
// AST, otherwise leave it to the child AST to handle it, and there,
|
|
2548
|
-
// use the (?:^|/) style of start binding.
|
|
2549
|
-
//
|
|
2550
|
-
// Even simplified further:
|
|
2551
|
-
// - Since the start for a join is eg /(?!\.) and the start for a part
|
|
2552
|
-
// is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
|
|
2553
|
-
// or start or whatever) and prepend ^ or / at the Regexp construction.
|
|
2554
|
-
toRegExpSource(allowDot) {
|
|
2555
|
-
const dot = allowDot ?? !!this.#options.dot;
|
|
2556
|
-
if (this.#root === this)
|
|
2557
|
-
this.#fillNegs();
|
|
2558
|
-
if (!this.type) {
|
|
2559
|
-
const noEmpty = this.isStart() && this.isEnd();
|
|
2560
|
-
const src = this.#parts.map((p) => {
|
|
2561
|
-
const [re, _, hasMagic, uflag] = typeof p === "string" ? _AST.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
|
|
2562
|
-
this.#hasMagic = this.#hasMagic || hasMagic;
|
|
2563
|
-
this.#uflag = this.#uflag || uflag;
|
|
2564
|
-
return re;
|
|
2565
|
-
}).join("");
|
|
2566
|
-
let start2 = "";
|
|
2567
|
-
if (this.isStart()) {
|
|
2568
|
-
if (typeof this.#parts[0] === "string") {
|
|
2569
|
-
const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]);
|
|
2570
|
-
if (!dotTravAllowed) {
|
|
2571
|
-
const aps = addPatternStart;
|
|
2572
|
-
const needNoTrav = (
|
|
2573
|
-
// dots are allowed, and the pattern starts with [ or .
|
|
2574
|
-
dot && aps.has(src.charAt(0)) || // the pattern starts with \., and then [ or .
|
|
2575
|
-
src.startsWith("\\.") && aps.has(src.charAt(2)) || // the pattern starts with \.\., and then [ or .
|
|
2576
|
-
src.startsWith("\\.\\.") && aps.has(src.charAt(4))
|
|
2577
|
-
);
|
|
2578
|
-
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
|
|
2579
|
-
start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : "";
|
|
2580
|
-
}
|
|
2581
|
-
}
|
|
2582
|
-
}
|
|
2583
|
-
let end = "";
|
|
2584
|
-
if (this.isEnd() && this.#root.#filledNegs && this.#parent?.type === "!") {
|
|
2585
|
-
end = "(?:$|\\/)";
|
|
2586
|
-
}
|
|
2587
|
-
const final2 = start2 + src + end;
|
|
2588
|
-
return [
|
|
2589
|
-
final2,
|
|
2590
|
-
unescape(src),
|
|
2591
|
-
this.#hasMagic = !!this.#hasMagic,
|
|
2592
|
-
this.#uflag
|
|
2593
|
-
];
|
|
2594
|
-
}
|
|
2595
|
-
const repeated = this.type === "*" || this.type === "+";
|
|
2596
|
-
const start = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
2597
|
-
let body = this.#partsToRegExp(dot);
|
|
2598
|
-
if (this.isStart() && this.isEnd() && !body && this.type !== "!") {
|
|
2599
|
-
const s = this.toString();
|
|
2600
|
-
this.#parts = [s];
|
|
2601
|
-
this.type = null;
|
|
2602
|
-
this.#hasMagic = void 0;
|
|
2603
|
-
return [s, unescape(this.toString()), false, false];
|
|
2604
|
-
}
|
|
2605
|
-
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : this.#partsToRegExp(true);
|
|
2606
|
-
if (bodyDotAllowed === body) {
|
|
2607
|
-
bodyDotAllowed = "";
|
|
2608
|
-
}
|
|
2609
|
-
if (bodyDotAllowed) {
|
|
2610
|
-
body = `(?:${body})(?:${bodyDotAllowed})*?`;
|
|
2611
|
-
}
|
|
2612
|
-
let final = "";
|
|
2613
|
-
if (this.type === "!" && this.#emptyExt) {
|
|
2614
|
-
final = (this.isStart() && !dot ? startNoDot : "") + starNoEmpty;
|
|
2615
|
-
} else {
|
|
2616
|
-
const close = this.type === "!" ? (
|
|
2617
|
-
// !() must match something,but !(x) can match ''
|
|
2618
|
-
"))" + (this.isStart() && !dot && !allowDot ? startNoDot : "") + star + ")"
|
|
2619
|
-
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && bodyDotAllowed ? ")" : this.type === "*" && bodyDotAllowed ? `)?` : `)${this.type}`;
|
|
2620
|
-
final = start + body + close;
|
|
2621
|
-
}
|
|
2622
|
-
return [
|
|
2623
|
-
final,
|
|
2624
|
-
unescape(body),
|
|
2625
|
-
this.#hasMagic = !!this.#hasMagic,
|
|
2626
|
-
this.#uflag
|
|
2627
|
-
];
|
|
2628
|
-
}
|
|
2629
|
-
#partsToRegExp(dot) {
|
|
2630
|
-
return this.#parts.map((p) => {
|
|
2631
|
-
if (typeof p === "string") {
|
|
2632
|
-
throw new Error("string type in extglob ast??");
|
|
2633
|
-
}
|
|
2634
|
-
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
|
|
2635
|
-
this.#uflag = this.#uflag || uflag;
|
|
2636
|
-
return re;
|
|
2637
|
-
}).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|");
|
|
2638
|
-
}
|
|
2639
|
-
static #parseGlob(glob, hasMagic, noEmpty = false) {
|
|
2640
|
-
let escaping = false;
|
|
2641
|
-
let re = "";
|
|
2642
|
-
let uflag = false;
|
|
2643
|
-
for (let i = 0; i < glob.length; i++) {
|
|
2644
|
-
const c = glob.charAt(i);
|
|
2645
|
-
if (escaping) {
|
|
2646
|
-
escaping = false;
|
|
2647
|
-
re += (reSpecials.has(c) ? "\\" : "") + c;
|
|
2648
|
-
continue;
|
|
2649
|
-
}
|
|
2650
|
-
if (c === "\\") {
|
|
2651
|
-
if (i === glob.length - 1) {
|
|
2652
|
-
re += "\\\\";
|
|
2653
|
-
} else {
|
|
2654
|
-
escaping = true;
|
|
2655
|
-
}
|
|
2656
|
-
continue;
|
|
2657
|
-
}
|
|
2658
|
-
if (c === "[") {
|
|
2659
|
-
const [src, needUflag, consumed, magic] = parseClass(glob, i);
|
|
2660
|
-
if (consumed) {
|
|
2661
|
-
re += src;
|
|
2662
|
-
uflag = uflag || needUflag;
|
|
2663
|
-
i += consumed - 1;
|
|
2664
|
-
hasMagic = hasMagic || magic;
|
|
2665
|
-
continue;
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
if (c === "*") {
|
|
2669
|
-
if (noEmpty && glob === "*")
|
|
2670
|
-
re += starNoEmpty;
|
|
2671
|
-
else
|
|
2672
|
-
re += star;
|
|
2673
|
-
hasMagic = true;
|
|
2674
|
-
continue;
|
|
2675
|
-
}
|
|
2676
|
-
if (c === "?") {
|
|
2677
|
-
re += qmark;
|
|
2678
|
-
hasMagic = true;
|
|
2679
|
-
continue;
|
|
2680
|
-
}
|
|
2681
|
-
re += regExpEscape(c);
|
|
2682
|
-
}
|
|
2683
|
-
return [re, unescape(glob), !!hasMagic, uflag];
|
|
2684
|
-
}
|
|
2685
|
-
};
|
|
2686
|
-
|
|
2687
|
-
// ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/escape.js
|
|
2688
|
-
var escape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
2689
|
-
return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
2690
|
-
};
|
|
2691
|
-
|
|
2692
|
-
// ../../node_modules/.pnpm/minimatch@10.0.3/node_modules/minimatch/dist/esm/index.js
|
|
2693
|
-
var minimatch = (p, pattern, options = {}) => {
|
|
2694
|
-
assertValidPattern(pattern);
|
|
2695
|
-
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
2696
|
-
return false;
|
|
2697
|
-
}
|
|
2698
|
-
return new Minimatch(pattern, options).match(p);
|
|
2699
|
-
};
|
|
2700
|
-
var starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
|
|
2701
|
-
var starDotExtTest = (ext2) => (f) => !f.startsWith(".") && f.endsWith(ext2);
|
|
2702
|
-
var starDotExtTestDot = (ext2) => (f) => f.endsWith(ext2);
|
|
2703
|
-
var starDotExtTestNocase = (ext2) => {
|
|
2704
|
-
ext2 = ext2.toLowerCase();
|
|
2705
|
-
return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext2);
|
|
2706
|
-
};
|
|
2707
|
-
var starDotExtTestNocaseDot = (ext2) => {
|
|
2708
|
-
ext2 = ext2.toLowerCase();
|
|
2709
|
-
return (f) => f.toLowerCase().endsWith(ext2);
|
|
2710
|
-
};
|
|
2711
|
-
var starDotStarRE = /^\*+\.\*+$/;
|
|
2712
|
-
var starDotStarTest = (f) => !f.startsWith(".") && f.includes(".");
|
|
2713
|
-
var starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes(".");
|
|
2714
|
-
var dotStarRE = /^\.\*+$/;
|
|
2715
|
-
var dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith(".");
|
|
2716
|
-
var starRE = /^\*+$/;
|
|
2717
|
-
var starTest = (f) => f.length !== 0 && !f.startsWith(".");
|
|
2718
|
-
var starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..";
|
|
2719
|
-
var qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
|
|
2720
|
-
var qmarksTestNocase = ([$0, ext2 = ""]) => {
|
|
2721
|
-
const noext = qmarksTestNoExt([$0]);
|
|
2722
|
-
if (!ext2)
|
|
2723
|
-
return noext;
|
|
2724
|
-
ext2 = ext2.toLowerCase();
|
|
2725
|
-
return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
|
|
2726
|
-
};
|
|
2727
|
-
var qmarksTestNocaseDot = ([$0, ext2 = ""]) => {
|
|
2728
|
-
const noext = qmarksTestNoExtDot([$0]);
|
|
2729
|
-
if (!ext2)
|
|
2730
|
-
return noext;
|
|
2731
|
-
ext2 = ext2.toLowerCase();
|
|
2732
|
-
return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
|
|
2733
|
-
};
|
|
2734
|
-
var qmarksTestDot = ([$0, ext2 = ""]) => {
|
|
2735
|
-
const noext = qmarksTestNoExtDot([$0]);
|
|
2736
|
-
return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
|
|
2737
|
-
};
|
|
2738
|
-
var qmarksTest = ([$0, ext2 = ""]) => {
|
|
2739
|
-
const noext = qmarksTestNoExt([$0]);
|
|
2740
|
-
return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
|
|
2741
|
-
};
|
|
2742
|
-
var qmarksTestNoExt = ([$0]) => {
|
|
2743
|
-
const len = $0.length;
|
|
2744
|
-
return (f) => f.length === len && !f.startsWith(".");
|
|
2745
|
-
};
|
|
2746
|
-
var qmarksTestNoExtDot = ([$0]) => {
|
|
2747
|
-
const len = $0.length;
|
|
2748
|
-
return (f) => f.length === len && f !== "." && f !== "..";
|
|
2749
|
-
};
|
|
2750
|
-
var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
2751
|
-
var path3 = {
|
|
2752
|
-
win32: { sep: "\\" },
|
|
2753
|
-
posix: { sep: "/" }
|
|
2754
|
-
};
|
|
2755
|
-
var sep = defaultPlatform === "win32" ? path3.win32.sep : path3.posix.sep;
|
|
2756
|
-
minimatch.sep = sep;
|
|
2757
|
-
var GLOBSTAR = /* @__PURE__ */ Symbol("globstar **");
|
|
2758
|
-
minimatch.GLOBSTAR = GLOBSTAR;
|
|
2759
|
-
var qmark2 = "[^/]";
|
|
2760
|
-
var star2 = qmark2 + "*?";
|
|
2761
|
-
var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
|
|
2762
|
-
var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
|
|
2763
|
-
var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
|
|
2764
|
-
minimatch.filter = filter;
|
|
2765
|
-
var ext = (a, b = {}) => Object.assign({}, a, b);
|
|
2766
|
-
var defaults = (def) => {
|
|
2767
|
-
if (!def || typeof def !== "object" || !Object.keys(def).length) {
|
|
2768
|
-
return minimatch;
|
|
2769
|
-
}
|
|
2770
|
-
const orig = minimatch;
|
|
2771
|
-
const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
|
|
2772
|
-
return Object.assign(m, {
|
|
2773
|
-
Minimatch: class Minimatch extends orig.Minimatch {
|
|
2774
|
-
constructor(pattern, options = {}) {
|
|
2775
|
-
super(pattern, ext(def, options));
|
|
2776
|
-
}
|
|
2777
|
-
static defaults(options) {
|
|
2778
|
-
return orig.defaults(ext(def, options)).Minimatch;
|
|
2779
|
-
}
|
|
2780
|
-
},
|
|
2781
|
-
AST: class AST extends orig.AST {
|
|
2782
|
-
/* c8 ignore start */
|
|
2783
|
-
constructor(type, parent, options = {}) {
|
|
2784
|
-
super(type, parent, ext(def, options));
|
|
2785
|
-
}
|
|
2786
|
-
/* c8 ignore stop */
|
|
2787
|
-
static fromGlob(pattern, options = {}) {
|
|
2788
|
-
return orig.AST.fromGlob(pattern, ext(def, options));
|
|
2789
|
-
}
|
|
2790
|
-
},
|
|
2791
|
-
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
|
|
2792
|
-
escape: (s, options = {}) => orig.escape(s, ext(def, options)),
|
|
2793
|
-
filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
|
|
2794
|
-
defaults: (options) => orig.defaults(ext(def, options)),
|
|
2795
|
-
makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
|
|
2796
|
-
braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
|
|
2797
|
-
match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
|
|
2798
|
-
sep: orig.sep,
|
|
2799
|
-
GLOBSTAR
|
|
2800
|
-
});
|
|
2801
|
-
};
|
|
2802
|
-
minimatch.defaults = defaults;
|
|
2803
|
-
var braceExpand = (pattern, options = {}) => {
|
|
2804
|
-
assertValidPattern(pattern);
|
|
2805
|
-
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
|
|
2806
|
-
return [pattern];
|
|
2807
|
-
}
|
|
2808
|
-
return expand(pattern);
|
|
2809
|
-
};
|
|
2810
|
-
minimatch.braceExpand = braceExpand;
|
|
2811
|
-
var makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
|
|
2812
|
-
minimatch.makeRe = makeRe;
|
|
2813
|
-
var match = (list, pattern, options = {}) => {
|
|
2814
|
-
const mm = new Minimatch(pattern, options);
|
|
2815
|
-
list = list.filter((f) => mm.match(f));
|
|
2816
|
-
if (mm.options.nonull && !list.length) {
|
|
2817
|
-
list.push(pattern);
|
|
2818
|
-
}
|
|
2819
|
-
return list;
|
|
2820
|
-
};
|
|
2821
|
-
minimatch.match = match;
|
|
2822
|
-
var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
2823
|
-
var regExpEscape2 = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
2824
|
-
var Minimatch = class {
|
|
2825
|
-
options;
|
|
2826
|
-
set;
|
|
2827
|
-
pattern;
|
|
2828
|
-
windowsPathsNoEscape;
|
|
2829
|
-
nonegate;
|
|
2830
|
-
negate;
|
|
2831
|
-
comment;
|
|
2832
|
-
empty;
|
|
2833
|
-
preserveMultipleSlashes;
|
|
2834
|
-
partial;
|
|
2835
|
-
globSet;
|
|
2836
|
-
globParts;
|
|
2837
|
-
nocase;
|
|
2838
|
-
isWindows;
|
|
2839
|
-
platform;
|
|
2840
|
-
windowsNoMagicRoot;
|
|
2841
|
-
regexp;
|
|
2842
|
-
constructor(pattern, options = {}) {
|
|
2843
|
-
assertValidPattern(pattern);
|
|
2844
|
-
options = options || {};
|
|
2845
|
-
this.options = options;
|
|
2846
|
-
this.pattern = pattern;
|
|
2847
|
-
this.platform = options.platform || defaultPlatform;
|
|
2848
|
-
this.isWindows = this.platform === "win32";
|
|
2849
|
-
this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false;
|
|
2850
|
-
if (this.windowsPathsNoEscape) {
|
|
2851
|
-
this.pattern = this.pattern.replace(/\\/g, "/");
|
|
2852
|
-
}
|
|
2853
|
-
this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
|
|
2854
|
-
this.regexp = null;
|
|
2855
|
-
this.negate = false;
|
|
2856
|
-
this.nonegate = !!options.nonegate;
|
|
2857
|
-
this.comment = false;
|
|
2858
|
-
this.empty = false;
|
|
2859
|
-
this.partial = !!options.partial;
|
|
2860
|
-
this.nocase = !!this.options.nocase;
|
|
2861
|
-
this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
|
|
2862
|
-
this.globSet = [];
|
|
2863
|
-
this.globParts = [];
|
|
2864
|
-
this.set = [];
|
|
2865
|
-
this.make();
|
|
2866
|
-
}
|
|
2867
|
-
hasMagic() {
|
|
2868
|
-
if (this.options.magicalBraces && this.set.length > 1) {
|
|
2869
|
-
return true;
|
|
2870
|
-
}
|
|
2871
|
-
for (const pattern of this.set) {
|
|
2872
|
-
for (const part of pattern) {
|
|
2873
|
-
if (typeof part !== "string")
|
|
2874
|
-
return true;
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
return false;
|
|
2878
|
-
}
|
|
2879
|
-
debug(..._) {
|
|
2880
|
-
}
|
|
2881
|
-
make() {
|
|
2882
|
-
const pattern = this.pattern;
|
|
2883
|
-
const options = this.options;
|
|
2884
|
-
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
2885
|
-
this.comment = true;
|
|
2886
|
-
return;
|
|
2887
|
-
}
|
|
2888
|
-
if (!pattern) {
|
|
2889
|
-
this.empty = true;
|
|
2890
|
-
return;
|
|
2891
|
-
}
|
|
2892
|
-
this.parseNegate();
|
|
2893
|
-
this.globSet = [...new Set(this.braceExpand())];
|
|
2894
|
-
if (options.debug) {
|
|
2895
|
-
this.debug = (...args) => console.error(...args);
|
|
2896
|
-
}
|
|
2897
|
-
this.debug(this.pattern, this.globSet);
|
|
2898
|
-
const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
|
|
2899
|
-
this.globParts = this.preprocess(rawGlobParts);
|
|
2900
|
-
this.debug(this.pattern, this.globParts);
|
|
2901
|
-
let set = this.globParts.map((s, _, __) => {
|
|
2902
|
-
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
2903
|
-
const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
|
|
2904
|
-
const isDrive = /^[a-z]:/i.test(s[0]);
|
|
2905
|
-
if (isUNC) {
|
|
2906
|
-
return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))];
|
|
2907
|
-
} else if (isDrive) {
|
|
2908
|
-
return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
|
-
return s.map((ss) => this.parse(ss));
|
|
2912
|
-
});
|
|
2913
|
-
this.debug(this.pattern, set);
|
|
2914
|
-
this.set = set.filter((s) => s.indexOf(false) === -1);
|
|
2915
|
-
if (this.isWindows) {
|
|
2916
|
-
for (let i = 0; i < this.set.length; i++) {
|
|
2917
|
-
const p = this.set[i];
|
|
2918
|
-
if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
|
|
2919
|
-
p[2] = "?";
|
|
2920
|
-
}
|
|
2921
|
-
}
|
|
2922
|
-
}
|
|
2923
|
-
this.debug(this.pattern, this.set);
|
|
2924
|
-
}
|
|
2925
|
-
// various transforms to equivalent pattern sets that are
|
|
2926
|
-
// faster to process in a filesystem walk. The goal is to
|
|
2927
|
-
// eliminate what we can, and push all ** patterns as far
|
|
2928
|
-
// to the right as possible, even if it increases the number
|
|
2929
|
-
// of patterns that we have to process.
|
|
2930
|
-
preprocess(globParts) {
|
|
2931
|
-
if (this.options.noglobstar) {
|
|
2932
|
-
for (let i = 0; i < globParts.length; i++) {
|
|
2933
|
-
for (let j = 0; j < globParts[i].length; j++) {
|
|
2934
|
-
if (globParts[i][j] === "**") {
|
|
2935
|
-
globParts[i][j] = "*";
|
|
2936
|
-
}
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
}
|
|
2940
|
-
const { optimizationLevel = 1 } = this.options;
|
|
2941
|
-
if (optimizationLevel >= 2) {
|
|
2942
|
-
globParts = this.firstPhasePreProcess(globParts);
|
|
2943
|
-
globParts = this.secondPhasePreProcess(globParts);
|
|
2944
|
-
} else if (optimizationLevel >= 1) {
|
|
2945
|
-
globParts = this.levelOneOptimize(globParts);
|
|
2946
|
-
} else {
|
|
2947
|
-
globParts = this.adjascentGlobstarOptimize(globParts);
|
|
2948
|
-
}
|
|
2949
|
-
return globParts;
|
|
2950
|
-
}
|
|
2951
|
-
// just get rid of adjascent ** portions
|
|
2952
|
-
adjascentGlobstarOptimize(globParts) {
|
|
2953
|
-
return globParts.map((parts) => {
|
|
2954
|
-
let gs = -1;
|
|
2955
|
-
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
2956
|
-
let i = gs;
|
|
2957
|
-
while (parts[i + 1] === "**") {
|
|
2958
|
-
i++;
|
|
2959
|
-
}
|
|
2960
|
-
if (i !== gs) {
|
|
2961
|
-
parts.splice(gs, i - gs);
|
|
2962
|
-
}
|
|
2963
|
-
}
|
|
2964
|
-
return parts;
|
|
2965
|
-
});
|
|
2966
|
-
}
|
|
2967
|
-
// get rid of adjascent ** and resolve .. portions
|
|
2968
|
-
levelOneOptimize(globParts) {
|
|
2969
|
-
return globParts.map((parts) => {
|
|
2970
|
-
parts = parts.reduce((set, part) => {
|
|
2971
|
-
const prev = set[set.length - 1];
|
|
2972
|
-
if (part === "**" && prev === "**") {
|
|
2973
|
-
return set;
|
|
2974
|
-
}
|
|
2975
|
-
if (part === "..") {
|
|
2976
|
-
if (prev && prev !== ".." && prev !== "." && prev !== "**") {
|
|
2977
|
-
set.pop();
|
|
2978
|
-
return set;
|
|
2979
|
-
}
|
|
2980
|
-
}
|
|
2981
|
-
set.push(part);
|
|
2982
|
-
return set;
|
|
2983
|
-
}, []);
|
|
2984
|
-
return parts.length === 0 ? [""] : parts;
|
|
2985
|
-
});
|
|
2986
|
-
}
|
|
2987
|
-
levelTwoFileOptimize(parts) {
|
|
2988
|
-
if (!Array.isArray(parts)) {
|
|
2989
|
-
parts = this.slashSplit(parts);
|
|
2990
|
-
}
|
|
2991
|
-
let didSomething = false;
|
|
2992
|
-
do {
|
|
2993
|
-
didSomething = false;
|
|
2994
|
-
if (!this.preserveMultipleSlashes) {
|
|
2995
|
-
for (let i = 1; i < parts.length - 1; i++) {
|
|
2996
|
-
const p = parts[i];
|
|
2997
|
-
if (i === 1 && p === "" && parts[0] === "")
|
|
2998
|
-
continue;
|
|
2999
|
-
if (p === "." || p === "") {
|
|
3000
|
-
didSomething = true;
|
|
3001
|
-
parts.splice(i, 1);
|
|
3002
|
-
i--;
|
|
3003
|
-
}
|
|
3004
|
-
}
|
|
3005
|
-
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
3006
|
-
didSomething = true;
|
|
3007
|
-
parts.pop();
|
|
3008
|
-
}
|
|
3009
|
-
}
|
|
3010
|
-
let dd = 0;
|
|
3011
|
-
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
3012
|
-
const p = parts[dd - 1];
|
|
3013
|
-
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
3014
|
-
didSomething = true;
|
|
3015
|
-
parts.splice(dd - 1, 2);
|
|
3016
|
-
dd -= 2;
|
|
3017
|
-
}
|
|
3018
|
-
}
|
|
3019
|
-
} while (didSomething);
|
|
3020
|
-
return parts.length === 0 ? [""] : parts;
|
|
3021
|
-
}
|
|
3022
|
-
// First phase: single-pattern processing
|
|
3023
|
-
// <pre> is 1 or more portions
|
|
3024
|
-
// <rest> is 1 or more portions
|
|
3025
|
-
// <p> is any portion other than ., .., '', or **
|
|
3026
|
-
// <e> is . or ''
|
|
3027
|
-
//
|
|
3028
|
-
// **/.. is *brutal* for filesystem walking performance, because
|
|
3029
|
-
// it effectively resets the recursive walk each time it occurs,
|
|
3030
|
-
// and ** cannot be reduced out by a .. pattern part like a regexp
|
|
3031
|
-
// or most strings (other than .., ., and '') can be.
|
|
3032
|
-
//
|
|
3033
|
-
// <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
|
|
3034
|
-
// <pre>/<e>/<rest> -> <pre>/<rest>
|
|
3035
|
-
// <pre>/<p>/../<rest> -> <pre>/<rest>
|
|
3036
|
-
// **/**/<rest> -> **/<rest>
|
|
3037
|
-
//
|
|
3038
|
-
// **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
|
|
3039
|
-
// this WOULD be allowed if ** did follow symlinks, or * didn't
|
|
3040
|
-
firstPhasePreProcess(globParts) {
|
|
3041
|
-
let didSomething = false;
|
|
3042
|
-
do {
|
|
3043
|
-
didSomething = false;
|
|
3044
|
-
for (let parts of globParts) {
|
|
3045
|
-
let gs = -1;
|
|
3046
|
-
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
3047
|
-
let gss = gs;
|
|
3048
|
-
while (parts[gss + 1] === "**") {
|
|
3049
|
-
gss++;
|
|
3050
|
-
}
|
|
3051
|
-
if (gss > gs) {
|
|
3052
|
-
parts.splice(gs + 1, gss - gs);
|
|
3053
|
-
}
|
|
3054
|
-
let next = parts[gs + 1];
|
|
3055
|
-
const p = parts[gs + 2];
|
|
3056
|
-
const p2 = parts[gs + 3];
|
|
3057
|
-
if (next !== "..")
|
|
3058
|
-
continue;
|
|
3059
|
-
if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
|
|
3060
|
-
continue;
|
|
3061
|
-
}
|
|
3062
|
-
didSomething = true;
|
|
3063
|
-
parts.splice(gs, 1);
|
|
3064
|
-
const other = parts.slice(0);
|
|
3065
|
-
other[gs] = "**";
|
|
3066
|
-
globParts.push(other);
|
|
3067
|
-
gs--;
|
|
3068
|
-
}
|
|
3069
|
-
if (!this.preserveMultipleSlashes) {
|
|
3070
|
-
for (let i = 1; i < parts.length - 1; i++) {
|
|
3071
|
-
const p = parts[i];
|
|
3072
|
-
if (i === 1 && p === "" && parts[0] === "")
|
|
3073
|
-
continue;
|
|
3074
|
-
if (p === "." || p === "") {
|
|
3075
|
-
didSomething = true;
|
|
3076
|
-
parts.splice(i, 1);
|
|
3077
|
-
i--;
|
|
3078
|
-
}
|
|
3079
|
-
}
|
|
3080
|
-
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
3081
|
-
didSomething = true;
|
|
3082
|
-
parts.pop();
|
|
3083
|
-
}
|
|
3084
|
-
}
|
|
3085
|
-
let dd = 0;
|
|
3086
|
-
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
3087
|
-
const p = parts[dd - 1];
|
|
3088
|
-
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
3089
|
-
didSomething = true;
|
|
3090
|
-
const needDot = dd === 1 && parts[dd + 1] === "**";
|
|
3091
|
-
const splin = needDot ? ["."] : [];
|
|
3092
|
-
parts.splice(dd - 1, 2, ...splin);
|
|
3093
|
-
if (parts.length === 0)
|
|
3094
|
-
parts.push("");
|
|
3095
|
-
dd -= 2;
|
|
3096
|
-
}
|
|
3097
|
-
}
|
|
3098
|
-
}
|
|
3099
|
-
} while (didSomething);
|
|
3100
|
-
return globParts;
|
|
3101
|
-
}
|
|
3102
|
-
// second phase: multi-pattern dedupes
|
|
3103
|
-
// {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
|
|
3104
|
-
// {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
|
|
3105
|
-
// {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
|
|
3106
|
-
//
|
|
3107
|
-
// {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
|
|
3108
|
-
// ^-- not valid because ** doens't follow symlinks
|
|
3109
|
-
secondPhasePreProcess(globParts) {
|
|
3110
|
-
for (let i = 0; i < globParts.length - 1; i++) {
|
|
3111
|
-
for (let j = i + 1; j < globParts.length; j++) {
|
|
3112
|
-
const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
|
|
3113
|
-
if (matched) {
|
|
3114
|
-
globParts[i] = [];
|
|
3115
|
-
globParts[j] = matched;
|
|
3116
|
-
break;
|
|
3117
|
-
}
|
|
3118
|
-
}
|
|
3119
|
-
}
|
|
3120
|
-
return globParts.filter((gs) => gs.length);
|
|
3121
|
-
}
|
|
3122
|
-
partsMatch(a, b, emptyGSMatch = false) {
|
|
3123
|
-
let ai = 0;
|
|
3124
|
-
let bi = 0;
|
|
3125
|
-
let result = [];
|
|
3126
|
-
let which = "";
|
|
3127
|
-
while (ai < a.length && bi < b.length) {
|
|
3128
|
-
if (a[ai] === b[bi]) {
|
|
3129
|
-
result.push(which === "b" ? b[bi] : a[ai]);
|
|
3130
|
-
ai++;
|
|
3131
|
-
bi++;
|
|
3132
|
-
} else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
|
|
3133
|
-
result.push(a[ai]);
|
|
3134
|
-
ai++;
|
|
3135
|
-
} else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
|
|
3136
|
-
result.push(b[bi]);
|
|
3137
|
-
bi++;
|
|
3138
|
-
} else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
|
|
3139
|
-
if (which === "b")
|
|
3140
|
-
return false;
|
|
3141
|
-
which = "a";
|
|
3142
|
-
result.push(a[ai]);
|
|
3143
|
-
ai++;
|
|
3144
|
-
bi++;
|
|
3145
|
-
} else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
|
|
3146
|
-
if (which === "a")
|
|
3147
|
-
return false;
|
|
3148
|
-
which = "b";
|
|
3149
|
-
result.push(b[bi]);
|
|
3150
|
-
ai++;
|
|
3151
|
-
bi++;
|
|
3152
|
-
} else {
|
|
3153
|
-
return false;
|
|
3154
|
-
}
|
|
3155
|
-
}
|
|
3156
|
-
return a.length === b.length && result;
|
|
3157
|
-
}
|
|
3158
|
-
parseNegate() {
|
|
3159
|
-
if (this.nonegate)
|
|
3160
|
-
return;
|
|
3161
|
-
const pattern = this.pattern;
|
|
3162
|
-
let negate = false;
|
|
3163
|
-
let negateOffset = 0;
|
|
3164
|
-
for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
|
|
3165
|
-
negate = !negate;
|
|
3166
|
-
negateOffset++;
|
|
3167
|
-
}
|
|
3168
|
-
if (negateOffset)
|
|
3169
|
-
this.pattern = pattern.slice(negateOffset);
|
|
3170
|
-
this.negate = negate;
|
|
3171
|
-
}
|
|
3172
|
-
// set partial to true to test if, for example,
|
|
3173
|
-
// "/a/b" matches the start of "/*/b/*/d"
|
|
3174
|
-
// Partial means, if you run out of file before you run
|
|
3175
|
-
// out of pattern, then that's fine, as long as all
|
|
3176
|
-
// the parts match.
|
|
3177
|
-
matchOne(file, pattern, partial = false) {
|
|
3178
|
-
const options = this.options;
|
|
3179
|
-
if (this.isWindows) {
|
|
3180
|
-
const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
|
|
3181
|
-
const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
|
|
3182
|
-
const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
|
|
3183
|
-
const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
|
|
3184
|
-
const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0;
|
|
3185
|
-
const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0;
|
|
3186
|
-
if (typeof fdi === "number" && typeof pdi === "number") {
|
|
3187
|
-
const [fd, pd] = [file[fdi], pattern[pdi]];
|
|
3188
|
-
if (fd.toLowerCase() === pd.toLowerCase()) {
|
|
3189
|
-
pattern[pdi] = fd;
|
|
3190
|
-
if (pdi > fdi) {
|
|
3191
|
-
pattern = pattern.slice(pdi);
|
|
3192
|
-
} else if (fdi > pdi) {
|
|
3193
|
-
file = file.slice(fdi);
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
}
|
|
3197
|
-
}
|
|
3198
|
-
const { optimizationLevel = 1 } = this.options;
|
|
3199
|
-
if (optimizationLevel >= 2) {
|
|
3200
|
-
file = this.levelTwoFileOptimize(file);
|
|
3201
|
-
}
|
|
3202
|
-
this.debug("matchOne", this, { file, pattern });
|
|
3203
|
-
this.debug("matchOne", file.length, pattern.length);
|
|
3204
|
-
for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
|
|
3205
|
-
this.debug("matchOne loop");
|
|
3206
|
-
var p = pattern[pi];
|
|
3207
|
-
var f = file[fi];
|
|
3208
|
-
this.debug(pattern, p, f);
|
|
3209
|
-
if (p === false) {
|
|
3210
|
-
return false;
|
|
3211
|
-
}
|
|
3212
|
-
if (p === GLOBSTAR) {
|
|
3213
|
-
this.debug("GLOBSTAR", [pattern, p, f]);
|
|
3214
|
-
var fr = fi;
|
|
3215
|
-
var pr = pi + 1;
|
|
3216
|
-
if (pr === pl) {
|
|
3217
|
-
this.debug("** at the end");
|
|
3218
|
-
for (; fi < fl; fi++) {
|
|
3219
|
-
if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".")
|
|
3220
|
-
return false;
|
|
3221
|
-
}
|
|
3222
|
-
return true;
|
|
3223
|
-
}
|
|
3224
|
-
while (fr < fl) {
|
|
3225
|
-
var swallowee = file[fr];
|
|
3226
|
-
this.debug("\nglobstar while", file, fr, pattern, pr, swallowee);
|
|
3227
|
-
if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
|
|
3228
|
-
this.debug("globstar found match!", fr, fl, swallowee);
|
|
3229
|
-
return true;
|
|
3230
|
-
} else {
|
|
3231
|
-
if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
|
|
3232
|
-
this.debug("dot detected!", file, fr, pattern, pr);
|
|
3233
|
-
break;
|
|
3234
|
-
}
|
|
3235
|
-
this.debug("globstar swallow a segment, and continue");
|
|
3236
|
-
fr++;
|
|
3237
|
-
}
|
|
3238
|
-
}
|
|
3239
|
-
if (partial) {
|
|
3240
|
-
this.debug("\n>>> no match, partial?", file, fr, pattern, pr);
|
|
3241
|
-
if (fr === fl) {
|
|
3242
|
-
return true;
|
|
3243
|
-
}
|
|
3244
|
-
}
|
|
3245
|
-
return false;
|
|
3246
|
-
}
|
|
3247
|
-
let hit;
|
|
3248
|
-
if (typeof p === "string") {
|
|
3249
|
-
hit = f === p;
|
|
3250
|
-
this.debug("string match", p, f, hit);
|
|
3251
|
-
} else {
|
|
3252
|
-
hit = p.test(f);
|
|
3253
|
-
this.debug("pattern match", p, f, hit);
|
|
3254
|
-
}
|
|
3255
|
-
if (!hit)
|
|
3256
|
-
return false;
|
|
3257
|
-
}
|
|
3258
|
-
if (fi === fl && pi === pl) {
|
|
3259
|
-
return true;
|
|
3260
|
-
} else if (fi === fl) {
|
|
3261
|
-
return partial;
|
|
3262
|
-
} else if (pi === pl) {
|
|
3263
|
-
return fi === fl - 1 && file[fi] === "";
|
|
3264
|
-
} else {
|
|
3265
|
-
throw new Error("wtf?");
|
|
3266
|
-
}
|
|
3267
|
-
}
|
|
3268
|
-
braceExpand() {
|
|
3269
|
-
return braceExpand(this.pattern, this.options);
|
|
3270
|
-
}
|
|
3271
|
-
parse(pattern) {
|
|
3272
|
-
assertValidPattern(pattern);
|
|
3273
|
-
const options = this.options;
|
|
3274
|
-
if (pattern === "**")
|
|
3275
|
-
return GLOBSTAR;
|
|
3276
|
-
if (pattern === "")
|
|
3277
|
-
return "";
|
|
3278
|
-
let m;
|
|
3279
|
-
let fastTest = null;
|
|
3280
|
-
if (m = pattern.match(starRE)) {
|
|
3281
|
-
fastTest = options.dot ? starTestDot : starTest;
|
|
3282
|
-
} else if (m = pattern.match(starDotExtRE)) {
|
|
3283
|
-
fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
|
|
3284
|
-
} else if (m = pattern.match(qmarksRE)) {
|
|
3285
|
-
fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
|
|
3286
|
-
} else if (m = pattern.match(starDotStarRE)) {
|
|
3287
|
-
fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
|
|
3288
|
-
} else if (m = pattern.match(dotStarRE)) {
|
|
3289
|
-
fastTest = dotStarTest;
|
|
3290
|
-
}
|
|
3291
|
-
const re = AST.fromGlob(pattern, this.options).toMMPattern();
|
|
3292
|
-
if (fastTest && typeof re === "object") {
|
|
3293
|
-
Reflect.defineProperty(re, "test", { value: fastTest });
|
|
3294
|
-
}
|
|
3295
|
-
return re;
|
|
3296
|
-
}
|
|
3297
|
-
makeRe() {
|
|
3298
|
-
if (this.regexp || this.regexp === false)
|
|
3299
|
-
return this.regexp;
|
|
3300
|
-
const set = this.set;
|
|
3301
|
-
if (!set.length) {
|
|
3302
|
-
this.regexp = false;
|
|
3303
|
-
return this.regexp;
|
|
3304
|
-
}
|
|
3305
|
-
const options = this.options;
|
|
3306
|
-
const twoStar = options.noglobstar ? star2 : options.dot ? twoStarDot : twoStarNoDot;
|
|
3307
|
-
const flags = new Set(options.nocase ? ["i"] : []);
|
|
3308
|
-
let re = set.map((pattern) => {
|
|
3309
|
-
const pp = pattern.map((p) => {
|
|
3310
|
-
if (p instanceof RegExp) {
|
|
3311
|
-
for (const f of p.flags.split(""))
|
|
3312
|
-
flags.add(f);
|
|
3313
|
-
}
|
|
3314
|
-
return typeof p === "string" ? regExpEscape2(p) : p === GLOBSTAR ? GLOBSTAR : p._src;
|
|
3315
|
-
});
|
|
3316
|
-
pp.forEach((p, i) => {
|
|
3317
|
-
const next = pp[i + 1];
|
|
3318
|
-
const prev = pp[i - 1];
|
|
3319
|
-
if (p !== GLOBSTAR || prev === GLOBSTAR) {
|
|
3320
|
-
return;
|
|
3321
|
-
}
|
|
3322
|
-
if (prev === void 0) {
|
|
3323
|
-
if (next !== void 0 && next !== GLOBSTAR) {
|
|
3324
|
-
pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
|
|
3325
|
-
} else {
|
|
3326
|
-
pp[i] = twoStar;
|
|
3327
|
-
}
|
|
3328
|
-
} else if (next === void 0) {
|
|
3329
|
-
pp[i - 1] = prev + "(?:\\/|" + twoStar + ")?";
|
|
3330
|
-
} else if (next !== GLOBSTAR) {
|
|
3331
|
-
pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
|
|
3332
|
-
pp[i + 1] = GLOBSTAR;
|
|
3333
|
-
}
|
|
3334
|
-
});
|
|
3335
|
-
return pp.filter((p) => p !== GLOBSTAR).join("/");
|
|
3336
|
-
}).join("|");
|
|
3337
|
-
const [open, close] = set.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
3338
|
-
re = "^" + open + re + close + "$";
|
|
3339
|
-
if (this.negate)
|
|
3340
|
-
re = "^(?!" + re + ").+$";
|
|
3341
|
-
try {
|
|
3342
|
-
this.regexp = new RegExp(re, [...flags].join(""));
|
|
3343
|
-
} catch (ex) {
|
|
3344
|
-
this.regexp = false;
|
|
3345
|
-
}
|
|
3346
|
-
return this.regexp;
|
|
3347
|
-
}
|
|
3348
|
-
slashSplit(p) {
|
|
3349
|
-
if (this.preserveMultipleSlashes) {
|
|
3350
|
-
return p.split("/");
|
|
3351
|
-
} else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
|
|
3352
|
-
return ["", ...p.split(/\/+/)];
|
|
3353
|
-
} else {
|
|
3354
|
-
return p.split(/\/+/);
|
|
3355
|
-
}
|
|
3356
|
-
}
|
|
3357
|
-
match(f, partial = this.partial) {
|
|
3358
|
-
this.debug("match", f, this.pattern);
|
|
3359
|
-
if (this.comment) {
|
|
3360
|
-
return false;
|
|
3361
|
-
}
|
|
3362
|
-
if (this.empty) {
|
|
3363
|
-
return f === "";
|
|
3364
|
-
}
|
|
3365
|
-
if (f === "/" && partial) {
|
|
3366
|
-
return true;
|
|
3367
|
-
}
|
|
3368
|
-
const options = this.options;
|
|
3369
|
-
if (this.isWindows) {
|
|
3370
|
-
f = f.split("\\").join("/");
|
|
3371
|
-
}
|
|
3372
|
-
const ff = this.slashSplit(f);
|
|
3373
|
-
this.debug(this.pattern, "split", ff);
|
|
3374
|
-
const set = this.set;
|
|
3375
|
-
this.debug(this.pattern, "set", set);
|
|
3376
|
-
let filename = ff[ff.length - 1];
|
|
3377
|
-
if (!filename) {
|
|
3378
|
-
for (let i = ff.length - 2; !filename && i >= 0; i--) {
|
|
3379
|
-
filename = ff[i];
|
|
3380
|
-
}
|
|
3381
|
-
}
|
|
3382
|
-
for (let i = 0; i < set.length; i++) {
|
|
3383
|
-
const pattern = set[i];
|
|
3384
|
-
let file = ff;
|
|
3385
|
-
if (options.matchBase && pattern.length === 1) {
|
|
3386
|
-
file = [filename];
|
|
3387
|
-
}
|
|
3388
|
-
const hit = this.matchOne(file, pattern, partial);
|
|
3389
|
-
if (hit) {
|
|
3390
|
-
if (options.flipNegate) {
|
|
3391
|
-
return true;
|
|
3392
|
-
}
|
|
3393
|
-
return !this.negate;
|
|
3394
|
-
}
|
|
3395
|
-
}
|
|
3396
|
-
if (options.flipNegate) {
|
|
3397
|
-
return false;
|
|
3398
|
-
}
|
|
3399
|
-
return this.negate;
|
|
3400
|
-
}
|
|
3401
|
-
static defaults(def) {
|
|
3402
|
-
return minimatch.defaults(def).Minimatch;
|
|
3403
|
-
}
|
|
3404
|
-
};
|
|
3405
|
-
minimatch.AST = AST;
|
|
3406
|
-
minimatch.Minimatch = Minimatch;
|
|
3407
|
-
minimatch.escape = escape;
|
|
3408
|
-
minimatch.unescape = unescape;
|
|
3409
|
-
|
|
3410
|
-
// ../agent/dist/chunk-64ESYBKE.js
|
|
3411
|
-
import fs4 from "fs/promises";
|
|
3412
|
-
var sep2 = "/";
|
|
3413
|
-
function join(...parts) {
|
|
3414
|
-
const joined = parts.filter(Boolean).join("/");
|
|
3415
|
-
return normalize(joined);
|
|
3416
|
-
}
|
|
3417
|
-
function dirname(p) {
|
|
3418
|
-
if (!p) return ".";
|
|
3419
|
-
const i = p.lastIndexOf("/");
|
|
3420
|
-
if (i < 0) return ".";
|
|
3421
|
-
if (i === 0) return "/";
|
|
3422
|
-
return p.slice(0, i);
|
|
3423
|
-
}
|
|
3424
|
-
function basename(p, ext2) {
|
|
3425
|
-
if (p.endsWith("/")) p = p.slice(0, -1);
|
|
3426
|
-
const i = p.lastIndexOf("/");
|
|
3427
|
-
const base = i < 0 ? p : p.slice(i + 1);
|
|
3428
|
-
if (ext2 && base.endsWith(ext2)) return base.slice(0, -ext2.length);
|
|
3429
|
-
return base;
|
|
3430
|
-
}
|
|
3431
|
-
function extname(p) {
|
|
3432
|
-
const base = basename(p);
|
|
3433
|
-
const i = base.lastIndexOf(".");
|
|
3434
|
-
if (i <= 0) return "";
|
|
3435
|
-
return base.slice(i);
|
|
3436
|
-
}
|
|
3437
|
-
function isAbsolute(p) {
|
|
3438
|
-
return p.startsWith("/");
|
|
3439
|
-
}
|
|
3440
|
-
function normalize(p) {
|
|
3441
|
-
if (!p) return ".";
|
|
3442
|
-
const isAbs = p.startsWith("/");
|
|
3443
|
-
const segments = p.split("/");
|
|
3444
|
-
const out = [];
|
|
3445
|
-
for (const s of segments) {
|
|
3446
|
-
if (s === "" || s === ".") continue;
|
|
3447
|
-
if (s === "..") {
|
|
3448
|
-
if (out.length > 0 && out[out.length - 1] !== "..") {
|
|
3449
|
-
out.pop();
|
|
3450
|
-
} else if (!isAbs) {
|
|
3451
|
-
out.push("..");
|
|
3452
|
-
}
|
|
3453
|
-
} else {
|
|
3454
|
-
out.push(s);
|
|
3455
|
-
}
|
|
3456
|
-
}
|
|
3457
|
-
const result = out.join("/");
|
|
3458
|
-
if (isAbs) return "/" + result;
|
|
3459
|
-
return result || ".";
|
|
3460
|
-
}
|
|
3461
|
-
function relative(from, to) {
|
|
3462
|
-
from = normalize(from);
|
|
3463
|
-
to = normalize(to);
|
|
3464
|
-
if (from === to) return "";
|
|
3465
|
-
const fromParts = from.split("/").filter(Boolean);
|
|
3466
|
-
const toParts = to.split("/").filter(Boolean);
|
|
3467
|
-
let common = 0;
|
|
3468
|
-
while (common < fromParts.length && common < toParts.length && fromParts[common] === toParts[common]) {
|
|
3469
|
-
common++;
|
|
3470
|
-
}
|
|
3471
|
-
const ups = fromParts.length - common;
|
|
3472
|
-
const downs = toParts.slice(common);
|
|
3473
|
-
const parts = [...Array(ups).fill(".."), ...downs];
|
|
3474
|
-
return parts.join("/") || ".";
|
|
3475
|
-
}
|
|
3476
|
-
function resolve(...parts) {
|
|
3477
|
-
let resolved = "";
|
|
3478
|
-
for (let i = parts.length - 1; i >= 0; i--) {
|
|
3479
|
-
const part = parts[i];
|
|
3480
|
-
if (!part) continue;
|
|
3481
|
-
resolved = resolved ? part + "/" + resolved : part;
|
|
3482
|
-
if (isAbsolute(part)) break;
|
|
3483
|
-
}
|
|
3484
|
-
return normalize(resolved);
|
|
3485
|
-
}
|
|
3486
|
-
var _env = {};
|
|
3487
|
-
function truthy(key) {
|
|
3488
|
-
const value = _env[key]?.toLowerCase();
|
|
3489
|
-
return value === "true" || value === "1";
|
|
3490
|
-
}
|
|
3491
|
-
function falsy(key) {
|
|
3492
|
-
const value = _env[key]?.toLowerCase();
|
|
3493
|
-
return value === "false" || value === "0";
|
|
3494
|
-
}
|
|
3495
|
-
function number(key) {
|
|
3496
|
-
const value = _env[key];
|
|
3497
|
-
if (!value) return void 0;
|
|
3498
|
-
const parsed = Number(value);
|
|
3499
|
-
return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
3500
|
-
}
|
|
3501
|
-
var Flag;
|
|
3502
|
-
((Flag2) => {
|
|
3503
|
-
function init(env) {
|
|
3504
|
-
_env = env;
|
|
3505
|
-
Flag2.OPENCODE_AUTO_SHARE = truthy("OPENCODE_AUTO_SHARE");
|
|
3506
|
-
Flag2.OPENCODE_GIT_BASH_PATH = _env["OPENCODE_GIT_BASH_PATH"];
|
|
3507
|
-
Flag2.OPENCODE_CONFIG = _env["OPENCODE_CONFIG"];
|
|
3508
|
-
Flag2.OPENCODE_CONFIG_CONTENT = _env["OPENCODE_CONFIG_CONTENT"];
|
|
3509
|
-
Flag2.OPENCODE_DISABLE_AUTOUPDATE = truthy("OPENCODE_DISABLE_AUTOUPDATE");
|
|
3510
|
-
Flag2.OPENCODE_DISABLE_PRUNE = truthy("OPENCODE_DISABLE_PRUNE");
|
|
3511
|
-
Flag2.OPENCODE_DISABLE_TERMINAL_TITLE = truthy("OPENCODE_DISABLE_TERMINAL_TITLE");
|
|
3512
|
-
Flag2.OPENCODE_PERMISSION = _env["OPENCODE_PERMISSION"];
|
|
3513
|
-
Flag2.OPENCODE_DISABLE_DEFAULT_PLUGINS = truthy("OPENCODE_DISABLE_DEFAULT_PLUGINS");
|
|
3514
|
-
Flag2.OPENCODE_DISABLE_LSP_DOWNLOAD = truthy("OPENCODE_DISABLE_LSP_DOWNLOAD");
|
|
3515
|
-
Flag2.OPENCODE_ENABLE_EXPERIMENTAL_MODELS = truthy("OPENCODE_ENABLE_EXPERIMENTAL_MODELS");
|
|
3516
|
-
Flag2.OPENCODE_DISABLE_AUTOCOMPACT = truthy("OPENCODE_DISABLE_AUTOCOMPACT");
|
|
3517
|
-
Flag2.OPENCODE_DISABLE_MODELS_FETCH = truthy("OPENCODE_DISABLE_MODELS_FETCH");
|
|
3518
|
-
Flag2.OPENCODE_DISABLE_CLAUDE_CODE = truthy("OPENCODE_DISABLE_CLAUDE_CODE");
|
|
3519
|
-
Flag2.OPENCODE_DISABLE_CLAUDE_CODE_PROMPT = Flag2.OPENCODE_DISABLE_CLAUDE_CODE || truthy("OPENCODE_DISABLE_CLAUDE_CODE_PROMPT");
|
|
3520
|
-
Flag2.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS = Flag2.OPENCODE_DISABLE_CLAUDE_CODE || truthy("OPENCODE_DISABLE_CLAUDE_CODE_SKILLS");
|
|
3521
|
-
Flag2.OPENCODE_DISABLE_EXTERNAL_SKILLS = Flag2.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS || truthy("OPENCODE_DISABLE_EXTERNAL_SKILLS");
|
|
3522
|
-
Flag2.OPENCODE_FAKE_VCS = _env["OPENCODE_FAKE_VCS"];
|
|
3523
|
-
Flag2.OPENCODE_SERVER_PASSWORD = _env["OPENCODE_SERVER_PASSWORD"];
|
|
3524
|
-
Flag2.OPENCODE_SERVER_USERNAME = _env["OPENCODE_SERVER_USERNAME"];
|
|
3525
|
-
Flag2.OPENCODE_ENABLE_QUESTION_TOOL = truthy("OPENCODE_ENABLE_QUESTION_TOOL");
|
|
3526
|
-
Flag2.OPENCODE_EXPERIMENTAL = truthy("OPENCODE_EXPERIMENTAL");
|
|
3527
|
-
Flag2.OPENCODE_EXPERIMENTAL_FILEWATCHER = truthy("OPENCODE_EXPERIMENTAL_FILEWATCHER");
|
|
3528
|
-
Flag2.OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER = truthy("OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER");
|
|
3529
|
-
Flag2.OPENCODE_EXPERIMENTAL_ICON_DISCOVERY = Flag2.OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_ICON_DISCOVERY");
|
|
3530
|
-
Flag2.OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT = (() => {
|
|
3531
|
-
const copy = _env["OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT"];
|
|
3532
|
-
return copy === void 0 ? false : truthy("OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT");
|
|
3533
|
-
})();
|
|
3534
|
-
Flag2.OPENCODE_ENABLE_EXA = truthy("OPENCODE_ENABLE_EXA") || Flag2.OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_EXA");
|
|
3535
|
-
Flag2.OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS = number("OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS");
|
|
3536
|
-
Flag2.OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX = number("OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX");
|
|
3537
|
-
Flag2.OPENCODE_EXPERIMENTAL_OXFMT = Flag2.OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_OXFMT");
|
|
3538
|
-
Flag2.OPENCODE_EXPERIMENTAL_LSP_TY = truthy("OPENCODE_EXPERIMENTAL_LSP_TY");
|
|
3539
|
-
Flag2.OPENCODE_EXPERIMENTAL_LSP_TOOL = Flag2.OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_LSP_TOOL");
|
|
3540
|
-
Flag2.OPENCODE_DISABLE_FILETIME_CHECK = truthy("OPENCODE_DISABLE_FILETIME_CHECK");
|
|
3541
|
-
Flag2.OPENCODE_EXPERIMENTAL_PLAN_MODE = Flag2.OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_PLAN_MODE");
|
|
3542
|
-
Flag2.OPENCODE_EXPERIMENTAL_WORKSPACES = Flag2.OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_WORKSPACES");
|
|
3543
|
-
Flag2.OPENCODE_EXPERIMENTAL_MARKDOWN = !falsy("OPENCODE_EXPERIMENTAL_MARKDOWN");
|
|
3544
|
-
Flag2.OPENCODE_MODELS_URL = _env["OPENCODE_MODELS_URL"];
|
|
3545
|
-
Flag2.OPENCODE_MODELS_PATH = _env["OPENCODE_MODELS_PATH"];
|
|
3546
|
-
Flag2.OPENCODE_DISABLE_CHANNEL_DB = truthy("OPENCODE_DISABLE_CHANNEL_DB");
|
|
3547
|
-
Flag2.OPENCODE_SKIP_MIGRATIONS = truthy("OPENCODE_SKIP_MIGRATIONS");
|
|
3548
|
-
Flag2.OPENCODE_STRICT_CONFIG_DEPS = truthy("OPENCODE_STRICT_CONFIG_DEPS");
|
|
3549
|
-
}
|
|
3550
|
-
Flag2.init = init;
|
|
3551
|
-
Flag2.OPENCODE_AUTO_SHARE = false;
|
|
3552
|
-
Flag2.OPENCODE_DISABLE_AUTOUPDATE = false;
|
|
3553
|
-
Flag2.OPENCODE_DISABLE_PRUNE = false;
|
|
3554
|
-
Flag2.OPENCODE_DISABLE_TERMINAL_TITLE = false;
|
|
3555
|
-
Flag2.OPENCODE_DISABLE_DEFAULT_PLUGINS = false;
|
|
3556
|
-
Flag2.OPENCODE_DISABLE_LSP_DOWNLOAD = false;
|
|
3557
|
-
Flag2.OPENCODE_ENABLE_EXPERIMENTAL_MODELS = false;
|
|
3558
|
-
Flag2.OPENCODE_DISABLE_AUTOCOMPACT = false;
|
|
3559
|
-
Flag2.OPENCODE_DISABLE_MODELS_FETCH = false;
|
|
3560
|
-
Flag2.OPENCODE_DISABLE_CLAUDE_CODE = false;
|
|
3561
|
-
Flag2.OPENCODE_DISABLE_CLAUDE_CODE_PROMPT = false;
|
|
3562
|
-
Flag2.OPENCODE_DISABLE_CLAUDE_CODE_SKILLS = false;
|
|
3563
|
-
Flag2.OPENCODE_DISABLE_EXTERNAL_SKILLS = false;
|
|
3564
|
-
Flag2.OPENCODE_ENABLE_QUESTION_TOOL = false;
|
|
3565
|
-
Flag2.OPENCODE_EXPERIMENTAL = false;
|
|
3566
|
-
Flag2.OPENCODE_EXPERIMENTAL_FILEWATCHER = false;
|
|
3567
|
-
Flag2.OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER = false;
|
|
3568
|
-
Flag2.OPENCODE_EXPERIMENTAL_ICON_DISCOVERY = false;
|
|
3569
|
-
Flag2.OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT = false;
|
|
3570
|
-
Flag2.OPENCODE_ENABLE_EXA = false;
|
|
3571
|
-
Flag2.OPENCODE_EXPERIMENTAL_OXFMT = false;
|
|
3572
|
-
Flag2.OPENCODE_EXPERIMENTAL_LSP_TY = false;
|
|
3573
|
-
Flag2.OPENCODE_EXPERIMENTAL_LSP_TOOL = false;
|
|
3574
|
-
Flag2.OPENCODE_DISABLE_FILETIME_CHECK = false;
|
|
3575
|
-
Flag2.OPENCODE_EXPERIMENTAL_PLAN_MODE = false;
|
|
3576
|
-
Flag2.OPENCODE_EXPERIMENTAL_WORKSPACES = false;
|
|
3577
|
-
Flag2.OPENCODE_EXPERIMENTAL_MARKDOWN = true;
|
|
3578
|
-
Flag2.OPENCODE_DISABLE_CHANNEL_DB = false;
|
|
3579
|
-
Flag2.OPENCODE_SKIP_MIGRATIONS = false;
|
|
3580
|
-
Flag2.OPENCODE_STRICT_CONFIG_DEPS = false;
|
|
3581
|
-
})(Flag || (Flag = {}));
|
|
3582
|
-
Object.defineProperty(Flag, "OPENCODE_DISABLE_PROJECT_CONFIG", {
|
|
3583
|
-
get() {
|
|
3584
|
-
return truthy("OPENCODE_DISABLE_PROJECT_CONFIG");
|
|
3585
|
-
},
|
|
3586
|
-
enumerable: true,
|
|
3587
|
-
configurable: false
|
|
3588
|
-
});
|
|
3589
|
-
Object.defineProperty(Flag, "OPENCODE_TUI_CONFIG", {
|
|
3590
|
-
get() {
|
|
3591
|
-
return _env["OPENCODE_TUI_CONFIG"];
|
|
3592
|
-
},
|
|
3593
|
-
enumerable: true,
|
|
3594
|
-
configurable: false
|
|
3595
|
-
});
|
|
3596
|
-
Object.defineProperty(Flag, "OPENCODE_CONFIG_DIR", {
|
|
3597
|
-
get() {
|
|
3598
|
-
return _env["OPENCODE_CONFIG_DIR"];
|
|
3599
|
-
},
|
|
3600
|
-
enumerable: true,
|
|
3601
|
-
configurable: false
|
|
3602
|
-
});
|
|
3603
|
-
Object.defineProperty(Flag, "OPENCODE_CLIENT", {
|
|
3604
|
-
get() {
|
|
3605
|
-
return _env["OPENCODE_CLIENT"] ?? "cli";
|
|
3606
|
-
},
|
|
3607
|
-
enumerable: true,
|
|
3608
|
-
configurable: false
|
|
3609
|
-
});
|
|
3610
|
-
var Glob;
|
|
3611
|
-
((Glob2) => {
|
|
3612
|
-
async function scan(context, pattern, options = {}) {
|
|
3613
|
-
return context.fs.glob(pattern, {
|
|
3614
|
-
cwd: options.cwd,
|
|
3615
|
-
absolute: options.absolute,
|
|
3616
|
-
dot: options.dot,
|
|
3617
|
-
follow: options.symlink ?? false,
|
|
3618
|
-
nodir: options.include !== "all"
|
|
3619
|
-
});
|
|
3620
|
-
}
|
|
3621
|
-
Glob2.scan = scan;
|
|
3622
|
-
function match2(pattern, filepath) {
|
|
3623
|
-
return minimatch(filepath, pattern, { dot: true });
|
|
3624
|
-
}
|
|
3625
|
-
Glob2.match = match2;
|
|
3626
|
-
})(Glob || (Glob = {}));
|
|
3627
|
-
var projectIdSchema = Schema_exports.String.pipe(Schema_exports.brand("ProjectID"));
|
|
3628
|
-
var ProjectID = projectIdSchema.pipe(
|
|
3629
|
-
withStatics((schema) => ({
|
|
3630
|
-
global: schema.makeUnsafe("global"),
|
|
3631
|
-
make: (id) => schema.makeUnsafe(id),
|
|
3632
|
-
zod: zod_default.string().pipe(zod_default.custom())
|
|
3633
|
-
}))
|
|
3634
|
-
);
|
|
3635
|
-
var ProjectTable = sqliteTable("project", {
|
|
3636
|
-
id: text().$type().primaryKey(),
|
|
3637
|
-
worktree: text().notNull(),
|
|
3638
|
-
vcs: text(),
|
|
3639
|
-
name: text(),
|
|
3640
|
-
icon_url: text(),
|
|
3641
|
-
icon_color: text(),
|
|
3642
|
-
...Timestamps,
|
|
3643
|
-
time_initialized: integer(),
|
|
3644
|
-
sandboxes: text({ mode: "json" }).notNull().$type(),
|
|
3645
|
-
commands: text({ mode: "json" }).$type()
|
|
3646
|
-
});
|
|
3647
|
-
var DARWIN_HOME = [
|
|
3648
|
-
"Music",
|
|
3649
|
-
"Pictures",
|
|
3650
|
-
"Movies",
|
|
3651
|
-
"Downloads",
|
|
3652
|
-
"Desktop",
|
|
3653
|
-
"Documents",
|
|
3654
|
-
"Public",
|
|
3655
|
-
"Applications",
|
|
3656
|
-
"Library"
|
|
3657
|
-
];
|
|
3658
|
-
var DARWIN_LIBRARY = [
|
|
3659
|
-
"Application Support/AddressBook",
|
|
3660
|
-
"Calendars",
|
|
3661
|
-
"Mail",
|
|
3662
|
-
"Messages",
|
|
3663
|
-
"Safari",
|
|
3664
|
-
"Cookies",
|
|
3665
|
-
"Application Support/com.apple.TCC",
|
|
3666
|
-
"PersonalizationPortrait",
|
|
3667
|
-
"Metadata/CoreSpotlight",
|
|
3668
|
-
"Suggestions"
|
|
3669
|
-
];
|
|
3670
|
-
var DARWIN_ROOT = ["/.DocumentRevisions-V100", "/.Spotlight-V100", "/.Trashes", "/.fseventsd"];
|
|
3671
|
-
var WIN32_HOME = ["AppData", "Downloads", "Desktop", "Documents", "Pictures", "Music", "Videos", "OneDrive"];
|
|
3672
|
-
var Protected;
|
|
3673
|
-
((Protected2) => {
|
|
3674
|
-
function names(platform) {
|
|
3675
|
-
if (platform === "darwin") return new Set(DARWIN_HOME);
|
|
3676
|
-
if (platform === "win32") return new Set(WIN32_HOME);
|
|
3677
|
-
return /* @__PURE__ */ new Set();
|
|
3678
|
-
}
|
|
3679
|
-
Protected2.names = names;
|
|
3680
|
-
function paths(home, platform) {
|
|
3681
|
-
if (platform === "darwin")
|
|
3682
|
-
return [
|
|
3683
|
-
...DARWIN_HOME.map((n) => join(home, n)),
|
|
3684
|
-
...DARWIN_LIBRARY.map((n) => join(home, "Library", n)),
|
|
3685
|
-
...DARWIN_ROOT
|
|
3686
|
-
];
|
|
3687
|
-
if (platform === "win32") return WIN32_HOME.map((n) => join(home, n));
|
|
3688
|
-
return [];
|
|
3689
|
-
}
|
|
3690
|
-
Protected2.paths = paths;
|
|
3691
|
-
})(Protected || (Protected = {}));
|
|
3692
|
-
var FileIgnore;
|
|
3693
|
-
((FileIgnore2) => {
|
|
3694
|
-
const FOLDERS = /* @__PURE__ */ new Set([
|
|
3695
|
-
"node_modules",
|
|
3696
|
-
"bower_components",
|
|
3697
|
-
".pnpm-store",
|
|
3698
|
-
"vendor",
|
|
3699
|
-
".npm",
|
|
3700
|
-
"dist",
|
|
3701
|
-
"build",
|
|
3702
|
-
"out",
|
|
3703
|
-
".next",
|
|
3704
|
-
"target",
|
|
3705
|
-
"bin",
|
|
3706
|
-
"obj",
|
|
3707
|
-
".git",
|
|
3708
|
-
".svn",
|
|
3709
|
-
".hg",
|
|
3710
|
-
".vscode",
|
|
3711
|
-
".idea",
|
|
3712
|
-
".turbo",
|
|
3713
|
-
".output",
|
|
3714
|
-
"desktop",
|
|
3715
|
-
".sst",
|
|
3716
|
-
".cache",
|
|
3717
|
-
".webkit-cache",
|
|
3718
|
-
"__pycache__",
|
|
3719
|
-
".pytest_cache",
|
|
3720
|
-
"mypy_cache",
|
|
3721
|
-
".history",
|
|
3722
|
-
".gradle"
|
|
3723
|
-
]);
|
|
3724
|
-
const FILES = [
|
|
3725
|
-
"**/*.swp",
|
|
3726
|
-
"**/*.swo",
|
|
3727
|
-
"**/*.pyc",
|
|
3728
|
-
"**/.DS_Store",
|
|
3729
|
-
"**/Thumbs.db",
|
|
3730
|
-
"**/logs/**",
|
|
3731
|
-
"**/tmp/**",
|
|
3732
|
-
"**/temp/**",
|
|
3733
|
-
"**/*.log",
|
|
3734
|
-
"**/coverage/**",
|
|
3735
|
-
"**/.nyc_output/**"
|
|
3736
|
-
];
|
|
3737
|
-
FileIgnore2.PATTERNS = [...FILES, ...FOLDERS];
|
|
3738
|
-
function match2(filepath, opts) {
|
|
3739
|
-
for (const pattern of opts?.whitelist || []) {
|
|
3740
|
-
if (Glob.match(pattern, filepath)) return false;
|
|
3741
|
-
}
|
|
3742
|
-
const parts = filepath.split(/[/\\]/);
|
|
3743
|
-
for (let i = 0; i < parts.length; i++) {
|
|
3744
|
-
if (FOLDERS.has(parts[i])) return true;
|
|
3745
|
-
}
|
|
3746
|
-
const extra = opts?.extra || [];
|
|
3747
|
-
for (const pattern of [...FILES, ...extra]) {
|
|
3748
|
-
if (Glob.match(pattern, filepath)) return true;
|
|
3749
|
-
}
|
|
3750
|
-
return false;
|
|
3751
|
-
}
|
|
3752
|
-
FileIgnore2.match = match2;
|
|
3753
|
-
})(FileIgnore || (FileIgnore = {}));
|
|
3754
|
-
var FileTimeService = class {
|
|
3755
|
-
readTimes = {};
|
|
3756
|
-
locks = /* @__PURE__ */ new Map();
|
|
3757
|
-
read(sessionID, file) {
|
|
3758
|
-
this.readTimes[sessionID] = this.readTimes[sessionID] || {};
|
|
3759
|
-
this.readTimes[sessionID][file] = /* @__PURE__ */ new Date();
|
|
3760
|
-
}
|
|
3761
|
-
get(sessionID, file) {
|
|
3762
|
-
return this.readTimes[sessionID]?.[file];
|
|
3763
|
-
}
|
|
3764
|
-
async assert(context, sessionID, filepath) {
|
|
3765
|
-
if (Flag.OPENCODE_DISABLE_FILETIME_CHECK === true) return;
|
|
3766
|
-
const time = this.get(sessionID, filepath);
|
|
3767
|
-
if (!time) throw new Error(`You must read file ${filepath} before overwriting it. Use the Read tool first`);
|
|
3768
|
-
const s = await context.fs.stat(filepath);
|
|
3769
|
-
const mtimeMs = s?.mtimeMs;
|
|
3770
|
-
if (mtimeMs && mtimeMs > time.getTime() + 50) {
|
|
3771
|
-
const mtime = new Date(mtimeMs);
|
|
3772
|
-
throw new Error(
|
|
3773
|
-
`File ${filepath} has been modified since it was last read.
|
|
3774
|
-
Last modification: ${mtime.toISOString()}
|
|
3775
|
-
Last read: ${time.toISOString()}
|
|
3776
|
-
|
|
3777
|
-
Please read the file again before modifying it.`
|
|
3778
|
-
);
|
|
3779
|
-
}
|
|
3780
|
-
}
|
|
3781
|
-
async withLock(filepath, fn) {
|
|
3782
|
-
const currentLock = this.locks.get(filepath) ?? Promise.resolve();
|
|
3783
|
-
let release = () => {
|
|
3784
|
-
};
|
|
3785
|
-
const nextLock = new Promise((resolve2) => {
|
|
3786
|
-
release = resolve2;
|
|
3787
|
-
});
|
|
3788
|
-
const chained = currentLock.then(() => nextLock);
|
|
3789
|
-
this.locks.set(filepath, chained);
|
|
3790
|
-
await currentLock;
|
|
3791
|
-
try {
|
|
3792
|
-
return await fn();
|
|
3793
|
-
} finally {
|
|
3794
|
-
release();
|
|
3795
|
-
if (this.locks.get(filepath) === chained) this.locks.delete(filepath);
|
|
3796
|
-
}
|
|
3797
|
-
}
|
|
3798
|
-
};
|
|
3799
|
-
var FileTime;
|
|
3800
|
-
((FileTime2) => {
|
|
3801
|
-
function svc(context) {
|
|
3802
|
-
if (context.fileTime) return context.fileTime;
|
|
3803
|
-
return context.fileTime;
|
|
3804
|
-
}
|
|
3805
|
-
function state(context) {
|
|
3806
|
-
const s = svc(context);
|
|
3807
|
-
return { read: s.readTimes, locks: s.locks };
|
|
3808
|
-
}
|
|
3809
|
-
FileTime2.state = state;
|
|
3810
|
-
function read(context, sessionID, file) {
|
|
3811
|
-
svc(context).read(sessionID, file);
|
|
3812
|
-
}
|
|
3813
|
-
FileTime2.read = read;
|
|
3814
|
-
function get(context, sessionID, file) {
|
|
3815
|
-
return svc(context).get(sessionID, file);
|
|
3816
|
-
}
|
|
3817
|
-
FileTime2.get = get;
|
|
3818
|
-
async function withLock(context, filepath, fn) {
|
|
3819
|
-
return svc(context).withLock(filepath, fn);
|
|
3820
|
-
}
|
|
3821
|
-
FileTime2.withLock = withLock;
|
|
3822
|
-
async function assert(context, sessionID, filepath) {
|
|
3823
|
-
return svc(context).assert(context, sessionID, filepath);
|
|
3824
|
-
}
|
|
3825
|
-
FileTime2.assert = assert;
|
|
3826
|
-
})(FileTime || (FileTime = {}));
|
|
3827
|
-
var Project;
|
|
3828
|
-
((Project2) => {
|
|
3829
|
-
Project2.Info = zod_default.object({
|
|
3830
|
-
id: ProjectID.zod,
|
|
3831
|
-
worktree: zod_default.string(),
|
|
3832
|
-
vcs: zod_default.literal("git").optional(),
|
|
3833
|
-
name: zod_default.string().optional(),
|
|
3834
|
-
icon: zod_default.object({
|
|
3835
|
-
url: zod_default.string().optional(),
|
|
3836
|
-
override: zod_default.string().optional(),
|
|
3837
|
-
color: zod_default.string().optional()
|
|
3838
|
-
}).optional(),
|
|
3839
|
-
commands: zod_default.object({
|
|
3840
|
-
start: zod_default.string().optional().describe("Startup script to run when creating a new workspace (worktree)")
|
|
3841
|
-
}).optional(),
|
|
3842
|
-
time: zod_default.object({
|
|
3843
|
-
created: zod_default.number(),
|
|
3844
|
-
updated: zod_default.number(),
|
|
3845
|
-
initialized: zod_default.number().optional()
|
|
3846
|
-
}),
|
|
3847
|
-
sandboxes: zod_default.array(zod_default.string())
|
|
3848
|
-
}).meta({ ref: "Project" });
|
|
3849
|
-
function fromRow(row) {
|
|
3850
|
-
const icon = row.icon_url || row.icon_color ? { url: row.icon_url ?? void 0, color: row.icon_color ?? void 0 } : void 0;
|
|
3851
|
-
return {
|
|
3852
|
-
id: ProjectID.make(row.id),
|
|
3853
|
-
worktree: row.worktree,
|
|
3854
|
-
vcs: row.vcs ? Project2.Info.shape.vcs.parse(row.vcs) : void 0,
|
|
3855
|
-
name: row.name ?? void 0,
|
|
3856
|
-
icon,
|
|
3857
|
-
time: {
|
|
3858
|
-
created: row.time_created,
|
|
3859
|
-
updated: row.time_updated,
|
|
3860
|
-
initialized: row.time_initialized ?? void 0
|
|
3861
|
-
},
|
|
3862
|
-
sandboxes: row.sandboxes,
|
|
3863
|
-
commands: row.commands ?? void 0
|
|
3864
|
-
};
|
|
3865
|
-
}
|
|
3866
|
-
Project2.fromRow = fromRow;
|
|
3867
|
-
function setInitialized(context, id) {
|
|
3868
|
-
context.db.update("project", { op: "eq", field: "id", value: id }, { time_initialized: Date.now() });
|
|
3869
|
-
}
|
|
3870
|
-
Project2.setInitialized = setInitialized;
|
|
3871
|
-
function list(context) {
|
|
3872
|
-
return context.db.findMany("project").map((row) => fromRow(row));
|
|
3873
|
-
}
|
|
3874
|
-
Project2.list = list;
|
|
3875
|
-
function get(context, id) {
|
|
3876
|
-
const row = context.db.findOne("project", { op: "eq", field: "id", value: id });
|
|
3877
|
-
if (!row) return void 0;
|
|
3878
|
-
return fromRow(row);
|
|
3879
|
-
}
|
|
3880
|
-
Project2.get = get;
|
|
3881
|
-
async function sandboxes(context, id) {
|
|
3882
|
-
const row = context.db.findOne("project", { op: "eq", field: "id", value: id });
|
|
3883
|
-
if (!row) return [];
|
|
3884
|
-
const data = fromRow(row);
|
|
3885
|
-
const valid = [];
|
|
3886
|
-
for (const dir of data.sandboxes) {
|
|
3887
|
-
const s = await context.fs.stat(dir);
|
|
3888
|
-
if (s?.isDirectory) valid.push(dir);
|
|
3889
|
-
}
|
|
3890
|
-
return valid;
|
|
3891
|
-
}
|
|
3892
|
-
Project2.sandboxes = sandboxes;
|
|
3893
|
-
})(Project || (Project = {}));
|
|
3894
|
-
var SessionTable = sqliteTable(
|
|
3895
|
-
"session",
|
|
3896
|
-
{
|
|
3897
|
-
id: text().$type().primaryKey(),
|
|
3898
|
-
project_id: text().$type().notNull().references(() => ProjectTable.id, { onDelete: "cascade" }),
|
|
3899
|
-
workspace_id: text().$type(),
|
|
3900
|
-
parent_id: text().$type(),
|
|
3901
|
-
slug: text().notNull(),
|
|
3902
|
-
directory: text().notNull(),
|
|
3903
|
-
title: text().notNull(),
|
|
3904
|
-
version: text().notNull(),
|
|
3905
|
-
share_url: text(),
|
|
3906
|
-
summary_additions: integer(),
|
|
3907
|
-
summary_deletions: integer(),
|
|
3908
|
-
summary_files: integer(),
|
|
3909
|
-
summary_diffs: text({ mode: "json" }).$type(),
|
|
3910
|
-
revert: text({ mode: "json" }).$type(),
|
|
3911
|
-
...Timestamps,
|
|
3912
|
-
time_compacting: integer(),
|
|
3913
|
-
time_archived: integer()
|
|
3914
|
-
},
|
|
3915
|
-
(table) => [
|
|
3916
|
-
index("session_project_idx").on(table.project_id),
|
|
3917
|
-
index("session_workspace_idx").on(table.workspace_id),
|
|
3918
|
-
index("session_parent_idx").on(table.parent_id)
|
|
3919
|
-
]
|
|
3920
|
-
);
|
|
3921
|
-
var MessageTable = sqliteTable(
|
|
3922
|
-
"message",
|
|
3923
|
-
{
|
|
3924
|
-
id: text().$type().primaryKey(),
|
|
3925
|
-
session_id: text().$type().notNull().references(() => SessionTable.id, { onDelete: "cascade" }),
|
|
3926
|
-
...Timestamps,
|
|
3927
|
-
data: text({ mode: "json" }).notNull().$type()
|
|
3928
|
-
},
|
|
3929
|
-
(table) => [index("message_session_time_created_id_idx").on(table.session_id, table.time_created, table.id)]
|
|
3930
|
-
);
|
|
3931
|
-
var PartTable = sqliteTable(
|
|
3932
|
-
"part",
|
|
3933
|
-
{
|
|
3934
|
-
id: text().$type().primaryKey(),
|
|
3935
|
-
message_id: text().$type().notNull().references(() => MessageTable.id, { onDelete: "cascade" }),
|
|
3936
|
-
session_id: text().$type().notNull(),
|
|
3937
|
-
...Timestamps,
|
|
3938
|
-
data: text({ mode: "json" }).notNull().$type()
|
|
3939
|
-
},
|
|
3940
|
-
(table) => [
|
|
3941
|
-
index("part_message_id_id_idx").on(table.message_id, table.id),
|
|
3942
|
-
index("part_session_idx").on(table.session_id)
|
|
3943
|
-
]
|
|
3944
|
-
);
|
|
3945
|
-
var TodoTable = sqliteTable(
|
|
3946
|
-
"todo",
|
|
3947
|
-
{
|
|
3948
|
-
session_id: text().$type().notNull().references(() => SessionTable.id, { onDelete: "cascade" }),
|
|
3949
|
-
content: text().notNull(),
|
|
3950
|
-
status: text().notNull(),
|
|
3951
|
-
priority: text().notNull(),
|
|
3952
|
-
position: integer().notNull(),
|
|
3953
|
-
...Timestamps
|
|
3954
|
-
},
|
|
3955
|
-
(table) => [
|
|
3956
|
-
primaryKey({ columns: [table.session_id, table.position] }),
|
|
3957
|
-
index("todo_session_idx").on(table.session_id)
|
|
3958
|
-
]
|
|
3959
|
-
);
|
|
3960
|
-
var NamedError = class _NamedError extends Error {
|
|
3961
|
-
static create(name, data) {
|
|
3962
|
-
const schema = zod_default.object({
|
|
3963
|
-
name: zod_default.literal(name),
|
|
3964
|
-
data
|
|
3965
|
-
}).meta({
|
|
3966
|
-
ref: name
|
|
3967
|
-
});
|
|
3968
|
-
const result = class extends _NamedError {
|
|
3969
|
-
constructor(data2, options) {
|
|
3970
|
-
super(name, options);
|
|
3971
|
-
this.data = data2;
|
|
3972
|
-
this.name = name;
|
|
3973
|
-
}
|
|
3974
|
-
static Schema = schema;
|
|
3975
|
-
name = name;
|
|
3976
|
-
static isInstance(input) {
|
|
3977
|
-
return typeof input === "object" && "name" in input && input.name === name;
|
|
3978
|
-
}
|
|
3979
|
-
schema() {
|
|
3980
|
-
return schema;
|
|
3981
|
-
}
|
|
3982
|
-
toObject() {
|
|
3983
|
-
return {
|
|
3984
|
-
name,
|
|
3985
|
-
data: this.data
|
|
3986
|
-
};
|
|
3987
|
-
}
|
|
3988
|
-
};
|
|
3989
|
-
Object.defineProperty(result, "name", { value: name });
|
|
3990
|
-
return result;
|
|
3991
|
-
}
|
|
3992
|
-
static Unknown = _NamedError.create(
|
|
3993
|
-
"UnknownError",
|
|
3994
|
-
zod_default.object({
|
|
3995
|
-
message: zod_default.string()
|
|
3996
|
-
})
|
|
3997
|
-
);
|
|
3998
|
-
};
|
|
3999
|
-
var Lock;
|
|
4000
|
-
((Lock2) => {
|
|
4001
|
-
const locks = /* @__PURE__ */ new Map();
|
|
4002
|
-
function get(key) {
|
|
4003
|
-
if (!locks.has(key)) {
|
|
4004
|
-
locks.set(key, {
|
|
4005
|
-
readers: 0,
|
|
4006
|
-
writer: false,
|
|
4007
|
-
waitingReaders: [],
|
|
4008
|
-
waitingWriters: []
|
|
4009
|
-
});
|
|
4010
|
-
}
|
|
4011
|
-
return locks.get(key);
|
|
4012
|
-
}
|
|
4013
|
-
function process2(key) {
|
|
4014
|
-
const lock = locks.get(key);
|
|
4015
|
-
if (!lock || lock.writer || lock.readers > 0) return;
|
|
4016
|
-
if (lock.waitingWriters.length > 0) {
|
|
4017
|
-
const nextWriter = lock.waitingWriters.shift();
|
|
4018
|
-
nextWriter();
|
|
4019
|
-
return;
|
|
4020
|
-
}
|
|
4021
|
-
while (lock.waitingReaders.length > 0) {
|
|
4022
|
-
const nextReader = lock.waitingReaders.shift();
|
|
4023
|
-
nextReader();
|
|
4024
|
-
}
|
|
4025
|
-
if (lock.readers === 0 && !lock.writer && lock.waitingReaders.length === 0 && lock.waitingWriters.length === 0) {
|
|
4026
|
-
locks.delete(key);
|
|
4027
|
-
}
|
|
4028
|
-
}
|
|
4029
|
-
async function read(key) {
|
|
4030
|
-
const lock = get(key);
|
|
4031
|
-
return new Promise((resolve2) => {
|
|
4032
|
-
if (!lock.writer && lock.waitingWriters.length === 0) {
|
|
4033
|
-
lock.readers++;
|
|
4034
|
-
resolve2({
|
|
4035
|
-
[Symbol.dispose]: () => {
|
|
4036
|
-
lock.readers--;
|
|
4037
|
-
process2(key);
|
|
4038
|
-
}
|
|
4039
|
-
});
|
|
4040
|
-
} else {
|
|
4041
|
-
lock.waitingReaders.push(() => {
|
|
4042
|
-
lock.readers++;
|
|
4043
|
-
resolve2({
|
|
4044
|
-
[Symbol.dispose]: () => {
|
|
4045
|
-
lock.readers--;
|
|
4046
|
-
process2(key);
|
|
4047
|
-
}
|
|
4048
|
-
});
|
|
4049
|
-
});
|
|
4050
|
-
}
|
|
4051
|
-
});
|
|
4052
|
-
}
|
|
4053
|
-
Lock2.read = read;
|
|
4054
|
-
async function write(key) {
|
|
4055
|
-
const lock = get(key);
|
|
4056
|
-
return new Promise((resolve2) => {
|
|
4057
|
-
if (!lock.writer && lock.readers === 0) {
|
|
4058
|
-
lock.writer = true;
|
|
4059
|
-
resolve2({
|
|
4060
|
-
[Symbol.dispose]: () => {
|
|
4061
|
-
lock.writer = false;
|
|
4062
|
-
process2(key);
|
|
4063
|
-
}
|
|
4064
|
-
});
|
|
4065
|
-
} else {
|
|
4066
|
-
lock.waitingWriters.push(() => {
|
|
4067
|
-
lock.writer = true;
|
|
4068
|
-
resolve2({
|
|
4069
|
-
[Symbol.dispose]: () => {
|
|
4070
|
-
lock.writer = false;
|
|
4071
|
-
process2(key);
|
|
4072
|
-
}
|
|
4073
|
-
});
|
|
4074
|
-
});
|
|
4075
|
-
}
|
|
4076
|
-
});
|
|
4077
|
-
}
|
|
4078
|
-
Lock2.write = write;
|
|
4079
|
-
})(Lock || (Lock = {}));
|
|
4080
|
-
var Timestamps = {
|
|
4081
|
-
time_created: integer().notNull().$default(() => Date.now()),
|
|
4082
|
-
time_updated: integer().notNull().$onUpdate(() => Date.now())
|
|
4083
|
-
};
|
|
4084
|
-
var NotFoundError = NamedError.create(
|
|
4085
|
-
"NotFoundError",
|
|
4086
|
-
zod_default.object({
|
|
4087
|
-
message: zod_default.string()
|
|
4088
|
-
})
|
|
4089
|
-
);
|
|
4090
|
-
var Database;
|
|
4091
|
-
((Database2) => {
|
|
4092
|
-
const INITIAL_MIGRATION = `-- project table
|
|
4093
|
-
CREATE TABLE IF NOT EXISTS "project" (
|
|
4094
|
-
"id" TEXT PRIMARY KEY NOT NULL,
|
|
4095
|
-
"worktree" TEXT NOT NULL,
|
|
4096
|
-
"vcs" TEXT,
|
|
4097
|
-
"name" TEXT,
|
|
4098
|
-
"icon_url" TEXT,
|
|
4099
|
-
"icon_color" TEXT,
|
|
4100
|
-
"time_created" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4101
|
-
"time_updated" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4102
|
-
"time_initialized" INTEGER,
|
|
4103
|
-
"sandboxes" TEXT NOT NULL DEFAULT '[]',
|
|
4104
|
-
"commands" TEXT
|
|
4105
|
-
);
|
|
4106
|
-
|
|
4107
|
-
-- session table
|
|
4108
|
-
CREATE TABLE IF NOT EXISTS "session" (
|
|
4109
|
-
"id" TEXT PRIMARY KEY NOT NULL,
|
|
4110
|
-
"project_id" TEXT NOT NULL REFERENCES "project"("id") ON DELETE CASCADE,
|
|
4111
|
-
"workspace_id" TEXT,
|
|
4112
|
-
"parent_id" TEXT,
|
|
4113
|
-
"slug" TEXT NOT NULL,
|
|
4114
|
-
"directory" TEXT NOT NULL,
|
|
4115
|
-
"title" TEXT NOT NULL,
|
|
4116
|
-
"version" TEXT NOT NULL,
|
|
4117
|
-
"share_url" TEXT,
|
|
4118
|
-
"summary_additions" INTEGER,
|
|
4119
|
-
"summary_deletions" INTEGER,
|
|
4120
|
-
"summary_files" INTEGER,
|
|
4121
|
-
"summary_diffs" TEXT,
|
|
4122
|
-
"revert" TEXT,
|
|
4123
|
-
"permission" TEXT,
|
|
4124
|
-
"time_created" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4125
|
-
"time_updated" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4126
|
-
"time_compacting" INTEGER,
|
|
4127
|
-
"time_archived" INTEGER
|
|
4128
|
-
);
|
|
4129
|
-
CREATE INDEX IF NOT EXISTS "session_project_idx" ON "session"("project_id");
|
|
4130
|
-
CREATE INDEX IF NOT EXISTS "session_workspace_idx" ON "session"("workspace_id");
|
|
4131
|
-
CREATE INDEX IF NOT EXISTS "session_parent_idx" ON "session"("parent_id");
|
|
4132
|
-
|
|
4133
|
-
-- message table
|
|
4134
|
-
CREATE TABLE IF NOT EXISTS "message" (
|
|
4135
|
-
"id" TEXT PRIMARY KEY NOT NULL,
|
|
4136
|
-
"session_id" TEXT NOT NULL REFERENCES "session"("id") ON DELETE CASCADE,
|
|
4137
|
-
"time_created" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4138
|
-
"time_updated" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4139
|
-
"data" TEXT NOT NULL
|
|
4140
|
-
);
|
|
4141
|
-
CREATE INDEX IF NOT EXISTS "message_session_time_created_id_idx" ON "message"("session_id", "time_created", "id");
|
|
4142
|
-
|
|
4143
|
-
-- part table
|
|
4144
|
-
CREATE TABLE IF NOT EXISTS "part" (
|
|
4145
|
-
"id" TEXT PRIMARY KEY NOT NULL,
|
|
4146
|
-
"message_id" TEXT NOT NULL REFERENCES "message"("id") ON DELETE CASCADE,
|
|
4147
|
-
"session_id" TEXT NOT NULL,
|
|
4148
|
-
"time_created" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4149
|
-
"time_updated" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4150
|
-
"data" TEXT NOT NULL
|
|
4151
|
-
);
|
|
4152
|
-
CREATE INDEX IF NOT EXISTS "part_message_id_id_idx" ON "part"("message_id", "id");
|
|
4153
|
-
CREATE INDEX IF NOT EXISTS "part_session_idx" ON "part"("session_id");
|
|
4154
|
-
|
|
4155
|
-
-- todo table
|
|
4156
|
-
CREATE TABLE IF NOT EXISTS "todo" (
|
|
4157
|
-
"session_id" TEXT NOT NULL REFERENCES "session"("id") ON DELETE CASCADE,
|
|
4158
|
-
"content" TEXT NOT NULL,
|
|
4159
|
-
"status" TEXT NOT NULL,
|
|
4160
|
-
"priority" TEXT NOT NULL,
|
|
4161
|
-
"position" INTEGER NOT NULL,
|
|
4162
|
-
"time_created" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4163
|
-
"time_updated" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4164
|
-
PRIMARY KEY ("session_id", "position")
|
|
4165
|
-
);
|
|
4166
|
-
CREATE INDEX IF NOT EXISTS "todo_session_idx" ON "todo"("session_id");
|
|
4167
|
-
|
|
4168
|
-
-- permission table
|
|
4169
|
-
CREATE TABLE IF NOT EXISTS "permission" (
|
|
4170
|
-
"project_id" TEXT PRIMARY KEY NOT NULL REFERENCES "project"("id") ON DELETE CASCADE,
|
|
4171
|
-
"time_created" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4172
|
-
"time_updated" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4173
|
-
"data" TEXT NOT NULL
|
|
4174
|
-
);
|
|
4175
|
-
|
|
4176
|
-
-- session_share table
|
|
4177
|
-
CREATE TABLE IF NOT EXISTS "session_share" (
|
|
4178
|
-
"session_id" TEXT PRIMARY KEY NOT NULL REFERENCES "session"("id") ON DELETE CASCADE,
|
|
4179
|
-
"id" TEXT NOT NULL,
|
|
4180
|
-
"secret" TEXT NOT NULL,
|
|
4181
|
-
"url" TEXT NOT NULL,
|
|
4182
|
-
"time_created" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4183
|
-
"time_updated" INTEGER NOT NULL DEFAULT (unixepoch() * 1000)
|
|
4184
|
-
);
|
|
4185
|
-
|
|
4186
|
-
-- workspace table
|
|
4187
|
-
CREATE TABLE IF NOT EXISTS "workspace" (
|
|
4188
|
-
"id" TEXT PRIMARY KEY NOT NULL,
|
|
4189
|
-
"type" TEXT NOT NULL,
|
|
4190
|
-
"branch" TEXT,
|
|
4191
|
-
"name" TEXT,
|
|
4192
|
-
"directory" TEXT,
|
|
4193
|
-
"extra" TEXT,
|
|
4194
|
-
"project_id" TEXT NOT NULL REFERENCES "project"("id") ON DELETE CASCADE
|
|
4195
|
-
);
|
|
4196
|
-
|
|
4197
|
-
-- account table
|
|
4198
|
-
CREATE TABLE IF NOT EXISTS "account" (
|
|
4199
|
-
"id" TEXT PRIMARY KEY NOT NULL,
|
|
4200
|
-
"email" TEXT NOT NULL,
|
|
4201
|
-
"url" TEXT NOT NULL,
|
|
4202
|
-
"access_token" TEXT NOT NULL,
|
|
4203
|
-
"refresh_token" TEXT NOT NULL,
|
|
4204
|
-
"token_expiry" INTEGER,
|
|
4205
|
-
"time_created" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4206
|
-
"time_updated" INTEGER NOT NULL DEFAULT (unixepoch() * 1000)
|
|
4207
|
-
);
|
|
4208
|
-
|
|
4209
|
-
-- account_state table
|
|
4210
|
-
CREATE TABLE IF NOT EXISTS "account_state" (
|
|
4211
|
-
"id" INTEGER PRIMARY KEY,
|
|
4212
|
-
"active_account_id" TEXT REFERENCES "account"("id") ON DELETE SET NULL,
|
|
4213
|
-
"active_org_id" TEXT
|
|
4214
|
-
);
|
|
4215
|
-
|
|
4216
|
-
-- control_account table (legacy)
|
|
4217
|
-
CREATE TABLE IF NOT EXISTS "control_account" (
|
|
4218
|
-
"email" TEXT NOT NULL,
|
|
4219
|
-
"url" TEXT NOT NULL,
|
|
4220
|
-
"access_token" TEXT NOT NULL,
|
|
4221
|
-
"refresh_token" TEXT NOT NULL,
|
|
4222
|
-
"token_expiry" INTEGER,
|
|
4223
|
-
"active" INTEGER NOT NULL DEFAULT 0,
|
|
4224
|
-
"time_created" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4225
|
-
"time_updated" INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
4226
|
-
PRIMARY KEY ("email", "url")
|
|
4227
|
-
);`;
|
|
4228
|
-
function getMigrations() {
|
|
4229
|
-
const entries = [
|
|
4230
|
-
{ sql: INITIAL_MIGRATION, timestamp: Date.UTC(2024, 0, 1), name: "20240101000000_initial" }
|
|
4231
|
-
];
|
|
4232
|
-
if (Flag.OPENCODE_SKIP_MIGRATIONS) {
|
|
4233
|
-
for (const item of entries) {
|
|
4234
|
-
item.sql = "select 1;";
|
|
4235
|
-
}
|
|
4236
|
-
}
|
|
4237
|
-
return entries;
|
|
4238
|
-
}
|
|
4239
|
-
Database2.getMigrations = getMigrations;
|
|
4240
|
-
})(Database || (Database = {}));
|
|
4241
|
-
var Storage;
|
|
4242
|
-
((Storage2) => {
|
|
4243
|
-
function getLog(context) {
|
|
4244
|
-
return context.log.create({ service: "storage" });
|
|
4245
|
-
}
|
|
4246
|
-
Storage2.NotFoundError = NamedError.create(
|
|
4247
|
-
"NotFoundError",
|
|
4248
|
-
zod_default.object({
|
|
4249
|
-
message: zod_default.string()
|
|
4250
|
-
})
|
|
4251
|
-
);
|
|
4252
|
-
const MIGRATIONS = [
|
|
4253
|
-
async (context, dir) => {
|
|
4254
|
-
const project = resolve(dir, "../project");
|
|
4255
|
-
if (!await context.fs.isDir(project)) return;
|
|
4256
|
-
const projectDirs = await context.fs.glob("*", {
|
|
4257
|
-
cwd: project,
|
|
4258
|
-
nodir: false
|
|
4259
|
-
});
|
|
4260
|
-
for (const projectDir of projectDirs) {
|
|
4261
|
-
const fullPath = join(project, projectDir);
|
|
4262
|
-
if (!await context.fs.isDir(fullPath)) continue;
|
|
4263
|
-
getLog(context).info(`migrating project ${projectDir}`);
|
|
4264
|
-
let projectID = projectDir;
|
|
4265
|
-
const fullProjectDir = join(project, projectDir);
|
|
4266
|
-
let worktree = "/";
|
|
4267
|
-
if (projectID !== "global") {
|
|
4268
|
-
for (const msgFile of await context.fs.glob("storage/session/message/*/*.json", {
|
|
4269
|
-
cwd: join(project, projectDir),
|
|
4270
|
-
absolute: true
|
|
4271
|
-
})) {
|
|
4272
|
-
const json = await context.fs.readJson(msgFile);
|
|
4273
|
-
worktree = json.path?.root;
|
|
4274
|
-
if (worktree) break;
|
|
4275
|
-
}
|
|
4276
|
-
if (!worktree) continue;
|
|
4277
|
-
if (!await context.fs.isDir(worktree)) continue;
|
|
4278
|
-
const result = await context.git.run(["rev-list", "--max-parents=0", "--all"], {
|
|
4279
|
-
cwd: worktree
|
|
4280
|
-
});
|
|
4281
|
-
const [id] = result.text().split("\n").filter(Boolean).map((x) => x.trim()).toSorted();
|
|
4282
|
-
if (!id) continue;
|
|
4283
|
-
projectID = id;
|
|
4284
|
-
await context.fs.writeJson(join(dir, "project", projectID + ".json"), {
|
|
4285
|
-
id,
|
|
4286
|
-
vcs: "git",
|
|
4287
|
-
worktree,
|
|
4288
|
-
time: {
|
|
4289
|
-
created: Date.now(),
|
|
4290
|
-
initialized: Date.now()
|
|
4291
|
-
}
|
|
4292
|
-
});
|
|
4293
|
-
getLog(context).info(`migrating sessions for project ${projectID}`);
|
|
4294
|
-
for (const sessionFile of await context.fs.glob("storage/session/info/*.json", {
|
|
4295
|
-
cwd: fullProjectDir,
|
|
4296
|
-
absolute: true
|
|
4297
|
-
})) {
|
|
4298
|
-
const dest = join(dir, "session", projectID, basename(sessionFile));
|
|
4299
|
-
getLog(context).info("copying", {
|
|
4300
|
-
sessionFile,
|
|
4301
|
-
dest
|
|
4302
|
-
});
|
|
4303
|
-
const session = await context.fs.readJson(sessionFile);
|
|
4304
|
-
await context.fs.writeJson(dest, session);
|
|
4305
|
-
getLog(context).info(`migrating messages for session ${session.id}`);
|
|
4306
|
-
for (const msgFile of await context.fs.glob(`storage/session/message/${session.id}/*.json`, {
|
|
4307
|
-
cwd: fullProjectDir,
|
|
4308
|
-
absolute: true
|
|
4309
|
-
})) {
|
|
4310
|
-
const dest2 = join(dir, "message", session.id, basename(msgFile));
|
|
4311
|
-
getLog(context).info("copying", {
|
|
4312
|
-
msgFile,
|
|
4313
|
-
dest: dest2
|
|
4314
|
-
});
|
|
4315
|
-
const message = await context.fs.readJson(msgFile);
|
|
4316
|
-
await context.fs.writeJson(dest2, message);
|
|
4317
|
-
getLog(context).info(`migrating parts for message ${message.id}`);
|
|
4318
|
-
for (const partFile of await context.fs.glob(`storage/session/part/${session.id}/${message.id}/*.json`, {
|
|
4319
|
-
cwd: fullProjectDir,
|
|
4320
|
-
absolute: true
|
|
4321
|
-
})) {
|
|
4322
|
-
const dest3 = join(dir, "part", message.id, basename(partFile));
|
|
4323
|
-
const part = await context.fs.readJson(partFile);
|
|
4324
|
-
getLog(context).info("copying", {
|
|
4325
|
-
partFile,
|
|
4326
|
-
dest: dest3
|
|
4327
|
-
});
|
|
4328
|
-
await context.fs.writeJson(dest3, part);
|
|
4329
|
-
}
|
|
4330
|
-
}
|
|
4331
|
-
}
|
|
4332
|
-
}
|
|
4333
|
-
}
|
|
4334
|
-
},
|
|
4335
|
-
async (context, dir) => {
|
|
4336
|
-
for (const item of await context.fs.glob("session/*/*.json", {
|
|
4337
|
-
cwd: dir,
|
|
4338
|
-
absolute: true
|
|
4339
|
-
})) {
|
|
4340
|
-
const session = await context.fs.readJson(item);
|
|
4341
|
-
if (!session.projectID) continue;
|
|
4342
|
-
if (!session.summary?.diffs) continue;
|
|
4343
|
-
const { diffs } = session.summary;
|
|
4344
|
-
await context.fs.write(join(dir, "session_diff", session.id + ".json"), JSON.stringify(diffs));
|
|
4345
|
-
await context.fs.writeJson(join(dir, "session", session.projectID, session.id + ".json"), {
|
|
4346
|
-
...session,
|
|
4347
|
-
summary: {
|
|
4348
|
-
additions: diffs.reduce((sum, x) => sum + x.additions, 0),
|
|
4349
|
-
deletions: diffs.reduce((sum, x) => sum + x.deletions, 0)
|
|
4350
|
-
}
|
|
4351
|
-
});
|
|
4352
|
-
}
|
|
4353
|
-
}
|
|
4354
|
-
];
|
|
4355
|
-
async function getDir(context) {
|
|
4356
|
-
const dir = join(context.dataPath, "storage");
|
|
4357
|
-
const migration = await context.fs.readJson(join(dir, "migration")).then((x) => parseInt(x)).catch(() => 0);
|
|
4358
|
-
for (let index2 = migration; index2 < MIGRATIONS.length; index2++) {
|
|
4359
|
-
getLog(context).info("running migration", { index: index2 });
|
|
4360
|
-
const migrationFn = MIGRATIONS[index2];
|
|
4361
|
-
await migrationFn(context, dir).catch(() => getLog(context).error("failed to run migration", { index: index2 }));
|
|
4362
|
-
await context.fs.write(join(dir, "migration"), (index2 + 1).toString());
|
|
4363
|
-
}
|
|
4364
|
-
return dir;
|
|
4365
|
-
}
|
|
4366
|
-
async function remove(context, key) {
|
|
4367
|
-
const dir = await getDir(context);
|
|
4368
|
-
const target = join(dir, ...key) + ".json";
|
|
4369
|
-
return withErrorHandling(async () => {
|
|
4370
|
-
await fs4.unlink(target).catch(() => {
|
|
4371
|
-
});
|
|
4372
|
-
});
|
|
4373
|
-
}
|
|
4374
|
-
Storage2.remove = remove;
|
|
4375
|
-
async function read(context, key) {
|
|
4376
|
-
const dir = await getDir(context);
|
|
4377
|
-
const target = join(dir, ...key) + ".json";
|
|
4378
|
-
return withErrorHandling(async () => {
|
|
4379
|
-
var _stack = [];
|
|
4380
|
-
try {
|
|
4381
|
-
const _ = __using(_stack, await Lock.read(target));
|
|
4382
|
-
const result = await context.fs.readJson(target);
|
|
4383
|
-
return result;
|
|
4384
|
-
} catch (_2) {
|
|
4385
|
-
var _error = _2, _hasError = true;
|
|
4386
|
-
} finally {
|
|
4387
|
-
__callDispose(_stack, _error, _hasError);
|
|
4388
|
-
}
|
|
4389
|
-
});
|
|
4390
|
-
}
|
|
4391
|
-
Storage2.read = read;
|
|
4392
|
-
async function update(context, key, fn) {
|
|
4393
|
-
const dir = await getDir(context);
|
|
4394
|
-
const target = join(dir, ...key) + ".json";
|
|
4395
|
-
return withErrorHandling(async () => {
|
|
4396
|
-
var _stack = [];
|
|
4397
|
-
try {
|
|
4398
|
-
const _ = __using(_stack, await Lock.write(target));
|
|
4399
|
-
const content = await context.fs.readJson(target);
|
|
4400
|
-
fn(content);
|
|
4401
|
-
await context.fs.writeJson(target, content);
|
|
4402
|
-
return content;
|
|
4403
|
-
} catch (_2) {
|
|
4404
|
-
var _error = _2, _hasError = true;
|
|
4405
|
-
} finally {
|
|
4406
|
-
__callDispose(_stack, _error, _hasError);
|
|
4407
|
-
}
|
|
4408
|
-
});
|
|
4409
|
-
}
|
|
4410
|
-
Storage2.update = update;
|
|
4411
|
-
async function write(context, key, content) {
|
|
4412
|
-
const dir = await getDir(context);
|
|
4413
|
-
const target = join(dir, ...key) + ".json";
|
|
4414
|
-
return withErrorHandling(async () => {
|
|
4415
|
-
var _stack = [];
|
|
4416
|
-
try {
|
|
4417
|
-
const _ = __using(_stack, await Lock.write(target));
|
|
4418
|
-
await context.fs.writeJson(target, content);
|
|
4419
|
-
} catch (_2) {
|
|
4420
|
-
var _error = _2, _hasError = true;
|
|
4421
|
-
} finally {
|
|
4422
|
-
__callDispose(_stack, _error, _hasError);
|
|
4423
|
-
}
|
|
4424
|
-
});
|
|
4425
|
-
}
|
|
4426
|
-
Storage2.write = write;
|
|
4427
|
-
async function withErrorHandling(body) {
|
|
4428
|
-
return body().catch((e) => {
|
|
4429
|
-
if (!(e instanceof Error)) throw e;
|
|
4430
|
-
const errnoException = e;
|
|
4431
|
-
if (errnoException.code === "ENOENT") {
|
|
4432
|
-
throw new Storage2.NotFoundError({ message: `Resource not found: ${errnoException.path}` });
|
|
4433
|
-
}
|
|
4434
|
-
throw e;
|
|
4435
|
-
});
|
|
4436
|
-
}
|
|
4437
|
-
async function list(context, prefix) {
|
|
4438
|
-
const dir = await getDir(context);
|
|
4439
|
-
try {
|
|
4440
|
-
const result = await context.fs.glob("**/*", {
|
|
4441
|
-
cwd: join(dir, ...prefix),
|
|
4442
|
-
nodir: true
|
|
4443
|
-
}).then((results) => results.map((x) => [...prefix, ...x.slice(0, -5).split(sep2)]));
|
|
4444
|
-
result.sort();
|
|
4445
|
-
return result;
|
|
4446
|
-
} catch {
|
|
4447
|
-
return [];
|
|
4448
|
-
}
|
|
4449
|
-
}
|
|
4450
|
-
Storage2.list = list;
|
|
4451
|
-
})(Storage || (Storage = {}));
|
|
4452
|
-
|
|
4453
|
-
export {
|
|
4454
|
-
consoleLogger,
|
|
4455
|
-
SqliteNoSqlDb,
|
|
4456
|
-
NodeFS,
|
|
4457
|
-
NodeSearchProvider,
|
|
4458
|
-
SqlJsStorage,
|
|
4459
|
-
join,
|
|
4460
|
-
dirname,
|
|
4461
|
-
basename,
|
|
4462
|
-
extname,
|
|
4463
|
-
isAbsolute,
|
|
4464
|
-
relative,
|
|
4465
|
-
resolve,
|
|
4466
|
-
Flag,
|
|
4467
|
-
ProjectID,
|
|
4468
|
-
ProjectTable,
|
|
4469
|
-
FileTimeService,
|
|
4470
|
-
SessionTable,
|
|
4471
|
-
MessageTable,
|
|
4472
|
-
PartTable,
|
|
4473
|
-
TodoTable,
|
|
4474
|
-
NamedError,
|
|
4475
|
-
Timestamps,
|
|
4476
|
-
NotFoundError,
|
|
4477
|
-
Database,
|
|
4478
|
-
Storage
|
|
4479
|
-
};
|