@miketromba/issy-app 0.1.1 → 0.1.4

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/server.js ADDED
@@ -0,0 +1,1899 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
4
+ // src/server.ts
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { createServer } from "node:http";
7
+ import { extname, join as join2, resolve } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ // ../core/src/lib/issues.ts
10
+ import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
11
+ import { join } from "node:path";
12
+ var issuesDir = null;
13
+ function setIssuesDir(dir) {
14
+ issuesDir = dir;
15
+ }
16
+ function getIssuesDir() {
17
+ if (!issuesDir) {
18
+ throw new Error("Issues directory not initialized. Call setIssuesDir() first.");
19
+ }
20
+ return issuesDir;
21
+ }
22
+ async function ensureIssuesDir() {
23
+ await mkdir(getIssuesDir(), { recursive: true });
24
+ }
25
+ function parseFrontmatter(content) {
26
+ const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
27
+ if (!match) {
28
+ return { frontmatter: {}, body: content };
29
+ }
30
+ const [, frontmatterStr, body] = match;
31
+ const frontmatter = {};
32
+ for (const line of frontmatterStr.split(`
33
+ `)) {
34
+ const colonIdx = line.indexOf(":");
35
+ if (colonIdx > 0) {
36
+ const key = line.slice(0, colonIdx).trim();
37
+ const value = line.slice(colonIdx + 1).trim();
38
+ frontmatter[key] = value;
39
+ }
40
+ }
41
+ return { frontmatter, body };
42
+ }
43
+ function generateFrontmatter(data) {
44
+ const lines = ["---"];
45
+ lines.push(`title: ${data.title}`);
46
+ lines.push(`description: ${data.description}`);
47
+ lines.push(`priority: ${data.priority}`);
48
+ lines.push(`type: ${data.type}`);
49
+ if (data.labels) {
50
+ lines.push(`labels: ${data.labels}`);
51
+ }
52
+ lines.push(`status: ${data.status}`);
53
+ lines.push(`created: ${data.created}`);
54
+ if (data.updated) {
55
+ lines.push(`updated: ${data.updated}`);
56
+ }
57
+ lines.push("---");
58
+ return lines.join(`
59
+ `);
60
+ }
61
+ function getIssueIdFromFilename(filename) {
62
+ const match = filename.match(/^(\d+)-/);
63
+ return match ? match[1] : filename.replace(".md", "");
64
+ }
65
+ function createSlug(title) {
66
+ return title.toLowerCase().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").slice(0, 50);
67
+ }
68
+ function formatDate(date = new Date) {
69
+ return date.toISOString().slice(0, 19);
70
+ }
71
+ async function getIssueFiles() {
72
+ try {
73
+ const files = await readdir(getIssuesDir());
74
+ return files.filter((f) => f.endsWith(".md") && /^\d{4}-/.test(f));
75
+ } catch {
76
+ return [];
77
+ }
78
+ }
79
+ async function getNextIssueNumber() {
80
+ const files = await getIssueFiles();
81
+ if (files.length === 0)
82
+ return "0001";
83
+ const numbers = files.map((f) => parseInt(getIssueIdFromFilename(f), 10)).filter((n) => !Number.isNaN(n));
84
+ const max = Math.max(...numbers, 0);
85
+ return String(max + 1).padStart(4, "0");
86
+ }
87
+ async function getIssue(id) {
88
+ const files = await getIssueFiles();
89
+ const paddedId = id.padStart(4, "0");
90
+ const file = files.find((f) => f.startsWith(paddedId) || getIssueIdFromFilename(f) === paddedId);
91
+ if (!file)
92
+ return null;
93
+ const filepath = join(getIssuesDir(), file);
94
+ const content = await readFile(filepath, "utf-8");
95
+ const { frontmatter, body } = parseFrontmatter(content);
96
+ return {
97
+ id: getIssueIdFromFilename(file),
98
+ filename: file,
99
+ frontmatter,
100
+ content: body
101
+ };
102
+ }
103
+ async function getAllIssues() {
104
+ const files = await getIssueFiles();
105
+ const issues = [];
106
+ for (const file of files) {
107
+ const filepath = join(getIssuesDir(), file);
108
+ const content = await readFile(filepath, "utf-8");
109
+ const { frontmatter, body } = parseFrontmatter(content);
110
+ issues.push({
111
+ id: getIssueIdFromFilename(file),
112
+ filename: file,
113
+ frontmatter,
114
+ content: body
115
+ });
116
+ }
117
+ const priorityOrder = { high: 0, medium: 1, low: 2 };
118
+ return issues.sort((a, b) => {
119
+ const priorityA = priorityOrder[a.frontmatter.priority] ?? 999;
120
+ const priorityB = priorityOrder[b.frontmatter.priority] ?? 999;
121
+ if (priorityA !== priorityB) {
122
+ return priorityA - priorityB;
123
+ }
124
+ return b.id.localeCompare(a.id);
125
+ });
126
+ }
127
+ async function createIssue(input) {
128
+ await ensureIssuesDir();
129
+ if (!input.title) {
130
+ throw new Error("Title is required");
131
+ }
132
+ const priority = input.priority || "medium";
133
+ const type = input.type || "improvement";
134
+ if (!["high", "medium", "low"].includes(priority)) {
135
+ throw new Error("Priority must be: high, medium, or low");
136
+ }
137
+ if (!["bug", "improvement"].includes(type)) {
138
+ throw new Error("Type must be: bug or improvement");
139
+ }
140
+ const issueNumber = await getNextIssueNumber();
141
+ const slug = createSlug(input.title);
142
+ const filename = `${issueNumber}-${slug}.md`;
143
+ const frontmatter = {
144
+ title: input.title,
145
+ description: input.description || input.title,
146
+ priority,
147
+ type,
148
+ labels: input.labels || undefined,
149
+ status: "open",
150
+ created: formatDate()
151
+ };
152
+ const content = `${generateFrontmatter(frontmatter)}
153
+
154
+ ## Details
155
+
156
+ <!-- Add detailed description here -->
157
+
158
+ `;
159
+ await writeFile(join(getIssuesDir(), filename), content);
160
+ return {
161
+ id: issueNumber,
162
+ filename,
163
+ frontmatter,
164
+ content: `
165
+ ## Details
166
+
167
+ <!-- Add detailed description here -->
168
+
169
+ `
170
+ };
171
+ }
172
+ async function updateIssue(id, input) {
173
+ const issue = await getIssue(id);
174
+ if (!issue) {
175
+ throw new Error(`Issue not found: ${id}`);
176
+ }
177
+ const updatedFrontmatter = {
178
+ ...issue.frontmatter,
179
+ ...input.title && { title: input.title },
180
+ ...input.description && { description: input.description },
181
+ ...input.priority && { priority: input.priority },
182
+ ...input.type && { type: input.type },
183
+ ...input.labels !== undefined && {
184
+ labels: input.labels || undefined
185
+ },
186
+ ...input.status && { status: input.status },
187
+ updated: formatDate()
188
+ };
189
+ const content = `${generateFrontmatter(updatedFrontmatter)}
190
+ ${issue.content}`;
191
+ await writeFile(join(getIssuesDir(), issue.filename), content);
192
+ return {
193
+ ...issue,
194
+ frontmatter: updatedFrontmatter
195
+ };
196
+ }
197
+ async function closeIssue(id) {
198
+ return updateIssue(id, { status: "closed" });
199
+ }
200
+ async function reopenIssue(id) {
201
+ return updateIssue(id, { status: "open" });
202
+ }
203
+ async function deleteIssue(id) {
204
+ const issue = await getIssue(id);
205
+ if (!issue) {
206
+ throw new Error(`Issue not found: ${id}`);
207
+ }
208
+ const { unlink } = await import("node:fs/promises");
209
+ await unlink(join(getIssuesDir(), issue.filename));
210
+ }
211
+ // ../core/src/lib/query-parser.ts
212
+ var SUPPORTED_QUALIFIERS = new Set([
213
+ "is",
214
+ "priority",
215
+ "type",
216
+ "label",
217
+ "sort"
218
+ ]);
219
+ function parseQuery(query) {
220
+ const qualifiers = {};
221
+ const searchTextParts = [];
222
+ if (!query || !query.trim()) {
223
+ return { qualifiers, searchText: "" };
224
+ }
225
+ const tokens = tokenizeQuery(query);
226
+ for (const token of tokens) {
227
+ const colonIndex = token.indexOf(":");
228
+ if (colonIndex > 0 && colonIndex < token.length - 1) {
229
+ const key = token.substring(0, colonIndex);
230
+ const value = token.substring(colonIndex + 1);
231
+ if (SUPPORTED_QUALIFIERS.has(key)) {
232
+ qualifiers[key] = value;
233
+ } else {
234
+ searchTextParts.push(token);
235
+ }
236
+ } else {
237
+ searchTextParts.push(token);
238
+ }
239
+ }
240
+ return {
241
+ qualifiers,
242
+ searchText: searchTextParts.join(" ").trim()
243
+ };
244
+ }
245
+ function tokenizeQuery(query) {
246
+ const tokens = [];
247
+ let currentToken = "";
248
+ let inQuotes = false;
249
+ let quoteChar = "";
250
+ for (let i = 0;i < query.length; i++) {
251
+ const char = query[i];
252
+ if ((char === '"' || char === "'") && !inQuotes) {
253
+ inQuotes = true;
254
+ quoteChar = char;
255
+ } else if (char === quoteChar && inQuotes) {
256
+ inQuotes = false;
257
+ quoteChar = "";
258
+ } else if (char === " " && !inQuotes) {
259
+ if (currentToken) {
260
+ tokens.push(currentToken);
261
+ currentToken = "";
262
+ }
263
+ } else {
264
+ currentToken += char;
265
+ }
266
+ }
267
+ if (currentToken) {
268
+ tokens.push(currentToken);
269
+ }
270
+ return tokens;
271
+ }
272
+ // ../../node_modules/.bun/fuse.js@7.1.0/node_modules/fuse.js/dist/fuse.mjs
273
+ function isArray(value) {
274
+ return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
275
+ }
276
+ var INFINITY = 1 / 0;
277
+ function baseToString(value) {
278
+ if (typeof value == "string") {
279
+ return value;
280
+ }
281
+ let result = value + "";
282
+ return result == "0" && 1 / value == -INFINITY ? "-0" : result;
283
+ }
284
+ function toString(value) {
285
+ return value == null ? "" : baseToString(value);
286
+ }
287
+ function isString(value) {
288
+ return typeof value === "string";
289
+ }
290
+ function isNumber(value) {
291
+ return typeof value === "number";
292
+ }
293
+ function isBoolean(value) {
294
+ return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
295
+ }
296
+ function isObject(value) {
297
+ return typeof value === "object";
298
+ }
299
+ function isObjectLike(value) {
300
+ return isObject(value) && value !== null;
301
+ }
302
+ function isDefined(value) {
303
+ return value !== undefined && value !== null;
304
+ }
305
+ function isBlank(value) {
306
+ return !value.trim().length;
307
+ }
308
+ function getTag(value) {
309
+ return value == null ? value === undefined ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
310
+ }
311
+ var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
312
+ var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
313
+ var PATTERN_LENGTH_TOO_LARGE = (max) => `Pattern length exceeds max of ${max}.`;
314
+ var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
315
+ var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
316
+ var hasOwn = Object.prototype.hasOwnProperty;
317
+
318
+ class KeyStore {
319
+ constructor(keys) {
320
+ this._keys = [];
321
+ this._keyMap = {};
322
+ let totalWeight = 0;
323
+ keys.forEach((key) => {
324
+ let obj = createKey(key);
325
+ this._keys.push(obj);
326
+ this._keyMap[obj.id] = obj;
327
+ totalWeight += obj.weight;
328
+ });
329
+ this._keys.forEach((key) => {
330
+ key.weight /= totalWeight;
331
+ });
332
+ }
333
+ get(keyId) {
334
+ return this._keyMap[keyId];
335
+ }
336
+ keys() {
337
+ return this._keys;
338
+ }
339
+ toJSON() {
340
+ return JSON.stringify(this._keys);
341
+ }
342
+ }
343
+ function createKey(key) {
344
+ let path = null;
345
+ let id = null;
346
+ let src = null;
347
+ let weight = 1;
348
+ let getFn = null;
349
+ if (isString(key) || isArray(key)) {
350
+ src = key;
351
+ path = createKeyPath(key);
352
+ id = createKeyId(key);
353
+ } else {
354
+ if (!hasOwn.call(key, "name")) {
355
+ throw new Error(MISSING_KEY_PROPERTY("name"));
356
+ }
357
+ const name = key.name;
358
+ src = name;
359
+ if (hasOwn.call(key, "weight")) {
360
+ weight = key.weight;
361
+ if (weight <= 0) {
362
+ throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
363
+ }
364
+ }
365
+ path = createKeyPath(name);
366
+ id = createKeyId(name);
367
+ getFn = key.getFn;
368
+ }
369
+ return { path, id, weight, src, getFn };
370
+ }
371
+ function createKeyPath(key) {
372
+ return isArray(key) ? key : key.split(".");
373
+ }
374
+ function createKeyId(key) {
375
+ return isArray(key) ? key.join(".") : key;
376
+ }
377
+ function get(obj, path) {
378
+ let list = [];
379
+ let arr = false;
380
+ const deepGet = (obj2, path2, index) => {
381
+ if (!isDefined(obj2)) {
382
+ return;
383
+ }
384
+ if (!path2[index]) {
385
+ list.push(obj2);
386
+ } else {
387
+ let key = path2[index];
388
+ const value = obj2[key];
389
+ if (!isDefined(value)) {
390
+ return;
391
+ }
392
+ if (index === path2.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
393
+ list.push(toString(value));
394
+ } else if (isArray(value)) {
395
+ arr = true;
396
+ for (let i = 0, len = value.length;i < len; i += 1) {
397
+ deepGet(value[i], path2, index + 1);
398
+ }
399
+ } else if (path2.length) {
400
+ deepGet(value, path2, index + 1);
401
+ }
402
+ }
403
+ };
404
+ deepGet(obj, isString(path) ? path.split(".") : path, 0);
405
+ return arr ? list : list[0];
406
+ }
407
+ var MatchOptions = {
408
+ includeMatches: false,
409
+ findAllMatches: false,
410
+ minMatchCharLength: 1
411
+ };
412
+ var BasicOptions = {
413
+ isCaseSensitive: false,
414
+ ignoreDiacritics: false,
415
+ includeScore: false,
416
+ keys: [],
417
+ shouldSort: true,
418
+ sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
419
+ };
420
+ var FuzzyOptions = {
421
+ location: 0,
422
+ threshold: 0.6,
423
+ distance: 100
424
+ };
425
+ var AdvancedOptions = {
426
+ useExtendedSearch: false,
427
+ getFn: get,
428
+ ignoreLocation: false,
429
+ ignoreFieldNorm: false,
430
+ fieldNormWeight: 1
431
+ };
432
+ var Config = {
433
+ ...BasicOptions,
434
+ ...MatchOptions,
435
+ ...FuzzyOptions,
436
+ ...AdvancedOptions
437
+ };
438
+ var SPACE = /[^ ]+/g;
439
+ function norm(weight = 1, mantissa = 3) {
440
+ const cache = new Map;
441
+ const m = Math.pow(10, mantissa);
442
+ return {
443
+ get(value) {
444
+ const numTokens = value.match(SPACE).length;
445
+ if (cache.has(numTokens)) {
446
+ return cache.get(numTokens);
447
+ }
448
+ const norm2 = 1 / Math.pow(numTokens, 0.5 * weight);
449
+ const n = parseFloat(Math.round(norm2 * m) / m);
450
+ cache.set(numTokens, n);
451
+ return n;
452
+ },
453
+ clear() {
454
+ cache.clear();
455
+ }
456
+ };
457
+ }
458
+
459
+ class FuseIndex {
460
+ constructor({
461
+ getFn = Config.getFn,
462
+ fieldNormWeight = Config.fieldNormWeight
463
+ } = {}) {
464
+ this.norm = norm(fieldNormWeight, 3);
465
+ this.getFn = getFn;
466
+ this.isCreated = false;
467
+ this.setIndexRecords();
468
+ }
469
+ setSources(docs = []) {
470
+ this.docs = docs;
471
+ }
472
+ setIndexRecords(records = []) {
473
+ this.records = records;
474
+ }
475
+ setKeys(keys = []) {
476
+ this.keys = keys;
477
+ this._keysMap = {};
478
+ keys.forEach((key, idx) => {
479
+ this._keysMap[key.id] = idx;
480
+ });
481
+ }
482
+ create() {
483
+ if (this.isCreated || !this.docs.length) {
484
+ return;
485
+ }
486
+ this.isCreated = true;
487
+ if (isString(this.docs[0])) {
488
+ this.docs.forEach((doc, docIndex) => {
489
+ this._addString(doc, docIndex);
490
+ });
491
+ } else {
492
+ this.docs.forEach((doc, docIndex) => {
493
+ this._addObject(doc, docIndex);
494
+ });
495
+ }
496
+ this.norm.clear();
497
+ }
498
+ add(doc) {
499
+ const idx = this.size();
500
+ if (isString(doc)) {
501
+ this._addString(doc, idx);
502
+ } else {
503
+ this._addObject(doc, idx);
504
+ }
505
+ }
506
+ removeAt(idx) {
507
+ this.records.splice(idx, 1);
508
+ for (let i = idx, len = this.size();i < len; i += 1) {
509
+ this.records[i].i -= 1;
510
+ }
511
+ }
512
+ getValueForItemAtKeyId(item, keyId) {
513
+ return item[this._keysMap[keyId]];
514
+ }
515
+ size() {
516
+ return this.records.length;
517
+ }
518
+ _addString(doc, docIndex) {
519
+ if (!isDefined(doc) || isBlank(doc)) {
520
+ return;
521
+ }
522
+ let record = {
523
+ v: doc,
524
+ i: docIndex,
525
+ n: this.norm.get(doc)
526
+ };
527
+ this.records.push(record);
528
+ }
529
+ _addObject(doc, docIndex) {
530
+ let record = { i: docIndex, $: {} };
531
+ this.keys.forEach((key, keyIndex) => {
532
+ let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
533
+ if (!isDefined(value)) {
534
+ return;
535
+ }
536
+ if (isArray(value)) {
537
+ let subRecords = [];
538
+ const stack = [{ nestedArrIndex: -1, value }];
539
+ while (stack.length) {
540
+ const { nestedArrIndex, value: value2 } = stack.pop();
541
+ if (!isDefined(value2)) {
542
+ continue;
543
+ }
544
+ if (isString(value2) && !isBlank(value2)) {
545
+ let subRecord = {
546
+ v: value2,
547
+ i: nestedArrIndex,
548
+ n: this.norm.get(value2)
549
+ };
550
+ subRecords.push(subRecord);
551
+ } else if (isArray(value2)) {
552
+ value2.forEach((item, k) => {
553
+ stack.push({
554
+ nestedArrIndex: k,
555
+ value: item
556
+ });
557
+ });
558
+ } else
559
+ ;
560
+ }
561
+ record.$[keyIndex] = subRecords;
562
+ } else if (isString(value) && !isBlank(value)) {
563
+ let subRecord = {
564
+ v: value,
565
+ n: this.norm.get(value)
566
+ };
567
+ record.$[keyIndex] = subRecord;
568
+ }
569
+ });
570
+ this.records.push(record);
571
+ }
572
+ toJSON() {
573
+ return {
574
+ keys: this.keys,
575
+ records: this.records
576
+ };
577
+ }
578
+ }
579
+ function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
580
+ const myIndex = new FuseIndex({ getFn, fieldNormWeight });
581
+ myIndex.setKeys(keys.map(createKey));
582
+ myIndex.setSources(docs);
583
+ myIndex.create();
584
+ return myIndex;
585
+ }
586
+ function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
587
+ const { keys, records } = data;
588
+ const myIndex = new FuseIndex({ getFn, fieldNormWeight });
589
+ myIndex.setKeys(keys);
590
+ myIndex.setIndexRecords(records);
591
+ return myIndex;
592
+ }
593
+ function computeScore$1(pattern, {
594
+ errors = 0,
595
+ currentLocation = 0,
596
+ expectedLocation = 0,
597
+ distance = Config.distance,
598
+ ignoreLocation = Config.ignoreLocation
599
+ } = {}) {
600
+ const accuracy = errors / pattern.length;
601
+ if (ignoreLocation) {
602
+ return accuracy;
603
+ }
604
+ const proximity = Math.abs(expectedLocation - currentLocation);
605
+ if (!distance) {
606
+ return proximity ? 1 : accuracy;
607
+ }
608
+ return accuracy + proximity / distance;
609
+ }
610
+ function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
611
+ let indices = [];
612
+ let start = -1;
613
+ let end = -1;
614
+ let i = 0;
615
+ for (let len = matchmask.length;i < len; i += 1) {
616
+ let match = matchmask[i];
617
+ if (match && start === -1) {
618
+ start = i;
619
+ } else if (!match && start !== -1) {
620
+ end = i - 1;
621
+ if (end - start + 1 >= minMatchCharLength) {
622
+ indices.push([start, end]);
623
+ }
624
+ start = -1;
625
+ }
626
+ }
627
+ if (matchmask[i - 1] && i - start >= minMatchCharLength) {
628
+ indices.push([start, i - 1]);
629
+ }
630
+ return indices;
631
+ }
632
+ var MAX_BITS = 32;
633
+ function search(text, pattern, patternAlphabet, {
634
+ location = Config.location,
635
+ distance = Config.distance,
636
+ threshold = Config.threshold,
637
+ findAllMatches = Config.findAllMatches,
638
+ minMatchCharLength = Config.minMatchCharLength,
639
+ includeMatches = Config.includeMatches,
640
+ ignoreLocation = Config.ignoreLocation
641
+ } = {}) {
642
+ if (pattern.length > MAX_BITS) {
643
+ throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
644
+ }
645
+ const patternLen = pattern.length;
646
+ const textLen = text.length;
647
+ const expectedLocation = Math.max(0, Math.min(location, textLen));
648
+ let currentThreshold = threshold;
649
+ let bestLocation = expectedLocation;
650
+ const computeMatches = minMatchCharLength > 1 || includeMatches;
651
+ const matchMask = computeMatches ? Array(textLen) : [];
652
+ let index;
653
+ while ((index = text.indexOf(pattern, bestLocation)) > -1) {
654
+ let score = computeScore$1(pattern, {
655
+ currentLocation: index,
656
+ expectedLocation,
657
+ distance,
658
+ ignoreLocation
659
+ });
660
+ currentThreshold = Math.min(score, currentThreshold);
661
+ bestLocation = index + patternLen;
662
+ if (computeMatches) {
663
+ let i = 0;
664
+ while (i < patternLen) {
665
+ matchMask[index + i] = 1;
666
+ i += 1;
667
+ }
668
+ }
669
+ }
670
+ bestLocation = -1;
671
+ let lastBitArr = [];
672
+ let finalScore = 1;
673
+ let binMax = patternLen + textLen;
674
+ const mask = 1 << patternLen - 1;
675
+ for (let i = 0;i < patternLen; i += 1) {
676
+ let binMin = 0;
677
+ let binMid = binMax;
678
+ while (binMin < binMid) {
679
+ const score2 = computeScore$1(pattern, {
680
+ errors: i,
681
+ currentLocation: expectedLocation + binMid,
682
+ expectedLocation,
683
+ distance,
684
+ ignoreLocation
685
+ });
686
+ if (score2 <= currentThreshold) {
687
+ binMin = binMid;
688
+ } else {
689
+ binMax = binMid;
690
+ }
691
+ binMid = Math.floor((binMax - binMin) / 2 + binMin);
692
+ }
693
+ binMax = binMid;
694
+ let start = Math.max(1, expectedLocation - binMid + 1);
695
+ let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
696
+ let bitArr = Array(finish + 2);
697
+ bitArr[finish + 1] = (1 << i) - 1;
698
+ for (let j = finish;j >= start; j -= 1) {
699
+ let currentLocation = j - 1;
700
+ let charMatch = patternAlphabet[text.charAt(currentLocation)];
701
+ if (computeMatches) {
702
+ matchMask[currentLocation] = +!!charMatch;
703
+ }
704
+ bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
705
+ if (i) {
706
+ bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
707
+ }
708
+ if (bitArr[j] & mask) {
709
+ finalScore = computeScore$1(pattern, {
710
+ errors: i,
711
+ currentLocation,
712
+ expectedLocation,
713
+ distance,
714
+ ignoreLocation
715
+ });
716
+ if (finalScore <= currentThreshold) {
717
+ currentThreshold = finalScore;
718
+ bestLocation = currentLocation;
719
+ if (bestLocation <= expectedLocation) {
720
+ break;
721
+ }
722
+ start = Math.max(1, 2 * expectedLocation - bestLocation);
723
+ }
724
+ }
725
+ }
726
+ const score = computeScore$1(pattern, {
727
+ errors: i + 1,
728
+ currentLocation: expectedLocation,
729
+ expectedLocation,
730
+ distance,
731
+ ignoreLocation
732
+ });
733
+ if (score > currentThreshold) {
734
+ break;
735
+ }
736
+ lastBitArr = bitArr;
737
+ }
738
+ const result = {
739
+ isMatch: bestLocation >= 0,
740
+ score: Math.max(0.001, finalScore)
741
+ };
742
+ if (computeMatches) {
743
+ const indices = convertMaskToIndices(matchMask, minMatchCharLength);
744
+ if (!indices.length) {
745
+ result.isMatch = false;
746
+ } else if (includeMatches) {
747
+ result.indices = indices;
748
+ }
749
+ }
750
+ return result;
751
+ }
752
+ function createPatternAlphabet(pattern) {
753
+ let mask = {};
754
+ for (let i = 0, len = pattern.length;i < len; i += 1) {
755
+ const char = pattern.charAt(i);
756
+ mask[char] = (mask[char] || 0) | 1 << len - i - 1;
757
+ }
758
+ return mask;
759
+ }
760
+ var stripDiacritics = String.prototype.normalize ? (str) => str.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "") : (str) => str;
761
+
762
+ class BitapSearch {
763
+ constructor(pattern, {
764
+ location = Config.location,
765
+ threshold = Config.threshold,
766
+ distance = Config.distance,
767
+ includeMatches = Config.includeMatches,
768
+ findAllMatches = Config.findAllMatches,
769
+ minMatchCharLength = Config.minMatchCharLength,
770
+ isCaseSensitive = Config.isCaseSensitive,
771
+ ignoreDiacritics = Config.ignoreDiacritics,
772
+ ignoreLocation = Config.ignoreLocation
773
+ } = {}) {
774
+ this.options = {
775
+ location,
776
+ threshold,
777
+ distance,
778
+ includeMatches,
779
+ findAllMatches,
780
+ minMatchCharLength,
781
+ isCaseSensitive,
782
+ ignoreDiacritics,
783
+ ignoreLocation
784
+ };
785
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
786
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
787
+ this.pattern = pattern;
788
+ this.chunks = [];
789
+ if (!this.pattern.length) {
790
+ return;
791
+ }
792
+ const addChunk = (pattern2, startIndex) => {
793
+ this.chunks.push({
794
+ pattern: pattern2,
795
+ alphabet: createPatternAlphabet(pattern2),
796
+ startIndex
797
+ });
798
+ };
799
+ const len = this.pattern.length;
800
+ if (len > MAX_BITS) {
801
+ let i = 0;
802
+ const remainder = len % MAX_BITS;
803
+ const end = len - remainder;
804
+ while (i < end) {
805
+ addChunk(this.pattern.substr(i, MAX_BITS), i);
806
+ i += MAX_BITS;
807
+ }
808
+ if (remainder) {
809
+ const startIndex = len - MAX_BITS;
810
+ addChunk(this.pattern.substr(startIndex), startIndex);
811
+ }
812
+ } else {
813
+ addChunk(this.pattern, 0);
814
+ }
815
+ }
816
+ searchIn(text) {
817
+ const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
818
+ text = isCaseSensitive ? text : text.toLowerCase();
819
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
820
+ if (this.pattern === text) {
821
+ let result2 = {
822
+ isMatch: true,
823
+ score: 0
824
+ };
825
+ if (includeMatches) {
826
+ result2.indices = [[0, text.length - 1]];
827
+ }
828
+ return result2;
829
+ }
830
+ const {
831
+ location,
832
+ distance,
833
+ threshold,
834
+ findAllMatches,
835
+ minMatchCharLength,
836
+ ignoreLocation
837
+ } = this.options;
838
+ let allIndices = [];
839
+ let totalScore = 0;
840
+ let hasMatches = false;
841
+ this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
842
+ const { isMatch, score, indices } = search(text, pattern, alphabet, {
843
+ location: location + startIndex,
844
+ distance,
845
+ threshold,
846
+ findAllMatches,
847
+ minMatchCharLength,
848
+ includeMatches,
849
+ ignoreLocation
850
+ });
851
+ if (isMatch) {
852
+ hasMatches = true;
853
+ }
854
+ totalScore += score;
855
+ if (isMatch && indices) {
856
+ allIndices = [...allIndices, ...indices];
857
+ }
858
+ });
859
+ let result = {
860
+ isMatch: hasMatches,
861
+ score: hasMatches ? totalScore / this.chunks.length : 1
862
+ };
863
+ if (hasMatches && includeMatches) {
864
+ result.indices = allIndices;
865
+ }
866
+ return result;
867
+ }
868
+ }
869
+
870
+ class BaseMatch {
871
+ constructor(pattern) {
872
+ this.pattern = pattern;
873
+ }
874
+ static isMultiMatch(pattern) {
875
+ return getMatch(pattern, this.multiRegex);
876
+ }
877
+ static isSingleMatch(pattern) {
878
+ return getMatch(pattern, this.singleRegex);
879
+ }
880
+ search() {}
881
+ }
882
+ function getMatch(pattern, exp) {
883
+ const matches = pattern.match(exp);
884
+ return matches ? matches[1] : null;
885
+ }
886
+
887
+ class ExactMatch extends BaseMatch {
888
+ constructor(pattern) {
889
+ super(pattern);
890
+ }
891
+ static get type() {
892
+ return "exact";
893
+ }
894
+ static get multiRegex() {
895
+ return /^="(.*)"$/;
896
+ }
897
+ static get singleRegex() {
898
+ return /^=(.*)$/;
899
+ }
900
+ search(text) {
901
+ const isMatch = text === this.pattern;
902
+ return {
903
+ isMatch,
904
+ score: isMatch ? 0 : 1,
905
+ indices: [0, this.pattern.length - 1]
906
+ };
907
+ }
908
+ }
909
+
910
+ class InverseExactMatch extends BaseMatch {
911
+ constructor(pattern) {
912
+ super(pattern);
913
+ }
914
+ static get type() {
915
+ return "inverse-exact";
916
+ }
917
+ static get multiRegex() {
918
+ return /^!"(.*)"$/;
919
+ }
920
+ static get singleRegex() {
921
+ return /^!(.*)$/;
922
+ }
923
+ search(text) {
924
+ const index = text.indexOf(this.pattern);
925
+ const isMatch = index === -1;
926
+ return {
927
+ isMatch,
928
+ score: isMatch ? 0 : 1,
929
+ indices: [0, text.length - 1]
930
+ };
931
+ }
932
+ }
933
+
934
+ class PrefixExactMatch extends BaseMatch {
935
+ constructor(pattern) {
936
+ super(pattern);
937
+ }
938
+ static get type() {
939
+ return "prefix-exact";
940
+ }
941
+ static get multiRegex() {
942
+ return /^\^"(.*)"$/;
943
+ }
944
+ static get singleRegex() {
945
+ return /^\^(.*)$/;
946
+ }
947
+ search(text) {
948
+ const isMatch = text.startsWith(this.pattern);
949
+ return {
950
+ isMatch,
951
+ score: isMatch ? 0 : 1,
952
+ indices: [0, this.pattern.length - 1]
953
+ };
954
+ }
955
+ }
956
+
957
+ class InversePrefixExactMatch extends BaseMatch {
958
+ constructor(pattern) {
959
+ super(pattern);
960
+ }
961
+ static get type() {
962
+ return "inverse-prefix-exact";
963
+ }
964
+ static get multiRegex() {
965
+ return /^!\^"(.*)"$/;
966
+ }
967
+ static get singleRegex() {
968
+ return /^!\^(.*)$/;
969
+ }
970
+ search(text) {
971
+ const isMatch = !text.startsWith(this.pattern);
972
+ return {
973
+ isMatch,
974
+ score: isMatch ? 0 : 1,
975
+ indices: [0, text.length - 1]
976
+ };
977
+ }
978
+ }
979
+
980
+ class SuffixExactMatch extends BaseMatch {
981
+ constructor(pattern) {
982
+ super(pattern);
983
+ }
984
+ static get type() {
985
+ return "suffix-exact";
986
+ }
987
+ static get multiRegex() {
988
+ return /^"(.*)"\$$/;
989
+ }
990
+ static get singleRegex() {
991
+ return /^(.*)\$$/;
992
+ }
993
+ search(text) {
994
+ const isMatch = text.endsWith(this.pattern);
995
+ return {
996
+ isMatch,
997
+ score: isMatch ? 0 : 1,
998
+ indices: [text.length - this.pattern.length, text.length - 1]
999
+ };
1000
+ }
1001
+ }
1002
+
1003
+ class InverseSuffixExactMatch extends BaseMatch {
1004
+ constructor(pattern) {
1005
+ super(pattern);
1006
+ }
1007
+ static get type() {
1008
+ return "inverse-suffix-exact";
1009
+ }
1010
+ static get multiRegex() {
1011
+ return /^!"(.*)"\$$/;
1012
+ }
1013
+ static get singleRegex() {
1014
+ return /^!(.*)\$$/;
1015
+ }
1016
+ search(text) {
1017
+ const isMatch = !text.endsWith(this.pattern);
1018
+ return {
1019
+ isMatch,
1020
+ score: isMatch ? 0 : 1,
1021
+ indices: [0, text.length - 1]
1022
+ };
1023
+ }
1024
+ }
1025
+
1026
+ class FuzzyMatch extends BaseMatch {
1027
+ constructor(pattern, {
1028
+ location = Config.location,
1029
+ threshold = Config.threshold,
1030
+ distance = Config.distance,
1031
+ includeMatches = Config.includeMatches,
1032
+ findAllMatches = Config.findAllMatches,
1033
+ minMatchCharLength = Config.minMatchCharLength,
1034
+ isCaseSensitive = Config.isCaseSensitive,
1035
+ ignoreDiacritics = Config.ignoreDiacritics,
1036
+ ignoreLocation = Config.ignoreLocation
1037
+ } = {}) {
1038
+ super(pattern);
1039
+ this._bitapSearch = new BitapSearch(pattern, {
1040
+ location,
1041
+ threshold,
1042
+ distance,
1043
+ includeMatches,
1044
+ findAllMatches,
1045
+ minMatchCharLength,
1046
+ isCaseSensitive,
1047
+ ignoreDiacritics,
1048
+ ignoreLocation
1049
+ });
1050
+ }
1051
+ static get type() {
1052
+ return "fuzzy";
1053
+ }
1054
+ static get multiRegex() {
1055
+ return /^"(.*)"$/;
1056
+ }
1057
+ static get singleRegex() {
1058
+ return /^(.*)$/;
1059
+ }
1060
+ search(text) {
1061
+ return this._bitapSearch.searchIn(text);
1062
+ }
1063
+ }
1064
+
1065
+ class IncludeMatch extends BaseMatch {
1066
+ constructor(pattern) {
1067
+ super(pattern);
1068
+ }
1069
+ static get type() {
1070
+ return "include";
1071
+ }
1072
+ static get multiRegex() {
1073
+ return /^'"(.*)"$/;
1074
+ }
1075
+ static get singleRegex() {
1076
+ return /^'(.*)$/;
1077
+ }
1078
+ search(text) {
1079
+ let location = 0;
1080
+ let index;
1081
+ const indices = [];
1082
+ const patternLen = this.pattern.length;
1083
+ while ((index = text.indexOf(this.pattern, location)) > -1) {
1084
+ location = index + patternLen;
1085
+ indices.push([index, location - 1]);
1086
+ }
1087
+ const isMatch = !!indices.length;
1088
+ return {
1089
+ isMatch,
1090
+ score: isMatch ? 0 : 1,
1091
+ indices
1092
+ };
1093
+ }
1094
+ }
1095
+ var searchers = [
1096
+ ExactMatch,
1097
+ IncludeMatch,
1098
+ PrefixExactMatch,
1099
+ InversePrefixExactMatch,
1100
+ InverseSuffixExactMatch,
1101
+ SuffixExactMatch,
1102
+ InverseExactMatch,
1103
+ FuzzyMatch
1104
+ ];
1105
+ var searchersLen = searchers.length;
1106
+ var SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
1107
+ var OR_TOKEN = "|";
1108
+ function parseQuery2(pattern, options = {}) {
1109
+ return pattern.split(OR_TOKEN).map((item) => {
1110
+ let query = item.trim().split(SPACE_RE).filter((item2) => item2 && !!item2.trim());
1111
+ let results = [];
1112
+ for (let i = 0, len = query.length;i < len; i += 1) {
1113
+ const queryItem = query[i];
1114
+ let found = false;
1115
+ let idx = -1;
1116
+ while (!found && ++idx < searchersLen) {
1117
+ const searcher = searchers[idx];
1118
+ let token = searcher.isMultiMatch(queryItem);
1119
+ if (token) {
1120
+ results.push(new searcher(token, options));
1121
+ found = true;
1122
+ }
1123
+ }
1124
+ if (found) {
1125
+ continue;
1126
+ }
1127
+ idx = -1;
1128
+ while (++idx < searchersLen) {
1129
+ const searcher = searchers[idx];
1130
+ let token = searcher.isSingleMatch(queryItem);
1131
+ if (token) {
1132
+ results.push(new searcher(token, options));
1133
+ break;
1134
+ }
1135
+ }
1136
+ }
1137
+ return results;
1138
+ });
1139
+ }
1140
+ var MultiMatchSet = new Set([FuzzyMatch.type, IncludeMatch.type]);
1141
+
1142
+ class ExtendedSearch {
1143
+ constructor(pattern, {
1144
+ isCaseSensitive = Config.isCaseSensitive,
1145
+ ignoreDiacritics = Config.ignoreDiacritics,
1146
+ includeMatches = Config.includeMatches,
1147
+ minMatchCharLength = Config.minMatchCharLength,
1148
+ ignoreLocation = Config.ignoreLocation,
1149
+ findAllMatches = Config.findAllMatches,
1150
+ location = Config.location,
1151
+ threshold = Config.threshold,
1152
+ distance = Config.distance
1153
+ } = {}) {
1154
+ this.query = null;
1155
+ this.options = {
1156
+ isCaseSensitive,
1157
+ ignoreDiacritics,
1158
+ includeMatches,
1159
+ minMatchCharLength,
1160
+ findAllMatches,
1161
+ ignoreLocation,
1162
+ location,
1163
+ threshold,
1164
+ distance
1165
+ };
1166
+ pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
1167
+ pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
1168
+ this.pattern = pattern;
1169
+ this.query = parseQuery2(this.pattern, this.options);
1170
+ }
1171
+ static condition(_, options) {
1172
+ return options.useExtendedSearch;
1173
+ }
1174
+ searchIn(text) {
1175
+ const query = this.query;
1176
+ if (!query) {
1177
+ return {
1178
+ isMatch: false,
1179
+ score: 1
1180
+ };
1181
+ }
1182
+ const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
1183
+ text = isCaseSensitive ? text : text.toLowerCase();
1184
+ text = ignoreDiacritics ? stripDiacritics(text) : text;
1185
+ let numMatches = 0;
1186
+ let allIndices = [];
1187
+ let totalScore = 0;
1188
+ for (let i = 0, qLen = query.length;i < qLen; i += 1) {
1189
+ const searchers2 = query[i];
1190
+ allIndices.length = 0;
1191
+ numMatches = 0;
1192
+ for (let j = 0, pLen = searchers2.length;j < pLen; j += 1) {
1193
+ const searcher = searchers2[j];
1194
+ const { isMatch, indices, score } = searcher.search(text);
1195
+ if (isMatch) {
1196
+ numMatches += 1;
1197
+ totalScore += score;
1198
+ if (includeMatches) {
1199
+ const type = searcher.constructor.type;
1200
+ if (MultiMatchSet.has(type)) {
1201
+ allIndices = [...allIndices, ...indices];
1202
+ } else {
1203
+ allIndices.push(indices);
1204
+ }
1205
+ }
1206
+ } else {
1207
+ totalScore = 0;
1208
+ numMatches = 0;
1209
+ allIndices.length = 0;
1210
+ break;
1211
+ }
1212
+ }
1213
+ if (numMatches) {
1214
+ let result = {
1215
+ isMatch: true,
1216
+ score: totalScore / numMatches
1217
+ };
1218
+ if (includeMatches) {
1219
+ result.indices = allIndices;
1220
+ }
1221
+ return result;
1222
+ }
1223
+ }
1224
+ return {
1225
+ isMatch: false,
1226
+ score: 1
1227
+ };
1228
+ }
1229
+ }
1230
+ var registeredSearchers = [];
1231
+ function register(...args) {
1232
+ registeredSearchers.push(...args);
1233
+ }
1234
+ function createSearcher(pattern, options) {
1235
+ for (let i = 0, len = registeredSearchers.length;i < len; i += 1) {
1236
+ let searcherClass = registeredSearchers[i];
1237
+ if (searcherClass.condition(pattern, options)) {
1238
+ return new searcherClass(pattern, options);
1239
+ }
1240
+ }
1241
+ return new BitapSearch(pattern, options);
1242
+ }
1243
+ var LogicalOperator = {
1244
+ AND: "$and",
1245
+ OR: "$or"
1246
+ };
1247
+ var KeyType = {
1248
+ PATH: "$path",
1249
+ PATTERN: "$val"
1250
+ };
1251
+ var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
1252
+ var isPath = (query) => !!query[KeyType.PATH];
1253
+ var isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
1254
+ var convertToExplicit = (query) => ({
1255
+ [LogicalOperator.AND]: Object.keys(query).map((key) => ({
1256
+ [key]: query[key]
1257
+ }))
1258
+ });
1259
+ function parse(query, options, { auto = true } = {}) {
1260
+ const next = (query2) => {
1261
+ let keys = Object.keys(query2);
1262
+ const isQueryPath = isPath(query2);
1263
+ if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
1264
+ return next(convertToExplicit(query2));
1265
+ }
1266
+ if (isLeaf(query2)) {
1267
+ const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
1268
+ const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
1269
+ if (!isString(pattern)) {
1270
+ throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
1271
+ }
1272
+ const obj = {
1273
+ keyId: createKeyId(key),
1274
+ pattern
1275
+ };
1276
+ if (auto) {
1277
+ obj.searcher = createSearcher(pattern, options);
1278
+ }
1279
+ return obj;
1280
+ }
1281
+ let node = {
1282
+ children: [],
1283
+ operator: keys[0]
1284
+ };
1285
+ keys.forEach((key) => {
1286
+ const value = query2[key];
1287
+ if (isArray(value)) {
1288
+ value.forEach((item) => {
1289
+ node.children.push(next(item));
1290
+ });
1291
+ }
1292
+ });
1293
+ return node;
1294
+ };
1295
+ if (!isExpression(query)) {
1296
+ query = convertToExplicit(query);
1297
+ }
1298
+ return next(query);
1299
+ }
1300
+ function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
1301
+ results.forEach((result) => {
1302
+ let totalScore = 1;
1303
+ result.matches.forEach(({ key, norm: norm2, score }) => {
1304
+ const weight = key ? key.weight : null;
1305
+ totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm2));
1306
+ });
1307
+ result.score = totalScore;
1308
+ });
1309
+ }
1310
+ function transformMatches(result, data) {
1311
+ const matches = result.matches;
1312
+ data.matches = [];
1313
+ if (!isDefined(matches)) {
1314
+ return;
1315
+ }
1316
+ matches.forEach((match) => {
1317
+ if (!isDefined(match.indices) || !match.indices.length) {
1318
+ return;
1319
+ }
1320
+ const { indices, value } = match;
1321
+ let obj = {
1322
+ indices,
1323
+ value
1324
+ };
1325
+ if (match.key) {
1326
+ obj.key = match.key.src;
1327
+ }
1328
+ if (match.idx > -1) {
1329
+ obj.refIndex = match.idx;
1330
+ }
1331
+ data.matches.push(obj);
1332
+ });
1333
+ }
1334
+ function transformScore(result, data) {
1335
+ data.score = result.score;
1336
+ }
1337
+ function format(results, docs, {
1338
+ includeMatches = Config.includeMatches,
1339
+ includeScore = Config.includeScore
1340
+ } = {}) {
1341
+ const transformers = [];
1342
+ if (includeMatches)
1343
+ transformers.push(transformMatches);
1344
+ if (includeScore)
1345
+ transformers.push(transformScore);
1346
+ return results.map((result) => {
1347
+ const { idx } = result;
1348
+ const data = {
1349
+ item: docs[idx],
1350
+ refIndex: idx
1351
+ };
1352
+ if (transformers.length) {
1353
+ transformers.forEach((transformer) => {
1354
+ transformer(result, data);
1355
+ });
1356
+ }
1357
+ return data;
1358
+ });
1359
+ }
1360
+
1361
+ class Fuse {
1362
+ constructor(docs, options = {}, index) {
1363
+ this.options = { ...Config, ...options };
1364
+ if (this.options.useExtendedSearch && false) {}
1365
+ this._keyStore = new KeyStore(this.options.keys);
1366
+ this.setCollection(docs, index);
1367
+ }
1368
+ setCollection(docs, index) {
1369
+ this._docs = docs;
1370
+ if (index && !(index instanceof FuseIndex)) {
1371
+ throw new Error(INCORRECT_INDEX_TYPE);
1372
+ }
1373
+ this._myIndex = index || createIndex(this.options.keys, this._docs, {
1374
+ getFn: this.options.getFn,
1375
+ fieldNormWeight: this.options.fieldNormWeight
1376
+ });
1377
+ }
1378
+ add(doc) {
1379
+ if (!isDefined(doc)) {
1380
+ return;
1381
+ }
1382
+ this._docs.push(doc);
1383
+ this._myIndex.add(doc);
1384
+ }
1385
+ remove(predicate = () => false) {
1386
+ const results = [];
1387
+ for (let i = 0, len = this._docs.length;i < len; i += 1) {
1388
+ const doc = this._docs[i];
1389
+ if (predicate(doc, i)) {
1390
+ this.removeAt(i);
1391
+ i -= 1;
1392
+ len -= 1;
1393
+ results.push(doc);
1394
+ }
1395
+ }
1396
+ return results;
1397
+ }
1398
+ removeAt(idx) {
1399
+ this._docs.splice(idx, 1);
1400
+ this._myIndex.removeAt(idx);
1401
+ }
1402
+ getIndex() {
1403
+ return this._myIndex;
1404
+ }
1405
+ search(query, { limit = -1 } = {}) {
1406
+ const {
1407
+ includeMatches,
1408
+ includeScore,
1409
+ shouldSort,
1410
+ sortFn,
1411
+ ignoreFieldNorm
1412
+ } = this.options;
1413
+ let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
1414
+ computeScore(results, { ignoreFieldNorm });
1415
+ if (shouldSort) {
1416
+ results.sort(sortFn);
1417
+ }
1418
+ if (isNumber(limit) && limit > -1) {
1419
+ results = results.slice(0, limit);
1420
+ }
1421
+ return format(results, this._docs, {
1422
+ includeMatches,
1423
+ includeScore
1424
+ });
1425
+ }
1426
+ _searchStringList(query) {
1427
+ const searcher = createSearcher(query, this.options);
1428
+ const { records } = this._myIndex;
1429
+ const results = [];
1430
+ records.forEach(({ v: text, i: idx, n: norm2 }) => {
1431
+ if (!isDefined(text)) {
1432
+ return;
1433
+ }
1434
+ const { isMatch, score, indices } = searcher.searchIn(text);
1435
+ if (isMatch) {
1436
+ results.push({
1437
+ item: text,
1438
+ idx,
1439
+ matches: [{ score, value: text, norm: norm2, indices }]
1440
+ });
1441
+ }
1442
+ });
1443
+ return results;
1444
+ }
1445
+ _searchLogical(query) {
1446
+ const expression = parse(query, this.options);
1447
+ const evaluate = (node, item, idx) => {
1448
+ if (!node.children) {
1449
+ const { keyId, searcher } = node;
1450
+ const matches = this._findMatches({
1451
+ key: this._keyStore.get(keyId),
1452
+ value: this._myIndex.getValueForItemAtKeyId(item, keyId),
1453
+ searcher
1454
+ });
1455
+ if (matches && matches.length) {
1456
+ return [
1457
+ {
1458
+ idx,
1459
+ item,
1460
+ matches
1461
+ }
1462
+ ];
1463
+ }
1464
+ return [];
1465
+ }
1466
+ const res = [];
1467
+ for (let i = 0, len = node.children.length;i < len; i += 1) {
1468
+ const child = node.children[i];
1469
+ const result = evaluate(child, item, idx);
1470
+ if (result.length) {
1471
+ res.push(...result);
1472
+ } else if (node.operator === LogicalOperator.AND) {
1473
+ return [];
1474
+ }
1475
+ }
1476
+ return res;
1477
+ };
1478
+ const records = this._myIndex.records;
1479
+ const resultMap = {};
1480
+ const results = [];
1481
+ records.forEach(({ $: item, i: idx }) => {
1482
+ if (isDefined(item)) {
1483
+ let expResults = evaluate(expression, item, idx);
1484
+ if (expResults.length) {
1485
+ if (!resultMap[idx]) {
1486
+ resultMap[idx] = { idx, item, matches: [] };
1487
+ results.push(resultMap[idx]);
1488
+ }
1489
+ expResults.forEach(({ matches }) => {
1490
+ resultMap[idx].matches.push(...matches);
1491
+ });
1492
+ }
1493
+ }
1494
+ });
1495
+ return results;
1496
+ }
1497
+ _searchObjectList(query) {
1498
+ const searcher = createSearcher(query, this.options);
1499
+ const { keys, records } = this._myIndex;
1500
+ const results = [];
1501
+ records.forEach(({ $: item, i: idx }) => {
1502
+ if (!isDefined(item)) {
1503
+ return;
1504
+ }
1505
+ let matches = [];
1506
+ keys.forEach((key, keyIndex) => {
1507
+ matches.push(...this._findMatches({
1508
+ key,
1509
+ value: item[keyIndex],
1510
+ searcher
1511
+ }));
1512
+ });
1513
+ if (matches.length) {
1514
+ results.push({
1515
+ idx,
1516
+ item,
1517
+ matches
1518
+ });
1519
+ }
1520
+ });
1521
+ return results;
1522
+ }
1523
+ _findMatches({ key, value, searcher }) {
1524
+ if (!isDefined(value)) {
1525
+ return [];
1526
+ }
1527
+ let matches = [];
1528
+ if (isArray(value)) {
1529
+ value.forEach(({ v: text, i: idx, n: norm2 }) => {
1530
+ if (!isDefined(text)) {
1531
+ return;
1532
+ }
1533
+ const { isMatch, score, indices } = searcher.searchIn(text);
1534
+ if (isMatch) {
1535
+ matches.push({
1536
+ score,
1537
+ key,
1538
+ value: text,
1539
+ idx,
1540
+ norm: norm2,
1541
+ indices
1542
+ });
1543
+ }
1544
+ });
1545
+ } else {
1546
+ const { v: text, n: norm2 } = value;
1547
+ const { isMatch, score, indices } = searcher.searchIn(text);
1548
+ if (isMatch) {
1549
+ matches.push({ score, key, value: text, norm: norm2, indices });
1550
+ }
1551
+ }
1552
+ return matches;
1553
+ }
1554
+ }
1555
+ Fuse.version = "7.1.0";
1556
+ Fuse.createIndex = createIndex;
1557
+ Fuse.parseIndex = parseIndex;
1558
+ Fuse.config = Config;
1559
+ {
1560
+ Fuse.parseQuery = parse;
1561
+ }
1562
+ {
1563
+ register(ExtendedSearch);
1564
+ }
1565
+
1566
+ // ../core/src/lib/search.ts
1567
+ var FUSE_OPTIONS = {
1568
+ keys: [
1569
+ { name: "frontmatter.title", weight: 1 },
1570
+ { name: "frontmatter.description", weight: 0.7 },
1571
+ { name: "frontmatter.labels", weight: 0.5 },
1572
+ { name: "content", weight: 0.3 }
1573
+ ],
1574
+ threshold: 0.4,
1575
+ ignoreLocation: true,
1576
+ includeScore: true
1577
+ };
1578
+ function createSearchIndex(issues) {
1579
+ return new Fuse(issues, FUSE_OPTIONS);
1580
+ }
1581
+ function filterIssues(issues, filters) {
1582
+ return issues.filter((issue) => {
1583
+ if (filters.status && issue.frontmatter.status !== filters.status) {
1584
+ return false;
1585
+ }
1586
+ if (filters.priority && issue.frontmatter.priority !== filters.priority) {
1587
+ return false;
1588
+ }
1589
+ if (filters.type && issue.frontmatter.type !== filters.type) {
1590
+ return false;
1591
+ }
1592
+ return true;
1593
+ });
1594
+ }
1595
+ function filterAndSearchIssues(issues, filters) {
1596
+ let result = filterIssues(issues, filters);
1597
+ if (filters.search?.trim()) {
1598
+ const query = filters.search.trim();
1599
+ const idMatches = [];
1600
+ const nonIdMatches = [];
1601
+ const normalizedQuery = query.replace(/^0+/, "");
1602
+ for (const issue of result) {
1603
+ const normalizedId = issue.id.replace(/^0+/, "");
1604
+ if (normalizedId.startsWith(normalizedQuery) || issue.id.startsWith(query)) {
1605
+ idMatches.push(issue);
1606
+ }
1607
+ }
1608
+ const fuse = createSearchIndex(issues);
1609
+ const searchResults = fuse.search(query);
1610
+ const matchedIds = new Set(searchResults.map((r) => r.item.id));
1611
+ const idMatchSet = new Set(idMatches.map((i) => i.id));
1612
+ for (const issue of result) {
1613
+ if (!idMatchSet.has(issue.id) && matchedIds.has(issue.id)) {
1614
+ nonIdMatches.push(issue);
1615
+ }
1616
+ }
1617
+ nonIdMatches.sort((a, b) => {
1618
+ const aScore = searchResults.find((r) => r.item.id === a.id)?.score ?? 1;
1619
+ const bScore = searchResults.find((r) => r.item.id === b.id)?.score ?? 1;
1620
+ return aScore - bScore;
1621
+ });
1622
+ result = [...idMatches, ...nonIdMatches];
1623
+ }
1624
+ return result;
1625
+ }
1626
+ function sortIssues(issues, sortBy) {
1627
+ const sortOption = sortBy.toLowerCase();
1628
+ if (sortOption === "priority") {
1629
+ const priorityOrder = {
1630
+ high: 0,
1631
+ medium: 1,
1632
+ low: 2
1633
+ };
1634
+ issues.sort((a, b) => {
1635
+ const priorityA = priorityOrder[a.frontmatter.priority] ?? 999;
1636
+ const priorityB = priorityOrder[b.frontmatter.priority] ?? 999;
1637
+ if (priorityA !== priorityB)
1638
+ return priorityA - priorityB;
1639
+ return b.id.localeCompare(a.id);
1640
+ });
1641
+ } else if (sortOption === "created") {
1642
+ issues.sort((a, b) => {
1643
+ const dateA = a.frontmatter.created || "";
1644
+ const dateB = b.frontmatter.created || "";
1645
+ if (dateA !== dateB)
1646
+ return dateB.localeCompare(dateA);
1647
+ return b.id.localeCompare(a.id);
1648
+ });
1649
+ } else if (sortOption === "created-asc") {
1650
+ issues.sort((a, b) => {
1651
+ const dateA = a.frontmatter.created || "";
1652
+ const dateB = b.frontmatter.created || "";
1653
+ if (dateA !== dateB)
1654
+ return dateA.localeCompare(dateB);
1655
+ return a.id.localeCompare(b.id);
1656
+ });
1657
+ } else if (sortOption === "updated") {
1658
+ issues.sort((a, b) => {
1659
+ const dateA = a.frontmatter.updated || a.frontmatter.created || "";
1660
+ const dateB = b.frontmatter.updated || b.frontmatter.created || "";
1661
+ if (dateA !== dateB)
1662
+ return dateB.localeCompare(dateA);
1663
+ return b.id.localeCompare(a.id);
1664
+ });
1665
+ } else if (sortOption === "id") {
1666
+ issues.sort((a, b) => b.id.localeCompare(a.id));
1667
+ } else {
1668
+ const priorityOrder = {
1669
+ high: 0,
1670
+ medium: 1,
1671
+ low: 2
1672
+ };
1673
+ issues.sort((a, b) => {
1674
+ const priorityA = priorityOrder[a.frontmatter.priority] ?? 999;
1675
+ const priorityB = priorityOrder[b.frontmatter.priority] ?? 999;
1676
+ if (priorityA !== priorityB)
1677
+ return priorityA - priorityB;
1678
+ return b.id.localeCompare(a.id);
1679
+ });
1680
+ }
1681
+ }
1682
+ function filterByQuery(issues, query) {
1683
+ const parsed = parseQuery(query);
1684
+ let result = issues.filter((issue) => {
1685
+ if (parsed.qualifiers.is) {
1686
+ const statusValue = parsed.qualifiers.is.toLowerCase();
1687
+ if (statusValue === "open" || statusValue === "closed") {
1688
+ if (issue.frontmatter.status !== statusValue) {
1689
+ return false;
1690
+ }
1691
+ }
1692
+ }
1693
+ if (parsed.qualifiers.priority) {
1694
+ const priorityValue = parsed.qualifiers.priority.toLowerCase();
1695
+ if (priorityValue === "high" || priorityValue === "medium" || priorityValue === "low") {
1696
+ if (issue.frontmatter.priority !== priorityValue) {
1697
+ return false;
1698
+ }
1699
+ }
1700
+ }
1701
+ if (parsed.qualifiers.type) {
1702
+ const typeValue = parsed.qualifiers.type.toLowerCase();
1703
+ if (typeValue === "bug" || typeValue === "improvement") {
1704
+ if (issue.frontmatter.type !== typeValue) {
1705
+ return false;
1706
+ }
1707
+ }
1708
+ }
1709
+ if (parsed.qualifiers.label) {
1710
+ const labelQuery = parsed.qualifiers.label.toLowerCase();
1711
+ const issueLabels = (issue.frontmatter.labels || "").toLowerCase();
1712
+ if (!issueLabels.includes(labelQuery)) {
1713
+ return false;
1714
+ }
1715
+ }
1716
+ return true;
1717
+ });
1718
+ if (!parsed.searchText.trim()) {
1719
+ const sortBy = parsed.qualifiers.sort?.toLowerCase() || "priority";
1720
+ sortIssues(result, sortBy);
1721
+ }
1722
+ if (parsed.searchText.trim()) {
1723
+ const searchQuery = parsed.searchText.trim();
1724
+ const idMatches = [];
1725
+ const nonIdMatches = [];
1726
+ const normalizedQuery = searchQuery.replace(/^0+/, "");
1727
+ for (const issue of result) {
1728
+ const normalizedId = issue.id.replace(/^0+/, "");
1729
+ if (normalizedId.startsWith(normalizedQuery) || issue.id.startsWith(searchQuery)) {
1730
+ idMatches.push(issue);
1731
+ }
1732
+ }
1733
+ const fuse = createSearchIndex(result);
1734
+ const searchResults = fuse.search(searchQuery);
1735
+ const matchedIds = new Set(searchResults.map((r) => r.item.id));
1736
+ const idMatchSet = new Set(idMatches.map((i) => i.id));
1737
+ for (const issue of result) {
1738
+ if (!idMatchSet.has(issue.id) && matchedIds.has(issue.id)) {
1739
+ nonIdMatches.push(issue);
1740
+ }
1741
+ }
1742
+ nonIdMatches.sort((a, b) => {
1743
+ const aScore = searchResults.find((r) => r.item.id === a.id)?.score ?? 1;
1744
+ const bScore = searchResults.find((r) => r.item.id === b.id)?.score ?? 1;
1745
+ return aScore - bScore;
1746
+ });
1747
+ result = [...idMatches, ...nonIdMatches];
1748
+ }
1749
+ return result;
1750
+ }
1751
+ // src/server.ts
1752
+ var DEFAULT_ROOT = process.env.ISSUES_ROOT || process.cwd();
1753
+ var ISSUES_DIR = process.env.ISSUES_DIR || resolve(DEFAULT_ROOT, ".issues");
1754
+ setIssuesDir(ISSUES_DIR);
1755
+ var PORT = Number(process.env.ISSUES_PORT || process.env.PORT || 1554);
1756
+ var __dirname2 = resolve(fileURLToPath(import.meta.url), "..");
1757
+ var distDir = __dirname2.endsWith("dist") ? __dirname2 : resolve(__dirname2, "..", "dist");
1758
+ var mimeTypes = {
1759
+ ".html": "text/html",
1760
+ ".js": "application/javascript",
1761
+ ".css": "text/css",
1762
+ ".json": "application/json",
1763
+ ".png": "image/png",
1764
+ ".svg": "image/svg+xml"
1765
+ };
1766
+ async function parseBody(req) {
1767
+ return new Promise((resolve2, reject) => {
1768
+ let body = "";
1769
+ req.on("data", (chunk) => {
1770
+ body += chunk;
1771
+ });
1772
+ req.on("end", () => {
1773
+ try {
1774
+ resolve2(body ? JSON.parse(body) : {});
1775
+ } catch (e) {
1776
+ reject(e);
1777
+ }
1778
+ });
1779
+ req.on("error", reject);
1780
+ });
1781
+ }
1782
+ function jsonResponse(res, data, status = 200) {
1783
+ res.writeHead(status, { "Content-Type": "application/json" });
1784
+ res.end(JSON.stringify(data));
1785
+ }
1786
+ function matchRoute(pattern, path) {
1787
+ const patternParts = pattern.split("/");
1788
+ const pathParts = path.split("/");
1789
+ if (patternParts.length !== pathParts.length) {
1790
+ return { match: false, params: {} };
1791
+ }
1792
+ const params = {};
1793
+ for (let i = 0;i < patternParts.length; i++) {
1794
+ if (patternParts[i].startsWith(":")) {
1795
+ params[patternParts[i].slice(1)] = pathParts[i];
1796
+ } else if (patternParts[i] !== pathParts[i]) {
1797
+ return { match: false, params: {} };
1798
+ }
1799
+ }
1800
+ return { match: true, params };
1801
+ }
1802
+ var server = createServer(async (req, res) => {
1803
+ const url = new URL(req.url || "/", `http://localhost:${PORT}`);
1804
+ const path = url.pathname;
1805
+ const method = req.method || "GET";
1806
+ try {
1807
+ if (path.startsWith("/api/")) {
1808
+ if (path === "/api/issues" && method === "GET") {
1809
+ const allIssues = await getAllIssues();
1810
+ const query = url.searchParams.get("q");
1811
+ if (query) {
1812
+ return jsonResponse(res, filterByQuery(allIssues, query));
1813
+ }
1814
+ const status = url.searchParams.get("status") || undefined;
1815
+ const priority = url.searchParams.get("priority") || undefined;
1816
+ const type = url.searchParams.get("type") || undefined;
1817
+ const search2 = url.searchParams.get("search") || undefined;
1818
+ if (status || priority || type || search2) {
1819
+ return jsonResponse(res, filterAndSearchIssues(allIssues, {
1820
+ status,
1821
+ priority,
1822
+ type,
1823
+ search: search2
1824
+ }));
1825
+ }
1826
+ return jsonResponse(res, allIssues);
1827
+ }
1828
+ if (path === "/api/issues/create" && method === "POST") {
1829
+ const input = await parseBody(req);
1830
+ const issue = await createIssue(input);
1831
+ return jsonResponse(res, issue, 201);
1832
+ }
1833
+ if (path === "/api/health" && method === "GET") {
1834
+ return jsonResponse(res, { status: "ok", service: "issy" });
1835
+ }
1836
+ const issueMatch = matchRoute("/api/issues/:id", path);
1837
+ if (issueMatch.match) {
1838
+ const { id } = issueMatch.params;
1839
+ if (method === "GET") {
1840
+ const issue = await getIssue(id);
1841
+ if (!issue) {
1842
+ return jsonResponse(res, { error: "Issue not found" }, 404);
1843
+ }
1844
+ return jsonResponse(res, issue);
1845
+ }
1846
+ if (method === "PATCH") {
1847
+ const input = await parseBody(req);
1848
+ const issue = await updateIssue(id, input);
1849
+ return jsonResponse(res, issue);
1850
+ }
1851
+ }
1852
+ const closeMatch = matchRoute("/api/issues/:id/close", path);
1853
+ if (closeMatch.match && method === "POST") {
1854
+ const issue = await closeIssue(closeMatch.params.id);
1855
+ return jsonResponse(res, issue);
1856
+ }
1857
+ const reopenMatch = matchRoute("/api/issues/:id/reopen", path);
1858
+ if (reopenMatch.match && method === "POST") {
1859
+ const issue = await reopenIssue(reopenMatch.params.id);
1860
+ return jsonResponse(res, issue);
1861
+ }
1862
+ const deleteMatch = matchRoute("/api/issues/:id/delete", path);
1863
+ if (deleteMatch.match && method === "DELETE") {
1864
+ await deleteIssue(deleteMatch.params.id);
1865
+ return jsonResponse(res, { success: true });
1866
+ }
1867
+ return jsonResponse(res, { error: "Not found" }, 404);
1868
+ }
1869
+ const filePath = path === "/" ? "/index.html" : path;
1870
+ const fullPath = join2(distDir, filePath);
1871
+ if (!fullPath.startsWith(distDir)) {
1872
+ res.writeHead(403);
1873
+ return res.end("Forbidden");
1874
+ }
1875
+ let targetPath = fullPath;
1876
+ if (!existsSync(fullPath)) {
1877
+ targetPath = join2(distDir, "index.html");
1878
+ }
1879
+ if (existsSync(targetPath)) {
1880
+ const ext = extname(targetPath);
1881
+ const contentType = mimeTypes[ext] || "application/octet-stream";
1882
+ const content = readFileSync(targetPath);
1883
+ res.writeHead(200, { "Content-Type": contentType });
1884
+ return res.end(content);
1885
+ }
1886
+ res.writeHead(404);
1887
+ res.end("Not found");
1888
+ } catch (e) {
1889
+ const message = e instanceof Error ? e.message : "Unknown error";
1890
+ console.error("Server error:", message);
1891
+ jsonResponse(res, { error: message }, 500);
1892
+ }
1893
+ });
1894
+ server.listen(PORT, () => {
1895
+ console.log(`\uD83D\uDCCB issy running at http://localhost:${PORT}/`);
1896
+ });
1897
+ export {
1898
+ server
1899
+ };