@anysphere/file-service 0.0.0-f2b1ba30 → 0.0.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.
package/Cargo.toml CHANGED
@@ -17,9 +17,6 @@ tempfile = "3.8.0"
17
17
  anyhow = "1.0.75"
18
18
  tonic = "0.9.2"
19
19
  prost = "0.11.9"
20
- tracing = "0.1.37"
21
- tracing-subscriber = "0.3.17"
22
- tracing-appender = "0.2.2"
23
20
 
24
21
  [build-dependencies]
25
22
  napi-build = "2.0.1"
package/build.rs CHANGED
@@ -6,38 +6,38 @@ fn main() -> Result<(), anyhow::Error> {
6
6
  napi_build::setup();
7
7
 
8
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
-
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
+ // ];
27
18
  // let proto_paths = relevant_protos
28
19
  // .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)?;
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
41
 
42
42
 
43
43
  Ok(())
package/index.d.ts CHANGED
@@ -4,17 +4,10 @@
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
6
  export class MerkleClient {
7
- constructor(rootDirectory: string)
8
7
  init(): Promise<void>
8
+ syncWithRemote(): Promise<void>
9
9
  computeMerkleTree(): Promise<void>
10
10
  updateFile(filePath: string): Promise<void>
11
11
  deleteFile(filePath: string): Promise<void>
12
- getSubtreeHash(relativePath: string): Promise<string>
13
- getNumEmbeddableFiles(): Promise<number>
14
- getAllFiles(): Promise<Array<string>>
15
- 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
12
  updateRootDirectory(rootDirectory: string): void
20
13
  }
package/package.json CHANGED
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "name": "@anysphere/file-service",
3
- "version": "0.0.0-f2b1ba30",
3
+ "version": "0.0.0",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
7
7
  "name": "file_service",
8
8
  "triples": {
9
9
  "additional": [
10
- "aarch64-apple-darwin",
11
- "aarch64-pc-windows-msvc",
12
- "universal-apple-darwin"
10
+ "aarch64-apple-darwin"
13
11
  ]
14
12
  }
15
13
  },
@@ -31,15 +29,12 @@
31
29
  "prepublishOnly": "napi prepublish -t npm",
32
30
  "test": "ava",
33
31
  "universal": "napi universal",
34
- "preversion": "git config --global user.name || git config --global user.name 'Your Name'; git config --global user.email || git config --global user.email 'youremail@example.com'",
35
32
  "version": "napi version"
36
33
  },
37
34
  "optionalDependencies": {
38
- "@anysphere/file-service-win32-x64-msvc": "0.0.0-f2b1ba30",
39
- "@anysphere/file-service-darwin-x64": "0.0.0-f2b1ba30",
40
- "@anysphere/file-service-linux-x64-gnu": "0.0.0-f2b1ba30",
41
- "@anysphere/file-service-darwin-arm64": "0.0.0-f2b1ba30",
42
- "@anysphere/file-service-win32-arm64-msvc": "0.0.0-f2b1ba30",
43
- "@anysphere/file-service-darwin-universal": "0.0.0-f2b1ba30"
35
+ "@anysphere/file-service-win32-x64-msvc": "0.0.0",
36
+ "@anysphere/file-service-darwin-x64": "0.0.0",
37
+ "@anysphere/file-service-linux-x64-gnu": "0.0.0",
38
+ "@anysphere/file-service-darwin-arm64": "0.0.0"
44
39
  }
45
40
  }
package/src/file_utils.rs CHANGED
@@ -12,15 +12,15 @@ pub fn is_in_bad_dir(file_path: &Path) -> Result<bool, Error> {
12
12
  let item_path = file_path
13
13
  .to_str()
14
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");
15
+ let is_bad_dir = (item_path.contains("node_modules") || item_path.contains(".git"))
16
+ && !(item_path.ends_with(".git") || item_path.ends_with("node_modules"));
17
17
  Ok(is_bad_dir)
18
18
  }
19
19
 
20
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"))?;
21
+ let item_path = file_path.to_str().ok_or(anyhow::anyhow!(
22
+ "Failed to convert path to string"
23
+ ))?;
24
24
 
25
25
  let path = Path::new(item_path);
26
26
  let file_name = path
