@anysphere/file-service 0.0.0-c8c4f8fc → 0.0.0-c91bace5

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/index.d.ts CHANGED
@@ -3,18 +3,92 @@
3
3
 
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
- export class MerkleClient {
6
+ export const enum DiffType {
7
+ Insert = 'Insert',
8
+ Delete = 'Delete',
9
+ Equal = 'Equal'
10
+ }
11
+ export interface DiffChunk {
12
+ diffType: DiffType
13
+ text: string
14
+ }
15
+ export interface WalkDirConfig {
16
+ maxNumFiles: number
17
+ logFilePath?: string
18
+ }
19
+ export interface CommitData {
20
+ sha: string
21
+ date: number
22
+ message: string
23
+ author: string
24
+ parents: Array<string>
25
+ files: Array<CommitFile>
26
+ }
27
+ export interface CommitFile {
28
+ from: string
29
+ to: string
30
+ additions: number
31
+ deletions: number
32
+ status: CommitFileStatus
33
+ }
34
+ export const enum CommitFileStatus {
35
+ Added = 0,
36
+ Deleted = 1,
37
+ Modified = 2,
38
+ Renamed = 3
39
+ }
40
+ export const enum CommitChainGetFiles {
41
+ DoGetFiles = 0,
42
+ DontGetFiles = 1
43
+ }
44
+ export interface VerifyData {
45
+ commitTime: number
46
+ fileContent: string
47
+ filePath: string
48
+ }
49
+ export interface Candidate {
50
+ path: string
51
+ locations: Array<number>
52
+ weight: number
53
+ }
54
+ export declare class DiffClient {
55
+ constructor()
56
+ diff(text1: string, text2: string): Array<DiffChunk>
57
+ /**
58
+ * use https://docs.rs/diffmatchpatch/latest/diffmatchpatch/struct.DiffMatchPatch.html#method.diff_lines_to_chars
59
+ * then diff the chars.
60
+ * then convert back to lines.
61
+ *
62
+ * takes in two strings. splits based on newlines.
63
+ * returns diffs based on lines.
64
+ */
65
+ diffLines(text1: string, text2: string): Array<DiffChunk>
66
+ }
67
+ export declare class MerkleClient {
7
68
  constructor(absoluteRootDirectory: string)
8
- init(): Promise<void>
9
- computeMerkleTree(): Promise<void>
10
- updateFile(filePath: string): Promise<void>
11
- deleteFile(filePath: string): Promise<void>
69
+ computeFullTree(config: WalkDirConfig): Promise<void>
12
70
  getSubtreeHash(relativePath: string): Promise<string>
13
71
  getNumEmbeddableFiles(): Promise<number>
72
+ getImportantPaths(k: number): Promise<Array<string>>
14
73
  getAllFiles(): Promise<Array<string>>
15
74
  getAllDirFilesToEmbed(absoluteFilePath: string): Promise<Array<string>>
16
- getNextFileToEmbed(): Promise<Array<string>>
17
- getSpline(absoluteFilePath: string): Promise<Array<string>>
18
- getHashesForFiles(files: Array<string>): Promise<Array<string>>
19
- updateRootDirectory(rootDirectory: string): void
75
+ onDidCreate(absoluteFilePath: string): void
76
+ onDidChange(absoluteFilePath: string): void
77
+ onDidDelete(absoluteFilePath: string): void
78
+ }
79
+ export declare class GitClient {
80
+ constructor(absoluteRootDirectory: string)
81
+ getTotalCommitCount(): Promise<number>
82
+ getCommitVerifyData(commit: string): Promise<VerifyData>
83
+ throwIfCommitDoesntExist(rootSha: string): Promise<void>
84
+ getVerifyCommit(): Promise<string>
85
+ getRepoHeadSha(): Promise<string | null>
86
+ getCommitChain(hash: string, depth: number, getFiles: CommitChainGetFiles): Promise<Array<CommitData>>
87
+ }
88
+ export declare class GitFile {
89
+ findSimilarFiles(lineno: number): Promise<Array<Candidate>>
90
+ }
91
+ export declare class LocalGitGraph {
92
+ constructor(repo: string)
93
+ openFile(path: string): Promise<GitFile>
20
94
  }
package/index.js CHANGED
@@ -224,14 +224,72 @@ switch (platform) {
224
224
  }
225
225
  break
226
226
  case 'arm':
227
+ if (isMusl()) {
228
+ localFileExisted = existsSync(
229
+ join(__dirname, 'file_service.linux-arm-musleabihf.node')
230
+ )
231
+ try {
232
+ if (localFileExisted) {
233
+ nativeBinding = require('./file_service.linux-arm-musleabihf.node')
234
+ } else {
235
+ nativeBinding = require('@anysphere/file-service-linux-arm-musleabihf')
236
+ }
237
+ } catch (e) {
238
+ loadError = e
239
+ }
240
+ } else {
241
+ localFileExisted = existsSync(
242
+ join(__dirname, 'file_service.linux-arm-gnueabihf.node')
243
+ )
244
+ try {
245
+ if (localFileExisted) {
246
+ nativeBinding = require('./file_service.linux-arm-gnueabihf.node')
247
+ } else {
248
+ nativeBinding = require('@anysphere/file-service-linux-arm-gnueabihf')
249
+ }
250
+ } catch (e) {
251
+ loadError = e
252
+ }
253
+ }
254
+ break
255
+ case 'riscv64':
256
+ if (isMusl()) {
257
+ localFileExisted = existsSync(
258
+ join(__dirname, 'file_service.linux-riscv64-musl.node')
259
+ )
260
+ try {
261
+ if (localFileExisted) {
262
+ nativeBinding = require('./file_service.linux-riscv64-musl.node')
263
+ } else {
264
+ nativeBinding = require('@anysphere/file-service-linux-riscv64-musl')
265
+ }
266
+ } catch (e) {
267
+ loadError = e
268
+ }
269
+ } else {
270
+ localFileExisted = existsSync(
271
+ join(__dirname, 'file_service.linux-riscv64-gnu.node')
272
+ )
273
+ try {
274
+ if (localFileExisted) {
275
+ nativeBinding = require('./file_service.linux-riscv64-gnu.node')
276
+ } else {
277
+ nativeBinding = require('@anysphere/file-service-linux-riscv64-gnu')
278
+ }
279
+ } catch (e) {
280
+ loadError = e
281
+ }
282
+ }
283
+ break
284
+ case 's390x':
227
285
  localFileExisted = existsSync(
228
- join(__dirname, 'file_service.linux-arm-gnueabihf.node')
286
+ join(__dirname, 'file_service.linux-s390x-gnu.node')
229
287
  )
230
288
  try {
231
289
  if (localFileExisted) {
232
- nativeBinding = require('./file_service.linux-arm-gnueabihf.node')
290
+ nativeBinding = require('./file_service.linux-s390x-gnu.node')
233
291
  } else {
234
- nativeBinding = require('@anysphere/file-service-linux-arm-gnueabihf')
292
+ nativeBinding = require('@anysphere/file-service-linux-s390x-gnu')
235
293
  }
236
294
  } catch (e) {
237
295
  loadError = e
@@ -252,6 +310,13 @@ if (!nativeBinding) {
252
310
  throw new Error(`Failed to load native binding`)
253
311
  }
254
312
 
255
- const { MerkleClient } = nativeBinding
313
+ const { DiffType, DiffClient, MerkleClient, GitClient, CommitFileStatus, CommitChainGetFiles, GitFile, LocalGitGraph } = nativeBinding
256
314
 
315
+ module.exports.DiffType = DiffType
316
+ module.exports.DiffClient = DiffClient
257
317
  module.exports.MerkleClient = MerkleClient
318
+ module.exports.GitClient = GitClient
319
+ module.exports.CommitFileStatus = CommitFileStatus
320
+ module.exports.CommitChainGetFiles = CommitChainGetFiles
321
+ module.exports.GitFile = GitFile
322
+ module.exports.LocalGitGraph = LocalGitGraph
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anysphere/file-service",
3
- "version": "0.0.0-c8c4f8fc",
3
+ "version": "0.0.0-c91bace5",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
@@ -14,9 +14,13 @@
14
14
  ]
15
15
  }
