@neuralsea/workspace-indexer 0.4.0 → 0.4.1

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.
@@ -1,3 +1,10 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
1
8
  // src/progress.ts
2
9
  function toHandler(progress) {
3
10
  if (!progress) return null;
@@ -2764,6 +2771,7 @@ var betterSqlite3Adapter = {
2764
2771
 
2765
2772
  // src/store/workspace/sqlJsAdapter.ts
2766
2773
  import fs12 from "fs";
2774
+ import { createRequire as createRequire2 } from "module";
2767
2775
  import path15 from "path";
2768
2776
  function detectFts5Support2(db) {
2769
2777
  try {
@@ -2844,20 +2852,37 @@ var SqlJsDbAdapter = class {
2844
2852
  this.db.close();
2845
2853
  }
2846
2854
  };
2855
+ function defaultLocateFile(file) {
2856
+ const spec = `sql.js/dist/${file}`;
2857
+ try {
2858
+ if (typeof __require === "function" && typeof __require.resolve === "function") {
2859
+ return __require.resolve(spec);
2860
+ }
2861
+ } catch {
2862
+ }
2863
+ try {
2864
+ const req = createRequire2(import.meta.url);
2865
+ return req.resolve(spec);
2866
+ } catch {
2867
+ return file;
2868
+ }
2869
+ }
2847
2870
  async function sqlJsAdapter(opts = {}) {
2848
2871
  let init;
2849
2872
  try {
2850
- const mod = await import("./sql-wasm-LT2WFO7Q.js");
2873
+ const mod = await import("sql.js");
2851
2874
  init = mod?.default ?? mod;
2852
2875
  } catch (e) {
2853
2876
  throw new Error(`sqlJsAdapter requires optional dependency 'sql.js' (install it to use this adapter): ${String(e?.message ?? e)}`);
2854
2877
  }
2855
- const SQL = await init({ locateFile: opts.locateFile, wasmBinary: opts.wasmBinary });
2878
+ const SQL = await init({
2879
+ locateFile: opts.locateFile ?? defaultLocateFile,
2880
+ wasmBinary: opts.wasmBinary
2881
+ });
2856
2882
  return {
2857
2883
  open(dbPath) {
2858
- const abs = path15.resolve(dbPath);
2859
- const exists = fs12.existsSync(abs);
2860
- const bytes = exists ? new Uint8Array(fs12.readFileSync(abs)) : void 0;
2884
+ const abs = dbPath === ":memory:" ? ":memory:" : path15.resolve(dbPath);
2885
+ const bytes = abs !== ":memory:" && fs12.existsSync(abs) ? new Uint8Array(fs12.readFileSync(abs)) : void 0;
2861
2886
  const db = bytes ? new SQL.Database(bytes) : new SQL.Database();
2862
2887
  return new SqlJsDbAdapter(db, abs);
2863
2888
  }
@@ -3380,7 +3405,7 @@ var WorkspaceStore = class {
3380
3405
  };
3381
3406
 
3382
3407
  // src/graph/neo4j.ts
3383
- import { createRequire as createRequire2 } from "module";
3408
+ import { createRequire as createRequire3 } from "module";
3384
3409
  async function runSession(driver, database, fn) {
3385
3410
  const session = driver.session(database ? { database } : void 0);
3386
3411
  try {
@@ -3464,13 +3489,13 @@ var Neo4jGraphStore = class {
3464
3489
  async runMigrations() {
3465
3490
  const startedAt = Date.now();
3466
3491
  this.opStart("migrations");
3467
- const { Repo, File, Symbol, External } = this.labels();
3492
+ const { Repo, File, Symbol: Symbol2, External } = this.labels();
3468
3493
  let v = await this.getSchemaVersion();
3469
3494
  if (v < 1) {
3470
3495
  await runSession(this.driver, this.cfg.database, async (s) => {
3471
3496
  const stmts = [
3472
3497
  `CREATE CONSTRAINT ${Repo}_repo_id IF NOT EXISTS FOR (r:${Repo}) REQUIRE r.repo_id IS UNIQUE`,
3473
- `CREATE CONSTRAINT ${Symbol}_id IF NOT EXISTS FOR (s:${Symbol}) REQUIRE s.id IS UNIQUE`,
3498
+ `CREATE CONSTRAINT ${Symbol2}_id IF NOT EXISTS FOR (s:${Symbol2}) REQUIRE s.id IS UNIQUE`,
3474
3499
  `CREATE CONSTRAINT ${External}_key IF NOT EXISTS FOR (e:${External}) REQUIRE e.key IS UNIQUE`,
3475
3500
  `CREATE CONSTRAINT ${File}_key IF NOT EXISTS FOR (f:${File}) REQUIRE f.key IS UNIQUE`
3476
3501
  ];
@@ -3487,7 +3512,7 @@ var Neo4jGraphStore = class {
3487
3512
  if (v < 2) {
3488
3513
  await runSession(this.driver, this.cfg.database, async (s) => {
3489
3514
  const stmts = [
3490
- `CREATE INDEX ${Symbol}_repo_path IF NOT EXISTS FOR (s:${Symbol}) ON (s.repo_id, s.path)`,
3515
+ `CREATE INDEX ${Symbol2}_repo_path IF NOT EXISTS FOR (s:${Symbol2}) ON (s.repo_id, s.path)`,
3491
3516
  `CREATE INDEX ${File}_repo IF NOT EXISTS FOR (f:${File}) ON (f.repo_id)`,
3492
3517
  `CREATE INDEX ${External}_repo IF NOT EXISTS FOR (e:${External}) ON (e.repo_id)`
3493
3518
  ];
@@ -3509,7 +3534,7 @@ var Neo4jGraphStore = class {
3509
3534
  async setRepoHead(args) {
3510
3535
  const startedAt = Date.now();
3511
3536
  this.opStart("setRepoHead", { repoId: args.repoId });
3512
- const { Repo, File, Symbol, External } = this.labels();
3537
+ const { Repo, File, Symbol: Symbol2, External } = this.labels();
3513
3538
  const { repoId, repoRoot, commit, branch } = args;
3514
3539
  await runSession(this.driver, this.cfg.database, async (s) => {
3515
3540
  const prev = await s.run(
@@ -3522,7 +3547,7 @@ var Neo4jGraphStore = class {
3522
3547
  const prevCommit = prev?.records?.[0]?.get?.("commit");
3523
3548
  const prevCommitStr = typeof prevCommit === "string" ? prevCommit : `${prevCommit ?? ""}`;
3524
3549
  if (prevCommitStr && prevCommitStr !== commit) {
3525
- await s.run(`MATCH (s:${Symbol} {repo_id:$repoId}) DETACH DELETE s`, { repoId });
3550
+ await s.run(`MATCH (s:${Symbol2} {repo_id:$repoId}) DETACH DELETE s`, { repoId });
3526
3551
  await s.run(
3527
3552
  `MATCH (f:${File} {repo_id:$repoId})
3528
3553
  DETACH DELETE f`,
@@ -3544,9 +3569,9 @@ var Neo4jGraphStore = class {
3544
3569
  async deleteFile(args) {
3545
3570
  const startedAt = Date.now();
3546
3571
  this.opStart("deleteFile", { repoId: args.repoId, path: args.path });
3547
- const { File, Symbol } = this.labels();
3572
+ const { File, Symbol: Symbol2 } = this.labels();
3548
3573
  await runSession(this.driver, this.cfg.database, async (s) => {
3549
- await s.run(`MATCH (s:${Symbol} {repo_id:$repoId, path:$path}) DETACH DELETE s`, args);
3574
+ await s.run(`MATCH (s:${Symbol2} {repo_id:$repoId, path:$path}) DETACH DELETE s`, args);
3550
3575
  await s.run(`MATCH (f:${File} {repo_id:$repoId, path:$path}) DETACH DELETE f`, args);
3551
3576
  });
3552
3577
  this.opDone("deleteFile", startedAt, { repoId: args.repoId, path: args.path });
@@ -3554,14 +3579,14 @@ var Neo4jGraphStore = class {
3554
3579
  async replaceOutgoingSymbolEdgesFromFile(args) {
3555
3580
  const startedAt = Date.now();
3556
3581
  this.opStart("replaceOutgoingSymbolEdgesFromFile", { repoId: args.repoId, path: args.fromPath });
3557
- const { Symbol } = this.labels();
3582
+ const { Symbol: Symbol2 } = this.labels();
3558
3583
  const kinds = args.edges.length > 0 ? Array.from(new Set(args.edges.map((e) => e.kind))) : ["definition", "reference", "implementation", "typeDefinition"];
3559
3584
  const keep = args.edges.map((e) => `${e.fromId}|${e.kind}|${e.toId}`);
3560
3585
  await runSession(this.driver, this.cfg.database, async (s) => {
3561
3586
  await s.run(
3562
3587
  `UNWIND $edges AS e
3563
- MERGE (a:${Symbol} {id:e.fromId})
3564
- MERGE (b:${Symbol} {id:e.toId})
3588
+ MERGE (a:${Symbol2} {id:e.fromId})
3589
+ MERGE (b:${Symbol2} {id:e.toId})
3565
3590
  ON CREATE SET b.repo_id=$repoId, b.path=coalesce(e.toPath, '')
3566
3591
  SET b.repo_id = coalesce(b.repo_id, $repoId),
3567
3592
  b.path = CASE WHEN coalesce(b.path, '') = '' AND e.toPath IS NOT NULL THEN e.toPath ELSE b.path END
@@ -3570,7 +3595,7 @@ var Neo4jGraphStore = class {
3570
3595
  ).catch(() => void 0);
3571
3596
  if (keep.length === 0) {
3572
3597
  await s.run(
3573
- `MATCH (a:${Symbol} {repo_id:$repoId, path:$fromPath})-[r:SYMBOL_EDGE]->()
3598
+ `MATCH (a:${Symbol2} {repo_id:$repoId, path:$fromPath})-[r:SYMBOL_EDGE]->()
3574
3599
  WHERE r.kind IN $kinds
3575
3600
  DELETE r`,
3576
3601
  { repoId: args.repoId, fromPath: args.fromPath, kinds }
@@ -3578,7 +3603,7 @@ var Neo4jGraphStore = class {
3578
3603
  return;
3579
3604
  }
3580
3605
  await s.run(
3581
- `MATCH (a:${Symbol} {repo_id:$repoId, path:$fromPath})-[r:SYMBOL_EDGE]->(b:${Symbol})
3606
+ `MATCH (a:${Symbol2} {repo_id:$repoId, path:$fromPath})-[r:SYMBOL_EDGE]->(b:${Symbol2})
3582
3607
  WHERE r.kind IN $kinds
3583
3608
  AND NOT (a.id + '|' + r.kind + '|' + b.id) IN $keep
3584
3609
  DELETE r`,
@@ -3590,7 +3615,7 @@ var Neo4jGraphStore = class {
3590
3615
  async replaceFileGraph(update) {
3591
3616
  const startedAt = Date.now();
3592
3617
  this.opStart("replaceFileGraph", { repoId: update.repoId, path: update.path });
3593
- const { Repo, File, Symbol, External } = this.labels();
3618
+ const { Repo, File, Symbol: Symbol2, External } = this.labels();
3594
3619
  const symbols = update.symbols.map((s) => ({
3595
3620
  id: s.id,
3596
3621
  name: s.name,
@@ -3650,7 +3675,7 @@ var Neo4jGraphStore = class {
3650
3675
  await s.run(
3651
3676
  `MATCH (f:${File} {repo_id:$repoId, path:$path})
3652
3677
  UNWIND $symbols AS s
3653
- MERGE (n:${Symbol} {id:s.id})
3678
+ MERGE (n:${Symbol2} {id:s.id})
3654
3679
  ON CREATE SET n.repo_id=$repoId
3655
3680
  SET n.repo_root=$repoRoot, n.path=$path,
3656
3681
  n.language=s.language, n.name=s.name, n.kind=s.kind,
@@ -3661,13 +3686,13 @@ var Neo4jGraphStore = class {
3661
3686
  );
3662
3687
  const ids = symbols.map((s2) => s2.id);
3663
3688
  await s.run(
3664
- `MATCH (f:${File} {repo_id:$repoId, path:$path})-[r:CONTAINS]->(n:${Symbol})
3689
+ `MATCH (f:${File} {repo_id:$repoId, path:$path})-[r:CONTAINS]->(n:${Symbol2})
3665
3690
  WHERE NOT n.id IN $ids
3666
3691
  DELETE r`,
3667
3692
  { repoId: update.repoId, path: update.path, ids }
3668
3693
  ).catch(() => void 0);
3669
3694
  await s.run(
3670
- `MATCH (n:${Symbol} {repo_id:$repoId, path:$path})
3695
+ `MATCH (n:${Symbol2} {repo_id:$repoId, path:$path})
3671
3696
  WHERE NOT n.id IN $ids
3672
3697
  DETACH DELETE n`,
3673
3698
  { repoId: update.repoId, path: update.path, ids }
@@ -3678,21 +3703,21 @@ var Neo4jGraphStore = class {
3678
3703
  { repoId: update.repoId, path: update.path }
3679
3704
  ).catch(() => void 0);
3680
3705
  await s.run(
3681
- `MATCH (n:${Symbol} {repo_id:$repoId, path:$path}) DETACH DELETE n`,
3706
+ `MATCH (n:${Symbol2} {repo_id:$repoId, path:$path}) DETACH DELETE n`,
3682
3707
  { repoId: update.repoId, path: update.path }
3683
3708
  ).catch(() => void 0);
3684
3709
  }
3685
3710
  if (symbolEdges.length) {
3686
3711
  await s.run(
3687
3712
  `UNWIND $edges AS e
3688
- MERGE (a:${Symbol} {id:e.fromId})
3689
- MERGE (b:${Symbol} {id:e.toId})
3713
+ MERGE (a:${Symbol2} {id:e.fromId})
3714
+ MERGE (b:${Symbol2} {id:e.toId})
3690
3715
  MERGE (a)-[:SYMBOL_EDGE {kind:e.kind}]->(b)`,
3691
3716
  { edges: symbolEdges }
3692
3717
  ).catch(() => void 0);
3693
3718
  if (managedSymbolEdgeKinds.length > 0) {
3694
3719
  await s.run(
3695
- `MATCH (a:${Symbol} {repo_id:$repoId, path:$path})-[r:SYMBOL_EDGE]->(b:${Symbol})
3720
+ `MATCH (a:${Symbol2} {repo_id:$repoId, path:$path})-[r:SYMBOL_EDGE]->(b:${Symbol2})
3696
3721
  WHERE r.kind IN $kinds
3697
3722
  AND NOT (a.id + '|' + r.kind + '|' + b.id) IN $keep
3698
3723
  DELETE r`,
@@ -3741,14 +3766,14 @@ var Neo4jGraphStore = class {
3741
3766
  async neighborFiles(args) {
3742
3767
  const startedAt = Date.now();
3743
3768
  this.opStart("neighborFiles");
3744
- const { File, Symbol } = this.labels();
3769
+ const { File, Symbol: Symbol2 } = this.labels();
3745
3770
  const limit = args.limit ?? 20;
3746
3771
  const kinds = args.kinds && args.kinds.length > 0 ? args.kinds : null;
3747
3772
  const rows = [];
3748
3773
  await runSession(this.driver, this.cfg.database, async (s) => {
3749
3774
  const res = await s.run(
3750
3775
  `UNWIND $seeds AS seed
3751
- MATCH (f:${File} {repo_id:seed.repoId, path:seed.path})-[:CONTAINS]->(a:${Symbol})-[e:SYMBOL_EDGE]->(b:${Symbol})<-[:CONTAINS]-(g:${File})
3776
+ MATCH (f:${File} {repo_id:seed.repoId, path:seed.path})-[:CONTAINS]->(a:${Symbol2})-[e:SYMBOL_EDGE]->(b:${Symbol2})<-[:CONTAINS]-(g:${File})
3752
3777
  WHERE (g.repo_id <> seed.repoId OR g.path <> seed.path)
3753
3778
  AND ($kinds IS NULL OR e.kind IN $kinds)
3754
3779
  RETURN g.repo_id AS repoId, g.path AS path, count(*) AS weight
@@ -3791,14 +3816,14 @@ var Neo4jGraphStore = class {
3791
3816
  async extractFileSubgraph(args) {
3792
3817
  const startedAt = Date.now();
3793
3818
  this.opStart("extractFileSubgraph");
3794
- const { File, Symbol } = this.labels();
3819
+ const { File, Symbol: Symbol2 } = this.labels();
3795
3820
  const limitEdges = args.limitEdges ?? 200;
3796
3821
  const nodes = /* @__PURE__ */ new Map();
3797
3822
  const edges = [];
3798
3823
  await runSession(this.driver, this.cfg.database, async (s) => {
3799
3824
  const res = await s.run(
3800
3825
  `UNWIND $seeds AS seed
3801
- MATCH (f:${File} {repo_id:seed.repoId, path:seed.path})-[:CONTAINS]->(a:${Symbol})-[e:SYMBOL_EDGE]->(b:${Symbol})<-[:CONTAINS]-(g:${File})
3826
+ MATCH (f:${File} {repo_id:seed.repoId, path:seed.path})-[:CONTAINS]->(a:${Symbol2})-[e:SYMBOL_EDGE]->(b:${Symbol2})<-[:CONTAINS]-(g:${File})
3802
3827
  RETURN f.repo_id AS fromRepoId, f.path AS fromPath, g.repo_id AS toRepoId, g.path AS toPath, e.kind AS kind
3803
3828
  LIMIT $limit`,
3804
3829
  { seeds: args.seeds, limit: limitEdges }
@@ -3821,7 +3846,7 @@ var Neo4jGraphStore = class {
3821
3846
  };
3822
3847
  async function createNeo4jGraphStore(cfg) {
3823
3848
  try {
3824
- const require2 = createRequire2(import.meta.url);
3849
+ const require2 = createRequire3(import.meta.url);
3825
3850
  const neo4j = require2("neo4j-driver");
3826
3851
  const driver = neo4j.driver(cfg.uri, neo4j.auth.basic(cfg.user, cfg.password));
3827
3852
  const store = new Neo4jGraphStore(driver, cfg);