@@ -36,24 +36,20 @@ pub fn is_good_file(file_path: &Path) -> Result<(), Error> {
36
36
  .ok_or(anyhow::anyhow!("Failed to convert extension to string"))?;
37
37
 
38
38
  match file_name {
39
- "package-lock.json" | "pnpm-lock.yaml" | "yarn.lock" | "composer.lock"
40
- | "Gemfile.lock" | "bun.lockb" => {
39
+ "package-lock.json" | "pnpm-lock.yaml" | "yarn.lock" | "composer.lock" | "Gemfile.lock" => {
41
40
  return Err(anyhow::anyhow!("File is just a lock file"));
42
41
  }
43
42
  _ => {}
44
43
  }
45
44
 
46
45
  match extension {
47
- "lock" | "bak" | "tmp" | "bin" | "exe" | "dll" | "so" | "lockb" => {
46
+ "lock" | "bak" | "tmp" | "bin" | "exe" | "dll" | "so" => {
48
47
  return Err(anyhow::anyhow!("File is just a lock file"));
49
48
  }
50
49
  _ => {}
51
50
  }
52
51
 
53
- if item_path.contains(".git")
54
- || item_path.contains(".svn")
55
- || item_path.contains(".hg")
56
- {
52
+ if item_path.contains(".git") || item_path.contains(".svn") || item_path.contains(".hg") {
57
53
  return Err(anyhow::anyhow!("File is just a lock file"));
58
54
  }
59
55
 
@@ -64,39 +60,29 @@ pub fn is_good_file(file_path: &Path) -> Result<(), Error> {
64
60
  if bad_extensions.contains(&ext_str) {
65
61
  return Err(anyhow::anyhow!("File is not a valid UTF-8 string"));
66
62
  }
67
- }
68
- None => {
69
- return Err(anyhow::anyhow!("Failed to convert extension to string"))
70
- }
63
+ },
64
+ None => return Err(anyhow::anyhow!("Failed to convert extension to string")),
71
65
  },
72
66
  None => return Err(anyhow::anyhow!("Failed to get extension")),
73
67
  }
74
68
 
75
- // #[cfg(not(test))]
76
- // {
77
69
  let path = Path::new(item_path);
78
70
  for part in path.iter() {
79
71
  match part.to_str() {
80
- Some(s) if s.starts_with(".") => {
81
- return Err(anyhow::anyhow!("File is hidden"))
82
- }
72
+ Some(s) if s.starts_with(".") => return Err(anyhow::anyhow!("File is hidden")),
83
73
  _ => {}
84
74
  }
85
75
  }
86
- // }
87
76
 
88
77
  Ok(())
89
78
  }
90
79
 
91
80
  // implement the buffer above:
92
- pub async fn is_good_file_runtime_check(
93
- file_path: &Path,
94
- buffer: &[u8],
95
- ) -> Result<(), Error> {
81
+ pub async fn is_good_file_runtime_check(file_path: &Path, buffer: &[u8]) -> Result<(), Error> {
96
82
  match get_file_size(file_path).await {
97
83
  Ok(size) if size > 2 * 1024 * 1024 => {
98
84
  return Err(anyhow::anyhow!("Buffer is too large"));
99
- }
85
+ },
100
86
  Err(e) => return Err(e),
101
87
  _ => {}
102
88
  }
@@ -111,10 +97,7 @@ pub async fn is_good_file_runtime_check(
111
97
  Ok(())
112
98
  }
113
99
 
114
- pub fn as_relative_path(
115
- base_path: &Path,
116
- file_path: &Path,
117
- ) -> Result<String, Error> {
100
+ pub fn as_relative_path(base_path: &Path, file_path: &Path) -> Result<String, Error> {
118
101
  let relative_path = file_path.strip_prefix(base_path)?;
119
102
  Ok(
120
103
  relative_path
@@ -134,7 +117,7 @@ pub async fn get_file_size(file_path: &Path) -> Result<u64, Error> {
134
117
  mod tests {
135
118
  use super::*;
136
119
  use std::path::Path;
137
- use tokio::io::AsyncWriteExt;
120
+ use tokio::io::AsyncWriteExt;
138
121
 
139
122
  #[test]
140
123
  fn test_is_in_bad_dir() {
@@ -167,12 +150,7 @@ mod tests {
167
150
  let mut temp_file = fs::File::create(&temp_file_path).await.unwrap();
168
151
  temp_file.write_all(b"Hello, world!").await.unwrap();
169
152
  let buffer = fs::read(&temp_file_path).await.unwrap();
170
- assert_eq!(
171
- is_good_file_runtime_check(&temp_file_path, &buffer)
172
- .await
173
- .is_ok(),
174
- true
175
- );
153
+ assert_eq!(is_good_file_runtime_check(&temp_file_path, &buffer).await.is_ok(), true);
176
154
  temp_dir.close().unwrap();
177
155
 
178
156
  let temp_dir = tempfile::tempdir().unwrap();
@@ -180,12 +158,7 @@ mod tests {
180
158
  let mut temp_file = fs::File::create(&temp_file_path).await.unwrap();
181
159
  temp_file.write_all(&[0, 159, 146, 150]).await.unwrap(); // Invalid UTF-8 sequence
182
160
  let buffer = fs::read(&temp_file_path).await.unwrap();
183
- assert_eq!(
184
- is_good_file_runtime_check(&temp_file_path, &buffer)
185
- .await
186
- .is_err(),
187
- true
188
- );
161
+ assert_eq!(is_good_file_runtime_check(&temp_file_path, &buffer).await.is_err(), true);
189
162
  temp_dir.close().unwrap();
190
163
  }
191
164
 
@@ -209,5 +182,6 @@ mod tests {
209
182
  let size = get_file_size(&temp_file_path).await.unwrap();
210
183
  assert_eq!(size, 13);
211
184
  temp_dir.close().unwrap();
185
+
212
186
  }
213
187
  }
package/src/git_utils.rs CHANGED
@@ -1,10 +1,10 @@
1
1
  use std::collections::HashSet;
2
+ use std::path::PathBuf;
2
3
  use std::process::Command;
3
4
 
4
5
  pub fn list_ignored_files(
5
6
  workspace_root_path: &str,
6
- should_return_absolute_paths: bool,
7
- ) -> Result<HashSet<String>, Box<dyn std::error::Error>> {
7
+ ) -> Result<HashSet<PathBuf>, Box<dyn std::error::Error>> {
8
8
  let mut gitignored_files = HashSet::new();
9
9
 
10
10
  let commands = vec![
@@ -15,66 +15,12 @@ pub fn list_ignored_files(
15
15
  "--ignored",
16
16
  "--exclude-standard",
17
17
  ],
18
- // FIXME(sualeh): this is super sketchy and might totally break in like a bazillion ways. i dont like it.
19
- vec![
20
- "sh",
21
- "-c",
22
- "git submodule foreach --quiet 'git ls-files --others --ignored --exclude-standard | sed \"s|^|$path/|\"'",
23
- ],
24
- ];
25
-
26
- for command in commands {
27
- let output = Command::new(&command[0])
28
- .args(&command[1..])
29
- .current_dir(workspace_root_path)
30
- .output()?;
31
-
32
- if output.status.success() {
33
- let files = String::from_utf8(output.stdout)?
34
- .lines()
35
- .filter(|line| !line.is_empty())
36
- .map(|line| {
37
- if should_return_absolute_paths {
38
- let mut path = std::path::PathBuf::from(workspace_root_path);
39
- path.push(line);
40
-
41
- match path.canonicalize() {
42
- Ok(canonical_path) => {
43
- canonical_path.to_string_lossy().into_owned()
44
- }
45
- Err(_) => String::from(line),
46
- }
47
- } else {
48
- String::from(line)
49
- }
50
- })
51
- .collect::<HashSet<_>>();
52
-
53
- gitignored_files.extend(files);
54
- }
55
- }
56
-
57
- Ok(gitignored_files)
58
- }
59
-
60
- pub fn list_ignored_files_with_absolute_paths(
61
- workspace_root_path: &str,
62
- ) -> Result<HashSet<String>, Box<dyn std::error::Error>> {
63
- let mut gitignored_files = HashSet::new();
64
-
65
- let commands = vec![
66
18
  vec![
67
19
  "git",
68
- "ls-files",
69
- "--others",
70
- "--ignored",
71
- "--exclude-standard",
72
- ],
73
- // FIXME(sualeh): this is super sketchy and might totally break in like a bazillion ways. i dont like it.
74
- vec![
75
- "sh",
76
- "-c",
77
- "git submodule foreach --quiet 'git ls-files --others --ignored --exclude-standard | sed \"s|^|$path/|\"'",
20
+ "submodule",
21
+ "foreach",
22
+ "--quiet",
23
+ "git ls-files --others --ignored --exclude-standard | sed 's|^|$path/|'",
78
24
  ],
79
25
  ];
80
26
 
@@ -88,7 +34,7 @@ pub fn list_ignored_files_with_absolute_paths(
88
34
  let files = String::from_utf8(output.stdout)?
89
35
  .lines()
90
36
  .filter(|line| !line.is_empty())
91
- .map(|line| String::from(line))
37
+ .map(|line| PathBuf::from(line))
92
38
  .collect::<HashSet<_>>();
93
39
 
94
40
  gitignored_files.extend(files);
@@ -111,18 +57,6 @@ pub async fn is_git_ignored(
111
57
  Ok(output.status.success())
112
58
  }
113
59
 
114
- pub async fn is_git_directory(
115
- workspace_root_path: &str,
116
- ) -> Result<bool, anyhow::Error> {
117
- let output = tokio::process::Command::new("git")
118
- .args(&["rev-parse", "--is-inside-work-tree"])
119
- .current_dir(workspace_root_path)
120
- .output()
121
- .await?;
122
-
123
- Ok(output.status.success())
124
- }
125
-
126
60
  #[cfg(test)]
127
61
  mod tests {
128
62
  use super::*;
@@ -132,8 +66,7 @@ mod tests {
132
66
  #[test]
133
67
  fn test_no_ignored_files() {
134
68
  let dir = tempfile::tempdir().unwrap();
135
- let gitignored_files =
136
- list_ignored_files(dir.path().to_str().unwrap(), false).unwrap();
69
+ let gitignored_files = list_ignored_files(dir.path().to_str().unwrap()).unwrap();
137
70
  Command::new("git")
138
71
  .args(&["init"])
139
72
  .current_dir(dir.path())
@@ -159,14 +92,13 @@ mod tests {
159
92
  .current_dir(dir.path())
160
93
  .output()
161
94
  .unwrap();
162
- let gitignored_files =
163
- list_ignored_files(dir.path().to_str().unwrap(), false).unwrap();
95
+ let gitignored_files = list_ignored_files(dir.path().to_str().unwrap()).unwrap();
164
96
  println!(
165
97
  "ignored files for test_one_ignored_file: {:?}",
166
98
  gitignored_files
167
99
  );
168
100
  // assert_eq!(gitignored_files.len(), 1);
169
- assert!(gitignored_files.contains(&String::from("ignored.txt")));
101
+ assert!(gitignored_files.contains(&PathBuf::from("ignored.txt")));
170
102
  }
171
103
 
172
104
  #[test]
@@ -189,83 +121,19 @@ mod tests {
189
121
  .current_dir(dir.path())
190
122
  .output()
191
123
  .unwrap();
192
- let gitignored_files =
193
- list_ignored_files(dir.path().to_str().unwrap(), false).unwrap();
124
+ let gitignored_files = list_ignored_files(dir.path().to_str().unwrap()).unwrap();
194
125
  println!(
195
126
  "ignored files for test_multiple_ignored_files: {:?}",
196
127
  gitignored_files
197
128
  );
198
129
  // assert_eq!(gitignored_files.len(), 2);
199
- assert!(gitignored_files.contains(&String::from("ignored1.txt")));
200
- assert!(gitignored_files.contains(&String::from("ignored2.txt")));
201
- }
202
-
203
- #[test]
204
- fn test_git_submodule_ignored_files() {
205
- let dir = tempfile::tempdir().unwrap();
206
- let submodule_path = dir.path().join("submodule");
207
- std::fs::create_dir(&submodule_path).unwrap();
208
-
209
- let o = Command::new("git")
210
- .args(&["init"])
211
- .current_dir(&submodule_path)
212
- .output()
213
- .unwrap();
214
- println!("git init output: {:?}", o);
215
-
216
- let file_path = submodule_path.join("ignored.txt");
217
- let mut file = File::create(&file_path).unwrap();
218
- writeln!(file, "This is an ignored file.").unwrap();
219
-
220
- let file2 = submodule_path.join("ignored2.txt");
221
- let mut file = File::create(&file2).unwrap();
222
- writeln!(file, "This is another ignored file.").unwrap();
223
-
224
- let gitignore_path = submodule_path.join(".gitignore");
225
- let mut gitignore = File::create(&gitignore_path).unwrap();
226
- writeln!(gitignore, "*.txt").unwrap();
227
-
228
- let o = Command::new("git")
229
- .args(&["init"])
230
- .current_dir(dir.path())
231
- .output()
232
- .unwrap();
233
- println!("git init output: {:?}", o);
234
-
235
- // make a commit in the submodule
236
- let o = Command::new("git")
237
- .args(&["add", "."])
238
- .current_dir(&submodule_path)
239
- .output()
240
- .unwrap();
241
- println!("git add output: {:?}", o);
242
- let o = Command::new("git")
243
- .args(&["commit", "-m", "initial commit"])
244
- .current_dir(&submodule_path)
245
- .output()
246
- .unwrap();
247
- println!("git commit output: {:?}", o);
248
-
249
- let o = Command::new("git")
250
- .args(&["submodule", "add", "./submodule"])
251
- .current_dir(dir.path())
252
- .output()
253
- .unwrap();
254
- println!("git submodule add output: {:?}", o);
255
-
256
- let gitignored_files =
257
- list_ignored_files(dir.path().to_str().unwrap(), false).unwrap();
258
- println!(
259
- "ignored files for test_git_submodule_ignored_files: {:?}",
260
- gitignored_files
261
- );
262
- assert!(gitignored_files.contains(&String::from("submodule/ignored.txt")));
263
- assert!(gitignored_files.contains(&String::from("submodule/ignored2.txt")));
130
+ assert!(gitignored_files.contains(&PathBuf::from("ignored1.txt")));
131
+ assert!(gitignored_files.contains(&PathBuf::from("ignored2.txt")));
264
132
  }
265
133
 
266
134
  #[test]
267
135
  fn test_multiple_ignored_files_in_current_dir() {
268
- let gitignored_files = list_ignored_files(".", false).unwrap();
136
+ let gitignored_files = list_ignored_files(".").unwrap();
269
137
  assert!(gitignored_files.len() > 1);
270
138
 
271
139
  // print a sample of the ignored files
@@ -279,6 +147,7 @@ mod tests {
279
147
  }
280
148
  }
281
149
 
150
+
282
151
  #[tokio::test]
283
152
  async fn test_file_not_ignored() {
284
153
  let dir = tempfile::tempdir().unwrap();
@@ -291,10 +160,7 @@ mod tests {
291
160
  .current_dir(dir.path())
292
161
  .output()
293
162
  .unwrap();
294
- let is_ignored =
295
- is_git_ignored(dir.path().to_str().unwrap(), "not_ignored.txt")
296
- .await
297
- .unwrap();
163
+ let is_ignored = is_git_ignored(dir.path().to_str().unwrap(), "not_ignored.txt").await.unwrap();
298
164
  assert_eq!(is_ignored, false);
299
165
  }
300
166
 
@@ -314,10 +180,7 @@ mod tests {
314
180
  .current_dir(dir.path())
315
181
  .output()
316
182
  .unwrap();
317
- let is_ignored =
318
- is_git_ignored(dir.path().to_str().unwrap(), "ignored.txt")
319
- .await
320
- .unwrap();
183
+ let is_ignored = is_git_ignored(dir.path().to_str().unwrap(), "ignored.txt").await.unwrap();
321
184
  assert_eq!(is_ignored, true);
322
185
  }
323
186
 
@@ -337,10 +200,8 @@ mod tests {
337
200
  .current_dir(dir.path())
338
201
  .output()
339
202
  .unwrap();
340
- let is_ignored =
341
- is_git_ignored(dir.path().to_str().unwrap(), "ignored.txt")
342
- .await
343
- .unwrap();
203
+ let is_ignored = is_git_ignored(dir.path().to_str().unwrap(), "ignored.txt").await.unwrap();
344
204
  assert_eq!(is_ignored, true);
345
205
  }
206
+
346
207
  }