16
16
  },
17
+ "files": [
18
+ "index.js",
19
+ "index.d.ts"
20
+ ],
17
21
  "license": "MIT",
18
22
  "devDependencies": {
19
- "@napi-rs/cli": "^2.16.2",
23
+ "@napi-rs/cli": "^2.18.4",
20
24
  "ava": "^5.1.1"
21
25
  },
22
26
  "ava": {
@@ -36,12 +40,12 @@
36
40
  "version": "napi version"
37
41
  },
38
42
  "optionalDependencies": {
39
- "@anysphere/file-service-win32-x64-msvc": "0.0.0-c8c4f8fc",
40
- "@anysphere/file-service-darwin-x64": "0.0.0-c8c4f8fc",
41
- "@anysphere/file-service-linux-x64-gnu": "0.0.0-c8c4f8fc",
42
- "@anysphere/file-service-darwin-arm64": "0.0.0-c8c4f8fc",
43
- "@anysphere/file-service-win32-arm64-msvc": "0.0.0-c8c4f8fc",
44
- "@anysphere/file-service-darwin-universal": "0.0.0-c8c4f8fc",
45
- "@anysphere/file-service-linux-arm64-gnu": "0.0.0-c8c4f8fc"
43
+ "@anysphere/file-service-win32-x64-msvc": "0.0.0-c91bace5",
44
+ "@anysphere/file-service-darwin-x64": "0.0.0-c91bace5",
45
+ "@anysphere/file-service-linux-x64-gnu": "0.0.0-c91bace5",
46
+ "@anysphere/file-service-darwin-arm64": "0.0.0-c91bace5",
47
+ "@anysphere/file-service-win32-arm64-msvc": "0.0.0-c91bace5",
48
+ "@anysphere/file-service-darwin-universal": "0.0.0-c91bace5",
49
+ "@anysphere/file-service-linux-arm64-gnu": "0.0.0-c91bace5"
46
50
  }
