@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.
@@ -39,14 +39,13 @@ var import_commander30 = require("commander");
39
39
  var import_commander = require("commander");
40
40
 
41
41
  // src/cli/env.ts
42
- var import_fs2 = require("fs");
42
+ var import_node_fs2 = require("fs");
43
43
 
44
44
  // src/internals/context.ts
45
45
  var import_typescript = __toESM(require("typescript"), 1);
46
- var import_url = require("url");
47
46
  var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
48
47
  var import_promises2 = require("fs/promises");
49
- var import_path2 = __toESM(require("path"), 1);
48
+ var import_node_path2 = __toESM(require("path"), 1);
50
49
  var import_better_sqlite32 = require("drizzle-orm/better-sqlite3");
51
50
 
52
51
  // ../errors/dist/index.js
@@ -110,6 +109,7 @@ var index_default = errors;
110
109
  var err = index_default({
111
110
  file_outside_project_path: (data) => `File "${data.file_path}" is outside project path "${data.project_path}"`,
112
111
  file_not_found: (data) => `File not found: ${data.path}`,
112
+ file_stat_error: (data) => `Could not get file stats for ${data.path}: ${data.reason}`,
113
113
  db_error: (data) => `Database error in ${data.operation}: ${data.reason}`,
114
114
  symbol_meta_parse_error: (data) => `Failed to parse symbol metadata for symbol ${data.symbol_id}: ${data.reason}`,
115
115
  exported_symbol_not_found: (data) => `Exported symbol "${data.name}" not found in file with id ${data.file_id}`,
@@ -122,6 +122,8 @@ var err = index_default({
122
122
  symbol_node_not_found: (data) => `Symbol node not found for ${data.name} in ${data.file_path}`,
123
123
  symbol_not_found: (data) => `Symbol "${data.name}" not found in file "${data.path}"`,
124
124
  describe_dependency_failed: (data) => `Failed to describe ${data.package}#${data.name}: ${data.reason}`,
125
+ could_not_describe_files_due_to_pending_symbols: (data) => `Cannot start describing files before describing all symbols; ${data.count} symbols are still pending`,
126
+ could_not_describe_directories_due_to_pending_files: (data) => `Cannot start describing directories before describing all files; ${data.count} files are still pending`,
125
127
  // CLI errors
126
128
  could_not_read_file: (data) => `Could not read file ${data.path}: ${data.reason}`,
127
129
  invalid_json: (data) => `Invalid JSON: ${data.reason}`,
@@ -131,7 +133,7 @@ var err = index_default({
131
133
 
132
134
  // src/db/migrate.ts
133
135
  var import_promises = require("fs/promises");
134
- var import_path = require("path");
136
+ var import_node_path = require("path");
135
137
  var import_drizzle_orm2 = require("drizzle-orm");
136
138
 
137
139
  // src/db/schema.ts
@@ -457,7 +459,7 @@ async function get_applied_migration_names({ db: db6 }) {
457
459
  return new Set(applied.map((x) => x.name));
458
460
  }
459
461
  async function apply_migration({ sqlite, migrations_path }, filename) {
460
- const file_path = (0, import_path.join)(migrations_path, filename);
462
+ const file_path = (0, import_node_path.join)(migrations_path, filename);
461
463
  const queries = await (0, import_promises.readFile)(file_path, "utf-8");
462
464
  sqlite.transaction(() => {
463
465
  sqlite.exec(queries);
@@ -482,6 +484,9 @@ function do_search(db6, table, options) {
482
484
  if (!options.select.includes("id")) options.select.push("id");
483
485
  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();
484
486
  }
487
+ function do_count(db6, table, options) {
488
+ return db6.select({ count: (0, import_drizzle_orm3.count)() }).from(table).where(conditions(table, options)).get()?.count ?? 0;
489
+ }
485
490
  function fields(table, fields2) {
486
491
  const res = {};
487
492
  for (const field of fields2) res[field] = table[field];
@@ -533,8 +538,10 @@ __export(files_exports, {
533
538
  by_directory_path: () => by_directory_path,
534
539
  by_id: () => by_id,
535
540
  by_id_and_state: () => by_id_and_state,
541
+ by_ids: () => by_ids,
536
542
  by_path: () => by_path,
537
543
  by_state: () => by_state,
544
+ count: () => count2,
538
545
  del: () => del,
539
546
  del_by_dir: () => del_by_dir,
540
547
  get_directory_ids: () => get_directory_ids,
@@ -548,48 +555,6 @@ __export(files_exports, {
548
555
  });
549
556
  var import_drizzle_orm5 = require("drizzle-orm");
550
557
 
551
- // src/internals/utils.ts
552
- var import_fs = require("fs");
553
- var parse_json = err.safe(JSON.parse, (reason, text2) => err.new("invalid_json", { reason, text: text2 }));
554
- var read_file = err.safe(
555
- (path6) => (0, import_fs.readFileSync)(path6, "utf-8"),
556
- (reason, path6) => err.new("could_not_read_file", { path: path6, reason })
557
- );
558
- function group_by_unique(items, key) {
559
- const groups = {};
560
- for (const item of items) {
561
- groups[key(item)] = item;
562
- }
563
- return groups;
564
- }
565
- function expand({ items, get_children, get_key }) {
566
- const visited = /* @__PURE__ */ new Set();
567
- const result = [];
568
- const queue = [...items];
569
- while (queue.length > 0) {
570
- const item = queue.shift();
571
- const key = get_key(item);
572
- if (err.any(key)) return key;
573
- if (visited.has(key)) continue;
574
- visited.add(key);
575
- result.push(item);
576
- const children3 = get_children(item);
577
- if (err.any(children3)) return children3;
578
- queue.push(...children3);
579
- }
580
- return result;
581
- }
582
- function uniq(items) {
583
- return [...new Set(items)];
584
- }
585
- function merge(a, b) {
586
- const res = { ...a };
587
- for (const key of Object.keys(b)) {
588
- if (b[key] !== void 0) res[key] = b[key];
589
- }
590
- return res;
591
- }
592
-
593
558
  // src/db/defaults.ts
594
559
  var files2 = {
595
560
  select: ["id", "directory_id", "path", "state", "error"],
@@ -619,6 +584,34 @@ var external_dependencies2 = {
619
584
  offset: 0,
620
585
  where: {}
621
586
  };
587
+ var imports2 = {
588
+ select: ["id", "exporter_file_id", "importer_file_id", "symbol_id", "name", "alias", "is_dynamic", "state", "error"],
589
+ order_by: ["id", "asc"],
590
+ limit: 20,
591
+ offset: 0,
592
+ where: {}
593
+ };
594
+ var external_imports2 = {
595
+ select: ["id", "file_id", "external_dependency_id", "alias", "is_dynamic"],
596
+ order_by: ["id", "asc"],
597
+ limit: 20,
598
+ offset: 0,
599
+ where: {}
600
+ };
601
+ var symbol_internal_links2 = {
602
+ select: ["id", "from_file_id", "to_file_id", "from_symbol_id", "to_symbol_id", "state", "error"],
603
+ order_by: ["id", "asc"],
604
+ limit: 20,
605
+ offset: 0,
606
+ where: {}
607
+ };
608
+ var symbol_external_links2 = {
609
+ select: ["id", "symbol_id", "external_import_id"],
610
+ order_by: ["id", "asc"],
611
+ limit: 20,
612
+ offset: 0,
613
+ where: {}
614
+ };
622
615
 
623
616
  // src/db/files.ts
624
617
  var default_select_fields = ["id", "directory_id", "path", "state", "error"];
@@ -626,15 +619,23 @@ var all = safe_query("files.all", (ctx) => ctx.db.select().from(files).all());
626
619
  var search = safe_query("files.search", (ctx, options = {}) => {
627
620
  return do_search(ctx.db, files, merge(files2, options));
628
621
  });
622
+ var count2 = safe_query("files.count", (ctx, where = {}) => {
623
+ return do_count(ctx.db, files, where);
624
+ });
629
625
  var by_id = safe_query("files.by_id", (ctx, id) => ctx.db.select().from(files).where((0, import_drizzle_orm5.eq)(files.id, id)).get());
626
+ var by_ids = safe_query(
627
+ "files.by_ids",
628
+ (ctx, ids) => ctx.db.select().from(files).where((0, import_drizzle_orm5.inArray)(files.id, ids)).all()
629
+ );
630
630
  var by_path = safe_query(
631
631
  "files.by_path",
632
632
  (ctx, path6) => ctx.db.select().from(files).where((0, import_drizzle_orm5.eq)(files.path, path6)).get()
633
633
  );
634
- var by_state = safe_query(
635
- "files.by_state",
636
- (ctx, state) => ctx.db.select().from(files).where((0, import_drizzle_orm5.eq)(files.state, state)).all()
637
- );
634
+ var by_state = safe_query("files.by_state", (ctx, state, limit) => {
635
+ let query = ctx.db.select().from(files).where((0, import_drizzle_orm5.eq)(files.state, state));
636
+ if (limit) query = query.limit(limit);
637
+ return query.all();
638
+ });
638
639
  var insert = safe_query("files.insert", (ctx, values) => ctx.db.insert(files).values(values).run());
639
640
  var update = safe_query(
640
641
  "files.update",
@@ -676,8 +677,8 @@ var using_dependency = safe_query(
676
677
  "files.using_dependency",
677
678
  (ctx, external_dependency_id, fields_to_select = default_select_fields) => {
678
679
  if (!fields_to_select.includes("id")) fields_to_select.push("id");
679
- const imports2 = ctx.db.select({ file_id: external_imports.file_id }).from(external_imports).where((0, import_drizzle_orm5.eq)(external_imports.external_dependency_id, external_dependency_id)).all();
680
- const file_ids = uniq(imports2.map((i) => i.file_id));
680
+ const imports4 = ctx.db.select({ file_id: external_imports.file_id }).from(external_imports).where((0, import_drizzle_orm5.eq)(external_imports.external_dependency_id, external_dependency_id)).all();
681
+ const file_ids = uniq(imports4.map((i) => i.file_id));
681
682
  if (file_ids.length === 0) return [];
682
683
  return ctx.db.select(fields(files, fields_to_select)).from(files).where((0, import_drizzle_orm5.inArray)(files.id, file_ids)).all();
683
684
  }
@@ -708,8 +709,10 @@ var directories_exports = {};
708
709
  __export(directories_exports, {
709
710
  by_id: () => by_id2,
710
711
  by_id_and_state: () => by_id_and_state2,
712
+ by_ids: () => by_ids2,
711
713
  by_path: () => by_path2,
712
714
  by_state: () => by_state2,
715
+ count: () => count3,
713
716
  insert: () => insert2,
714
717
  search: () => search2,
715
718
  update: () => update2,
@@ -720,6 +723,10 @@ var by_id2 = safe_query(
720
723
  "directories.by_id",
721
724
  (ctx, id) => ctx.db.select().from(directories).where((0, import_drizzle_orm6.eq)(directories.id, id)).get()
722
725
  );
726
+ var by_ids2 = safe_query(
727
+ "directories.by_ids",
728
+ (ctx, ids) => ctx.db.select().from(directories).where((0, import_drizzle_orm6.inArray)(directories.id, ids)).all()
729
+ );
723
730
  var by_path2 = safe_query(
724
731
  "directories.by_path",
725
732
  (ctx, path6) => ctx.db.select().from(directories).where((0, import_drizzle_orm6.eq)(directories.path, path6)).get()
@@ -747,6 +754,9 @@ var by_id_and_state2 = safe_query(
747
754
  var search2 = safe_query("directories.search", (ctx, options = {}) => {
748
755
  return do_search(ctx.db, directories, merge(directories2, options));
749
756
  });
757
+ var count3 = safe_query("directories.count", (ctx, where = {}) => {
758
+ return do_count(ctx.db, directories, where);
759
+ });
750
760
 
751
761
  // src/db/imports.ts
752
762
  var imports_exports = {};
@@ -754,11 +764,23 @@ __export(imports_exports, {
754
764
  by_exporter_file: () => by_exporter_file,
755
765
  by_importer_file: () => by_importer_file,
756
766
  by_state: () => by_state3,
767
+ count: () => count4,
768
+ count_pending_symbols: () => count_pending_symbols,
757
769
  del_by_importer_file: () => del_by_importer_file,
758
770
  insert_many: () => insert_many,
771
+ search: () => search3,
759
772
  update: () => update3
760
773
  });
761
774
  var import_drizzle_orm7 = require("drizzle-orm");
775
+ var search3 = safe_query("imports.search", (ctx, options = {}) => {
776
+ return do_search(ctx.db, imports, merge(imports2, options));
777
+ });
778
+ var count4 = safe_query("imports.count", (ctx, where = {}) => {
779
+ return do_count(ctx.db, imports, where);
780
+ });
781
+ var count_pending_symbols = safe_query("imports.count_pending_symbols", (ctx, file_id) => {
782
+ return ctx.db.select({ count: (0, import_drizzle_orm7.count)() }).from(imports).innerJoin(symbols, (0, import_drizzle_orm7.eq)(imports.symbol_id, symbols.id)).where((0, import_drizzle_orm7.and)((0, import_drizzle_orm7.eq)(imports.importer_file_id, file_id), (0, import_drizzle_orm7.ne)(symbols.state, "ready"))).get()?.count ?? 0;
783
+ });
762
784
  var by_exporter_file = safe_query(
763
785
  "imports.by_exporter_file",
764
786
  (ctx, exporter_file_id) => ctx.db.select().from(imports).where((0, import_drizzle_orm7.eq)(imports.exporter_file_id, exporter_file_id)).all()
@@ -788,17 +810,67 @@ __export(symbols_exports, {
788
810
  by_file_and_name: () => by_file_and_name,
789
811
  by_id: () => by_id3,
790
812
  by_id_and_state: () => by_id_and_state3,
813
+ by_ids: () => by_ids3,
791
814
  by_state: () => by_state4,
815
+ count: () => count5,
792
816
  del_by_file: () => del_by_file,
793
817
  insert_many: () => insert_many2,
794
818
  meta: () => meta,
795
819
  referenced_by: () => referenced_by,
796
820
  referencing: () => referencing,
797
- search: () => search3,
821
+ search: () => search4,
798
822
  update: () => update4,
799
823
  using_dependency: () => using_dependency2
800
824
  });
801
825
  var import_drizzle_orm8 = require("drizzle-orm");
826
+
827
+ // src/internals/utils.ts
828
+ var import_node_fs = require("fs");
829
+ var parse_json = err.safe(JSON.parse, (reason, text2) => err.new("invalid_json", { reason, text: text2 }));
830
+ var read_file = err.safe(
831
+ (path6) => (0, import_node_fs.readFileSync)(path6, "utf-8"),
832
+ (reason, path6) => err.new("could_not_read_file", { path: path6, reason })
833
+ );
834
+ var file_stat = err.safe(
835
+ (path6) => (0, import_node_fs.statSync)(path6),
836
+ (reason, path6) => err.new("file_stat_error", { path: path6, reason })
837
+ );
838
+ function group_by_unique(items, key) {
839
+ const groups = {};
840
+ for (const item of items) {
841
+ groups[key(item)] = item;
842
+ }
843
+ return groups;
844
+ }
845
+ function expand({ items, get_children, get_key }) {
846
+ const visited = /* @__PURE__ */ new Set();
847
+ const result = [];
848
+ const queue = [...items];
849
+ while (queue.length > 0) {
850
+ const item = queue.shift();
851
+ const key = get_key(item);
852
+ if (err.any(key)) return key;
853
+ if (visited.has(key)) continue;
854
+ visited.add(key);
855
+ result.push(item);
856
+ const children3 = get_children(item);
857
+ if (err.any(children3)) return children3;
858
+ queue.push(...children3);
859
+ }
860
+ return result;
861
+ }
862
+ function uniq(items) {
863
+ return [...new Set(items)];
864
+ }
865
+ function merge(a, b) {
866
+ const res = { ...a };
867
+ for (const key of Object.keys(b)) {
868
+ if (b[key] !== void 0) res[key] = b[key];
869
+ }
870
+ return res;
871
+ }
872
+
873
+ // src/db/symbols.ts
802
874
  var insert_many2 = safe_query("symbols.insert_many", (ctx, values) => ctx.db.insert(symbols).values(values).run());
803
875
  var del_by_file = safe_query(
804
876
  "symbols.delete_by_file",
@@ -821,6 +893,10 @@ var update4 = safe_query(
821
893
  (ctx, id, data) => ctx.db.update(symbols).set(data).where((0, import_drizzle_orm8.eq)(symbols.id, id)).run()
822
894
  );
823
895
  var by_id3 = safe_query("symbols.by_id", (ctx, id) => ctx.db.select().from(symbols).where((0, import_drizzle_orm8.eq)(symbols.id, id)).get());
896
+ var by_ids3 = safe_query(
897
+ "symbols.by_ids",
898
+ (ctx, ids) => ctx.db.select().from(symbols).where((0, import_drizzle_orm8.inArray)(symbols.id, ids)).all()
899
+ );
824
900
  var by_id_and_state3 = safe_query(
825
901
  "symbols.by_id_and_state",
826
902
  (ctx, params) => ctx.db.select().from(symbols).where((0, import_drizzle_orm8.and)((0, import_drizzle_orm8.eq)(symbols.id, params.id), (0, import_drizzle_orm8.eq)(symbols.state, params.state))).get()
@@ -831,8 +907,12 @@ function meta(symbol) {
831
907
  (reason) => err.new("symbol_meta_parse_error", { reason, symbol_id: symbol.id, meta: symbol.meta })
832
908
  );
833
909
  }
834
- var search3 = safe_query("symbols.search", (ctx, options = {}) => {
835
- return do_search(ctx.db, symbols, merge(symbols2, options));
910
+ var search4 = safe_query(
911
+ "symbols.search",
912
+ (ctx, options = {}) => do_search(ctx.db, symbols, merge(symbols2, options))
913
+ );
914
+ var count5 = safe_query("symbols.count", (ctx, where = {}) => {
915
+ return do_count(ctx.db, symbols, where);
836
916
  });
837
917
  var referenced_by = safe_query(
838
918
  "symbols.referenced_by",
@@ -870,11 +950,13 @@ var external_dependencies_exports = {};
870
950
  __export(external_dependencies_exports, {
871
951
  all: () => all2,
872
952
  by_id: () => by_id4,
953
+ by_ids: () => by_ids4,
873
954
  by_package_subpath_and_name: () => by_package_subpath_and_name,
874
955
  by_state: () => by_state5,
956
+ count: () => count6,
875
957
  get_or_create: () => get_or_create,
876
958
  insert: () => insert3,
877
- search: () => search4,
959
+ search: () => search5,
878
960
  update: () => update5,
879
961
  used_by_file: () => used_by_file,
880
962
  used_by_symbol: () => used_by_symbol
@@ -884,6 +966,10 @@ var by_id4 = safe_query(
884
966
  "external_dependencies.by_id",
885
967
  (ctx, id) => ctx.db.select().from(external_dependencies).where((0, import_drizzle_orm9.eq)(external_dependencies.id, id)).get()
886
968
  );
969
+ var by_ids4 = safe_query(
970
+ "external_dependencies.by_ids",
971
+ (ctx, ids) => ctx.db.select().from(external_dependencies).where((0, import_drizzle_orm9.inArray)(external_dependencies.id, ids)).all()
972
+ );
887
973
  var by_state5 = safe_query(
888
974
  "external_dependencies.by_state",
889
975
  (ctx, state) => ctx.db.select().from(external_dependencies).where((0, import_drizzle_orm9.eq)(external_dependencies.state, state)).all()
@@ -913,11 +999,13 @@ function get_or_create(ctx, value) {
913
999
  (existing) => existing || insert3(ctx, value)
914
1000
  );
915
1001
  }
916
- var search4 = safe_query(
1002
+ var search5 = safe_query(
917
1003
  "external_dependencies.search",
918
- (ctx, options = {}) => {
919
- return do_search(ctx.db, external_dependencies, merge(external_dependencies2, options));
920
- }
1004
+ (ctx, options = {}) => do_search(ctx.db, external_dependencies, merge(external_dependencies2, options))
1005
+ );
1006
+ var count6 = safe_query(
1007
+ "external_dependencies.count",
1008
+ (ctx, where = {}) => do_count(ctx.db, external_dependencies, where)
921
1009
  );
922
1010
  var used_by_file = safe_query(
923
1011
  "external_dependencies.used_by_file",
@@ -949,10 +1037,22 @@ __export(external_imports_exports, {
949
1037
  by_external_dependency: () => by_external_dependency,
950
1038
  by_file: () => by_file2,
951
1039
  by_symbol: () => by_symbol,
1040
+ count: () => count7,
1041
+ count_pending_dependencies: () => count_pending_dependencies,
952
1042
  del_by_file: () => del_by_file2,
953
- insert_many: () => insert_many3
1043
+ insert_many: () => insert_many3,
1044
+ search: () => search6
954
1045
  });
955
1046
  var import_drizzle_orm10 = require("drizzle-orm");
1047
+ var search6 = safe_query("external_imports.search", (ctx, options = {}) => {
1048
+ return do_search(ctx.db, external_imports, merge(external_imports2, options));
1049
+ });
1050
+ var count7 = safe_query("external_imports.count", (ctx, where = {}) => {
1051
+ return do_count(ctx.db, external_imports, where);
1052
+ });
1053
+ var count_pending_dependencies = safe_query("external_imports.count_pending_dependencies", (ctx, file_id) => {
1054
+ return ctx.db.select({ count: (0, import_drizzle_orm10.count)() }).from(external_imports).innerJoin(external_dependencies, (0, import_drizzle_orm10.eq)(external_imports.external_dependency_id, external_dependencies.id)).where((0, import_drizzle_orm10.and)((0, import_drizzle_orm10.eq)(external_imports.file_id, file_id), (0, import_drizzle_orm10.ne)(external_dependencies.state, "ready"))).get()?.count ?? 0;
1055
+ });
956
1056
  var insert_many3 = safe_query(
957
1057
  "external_imports.insert_many",
958
1058
  (ctx, values) => ctx.db.insert(external_imports).values(values).run()
@@ -987,11 +1087,20 @@ var by_symbol = safe_query(
987
1087
  var symbol_internal_links_exports = {};
988
1088
  __export(symbol_internal_links_exports, {
989
1089
  by_from_symbol: () => by_from_symbol,
1090
+ count: () => count8,
990
1091
  del_by_from_symbol: () => del_by_from_symbol,
991
1092
  exists: () => exists,
992
- insert: () => insert4
1093
+ insert: () => insert4,
1094
+ search: () => search7,
1095
+ update_state_by_to_symbol: () => update_state_by_to_symbol
993
1096
  });
994
1097
  var import_drizzle_orm11 = require("drizzle-orm");
1098
+ var search7 = safe_query("symbol_internal_links.search", (ctx, options = {}) => {
1099
+ return do_search(ctx.db, symbol_internal_links, merge(symbol_internal_links2, options));
1100
+ });
1101
+ var count8 = safe_query("symbol_internal_links.count", (ctx, where = {}) => {
1102
+ return do_count(ctx.db, symbol_internal_links, where);
1103
+ });
995
1104
  var by_from_symbol = safe_query(
996
1105
  "symbol_internal_links.by_from_symbol",
997
1106
  (ctx, from_symbol_id) => ctx.db.query.symbol_internal_links.findMany({
@@ -1017,17 +1126,37 @@ var del_by_from_symbol = safe_query(
1017
1126
  "symbol_internal_links.del_by_from_symbol",
1018
1127
  (ctx, from_symbol_id) => ctx.db.delete(symbol_internal_links).where((0, import_drizzle_orm11.eq)(symbol_internal_links.from_symbol_id, from_symbol_id)).run()
1019
1128
  );
1129
+ var update_state_by_to_symbol = safe_query(
1130
+ "symbol_internal_links.update_state_by_to_symbol",
1131
+ (ctx, to_symbol_id, state) => ctx.db.update(symbol_internal_links).set({ state }).where((0, import_drizzle_orm11.eq)(symbol_internal_links.to_symbol_id, to_symbol_id)).run()
1132
+ );
1020
1133
 
1021
1134
  // src/db/symbol_external_links.ts
1022
1135
  var symbol_external_links_exports = {};
1023
1136
  __export(symbol_external_links_exports, {
1024
1137
  by_external_import: () => by_external_import,
1025
1138
  by_symbol: () => by_symbol2,
1139
+ count: () => count9,
1140
+ count_by_dependency: () => count_by_dependency,
1141
+ count_pending_deps: () => count_pending_deps,
1026
1142
  del_by_symbol: () => del_by_symbol,
1027
1143
  exists: () => exists2,
1028
- insert: () => insert5
1144
+ insert: () => insert5,
1145
+ search: () => search8
1029
1146
  });
1030
1147
  var import_drizzle_orm12 = require("drizzle-orm");
1148
+ var search8 = safe_query("symbol_external_links.search", (ctx, options = {}) => {
1149
+ return do_search(ctx.db, symbol_external_links, merge(symbol_external_links2, options));
1150
+ });
1151
+ var count9 = safe_query("symbol_external_links.count", (ctx, where = {}) => {
1152
+ return do_count(ctx.db, symbol_external_links, where);
1153
+ });
1154
+ var count_by_dependency = safe_query("symbol_external_links.count_by_dependency", (ctx, dependency_id) => {
1155
+ return ctx.db.select({ count: (0, import_drizzle_orm12.count)() }).from(symbol_external_links).innerJoin(external_imports, (0, import_drizzle_orm12.eq)(symbol_external_links.external_import_id, external_imports.id)).where((0, import_drizzle_orm12.eq)(external_imports.external_dependency_id, dependency_id)).get()?.count ?? 0;
1156
+ });
1157
+ var count_pending_deps = safe_query("symbol_external_links.count_pending_deps", (ctx, symbol_id) => {
1158
+ return ctx.db.select({ count: (0, import_drizzle_orm12.count)() }).from(symbol_external_links).innerJoin(external_imports, (0, import_drizzle_orm12.eq)(symbol_external_links.external_import_id, external_imports.id)).innerJoin(external_dependencies, (0, import_drizzle_orm12.eq)(external_imports.external_dependency_id, external_dependencies.id)).where((0, import_drizzle_orm12.and)((0, import_drizzle_orm12.eq)(symbol_external_links.symbol_id, symbol_id), (0, import_drizzle_orm12.ne)(external_dependencies.state, "ready"))).get()?.count ?? 0;
1159
+ });
1031
1160
  var by_symbol2 = safe_query(
1032
1161
  "symbol_external_links.by_symbol",
1033
1162
  (ctx, symbol_id) => ctx.db.select().from(symbol_external_links).where((0, import_drizzle_orm12.eq)(symbol_external_links.symbol_id, symbol_id)).all()
@@ -1050,19 +1179,18 @@ var del_by_symbol = safe_query(
1050
1179
  );
1051
1180
 
1052
1181
  // src/internals/context.ts
1053
- var import_meta = {};
1054
1182
  async function create_context(sqlite, db6, config) {
1055
- const project_path = import_path2.default.resolve(config.project_path);
1056
- const currentDir = (0, import_path2.dirname)((0, import_url.fileURLToPath)(import_meta.url));
1057
- const migrations_path = currentDir.includes("/dist") ? (0, import_path2.join)(currentDir, "../migrations") : (0, import_path2.join)(currentDir, "../../migrations");
1058
- const tsconfig_path = (0, import_path2.join)(project_path, "tsconfig.json");
1183
+ const project_path = import_node_path2.default.resolve(config.project_path);
1184
+ const currentDir = __dirname;
1185
+ const migrations_path = currentDir.includes("/dist") ? (0, import_node_path2.join)(currentDir, "../migrations") : (0, import_node_path2.join)(currentDir, "../../migrations");
1186
+ const tsconfig_path = (0, import_node_path2.join)(project_path, "tsconfig.json");
1059
1187
  if (!import_typescript.default.sys.fileExists(tsconfig_path)) {
1060
1188
  throw err.new("file_not_found", { path: tsconfig_path });
1061
1189
  }
1062
1190
  const tsconfig = import_typescript.default.parseJsonConfigFileContent(import_typescript.default.readConfigFile(tsconfig_path, import_typescript.default.sys.readFile).config, import_typescript.default.sys, project_path);
1063
1191
  const program = import_typescript.default.createProgram({ rootNames: tsconfig.fileNames, options: tsconfig.options });
1064
- const package_json_path = config.package_json_path ?? import_path2.default.join(project_path, "package.json");
1065
- const node_modules_paths = config.node_modules_paths ?? [import_path2.default.join(project_path, "node_modules")];
1192
+ const package_json_path = config.package_json_path ?? import_node_path2.default.join(project_path, "package.json");
1193
+ const node_modules_paths = config.node_modules_paths ?? [import_node_path2.default.join(project_path, "node_modules")];
1066
1194
  const dependencies2 = await get_dependencies(package_json_path, node_modules_paths);
1067
1195
  const ctx = { db: db6, sqlite, migrations_path, project_path, program, dependencies: dependencies2 };
1068
1196
  await migrate(ctx);
@@ -1121,7 +1249,7 @@ async function get_dependencies(package_json_path, node_modules_paths) {
1121
1249
  async function get_github_repo(node_modules_paths, package_name) {
1122
1250
  for (const node_modules_path of node_modules_paths) {
1123
1251
  try {
1124
- const package_json_path = import_path2.default.join(node_modules_path, package_name, "package.json");
1252
+ const package_json_path = import_node_path2.default.join(node_modules_path, package_name, "package.json");
1125
1253
  const package_json = JSON.parse(await (0, import_promises2.readFile)(package_json_path, "utf-8"));
1126
1254
  const url = package_json.repository?.url || package_json.repository;
1127
1255
  if (typeof url === "string") {
@@ -1138,7 +1266,7 @@ async function get_github_repo(node_modules_paths, package_name) {
1138
1266
  // src/cli/env.ts
1139
1267
  var env = {
1140
1268
  read_file,
1141
- file_exists: (path6) => (0, import_fs2.existsSync)(path6),
1269
+ file_exists: (path6) => (0, import_node_fs2.existsSync)(path6),
1142
1270
  argv: () => process.argv,
1143
1271
  log: (...args) => console.log(...args),
1144
1272
  error: (...args) => console.error(...args),
@@ -1262,7 +1390,7 @@ var DependencySelectOptions = import_zod.z.object({
1262
1390
  });
1263
1391
 
1264
1392
  // src/update/track_changes.ts
1265
- var import_path3 = __toESM(require("path"), 1);
1393
+ var import_node_path3 = __toESM(require("path"), 1);
1266
1394
  var import_typescript2 = require("typescript");
1267
1395
  var import_promises3 = require("fs/promises");
1268
1396
 
@@ -1273,9 +1401,9 @@ function file_updated(ctx, file_id) {
1273
1401
  items: [file_id],
1274
1402
  get_key: (id) => id,
1275
1403
  get_children: (id) => {
1276
- const imports2 = imports_exports.by_exporter_file(ctx, id);
1277
- if (err.any(imports2)) return imports2;
1278
- return imports2.map((x) => x.importer_file_id);
1404
+ const imports4 = imports_exports.by_exporter_file(ctx, id);
1405
+ if (err.any(imports4)) return imports4;
1406
+ return imports4.map((x) => x.importer_file_id);
1279
1407
  }
1280
1408
  })
1281
1409
  );
@@ -1308,7 +1436,7 @@ function get_source_files(ctx) {
1308
1436
  for (const file of ctx.program.getSourceFiles()) {
1309
1437
  if (ctx.program.isSourceFileDefaultLibrary(file)) continue;
1310
1438
  if (ctx.program.isSourceFileFromExternalLibrary(file)) continue;
1311
- if (!import_path3.default.resolve(file.fileName).startsWith(ctx.project_path)) continue;
1439
+ if (!import_node_path3.default.resolve(file.fileName).startsWith(ctx.project_path)) continue;
1312
1440
  src_files.push(file);
1313
1441
  }
1314
1442
  return src_files;
@@ -1356,7 +1484,7 @@ async function changes(ctx, source_files, db_files) {
1356
1484
  return { created, updated, deleted };
1357
1485
  }
1358
1486
  function get_file_path(ctx, file) {
1359
- const absolute_path = import_path3.default.resolve(file.fileName);
1487
+ const absolute_path = import_node_path3.default.resolve(file.fileName);
1360
1488
  if (absolute_path.startsWith(ctx.project_path)) return absolute_path.slice(ctx.project_path.length);
1361
1489
  return err.new("file_outside_project_path", { file_path: absolute_path, project_path: ctx.project_path });
1362
1490
  }
@@ -1364,10 +1492,10 @@ function get_parents_paths(ctx, file) {
1364
1492
  const file_path = get_file_path(ctx, file);
1365
1493
  if (err.any(file_path)) return file_path;
1366
1494
  const dirs = [];
1367
- let current = import_path3.default.dirname(file_path);
1368
- while (current !== import_path3.default.sep) {
1495
+ let current = import_node_path3.default.dirname(file_path);
1496
+ while (current !== import_node_path3.default.sep) {
1369
1497
  dirs.push(current);
1370
- current = import_path3.default.dirname(current);
1498
+ current = import_node_path3.default.dirname(current);
1371
1499
  }
1372
1500
  dirs.push(current);
1373
1501
  return dirs.reverse();
@@ -1401,19 +1529,19 @@ async function sync_external_dependencies(ctx) {
1401
1529
  }
1402
1530
 
1403
1531
  // src/update/scan_files/scan_files.ts
1404
- var import_path5 = __toESM(require("path"), 1);
1532
+ var import_node_path5 = __toESM(require("path"), 1);
1405
1533
  var import_typescript10 = __toESM(require("typescript"), 1);
1406
1534
 
1407
1535
  // src/update/scan_files/imports.ts
1408
1536
  var import_typescript4 = __toESM(require("typescript"), 1);
1409
1537
 
1410
1538
  // src/update/scan_files/common.ts
1411
- var import_path4 = __toESM(require("path"), 1);
1539
+ var import_node_path4 = __toESM(require("path"), 1);
1412
1540
  var import_typescript3 = __toESM(require("typescript"), 1);
1413
1541
  function is_external_module(ctx, source_file, module_path) {
1414
1542
  const resolved = import_typescript3.default.resolveModuleName(module_path, source_file.fileName, ctx.program.getCompilerOptions(), import_typescript3.default.sys);
1415
1543
  if (!resolved.resolvedModule) return true;
1416
- const resolved_path = import_path4.default.resolve(resolved.resolvedModule.resolvedFileName);
1544
+ const resolved_path = import_node_path4.default.resolve(resolved.resolvedModule.resolvedFileName);
1417
1545
  return !resolved_path.startsWith(ctx.project_path);
1418
1546
  }
1419
1547
  function has_export_modifier(node) {
@@ -1522,13 +1650,13 @@ function is_import(ctx, source_file, node) {
1522
1650
  return !is_external_module(ctx, source_file, node.moduleSpecifier.text);
1523
1651
  }
1524
1652
  function extract_import(ctx, source_file, node, file_id) {
1525
- const imports2 = [];
1653
+ const imports4 = [];
1526
1654
  const clause = node.importClause;
1527
- if (!clause || !node.moduleSpecifier || !import_typescript4.default.isStringLiteral(node.moduleSpecifier)) return imports2;
1655
+ if (!clause || !node.moduleSpecifier || !import_typescript4.default.isStringLiteral(node.moduleSpecifier)) return imports4;
1528
1656
  const exporter_file_id = resolve_exporter_file(ctx, source_file, node.moduleSpecifier.text);
1529
- if (err.any(exporter_file_id)) return imports2;
1657
+ if (err.any(exporter_file_id)) return imports4;
1530
1658
  if (clause.name) {
1531
- imports2.push({
1659
+ imports4.push({
1532
1660
  importer_file_id: file_id,
1533
1661
  exporter_file_id,
1534
1662
  name: "default",
@@ -1538,7 +1666,7 @@ function extract_import(ctx, source_file, node, file_id) {
1538
1666
  }
1539
1667
  if (clause.namedBindings && import_typescript4.default.isNamedImports(clause.namedBindings)) {
1540
1668
  for (const element of clause.namedBindings.elements) {
1541
- imports2.push({
1669
+ imports4.push({
1542
1670
  importer_file_id: file_id,
1543
1671
  exporter_file_id,
1544
1672
  name: (element.propertyName || element.name).text,
@@ -1548,7 +1676,7 @@ function extract_import(ctx, source_file, node, file_id) {
1548
1676
  }
1549
1677
  }
1550
1678
  if (clause.namedBindings && import_typescript4.default.isNamespaceImport(clause.namedBindings)) {
1551
- imports2.push({
1679
+ imports4.push({
1552
1680
  importer_file_id: file_id,
1553
1681
  exporter_file_id,
1554
1682
  name: "*",
@@ -1556,7 +1684,7 @@ function extract_import(ctx, source_file, node, file_id) {
1556
1684
  state: "to_link"
1557
1685
  });
1558
1686
  }
1559
- return imports2;
1687
+ return imports4;
1560
1688
  }
1561
1689
  function extract_dynamic_import(ctx, source_file, node, file_id) {
1562
1690
  const arg = node.arguments[0];
@@ -1668,7 +1796,7 @@ function extract_external_import_info(node) {
1668
1796
  }
1669
1797
  function extract_external_import(ctx, node, file_id) {
1670
1798
  const infos = extract_external_import_info(node);
1671
- const external_imports2 = [];
1799
+ const external_imports3 = [];
1672
1800
  for (const info of infos) {
1673
1801
  const dep_meta = Object.values(ctx.dependencies).find((dep) => info.package.startsWith(dep.name));
1674
1802
  const dependency = external_dependencies_exports.get_or_create(ctx, {
@@ -1681,9 +1809,9 @@ function extract_external_import(ctx, node, file_id) {
1681
1809
  state: "to_describe"
1682
1810
  });
1683
1811
  if (err.any(dependency)) return dependency;
1684
- external_imports2.push({ file_id, external_dependency_id: dependency.id, alias: info.alias, is_dynamic: false });
1812
+ external_imports3.push({ file_id, external_dependency_id: dependency.id, alias: info.alias, is_dynamic: false });
1685
1813
  }
1686
- return external_imports2;
1814
+ return external_imports3;
1687
1815
  }
1688
1816
  function extract_external_dynamic_import(ctx, node, file_id) {
1689
1817
  const arg = node.arguments[0];
@@ -1988,32 +2116,32 @@ function scan_file(ctx, file) {
1988
2116
  () => external_imports_exports.del_by_file(ctx, file.id),
1989
2117
  () => get_source_file(ctx, file.path),
1990
2118
  (source_file) => parse_file(ctx, source_file, file.id),
1991
- ({ imports: imports2, symbols: symbols4, external_imports: external_imports2 }) => err.pipe(
1992
- () => external_imports2.length && external_imports_exports.insert_many(ctx, external_imports2),
1993
- () => imports2.length && imports_exports.insert_many(ctx, imports2),
2119
+ ({ imports: imports4, symbols: symbols4, external_imports: external_imports3 }) => err.pipe(
2120
+ () => external_imports3.length && external_imports_exports.insert_many(ctx, external_imports3),
2121
+ () => imports4.length && imports_exports.insert_many(ctx, imports4),
1994
2122
  () => symbols4.length && symbols_exports.insert_many(ctx, symbols4)
1995
2123
  )
1996
2124
  );
1997
2125
  }
1998
2126
  function get_source_file(ctx, file_path) {
1999
- const source_file = ctx.program.getSourceFile(import_path5.default.join(ctx.project_path, file_path));
2127
+ const source_file = ctx.program.getSourceFile(import_node_path5.default.join(ctx.project_path, file_path));
2000
2128
  if (!source_file) return err.new("file_not_found", { path: file_path });
2001
2129
  return source_file;
2002
2130
  }
2003
2131
  function parse_file(ctx, source_file, file_id) {
2004
- const imports2 = [];
2132
+ const imports4 = [];
2005
2133
  const symbols4 = [];
2006
- const external_imports2 = [];
2134
+ const external_imports3 = [];
2007
2135
  function find_dynamic_imports(node) {
2008
2136
  if (is_dynamic_import(node)) {
2009
2137
  const arg = node.arguments[0];
2010
2138
  if (is_external_module(ctx, source_file, arg.text)) {
2011
2139
  const result = extract_external_dynamic_import(ctx, node, file_id);
2012
2140
  if (err.any(result)) return result;
2013
- external_imports2.push(result);
2141
+ external_imports3.push(result);
2014
2142
  } else {
2015
2143
  const result = extract_dynamic_import(ctx, source_file, node, file_id);
2016
- if (result) imports2.push(result);
2144
+ if (result) imports4.push(result);
2017
2145
  }
2018
2146
  }
2019
2147
  import_typescript10.default.forEachChild(node, find_dynamic_imports);
@@ -2026,24 +2154,24 @@ function parse_file(ctx, source_file, file_id) {
2026
2154
  error = res;
2027
2155
  return;
2028
2156
  }
2029
- imports2.push(...res.imports);
2157
+ imports4.push(...res.imports);
2030
2158
  symbols4.push(...res.symbols);
2031
- external_imports2.push(...res.external_imports);
2159
+ external_imports3.push(...res.external_imports);
2032
2160
  error = find_dynamic_imports(statement);
2033
2161
  });
2034
2162
  if (error) return error;
2035
- return { imports: imports2, symbols: symbols4, external_imports: external_imports2 };
2163
+ return { imports: imports4, symbols: symbols4, external_imports: external_imports3 };
2036
2164
  }
2037
2165
  function parse_node(ctx, source_file, node, file_id) {
2038
- const imports2 = [];
2166
+ const imports4 = [];
2039
2167
  const symbols4 = [];
2040
- const external_imports2 = [];
2168
+ const external_imports3 = [];
2041
2169
  if (is_external_import(ctx, source_file, node)) {
2042
2170
  const result = extract_external_import(ctx, node, file_id);
2043
2171
  if (err.any(result)) return result;
2044
- external_imports2.push(...result);
2172
+ external_imports3.push(...result);
2045
2173
  } else if (is_import(ctx, source_file, node)) {
2046
- imports2.push(...extract_import(ctx, source_file, node, file_id));
2174
+ imports4.push(...extract_import(ctx, source_file, node, file_id));
2047
2175
  } else if (import_typescript10.default.isExportAssignment(node) && !node.isExportEquals) {
2048
2176
  symbols4.push({
2049
2177
  file_id,
@@ -2085,14 +2213,14 @@ function parse_node(ctx, source_file, node, file_id) {
2085
2213
  symbols4.push(extract_class_symbol(node, file_id, source_file));
2086
2214
  symbols4.push(...extract_class_fields(node, file_id, source_file));
2087
2215
  }
2088
- return { imports: imports2, symbols: symbols4, external_imports: external_imports2 };
2216
+ return { imports: imports4, symbols: symbols4, external_imports: external_imports3 };
2089
2217
  }
2090
2218
 
2091
2219
  // src/update/link_imports.ts
2092
2220
  async function link_imports(ctx) {
2093
- const imports2 = err.or_throw(imports_exports.by_state(ctx, "to_link"));
2221
+ const imports4 = err.or_throw(imports_exports.by_state(ctx, "to_link"));
2094
2222
  let i = 0;
2095
- for (const import_ of imports2) {
2223
+ for (const import_ of imports4) {
2096
2224
  const res = link_import(ctx, import_);
2097
2225
  if (err.any(res)) err.or_throw(imports_exports.update(ctx, import_.id, { error: String(res) }));
2098
2226
  }
@@ -2108,7 +2236,7 @@ function link_import(ctx, import_) {
2108
2236
  }
2109
2237
 
2110
2238
  // src/update/link_symbols.ts
2111
- var import_path6 = __toESM(require("path"), 1);
2239
+ var import_node_path6 = __toESM(require("path"), 1);
2112
2240
  var import_typescript11 = __toESM(require("typescript"), 1);
2113
2241
  async function link_symbols(ctx) {
2114
2242
  const symbols4 = err.or_throw(symbols_exports.by_state(ctx, "to_link"));
@@ -2134,7 +2262,7 @@ function find_symbol_references(ctx, symbol) {
2134
2262
  const file = files_exports.by_id(ctx, symbol.file_id);
2135
2263
  if (err.any(file)) return file;
2136
2264
  if (!file) return err.new("file_not_found", { path: `file_id=${symbol.file_id}` });
2137
- const file_path = import_path6.default.join(ctx.project_path, file.path);
2265
+ const file_path = import_node_path6.default.join(ctx.project_path, file.path);
2138
2266
  const source_file = ctx.program.getSourceFile(file_path);
2139
2267
  if (!source_file) return err.new("file_not_found", { path: file_path });
2140
2268
  const symbol_node = find_symbol_node(source_file, symbol);
@@ -2359,7 +2487,7 @@ async function update6(ctx) {
2359
2487
 
2360
2488
  // src/counts.ts
2361
2489
  var import_drizzle_orm13 = require("drizzle-orm");
2362
- var counts = safe_query("counts", (ctx) => {
2490
+ function counts(ctx) {
2363
2491
  const symbol_counts = ctx.db.select({ state: symbols.state, count: (0, import_drizzle_orm13.count)() }).from(symbols).groupBy(symbols.state).all();
2364
2492
  const file_counts = ctx.db.select({ state: files.state, count: (0, import_drizzle_orm13.count)() }).from(files).groupBy(files.state).all();
2365
2493
  const dir_counts = ctx.db.select({ state: directories.state, count: (0, import_drizzle_orm13.count)() }).from(directories).groupBy(directories.state).all();
@@ -2370,7 +2498,7 @@ var counts = safe_query("counts", (ctx) => {
2370
2498
  directories: get_groups(dir_counts, ["to_describe", "ready"]),
2371
2499
  dependencies: get_groups(dep_counts, ["to_describe", "ready"])
2372
2500
  };
2373
- });
2501
+ }
2374
2502
  function get_groups(items, states) {
2375
2503
  const groups = { total: 0 };
2376
2504
  for (const state of states) groups[state] = 0;
@@ -2386,7 +2514,7 @@ function get_groups(items, states) {
2386
2514
  function files_wiki(ctx) {
2387
2515
  return {
2388
2516
  get: (id) => get2(ctx, id),
2389
- search: (options) => search5(ctx, options),
2517
+ search: (options) => search9(ctx, options),
2390
2518
  set_description: (id, description) => set_description(ctx, id, description),
2391
2519
  imported_by_file: (file_id, options) => imported_by_file(ctx, file_id, options),
2392
2520
  importing_file: (file_id, options) => importing_file(ctx, file_id, options),
@@ -2396,11 +2524,11 @@ function files_wiki(ctx) {
2396
2524
  function get2(ctx, id) {
2397
2525
  return err.or_throw(files_exports.by_id(ctx, id)) ?? null;
2398
2526
  }
2399
- function search5(ctx, options) {
2527
+ function search9(ctx, options) {
2400
2528
  return err.or_throw(files_exports.search(ctx, options));
2401
2529
  }
2402
2530
  function set_description(ctx, id, description) {
2403
- err.or_throw(files_exports.update(ctx, id, { description }));
2531
+ err.or_throw(files_exports.update(ctx, id, { description, state: "ready", error: null }));
2404
2532
  }
2405
2533
  function imported_by_file(ctx, file_id, options = {}) {
2406
2534
  let imported_files = err.or_throw(files_exports.imported_by(ctx, file_id, options.select));
@@ -2452,7 +2580,7 @@ function importing_dependency(ctx, dependency_id, options = {}) {
2452
2580
  function symbols_wiki(ctx) {
2453
2581
  return {
2454
2582
  get: (id) => get3(ctx, id),
2455
- search: (options) => search6(ctx, options),
2583
+ search: (options) => search10(ctx, options),
2456
2584
  set_description: (id, description) => set_description2(ctx, id, description),
2457
2585
  referencing_symbol: (symbol_id, options) => referencing_symbol(ctx, symbol_id, options),
2458
2586
  referenced_by_symbol: (symbol_id, options) => referenced_by_symbol(ctx, symbol_id, options),
@@ -2462,11 +2590,12 @@ function symbols_wiki(ctx) {
2462
2590
  function get3(ctx, id) {
2463
2591
  return err.or_throw(symbols_exports.by_id(ctx, id)) ?? null;
2464
2592
  }
2465
- function search6(ctx, options) {
2593
+ function search10(ctx, options) {
2466
2594
  return err.or_throw(symbols_exports.search(ctx, options));
2467
2595
  }
2468
2596
  function set_description2(ctx, id, description) {
2469
- err.or_throw(symbols_exports.update(ctx, id, { description }));
2597
+ err.or_throw(symbols_exports.update(ctx, id, { description, state: "ready", error: null }));
2598
+ err.or_throw(symbol_internal_links_exports.update_state_by_to_symbol(ctx, id, "ready"));
2470
2599
  }
2471
2600
  function referenced_by_symbol(ctx, symbol_id, options = {}) {
2472
2601
  let referenced_symbols = err.or_throw(symbols_exports.referenced_by(ctx, symbol_id, options.select));
@@ -2518,7 +2647,7 @@ function using_dependency3(ctx, dependency_id, options = {}) {
2518
2647
  function directories_wiki(ctx) {
2519
2648
  return {
2520
2649
  get: (id) => get4(ctx, id),
2521
- search: (options) => search7(ctx, options),
2650
+ search: (options) => search11(ctx, options),
2522
2651
  set_description: (id, description) => set_description3(ctx, id, description),
2523
2652
  children: (parent_id, options) => children(ctx, parent_id, options),
2524
2653
  files: (directory_id, options) => directory_files(ctx, directory_id, options)
@@ -2527,11 +2656,11 @@ function directories_wiki(ctx) {
2527
2656
  function get4(ctx, id) {
2528
2657
  return err.or_throw(directories_exports.by_id(ctx, id)) ?? null;
2529
2658
  }
2530
- function search7(ctx, options) {
2659
+ function search11(ctx, options) {
2531
2660
  return err.or_throw(directories_exports.search(ctx, options));
2532
2661
  }
2533
2662
  function set_description3(ctx, id, description) {
2534
- err.or_throw(directories_exports.update(ctx, id, { description }));
2663
+ err.or_throw(directories_exports.update(ctx, id, { description, state: "ready", error: null }));
2535
2664
  }
2536
2665
  function children(ctx, parent_id, options = {}) {
2537
2666
  let child_directories = err.or_throw(directories_exports.search(ctx, { select: options.select, where: { parent_id }, limit: 1e4 }));
@@ -2574,7 +2703,7 @@ function directory_files(ctx, directory_id, options = {}) {
2574
2703
  function dependencies_wiki(ctx) {
2575
2704
  return {
2576
2705
  get: (id) => get5(ctx, id),
2577
- search: (options) => search8(ctx, options),
2706
+ search: (options) => search12(ctx, options),
2578
2707
  set_description: (id, description) => set_description4(ctx, id, description),
2579
2708
  used_by_file: (file_id, options) => used_by_file2(ctx, file_id, options),
2580
2709
  used_by_symbol: (symbol_id, options) => used_by_symbol2(ctx, symbol_id, options)
@@ -2583,7 +2712,7 @@ function dependencies_wiki(ctx) {
2583
2712
  function get5(ctx, id) {
2584
2713
  return err.or_throw(external_dependencies_exports.by_id(ctx, id)) ?? null;
2585
2714
  }
2586
- function search8(ctx, options) {
2715
+ function search12(ctx, options) {
2587
2716
  return err.or_throw(external_dependencies_exports.search(ctx, options));
2588
2717
  }
2589
2718
  function set_description4(ctx, id, description) {
@@ -2596,13 +2725,88 @@ function used_by_symbol2(ctx, symbol_id, options) {
2596
2725
  return err.or_throw(external_dependencies_exports.used_by_symbol(ctx, symbol_id, options?.select));
2597
2726
  }
2598
2727
 
2728
+ // src/to_describe.ts
2729
+ function to_describe(ctx, limit) {
2730
+ const dependencies_count = err.or_throw(external_dependencies_exports.count(ctx, { state: "to_describe" }));
2731
+ if (dependencies_count > 0) return { type: "dependencies", items: dependencies_to_describe(ctx, limit) };
2732
+ const symbols_count = err.or_throw(symbols_exports.count(ctx, { state: "to_describe" }));
2733
+ if (symbols_count > 0) return { type: "symbols", items: symbols_to_describe(ctx, limit) };
2734
+ const pending_symbols_count = err.or_throw(symbols_exports.count(ctx, { state: "to_link" }));
2735
+ if (pending_symbols_count > 0) throw err.new("could_not_describe_files_due_to_pending_symbols", { count: pending_symbols_count });
2736
+ const files_count = err.or_throw(files_exports.count(ctx, { state: "to_describe" }));
2737
+ if (files_count > 0) return { type: "files", items: files_to_describe(ctx, limit) };
2738
+ const pending_files_count = err.or_throw(files_exports.count(ctx, { state: "to_scan" }));
2739
+ if (pending_files_count > 0) throw err.new("could_not_describe_directories_due_to_pending_files", { count: pending_files_count });
2740
+ const directories_count = err.or_throw(directories_exports.count(ctx, { state: "to_describe" }));
2741
+ if (directories_count > 0) return { type: "directories", items: directories_to_describe(ctx, limit) };
2742
+ return { type: "none" };
2743
+ }
2744
+ function dependencies_to_describe(ctx, limit) {
2745
+ const candidates = err.or_throw(
2746
+ external_dependencies_exports.search(ctx, {
2747
+ where: { state: "to_describe" },
2748
+ select: ["id", "package", "name"],
2749
+ limit: 1e5
2750
+ })
2751
+ );
2752
+ candidates.sort((a, b) => {
2753
+ if (a.package !== b.package) return a.package.localeCompare(b.package);
2754
+ return (a.name || "").localeCompare(b.name || "");
2755
+ });
2756
+ const ids = candidates.slice(0, limit).map((dep) => dep.id);
2757
+ const items = err.or_throw(external_dependencies_exports.by_ids(ctx, ids));
2758
+ const by_id5 = new Map(items.map((item) => [item.id, item]));
2759
+ return ids.map((id) => by_id5.get(id)).filter((item) => !!item);
2760
+ }
2761
+ function symbols_to_describe(ctx, limit) {
2762
+ const candidates = err.or_throw(symbols_exports.search(ctx, { where: { state: "to_describe" }, select: ["id", "text"], limit: 1e5 }));
2763
+ const counts2 = {};
2764
+ for (const symbol of candidates) {
2765
+ counts2[symbol.id] = {
2766
+ length: symbol.text?.length ?? 0,
2767
+ missing_external: err.or_throw(symbol_external_links_exports.count_pending_deps(ctx, symbol.id)),
2768
+ missing_internal: err.or_throw(symbol_internal_links_exports.count(ctx, { from_symbol_id: symbol.id, state: "pending" }))
2769
+ };
2770
+ }
2771
+ candidates.sort((x, y) => {
2772
+ const a = counts2[x.id];
2773
+ const b = counts2[y.id];
2774
+ if (!a || !b) return 0;
2775
+ if (a.missing_internal !== b.missing_internal) return a.missing_internal - b.missing_internal;
2776
+ if (a.missing_external !== b.missing_external) return a.missing_external - b.missing_external;
2777
+ return a.length - b.length;
2778
+ });
2779
+ const ids = candidates.slice(0, limit).map((symbol) => symbol.id);
2780
+ const items = err.or_throw(symbols_exports.by_ids(ctx, ids));
2781
+ const by_id5 = new Map(items.map((item) => [item.id, item]));
2782
+ return ids.map((id) => by_id5.get(id)).filter((item) => !!item);
2783
+ }
2784
+ function files_to_describe(ctx, limit) {
2785
+ return err.or_throw(files_exports.by_state(ctx, "to_describe", limit));
2786
+ }
2787
+ function directories_to_describe(ctx, limit) {
2788
+ const candidates = err.or_throw(
2789
+ directories_exports.search(ctx, {
2790
+ where: { state: "to_describe" },
2791
+ select: ["id", "path"],
2792
+ limit: 1e5
2793
+ })
2794
+ );
2795
+ candidates.sort((a, b) => b.path.split("/").length - a.path.split("/").length);
2796
+ const ids = candidates.slice(0, limit).map((dir) => dir.id);
2797
+ const items = err.or_throw(directories_exports.by_ids(ctx, ids));
2798
+ const by_id5 = new Map(items.map((item) => [item.id, item]));
2799
+ return ids.map((id) => by_id5.get(id)).filter((item) => !!item);
2800
+ }
2801
+
2599
2802
  // src/index.ts
2600
2803
  async function create(config) {
2601
2804
  const ctx = await context_from_config(config);
2602
2805
  return {
2603
2806
  config,
2604
2807
  update: () => update6(ctx),
2605
- counts: () => err.or_throw(counts(ctx)),
2808
+ counts: () => counts(ctx),
2809
+ to_describe: (limit) => to_describe(ctx, limit),
2606
2810
  files: files_wiki(ctx),
2607
2811
  symbols: symbols_wiki(ctx),
2608
2812
  directories: directories_wiki(ctx),
@@ -2622,7 +2826,8 @@ async function load(db_path) {
2622
2826
  return {
2623
2827
  config,
2624
2828
  update: () => update6(ctx),
2625
- counts: () => err.or_throw(counts(ctx)),
2829
+ counts: () => counts(ctx),
2830
+ to_describe: (limit) => to_describe(ctx, limit),
2626
2831
  files: files_wiki(ctx),
2627
2832
  symbols: symbols_wiki(ctx),
2628
2833
  directories: directories_wiki(ctx),
@@ -2802,10 +3007,10 @@ get6.action(async (id) => {
2802
3007
 
2803
3008
  // src/cli/commands/files/search.ts
2804
3009
  var import_commander5 = require("commander");
2805
- var search9 = new import_commander5.Command("search");
2806
- search9.description("Search files with JSON options");
2807
- search9.argument("<options>", "JSON options for search");
2808
- search9.action(async (options_json) => {
3010
+ var search13 = new import_commander5.Command("search");
3011
+ search13.description("Search files with JSON options");
3012
+ search13.argument("<options>", "JSON options for search");
3013
+ search13.action(async (options_json) => {
2809
3014
  const wiki = await load_wiki();
2810
3015
  const options = parse_options(options_json, FileSearchOptions, "files search");
2811
3016
  const results = wiki.files.search(options);
@@ -2813,7 +3018,7 @@ search9.action(async (options_json) => {
2813
3018
  });
2814
3019
 
2815
3020
  // src/cli/commands/files/set-description.ts
2816
- var import_fs3 = require("fs");
3021
+ var import_node_fs3 = require("fs");
2817
3022
  var import_commander6 = require("commander");
2818
3023
  var set_description5 = new import_commander6.Command("set-description");
2819
3024
  set_description5.description("Set description for a file");
@@ -2822,7 +3027,7 @@ set_description5.argument("<markdown-file>", "Path to markdown file");
2822
3027
  set_description5.action(async (id, file) => {
2823
3028
  const wiki = await load_wiki();
2824
3029
  try {
2825
- const content = (0, import_fs3.readFileSync)(file, "utf-8");
3030
+ const content = (0, import_node_fs3.readFileSync)(file, "utf-8");
2826
3031
  wiki.files.set_description(Number(id), content);
2827
3032
  env.log("Description saved. Run `codewiki describe` to describe the next item.");
2828
3033
  } catch (err2) {
@@ -2874,7 +3079,7 @@ importing_dependency2.action(async (dep_id, options_json) => {
2874
3079
  var files3 = new import_commander10.Command("files");
2875
3080
  files3.description("Explore files");
2876
3081
  files3.addCommand(get6);
2877
- files3.addCommand(search9);
3082
+ files3.addCommand(search13);
2878
3083
  files3.addCommand(set_description5);
2879
3084
  files3.addCommand(imported_by_file2);
2880
3085
  files3.addCommand(importing_file2);
@@ -2925,10 +3130,10 @@ get7.action(async (id) => {
2925
3130
 
2926
3131
  // src/cli/commands/symbols/search.ts
2927
3132
  var import_commander12 = require("commander");
2928
- var search10 = new import_commander12.Command("search");
2929
- search10.description("Search symbols with JSON options");
2930
- search10.argument("<options>", "JSON options");
2931
- search10.action(async (options_json) => {
3133
+ var search14 = new import_commander12.Command("search");
3134
+ search14.description("Search symbols with JSON options");
3135
+ search14.argument("<options>", "JSON options");
3136
+ search14.action(async (options_json) => {
2932
3137
  const wiki = await load_wiki();
2933
3138
  const options = parse_options(options_json, SymbolSearchOptions, "symbols search");
2934
3139
  const results = wiki.symbols.search(options);
@@ -2936,7 +3141,7 @@ search10.action(async (options_json) => {
2936
3141
  });
2937
3142
 
2938
3143
  // src/cli/commands/symbols/set-description.ts
2939
- var import_fs4 = require("fs");
3144
+ var import_node_fs4 = require("fs");
2940
3145
  var import_commander13 = require("commander");
2941
3146
  var set_description6 = new import_commander13.Command("set-description");
2942
3147
  set_description6.description("Set description for a symbol");
@@ -2945,7 +3150,7 @@ set_description6.argument("<markdown-file>", "Path to markdown file");
2945
3150
  set_description6.action(async (id, file) => {
2946
3151
  const wiki = await load_wiki();
2947
3152
  try {
2948
- const content = (0, import_fs4.readFileSync)(file, "utf-8");
3153
+ const content = (0, import_node_fs4.readFileSync)(file, "utf-8");
2949
3154
  wiki.symbols.set_description(Number(id), content);
2950
3155
  env.log("Description saved. Run `codewiki describe` to describe the next item.");
2951
3156
  } catch (err2) {
@@ -2997,7 +3202,7 @@ using_dependency4.action(async (dep_id, options_json) => {
2997
3202
  var symbols3 = new import_commander17.Command("symbols");
2998
3203
  symbols3.description("Explore symbols");
2999
3204
  symbols3.addCommand(get7);
3000
- symbols3.addCommand(search10);
3205
+ symbols3.addCommand(search14);
3001
3206
  symbols3.addCommand(set_description6);
3002
3207
  symbols3.addCommand(referencing_symbol2);
3003
3208
  symbols3.addCommand(referenced_by_symbol2);
@@ -3048,10 +3253,10 @@ get8.action(async (id) => {
3048
3253
 
3049
3254
  // src/cli/commands/directories/search.ts
3050
3255
  var import_commander19 = require("commander");
3051
- var search11 = new import_commander19.Command("search");
3052
- search11.description("Search directories with JSON options");
3053
- search11.argument("<options>", "JSON options");
3054
- search11.action(async (options_json) => {
3256
+ var search15 = new import_commander19.Command("search");
3257
+ search15.description("Search directories with JSON options");
3258
+ search15.argument("<options>", "JSON options");
3259
+ search15.action(async (options_json) => {
3055
3260
  const wiki = await load_wiki();
3056
3261
  const options = parse_options(options_json, DirectorySearchOptions, "directories search");
3057
3262
  const results = wiki.directories.search(options);
@@ -3059,7 +3264,7 @@ search11.action(async (options_json) => {
3059
3264
  });
3060
3265
 
3061
3266
  // src/cli/commands/directories/set-description.ts
3062
- var import_fs5 = require("fs");
3267
+ var import_node_fs5 = require("fs");
3063
3268
  var import_commander20 = require("commander");
3064
3269
  var set_description7 = new import_commander20.Command("set-description");
3065
3270
  set_description7.description("Set description for a directory");
@@ -3068,7 +3273,7 @@ set_description7.argument("<markdown-file>", "Path to markdown file");
3068
3273
  set_description7.action(async (id, file) => {
3069
3274
  const wiki = await load_wiki();
3070
3275
  try {
3071
- const content = (0, import_fs5.readFileSync)(file, "utf-8");
3276
+ const content = (0, import_node_fs5.readFileSync)(file, "utf-8");
3072
3277
  wiki.directories.set_description(Number(id), content);
3073
3278
  env.log("Description saved. Run `codewiki describe` to describe the next item.");
3074
3279
  } catch (err2) {
@@ -3107,7 +3312,7 @@ files4.action(async (directory_id, options_json) => {
3107
3312
  var directories3 = new import_commander23.Command("directories");
3108
3313
  directories3.description("Explore directories");
3109
3314
  directories3.addCommand(get8);
3110
- directories3.addCommand(search11);
3315
+ directories3.addCommand(search15);
3111
3316
  directories3.addCommand(set_description7);
3112
3317
  directories3.addCommand(children2);
3113
3318
  directories3.addCommand(files4);
@@ -3157,10 +3362,10 @@ get9.action(async (id) => {
3157
3362
 
3158
3363
  // src/cli/commands/dependencies/search.ts
3159
3364
  var import_commander25 = require("commander");
3160
- var search12 = new import_commander25.Command("search");
3161
- search12.description("Search dependencies with JSON options");
3162
- search12.argument("<options>", "JSON options");
3163
- search12.action(async (options_json) => {
3365
+ var search16 = new import_commander25.Command("search");
3366
+ search16.description("Search dependencies with JSON options");
3367
+ search16.argument("<options>", "JSON options");
3368
+ search16.action(async (options_json) => {
3164
3369
  const wiki = await load_wiki();
3165
3370
  const options = parse_options(options_json, DependencySearchOptions, "dependencies search");
3166
3371
  const results = wiki.dependencies.search(options);
@@ -3168,7 +3373,7 @@ search12.action(async (options_json) => {
3168
3373
  });
3169
3374
 
3170
3375
  // src/cli/commands/dependencies/set-description.ts
3171
- var import_fs6 = require("fs");
3376
+ var import_node_fs6 = require("fs");
3172
3377
  var import_commander26 = require("commander");
3173
3378
  var set_description8 = new import_commander26.Command("set-description");
3174
3379
  set_description8.description("Set description for a dependency");
@@ -3177,7 +3382,7 @@ set_description8.argument("<markdown-file>", "Path to markdown file");
3177
3382
  set_description8.action(async (id, file) => {
3178
3383
  const wiki = await load_wiki();
3179
3384
  try {
3180
- const content = (0, import_fs6.readFileSync)(file, "utf-8");
3385
+ const content = (0, import_node_fs6.readFileSync)(file, "utf-8");
3181
3386
  wiki.dependencies.set_description(Number(id), content);
3182
3387
  env.log("Description saved. Run `codewiki describe` to describe the next item.");
3183
3388
  } catch (err2) {
@@ -3216,7 +3421,7 @@ used_by_symbol3.action(async (symbol_id, options_json) => {
3216
3421
  var dependencies = new import_commander29.Command("dependencies");
3217
3422
  dependencies.description("Explore dependencies");
3218
3423
  dependencies.addCommand(get9);
3219
- dependencies.addCommand(search12);
3424
+ dependencies.addCommand(search16);
3220
3425
  dependencies.addCommand(set_description8);
3221
3426
  dependencies.addCommand(used_by_file3);
3222
3427
  dependencies.addCommand(used_by_symbol3);
@@ -3262,4 +3467,4 @@ async function run(argv) {
3262
3467
  0 && (module.exports = {
3263
3468
  run
3264
3469
  });
3265
- //# sourceMappingURL=index.cjs.map
3470
+ //# sourceMappingURL=cli.cjs.map