@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.
- package/dist/{cli/bin.cjs → bin.cjs} +363 -158
- package/dist/bin.cjs.map +1 -0
- package/dist/{cli/bin.js → bin.js} +378 -165
- package/dist/bin.js.map +1 -0
- package/dist/{cli/index.cjs → cli.cjs} +364 -159
- package/dist/cli.cjs.map +1 -0
- package/dist/{cli/index.js → cli.js} +379 -166
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +291 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +314 -103
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/cli/bin.cjs.map +0 -1
- package/dist/cli/bin.js.map +0 -1
- package/dist/cli/index.cjs.map +0 -1
- package/dist/cli/index.js.map +0 -1
- /package/dist/{cli/bin.d.cts → bin.d.cts} +0 -0
- /package/dist/{cli/bin.d.ts → bin.d.ts} +0 -0
- /package/dist/{cli/index.d.cts → cli.d.cts} +0 -0
- /package/dist/{cli/index.d.ts → cli.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -4,12 +4,18 @@ 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/internals/context.ts
|
|
8
15
|
import ts from "typescript";
|
|
9
|
-
import { fileURLToPath } from "url";
|
|
10
16
|
import Database from "better-sqlite3";
|
|
11
17
|
import { readFile as readFile2 } from "fs/promises";
|
|
12
|
-
import
|
|
18
|
+
import path2, { join as join2 } from "path";
|
|
13
19
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
14
20
|
|
|
15
21
|
// ../errors/dist/index.js
|
|
@@ -73,6 +79,7 @@ var index_default = errors;
|
|
|
73
79
|
var err = index_default({
|
|
74
80
|
file_outside_project_path: (data) => `File "${data.file_path}" is outside project path "${data.project_path}"`,
|
|
75
81
|
file_not_found: (data) => `File not found: ${data.path}`,
|
|
82
|
+
file_stat_error: (data) => `Could not get file stats for ${data.path}: ${data.reason}`,
|
|
76
83
|
db_error: (data) => `Database error in ${data.operation}: ${data.reason}`,
|
|
77
84
|
symbol_meta_parse_error: (data) => `Failed to parse symbol metadata for symbol ${data.symbol_id}: ${data.reason}`,
|
|
78
85
|
exported_symbol_not_found: (data) => `Exported symbol "${data.name}" not found in file with id ${data.file_id}`,
|
|
@@ -85,6 +92,8 @@ var err = index_default({
|
|
|
85
92
|
symbol_node_not_found: (data) => `Symbol node not found for ${data.name} in ${data.file_path}`,
|
|
86
93
|
symbol_not_found: (data) => `Symbol "${data.name}" not found in file "${data.path}"`,
|
|
87
94
|
describe_dependency_failed: (data) => `Failed to describe ${data.package}#${data.name}: ${data.reason}`,
|
|
95
|
+
could_not_describe_files_due_to_pending_symbols: (data) => `Cannot start describing files before describing all symbols; ${data.count} symbols are still pending`,
|
|
96
|
+
could_not_describe_directories_due_to_pending_files: (data) => `Cannot start describing directories before describing all files; ${data.count} files are still pending`,
|
|
88
97
|
// CLI errors
|
|
89
98
|
could_not_read_file: (data) => `Could not read file ${data.path}: ${data.reason}`,
|
|
90
99
|
invalid_json: (data) => `Invalid JSON: ${data.reason}`,
|
|
@@ -437,7 +446,7 @@ __export(configs_exports, {
|
|
|
437
446
|
import { eq as eq2, sql as sql3 } from "drizzle-orm";
|
|
438
447
|
|
|
439
448
|
// src/db/common.ts
|
|
440
|
-
import { eq, like, or, and, asc, desc } from "drizzle-orm";
|
|
449
|
+
import { eq, like, or, and, asc, desc, count } from "drizzle-orm";
|
|
441
450
|
function safe_query(operation, fn) {
|
|
442
451
|
return err.safe(fn, (reason, ...args) => err.new("db_error", { operation, args: args.slice(1), reason }));
|
|
443
452
|
}
|
|
@@ -445,6 +454,9 @@ function do_search(db6, table, options) {
|
|
|
445
454
|
if (!options.select.includes("id")) options.select.push("id");
|
|
446
455
|
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();
|
|
447
456
|
}
|
|
457
|
+
function do_count(db6, table, options) {
|
|
458
|
+
return db6.select({ count: count() }).from(table).where(conditions(table, options)).get()?.count ?? 0;
|
|
459
|
+
}
|
|
448
460
|
function fields(table, fields2) {
|
|
449
461
|
const res = {};
|
|
450
462
|
for (const field of fields2) res[field] = table[field];
|
|
@@ -496,8 +508,10 @@ __export(files_exports, {
|
|
|
496
508
|
by_directory_path: () => by_directory_path,
|
|
497
509
|
by_id: () => by_id,
|
|
498
510
|
by_id_and_state: () => by_id_and_state,
|
|
511
|
+
by_ids: () => by_ids,
|
|
499
512
|
by_path: () => by_path,
|
|
500
513
|
by_state: () => by_state,
|
|
514
|
+
count: () => count2,
|
|
501
515
|
del: () => del,
|
|
502
516
|
del_by_dir: () => del_by_dir,
|
|
503
517
|
get_directory_ids: () => get_directory_ids,
|
|
@@ -512,11 +526,15 @@ __export(files_exports, {
|
|
|
512
526
|
import { eq as eq3, and as and2, inArray, or as or2, like as like2 } from "drizzle-orm";
|
|
513
527
|
|
|
514
528
|
// src/internals/utils.ts
|
|
515
|
-
import { readFileSync } from "fs";
|
|
529
|
+
import { readFileSync, statSync } from "fs";
|
|
516
530
|
var parse_json = err.safe(JSON.parse, (reason, text2) => err.new("invalid_json", { reason, text: text2 }));
|
|
517
531
|
var read_file = err.safe(
|
|
518
|
-
(
|
|
519
|
-
(reason,
|
|
532
|
+
(path7) => readFileSync(path7, "utf-8"),
|
|
533
|
+
(reason, path7) => err.new("could_not_read_file", { path: path7, reason })
|
|
534
|
+
);
|
|
535
|
+
var file_stat = err.safe(
|
|
536
|
+
(path7) => statSync(path7),
|
|
537
|
+
(reason, path7) => err.new("file_stat_error", { path: path7, reason })
|
|
520
538
|
);
|
|
521
539
|
function group_by_unique(items, key) {
|
|
522
540
|
const groups = {};
|
|
@@ -582,6 +600,34 @@ var external_dependencies2 = {
|
|
|
582
600
|
offset: 0,
|
|
583
601
|
where: {}
|
|
584
602
|
};
|
|
603
|
+
var imports2 = {
|
|
604
|
+
select: ["id", "exporter_file_id", "importer_file_id", "symbol_id", "name", "alias", "is_dynamic", "state", "error"],
|
|
605
|
+
order_by: ["id", "asc"],
|
|
606
|
+
limit: 20,
|
|
607
|
+
offset: 0,
|
|
608
|
+
where: {}
|
|
609
|
+
};
|
|
610
|
+
var external_imports2 = {
|
|
611
|
+
select: ["id", "file_id", "external_dependency_id", "alias", "is_dynamic"],
|
|
612
|
+
order_by: ["id", "asc"],
|
|
613
|
+
limit: 20,
|
|
614
|
+
offset: 0,
|
|
615
|
+
where: {}
|
|
616
|
+
};
|
|
617
|
+
var symbol_internal_links2 = {
|
|
618
|
+
select: ["id", "from_file_id", "to_file_id", "from_symbol_id", "to_symbol_id", "state", "error"],
|
|
619
|
+
order_by: ["id", "asc"],
|
|
620
|
+
limit: 20,
|
|
621
|
+
offset: 0,
|
|
622
|
+
where: {}
|
|
623
|
+
};
|
|
624
|
+
var symbol_external_links2 = {
|
|
625
|
+
select: ["id", "symbol_id", "external_import_id"],
|
|
626
|
+
order_by: ["id", "asc"],
|
|
627
|
+
limit: 20,
|
|
628
|
+
offset: 0,
|
|
629
|
+
where: {}
|
|
630
|
+
};
|
|
585
631
|
|
|
586
632
|
// src/db/files.ts
|
|
587
633
|
var default_select_fields = ["id", "directory_id", "path", "state", "error"];
|
|
@@ -589,15 +635,23 @@ var all = safe_query("files.all", (ctx) => ctx.db.select().from(files).all());
|
|
|
589
635
|
var search = safe_query("files.search", (ctx, options = {}) => {
|
|
590
636
|
return do_search(ctx.db, files, merge(files2, options));
|
|
591
637
|
});
|
|
638
|
+
var count2 = safe_query("files.count", (ctx, where = {}) => {
|
|
639
|
+
return do_count(ctx.db, files, where);
|
|
640
|
+
});
|
|
592
641
|
var by_id = safe_query("files.by_id", (ctx, id) => ctx.db.select().from(files).where(eq3(files.id, id)).get());
|
|
642
|
+
var by_ids = safe_query(
|
|
643
|
+
"files.by_ids",
|
|
644
|
+
(ctx, ids) => ctx.db.select().from(files).where(inArray(files.id, ids)).all()
|
|
645
|
+
);
|
|
593
646
|
var by_path = safe_query(
|
|
594
647
|
"files.by_path",
|
|
595
|
-
(ctx,
|
|
596
|
-
);
|
|
597
|
-
var by_state = safe_query(
|
|
598
|
-
"files.by_state",
|
|
599
|
-
(ctx, state) => ctx.db.select().from(files).where(eq3(files.state, state)).all()
|
|
648
|
+
(ctx, path7) => ctx.db.select().from(files).where(eq3(files.path, path7)).get()
|
|
600
649
|
);
|
|
650
|
+
var by_state = safe_query("files.by_state", (ctx, state, limit) => {
|
|
651
|
+
let query = ctx.db.select().from(files).where(eq3(files.state, state));
|
|
652
|
+
if (limit) query = query.limit(limit);
|
|
653
|
+
return query.all();
|
|
654
|
+
});
|
|
601
655
|
var insert = safe_query("files.insert", (ctx, values) => ctx.db.insert(files).values(values).run());
|
|
602
656
|
var update = safe_query(
|
|
603
657
|
"files.update",
|
|
@@ -639,8 +693,8 @@ var using_dependency = safe_query(
|
|
|
639
693
|
"files.using_dependency",
|
|
640
694
|
(ctx, external_dependency_id, fields_to_select = default_select_fields) => {
|
|
641
695
|
if (!fields_to_select.includes("id")) fields_to_select.push("id");
|
|
642
|
-
const
|
|
643
|
-
const file_ids = uniq(
|
|
696
|
+
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();
|
|
697
|
+
const file_ids = uniq(imports4.map((i) => i.file_id));
|
|
644
698
|
if (file_ids.length === 0) return [];
|
|
645
699
|
return ctx.db.select(fields(files, fields_to_select)).from(files).where(inArray(files.id, file_ids)).all();
|
|
646
700
|
}
|
|
@@ -671,8 +725,10 @@ var directories_exports = {};
|
|
|
671
725
|
__export(directories_exports, {
|
|
672
726
|
by_id: () => by_id2,
|
|
673
727
|
by_id_and_state: () => by_id_and_state2,
|
|
728
|
+
by_ids: () => by_ids2,
|
|
674
729
|
by_path: () => by_path2,
|
|
675
730
|
by_state: () => by_state2,
|
|
731
|
+
count: () => count3,
|
|
676
732
|
insert: () => insert2,
|
|
677
733
|
search: () => search2,
|
|
678
734
|
update: () => update2,
|
|
@@ -683,9 +739,13 @@ var by_id2 = safe_query(
|
|
|
683
739
|
"directories.by_id",
|
|
684
740
|
(ctx, id) => ctx.db.select().from(directories).where(eq4(directories.id, id)).get()
|
|
685
741
|
);
|
|
742
|
+
var by_ids2 = safe_query(
|
|
743
|
+
"directories.by_ids",
|
|
744
|
+
(ctx, ids) => ctx.db.select().from(directories).where(inArray2(directories.id, ids)).all()
|
|
745
|
+
);
|
|
686
746
|
var by_path2 = safe_query(
|
|
687
747
|
"directories.by_path",
|
|
688
|
-
(ctx,
|
|
748
|
+
(ctx, path7) => ctx.db.select().from(directories).where(eq4(directories.path, path7)).get()
|
|
689
749
|
);
|
|
690
750
|
var by_state2 = safe_query(
|
|
691
751
|
"directories.by_state",
|
|
@@ -710,6 +770,9 @@ var by_id_and_state2 = safe_query(
|
|
|
710
770
|
var search2 = safe_query("directories.search", (ctx, options = {}) => {
|
|
711
771
|
return do_search(ctx.db, directories, merge(directories2, options));
|
|
712
772
|
});
|
|
773
|
+
var count3 = safe_query("directories.count", (ctx, where = {}) => {
|
|
774
|
+
return do_count(ctx.db, directories, where);
|
|
775
|
+
});
|
|
713
776
|
|
|
714
777
|
// src/db/imports.ts
|
|
715
778
|
var imports_exports = {};
|
|
@@ -717,11 +780,23 @@ __export(imports_exports, {
|
|
|
717
780
|
by_exporter_file: () => by_exporter_file,
|
|
718
781
|
by_importer_file: () => by_importer_file,
|
|
719
782
|
by_state: () => by_state3,
|
|
783
|
+
count: () => count4,
|
|
784
|
+
count_pending_symbols: () => count_pending_symbols,
|
|
720
785
|
del_by_importer_file: () => del_by_importer_file,
|
|
721
786
|
insert_many: () => insert_many,
|
|
787
|
+
search: () => search3,
|
|
722
788
|
update: () => update3
|
|
723
789
|
});
|
|
724
|
-
import { eq as eq5 } from "drizzle-orm";
|
|
790
|
+
import { eq as eq5, ne, and as and4, count as countFn } from "drizzle-orm";
|
|
791
|
+
var search3 = safe_query("imports.search", (ctx, options = {}) => {
|
|
792
|
+
return do_search(ctx.db, imports, merge(imports2, options));
|
|
793
|
+
});
|
|
794
|
+
var count4 = safe_query("imports.count", (ctx, where = {}) => {
|
|
795
|
+
return do_count(ctx.db, imports, where);
|
|
796
|
+
});
|
|
797
|
+
var count_pending_symbols = safe_query("imports.count_pending_symbols", (ctx, file_id) => {
|
|
798
|
+
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;
|
|
799
|
+
});
|
|
725
800
|
var by_exporter_file = safe_query(
|
|
726
801
|
"imports.by_exporter_file",
|
|
727
802
|
(ctx, exporter_file_id) => ctx.db.select().from(imports).where(eq5(imports.exporter_file_id, exporter_file_id)).all()
|
|
@@ -751,17 +826,19 @@ __export(symbols_exports, {
|
|
|
751
826
|
by_file_and_name: () => by_file_and_name,
|
|
752
827
|
by_id: () => by_id3,
|
|
753
828
|
by_id_and_state: () => by_id_and_state3,
|
|
829
|
+
by_ids: () => by_ids3,
|
|
754
830
|
by_state: () => by_state4,
|
|
831
|
+
count: () => count5,
|
|
755
832
|
del_by_file: () => del_by_file,
|
|
756
833
|
insert_many: () => insert_many2,
|
|
757
834
|
meta: () => meta,
|
|
758
835
|
referenced_by: () => referenced_by,
|
|
759
836
|
referencing: () => referencing,
|
|
760
|
-
search: () =>
|
|
837
|
+
search: () => search4,
|
|
761
838
|
update: () => update4,
|
|
762
839
|
using_dependency: () => using_dependency2
|
|
763
840
|
});
|
|
764
|
-
import { eq as eq6, and as
|
|
841
|
+
import { eq as eq6, and as and5, inArray as inArray3 } from "drizzle-orm";
|
|
765
842
|
var insert_many2 = safe_query("symbols.insert_many", (ctx, values) => ctx.db.insert(symbols).values(values).run());
|
|
766
843
|
var del_by_file = safe_query(
|
|
767
844
|
"symbols.delete_by_file",
|
|
@@ -769,7 +846,7 @@ var del_by_file = safe_query(
|
|
|
769
846
|
);
|
|
770
847
|
var by_file_and_name = safe_query(
|
|
771
848
|
"symbols.by_file_and_name",
|
|
772
|
-
(ctx, params) => ctx.db.select().from(symbols).where(
|
|
849
|
+
(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()
|
|
773
850
|
);
|
|
774
851
|
var by_state4 = safe_query(
|
|
775
852
|
"symbols.by_state",
|
|
@@ -784,9 +861,13 @@ var update4 = safe_query(
|
|
|
784
861
|
(ctx, id, data) => ctx.db.update(symbols).set(data).where(eq6(symbols.id, id)).run()
|
|
785
862
|
);
|
|
786
863
|
var by_id3 = safe_query("symbols.by_id", (ctx, id) => ctx.db.select().from(symbols).where(eq6(symbols.id, id)).get());
|
|
864
|
+
var by_ids3 = safe_query(
|
|
865
|
+
"symbols.by_ids",
|
|
866
|
+
(ctx, ids) => ctx.db.select().from(symbols).where(inArray3(symbols.id, ids)).all()
|
|
867
|
+
);
|
|
787
868
|
var by_id_and_state3 = safe_query(
|
|
788
869
|
"symbols.by_id_and_state",
|
|
789
|
-
(ctx, params) => ctx.db.select().from(symbols).where(
|
|
870
|
+
(ctx, params) => ctx.db.select().from(symbols).where(and5(eq6(symbols.id, params.id), eq6(symbols.state, params.state))).get()
|
|
790
871
|
);
|
|
791
872
|
function meta(symbol) {
|
|
792
873
|
return err.catch(
|
|
@@ -794,8 +875,12 @@ function meta(symbol) {
|
|
|
794
875
|
(reason) => err.new("symbol_meta_parse_error", { reason, symbol_id: symbol.id, meta: symbol.meta })
|
|
795
876
|
);
|
|
796
877
|
}
|
|
797
|
-
var
|
|
798
|
-
|
|
878
|
+
var search4 = safe_query(
|
|
879
|
+
"symbols.search",
|
|
880
|
+
(ctx, options = {}) => do_search(ctx.db, symbols, merge(symbols2, options))
|
|
881
|
+
);
|
|
882
|
+
var count5 = safe_query("symbols.count", (ctx, where = {}) => {
|
|
883
|
+
return do_count(ctx.db, symbols, where);
|
|
799
884
|
});
|
|
800
885
|
var referenced_by = safe_query(
|
|
801
886
|
"symbols.referenced_by",
|
|
@@ -833,20 +918,26 @@ var external_dependencies_exports = {};
|
|
|
833
918
|
__export(external_dependencies_exports, {
|
|
834
919
|
all: () => all2,
|
|
835
920
|
by_id: () => by_id4,
|
|
921
|
+
by_ids: () => by_ids4,
|
|
836
922
|
by_package_subpath_and_name: () => by_package_subpath_and_name,
|
|
837
923
|
by_state: () => by_state5,
|
|
924
|
+
count: () => count6,
|
|
838
925
|
get_or_create: () => get_or_create,
|
|
839
926
|
insert: () => insert3,
|
|
840
|
-
search: () =>
|
|
927
|
+
search: () => search5,
|
|
841
928
|
update: () => update5,
|
|
842
929
|
used_by_file: () => used_by_file,
|
|
843
930
|
used_by_symbol: () => used_by_symbol
|
|
844
931
|
});
|
|
845
|
-
import { eq as eq7, and as
|
|
932
|
+
import { eq as eq7, and as and6, sql as sql4, inArray as inArray4 } from "drizzle-orm";
|
|
846
933
|
var by_id4 = safe_query(
|
|
847
934
|
"external_dependencies.by_id",
|
|
848
935
|
(ctx, id) => ctx.db.select().from(external_dependencies).where(eq7(external_dependencies.id, id)).get()
|
|
849
936
|
);
|
|
937
|
+
var by_ids4 = safe_query(
|
|
938
|
+
"external_dependencies.by_ids",
|
|
939
|
+
(ctx, ids) => ctx.db.select().from(external_dependencies).where(inArray4(external_dependencies.id, ids)).all()
|
|
940
|
+
);
|
|
850
941
|
var by_state5 = safe_query(
|
|
851
942
|
"external_dependencies.by_state",
|
|
852
943
|
(ctx, state) => ctx.db.select().from(external_dependencies).where(eq7(external_dependencies.state, state)).all()
|
|
@@ -854,7 +945,7 @@ var by_state5 = safe_query(
|
|
|
854
945
|
var by_package_subpath_and_name = safe_query(
|
|
855
946
|
"external_dependencies.by_package_subpath_and_name",
|
|
856
947
|
(ctx, params) => ctx.db.select().from(external_dependencies).where(
|
|
857
|
-
|
|
948
|
+
and6(
|
|
858
949
|
eq7(external_dependencies.package, params.package),
|
|
859
950
|
params.subpath === null ? sql4`${external_dependencies.subpath} IS NULL` : eq7(external_dependencies.subpath, params.subpath),
|
|
860
951
|
params.name === null ? sql4`${external_dependencies.name} IS NULL` : eq7(external_dependencies.name, params.name)
|
|
@@ -876,11 +967,13 @@ function get_or_create(ctx, value) {
|
|
|
876
967
|
(existing) => existing || insert3(ctx, value)
|
|
877
968
|
);
|
|
878
969
|
}
|
|
879
|
-
var
|
|
970
|
+
var search5 = safe_query(
|
|
880
971
|
"external_dependencies.search",
|
|
881
|
-
(ctx, options = {}) =>
|
|
882
|
-
|
|
883
|
-
|
|
972
|
+
(ctx, options = {}) => do_search(ctx.db, external_dependencies, merge(external_dependencies2, options))
|
|
973
|
+
);
|
|
974
|
+
var count6 = safe_query(
|
|
975
|
+
"external_dependencies.count",
|
|
976
|
+
(ctx, where = {}) => do_count(ctx.db, external_dependencies, where)
|
|
884
977
|
);
|
|
885
978
|
var used_by_file = safe_query(
|
|
886
979
|
"external_dependencies.used_by_file",
|
|
@@ -912,10 +1005,22 @@ __export(external_imports_exports, {
|
|
|
912
1005
|
by_external_dependency: () => by_external_dependency,
|
|
913
1006
|
by_file: () => by_file2,
|
|
914
1007
|
by_symbol: () => by_symbol,
|
|
1008
|
+
count: () => count7,
|
|
1009
|
+
count_pending_dependencies: () => count_pending_dependencies,
|
|
915
1010
|
del_by_file: () => del_by_file2,
|
|
916
|
-
insert_many: () => insert_many3
|
|
1011
|
+
insert_many: () => insert_many3,
|
|
1012
|
+
search: () => search6
|
|
1013
|
+
});
|
|
1014
|
+
import { eq as eq8, ne as ne2, and as and7, count as countFn2 } from "drizzle-orm";
|
|
1015
|
+
var search6 = safe_query("external_imports.search", (ctx, options = {}) => {
|
|
1016
|
+
return do_search(ctx.db, external_imports, merge(external_imports2, options));
|
|
1017
|
+
});
|
|
1018
|
+
var count7 = safe_query("external_imports.count", (ctx, where = {}) => {
|
|
1019
|
+
return do_count(ctx.db, external_imports, where);
|
|
1020
|
+
});
|
|
1021
|
+
var count_pending_dependencies = safe_query("external_imports.count_pending_dependencies", (ctx, file_id) => {
|
|
1022
|
+
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;
|
|
917
1023
|
});
|
|
918
|
-
import { eq as eq8 } from "drizzle-orm";
|
|
919
1024
|
var insert_many3 = safe_query(
|
|
920
1025
|
"external_imports.insert_many",
|
|
921
1026
|
(ctx, values) => ctx.db.insert(external_imports).values(values).run()
|
|
@@ -950,11 +1055,20 @@ var by_symbol = safe_query(
|
|
|
950
1055
|
var symbol_internal_links_exports = {};
|
|
951
1056
|
__export(symbol_internal_links_exports, {
|
|
952
1057
|
by_from_symbol: () => by_from_symbol,
|
|
1058
|
+
count: () => count8,
|
|
953
1059
|
del_by_from_symbol: () => del_by_from_symbol,
|
|
954
1060
|
exists: () => exists,
|
|
955
|
-
insert: () => insert4
|
|
1061
|
+
insert: () => insert4,
|
|
1062
|
+
search: () => search7,
|
|
1063
|
+
update_state_by_to_symbol: () => update_state_by_to_symbol
|
|
1064
|
+
});
|
|
1065
|
+
import { and as and8, eq as eq9 } from "drizzle-orm";
|
|
1066
|
+
var search7 = safe_query("symbol_internal_links.search", (ctx, options = {}) => {
|
|
1067
|
+
return do_search(ctx.db, symbol_internal_links, merge(symbol_internal_links2, options));
|
|
1068
|
+
});
|
|
1069
|
+
var count8 = safe_query("symbol_internal_links.count", (ctx, where = {}) => {
|
|
1070
|
+
return do_count(ctx.db, symbol_internal_links, where);
|
|
956
1071
|
});
|
|
957
|
-
import { and as and6, eq as eq9 } from "drizzle-orm";
|
|
958
1072
|
var by_from_symbol = safe_query(
|
|
959
1073
|
"symbol_internal_links.by_from_symbol",
|
|
960
1074
|
(ctx, from_symbol_id) => ctx.db.query.symbol_internal_links.findMany({
|
|
@@ -974,23 +1088,43 @@ var insert4 = safe_query(
|
|
|
974
1088
|
);
|
|
975
1089
|
var exists = safe_query(
|
|
976
1090
|
"symbol_internal_links.exists",
|
|
977
|
-
(ctx, params) => ctx.db.select({ id: symbol_internal_links.id }).from(symbol_internal_links).where(
|
|
1091
|
+
(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()
|
|
978
1092
|
);
|
|
979
1093
|
var del_by_from_symbol = safe_query(
|
|
980
1094
|
"symbol_internal_links.del_by_from_symbol",
|
|
981
1095
|
(ctx, from_symbol_id) => ctx.db.delete(symbol_internal_links).where(eq9(symbol_internal_links.from_symbol_id, from_symbol_id)).run()
|
|
982
1096
|
);
|
|
1097
|
+
var update_state_by_to_symbol = safe_query(
|
|
1098
|
+
"symbol_internal_links.update_state_by_to_symbol",
|
|
1099
|
+
(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()
|
|
1100
|
+
);
|
|
983
1101
|
|
|
984
1102
|
// src/db/symbol_external_links.ts
|
|
985
1103
|
var symbol_external_links_exports = {};
|
|
986
1104
|
__export(symbol_external_links_exports, {
|
|
987
1105
|
by_external_import: () => by_external_import,
|
|
988
1106
|
by_symbol: () => by_symbol2,
|
|
1107
|
+
count: () => count9,
|
|
1108
|
+
count_by_dependency: () => count_by_dependency,
|
|
1109
|
+
count_pending_deps: () => count_pending_deps,
|
|
989
1110
|
del_by_symbol: () => del_by_symbol,
|
|
990
1111
|
exists: () => exists2,
|
|
991
|
-
insert: () => insert5
|
|
1112
|
+
insert: () => insert5,
|
|
1113
|
+
search: () => search8
|
|
1114
|
+
});
|
|
1115
|
+
import { and as and9, eq as eq10, ne as ne3, count as countFn3 } from "drizzle-orm";
|
|
1116
|
+
var search8 = safe_query("symbol_external_links.search", (ctx, options = {}) => {
|
|
1117
|
+
return do_search(ctx.db, symbol_external_links, merge(symbol_external_links2, options));
|
|
1118
|
+
});
|
|
1119
|
+
var count9 = safe_query("symbol_external_links.count", (ctx, where = {}) => {
|
|
1120
|
+
return do_count(ctx.db, symbol_external_links, where);
|
|
1121
|
+
});
|
|
1122
|
+
var count_by_dependency = safe_query("symbol_external_links.count_by_dependency", (ctx, dependency_id) => {
|
|
1123
|
+
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;
|
|
1124
|
+
});
|
|
1125
|
+
var count_pending_deps = safe_query("symbol_external_links.count_pending_deps", (ctx, symbol_id) => {
|
|
1126
|
+
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;
|
|
992
1127
|
});
|
|
993
|
-
import { and as and7, eq as eq10 } from "drizzle-orm";
|
|
994
1128
|
var by_symbol2 = safe_query(
|
|
995
1129
|
"symbol_external_links.by_symbol",
|
|
996
1130
|
(ctx, symbol_id) => ctx.db.select().from(symbol_external_links).where(eq10(symbol_external_links.symbol_id, symbol_id)).all()
|
|
@@ -1005,7 +1139,7 @@ var by_external_import = safe_query(
|
|
|
1005
1139
|
);
|
|
1006
1140
|
var exists2 = safe_query(
|
|
1007
1141
|
"symbol_external_links.exists",
|
|
1008
|
-
(ctx, params) => ctx.db.select({ id: symbol_external_links.id }).from(symbol_external_links).where(
|
|
1142
|
+
(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()
|
|
1009
1143
|
);
|
|
1010
1144
|
var del_by_symbol = safe_query(
|
|
1011
1145
|
"symbol_external_links.del_by_symbol",
|
|
@@ -1014,8 +1148,8 @@ var del_by_symbol = safe_query(
|
|
|
1014
1148
|
|
|
1015
1149
|
// src/internals/context.ts
|
|
1016
1150
|
async function create_context(sqlite, db6, config) {
|
|
1017
|
-
const project_path =
|
|
1018
|
-
const currentDir =
|
|
1151
|
+
const project_path = path2.resolve(config.project_path);
|
|
1152
|
+
const currentDir = __dirname;
|
|
1019
1153
|
const migrations_path = currentDir.includes("/dist") ? join2(currentDir, "../migrations") : join2(currentDir, "../../migrations");
|
|
1020
1154
|
const tsconfig_path = join2(project_path, "tsconfig.json");
|
|
1021
1155
|
if (!ts.sys.fileExists(tsconfig_path)) {
|
|
@@ -1023,8 +1157,8 @@ async function create_context(sqlite, db6, config) {
|
|
|
1023
1157
|
}
|
|
1024
1158
|
const tsconfig = ts.parseJsonConfigFileContent(ts.readConfigFile(tsconfig_path, ts.sys.readFile).config, ts.sys, project_path);
|
|
1025
1159
|
const program = ts.createProgram({ rootNames: tsconfig.fileNames, options: tsconfig.options });
|
|
1026
|
-
const package_json_path = config.package_json_path ??
|
|
1027
|
-
const node_modules_paths = config.node_modules_paths ?? [
|
|
1160
|
+
const package_json_path = config.package_json_path ?? path2.join(project_path, "package.json");
|
|
1161
|
+
const node_modules_paths = config.node_modules_paths ?? [path2.join(project_path, "node_modules")];
|
|
1028
1162
|
const dependencies = await get_dependencies(package_json_path, node_modules_paths);
|
|
1029
1163
|
const ctx = { db: db6, sqlite, migrations_path, project_path, program, dependencies };
|
|
1030
1164
|
await migrate(ctx);
|
|
@@ -1083,7 +1217,7 @@ async function get_dependencies(package_json_path, node_modules_paths) {
|
|
|
1083
1217
|
async function get_github_repo(node_modules_paths, package_name) {
|
|
1084
1218
|
for (const node_modules_path of node_modules_paths) {
|
|
1085
1219
|
try {
|
|
1086
|
-
const package_json_path =
|
|
1220
|
+
const package_json_path = path2.join(node_modules_path, package_name, "package.json");
|
|
1087
1221
|
const package_json = JSON.parse(await readFile2(package_json_path, "utf-8"));
|
|
1088
1222
|
const url = package_json.repository?.url || package_json.repository;
|
|
1089
1223
|
if (typeof url === "string") {
|
|
@@ -1098,7 +1232,7 @@ async function get_github_repo(node_modules_paths, package_name) {
|
|
|
1098
1232
|
}
|
|
1099
1233
|
|
|
1100
1234
|
// src/update/track_changes.ts
|
|
1101
|
-
import
|
|
1235
|
+
import path3 from "path";
|
|
1102
1236
|
import "typescript";
|
|
1103
1237
|
import { stat } from "fs/promises";
|
|
1104
1238
|
|
|
@@ -1109,9 +1243,9 @@ function file_updated(ctx, file_id) {
|
|
|
1109
1243
|
items: [file_id],
|
|
1110
1244
|
get_key: (id) => id,
|
|
1111
1245
|
get_children: (id) => {
|
|
1112
|
-
const
|
|
1113
|
-
if (err.any(
|
|
1114
|
-
return
|
|
1246
|
+
const imports4 = imports_exports.by_exporter_file(ctx, id);
|
|
1247
|
+
if (err.any(imports4)) return imports4;
|
|
1248
|
+
return imports4.map((x) => x.importer_file_id);
|
|
1115
1249
|
}
|
|
1116
1250
|
})
|
|
1117
1251
|
);
|
|
@@ -1144,7 +1278,7 @@ function get_source_files(ctx) {
|
|
|
1144
1278
|
for (const file of ctx.program.getSourceFiles()) {
|
|
1145
1279
|
if (ctx.program.isSourceFileDefaultLibrary(file)) continue;
|
|
1146
1280
|
if (ctx.program.isSourceFileFromExternalLibrary(file)) continue;
|
|
1147
|
-
if (!
|
|
1281
|
+
if (!path3.resolve(file.fileName).startsWith(ctx.project_path)) continue;
|
|
1148
1282
|
src_files.push(file);
|
|
1149
1283
|
}
|
|
1150
1284
|
return src_files;
|
|
@@ -1192,7 +1326,7 @@ async function changes(ctx, source_files, db_files) {
|
|
|
1192
1326
|
return { created, updated, deleted };
|
|
1193
1327
|
}
|
|
1194
1328
|
function get_file_path(ctx, file) {
|
|
1195
|
-
const absolute_path =
|
|
1329
|
+
const absolute_path = path3.resolve(file.fileName);
|
|
1196
1330
|
if (absolute_path.startsWith(ctx.project_path)) return absolute_path.slice(ctx.project_path.length);
|
|
1197
1331
|
return err.new("file_outside_project_path", { file_path: absolute_path, project_path: ctx.project_path });
|
|
1198
1332
|
}
|
|
@@ -1200,10 +1334,10 @@ function get_parents_paths(ctx, file) {
|
|
|
1200
1334
|
const file_path = get_file_path(ctx, file);
|
|
1201
1335
|
if (err.any(file_path)) return file_path;
|
|
1202
1336
|
const dirs = [];
|
|
1203
|
-
let current =
|
|
1204
|
-
while (current !==
|
|
1337
|
+
let current = path3.dirname(file_path);
|
|
1338
|
+
while (current !== path3.sep) {
|
|
1205
1339
|
dirs.push(current);
|
|
1206
|
-
current =
|
|
1340
|
+
current = path3.dirname(current);
|
|
1207
1341
|
}
|
|
1208
1342
|
dirs.push(current);
|
|
1209
1343
|
return dirs.reverse();
|
|
@@ -1237,19 +1371,19 @@ async function sync_external_dependencies(ctx) {
|
|
|
1237
1371
|
}
|
|
1238
1372
|
|
|
1239
1373
|
// src/update/scan_files/scan_files.ts
|
|
1240
|
-
import
|
|
1374
|
+
import path5 from "path";
|
|
1241
1375
|
import ts10 from "typescript";
|
|
1242
1376
|
|
|
1243
1377
|
// src/update/scan_files/imports.ts
|
|
1244
1378
|
import ts4 from "typescript";
|
|
1245
1379
|
|
|
1246
1380
|
// src/update/scan_files/common.ts
|
|
1247
|
-
import
|
|
1381
|
+
import path4 from "path";
|
|
1248
1382
|
import ts3 from "typescript";
|
|
1249
1383
|
function is_external_module(ctx, source_file, module_path) {
|
|
1250
1384
|
const resolved = ts3.resolveModuleName(module_path, source_file.fileName, ctx.program.getCompilerOptions(), ts3.sys);
|
|
1251
1385
|
if (!resolved.resolvedModule) return true;
|
|
1252
|
-
const resolved_path =
|
|
1386
|
+
const resolved_path = path4.resolve(resolved.resolvedModule.resolvedFileName);
|
|
1253
1387
|
return !resolved_path.startsWith(ctx.project_path);
|
|
1254
1388
|
}
|
|
1255
1389
|
function has_export_modifier(node) {
|
|
@@ -1358,13 +1492,13 @@ function is_import(ctx, source_file, node) {
|
|
|
1358
1492
|
return !is_external_module(ctx, source_file, node.moduleSpecifier.text);
|
|
1359
1493
|
}
|
|
1360
1494
|
function extract_import(ctx, source_file, node, file_id) {
|
|
1361
|
-
const
|
|
1495
|
+
const imports4 = [];
|
|
1362
1496
|
const clause = node.importClause;
|
|
1363
|
-
if (!clause || !node.moduleSpecifier || !ts4.isStringLiteral(node.moduleSpecifier)) return
|
|
1497
|
+
if (!clause || !node.moduleSpecifier || !ts4.isStringLiteral(node.moduleSpecifier)) return imports4;
|
|
1364
1498
|
const exporter_file_id = resolve_exporter_file(ctx, source_file, node.moduleSpecifier.text);
|
|
1365
|
-
if (err.any(exporter_file_id)) return
|
|
1499
|
+
if (err.any(exporter_file_id)) return imports4;
|
|
1366
1500
|
if (clause.name) {
|
|
1367
|
-
|
|
1501
|
+
imports4.push({
|
|
1368
1502
|
importer_file_id: file_id,
|
|
1369
1503
|
exporter_file_id,
|
|
1370
1504
|
name: "default",
|
|
@@ -1374,7 +1508,7 @@ function extract_import(ctx, source_file, node, file_id) {
|
|
|
1374
1508
|
}
|
|
1375
1509
|
if (clause.namedBindings && ts4.isNamedImports(clause.namedBindings)) {
|
|
1376
1510
|
for (const element of clause.namedBindings.elements) {
|
|
1377
|
-
|
|
1511
|
+
imports4.push({
|
|
1378
1512
|
importer_file_id: file_id,
|
|
1379
1513
|
exporter_file_id,
|
|
1380
1514
|
name: (element.propertyName || element.name).text,
|
|
@@ -1384,7 +1518,7 @@ function extract_import(ctx, source_file, node, file_id) {
|
|
|
1384
1518
|
}
|
|
1385
1519
|
}
|
|
1386
1520
|
if (clause.namedBindings && ts4.isNamespaceImport(clause.namedBindings)) {
|
|
1387
|
-
|
|
1521
|
+
imports4.push({
|
|
1388
1522
|
importer_file_id: file_id,
|
|
1389
1523
|
exporter_file_id,
|
|
1390
1524
|
name: "*",
|
|
@@ -1392,7 +1526,7 @@ function extract_import(ctx, source_file, node, file_id) {
|
|
|
1392
1526
|
state: "to_link"
|
|
1393
1527
|
});
|
|
1394
1528
|
}
|
|
1395
|
-
return
|
|
1529
|
+
return imports4;
|
|
1396
1530
|
}
|
|
1397
1531
|
function extract_dynamic_import(ctx, source_file, node, file_id) {
|
|
1398
1532
|
const arg = node.arguments[0];
|
|
@@ -1504,7 +1638,7 @@ function extract_external_import_info(node) {
|
|
|
1504
1638
|
}
|
|
1505
1639
|
function extract_external_import(ctx, node, file_id) {
|
|
1506
1640
|
const infos = extract_external_import_info(node);
|
|
1507
|
-
const
|
|
1641
|
+
const external_imports3 = [];
|
|
1508
1642
|
for (const info of infos) {
|
|
1509
1643
|
const dep_meta = Object.values(ctx.dependencies).find((dep) => info.package.startsWith(dep.name));
|
|
1510
1644
|
const dependency = external_dependencies_exports.get_or_create(ctx, {
|
|
@@ -1517,9 +1651,9 @@ function extract_external_import(ctx, node, file_id) {
|
|
|
1517
1651
|
state: "to_describe"
|
|
1518
1652
|
});
|
|
1519
1653
|
if (err.any(dependency)) return dependency;
|
|
1520
|
-
|
|
1654
|
+
external_imports3.push({ file_id, external_dependency_id: dependency.id, alias: info.alias, is_dynamic: false });
|
|
1521
1655
|
}
|
|
1522
|
-
return
|
|
1656
|
+
return external_imports3;
|
|
1523
1657
|
}
|
|
1524
1658
|
function extract_external_dynamic_import(ctx, node, file_id) {
|
|
1525
1659
|
const arg = node.arguments[0];
|
|
@@ -1824,32 +1958,32 @@ function scan_file(ctx, file) {
|
|
|
1824
1958
|
() => external_imports_exports.del_by_file(ctx, file.id),
|
|
1825
1959
|
() => get_source_file(ctx, file.path),
|
|
1826
1960
|
(source_file) => parse_file(ctx, source_file, file.id),
|
|
1827
|
-
({ imports:
|
|
1828
|
-
() =>
|
|
1829
|
-
() =>
|
|
1961
|
+
({ imports: imports4, symbols: symbols3, external_imports: external_imports3 }) => err.pipe(
|
|
1962
|
+
() => external_imports3.length && external_imports_exports.insert_many(ctx, external_imports3),
|
|
1963
|
+
() => imports4.length && imports_exports.insert_many(ctx, imports4),
|
|
1830
1964
|
() => symbols3.length && symbols_exports.insert_many(ctx, symbols3)
|
|
1831
1965
|
)
|
|
1832
1966
|
);
|
|
1833
1967
|
}
|
|
1834
1968
|
function get_source_file(ctx, file_path) {
|
|
1835
|
-
const source_file = ctx.program.getSourceFile(
|
|
1969
|
+
const source_file = ctx.program.getSourceFile(path5.join(ctx.project_path, file_path));
|
|
1836
1970
|
if (!source_file) return err.new("file_not_found", { path: file_path });
|
|
1837
1971
|
return source_file;
|
|
1838
1972
|
}
|
|
1839
1973
|
function parse_file(ctx, source_file, file_id) {
|
|
1840
|
-
const
|
|
1974
|
+
const imports4 = [];
|
|
1841
1975
|
const symbols3 = [];
|
|
1842
|
-
const
|
|
1976
|
+
const external_imports3 = [];
|
|
1843
1977
|
function find_dynamic_imports(node) {
|
|
1844
1978
|
if (is_dynamic_import(node)) {
|
|
1845
1979
|
const arg = node.arguments[0];
|
|
1846
1980
|
if (is_external_module(ctx, source_file, arg.text)) {
|
|
1847
1981
|
const result = extract_external_dynamic_import(ctx, node, file_id);
|
|
1848
1982
|
if (err.any(result)) return result;
|
|
1849
|
-
|
|
1983
|
+
external_imports3.push(result);
|
|
1850
1984
|
} else {
|
|
1851
1985
|
const result = extract_dynamic_import(ctx, source_file, node, file_id);
|
|
1852
|
-
if (result)
|
|
1986
|
+
if (result) imports4.push(result);
|
|
1853
1987
|
}
|
|
1854
1988
|
}
|
|
1855
1989
|
ts10.forEachChild(node, find_dynamic_imports);
|
|
@@ -1862,24 +1996,24 @@ function parse_file(ctx, source_file, file_id) {
|
|
|
1862
1996
|
error = res;
|
|
1863
1997
|
return;
|
|
1864
1998
|
}
|
|
1865
|
-
|
|
1999
|
+
imports4.push(...res.imports);
|
|
1866
2000
|
symbols3.push(...res.symbols);
|
|
1867
|
-
|
|
2001
|
+
external_imports3.push(...res.external_imports);
|
|
1868
2002
|
error = find_dynamic_imports(statement);
|
|
1869
2003
|
});
|
|
1870
2004
|
if (error) return error;
|
|
1871
|
-
return { imports:
|
|
2005
|
+
return { imports: imports4, symbols: symbols3, external_imports: external_imports3 };
|
|
1872
2006
|
}
|
|
1873
2007
|
function parse_node(ctx, source_file, node, file_id) {
|
|
1874
|
-
const
|
|
2008
|
+
const imports4 = [];
|
|
1875
2009
|
const symbols3 = [];
|
|
1876
|
-
const
|
|
2010
|
+
const external_imports3 = [];
|
|
1877
2011
|
if (is_external_import(ctx, source_file, node)) {
|
|
1878
2012
|
const result = extract_external_import(ctx, node, file_id);
|
|
1879
2013
|
if (err.any(result)) return result;
|
|
1880
|
-
|
|
2014
|
+
external_imports3.push(...result);
|
|
1881
2015
|
} else if (is_import(ctx, source_file, node)) {
|
|
1882
|
-
|
|
2016
|
+
imports4.push(...extract_import(ctx, source_file, node, file_id));
|
|
1883
2017
|
} else if (ts10.isExportAssignment(node) && !node.isExportEquals) {
|
|
1884
2018
|
symbols3.push({
|
|
1885
2019
|
file_id,
|
|
@@ -1921,14 +2055,14 @@ function parse_node(ctx, source_file, node, file_id) {
|
|
|
1921
2055
|
symbols3.push(extract_class_symbol(node, file_id, source_file));
|
|
1922
2056
|
symbols3.push(...extract_class_fields(node, file_id, source_file));
|
|
1923
2057
|
}
|
|
1924
|
-
return { imports:
|
|
2058
|
+
return { imports: imports4, symbols: symbols3, external_imports: external_imports3 };
|
|
1925
2059
|
}
|
|
1926
2060
|
|
|
1927
2061
|
// src/update/link_imports.ts
|
|
1928
2062
|
async function link_imports(ctx) {
|
|
1929
|
-
const
|
|
2063
|
+
const imports4 = err.or_throw(imports_exports.by_state(ctx, "to_link"));
|
|
1930
2064
|
let i = 0;
|
|
1931
|
-
for (const import_ of
|
|
2065
|
+
for (const import_ of imports4) {
|
|
1932
2066
|
const res = link_import(ctx, import_);
|
|
1933
2067
|
if (err.any(res)) err.or_throw(imports_exports.update(ctx, import_.id, { error: String(res) }));
|
|
1934
2068
|
}
|
|
@@ -1944,7 +2078,7 @@ function link_import(ctx, import_) {
|
|
|
1944
2078
|
}
|
|
1945
2079
|
|
|
1946
2080
|
// src/update/link_symbols.ts
|
|
1947
|
-
import
|
|
2081
|
+
import path6 from "path";
|
|
1948
2082
|
import ts11 from "typescript";
|
|
1949
2083
|
async function link_symbols(ctx) {
|
|
1950
2084
|
const symbols3 = err.or_throw(symbols_exports.by_state(ctx, "to_link"));
|
|
@@ -1970,7 +2104,7 @@ function find_symbol_references(ctx, symbol) {
|
|
|
1970
2104
|
const file = files_exports.by_id(ctx, symbol.file_id);
|
|
1971
2105
|
if (err.any(file)) return file;
|
|
1972
2106
|
if (!file) return err.new("file_not_found", { path: `file_id=${symbol.file_id}` });
|
|
1973
|
-
const file_path =
|
|
2107
|
+
const file_path = path6.join(ctx.project_path, file.path);
|
|
1974
2108
|
const source_file = ctx.program.getSourceFile(file_path);
|
|
1975
2109
|
if (!source_file) return err.new("file_not_found", { path: file_path });
|
|
1976
2110
|
const symbol_node = find_symbol_node(source_file, symbol);
|
|
@@ -2194,19 +2328,19 @@ async function update6(ctx) {
|
|
|
2194
2328
|
}
|
|
2195
2329
|
|
|
2196
2330
|
// src/counts.ts
|
|
2197
|
-
import { count } from "drizzle-orm";
|
|
2198
|
-
|
|
2199
|
-
const symbol_counts = ctx.db.select({ state: symbols.state, count:
|
|
2200
|
-
const file_counts = ctx.db.select({ state: files.state, count:
|
|
2201
|
-
const dir_counts = ctx.db.select({ state: directories.state, count:
|
|
2202
|
-
const dep_counts = ctx.db.select({ state: external_dependencies.state, count:
|
|
2331
|
+
import { count as count10 } from "drizzle-orm";
|
|
2332
|
+
function counts(ctx) {
|
|
2333
|
+
const symbol_counts = ctx.db.select({ state: symbols.state, count: count10() }).from(symbols).groupBy(symbols.state).all();
|
|
2334
|
+
const file_counts = ctx.db.select({ state: files.state, count: count10() }).from(files).groupBy(files.state).all();
|
|
2335
|
+
const dir_counts = ctx.db.select({ state: directories.state, count: count10() }).from(directories).groupBy(directories.state).all();
|
|
2336
|
+
const dep_counts = ctx.db.select({ state: external_dependencies.state, count: count10() }).from(external_dependencies).groupBy(external_dependencies.state).all();
|
|
2203
2337
|
return {
|
|
2204
2338
|
symbols: get_groups(symbol_counts, ["to_link", "to_describe", "ready"]),
|
|
2205
2339
|
files: get_groups(file_counts, ["to_scan", "to_describe", "ready"]),
|
|
2206
2340
|
directories: get_groups(dir_counts, ["to_describe", "ready"]),
|
|
2207
2341
|
dependencies: get_groups(dep_counts, ["to_describe", "ready"])
|
|
2208
2342
|
};
|
|
2209
|
-
}
|
|
2343
|
+
}
|
|
2210
2344
|
function get_groups(items, states) {
|
|
2211
2345
|
const groups = { total: 0 };
|
|
2212
2346
|
for (const state of states) groups[state] = 0;
|
|
@@ -2222,7 +2356,7 @@ function get_groups(items, states) {
|
|
|
2222
2356
|
function files_wiki(ctx) {
|
|
2223
2357
|
return {
|
|
2224
2358
|
get: (id) => get2(ctx, id),
|
|
2225
|
-
search: (options) =>
|
|
2359
|
+
search: (options) => search9(ctx, options),
|
|
2226
2360
|
set_description: (id, description) => set_description(ctx, id, description),
|
|
2227
2361
|
imported_by_file: (file_id, options) => imported_by_file(ctx, file_id, options),
|
|
2228
2362
|
importing_file: (file_id, options) => importing_file(ctx, file_id, options),
|
|
@@ -2232,11 +2366,11 @@ function files_wiki(ctx) {
|
|
|
2232
2366
|
function get2(ctx, id) {
|
|
2233
2367
|
return err.or_throw(files_exports.by_id(ctx, id)) ?? null;
|
|
2234
2368
|
}
|
|
2235
|
-
function
|
|
2369
|
+
function search9(ctx, options) {
|
|
2236
2370
|
return err.or_throw(files_exports.search(ctx, options));
|
|
2237
2371
|
}
|
|
2238
2372
|
function set_description(ctx, id, description) {
|
|
2239
|
-
err.or_throw(files_exports.update(ctx, id, { description }));
|
|
2373
|
+
err.or_throw(files_exports.update(ctx, id, { description, state: "ready", error: null }));
|
|
2240
2374
|
}
|
|
2241
2375
|
function imported_by_file(ctx, file_id, options = {}) {
|
|
2242
2376
|
let imported_files = err.or_throw(files_exports.imported_by(ctx, file_id, options.select));
|
|
@@ -2288,7 +2422,7 @@ function importing_dependency(ctx, dependency_id, options = {}) {
|
|
|
2288
2422
|
function symbols_wiki(ctx) {
|
|
2289
2423
|
return {
|
|
2290
2424
|
get: (id) => get3(ctx, id),
|
|
2291
|
-
search: (options) =>
|
|
2425
|
+
search: (options) => search10(ctx, options),
|
|
2292
2426
|
set_description: (id, description) => set_description2(ctx, id, description),
|
|
2293
2427
|
referencing_symbol: (symbol_id, options) => referencing_symbol(ctx, symbol_id, options),
|
|
2294
2428
|
referenced_by_symbol: (symbol_id, options) => referenced_by_symbol(ctx, symbol_id, options),
|
|
@@ -2298,11 +2432,12 @@ function symbols_wiki(ctx) {
|
|
|
2298
2432
|
function get3(ctx, id) {
|
|
2299
2433
|
return err.or_throw(symbols_exports.by_id(ctx, id)) ?? null;
|
|
2300
2434
|
}
|
|
2301
|
-
function
|
|
2435
|
+
function search10(ctx, options) {
|
|
2302
2436
|
return err.or_throw(symbols_exports.search(ctx, options));
|
|
2303
2437
|
}
|
|
2304
2438
|
function set_description2(ctx, id, description) {
|
|
2305
|
-
err.or_throw(symbols_exports.update(ctx, id, { description }));
|
|
2439
|
+
err.or_throw(symbols_exports.update(ctx, id, { description, state: "ready", error: null }));
|
|
2440
|
+
err.or_throw(symbol_internal_links_exports.update_state_by_to_symbol(ctx, id, "ready"));
|
|
2306
2441
|
}
|
|
2307
2442
|
function referenced_by_symbol(ctx, symbol_id, options = {}) {
|
|
2308
2443
|
let referenced_symbols = err.or_throw(symbols_exports.referenced_by(ctx, symbol_id, options.select));
|
|
@@ -2354,7 +2489,7 @@ function using_dependency3(ctx, dependency_id, options = {}) {
|
|
|
2354
2489
|
function directories_wiki(ctx) {
|
|
2355
2490
|
return {
|
|
2356
2491
|
get: (id) => get4(ctx, id),
|
|
2357
|
-
search: (options) =>
|
|
2492
|
+
search: (options) => search11(ctx, options),
|
|
2358
2493
|
set_description: (id, description) => set_description3(ctx, id, description),
|
|
2359
2494
|
children: (parent_id, options) => children(ctx, parent_id, options),
|
|
2360
2495
|
files: (directory_id, options) => directory_files(ctx, directory_id, options)
|
|
@@ -2363,11 +2498,11 @@ function directories_wiki(ctx) {
|
|
|
2363
2498
|
function get4(ctx, id) {
|
|
2364
2499
|
return err.or_throw(directories_exports.by_id(ctx, id)) ?? null;
|
|
2365
2500
|
}
|
|
2366
|
-
function
|
|
2501
|
+
function search11(ctx, options) {
|
|
2367
2502
|
return err.or_throw(directories_exports.search(ctx, options));
|
|
2368
2503
|
}
|
|
2369
2504
|
function set_description3(ctx, id, description) {
|
|
2370
|
-
err.or_throw(directories_exports.update(ctx, id, { description }));
|
|
2505
|
+
err.or_throw(directories_exports.update(ctx, id, { description, state: "ready", error: null }));
|
|
2371
2506
|
}
|
|
2372
2507
|
function children(ctx, parent_id, options = {}) {
|
|
2373
2508
|
let child_directories = err.or_throw(directories_exports.search(ctx, { select: options.select, where: { parent_id }, limit: 1e4 }));
|
|
@@ -2410,7 +2545,7 @@ function directory_files(ctx, directory_id, options = {}) {
|
|
|
2410
2545
|
function dependencies_wiki(ctx) {
|
|
2411
2546
|
return {
|
|
2412
2547
|
get: (id) => get5(ctx, id),
|
|
2413
|
-
search: (options) =>
|
|
2548
|
+
search: (options) => search12(ctx, options),
|
|
2414
2549
|
set_description: (id, description) => set_description4(ctx, id, description),
|
|
2415
2550
|
used_by_file: (file_id, options) => used_by_file2(ctx, file_id, options),
|
|
2416
2551
|
used_by_symbol: (symbol_id, options) => used_by_symbol2(ctx, symbol_id, options)
|
|
@@ -2419,7 +2554,7 @@ function dependencies_wiki(ctx) {
|
|
|
2419
2554
|
function get5(ctx, id) {
|
|
2420
2555
|
return err.or_throw(external_dependencies_exports.by_id(ctx, id)) ?? null;
|
|
2421
2556
|
}
|
|
2422
|
-
function
|
|
2557
|
+
function search12(ctx, options) {
|
|
2423
2558
|
return err.or_throw(external_dependencies_exports.search(ctx, options));
|
|
2424
2559
|
}
|
|
2425
2560
|
function set_description4(ctx, id, description) {
|
|
@@ -2432,13 +2567,88 @@ function used_by_symbol2(ctx, symbol_id, options) {
|
|
|
2432
2567
|
return err.or_throw(external_dependencies_exports.used_by_symbol(ctx, symbol_id, options?.select));
|
|
2433
2568
|
}
|
|
2434
2569
|
|
|
2570
|
+
// src/to_describe.ts
|
|
2571
|
+
function to_describe(ctx, limit) {
|
|
2572
|
+
const dependencies_count = err.or_throw(external_dependencies_exports.count(ctx, { state: "to_describe" }));
|
|
2573
|
+
if (dependencies_count > 0) return { type: "dependencies", items: dependencies_to_describe(ctx, limit) };
|
|
2574
|
+
const symbols_count = err.or_throw(symbols_exports.count(ctx, { state: "to_describe" }));
|
|
2575
|
+
if (symbols_count > 0) return { type: "symbols", items: symbols_to_describe(ctx, limit) };
|
|
2576
|
+
const pending_symbols_count = err.or_throw(symbols_exports.count(ctx, { state: "to_link" }));
|
|
2577
|
+
if (pending_symbols_count > 0) throw err.new("could_not_describe_files_due_to_pending_symbols", { count: pending_symbols_count });
|
|
2578
|
+
const files_count = err.or_throw(files_exports.count(ctx, { state: "to_describe" }));
|
|
2579
|
+
if (files_count > 0) return { type: "files", items: files_to_describe(ctx, limit) };
|
|
2580
|
+
const pending_files_count = err.or_throw(files_exports.count(ctx, { state: "to_scan" }));
|
|
2581
|
+
if (pending_files_count > 0) throw err.new("could_not_describe_directories_due_to_pending_files", { count: pending_files_count });
|
|
2582
|
+
const directories_count = err.or_throw(directories_exports.count(ctx, { state: "to_describe" }));
|
|
2583
|
+
if (directories_count > 0) return { type: "directories", items: directories_to_describe(ctx, limit) };
|
|
2584
|
+
return { type: "none" };
|
|
2585
|
+
}
|
|
2586
|
+
function dependencies_to_describe(ctx, limit) {
|
|
2587
|
+
const candidates = err.or_throw(
|
|
2588
|
+
external_dependencies_exports.search(ctx, {
|
|
2589
|
+
where: { state: "to_describe" },
|
|
2590
|
+
select: ["id", "package", "name"],
|
|
2591
|
+
limit: 1e5
|
|
2592
|
+
})
|
|
2593
|
+
);
|
|
2594
|
+
candidates.sort((a, b) => {
|
|
2595
|
+
if (a.package !== b.package) return a.package.localeCompare(b.package);
|
|
2596
|
+
return (a.name || "").localeCompare(b.name || "");
|
|
2597
|
+
});
|
|
2598
|
+
const ids = candidates.slice(0, limit).map((dep) => dep.id);
|
|
2599
|
+
const items = err.or_throw(external_dependencies_exports.by_ids(ctx, ids));
|
|
2600
|
+
const by_id5 = new Map(items.map((item) => [item.id, item]));
|
|
2601
|
+
return ids.map((id) => by_id5.get(id)).filter((item) => !!item);
|
|
2602
|
+
}
|
|
2603
|
+
function symbols_to_describe(ctx, limit) {
|
|
2604
|
+
const candidates = err.or_throw(symbols_exports.search(ctx, { where: { state: "to_describe" }, select: ["id", "text"], limit: 1e5 }));
|
|
2605
|
+
const counts2 = {};
|
|
2606
|
+
for (const symbol of candidates) {
|
|
2607
|
+
counts2[symbol.id] = {
|
|
2608
|
+
length: symbol.text?.length ?? 0,
|
|
2609
|
+
missing_external: err.or_throw(symbol_external_links_exports.count_pending_deps(ctx, symbol.id)),
|
|
2610
|
+
missing_internal: err.or_throw(symbol_internal_links_exports.count(ctx, { from_symbol_id: symbol.id, state: "pending" }))
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
candidates.sort((x, y) => {
|
|
2614
|
+
const a = counts2[x.id];
|
|
2615
|
+
const b = counts2[y.id];
|
|
2616
|
+
if (!a || !b) return 0;
|
|
2617
|
+
if (a.missing_internal !== b.missing_internal) return a.missing_internal - b.missing_internal;
|
|
2618
|
+
if (a.missing_external !== b.missing_external) return a.missing_external - b.missing_external;
|
|
2619
|
+
return a.length - b.length;
|
|
2620
|
+
});
|
|
2621
|
+
const ids = candidates.slice(0, limit).map((symbol) => symbol.id);
|
|
2622
|
+
const items = err.or_throw(symbols_exports.by_ids(ctx, ids));
|
|
2623
|
+
const by_id5 = new Map(items.map((item) => [item.id, item]));
|
|
2624
|
+
return ids.map((id) => by_id5.get(id)).filter((item) => !!item);
|
|
2625
|
+
}
|
|
2626
|
+
function files_to_describe(ctx, limit) {
|
|
2627
|
+
return err.or_throw(files_exports.by_state(ctx, "to_describe", limit));
|
|
2628
|
+
}
|
|
2629
|
+
function directories_to_describe(ctx, limit) {
|
|
2630
|
+
const candidates = err.or_throw(
|
|
2631
|
+
directories_exports.search(ctx, {
|
|
2632
|
+
where: { state: "to_describe" },
|
|
2633
|
+
select: ["id", "path"],
|
|
2634
|
+
limit: 1e5
|
|
2635
|
+
})
|
|
2636
|
+
);
|
|
2637
|
+
candidates.sort((a, b) => b.path.split("/").length - a.path.split("/").length);
|
|
2638
|
+
const ids = candidates.slice(0, limit).map((dir) => dir.id);
|
|
2639
|
+
const items = err.or_throw(directories_exports.by_ids(ctx, ids));
|
|
2640
|
+
const by_id5 = new Map(items.map((item) => [item.id, item]));
|
|
2641
|
+
return ids.map((id) => by_id5.get(id)).filter((item) => !!item);
|
|
2642
|
+
}
|
|
2643
|
+
|
|
2435
2644
|
// src/index.ts
|
|
2436
2645
|
async function create(config) {
|
|
2437
2646
|
const ctx = await context_from_config(config);
|
|
2438
2647
|
return {
|
|
2439
2648
|
config,
|
|
2440
2649
|
update: () => update6(ctx),
|
|
2441
|
-
counts: () =>
|
|
2650
|
+
counts: () => counts(ctx),
|
|
2651
|
+
to_describe: (limit) => to_describe(ctx, limit),
|
|
2442
2652
|
files: files_wiki(ctx),
|
|
2443
2653
|
symbols: symbols_wiki(ctx),
|
|
2444
2654
|
directories: directories_wiki(ctx),
|
|
@@ -2458,7 +2668,8 @@ async function load(db_path) {
|
|
|
2458
2668
|
return {
|
|
2459
2669
|
config,
|
|
2460
2670
|
update: () => update6(ctx),
|
|
2461
|
-
counts: () =>
|
|
2671
|
+
counts: () => counts(ctx),
|
|
2672
|
+
to_describe: (limit) => to_describe(ctx, limit),
|
|
2462
2673
|
files: files_wiki(ctx),
|
|
2463
2674
|
symbols: symbols_wiki(ctx),
|
|
2464
2675
|
directories: directories_wiki(ctx),
|