47
51
  }
package/.yarnrc.yml DELETED
@@ -1 +0,0 @@
1
- nodeLinker: node-modules
package/Cargo.toml DELETED
@@ -1,33 +0,0 @@
1
- [package]
2
- edition = "2021"
3
- name = "file_service"
4
- version = "0.0.0"
5
-
6
- [lib]
7
- crate-type = ["cdylib"]
8
-
9
- [dependencies]
10
- # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
11
- napi = { version = "2.12.2", default-features = false, features = ["napi4", "async", "tokio_rt"] }
12
- napi-derive = "2.12.2"
13
- tokio = { version = "1.32.0", features = ["process", "full"] }
14
- sha2 = "0.10.7"
15
- rand = "0.8.5"
16
- tempfile = "3.8.0"
17
- anyhow = "1.0.75"
18
- tonic = "0.9.2"
19
- prost = "0.11.9"
20
- tracing = "0.1.37"
21
- tracing-subscriber = "0.3.17"
22
- tracing-appender = "0.2.2"
23
- binaryornot = "1.0.0"
24
- dunce = "1.0.1"
25
-
26
- [build-dependencies]
27
- napi-build = "2.0.1"
28
- tonic-build = "0.9.2"
29
- anyhow = "1.0.75"
30
- glob = "0.3.0"
31
-
32
- [profile.release]
33
- lto = true
package/build.rs DELETED
@@ -1,44 +0,0 @@
1
- use std::path::Path;
2
-
3
- extern crate napi_build;
4
-
5
- fn main() -> Result<(), anyhow::Error> {
6
- napi_build::setup();
7
-
8
- // print the relative path.
9
- // let workspace_root = "../../../../../";
10
- // let path = std::path::Path::new(workspace_root).canonicalize()?;
11
- // let include_path = Path::join(&path, "schema");
12
-
13
- // // let relevant_protos = &[
14
- // // "aiserver/v1/repository.proto",
15
- // // "aiserver/v1/symbolic_context.proto",
16
- // // "aiserver/v1/utils.proto"
17
- // // ];
18
- // // let proto_paths = relevant_protos
19
- // // .iter()
20
- // // .map(|proto| Path::join(&include_path, proto))
21
- // // .collect::<Vec<_>>();
22
- // let proto_glob = Path::join(&include_path, "aiserver/v1/*.proto");
23
- // let relevant_protos: Vec<_> = glob::glob(proto_glob.to_str().expect("Failed to convert path to str"))?
24
- // .filter_map(Result::ok)
25
- // .collect();
26
-
27
- // let proto_paths = relevant_protos
28
- // .iter()
29
- // .map(|proto_path| proto_path.to_str().expect("Failed to convert path to str"))
30
- // .collect::<Vec<_>>();
31
- // let includes = &[include_path.to_str().unwrap()];
32
-
33
- // // print the path
34
- // println!("cargo:rustc-env=INCLUDE_PATH={}", include_path.display());
35
-
36
- // tonic_build::configure()
37
- // .build_server(false)
38
- // .build_transport(true)
39
- // .out_dir("src/proto")
40
- // .compile(&proto_paths, includes)?;
41
-
42
-
43
- Ok(())
44
- }
package/src/file_utils.rs DELETED
@@ -1,212 +0,0 @@
1
- // what methods do i want to support here.
2
- // 1. isInBadDir
3
- // 2. isBadFile
4
- // 3. vscode.workspace.asRelativePath
5
- // 4. vscode.fs.stat
6
-
7
- use anyhow::Error;
8
- use std::path::Path;
9
- use tokio::fs;
10
-
11
- pub fn is_in_bad_dir(file_path: &Path) -> Result<bool, Error> {
12
- let item_path = file_path
13
- .to_str()
14
- .ok_or(anyhow::anyhow!("Failed to convert path to string"))?;
15
- let is_bad_dir =
16
- item_path.contains("node_modules") || item_path.contains(".git");
17
- Ok(is_bad_dir)
18
- }
19
-
20
- pub fn is_good_file(file_path: &Path) -> Result<(), Error> {
21
- let item_path = file_path
22
- .to_str()
23
- .ok_or(anyhow::anyhow!("Failed to convert path to string"))?;
24
-
25
- let path = Path::new(item_path);
26
- let file_name = path
27
- .file_name()
28
- .ok_or(anyhow::anyhow!("Failed to get file name"))?
29
- .to_str()
30
- .ok_or(anyhow::anyhow!("Failed to convert file name to string"))?;
31
-
32
- let extension = path
33
- .extension()
34
- .ok_or(anyhow::anyhow!("Failed to get extension"))?
35
- .to_str()
36
- .ok_or(anyhow::anyhow!("Failed to convert extension to string"))?;
37
-
38
- match file_name {
39
- "package-lock.json" | "pnpm-lock.yaml" | "yarn.lock" | "composer.lock"
40
- | "Gemfile.lock" | "bun.lockb" => {
41
- return Err(anyhow::anyhow!("File is just a lock file"));
42
- }
43
- _ => {}
44
- }
45
-
46
- match extension {
47
- "lock" | "bak" | "tmp" | "bin" | "exe" | "dll" | "so" | "lockb" => {
48
- return Err(anyhow::anyhow!("File is just a lock file"));
49
- }
50
- _ => {}
51
- }
52
-
53
- if item_path.contains(".git")
54
- || item_path.contains(".svn")
55
- || item_path.contains(".hg")
56
- {
57
- return Err(anyhow::anyhow!("File is just a lock file"));
58
- }
59
-
60
- let bad_extensions = vec![".exe", ".dll", ".so", ".o", ".bin"];
61
- match Path::new(item_path).extension() {
62
- Some(extension) => match extension.to_str() {
63
- Some(ext_str) => {
64
- if bad_extensions.contains(&ext_str) {
65
- return Err(anyhow::anyhow!("Binary file excluded from indexing."));
66
- }
67
- }
68
- None => {
69
- return Err(anyhow::anyhow!("Failed to convert extension to string"))
70
- }
71
- },
72
- None => return Err(anyhow::anyhow!("Failed to get extension")),
73
- }
74
-
75
- // #[cfg(not(test))]
76
- // {
77
- let path = Path::new(item_path);
78
- for part in path.iter() {
79
- match part.to_str() {
80
- Some(s) if s.starts_with(".") => {
81
- return Err(anyhow::anyhow!("File is hidden"))
82
- }
83
- _ => {}
84
- }
85
- }
86
- // }
87
-
88
- Ok(())
89
- }
90
-
91
- // use binaryornot::is_binary;
92
- // use anyhow::Context;
93
- // implement the buffer above:
94
- pub async fn is_good_file_runtime_check(
95
- file_path: &Path,
96
- _buffer: &[u8],
97
- ) -> Result<(), Error> {
98
- match get_file_size(file_path).await {
99
- Ok(size) if size > 2 * 1024 * 1024 => {
100
- return Err(anyhow::anyhow!("Buffer is too large"));
101
- }
102
- Err(e) => return Err(e),
103
- _ => {}
104
- }
105
-
106
- // if is_binary(file_path).context("Failed to check if file is binary")? {
107
- // return Err(anyhow::anyhow!("File is binary"));
108
- // }
109
-
110
- Ok(())
111
- }
112
-
113
- pub fn as_relative_path(
114
- base_path: &Path,
115
- file_path: &Path,
116
- ) -> Result<String, Error> {
117
- let relative_path = file_path.strip_prefix(base_path)?;
118
- Ok(
119
- relative_path
120
- .to_str()
121
- .ok_or(anyhow::anyhow!("Failed to convert relative path to string"))?
122
- .to_string(),
123
- )
124
- }
125
-
126
- pub async fn get_file_size(file_path: &Path) -> Result<u64, Error> {
127
- let metadata = fs::metadata(file_path).await?;
128
-
129
- Ok(metadata.len())
130
- }
131
-
132
- #[cfg(test)]
133
- mod tests {
134
- use super::*;
135
- use std::path::Path;
136
- use tokio::io::AsyncWriteExt;
137
-
138
- #[test]
139
- fn test_is_in_bad_dir() {
140
- let path = Path::new("src/node_modules/test.rs");
141
- assert_eq!(is_in_bad_dir(&path).unwrap(), true);
142
-
143
- let path = Path::new("src/.git/test.rs");
144
- assert_eq!(is_in_bad_dir(&path).unwrap(), true);
145
-
146
- let path = Path::new("src/test.rs");
147
- assert_eq!(is_in_bad_dir(&path).unwrap(), false);
148
- }
149
-
150
- #[test]
151
- fn test_is_good_file() {
152
- let path = Path::new("src/test.rs");
153
- assert_eq!(is_good_file(&path).is_ok(), true);
154
-
155
- let path = Path::new("src/test.exe");
156
- assert_eq!(is_good_file(&path).is_err(), true);
157
-
158
- let path = Path::new("src/.hidden");
159
- assert_eq!(is_good_file(&path).is_err(), true);
160
- }
161
-
162
- #[tokio::test]
163
- async fn test_is_good_file_runtime_check() {
164
- let temp_dir = tempfile::tempdir().unwrap();
165
- let temp_file_path = temp_dir.path().join("test_file");
166
- let mut temp_file = fs::File::create(&temp_file_path).await.unwrap();
167
- temp_file.write_all(b"Hello, world!").await.unwrap();
168
- let buffer = fs::read(&temp_file_path).await.unwrap();
169
- assert_eq!(
170
- is_good_file_runtime_check(&temp_file_path, &buffer)
171
- .await
172
- .is_ok(),
173
- true
174
- );
175
- temp_dir.close().unwrap();
176
-
177
- let temp_dir = tempfile::tempdir().unwrap();
178
- let temp_file_path = temp_dir.path().join("test_file");
179
- let mut temp_file = fs::File::create(&temp_file_path).await.unwrap();
180
- temp_file.write_all(&[0, 159, 146, 150]).await.unwrap(); // Invalid UTF-8 sequence
181
- let buffer = fs::read(&temp_file_path).await.unwrap();
182
- assert_eq!(
183
- is_good_file_runtime_check(&temp_file_path, &buffer)
184
- .await
185
- .is_err(),
186
- true
187
- );
188
- temp_dir.close().unwrap();
189
- }
190
-
191
- #[test]
192
- fn test_as_relative_path() {
193
- let base_path = Path::new("/home/user/src");
194
- let file_path = Path::new("/home/user/src/test.rs");
195
- assert_eq!(as_relative_path(&base_path, &file_path).unwrap(), "test.rs");
196
-
197
- let file_path = Path::new("/home/user/test.rs");
198
- assert!(as_relative_path(&base_path, &file_path).is_err());
199
- }
200
-
201
- #[tokio::test]
202
- async fn test_get_file_size() {
203
- let temp_dir = tempfile::tempdir().unwrap();
204
- let temp_file_path = temp_dir.path().join("test_file.txt");
205
- let mut temp_file = fs::File::create(&temp_file_path).await.unwrap();
206
- temp_file.write_all(b"Hello, world!").await.unwrap();
207
-
208
- let size = get_file_size(&temp_file_path).await.unwrap();
209
- assert_eq!(size, 13);
210
- temp_dir.close().unwrap();
211
- }
212
- }