@webneat/codewiki 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,13 @@ var __export = (target, all3) => {
4
4
  __defProp(target, name, { get: all3[name], enumerable: true });
5
5
  };
6
6
 
7
+ // ../../node_modules/.pnpm/tsup@8.5.0_postcss@8.5.6_tsx@4.20.6_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/esm_shims.js
8
+ import path from "path";
9
+ import { fileURLToPath } from "url";
10
+ var getFilename = () => fileURLToPath(import.meta.url);
11
+ var getDirname = () => path.dirname(getFilename());
12
+ var __dirname = /* @__PURE__ */ getDirname();
13
+
7
14
  // src/cli/index.ts
8
15
  import { Command as Command30 } from "commander";
9
16
 
@@ -15,10 +22,9 @@ import { existsSync } from "fs";
15
22
 
16
23
  // src/internals/context.ts
17
24
  import ts from "typescript";
18
- import { fileURLToPath } from "url";
19
25
  import Database from "better-sqlite3";
20
26
  import { readFile as readFile2 } from "fs/promises";
21
- import path, { dirname, join as join2 } from "path";
27
+ import path2, { join as join2 } from "path";
22
28
  import { drizzle } from "drizzle-orm/better-sqlite3";
23
29
 
24
30
  // ../errors/dist/index.js
