@marginallyuseful/soll-native 0.0.0 → 0.5.0

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.
Files changed (3) hide show
  1. package/index.d.ts +115 -0
  2. package/index.js +75 -0
  3. package/package.json +16 -1
package/index.d.ts ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * TypeScript types for the @marginallyuseful/soll-native napi-rs addon.
3
+ *
4
+ * These mirror the Rust types defined in crates/napi/src/conversions.rs
5
+ * and the Soll class in crates/napi/src/graph_api.rs.
6
+ */
7
+
8
+ /** Options for building the import graph from a set of source files. */
9
+ export interface GraphOptions {
10
+ /** Workspace root directory (absolute path). */
11
+ root: string;
12
+ /**
13
+ * Explicit list of file paths to include in the graph.
14
+ * When empty, files are discovered automatically via git.
15
+ */
16
+ include: string[];
17
+ }
18
+
19
+ /** A file node in the affected set. */
20
+ export interface AffectedFile {
21
+ /** Git-root-relative file path. */
22
+ path: string;
23
+ }
24
+
25
+ /** A diagnostic message produced during graph building or resolution. */
26
+ export interface Diagnostic {
27
+ /** Machine-readable error code (e.g. 'ParseError', 'CycleDetected'). */
28
+ code: string;
29
+ /** Human-readable description of the issue. */
30
+ message: string;
31
+ /** File where the issue was found (if known). */
32
+ file?: string;
33
+ /** Suggestion for fixing the issue (if available). */
34
+ help?: string;
35
+ }
36
+
37
+ /** Result of a buildGraph() call. */
38
+ export interface GraphResult {
39
+ /** Number of file nodes in the built graph. */
40
+ fileCount: number;
41
+ /** Number of directed import edges in the graph. */
42
+ edgeCount: number;
43
+ /** Any diagnostics collected during parsing and resolution. */
44
+ diagnostics: Diagnostic[];
45
+ }
46
+
47
+ /**
48
+ * Result of an affected-set computation.
49
+ * Returned by getAffectedFiles().
50
+ */
51
+ export interface AffectedResult {
52
+ /**
53
+ * All files transitively affected by the changed files.
54
+ */
55
+ affectedFiles: AffectedFile[];
56
+ /** Any diagnostics collected during the computation. */
57
+ diagnostics: Diagnostic[];
58
+ }
59
+
60
+ /**
61
+ * Import graph engine for computing affected file sets.
62
+ *
63
+ * Construct with `new Soll(options)` to parse files and build
64
+ * the import graph, then call query methods to compute affected sets.
65
+ *
66
+ * Each instance is self-contained — no module-level state is shared.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const scope = new Soll({ root: '/repo', include: files });
71
+ * console.log(scope.graph.edgeCount);
72
+ * const affected = scope.getAffectedFiles(['src/utils.ts']);
73
+ * ```
74
+ */
75
+ export class Soll {
76
+ /** Builds the import graph from the provided options. */
77
+ constructor(options: GraphOptions);
78
+
79
+ /** Graph build statistics (file count, edge count, diagnostics). */
80
+ readonly graph: GraphResult;
81
+
82
+ /**
83
+ * Rebuilds the import graph incrementally for the given changed files.
84
+ *
85
+ * Re-runs the facts pipeline scoped to changedFiles and updates the internal
86
+ * graph state. Returns the new graph statistics. Call this in watch mode
87
+ * whenever the filesystem changes, before calling getAffectedFiles().
88
+ */
89
+ rebuild(changedFiles: string[]): GraphResult;
90
+
91
+ /** Returns all files transitively affected by changedFiles. */
92
+ getAffectedFiles(changedFiles: string[]): AffectedResult;
93
+
94
+ /** Returns all file paths in the graph. */
95
+ getFiles(): string[];
96
+ }
97
+
98
+ /**
99
+ * Returns the git repository root for a directory.
100
+ *
101
+ * Walks up from `dir` to find the `.git` directory, then returns the
102
+ * canonicalized working directory path. Throws if `dir` is not inside
103
+ * a git repository.
104
+ */
105
+ export function getGitRoot(dir: string): string;
106
+
107
+ /**
108
+ * Returns all files changed since the merge-base with the default branch.
109
+ *
110
+ * Combines committed changes (since merge-base with main/master), uncommitted
111
+ * changes (staged + unstaged), and untracked files. Returns absolute paths.
112
+ *
113
+ * When `baseBranch` is omitted, auto-detects the default branch (main or master).
114
+ */
115
+ export function getChangedFiles(root: string, baseBranch?: string): string[];
package/index.js ADDED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Platform-aware loader for the soll-napi native addon.
3
+ *
4
+ * Resolution order:
5
+ * 1. Prebuilt .node file co-located with this package (placed by build.mjs)
6
+ * 2. Debug build output under <workspace-root>/target/debug/
7
+ * 3. Release build output under <workspace-root>/target/release/
8
+ *
9
+ * If none are found, throws a descriptive error pointing to the build script.
10
+ */
11
+
12
+ const { join, resolve } = require("path");
13
+ const { existsSync } = require("fs");
14
+
15
+ const { platform, arch } = process;
16
+
17
+ /** Maps Node.js platform/arch to the expected .node filename. */
18
+ function platformFilename() {
19
+ const key = `${platform}-${arch}`;
20
+ const map = {
21
+ "darwin-arm64": "soll-napi.darwin-arm64.node",
22
+ "linux-x64": "soll-napi.linux-x64-gnu.node",
23
+ "linux-arm64": "soll-napi.linux-arm64-gnu.node",
24
+ "win32-x64": "soll-napi.win32-x64-msvc.node",
25
+ };
26
+ return map[key] || null;
27
+ }
28
+
29
+ /** Workspace root is 2 directories up from crates/napi/. */
30
+ const workspaceRoot = resolve(__dirname, "..", "..");
31
+
32
+ const filename = platformFilename();
33
+
34
+ const candidates = [
35
+ // 1. Prebuilt alongside this file (placed by `node build.mjs`)
36
+ filename ? join(__dirname, filename) : null,
37
+ // 2. Generic prebuilt name
38
+ join(__dirname, "soll-napi.node"),
39
+ // 3. Raw cargo debug output (macOS dylib)
40
+ join(workspaceRoot, "target", "debug", "libsoll_napi.dylib"),
41
+ // 4. Raw cargo debug output (Linux .so)
42
+ join(workspaceRoot, "target", "debug", "libsoll_napi.so"),
43
+ // 5. Raw cargo debug output (Windows .dll)
44
+ join(workspaceRoot, "target", "debug", "soll_napi.dll"),
45
+ // 6. Release builds
46
+ join(workspaceRoot, "target", "release", "libsoll_napi.dylib"),
47
+ join(workspaceRoot, "target", "release", "libsoll_napi.so"),
48
+ join(workspaceRoot, "target", "release", "soll_napi.dll"),
49
+ ].filter(Boolean);
50
+
51
+ let nativeBinding = null;
52
+ const errors = [];
53
+
54
+ for (const candidate of candidates) {
55
+ if (!existsSync(candidate)) continue;
56
+ try {
57
+ nativeBinding = require(candidate);
58
+ break;
59
+ } catch (err) {
60
+ errors.push(` ${candidate}: ${err.message}`);
61
+ }
62
+ }
63
+
64
+ if (!nativeBinding) {
65
+ const tried = candidates.map((c) => ` - ${c}`).join("\n");
66
+ const errDetail = errors.length ? `\nErrors:\n${errors.join("\n")}` : "";
67
+ throw new Error(
68
+ `@marginallyuseful/soll-native: could not load the native binary.\n` +
69
+ `Tried:\n${tried}\n\n` +
70
+ `Build it first:\n pnpm --filter @marginallyuseful/soll-native build\n` +
71
+ `(run from the workspace root)${errDetail}`
72
+ );
73
+ }
74
+
75
+ module.exports = nativeBinding;
package/package.json CHANGED
@@ -1 +1,16 @@
1
- {"name":"@marginallyuseful/soll-native","version":"0.0.0","description":"Placeholder","license":"LicenseRef-Proprietary"}
1
+ {
2
+ "name": "@marginallyuseful/soll-native",
3
+ "version": "0.5.0",
4
+ "main": "index.js",
5
+ "types": "index.d.ts",
6
+ "files": [
7
+ "index.js",
8
+ "index.d.ts"
9
+ ],
10
+ "optionalDependencies": {
11
+ "@marginallyuseful/soll-native-darwin-arm64": "0.5.0",
12
+ "@marginallyuseful/soll-native-linux-x64-gnu": "0.5.0",
13
+ "@marginallyuseful/soll-native-linux-arm64-gnu": "0.5.0"
14
+ },
15
+ "license": "LicenseRef-Proprietary"
16
+ }