@webneat/codewiki 0.0.5 → 0.0.7

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.cjs CHANGED
@@ -578,7 +578,7 @@ var symbols2 = {
578
578
  where: {}
579
579
  };
580
580
  var external_dependencies2 = {
581
- select: ["id", "package", "subpath", "name", "state", "error"],
581
+ select: ["id", "package", "subpath", "name", "is_builtin", "state", "error"],
582
582
  order_by: ["id", "asc"],
583
583
  limit: 20,
584
584
  offset: 0,
@@ -1204,12 +1204,6 @@ async function create_context(sqlite, db6, config) {
1204
1204
  );
1205
1205
  return ctx;
1206
1206
  }
1207
- async function context_from_config(config) {
1208
- const sqlite = new import_better_sqlite3.default(config.db_path);
1209
- sqlite.pragma("foreign_keys = ON");
1210
- const db6 = (0, import_better_sqlite32.drizzle)(sqlite, { schema: schema_exports });
1211
- return create_context(sqlite, db6, config);
1212
- }
1213
1207
  async function context_from_db(db_path) {
1214
1208
  const sqlite = new import_better_sqlite3.default(db_path);
1215
1209
  sqlite.pragma("foreign_keys = ON");
@@ -1266,6 +1260,7 @@ async function get_github_repo(node_modules_paths, package_name) {
1266
1260
  // src/cli/env.ts
1267
1261
  var env = {
1268
1262
  read_file,
1263
+ cwd: () => process.cwd(),
1269
1264
  file_exists: (path6) => (0, import_node_fs2.existsSync)(path6),
1270
1265
  argv: () => process.argv,
1271
1266
  log: (...args) => console.log(...args),
@@ -1274,120 +1269,7 @@ var env = {
1274
1269
  };
1275
1270
 
1276
1271
  // src/cli/commands/_common.ts
1277
- var import_zod2 = require("zod");
1278
-
1279
- // src/cli/schema.ts
1280
1272
  var import_zod = require("zod");
1281
- var Config = import_zod.z.object({
1282
- db_path: import_zod.z.string().describe("Path to SQLite database"),
1283
- project_path: import_zod.z.string().describe("Path to TypeScript project"),
1284
- description: import_zod.z.string().optional(),
1285
- package_json_path: import_zod.z.string().optional(),
1286
- node_modules_paths: import_zod.z.array(import_zod.z.string()).optional()
1287
- });
1288
- var StringFilter = import_zod.z.union([
1289
- import_zod.z.string(),
1290
- import_zod.z.object({ contains: import_zod.z.string() }),
1291
- import_zod.z.object({ starts_with: import_zod.z.string() }),
1292
- import_zod.z.object({ ends_with: import_zod.z.string() })
1293
- ]);
1294
- var OrderDirection = import_zod.z.enum(["asc", "desc"]);
1295
- var FileField = import_zod.z.enum(["id", "directory_id", "path", "description", "state", "error"]);
1296
- var FileState = import_zod.z.enum(["to_scan", "to_describe", "ready"]);
1297
- var FileSearchOptions = import_zod.z.object({
1298
- select: import_zod.z.array(FileField).optional(),
1299
- limit: import_zod.z.number().int().positive().optional(),
1300
- offset: import_zod.z.number().int().nonnegative().optional(),
1301
- where: import_zod.z.object({
1302
- id: import_zod.z.number().optional(),
1303
- directory_id: import_zod.z.number().optional(),
1304
- path: StringFilter.optional(),
1305
- description: StringFilter.optional(),
1306
- state: import_zod.z.union([FileState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1307
- error: StringFilter.optional()
1308
- }).optional(),
1309
- order_by: import_zod.z.tuple([FileField, OrderDirection]).optional()
1310
- });
1311
- var FileRelationOptions = import_zod.z.object({
1312
- select: import_zod.z.array(FileField).optional(),
1313
- limit: import_zod.z.number().int().positive().optional(),
1314
- offset: import_zod.z.number().int().nonnegative().optional(),
1315
- deep: import_zod.z.boolean().optional()
1316
- });
1317
- var SymbolField = import_zod.z.enum(["id", "file_id", "type", "name", "text", "meta", "description", "is_exported", "state", "error"]);
1318
- var SymbolType = import_zod.z.enum(["function", "class", "class_method", "class_property", "variable", "type"]);
1319
- var SymbolState = import_zod.z.enum(["to_link", "to_describe", "ready"]);
1320
- var SymbolSearchOptions = import_zod.z.object({
1321
- select: import_zod.z.array(SymbolField).optional(),
1322
- limit: import_zod.z.number().int().positive().optional(),
1323
- offset: import_zod.z.number().int().nonnegative().optional(),
1324
- where: import_zod.z.object({
1325
- id: import_zod.z.number().optional(),
1326
- file_id: import_zod.z.number().optional(),
1327
- type: import_zod.z.union([SymbolType, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1328
- name: StringFilter.optional(),
1329
- text: StringFilter.optional(),
1330
- meta: StringFilter.optional(),
1331
- description: StringFilter.optional(),
1332
- is_exported: import_zod.z.boolean().optional(),
1333
- state: import_zod.z.union([SymbolState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1334
- error: StringFilter.optional()
1335
- }).optional(),
1336
- order_by: import_zod.z.tuple([SymbolField, OrderDirection]).optional()
1337
- });
1338
- var SymbolRelationOptions = import_zod.z.object({
1339
- select: import_zod.z.array(SymbolField).optional(),
1340
- limit: import_zod.z.number().int().positive().optional(),
1341
- offset: import_zod.z.number().int().nonnegative().optional(),
1342
- deep: import_zod.z.boolean().optional()
1343
- });
1344
- var DirectoryField = import_zod.z.enum(["id", "parent_id", "path", "description", "state", "error"]);
1345
- var DirectoryState = import_zod.z.enum(["to_describe", "ready"]);
1346
- var DirectorySearchOptions = import_zod.z.object({
1347
- select: import_zod.z.array(DirectoryField).optional(),
1348
- limit: import_zod.z.number().int().positive().optional(),
1349
- offset: import_zod.z.number().int().nonnegative().optional(),
1350
- where: import_zod.z.object({
1351
- id: import_zod.z.number().optional(),
1352
- parent_id: import_zod.z.number().optional(),
1353
- path: StringFilter.optional(),
1354
- description: StringFilter.optional(),
1355
- state: import_zod.z.union([DirectoryState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1356
- error: StringFilter.optional()
1357
- }).optional(),
1358
- order_by: import_zod.z.tuple([DirectoryField, OrderDirection]).optional()
1359
- });
1360
- var DirectoryRelationOptions = import_zod.z.object({
1361
- select: import_zod.z.array(DirectoryField).optional(),
1362
- limit: import_zod.z.number().int().positive().optional(),
1363
- offset: import_zod.z.number().int().nonnegative().optional(),
1364
- deep: import_zod.z.boolean().optional()
1365
- });
1366
- var DependencyField = import_zod.z.enum(["id", "package", "subpath", "name", "version", "github_repo", "is_builtin", "description", "state", "error"]);
1367
- var DependencyState = import_zod.z.enum(["to_describe", "ready"]);
1368
- var DependencySearchOptions = import_zod.z.object({
1369
- select: import_zod.z.array(DependencyField).optional(),
1370
- limit: import_zod.z.number().int().positive().optional(),
1371
- offset: import_zod.z.number().int().nonnegative().optional(),
1372
- where: import_zod.z.object({
1373
- id: import_zod.z.number().optional(),
1374
- package: StringFilter.optional(),
1375
- subpath: StringFilter.optional(),
1376
- name: StringFilter.optional(),
1377
- version: StringFilter.optional(),
1378
- github_repo: StringFilter.optional(),
1379
- is_builtin: import_zod.z.boolean().optional(),
1380
- description: StringFilter.optional(),
1381
- state: import_zod.z.union([DependencyState, import_zod.z.object({ contains: import_zod.z.string() })]).optional(),
1382
- error: StringFilter.optional()
1383
- }).optional(),
1384
- order_by: import_zod.z.tuple([DependencyField, OrderDirection]).optional()
1385
- });
1386
- var DependencySelectOptions = import_zod.z.object({
1387
- select: import_zod.z.array(DependencyField).optional(),
1388
- limit: import_zod.z.number().int().positive().optional(),
1389
- offset: import_zod.z.number().int().nonnegative().optional()
1390
- });
1391
1273
 
1392
1274
  // src/update/track_changes.ts
1393
1275
  var import_node_path3 = __toESM(require("path"), 1);
@@ -2485,6 +2367,21 @@ async function update6(ctx) {
2485
2367
  await link_symbols(ctx);
2486
2368
  }
2487
2369
 
2370
+ // src/update_config.ts
2371
+ function update_config(ctx, config, updates) {
2372
+ if (Object.keys(updates).length === 0) return;
2373
+ const new_config = { ...config, ...updates };
2374
+ err.or_throw(
2375
+ configs_exports.upsert(ctx, {
2376
+ project_path: new_config.project_path,
2377
+ description: new_config.description ?? null,
2378
+ package_json_path: new_config.package_json_path ?? null,
2379
+ node_modules_paths: new_config.node_modules_paths ? JSON.stringify(new_config.node_modules_paths) : null
2380
+ })
2381
+ );
2382
+ Object.assign(config, updates);
2383
+ }
2384
+
2488
2385
  // src/counts.ts
2489
2386
  var import_drizzle_orm13 = require("drizzle-orm");
2490
2387
  function counts(ctx) {
@@ -2800,19 +2697,6 @@ function directories_to_describe(ctx, limit) {
2800
2697
  }
2801
2698
 
2802
2699
  // src/index.ts
2803
- async function create(config) {
2804
- const ctx = await context_from_config(config);
2805
- return {
2806
- config,
2807
- update: () => update6(ctx),
2808
- counts: () => counts(ctx),
2809
- to_describe: (limit) => to_describe(ctx, limit),
2810
- files: files_wiki(ctx),
2811
- symbols: symbols_wiki(ctx),
2812
- directories: directories_wiki(ctx),
2813
- dependencies: dependencies_wiki(ctx)
2814
- };
2815
- }
2816
2700
  async function load(db_path) {
2817
2701
  const ctx = await context_from_db(db_path);
2818
2702
  const stored = ctx.db.select().from(schema_exports.configs).get();
@@ -2825,6 +2709,7 @@ async function load(db_path) {
2825
2709
  };
2826
2710
  return {
2827
2711
  config,
2712
+ update_config: (updates) => update_config(ctx, config, updates),
2828
2713
  update: () => update6(ctx),
2829
2714
  counts: () => counts(ctx),
2830
2715
  to_describe: (limit) => to_describe(ctx, limit),
@@ -2836,30 +2721,18 @@ async function load(db_path) {
2836
2721
  }
2837
2722
 
2838
2723
  // src/cli/commands/_common.ts
2839
- var config_path = "codewiki.json";
2840
- async function load_wiki() {
2841
- try {
2842
- const content = err.or_throw(env.read_file(config_path));
2843
- const raw_config = err.or_throw(parse_json(content));
2844
- const res = Config.safeParse(raw_config);
2845
- if (!res.success) throw err.new("invalid_config", { errors: res.error.issues });
2846
- const config = res.data;
2847
- if (env.file_exists(config.db_path)) return load(config.db_path);
2848
- return create(config);
2849
- } catch (error) {
2850
- if (error.type === "could_not_read_file") {
2851
- env.error(`Error: Configuration file ${config_path} not found`);
2852
- } else if (error.type === "invalid_json") {
2853
- env.error(`Error: Invalid JSON in ${config_path}`);
2854
- } else if (error.type === "invalid_config") {
2855
- env.error("Error: Invalid configuration");
2856
- } else if (error.message) {
2857
- env.error(`Error: ${error.message}`);
2858
- } else {
2859
- env.error(`Error: ${String(error)}`);
2860
- }
2861
- process.exit(1);
2724
+ function get_db_path(...args) {
2725
+ const cmd = args[args.length - 1];
2726
+ return cmd.optsWithGlobals().db;
2727
+ }
2728
+ async function load_wiki(db_path) {
2729
+ if (!env.file_exists(db_path)) {
2730
+ env.error(`Error: No wiki found at ${db_path}`);
2731
+ env.error(`Run \`codewiki init\` to create one.`);
2732
+ env.exit(1);
2733
+ return void 0;
2862
2734
  }
2735
+ return load(db_path);
2863
2736
  }
2864
2737
  function parse_options(options_json, schema, context) {
2865
2738
  let parsed_json;
@@ -2907,8 +2780,8 @@ function count_text({ total, ...states }) {
2907
2780
  // src/cli/commands/update.ts
2908
2781
  var update7 = new import_commander.Command("update");
2909
2782
  update7.description("Reads current files and updates the wiki database");
2910
- update7.action(async () => {
2911
- const wiki = await load_wiki();
2783
+ update7.action(async (...args) => {
2784
+ const wiki = await load_wiki(get_db_path(...args));
2912
2785
  await wiki.update();
2913
2786
  env.log("Update complete.\n");
2914
2787
  const counts2 = wiki.counts();
@@ -2920,8 +2793,8 @@ update7.action(async () => {
2920
2793
  var import_commander2 = require("commander");
2921
2794
  var status = new import_commander2.Command("status");
2922
2795
  status.description("Show the status of the wiki");
2923
- status.action(async () => {
2924
- const wiki = await load_wiki();
2796
+ status.action(async (...args) => {
2797
+ const wiki = await load_wiki(get_db_path(...args));
2925
2798
  const counts2 = wiki.counts();
2926
2799
  env.log(format_counts(counts2));
2927
2800
  });
@@ -2931,14 +2804,25 @@ var import_dedent2 = __toESM(require("dedent"), 1);
2931
2804
  var import_commander3 = require("commander");
2932
2805
  var describe = new import_commander3.Command("describe");
2933
2806
  describe.description("Show the next item to describe");
2934
- describe.action(async () => {
2935
- const wiki = await load_wiki();
2936
- const next = get_next_to_describe(wiki);
2937
- if (!next) return env.log("All items are described!");
2938
- if (next.type === "dependency") return describe_dependency(next.entity);
2939
- env.log(
2940
- `All external dependencies are described, and we don't support describing other items yet (we are implementing the right order ...). You are done for now!`
2941
- );
2807
+ describe.action(async (...args) => {
2808
+ const wiki = await load_wiki(get_db_path(...args));
2809
+ const result = wiki.to_describe(1);
2810
+ if (result.type === "none") {
2811
+ return env.log("All items are described!");
2812
+ }
2813
+ if (result.type === "dependencies" && result.items.length > 0) {
2814
+ return describe_dependency(result.items[0]);
2815
+ }
2816
+ if (result.type === "symbols" && result.items.length > 0) {
2817
+ return describe_symbol(wiki, result.items[0]);
2818
+ }
2819
+ if (result.type === "files" && result.items.length > 0) {
2820
+ return describe_file(result.items[0]);
2821
+ }
2822
+ if (result.type === "directories" && result.items.length > 0) {
2823
+ return describe_directory(result.items[0]);
2824
+ }
2825
+ env.log("No items to describe.");
2942
2826
  });
2943
2827
  function describe_dependency(dep) {
2944
2828
  env.log(import_dedent2.default`
@@ -2954,40 +2838,42 @@ function describe_dependency(dep) {
2954
2838
  \`codewiki dependencies set-description ${dep.id} <markdown-file>\`
2955
2839
  `);
2956
2840
  }
2957
- function get_next_to_describe(wiki) {
2958
- const deps = wiki.dependencies.search({
2959
- where: { state: "to_describe" },
2960
- limit: 1,
2961
- select: ["id", "package", "subpath", "name", "version", "github_repo"]
2962
- });
2963
- if (deps.length > 0) {
2964
- return { type: "dependency", entity: deps[0] };
2965
- }
2966
- const symbols4 = wiki.symbols.search({
2967
- where: { state: "to_describe" },
2968
- limit: 1,
2969
- select: ["id", "name", "type", "file_id", "is_exported"]
2970
- });
2971
- if (symbols4.length > 0) {
2972
- return { type: "symbol", entity: symbols4[0] };
2973
- }
2974
- const files5 = wiki.files.search({
2975
- where: { state: "to_describe" },
2976
- limit: 1,
2977
- select: ["id", "path"]
2978
- });
2979
- if (files5.length > 0) {
2980
- return { type: "file", entity: files5[0] };
2981
- }
2982
- const directories4 = wiki.directories.search({
2983
- where: { state: "to_describe" },
2984
- limit: 1,
2985
- select: ["id", "path"]
2986
- });
2987
- if (directories4.length > 0) {
2988
- return { type: "directory", entity: directories4[0] };
2989
- }
2990
- return null;
2841
+ function describe_symbol(wiki, sym) {
2842
+ const file = wiki.files.get(sym.file_id);
2843
+ env.log(import_dedent2.default`
2844
+ Your task is to describe the following symbol:
2845
+
2846
+ name: ${sym.name}
2847
+ type: ${sym.type}
2848
+ file: ${file?.path || "unknown"}
2849
+ exported: ${sym.is_exported}
2850
+
2851
+ Write a concise developer documentation for this ${sym.type} into a markdown file, then run:
2852
+
2853
+ codewiki symbols set-description ${sym.id} <markdown-file>
2854
+ `);
2855
+ }
2856
+ function describe_file(file) {
2857
+ env.log(import_dedent2.default`
2858
+ Your task is to describe the following file:
2859
+
2860
+ path: ${file.path}
2861
+
2862
+ Write a concise description of this file's purpose and contents into a markdown file, then run:
2863
+
2864
+ codewiki files set-description ${file.id} <markdown-file>
2865
+ `);
2866
+ }
2867
+ function describe_directory(dir) {
2868
+ env.log(import_dedent2.default`
2869
+ Your task is to describe the following directory:
2870
+
2871
+ path: ${dir.path}
2872
+
2873
+ Write a concise description of this directory's purpose and contents into a markdown file, then run:
2874
+
2875
+ codewiki directories set-description ${dir.id} <markdown-file>
2876
+ `);
2991
2877
  }
2992
2878
 
2993
2879
  // src/cli/commands/files/index.ts
@@ -2999,19 +2885,136 @@ var import_commander4 = require("commander");
2999
2885
  var get6 = new import_commander4.Command("get");
3000
2886
  get6.description("Get a file by ID");
3001
2887
  get6.argument("<id>", "File ID");
3002
- get6.action(async (id) => {
3003
- const wiki = await load_wiki();
2888
+ get6.action(async (...args) => {
2889
+ const [id] = args;
2890
+ const wiki = await load_wiki(get_db_path(...args));
3004
2891
  const file = wiki.files.get(Number(id));
3005
2892
  env.log(JSON.stringify(file, null, 2));
3006
2893
  });
3007
2894
 
3008
2895
  // src/cli/commands/files/search.ts
3009
2896
  var import_commander5 = require("commander");
2897
+
2898
+ // src/cli/schema.ts
2899
+ var import_zod2 = require("zod");
2900
+ var Config = import_zod2.z.object({
2901
+ db_path: import_zod2.z.string().describe("Path to SQLite database"),
2902
+ project_path: import_zod2.z.string().describe("Path to TypeScript project"),
2903
+ description: import_zod2.z.string().optional(),
2904
+ package_json_path: import_zod2.z.string().optional(),
2905
+ node_modules_paths: import_zod2.z.array(import_zod2.z.string()).optional()
2906
+ });
2907
+ var StringFilter = import_zod2.z.union([
2908
+ import_zod2.z.string(),
2909
+ import_zod2.z.object({ contains: import_zod2.z.string() }),
2910
+ import_zod2.z.object({ starts_with: import_zod2.z.string() }),
2911
+ import_zod2.z.object({ ends_with: import_zod2.z.string() })
2912
+ ]);
2913
+ var OrderDirection = import_zod2.z.enum(["asc", "desc"]);
2914
+ var FileField = import_zod2.z.enum(["id", "directory_id", "path", "description", "state", "error"]);
2915
+ var FileState = import_zod2.z.enum(["to_scan", "to_describe", "ready"]);
2916
+ var FileSearchOptions = import_zod2.z.object({
2917
+ select: import_zod2.z.array(FileField).optional(),
2918
+ limit: import_zod2.z.number().int().positive().optional(),
2919
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2920
+ where: import_zod2.z.object({
2921
+ id: import_zod2.z.number().optional(),
2922
+ directory_id: import_zod2.z.number().optional(),
2923
+ path: StringFilter.optional(),
2924
+ description: StringFilter.optional(),
2925
+ state: import_zod2.z.union([FileState, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
2926
+ error: StringFilter.optional()
2927
+ }).optional(),
2928
+ order_by: import_zod2.z.tuple([FileField, OrderDirection]).optional()
2929
+ });
2930
+ var FileRelationOptions = import_zod2.z.object({
2931
+ select: import_zod2.z.array(FileField).optional(),
2932
+ limit: import_zod2.z.number().int().positive().optional(),
2933
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2934
+ deep: import_zod2.z.boolean().optional()
2935
+ });
2936
+ var SymbolField = import_zod2.z.enum(["id", "file_id", "type", "name", "text", "meta", "description", "is_exported", "state", "error"]);
2937
+ var SymbolType = import_zod2.z.enum(["function", "class", "class_method", "class_property", "variable", "type"]);
2938
+ var SymbolState = import_zod2.z.enum(["to_link", "to_describe", "ready"]);
2939
+ var SymbolSearchOptions = import_zod2.z.object({
2940
+ select: import_zod2.z.array(SymbolField).optional(),
2941
+ limit: import_zod2.z.number().int().positive().optional(),
2942
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2943
+ where: import_zod2.z.object({
2944
+ id: import_zod2.z.number().optional(),
2945
+ file_id: import_zod2.z.number().optional(),
2946
+ type: import_zod2.z.union([SymbolType, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
2947
+ name: StringFilter.optional(),
2948
+ text: StringFilter.optional(),
2949
+ meta: StringFilter.optional(),
2950
+ description: StringFilter.optional(),
2951
+ is_exported: import_zod2.z.boolean().optional(),
2952
+ state: import_zod2.z.union([SymbolState, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
2953
+ error: StringFilter.optional()
2954
+ }).optional(),
2955
+ order_by: import_zod2.z.tuple([SymbolField, OrderDirection]).optional()
2956
+ });
2957
+ var SymbolRelationOptions = import_zod2.z.object({
2958
+ select: import_zod2.z.array(SymbolField).optional(),
2959
+ limit: import_zod2.z.number().int().positive().optional(),
2960
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2961
+ deep: import_zod2.z.boolean().optional()
2962
+ });
2963
+ var DirectoryField = import_zod2.z.enum(["id", "parent_id", "path", "description", "state", "error"]);
2964
+ var DirectoryState = import_zod2.z.enum(["to_describe", "ready"]);
2965
+ var DirectorySearchOptions = import_zod2.z.object({
2966
+ select: import_zod2.z.array(DirectoryField).optional(),
2967
+ limit: import_zod2.z.number().int().positive().optional(),
2968
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2969
+ where: import_zod2.z.object({
2970
+ id: import_zod2.z.number().optional(),
2971
+ parent_id: import_zod2.z.number().optional(),
2972
+ path: StringFilter.optional(),
2973
+ description: StringFilter.optional(),
2974
+ state: import_zod2.z.union([DirectoryState, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
2975
+ error: StringFilter.optional()
2976
+ }).optional(),
2977
+ order_by: import_zod2.z.tuple([DirectoryField, OrderDirection]).optional()
2978
+ });
2979
+ var DirectoryRelationOptions = import_zod2.z.object({
2980
+ select: import_zod2.z.array(DirectoryField).optional(),
2981
+ limit: import_zod2.z.number().int().positive().optional(),
2982
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2983
+ deep: import_zod2.z.boolean().optional()
2984
+ });
2985
+ var DependencyField = import_zod2.z.enum(["id", "package", "subpath", "name", "version", "github_repo", "is_builtin", "description", "state", "error"]);
2986
+ var DependencyState = import_zod2.z.enum(["to_describe", "ready"]);
2987
+ var DependencySearchOptions = import_zod2.z.object({
2988
+ select: import_zod2.z.array(DependencyField).optional(),
2989
+ limit: import_zod2.z.number().int().positive().optional(),
2990
+ offset: import_zod2.z.number().int().nonnegative().optional(),
2991
+ where: import_zod2.z.object({
2992
+ id: import_zod2.z.number().optional(),
2993
+ package: StringFilter.optional(),
2994
+ subpath: StringFilter.optional(),
2995
+ name: StringFilter.optional(),
2996
+ version: StringFilter.optional(),
2997
+ github_repo: StringFilter.optional(),
2998
+ is_builtin: import_zod2.z.boolean().optional(),
2999
+ description: StringFilter.optional(),
3000
+ state: import_zod2.z.union([DependencyState, import_zod2.z.object({ contains: import_zod2.z.string() })]).optional(),
3001
+ error: StringFilter.optional()
3002
+ }).optional(),
3003
+ order_by: import_zod2.z.tuple([DependencyField, OrderDirection]).optional()
3004
+ });
3005
+ var DependencySelectOptions = import_zod2.z.object({
3006
+ select: import_zod2.z.array(DependencyField).optional(),
3007
+ limit: import_zod2.z.number().int().positive().optional(),
3008
+ offset: import_zod2.z.number().int().nonnegative().optional()
3009
+ });
3010
+
3011
+ // src/cli/commands/files/search.ts
3010
3012
  var search13 = new import_commander5.Command("search");
3011
3013
  search13.description("Search files with JSON options");
3012
3014
  search13.argument("<options>", "JSON options for search");
3013
- search13.action(async (options_json) => {
3014
- const wiki = await load_wiki();
3015
+ search13.action(async (...args) => {
3016
+ const [options_json] = args;
3017
+ const wiki = await load_wiki(get_db_path(...args));
3015
3018
  const options = parse_options(options_json, FileSearchOptions, "files search");
3016
3019
  const results = wiki.files.search(options);
3017
3020
  env.log(JSON.stringify(results, null, 2));
@@ -3024,8 +3027,9 @@ var set_description5 = new import_commander6.Command("set-description");
3024
3027
  set_description5.description("Set description for a file");
3025
3028
  set_description5.argument("<file-id>", "File ID");
3026
3029
  set_description5.argument("<markdown-file>", "Path to markdown file");
3027
- set_description5.action(async (id, file) => {
3028
- const wiki = await load_wiki();
3030
+ set_description5.action(async (...args) => {
3031
+ const [id, file] = args;
3032
+ const wiki = await load_wiki(get_db_path(...args));
3029
3033
  try {
3030
3034
  const content = (0, import_node_fs3.readFileSync)(file, "utf-8");
3031
3035
  wiki.files.set_description(Number(id), content);
@@ -3042,8 +3046,9 @@ var imported_by_file2 = new import_commander7.Command("imported-by-file");
3042
3046
  imported_by_file2.description("Files imported by the given file");
3043
3047
  imported_by_file2.argument("<file-id>", "File ID");
3044
3048
  imported_by_file2.argument("<options>", "JSON options");
3045
- imported_by_file2.action(async (file_id, options_json) => {
3046
- const wiki = await load_wiki();
3049
+ imported_by_file2.action(async (...args) => {
3050
+ const [file_id, options_json] = args;
3051
+ const wiki = await load_wiki(get_db_path(...args));
3047
3052
  const options = parse_options(options_json, FileRelationOptions, "files imported-by-file");
3048
3053
  const results = wiki.files.imported_by_file(Number(file_id), options);
3049
3054
  env.log(JSON.stringify(results, null, 2));
@@ -3055,8 +3060,9 @@ var importing_file2 = new import_commander8.Command("importing-file");
3055
3060
  importing_file2.description("Files importing the given file");
3056
3061
  importing_file2.argument("<file-id>", "File ID");
3057
3062
  importing_file2.argument("<options>", "JSON options");
3058
- importing_file2.action(async (file_id, options_json) => {
3059
- const wiki = await load_wiki();
3063
+ importing_file2.action(async (...args) => {
3064
+ const [file_id, options_json] = args;
3065
+ const wiki = await load_wiki(get_db_path(...args));
3060
3066
  const options = parse_options(options_json, FileRelationOptions, "files importing-file");
3061
3067
  const results = wiki.files.importing_file(Number(file_id), options);
3062
3068
  env.log(JSON.stringify(results, null, 2));
@@ -3068,8 +3074,9 @@ var importing_dependency2 = new import_commander9.Command("importing-dependency"
3068
3074
  importing_dependency2.description("Files importing the given dependency");
3069
3075
  importing_dependency2.argument("<dep-id>", "Dependency ID");
3070
3076
  importing_dependency2.argument("<options>", "JSON options");
3071
- importing_dependency2.action(async (dep_id, options_json) => {
3072
- const wiki = await load_wiki();
3077
+ importing_dependency2.action(async (...args) => {
3078
+ const [dep_id, options_json] = args;
3079
+ const wiki = await load_wiki(get_db_path(...args));
3073
3080
  const options = parse_options(options_json, FileRelationOptions, "files importing-dependency");
3074
3081
  const results = wiki.files.importing_dependency(Number(dep_id), options);
3075
3082
  env.log(JSON.stringify(results, null, 2));
@@ -3122,8 +3129,9 @@ var import_commander11 = require("commander");
3122
3129
  var get7 = new import_commander11.Command("get");
3123
3130
  get7.description("Get a symbol by ID");
3124
3131
  get7.argument("<id>", "Symbol ID");
3125
- get7.action(async (id) => {
3126
- const wiki = await load_wiki();
3132
+ get7.action(async (...args) => {
3133
+ const [id] = args;
3134
+ const wiki = await load_wiki(get_db_path(...args));
3127
3135
  const symbol = wiki.symbols.get(Number(id));
3128
3136
  env.log(JSON.stringify(symbol, null, 2));
3129
3137
  });
@@ -3133,8 +3141,9 @@ var import_commander12 = require("commander");
3133
3141
  var search14 = new import_commander12.Command("search");
3134
3142
  search14.description("Search symbols with JSON options");
3135
3143
  search14.argument("<options>", "JSON options");
3136
- search14.action(async (options_json) => {
3137
- const wiki = await load_wiki();
3144
+ search14.action(async (...args) => {
3145
+ const [options_json] = args;
3146
+ const wiki = await load_wiki(get_db_path(...args));
3138
3147
  const options = parse_options(options_json, SymbolSearchOptions, "symbols search");
3139
3148
  const results = wiki.symbols.search(options);
3140
3149
  env.log(JSON.stringify(results, null, 2));
@@ -3147,8 +3156,9 @@ var set_description6 = new import_commander13.Command("set-description");
3147
3156
  set_description6.description("Set description for a symbol");
3148
3157
  set_description6.argument("<symbol-id>", "Symbol ID");
3149
3158
  set_description6.argument("<markdown-file>", "Path to markdown file");
3150
- set_description6.action(async (id, file) => {
3151
- const wiki = await load_wiki();
3159
+ set_description6.action(async (...args) => {
3160
+ const [id, file] = args;
3161
+ const wiki = await load_wiki(get_db_path(...args));
3152
3162
  try {
3153
3163
  const content = (0, import_node_fs4.readFileSync)(file, "utf-8");
3154
3164
  wiki.symbols.set_description(Number(id), content);
@@ -3165,8 +3175,9 @@ var referencing_symbol2 = new import_commander14.Command("referencing-symbol");
3165
3175
  referencing_symbol2.description("Symbols referencing the given symbol");
3166
3176
  referencing_symbol2.argument("<symbol-id>", "Symbol ID");
3167
3177
  referencing_symbol2.argument("<options>", "JSON options");
3168
- referencing_symbol2.action(async (symbol_id, options_json) => {
3169
- const wiki = await load_wiki();
3178
+ referencing_symbol2.action(async (...args) => {
3179
+ const [symbol_id, options_json] = args;
3180
+ const wiki = await load_wiki(get_db_path(...args));
3170
3181
  const options = parse_options(options_json, SymbolRelationOptions, "symbols referencing-symbol");
3171
3182
  const results = wiki.symbols.referencing_symbol(Number(symbol_id), options);
3172
3183
  env.log(JSON.stringify(results, null, 2));
@@ -3178,8 +3189,9 @@ var referenced_by_symbol2 = new import_commander15.Command("referenced-by-symbol
3178
3189
  referenced_by_symbol2.description("Symbols referenced by the given symbol");
3179
3190
  referenced_by_symbol2.argument("<symbol-id>", "Symbol ID");
3180
3191
  referenced_by_symbol2.argument("<options>", "JSON options");
3181
- referenced_by_symbol2.action(async (symbol_id, options_json) => {
3182
- const wiki = await load_wiki();
3192
+ referenced_by_symbol2.action(async (...args) => {
3193
+ const [symbol_id, options_json] = args;
3194
+ const wiki = await load_wiki(get_db_path(...args));
3183
3195
  const options = parse_options(options_json, SymbolRelationOptions, "symbols referenced-by-symbol");
3184
3196
  const results = wiki.symbols.referenced_by_symbol(Number(symbol_id), options);
3185
3197
  env.log(JSON.stringify(results, null, 2));
@@ -3191,8 +3203,9 @@ var using_dependency4 = new import_commander16.Command("using-dependency");
3191
3203
  using_dependency4.description("Symbols using the given dependency");
3192
3204
  using_dependency4.argument("<dep-id>", "Dependency ID");
3193
3205
  using_dependency4.argument("<options>", "JSON options");
3194
- using_dependency4.action(async (dep_id, options_json) => {
3195
- const wiki = await load_wiki();
3206
+ using_dependency4.action(async (...args) => {
3207
+ const [dep_id, options_json] = args;
3208
+ const wiki = await load_wiki(get_db_path(...args));
3196
3209
  const options = parse_options(options_json, SymbolRelationOptions, "symbols using-dependency");
3197
3210
  const results = wiki.symbols.using_dependency(Number(dep_id), options);
3198
3211
  env.log(JSON.stringify(results, null, 2));
@@ -3245,8 +3258,9 @@ var import_commander18 = require("commander");
3245
3258
  var get8 = new import_commander18.Command("get");
3246
3259
  get8.description("Get a directory by ID");
3247
3260
  get8.argument("<id>", "Directory ID");
3248
- get8.action(async (id) => {
3249
- const wiki = await load_wiki();
3261
+ get8.action(async (...args) => {
3262
+ const [id] = args;
3263
+ const wiki = await load_wiki(get_db_path(...args));
3250
3264
  const directory = wiki.directories.get(Number(id));
3251
3265
  env.log(JSON.stringify(directory, null, 2));
3252
3266
  });
@@ -3256,8 +3270,9 @@ var import_commander19 = require("commander");
3256
3270
  var search15 = new import_commander19.Command("search");
3257
3271
  search15.description("Search directories with JSON options");
3258
3272
  search15.argument("<options>", "JSON options");
3259
- search15.action(async (options_json) => {
3260
- const wiki = await load_wiki();
3273
+ search15.action(async (...args) => {
3274
+ const [options_json] = args;
3275
+ const wiki = await load_wiki(get_db_path(...args));
3261
3276
  const options = parse_options(options_json, DirectorySearchOptions, "directories search");
3262
3277
  const results = wiki.directories.search(options);
3263
3278
  env.log(JSON.stringify(results, null, 2));
@@ -3270,8 +3285,9 @@ var set_description7 = new import_commander20.Command("set-description");
3270
3285
  set_description7.description("Set description for a directory");
3271
3286
  set_description7.argument("<directory-id>", "Directory ID");
3272
3287
  set_description7.argument("<markdown-file>", "Path to markdown file");
3273
- set_description7.action(async (id, file) => {
3274
- const wiki = await load_wiki();
3288
+ set_description7.action(async (...args) => {
3289
+ const [id, file] = args;
3290
+ const wiki = await load_wiki(get_db_path(...args));
3275
3291
  try {
3276
3292
  const content = (0, import_node_fs5.readFileSync)(file, "utf-8");
3277
3293
  wiki.directories.set_description(Number(id), content);
@@ -3288,8 +3304,9 @@ var children2 = new import_commander21.Command("children");
3288
3304
  children2.description("Child directories of the given directory");
3289
3305
  children2.argument("<parent-id>", "Parent directory ID");
3290
3306
  children2.argument("<options>", "JSON options");
3291
- children2.action(async (parent_id, options_json) => {
3292
- const wiki = await load_wiki();
3307
+ children2.action(async (...args) => {
3308
+ const [parent_id, options_json] = args;
3309
+ const wiki = await load_wiki(get_db_path(...args));
3293
3310
  const options = parse_options(options_json, DirectoryRelationOptions, "directories children");
3294
3311
  const results = wiki.directories.children(Number(parent_id), options);
3295
3312
  env.log(JSON.stringify(results, null, 2));
@@ -3301,8 +3318,9 @@ var files4 = new import_commander22.Command("files");
3301
3318
  files4.description("Files in the given directory");
3302
3319
  files4.argument("<directory-id>", "Directory ID");
3303
3320
  files4.argument("<options>", "JSON options");
3304
- files4.action(async (directory_id, options_json) => {
3305
- const wiki = await load_wiki();
3321
+ files4.action(async (...args) => {
3322
+ const [directory_id, options_json] = args;
3323
+ const wiki = await load_wiki(get_db_path(...args));
3306
3324
  const options = parse_options(options_json, FileRelationOptions, "directories files");
3307
3325
  const results = wiki.directories.files(Number(directory_id), options);
3308
3326
  env.log(JSON.stringify(results, null, 2));
@@ -3354,8 +3372,9 @@ var import_commander24 = require("commander");
3354
3372
  var get9 = new import_commander24.Command("get");
3355
3373
  get9.description("Get a dependency by ID");
3356
3374
  get9.argument("<id>", "Dependency ID");
3357
- get9.action(async (id) => {
3358
- const wiki = await load_wiki();
3375
+ get9.action(async (...args) => {
3376
+ const [id] = args;
3377
+ const wiki = await load_wiki(get_db_path(...args));
3359
3378
  const dependency = wiki.dependencies.get(Number(id));
3360
3379
  env.log(JSON.stringify(dependency, null, 2));
3361
3380
  });
@@ -3365,8 +3384,9 @@ var import_commander25 = require("commander");
3365
3384
  var search16 = new import_commander25.Command("search");
3366
3385
  search16.description("Search dependencies with JSON options");
3367
3386
  search16.argument("<options>", "JSON options");
3368
- search16.action(async (options_json) => {
3369
- const wiki = await load_wiki();
3387
+ search16.action(async (...args) => {
3388
+ const [options_json] = args;
3389
+ const wiki = await load_wiki(get_db_path(...args));
3370
3390
  const options = parse_options(options_json, DependencySearchOptions, "dependencies search");
3371
3391
  const results = wiki.dependencies.search(options);
3372
3392
  env.log(JSON.stringify(results, null, 2));
@@ -3379,8 +3399,9 @@ var set_description8 = new import_commander26.Command("set-description");
3379
3399
  set_description8.description("Set description for a dependency");
3380
3400
  set_description8.argument("<dependency-id>", "Dependency ID");
3381
3401
  set_description8.argument("<markdown-file>", "Path to markdown file");
3382
- set_description8.action(async (id, file) => {
3383
- const wiki = await load_wiki();
3402
+ set_description8.action(async (...args) => {
3403
+ const [id, file] = args;
3404
+ const wiki = await load_wiki(get_db_path(...args));
3384
3405
  try {
3385
3406
  const content = (0, import_node_fs6.readFileSync)(file, "utf-8");
3386
3407
  wiki.dependencies.set_description(Number(id), content);
@@ -3397,8 +3418,9 @@ var used_by_file3 = new import_commander27.Command("used-by-file");
3397
3418
  used_by_file3.description("Dependencies used by the given file");
3398
3419
  used_by_file3.argument("<file-id>", "File ID");
3399
3420
  used_by_file3.argument("<options>", "JSON options");
3400
- used_by_file3.action(async (file_id, options_json) => {
3401
- const wiki = await load_wiki();
3421
+ used_by_file3.action(async (...args) => {
3422
+ const [file_id, options_json] = args;
3423
+ const wiki = await load_wiki(get_db_path(...args));
3402
3424
  const options = parse_options(options_json, DependencySelectOptions, "dependencies used-by-file");
3403
3425
  const results = wiki.dependencies.used_by_file(Number(file_id), options);
3404
3426
  env.log(JSON.stringify(results, null, 2));
@@ -3410,8 +3432,9 @@ var used_by_symbol3 = new import_commander28.Command("used-by-symbol");
3410
3432
  used_by_symbol3.description("Dependencies used by the given symbol");
3411
3433
  used_by_symbol3.argument("<symbol-id>", "Symbol ID");
3412
3434
  used_by_symbol3.argument("<options>", "JSON options");
3413
- used_by_symbol3.action(async (symbol_id, options_json) => {
3414
- const wiki = await load_wiki();
3435
+ used_by_symbol3.action(async (...args) => {
3436
+ const [symbol_id, options_json] = args;
3437
+ const wiki = await load_wiki(get_db_path(...args));
3415
3438
  const options = parse_options(options_json, DependencySelectOptions, "dependencies used-by-symbol");
3416
3439
  const results = wiki.dependencies.used_by_symbol(Number(symbol_id), options);
3417
3440
  env.log(JSON.stringify(results, null, 2));
@@ -3460,6 +3483,7 @@ var commands = [update7, status, describe, files3, symbols3, directories3, depen
3460
3483
  async function run(argv) {
3461
3484
  const program = new import_commander30.Command();
3462
3485
  program.name("codewiki").description("Describe and explore TypeScript codebases").version("0.0.1");
3486
+ program.option("--db <path>", "Database location", "./wiki.db");
3463
3487
  for (const cmd of commands) program.addCommand(cmd);
3464
3488
  return program.parseAsync(argv, { from: "user" });
3465
3489
  }