@@ -82,6 +88,7 @@ var index_default = errors;
82
88
  var err = index_default({
83
89
  file_outside_project_path: (data) => `File "${data.file_path}" is outside project path "${data.project_path}"`,
84
90
  file_not_found: (data) => `File not found: ${data.path}`,
91
+ file_stat_error: (data) => `Could not get file stats for ${data.path}: ${data.reason}`,
85
92
  db_error: (data) => `Database error in ${data.operation}: ${data.reason}`,
86
93
  symbol_meta_parse_error: (data) => `Failed to parse symbol metadata for symbol ${data.symbol_id}: ${data.reason}`,
87
94
  exported_symbol_not_found: (data) => `Exported symbol "${data.name}" not found in file with id ${data.file_id}`,
@@ -94,6 +101,8 @@ var err = index_default({
94
101
  symbol_node_not_found: (data) => `Symbol node not found for ${data.name} in ${data.file_path}`,
95
102
  symbol_not_found: (data) => `Symbol "${data.name}" not found in file "${data.path}"`,
96
103
  describe_dependency_failed: (data) => `Failed to describe ${data.package}#${data.name}: ${data.reason}`,
104
+ could_not_describe_files_due_to_pending_symbols: (data) => `Cannot start describing files before describing all symbols; ${data.count} symbols are still pending`,
105
+ could_not_describe_directories_due_to_pending_files: (data) => `Cannot start describing directories before describing all files; ${data.count} files are still pending`,
97
106
  // CLI errors
98
107
  could_not_read_file: (data) => `Could not read file ${data.path}: ${data.reason}`,
99
108
  invalid_json: (data) => `Invalid JSON: ${data.reason}`,
@@ -446,7 +455,7 @@ __export(configs_exports, {
446
455
  import { eq as eq2, sql as sql3 } from "drizzle-orm";
447
456
 
448
457
  // src/db/common.ts
449
- import { eq, like, or, and, asc, desc } from "drizzle-orm";
458
+ import { eq, like, or, and, asc, desc, count } from "drizzle-orm";
450
459
  function safe_query(operation, fn) {
451
460
  return err.safe(fn, (reason, ...args) => err.new("db_error", { operation, args: args.slice(1), reason }));
452
461
  }
@@ -454,6 +463,9 @@ function do_search(db6, table, options) {
454
463
  if (!options.select.includes("id")) options.select.push("id");
455
464
  return db6.select(fields(table, options.select)).from(table).where(conditions(table, options.where)).orderBy(order(table, options.order_by)).offset(options.offset).limit(options.limit).all();
456
465
  }
466
+ function do_count(db6, table, options) {
467
+ return db6.select({ count: count() }).from(table).where(conditions(table, options)).get()?.count ?? 0;
468
+ }
457
469
  function fields(table, fields2) {
458
470
  const res = {};
459
471
  for (const field of fields2) res[field] = table[field];
@@ -505,8 +517,10 @@ __export(files_exports, {
505
517
  by_directory_path: () => by_directory_path,
506
518
  by_id: () => by_id,
507
519
  by_id_and_state: () => by_id_and_state,
520
+ by_ids: () => by_ids,
508
521
  by_path: () => by_path,
509
522
  by_state: () => by_state,
523
+ count: () => count2,
510
524
  del: () => del,
511
525
  del_by_dir: () => del_by_dir,
512
526
  get_directory_ids: () => get_directory_ids,
@@ -520,48 +534,6 @@ __export(files_exports, {
520
534
  });
521
535
  import { eq as eq3, and as and2, inArray, or as or2, like as like2 } from "drizzle-orm";
522
536
 
523
- // src/internals/utils.ts
524
- import { readFileSync } from "fs";
525
- var parse_json = err.safe(JSON.parse, (reason, text2) => err.new("invalid_json", { reason, text: text2 }));
526
- var read_file = err.safe(
527
- (path6) => readFileSync(path6, "utf-8"),
528
- (reason, path6) => err.new("could_not_read_file", { path: path6, reason })
529
- );
530
- function group_by_unique(items, key) {
531
- const groups = {};
532
- for (const item of items) {
533
- groups[key(item)] = item;
534
- }
535
- return groups;
536
- }
537
- function expand({ items, get_children, get_key }) {
538
- const visited = /* @__PURE__ */ new Set();
539
- const result = [];
540
- const queue = [...items];
541
- while (queue.length > 0) {
542
- const item = queue.shift();
543
- const key = get_key(item);
544
- if (err.any(key)) return key;
545
- if (visited.has(key)) continue;
546
- visited.add(key);
547
- result.push(item);
548
- const children3 = get_children(item);
549
- if (err.any(children3)) return children3;
550
- queue.push(...children3);
551
- }
552
- return result;
553
- }
554
- function uniq(items) {
555
- return [...new Set(items)];
556
- }
557
- function merge(a, b) {
558
- const res = { ...a };
559
- for (const key of Object.keys(b)) {
560
- if (b[key] !== void 0) res[key] = b[key];
561
- }
562
- return res;
563
- }
564
-
565
537
  // src/db/defaults.ts
566
538
  var files2 = {
567
539
  select: ["id", "directory_id", "path", "state", "error"],
@@ -591,6 +563,34 @@ var external_dependencies2 = {
591
563
  offset: 0,
592
564
  where: {}
593
565
  };
566
+ var imports2 = {
567
+ select: ["id", "exporter_file_id", "importer_file_id", "symbol_id", "name", "alias", "is_dynamic", "state", "error"],
568
+ order_by: ["id", "asc"],
569
+ limit: 20,
570
+ offset: 0,
571
+ where: {}
572
+ };
573
+ var external_imports2 = {
574
+ select: ["id", "file_id", "external_dependency_id", "alias", "is_dynamic"],
575
+ order_by: ["id", "asc"],
576
+ limit: 20,
577
+ offset: 0,
578
+ where: {}
579
+ };
580
+ var symbol_internal_links2 = {
581
+ select: ["id", "from_file_id", "to_file_id", "from_symbol_id", "to_symbol_id", "state", "error"],
582
+ order_by: ["id", "asc"],
583
+ limit: 20,
584
+ offset: 0,
585
+ where: {}
586
+ };
587
+ var symbol_external_links2 = {
588
+ select: ["id", "symbol_id", "external_import_id"],
589
+ order_by: ["id", "asc"],
590
+ limit: 20,
591
+ offset: 0,
592
+ where: {}
593
+ };
594
594
 
595
595
  // src/db/files.ts
596
596
  var default_select_fields = ["id", "directory_id", "path", "state", "error"];
@@ -598,15 +598,23 @@ var all = safe_query("files.all", (ctx) => ctx.db.select().from(files).all());
598
598
  var search = safe_query("files.search", (ctx, options = {}) => {
599
599
  return do_search(ctx.db, files, merge(files2, options));
600
600
  });
601
+ var count2 = safe_query("files.count", (ctx, where = {}) => {
602
+ return do_count(ctx.db, files, where);
603
+ });
601
604
  var by_id = safe_query("files.by_id", (ctx, id) => ctx.db.select().from(files).where(eq3(files.id, id)).get());
605
+ var by_ids = safe_query(
606
+ "files.by_ids",
607
+ (ctx, ids) => ctx.db.select().from(files).where(inArray(files.id, ids)).all()
608
+ );
602
609
  var by_path = safe_query(
603
610
  "files.by_path",
604
- (ctx, path6) => ctx.db.select().from(files).where(eq3(files.path, path6)).get()
605
- );
606
- var by_state = safe_query(
607
- "files.by_state",
608
- (ctx, state) => ctx.db.select().from(files).where(eq3(files.state, state)).all()
611
+ (ctx, path7) => ctx.db.select().from(files).where(eq3(files.path, path7)).get()
609
612
  );
613
+ var by_state = safe_query("files.by_state", (ctx, state, limit) => {
614
+ let query = ctx.db.select().from(files).where(eq3(files.state, state));
615
+ if (limit) query = query.limit(limit);
616
+ return query.all();
617
+ });
610
618
  var insert = safe_query("files.insert", (ctx, values) => ctx.db.insert(files).values(values).run());
611
619
  var update = safe_query(
612
620
  "files.update",
@@ -648,8 +656,8 @@ var using_dependency = safe_query(
648
656
  "files.using_dependency",
649
657
  (ctx, external_dependency_id, fields_to_select = default_select_fields) => {
650
658
  if (!fields_to_select.includes("id")) fields_to_select.push("id");
651
- const imports2 = ctx.db.select({ file_id: external_imports.file_id }).from(external_imports).where(eq3(external_imports.external_dependency_id, external_dependency_id)).all();
652
- const file_ids = uniq(imports2.map((i) => i.file_id));
659
+ const imports4 = ctx.db.select({ file_id: external_imports.file_id }).from(external_imports).where(eq3(external_imports.external_dependency_id, external_dependency_id)).all();
660
+ const file_ids = uniq(imports4.map((i) => i.file_id));
653
661
  if (file_ids.length === 0) return [];
654
662
  return ctx.db.select(fields(files, fields_to_select)).from(files).where(inArray(files.id, file_ids)).all();
655
663
  }
@@ -680,8 +688,10 @@ var directories_exports = {};
680
688
  __export(directories_exports, {
681
689
  by_id: () => by_id2,
682
690
  by_id_and_state: () => by_id_and_state2,
691
+ by_ids: () => by_ids2,
683
692
  by_path: () => by_path2,
684
693
  by_state: () => by_state2,
694
+ count: () => count3,
685
695
  insert: () => insert2,
686
696
  search: () => search2,
687
697
  update: () => update2,
@@ -692,9 +702,13 @@ var by_id2 = safe_query(
692
702
  "directories.by_id",
693
703
  (ctx, id) => ctx.db.select().from(directories).where(eq4(directories.id, id)).get()
694
704
  );
705
+ var by_ids2 = safe_query(
706
+ "directories.by_ids",
707
+ (ctx, ids) => ctx.db.select().from(directories).where(inArray2(directories.id, ids)).all()
708
+ );
695
709
  var by_path2 = safe_query(
696
710
  "directories.by_path",
697
- (ctx, path6) => ctx.db.select().from(directories).where(eq4(directories.path, path6)).get()
711
+ (ctx, path7) => ctx.db.select().from(directories).where(eq4(directories.path, path7)).get()
698
712
  );
699
713
  var by_state2 = safe_query(
700
714
  "directories.by_state",
@@ -719,6 +733,9 @@ var by_id_and_state2 = safe_query(
719
733
  var search2 = safe_query("directories.search", (ctx, options = {}) => {
720
734
  return do_search(ctx.db, directories, merge(directories2, options));
721
735
  });
736
+ var count3 = safe_query("directories.count", (ctx, where = {}) => {
737
+ return do_count(ctx.db, directories, where);
738
+ });
722
739
 
723
740
  // src/db/imports.ts
724
741
  var imports_exports = {};
@@ -726,11 +743,23 @@ __export(imports_exports, {
726
743
  by_exporter_file: () => by_exporter_file,
727
744
  by_importer_file: () => by_importer_file,
728
745
  by_state: () => by_state3,
746
+ count: () => count4,
747
+ count_pending_symbols: () => count_pending_symbols,
729
748
  del_by_importer_file: () => del_by_importer_file,
730
749
  insert_many: () => insert_many,
750
+ search: () => search3,
731
751
  update: () => update3
732
752
  });
733
- import { eq as eq5 } from "drizzle-orm";
753
+ import { eq as eq5, ne, and as and4, count as countFn } from "drizzle-orm";
754
+ var search3 = safe_query("imports.search", (ctx, options = {}) => {
755
+ return do_search(ctx.db, imports, merge(imports2, options));
756
+ });
757
+ var count4 = safe_query("imports.count", (ctx, where = {}) => {
758
+ return do_count(ctx.db, imports, where);
759
+ });
760
+ var count_pending_symbols = safe_query("imports.count_pending_symbols", (ctx, file_id) => {
761
+ return ctx.db.select({ count: countFn() }).from(imports).innerJoin(symbols, eq5(imports.symbol_id, symbols.id)).where(and4(eq5(imports.importer_file_id, file_id), ne(symbols.state, "ready"))).get()?.count ?? 0;
762
+ });
734
763
  var by_exporter_file = safe_query(
735
764
  "imports.by_exporter_file",
736
765
  (ctx, exporter_file_id) => ctx.db.select().from(imports).where(eq5(imports.exporter_file_id, exporter_file_id)).all()
@@ -760,17 +789,67 @@ __export(symbols_exports, {
760
789
  by_file_and_name: () => by_file_and_name,
761
790
  by_id: () => by_id3,
762
791
  by_id_and_state: () => by_id_and_state3,
792
+ by_ids: () => by_ids3,
763
793
  by_state: () => by_state4,
794
+ count: () => count5,
764
795
  del_by_file: () => del_by_file,
765
796
  insert_many: () => insert_many2,
766
797
  meta: () => meta,
767
798
  referenced_by: () => referenced_by,
768
799
  referencing: () => referencing,
769
- search: () => search3,
800
+ search: () => search4,
770
801
  update: () => update4,
771
802
  using_dependency: () => using_dependency2
772
803
  });
773
- import { eq as eq6, and as and4, inArray as inArray3 } from "drizzle-orm";
804
+ import { eq as eq6, and as and5, inArray as inArray3 } from "drizzle-orm";
805
+
806
+ // src/internals/utils.ts
807
+ import { readFileSync, statSync } from "fs";
808
+ var parse_json = err.safe(JSON.parse, (reason, text2) => err.new("invalid_json", { reason, text: text2 }));
809
+ var read_file = err.safe(
810
+ (path7) => readFileSync(path7, "utf-8"),
811
+ (reason, path7) => err.new("could_not_read_file", { path: path7, reason })
812
+ );
813
+ var file_stat = err.safe(
814
+ (path7) => statSync(path7),
815
+ (reason, path7) => err.new("file_stat_error", { path: path7, reason })
816
+ );
817
+ function group_by_unique(items, key) {
818
+ const groups = {};
819
+ for (const item of items) {
820
+ groups[key(item)] = item;
821
+ }
822
+ return groups;
823
+ }
824
+ function expand({ items, get_children, get_key }) {
825
+ const visited = /* @__PURE__ */ new Set();
826
+ const result = [];
827
+ const queue = [...items];
828
+ while (queue.length > 0) {
829
+ const item = queue.shift();
830
+ const key = get_key(item);
831
+ if (err.any(key)) return key;
832
+ if (visited.has(key)) continue;
833
+ visited.add(key);
834
+ result.push(item);
835
+ const children3 = get_children(item);
836
+ if (err.any(children3)) return children3;
837
+ queue.push(...children3);
838
+ }
839
+ return result;
840
+ }
841
+ function uniq(items) {
842
+ return [...new Set(items)];
843
+ }
844
+ function merge(a, b) {
845
+ const res = { ...a };
846
+ for (const key of Object.keys(b)) {
847
+ if (b[key] !== void 0) res[key] = b[key];
848
+ }
849
+ return res;
850
+ }
851
+
852
+ // src/db/symbols.ts
774
853
  var insert_many2 = safe_query("symbols.insert_many", (ctx, values) => ctx.db.insert(symbols).values(values).run());
775
854
  var del_by_file = safe_query(
776
855
  "symbols.delete_by_file",
@@ -778,7 +857,7 @@ var del_by_file = safe_query(
778
857
  );
779
858
  var by_file_and_name = safe_query(
780
859
  "symbols.by_file_and_name",
781
- (ctx, params) => ctx.db.select().from(symbols).where(and4(eq6(symbols.file_id, params.file_id), eq6(symbols.name, params.name), eq6(symbols.is_exported, params.is_exported))).get()
860
+ (ctx, params) => ctx.db.select().from(symbols).where(and5(eq6(symbols.file_id, params.file_id), eq6(symbols.name, params.name), eq6(symbols.is_exported, params.is_exported))).get()
782
861
  );
783
862
  var by_state4 = safe_query(
784
863
  "symbols.by_state",
@@ -793,9 +872,13 @@ var update4 = safe_query(
793
872
  (ctx, id, data) => ctx.db.update(symbols).set(data).where(eq6(symbols.id, id)).run()
794
873
  );
795
874
  var by_id3 = safe_query("symbols.by_id", (ctx, id) => ctx.db.select().from(symbols).where(eq6(symbols.id, id)).get());
875
+ var by_ids3 = safe_query(
876
+ "symbols.by_ids",
877
+ (ctx, ids) => ctx.db.select().from(symbols).where(inArray3(symbols.id, ids)).all()
878
+ );
796
879
  var by_id_and_state3 = safe_query(
797
880
  "symbols.by_id_and_state",
798
- (ctx, params) => ctx.db.select().from(symbols).where(and4(eq6(symbols.id, params.id), eq6(symbols.state, params.state))).get()
881
+ (ctx, params) => ctx.db.select().from(symbols).where(and5(eq6(symbols.id, params.id), eq6(symbols.state, params.state))).get()
799
882
  );
800
883
  function meta(symbol) {
801
884
  return err.catch(
@@ -803,8 +886,12 @@ function meta(symbol) {
803
886
  (reason) => err.new("symbol_meta_parse_error", { reason, symbol_id: symbol.id, meta: symbol.meta })
804
887
  );
805
888
  }
806
- var search3 = safe_query("symbols.search", (ctx, options = {}) => {
807
- return do_search(ctx.db, symbols, merge(symbols2, options));
889
+ var search4 = safe_query(
890
+ "symbols.search",
891
+ (ctx, options = {}) => do_search(ctx.db, symbols, merge(symbols2, options))
892
+ );
893
+ var count5 = safe_query("symbols.count", (ctx, where = {}) => {
894
+ return do_count(ctx.db, symbols, where);
808
895
  });
809
896
  var referenced_by = safe_query(
810
897
  "symbols.referenced_by",
@@ -842,20 +929,26 @@ var external_dependencies_exports = {};
842
929
  __export(external_dependencies_exports, {
843
930
  all: () => all2,
844
931
  by_id: () => by_id4,
932
+ by_ids: () => by_ids4,
845
933
  by_package_subpath_and_name: () => by_package_subpath_and_name,
846
934
  by_state: () => by_state5,
935
+ count: () => count6,
847
936
  get_or_create: () => get_or_create,
848
937
  insert: () => insert3,
849
- search: () => search4,
938
+ search: () => search5,
850
939
  update: () => update5,
851
940
  used_by_file: () => used_by_file,
852
941
  used_by_symbol: () => used_by_symbol
853
942
  });
854
- import { eq as eq7, and as and5, sql as sql4, inArray as inArray4 } from "drizzle-orm";
943
+ import { eq as eq7, and as and6, sql as sql4, inArray as inArray4 } from "drizzle-orm";
855
944
  var by_id4 = safe_query(
856
945
  "external_dependencies.by_id",
857
946
  (ctx, id) => ctx.db.select().from(external_dependencies).where(eq7(external_dependencies.id, id)).get()
858
947
  );
948
+ var by_ids4 = safe_query(
949
+ "external_dependencies.by_ids",
950
+ (ctx, ids) => ctx.db.select().from(external_dependencies).where(inArray4(external_dependencies.id, ids)).all()
951
+ );
859
952
  var by_state5 = safe_query(
860
953
  "external_dependencies.by_state",
861
954
  (ctx, state) => ctx.db.select().from(external_dependencies).where(eq7(external_dependencies.state, state)).all()
@@ -863,7 +956,7 @@ var by_state5 = safe_query(
863
956
  var by_package_subpath_and_name = safe_query(
864
957
  "external_dependencies.by_package_subpath_and_name",
865
958
  (ctx, params) => ctx.db.select().from(external_dependencies).where(
866
- and5(
959
+ and6(
867
960
  eq7(external_dependencies.package, params.package),
868
961
  params.subpath === null ? sql4`${external_dependencies.subpath} IS NULL` : eq7(external_dependencies.subpath, params.subpath),
869
962
  params.name === null ? sql4`${external_dependencies.name} IS NULL` : eq7(external_dependencies.name, params.name)
@@ -885,11 +978,13 @@ function get_or_create(ctx, value) {
885
978
  (existing) => existing || insert3(ctx, value)
886
979
  );
887
980
  }
888
- var search4 = safe_query(
981
+ var search5 = safe_query(
889
982
  "external_dependencies.search",
890
- (ctx, options = {}) => {
891
- return do_search(ctx.db, external_dependencies, merge(external_dependencies2, options));
892
- }
983
+ (ctx, options = {}) => do_search(ctx.db, external_dependencies, merge(external_dependencies2, options))
984
+ );
985
+ var count6 = safe_query(
986
+ "external_dependencies.count",
987
+ (ctx, where = {}) => do_count(ctx.db, external_dependencies, where)
893
988
  );
894
989
  var used_by_file = safe_query(
895
990
  "external_dependencies.used_by_file",
@@ -921,10 +1016,22 @@ __export(external_imports_exports, {
921
1016
  by_external_dependency: () => by_external_dependency,
922
1017
  by_file: () => by_file2,
923
1018
  by_symbol: () => by_symbol,
1019
+ count: () => count7,
1020
+ count_pending_dependencies: () => count_pending_dependencies,
924
1021
  del_by_file: () => del_by_file2,
925
- insert_many: () => insert_many3
1022
+ insert_many: () => insert_many3,
1023
+ search: () => search6
1024
+ });
1025
+ import { eq as eq8, ne as ne2, and as and7, count as countFn2 } from "drizzle-orm";
1026
+ var search6 = safe_query("external_imports.search", (ctx, options = {}) => {
1027
+ return do_search(ctx.db, external_imports, merge(external_imports2, options));
1028
+ });
1029
+ var count7 = safe_query("external_imports.count", (ctx, where = {}) => {
1030
+ return do_count(ctx.db, external_imports, where);
1031
+ });
1032
+ var count_pending_dependencies = safe_query("external_imports.count_pending_dependencies", (ctx, file_id) => {
1033
+ return ctx.db.select({ count: countFn2() }).from(external_imports).innerJoin(external_dependencies, eq8(external_imports.external_dependency_id, external_dependencies.id)).where(and7(eq8(external_imports.file_id, file_id), ne2(external_dependencies.state, "ready"))).get()?.count ?? 0;
926
1034
  });
927
- import { eq as eq8 } from "drizzle-orm";
928
1035
  var insert_many3 = safe_query(
929
1036
  "external_imports.insert_many",
930
1037
  (ctx, values) => ctx.db.insert(external_imports).values(values).run()
@@ -959,11 +1066,20 @@ var by_symbol = safe_query(
959
1066
  var symbol_internal_links_exports = {};
960
1067
  __export(symbol_internal_links_exports, {
961
1068
  by_from_symbol: () => by_from_symbol,
1069
+ count: () => count8,
962
1070
  del_by_from_symbol: () => del_by_from_symbol,
963
1071
  exists: () => exists,
964
- insert: () => insert4
1072
+ insert: () => insert4,
1073
+ search: () => search7,
1074
+ update_state_by_to_symbol: () => update_state_by_to_symbol
1075
+ });
1076
+ import { and as and8, eq as eq9 } from "drizzle-orm";
1077
+ var search7 = safe_query("symbol_internal_links.search", (ctx, options = {}) => {
1078
+ return do_search(ctx.db, symbol_internal_links, merge(symbol_internal_links2, options));
1079
+ });
1080
+ var count8 = safe_query("symbol_internal_links.count", (ctx, where = {}) => {
1081
+ return do_count(ctx.db, symbol_internal_links, where);
965
1082
  });
966
- import { and as and6, eq as eq9 } from "drizzle-orm";
967
1083
  var by_from_symbol = safe_query(
968
1084
  "symbol_internal_links.by_from_symbol",
969
1085
  (ctx, from_symbol_id) => ctx.db.query.symbol_internal_links.findMany({
@@ -983,23 +1099,43 @@ var insert4 = safe_query(
983
1099
  );
984
1100
  var exists = safe_query(
985
1101
  "symbol_internal_links.exists",
986
- (ctx, params) => ctx.db.select({ id: symbol_internal_links.id }).from(symbol_internal_links).where(and6(eq9(symbol_internal_links.from_symbol_id, params.from_symbol_id), eq9(symbol_internal_links.to_symbol_id, params.to_symbol_id))).get()
1102
+ (ctx, params) => ctx.db.select({ id: symbol_internal_links.id }).from(symbol_internal_links).where(and8(eq9(symbol_internal_links.from_symbol_id, params.from_symbol_id), eq9(symbol_internal_links.to_symbol_id, params.to_symbol_id))).get()
987
1103
  );
988
1104
  var del_by_from_symbol = safe_query(
989
1105
  "symbol_internal_links.del_by_from_symbol",
990
1106
  (ctx, from_symbol_id) => ctx.db.delete(symbol_internal_links).where(eq9(symbol_internal_links.from_symbol_id, from_symbol_id)).run()
991
1107
  );
1108
+ var update_state_by_to_symbol = safe_query(
1109
+ "symbol_internal_links.update_state_by_to_symbol",
1110
+ (ctx, to_symbol_id, state) => ctx.db.update(symbol_internal_links).set({ state }).where(eq9(symbol_internal_links.to_symbol_id, to_symbol_id)).run()
1111
+ );
992
1112
 
993
1113
  // src/db/symbol_external_links.ts
994
1114
  var symbol_external_links_exports = {};
995
1115
  __export(symbol_external_links_exports, {
996
1116
  by_external_import: () => by_external_import,
997
1117
  by_symbol: () => by_symbol2,
1118
+ count: () => count9,
1119
+ count_by_dependency: () => count_by_dependency,
1120
+ count_pending_deps: () => count_pending_deps,
998
1121
  del_by_symbol: () => del_by_symbol,
999
1122
  exists: () => exists2,
1000
- insert: () => insert5
1123
+ insert: () => insert5,
1124
+ search: () => search8
1125
+ });
1126
+ import { and as and9, eq as eq10, ne as ne3, count as countFn3 } from "drizzle-orm";
1127
+ var search8 = safe_query("symbol_external_links.search", (ctx, options = {}) => {
1128
+ return do_search(ctx.db, symbol_external_links, merge(symbol_external_links2, options));
1129
+ });
1130
+ var count9 = safe_query("symbol_external_links.count", (ctx, where = {}) => {
1131
+ return do_count(ctx.db, symbol_external_links, where);
1132
+ });
1133
+ var count_by_dependency = safe_query("symbol_external_links.count_by_dependency", (ctx, dependency_id) => {
1134
+ return ctx.db.select({ count: countFn3() }).from(symbol_external_links).innerJoin(external_imports, eq10(symbol_external_links.external_import_id, external_imports.id)).where(eq10(external_imports.external_dependency_id, dependency_id)).get()?.count ?? 0;
1135
+ });
1136
+ var count_pending_deps = safe_query("symbol_external_links.count_pending_deps", (ctx, symbol_id) => {
1137
+ return ctx.db.select({ count: countFn3() }).from(symbol_external_links).innerJoin(external_imports, eq10(symbol_external_links.external_import_id, external_imports.id)).innerJoin(external_dependencies, eq10(external_imports.external_dependency_id, external_dependencies.id)).where(and9(eq10(symbol_external_links.symbol_id, symbol_id), ne3(external_dependencies.state, "ready"))).get()?.count ?? 0;
1001
1138
  });
1002
- import { and as and7, eq as eq10 } from "drizzle-orm";
1003
1139
  var by_symbol2 = safe_query(
1004
1140
  "symbol_external_links.by_symbol",
1005
1141
  (ctx, symbol_id) => ctx.db.select().from(symbol_external_links).where(eq10(symbol_external_links.symbol_id, symbol_id)).all()
@@ -1014,7 +1150,7 @@ var by_external_import = safe_query(
1014
1150
  );
1015
1151
  var exists2 = safe_query(
1016
1152
  "symbol_external_links.exists",
1017
- (ctx, params) => ctx.db.select({ id: symbol_external_links.id }).from(symbol_external_links).where(and7(eq10(symbol_external_links.symbol_id, params.symbol_id), eq10(symbol_external_links.external_import_id, params.external_import_id))).get()
1153
+ (ctx, params) => ctx.db.select({ id: symbol_external_links.id }).from(symbol_external_links).where(and9(eq10(symbol_external_links.symbol_id, params.symbol_id), eq10(symbol_external_links.external_import_id, params.external_import_id))).get()
1018
1154
  );
1019
1155
  var del_by_symbol = safe_query(
1020
1156
  "symbol_external_links.del_by_symbol",
@@ -1023,8 +1159,8 @@ var del_by_symbol = safe_query(
1023
1159
 
1024
1160
  // src/internals/context.ts
1025
1161
  async function create_context(sqlite, db6, config) {
1026
- const project_path = path.resolve(config.project_path);
1027
- const currentDir = dirname(fileURLToPath(import.meta.url));
1162
+ const project_path = path2.resolve(config.project_path);
1163
+ const currentDir = __dirname;
1028
1164
  const migrations_path = currentDir.includes("/dist") ? join2(currentDir, "../migrations") : join2(currentDir, "../../migrations");
1029
1165
  const tsconfig_path = join2(project_path, "tsconfig.json");
1030
1166
  if (!ts.sys.fileExists(tsconfig_path)) {
@@ -1032,8 +1168,8 @@ async function create_context(sqlite, db6, config) {
1032
1168
  }
1033
1169
  const tsconfig = ts.parseJsonConfigFileContent(ts.readConfigFile(tsconfig_path, ts.sys.readFile).config, ts.sys, project_path);
1034
1170
  const program = ts.createProgram({ rootNames: tsconfig.fileNames, options: tsconfig.options });
1035
- const package_json_path = config.package_json_path ?? path.join(project_path, "package.json");
1036
- const node_modules_paths = config.node_modules_paths ?? [path.join(project_path, "node_modules")];
1171
+ const package_json_path = config.package_json_path ?? path2.join(project_path, "package.json");
1172
+ const node_modules_paths = config.node_modules_paths ?? [path2.join(project_path, "node_modules")];
1037
1173
  const dependencies2 = await get_dependencies(package_json_path, node_modules_paths);
1038
1174
  const ctx = { db: db6, sqlite, migrations_path, project_path, program, dependencies: dependencies2 };
1039
1175
  await migrate(ctx);
@@ -1092,7 +1228,7 @@ async function get_dependencies(package_json_path, node_modules_paths) {
1092
1228
  async function get_github_repo(node_modules_paths, package_name) {
1093
1229
  for (const node_modules_path of node_modules_paths) {
1094
1230
  try {
1095
- const package_json_path = path.join(node_modules_path, package_name, "package.json");
1231
+ const package_json_path = path2.join(node_modules_path, package_name, "package.json");
1096
1232
  const package_json = JSON.parse(await readFile2(package_json_path, "utf-8"));
1097
1233
  const url = package_json.repository?.url || package_json.repository;
1098
1234
  if (typeof url === "string") {
@@ -1109,7 +1245,7 @@ async function get_github_repo(node_modules_paths, package_name) {
1109
1245
  // src/cli/env.ts
1110
1246
  var env = {
1111
1247
  read_file,
1112
- file_exists: (path6) => existsSync(path6),
1248
+ file_exists: (path7) => existsSync(path7),
1113
1249
  argv: () => process.argv,
1114
1250
  log: (...args) => console.log(...args),
1115
1251
  error: (...args) => console.error(...args),
@@ -1233,7 +1369,7 @@ var DependencySelectOptions = z.object({
1233
1369
  });
1234
1370
 
1235
1371
  // src/update/track_changes.ts
1236
- import path2 from "path";
1372
+ import path3 from "path";
1237
1373
  import "typescript";
1238
1374
  import { stat } from "fs/promises";
1239
1375
 
@@ -1244,9 +1380,9 @@ function file_updated(ctx, file_id) {
1244
1380
  items: [file_id],
1245
1381
  get_key: (id) => id,
1246
1382
  get_children: (id) => {
1247
- const imports2 = imports_exports.by_exporter_file(ctx, id);
1248
- if (err.any(imports2)) return imports2;
1249
- return imports2.map((x) => x.importer_file_id);
1383
+ const imports4 = imports_exports.by_exporter_file(ctx, id);
1384
+ if (err.any(imports4)) return imports4;
1385
+ return imports4.map((x) => x.importer_file_id);
1250
1386
  }
1251
1387
  })
1252
1388
  );
@@ -1279,7 +1415,7 @@ function get_source_files(ctx) {
1279
1415
  for (const file of ctx.program.getSourceFiles()) {
1280
1416
  if (ctx.program.isSourceFileDefaultLibrary(file)) continue;
1281
1417
  if (ctx.program.isSourceFileFromExternalLibrary(file)) continue;
1282
- if (!path2.resolve(file.fileName).startsWith(ctx.project_path)) continue;
1418
+ if (!path3.resolve(file.fileName).startsWith(ctx.project_path)) continue;
1283
1419
  src_files.push(file);
1284
1420
  }
1285
1421
  return src_files;
@@ -1327,7 +1463,7 @@ async function changes(ctx, source_files, db_files) {
1327
1463
  return { created, updated, deleted };
1328
1464
  }
1329
1465
  function get_file_path(ctx, file) {
1330
- const absolute_path = path2.resolve(file.fileName);
1466
+ const absolute_path = path3.resolve(file.fileName);
1331
1467
  if (absolute_path.startsWith(ctx.project_path)) return absolute_path.slice(ctx.project_path.length);
1332
1468
  return err.new("file_outside_project_path", { file_path: absolute_path, project_path: ctx.project_path });
1333
1469
  }
@@ -1335,10 +1471,10 @@ function get_parents_paths(ctx, file) {
1335
1471
  const file_path = get_file_path(ctx, file);
1336
1472
  if (err.any(file_path)) return file_path;
1337
1473
  const dirs = [];
1338
- let current = path2.dirname(file_path);
1339
- while (current !== path2.sep) {
1474
+ let current = path3.dirname(file_path);
1475
+ while (current !== path3.sep) {
1340
1476
  dirs.push(current);
1341
- current = path2.dirname(current);
1477
+ current = path3.dirname(current);
1342
1478
  }
1343
1479
  dirs.push(current);
1344
1480
  return dirs.reverse();
@@ -1372,19 +1508,19 @@ async function sync_external_dependencies(ctx) {
1372
1508
  }
1373
1509
 
1374
1510
  // src/update/scan_files/scan_files.ts
1375
- import path4 from "path";
1511
+ import path5 from "path";
1376
1512
  import ts10 from "typescript";
1377
1513
 
1378
1514
  // src/update/scan_files/imports.ts
1379
1515
  import ts4 from "typescript";
1380
1516
 
1381
1517
  // src/update/scan_files/common.ts
1382
- import path3 from "path";
1518
+ import path4 from "path";
1383
1519
  import ts3 from "typescript";
1384
1520
  function is_external_module(ctx, source_file, module_path) {
1385
1521
  const resolved = ts3.resolveModuleName(module_path, source_file.fileName, ctx.program.getCompilerOptions(), ts3.sys);
1386
1522
  if (!resolved.resolvedModule) return true;
1387
- const resolved_path = path3.resolve(resolved.resolvedModule.resolvedFileName);
1523
+ const resolved_path = path4.resolve(resolved.resolvedModule.resolvedFileName);
1388
1524
  return !resolved_path.startsWith(ctx.project_path);
1389
1525
  }
1390
1526
  function has_export_modifier(node) {
@@ -1493,13 +1629,13 @@ function is_import(ctx, source_file, node) {
1493
1629
  return !is_external_module(ctx, source_file, node.moduleSpecifier.text);
1494
1630
  }
1495
1631
  function extract_import(ctx, source_file, node, file_id) {
1496
- const imports2 = [];
1632
+ const imports4 = [];
1497
1633
  const clause = node.importClause;
1498
- if (!clause || !node.moduleSpecifier || !ts4.isStringLiteral(node.moduleSpecifier)) return imports2;
1634
+ if (!clause || !node.moduleSpecifier || !ts4.isStringLiteral(node.moduleSpecifier)) return imports4;
1499
1635
  const exporter_file_id = resolve_exporter_file(ctx, source_file, node.moduleSpecifier.text);
1500
- if (err.any(exporter_file_id)) return imports2;
1636
+ if (err.any(exporter_file_id)) return imports4;
1501
1637
  if (clause.name) {
1502
- imports2.push({
1638
+ imports4.push({
1503
1639
  importer_file_id: file_id,
1504
1640
  exporter_file_id,
1505
1641
  name: "default",
@@ -1509,7 +1645,7 @@ function extract_import(ctx, source_file, node, file_id) {
1509
1645
  }
1510
1646
  if (clause.namedBindings && ts4.isNamedImports(clause.namedBindings)) {
1511
1647
  for (const element of clause.namedBindings.elements) {
1512
- imports2.push({
1648
+ imports4.push({
1513
1649
  importer_file_id: file_id,
1514
1650
  exporter_file_id,
1515
1651
  name: (element.propertyName || element.name).text,
@@ -1519,7 +1655,7 @@ function extract_import(ctx, source_file, node, file_id) {
1519
1655
  }
1520
1656
  }
1521
1657
  if (clause.namedBindings && ts4.isNamespaceImport(clause.namedBindings)) {
1522
- imports2.push({
1658
+ imports4.push({
1523
1659
  importer_file_id: file_id,
1524
1660
  exporter_file_id,
1525
1661
  name: "*",
@@ -1527,7 +1663,7 @@ function extract_import(ctx, source_file, node, file_id) {
1527
1663
  state: "to_link"
1528
1664
  });
1529
1665
  }
1530
- return imports2;
1666
+ return imports4;
1531
1667
  }
1532
1668
  function extract_dynamic_import(ctx, source_file, node, file_id) {
1533
1669
  const arg = node.arguments[0];
@@ -1639,7 +1775,7 @@ function extract_external_import_info(node) {
1639
1775
  }
1640
1776
  function extract_external_import(ctx, node, file_id) {
1641
1777
  const infos = extract_external_import_info(node);
1642
- const external_imports2 = [];
1778
+ const external_imports3 = [];
1643
1779
  for (const info of infos) {
1644
1780
  const dep_meta = Object.values(ctx.dependencies).find((dep) => info.package.startsWith(dep.name));
1645
1781
  const dependency = external_dependencies_exports.get_or_create(ctx, {
@@ -1652,9 +1788,9 @@ function extract_external_import(ctx, node, file_id) {
1652
1788
  state: "to_describe"
1653
1789
  });
1654
1790
  if (err.any(dependency)) return dependency;
1655
- external_imports2.push({ file_id, external_dependency_id: dependency.id, alias: info.alias, is_dynamic: false });
1791
+ external_imports3.push({ file_id, external_dependency_id: dependency.id, alias: info.alias, is_dynamic: false });
1656
1792
  }
1657
- return external_imports2;
1793
+ return external_imports3;
1658
1794
  }
1659
1795
  function extract_external_dynamic_import(ctx, node, file_id) {
1660
1796
  const arg = node.arguments[0];
@@ -1959,32 +2095,32 @@ function scan_file(ctx, file) {
1959
2095
  () => external_imports_exports.del_by_file(ctx, file.id),
1960
2096
  () => get_source_file(ctx, file.path),
1961
2097
  (source_file) => parse_file(ctx, source_file, file.id),
1962
- ({ imports: imports2, symbols: symbols4, external_imports: external_imports2 }) => err.pipe(
1963
- () => external_imports2.length && external_imports_exports.insert_many(ctx, external_imports2),
1964
- () => imports2.length && imports_exports.insert_many(ctx, imports2),
2098
+ ({ imports: imports4, symbols: symbols4, external_imports: external_imports3 }) => err.pipe(
2099
+ () => external_imports3.length && external_imports_exports.insert_many(ctx, external_imports3),
2100
+ () => imports4.length && imports_exports.insert_many(ctx, imports4),
1965
2101
  () => symbols4.length && symbols_exports.insert_many(ctx, symbols4)
1966
2102
  )
1967
2103
  );
1968
2104
  }
1969
2105
  function get_source_file(ctx, file_path) {
1970
- const source_file = ctx.program.getSourceFile(path4.join(ctx.project_path, file_path));
2106
+ const source_file = ctx.program.getSourceFile(path5.join(ctx.project_path, file_path));
1971
2107
  if (!source_file) return err.new("file_not_found", { path: file_path });
1972
2108
  return source_file;
1973
2109
  }
1974
2110
  function parse_file(ctx, source_file, file_id) {
1975
- const imports2 = [];
2111
+ const imports4 = [];
1976
2112
  const symbols4 = [];
1977
- const external_imports2 = [];
2113
+ const external_imports3 = [];
1978
2114
  function find_dynamic_imports(node) {
1979
2115
  if (is_dynamic_import(node)) {
1980
2116
  const arg = node.arguments[0];
1981
2117
  if (is_external_module(ctx, source_file, arg.text)) {
1982
2118
  const result = extract_external_dynamic_import(ctx, node, file_id);
1983
2119
  if (err.any(result)) return result;
1984
- external_imports2.push(result);
2120
+ external_imports3.push(result);
1985
2121
  } else {
1986
2122
  const result = extract_dynamic_import(ctx, source_file, node, file_id);
1987
- if (result) imports2.push(result);
2123
+ if (result) imports4.push(result);
1988
2124
  }
1989
2125
  }
1990
2126
  ts10.forEachChild(node, find_dynamic_imports);
@@ -1997,24 +2133,24 @@ function parse_file(ctx, source_file, file_id) {
1997
2133
  error = res;
1998
2134
  return;
1999
2135
  }
2000
- imports2.push(...res.imports);
2136
+ imports4.push(...res.imports);
2001
2137
  symbols4.push(...res.symbols);
2002
- external_imports2.push(...res.external_imports);
2138
+ external_imports3.push(...res.external_imports);
2003
2139
  error = find_dynamic_imports(statement);
2004
2140
  });
2005
2141
  if (error) return error;
2006
- return { imports: imports2, symbols: symbols4, external_imports: external_imports2 };
2142
+ return { imports: imports4, symbols: symbols4, external_imports: external_imports3 };
2007
2143
  }
2008
2144
  function parse_node(ctx, source_file, node, file_id) {
2009
- const imports2 = [];
2145
+ const imports4 = [];
2010
2146
  const symbols4 = [];
2011
- const external_imports2 = [];
2147
+ const external_imports3 = [];
2012
2148
  if (is_external_import(ctx, source_file, node)) {
2013
2149
  const result = extract_external_import(ctx, node, file_id);
2014
2150
  if (err.any(result)) return result;
2015
- external_imports2.push(...result);
2151
+ external_imports3.push(...result);
2016
2152
  } else if (is_import(ctx, source_file, node)) {
2017
- imports2.push(...extract_import(ctx, source_file, node, file_id));
2153
+ imports4.push(...extract_import(ctx, source_file, node, file_id));
2018
2154
  } else if (ts10.isExportAssignment(node) && !node.isExportEquals) {
2019
2155
  symbols4.push({
2020
2156
  file_id,
@@ -2056,14 +2192,14 @@ function parse_node(ctx, source_file, node, file_id) {
2056
2192
  symbols4.push(extract_class_symbol(node, file_id, source_file));
2057
2193
  symbols4.push(...extract_class_fields(node, file_id, source_file));
2058
2194
  }
2059
- return { imports: imports2, symbols: symbols4, external_imports: external_imports2 };
2195
+ return { imports: imports4, symbols: symbols4, external_imports: external_imports3 };
2060
2196
  }
2061
2197
 
2062
2198
  // src/update/link_imports.ts
2063
2199
  async function link_imports(ctx) {
2064
- const imports2 = err.or_throw(imports_exports.by_state(ctx, "to_link"));
2200
+ const imports4 = err.or_throw(imports_exports.by_state(ctx, "to_link"));
2065
2201
  let i = 0;
2066
- for (const import_ of imports2) {
2202
+ for (const import_ of imports4) {
2067
2203
  const res = link_import(ctx, import_);
2068
2204
  if (err.any(res)) err.or_throw(imports_exports.update(ctx, import_.id, { error: String(res) }));
2069
2205
  }
@@ -2079,7 +2215,7 @@ function link_import(ctx, import_) {
2079
2215
  }
2080
2216
 
2081
2217
  // src/update/link_symbols.ts
2082
- import path5 from "path";
2218
+ import path6 from "path";
2083
2219
  import ts11 from "typescript";
2084
2220
  async function link_symbols(ctx) {
2085
2221
  const symbols4 = err.or_throw(symbols_exports.by_state(ctx, "to_link"));
@@ -2105,7 +2241,7 @@ function find_symbol_references(ctx, symbol) {
2105
2241
  const file = files_exports.by_id(ctx, symbol.file_id);
2106
2242
  if (err.any(file)) return file;
2107
2243
  if (!file) return err.new("file_not_found", { path: `file_id=${symbol.file_id}` });
2108
- const file_path = path5.join(ctx.project_path, file.path);
2244
+ const file_path = path6.join(ctx.project_path, file.path);
2109
2245
  const source_file = ctx.program.getSourceFile(file_path);
2110
2246
  if (!source_file) return err.new("file_not_found", { path: file_path });
2111
2247
  const symbol_node = find_symbol_node(source_file, symbol);
@@ -2329,19 +2465,19 @@ async function update6(ctx) {
2329
2465
  }
2330
2466
 
2331
2467
  // src/counts.ts
2332
- import { count } from "drizzle-orm";
2333
- var counts = safe_query("counts", (ctx) => {
2334
- const symbol_counts = ctx.db.select({ state: symbols.state, count: count() }).from(symbols).groupBy(symbols.state).all();
2335
- const file_counts = ctx.db.select({ state: files.state, count: count() }).from(files).groupBy(files.state).all();
2336
- const dir_counts = ctx.db.select({ state: directories.state, count: count() }).from(directories).groupBy(directories.state).all();
2337
- const dep_counts = ctx.db.select({ state: external_dependencies.state, count: count() }).from(external_dependencies).groupBy(external_dependencies.state).all();
2468
+ import { count as count10 } from "drizzle-orm";
2469
+ function counts(ctx) {
2470
+ const symbol_counts = ctx.db.select({ state: symbols.state, count: count10() }).from(symbols).groupBy(symbols.state).all();
2471
+ const file_counts = ctx.db.select({ state: files.state, count: count10() }).from(files).groupBy(files.state).all();
2472
+ const dir_counts = ctx.db.select({ state: directories.state, count: count10() }).from(directories).groupBy(directories.state).all();
2473
+ const dep_counts = ctx.db.select({ state: external_dependencies.state, count: count10() }).from(external_dependencies).groupBy(external_dependencies.state).all();
2338
2474
  return {
2339
2475
  symbols: get_groups(symbol_counts, ["to_link", "to_describe", "ready"]),
2340
2476
  files: get_groups(file_counts, ["to_scan", "to_describe", "ready"]),
2341
2477
  directories: get_groups(dir_counts, ["to_describe", "ready"]),
2342
2478
  dependencies: get_groups(dep_counts, ["to_describe", "ready"])
2343
2479
  };
2344
- });
2480
+ }
2345
2481
  function get_groups(items, states) {
2346
2482
  const groups = { total: 0 };
2347
2483
  for (const state of states) groups[state] = 0;
@@ -2357,7 +2493,7 @@ function get_groups(items, states) {
2357
2493
  function files_wiki(ctx) {
2358
2494
  return {
2359
2495
  get: (id) => get2(ctx, id),
2360
- search: (options) => search5(ctx, options),
2496
+ search: (options) => search9(ctx, options),
2361
2497
  set_description: (id, description) => set_description(ctx, id, description),
2362
2498
  imported_by_file: (file_id, options) => imported_by_file(ctx, file_id, options),
2363
2499
  importing_file: (file_id, options) => importing_file(ctx, file_id, options),
@@ -2367,11 +2503,11 @@ function files_wiki(ctx) {
2367
2503
  function get2(ctx, id) {
2368
2504
  return err.or_throw(files_exports.by_id(ctx, id)) ?? null;
2369
2505
  }
2370
- function search5(ctx, options) {
2506
+ function search9(ctx, options) {
2371
2507
  return err.or_throw(files_exports.search(ctx, options));
2372
2508
  }
2373
2509
  function set_description(ctx, id, description) {
2374
- err.or_throw(files_exports.update(ctx, id, { description }));
2510
+ err.or_throw(files_exports.update(ctx, id, { description, state: "ready", error: null }));
2375
2511
  }
2376
2512
  function imported_by_file(ctx, file_id, options = {}) {
2377
2513
  let imported_files = err.or_throw(files_exports.imported_by(ctx, file_id, options.select));
@@ -2423,7 +2559,7 @@ function importing_dependency(ctx, dependency_id, options = {}) {
2423
2559
  function symbols_wiki(ctx) {
2424
2560
  return {
2425
2561
  get: (id) => get3(ctx, id),
2426
- search: (options) => search6(ctx, options),
2562
+ search: (options) => search10(ctx, options),
2427
2563
  set_description: (id, description) => set_description2(ctx, id, description),
2428
2564
  referencing_symbol: (symbol_id, options) => referencing_symbol(ctx, symbol_id, options),
2429
2565
  referenced_by_symbol: (symbol_id, options) => referenced_by_symbol(ctx, symbol_id, options),
@@ -2433,11 +2569,12 @@ function symbols_wiki(ctx) {
2433
2569
  function get3(ctx, id) {
2434
2570
  return err.or_throw(symbols_exports.by_id(ctx, id)) ?? null;
2435
2571
  }
2436
- function search6(ctx, options) {
2572
+ function search10(ctx, options) {
2437
2573
  return err.or_throw(symbols_exports.search(ctx, options));
2438
2574
  }
2439
2575
  function set_description2(ctx, id, description) {
2440
- err.or_throw(symbols_exports.update(ctx, id, { description }));
2576
+ err.or_throw(symbols_exports.update(ctx, id, { description, state: "ready", error: null }));
2577
+ err.or_throw(symbol_internal_links_exports.update_state_by_to_symbol(ctx, id, "ready"));
2441
2578
  }
2442
2579
  function referenced_by_symbol(ctx, symbol_id, options = {}) {
2443
2580
  let referenced_symbols = err.or_throw(symbols_exports.referenced_by(ctx, symbol_id, options.select));
@@ -2489,7 +2626,7 @@ function using_dependency3(ctx, dependency_id, options = {}) {
2489
2626
  function directories_wiki(ctx) {
2490
2627
  return {
2491
2628
  get: (id) => get4(ctx, id),
2492
- search: (options) => search7(ctx, options),
2629
+ search: (options) => search11(ctx, options),
2493
2630
  set_description: (id, description) => set_description3(ctx, id, description),
2494
2631
  children: (parent_id, options) => children(ctx, parent_id, options),
2495
2632
  files: (directory_id, options) => directory_files(ctx, directory_id, options)
@@ -2498,11 +2635,11 @@ function directories_wiki(ctx) {
2498
2635
  function get4(ctx, id) {
2499
2636
  return err.or_throw(directories_exports.by_id(ctx, id)) ?? null;
2500
2637
  }
2501
- function search7(ctx, options) {
2638
+ function search11(ctx, options) {
2502
2639
  return err.or_throw(directories_exports.search(ctx, options));
2503
2640
  }
2504
2641
  function set_description3(ctx, id, description) {
2505
- err.or_throw(directories_exports.update(ctx, id, { description }));
2642
+ err.or_throw(directories_exports.update(ctx, id, { description, state: "ready", error: null }));
2506
2643
  }
2507
2644
  function children(ctx, parent_id, options = {}) {
2508
2645
  let child_directories = err.or_throw(directories_exports.search(ctx, { select: options.select, where: { parent_id }, limit: 1e4 }));
@@ -2545,7 +2682,7 @@ function directory_files(ctx, directory_id, options = {}) {
2545
2682
  function dependencies_wiki(ctx) {
2546
2683
  return {
2547
2684
  get: (id) => get5(ctx, id),
2548
- search: (options) => search8(ctx, options),
2685
+ search: (options) => search12(ctx, options),
2549
2686
  set_description: (id, description) => set_description4(ctx, id, description),
2550
2687
  used_by_file: (file_id, options) => used_by_file2(ctx, file_id, options),
2551
2688
  used_by_symbol: (symbol_id, options) => used_by_symbol2(ctx, symbol_id, options)
@@ -2554,7 +2691,7 @@ function dependencies_wiki(ctx) {
2554
2691
  function get5(ctx, id) {
2555
2692
  return err.or_throw(external_dependencies_exports.by_id(ctx, id)) ?? null;
2556
2693
  }
2557
- function search8(ctx, options) {
2694
+ function search12(ctx, options) {
2558
2695
  return err.or_throw(external_dependencies_exports.search(ctx, options));
2559
2696
  }
2560
2697
  function set_description4(ctx, id, description) {
@@ -2567,13 +2704,88 @@ function used_by_symbol2(ctx, symbol_id, options) {
2567
2704
  return err.or_throw(external_dependencies_exports.used_by_symbol(ctx, symbol_id, options?.select));
2568
2705
  }
2569
2706
 
2707
+ // src/to_describe.ts
2708
+ function to_describe(ctx, limit) {
2709
+ const dependencies_count = err.or_throw(external_dependencies_exports.count(ctx, { state: "to_describe" }));
2710
+ if (dependencies_count > 0) return { type: "dependencies", items: dependencies_to_describe(ctx, limit) };
2711
+ const symbols_count = err.or_throw(symbols_exports.count(ctx, { state: "to_describe" }));
2712
+ if (symbols_count > 0) return { type: "symbols", items: symbols_to_describe(ctx, limit) };
2713
+ const pending_symbols_count = err.or_throw(symbols_exports.count(ctx, { state: "to_link" }));
2714
+ if (pending_symbols_count > 0) throw err.new("could_not_describe_files_due_to_pending_symbols", { count: pending_symbols_count });
2715
+ const files_count = err.or_throw(files_exports.count(ctx, { state: "to_describe" }));
2716
+ if (files_count > 0) return { type: "files", items: files_to_describe(ctx, limit) };
2717
+ const pending_files_count = err.or_throw(files_exports.count(ctx, { state: "to_scan" }));
2718
+ if (pending_files_count > 0) throw err.new("could_not_describe_directories_due_to_pending_files", { count: pending_files_count });
2719
+ const directories_count = err.or_throw(directories_exports.count(ctx, { state: "to_describe" }));
2720
+ if (directories_count > 0) return { type: "directories", items: directories_to_describe(ctx, limit) };
2721
+ return { type: "none" };
2722
+ }
2723
+ function dependencies_to_describe(ctx, limit) {
2724
+ const candidates = err.or_throw(
2725
+ external_dependencies_exports.search(ctx, {
2726
+ where: { state: "to_describe" },
2727
+ select: ["id", "package", "name"],
2728
+ limit: 1e5
2729
+ })
2730
+ );
2731
+ candidates.sort((a, b) => {
2732
+ if (a.package !== b.package) return a.package.localeCompare(b.package);
2733
+ return (a.name || "").localeCompare(b.name || "");
2734
+ });
2735
+ const ids = candidates.slice(0, limit).map((dep) => dep.id);
2736
+ const items = err.or_throw(external_dependencies_exports.by_ids(ctx, ids));
2737
+ const by_id5 = new Map(items.map((item) => [item.id, item]));
2738
+ return ids.map((id) => by_id5.get(id)).filter((item) => !!item);
2739
+ }
2740
+ function symbols_to_describe(ctx, limit) {
2741
+ const candidates = err.or_throw(symbols_exports.search(ctx, { where: { state: "to_describe" }, select: ["id", "text"], limit: 1e5 }));
2742
+ const counts2 = {};
2743
+ for (const symbol of candidates) {
2744
+ counts2[symbol.id] = {
2745
+ length: symbol.text?.length ?? 0,
2746
+ missing_external: err.or_throw(symbol_external_links_exports.count_pending_deps(ctx, symbol.id)),
2747
+ missing_internal: err.or_throw(symbol_internal_links_exports.count(ctx, { from_symbol_id: symbol.id, state: "pending" }))
2748
+ };
2749
+ }
2750
+ candidates.sort((x, y) => {
2751
+ const a = counts2[x.id];
2752
+ const b = counts2[y.id];
2753
+ if (!a || !b) return 0;
2754
+ if (a.missing_internal !== b.missing_internal) return a.missing_internal - b.missing_internal;
2755
+ if (a.missing_external !== b.missing_external) return a.missing_external - b.missing_external;
2756
+ return a.length - b.length;
2757
+ });
2758
+ const ids = candidates.slice(0, limit).map((symbol) => symbol.id);
2759
+ const items = err.or_throw(symbols_exports.by_ids(ctx, ids));
2760
+ const by_id5 = new Map(items.map((item) => [item.id, item]));
2761
+ return ids.map((id) => by_id5.get(id)).filter((item) => !!item);
2762
+ }
2763
+ function files_to_describe(ctx, limit) {
2764
+ return err.or_throw(files_exports.by_state(ctx, "to_describe", limit));
2765
+ }
2766
+ function directories_to_describe(ctx, limit) {
2767
+ const candidates = err.or_throw(
2768
+ directories_exports.search(ctx, {
2769
+ where: { state: "to_describe" },
2770
+ select: ["id", "path"],
2771
+ limit: 1e5
2772
+ })
2773
+ );
2774
+ candidates.sort((a, b) => b.path.split("/").length - a.path.split("/").length);
2775
+ const ids = candidates.slice(0, limit).map((dir) => dir.id);
2776
+ const items = err.or_throw(directories_exports.by_ids(ctx, ids));
2777
+ const by_id5 = new Map(items.map((item) => [item.id, item]));
2778
+ return ids.map((id) => by_id5.get(id)).filter((item) => !!item);
2779
+ }
2780
+
2570
2781
  // src/index.ts
2571
2782
  async function create(config) {
2572
2783
  const ctx = await context_from_config(config);
2573
2784
  return {
2574
2785
  config,
2575
2786
  update: () => update6(ctx),
2576
- counts: () => err.or_throw(counts(ctx)),
2787
+ counts: () => counts(ctx),
2788
+ to_describe: (limit) => to_describe(ctx, limit),
2577
2789
  files: files_wiki(ctx),
2578
2790
  symbols: symbols_wiki(ctx),
2579
2791
  directories: directories_wiki(ctx),
@@ -2593,7 +2805,8 @@ async function load(db_path) {
2593
2805
  return {
2594
2806
  config,
2595
2807
  update: () => update6(ctx),
2596
- counts: () => err.or_throw(counts(ctx)),
2808
+ counts: () => counts(ctx),
2809
+ to_describe: (limit) => to_describe(ctx, limit),
2597
2810
  files: files_wiki(ctx),
2598
2811
  symbols: symbols_wiki(ctx),
2599
2812
  directories: directories_wiki(ctx),
@@ -2642,8 +2855,8 @@ function parse_options(options_json, schema, context) {
2642
2855
  env.log(`Error: Invalid options format in ${context}`);
2643
2856
  env.log("");
2644
2857
  for (const issue of validation_result.error.issues) {
2645
- const path6 = issue.path.length > 0 ? issue.path.join(".") : "root";
2646
- env.log(` \u2022 ${path6}: ${issue.message}`);
2858
+ const path7 = issue.path.length > 0 ? issue.path.join(".") : "root";
2859
+ env.log(` \u2022 ${path7}: ${issue.message}`);
2647
2860
  }
2648
2861
  env.log("");
2649
2862
  env.log(`Run 'codewiki ${context.split(" ")[0]} --help' for usage information`);
@@ -2773,10 +2986,10 @@ get6.action(async (id) => {
2773
2986
 
2774
2987
  // src/cli/commands/files/search.ts
2775
2988
  import { Command as Command5 } from "commander";
2776
- var search9 = new Command5("search");
2777
- search9.description("Search files with JSON options");
2778
- search9.argument("<options>", "JSON options for search");
2779
- search9.action(async (options_json) => {
2989
+ var search13 = new Command5("search");
2990
+ search13.description("Search files with JSON options");
2991
+ search13.argument("<options>", "JSON options for search");
2992
+ search13.action(async (options_json) => {
2780
2993
  const wiki = await load_wiki();
2781
2994
  const options = parse_options(options_json, FileSearchOptions, "files search");
2782
2995
  const results = wiki.files.search(options);
@@ -2845,7 +3058,7 @@ importing_dependency2.action(async (dep_id, options_json) => {
2845
3058
  var files3 = new Command10("files");
2846
3059
  files3.description("Explore files");
2847
3060
  files3.addCommand(get6);
2848
- files3.addCommand(search9);
3061
+ files3.addCommand(search13);
2849
3062
  files3.addCommand(set_description5);
2850
3063
  files3.addCommand(imported_by_file2);
2851
3064
  files3.addCommand(importing_file2);
@@ -2896,10 +3109,10 @@ get7.action(async (id) => {
2896
3109
 
2897
3110
  // src/cli/commands/symbols/search.ts
2898
3111
  import { Command as Command12 } from "commander";
2899
- var search10 = new Command12("search");
2900
- search10.description("Search symbols with JSON options");
2901
- search10.argument("<options>", "JSON options");
2902
- search10.action(async (options_json) => {
3112
+ var search14 = new Command12("search");
3113
+ search14.description("Search symbols with JSON options");
3114
+ search14.argument("<options>", "JSON options");
3115
+ search14.action(async (options_json) => {
2903
3116
  const wiki = await load_wiki();
2904
3117
  const options = parse_options(options_json, SymbolSearchOptions, "symbols search");
2905
3118
  const results = wiki.symbols.search(options);
@@ -2968,7 +3181,7 @@ using_dependency4.action(async (dep_id, options_json) => {
2968
3181
  var symbols3 = new Command17("symbols");
2969
3182
  symbols3.description("Explore symbols");
2970
3183
  symbols3.addCommand(get7);
2971
- symbols3.addCommand(search10);
3184
+ symbols3.addCommand(search14);
2972
3185
  symbols3.addCommand(set_description6);
2973
3186
  symbols3.addCommand(referencing_symbol2);
2974
3187
  symbols3.addCommand(referenced_by_symbol2);
@@ -3019,10 +3232,10 @@ get8.action(async (id) => {
3019
3232
 
3020
3233
  // src/cli/commands/directories/search.ts
3021
3234
  import { Command as Command19 } from "commander";
3022
- var search11 = new Command19("search");
3023
- search11.description("Search directories with JSON options");
3024
- search11.argument("<options>", "JSON options");
3025
- search11.action(async (options_json) => {
3235
+ var search15 = new Command19("search");
3236
+ search15.description("Search directories with JSON options");
3237
+ search15.argument("<options>", "JSON options");
3238
+ search15.action(async (options_json) => {
3026
3239
  const wiki = await load_wiki();
3027
3240
  const options = parse_options(options_json, DirectorySearchOptions, "directories search");
3028
3241
  const results = wiki.directories.search(options);
@@ -3078,7 +3291,7 @@ files4.action(async (directory_id, options_json) => {
3078
3291
  var directories3 = new Command23("directories");
3079
3292
  directories3.description("Explore directories");
3080
3293
  directories3.addCommand(get8);
3081
- directories3.addCommand(search11);
3294
+ directories3.addCommand(search15);
3082
3295
  directories3.addCommand(set_description7);
3083
3296
  directories3.addCommand(children2);
3084
3297
  directories3.addCommand(files4);
@@ -3128,10 +3341,10 @@ get9.action(async (id) => {
3128
3341
 
3129
3342
  // src/cli/commands/dependencies/search.ts
3130
3343
  import { Command as Command25 } from "commander";
3131
- var search12 = new Command25("search");
3132
- search12.description("Search dependencies with JSON options");
3133
- search12.argument("<options>", "JSON options");
3134
- search12.action(async (options_json) => {
3344
+ var search16 = new Command25("search");
3345
+ search16.description("Search dependencies with JSON options");
3346
+ search16.argument("<options>", "JSON options");
3347
+ search16.action(async (options_json) => {
3135
3348
  const wiki = await load_wiki();
3136
3349
  const options = parse_options(options_json, DependencySearchOptions, "dependencies search");
3137
3350
  const results = wiki.dependencies.search(options);
@@ -3187,7 +3400,7 @@ used_by_symbol3.action(async (symbol_id, options_json) => {
3187
3400
  var dependencies = new Command29("dependencies");
3188
3401
  dependencies.description("Explore dependencies");
3189
3402
  dependencies.addCommand(get9);
3190
- dependencies.addCommand(search12);
3403
+ dependencies.addCommand(search16);
3191
3404
  dependencies.addCommand(set_description8);
3192
3405
  dependencies.addCommand(used_by_file3);
3193
3406
  dependencies.addCommand(used_by_symbol3);
@@ -3232,4 +3445,4 @@ async function run(argv) {
3232
3445
  export {
3233
3446
  run
3234
3447
  };
3235
- //# sourceMappingURL=index.js.map
3448
+ //# sourceMappingURL=cli.js.map