@anysphere/file-service 0.0.0-a4fe55c1 → 0.0.0-b16d9d59

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
@@ -6,15 +6,11 @@
6
6
  export class MerkleClient {
7
7
  constructor(rootDirectory: string)
8
8
  init(): Promise<void>
9
- computeMerkleTree(): Promise<void>
10
9
  updateFile(filePath: string): Promise<void>
11
10
  deleteFile(filePath: string): Promise<void>
12
- getSubtreeHash(relativePath: string): Promise<string>
11
+ getSubtreeHash(path: string): Promise<string>
13
12
  getNumEmbeddableFiles(): Promise<number>
14
13
  getAllFiles(): Promise<Array<string>>
15
- getAllDirFilesToEmbed(absoluteFilePath: string): Promise<Array<string>>
16
14
  getNextFileToEmbed(): Promise<Array<string>>
17
- getSpline(absoluteFilePath: string): Promise<Array<string>>
18
15
  getHashesForFiles(files: Array<string>): Promise<Array<string>>
19
- updateRootDirectory(rootDirectory: string): void
20
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anysphere/file-service",
3
- "version": "0.0.0-a4fe55c1",
3
+ "version": "0.0.0-b16d9d59",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
@@ -35,11 +35,11 @@
35
35
  "version": "napi version"
36
36
  },
37
37
  "optionalDependencies": {
38
- "@anysphere/file-service-win32-x64-msvc": "0.0.0-a4fe55c1",
39
- "@anysphere/file-service-darwin-x64": "0.0.0-a4fe55c1",
40
- "@anysphere/file-service-linux-x64-gnu": "0.0.0-a4fe55c1",
41
- "@anysphere/file-service-darwin-arm64": "0.0.0-a4fe55c1",
42
- "@anysphere/file-service-win32-arm64-msvc": "0.0.0-a4fe55c1",
43
- "@anysphere/file-service-darwin-universal": "0.0.0-a4fe55c1"
38
+ "@anysphere/file-service-win32-x64-msvc": "0.0.0-b16d9d59",
39
+ "@anysphere/file-service-darwin-x64": "0.0.0-b16d9d59",
40
+ "@anysphere/file-service-linux-x64-gnu": "0.0.0-b16d9d59",
41
+ "@anysphere/file-service-darwin-arm64": "0.0.0-b16d9d59",
42
+ "@anysphere/file-service-win32-arm64-msvc": "0.0.0-b16d9d59",
43
+ "@anysphere/file-service-darwin-universal": "0.0.0-b16d9d59"
44
44
  }
45
45
  }
package/src/lib.rs CHANGED
@@ -40,7 +40,7 @@ impl MerkleClient {
40
40
  unimplemented!("Interrupt is not implemented yet");
41
41
  }
42
42
 
43
- #[napi]
43
+ // #[napi]
44
44
  pub async unsafe fn compute_merkle_tree(
45
45
  &mut self,
46
46
  ) -> Result<(), napi::Error> {
@@ -72,11 +72,9 @@ impl MerkleClient {
72
72
  #[napi]
73
73
  pub async fn get_subtree_hash(
74
74
  &self,
75
- relative_path: String,
75
+ path: String,
76
76
  ) -> Result<String, napi::Error> {
77
- let absolute_path =
78
- std::path::Path::new(&self.root_directory).join(relative_path);
79
- let hash = self.tree.get_subtree_hash(absolute_path).await;
77
+ let hash = self.tree.get_subtree_hash(path).await;
80
78
 
81
79
  match hash {
82
80
  Ok(hash) => Ok(hash),
@@ -100,26 +98,6 @@ impl MerkleClient {
100
98
  }
101
99
  }
102
100
 
103
- pub async fn get_num_embeddable_files_in_subtree(
104
- &self,
105
- relative_path: String,
106
- ) -> Result<i32, napi::Error> {
107
- let absolute_path =
108
- std::path::Path::new(&self.root_directory).join(relative_path);
109
- let num = self
110
- .tree
111
- .get_num_embeddable_files_in_subtree(absolute_path)
112
- .await;
113
-
114
- match num {
115
- Ok(num) => Ok(num),
116
- Err(e) => Err(napi::Error::new(
117
- napi::Status::Unknown,
118
- format!("Error in get_num_embeddable_files_in_subtree: {:?}", e),
119
- )),
120
- }
121
- }
122
-
123
101
  #[napi]
124
102
  pub async fn get_all_files(&self) -> Result<Vec<String>, napi::Error> {
125
103
  let files = self.tree.get_all_files().await;
@@ -133,26 +111,6 @@ impl MerkleClient {
133
111
  }
134
112
  }
135
113
 
136
- #[napi]
137
- pub async fn get_all_dir_files_to_embed(
138
- &self,
139
- absolute_file_path: String,
140
- ) -> Result<Vec<String>, napi::Error> {
141
- let absolute_path_str = absolute_file_path.as_str();
142
- let files = self
143
- .tree
144
- .get_all_dir_files_to_embed(absolute_path_str)
145
- .await;
146
-
147
- match files {
148
- Ok(files) => Ok(files),
149
- Err(e) => Err(napi::Error::new(
150
- napi::Status::Unknown,
151
- format!("Error in get_all_dir_files_to_embed: {:?}", e),
152
- )),
153
- }
154
- }
155
-
156
114
  #[napi]
157
115
  pub async unsafe fn get_next_file_to_embed(
158
116
  &mut self,
@@ -177,25 +135,6 @@ impl MerkleClient {
177
135
  }
178
136
  }
179
137
 
180
- // FIXME(sualeh): get_spline
181
- #[napi]
182
- pub async fn get_spline(
183
- &self,
184
- absolute_file_path: String,
185
- ) -> Result<Vec<String>, napi::Error> {
186
- // let spline = self.tree.get_spline(absolute_file_path).await;
187
-
188
- return Ok(vec![]);
189
-
190
- // match spline {
191
- // Ok(spline) => Ok(spline),
192
- // Err(e) => Err(napi::Error::new(
193
- // napi::Status::Unknown,
194
- // format!("Error in get_spline: {:?}", e),
195
- // )),
196
- // }
197
- }
198
-
199
138
  #[napi]
200
139
  pub async fn get_hashes_for_files(
201
140
  &self,
@@ -212,7 +151,7 @@ impl MerkleClient {
212
151
  }
213
152
  }
214
153
 
215
- #[napi]
154
+ // #[napi]
216
155
  pub fn update_root_directory(&mut self, root_directory: String) {
217
156
  self.root_directory = root_directory;
218
157
  }
@@ -3,7 +3,6 @@ use crate::merkle_tree::{
3
3
  };
4
4
 
5
5
  use super::{LocalConstruction, MerkleTree};
6
- use std::collections::BTreeMap;
7
6
  use std::path::PathBuf;
8
7
  use std::{collections::HashMap, path::Path, sync::Arc};
9
8
  use tonic::async_trait;
@@ -40,7 +39,7 @@ impl LocalConstruction for MerkleTree {
40
39
  let root_node = MerkleNode::new(path, None).await;
41
40
  let mut mt = MerkleTree {
42
41
  root: root_node,
43
- files: BTreeMap::new(),
42
+ files: HashMap::new(),
44
43
  root_path: root_directory,
45
44
  cursor: None,
46
45
  };
@@ -49,7 +48,7 @@ impl LocalConstruction for MerkleTree {
49
48
  // TODO(later): i can make this parallel.
50
49
  fn add_nodes_to_hashmap<'a>(
51
50
  node: &'a MerkleNodePtr,
52
- files: &'a mut BTreeMap<String, File>,
51
+ files: &'a mut HashMap<String, File>,
53
52
  ) -> PinnedFuture<'a, ()> {
54
53
  Box::pin(async move {
55
54
  let node_reader = node.read().await;
@@ -1,8 +1,7 @@
1
1
  use super::file_utils;
2
2
  use sha2::Digest;
3
- use std::collections::BTreeMap;
4
3
  use std::path::PathBuf;
5
- use std::{fs, path::Path, sync::Arc};
4
+ use std::{collections::HashMap, fs, path::Path, sync::Arc};
6
5
  use tokio::sync::RwLock;
7
6
  use tonic::async_trait;
8
7
  pub mod local_construction;
@@ -13,7 +12,7 @@ pub type MerkleNodePtr = Arc<RwLock<MerkleNode>>;
13
12
  pub struct MerkleTree {
14
13
  root_path: String,
15
14
  root: MerkleNodePtr,
16
- files: BTreeMap<String, File>,
15
+ files: HashMap<String, File>,
17
16
  cursor: Option<MerkleNodePtr>,
18
17
  }
19
18
 
@@ -88,7 +87,7 @@ impl MerkleTree {
88
87
  pub fn empty_tree() -> MerkleTree {
89
88
  MerkleTree {
90
89
  root: Arc::new(RwLock::new(MerkleNode::empty_node(None, None))),
91
- files: BTreeMap::new(),
90
+ files: HashMap::new(),
92
91
  root_path: "".to_string(),
93
92
  cursor: None,
94
93
  }
@@ -96,18 +95,10 @@ impl MerkleTree {
96
95
 
97
96
  pub async fn get_subtree_hash(
98
97
  &self,
99
- absolute_path: PathBuf,
98
+ path: String,
100
99
  ) -> Result<String, anyhow::Error> {
101
- let abs_string = match absolute_path.to_str() {
102
- Some(s) => s.to_string(),
103
- None => {
104
- return Err(anyhow::anyhow!(
105
- "get_subtree_hash: Failed to convert path to string"
106
- ))
107
- }
108
- };
109
-
110
- let node = match self.files.get(&abs_string) {
100
+ let path = PathBuf::from(path);
101
+ let node = match self.files.get(path.to_str().unwrap()) {
111
102
  Some(file) => file.node.clone(),
112
103
  None => {
113
104
  return Err(anyhow::anyhow!("Could not find file in tree!"));
@@ -141,43 +132,6 @@ impl MerkleTree {
141
132
  Ok(count)
142
133
  }
143
134
 
144
- pub async fn get_num_embeddable_files_in_subtree(
145
- &self,
146
- absolute_path: PathBuf,
147
- ) -> Result<i32, anyhow::Error> {
148
- let mut count = 0;
149
-
150
- let absolute_path = match absolute_path.to_str() {
151
- Some(s) => s.to_string(),
152
- None => {
153
- return Err(anyhow::anyhow!(
154
- "get_num_embeddable_files_in_subtree: Failed to convert path to string"
155
- ))
156
- }
157
- };
158
-
159
- // TODO(sualeh): worth keeping this list sorted.
160
-
161
- for (_, file) in &self.files {
162
- let file_reader = file.node.read().await;
163
- match &file_reader.node_type {
164
- NodeType::File(file_name) => {
165
- if file_name.contains(&absolute_path) {
166
- count += 1;
167
- }
168
- }
169
- NodeType::Branch(_) => {
170
- continue;
171
- }
172
- NodeType::ErrorNode(_) => {
173
- continue;
174
- }
175
- }
176
- }
177
-
178
- Ok(count)
179
- }
180
-
181
135
  pub async fn get_all_files(&self) -> Result<Vec<String>, anyhow::Error> {
182
136
  let mut files = Vec::new();
183
137
 
@@ -313,33 +267,6 @@ impl MerkleTree {
313
267
  Err(anyhow::anyhow!("Could not find file to embed!"))
314
268
  }
315
269
 
316
- pub async fn get_all_dir_files_to_embed(
317
- &self,
318
- absolute_path: &str,
319
- ) -> Result<Vec<String>, anyhow::Error> {
320
- let mut files = Vec::new();
321
-
322
- for (file_path, f) in &self.files {
323
- if !file_path.contains(absolute_path) {
324
- continue;
325
- }
326
-
327
- match f.node.read().await.node_type {
328
- NodeType::File(_) => {
329
- files.push(file_path.clone());
330
- }
331
- NodeType::Branch(_) => {
332
- continue;
333
- }
334
- NodeType::ErrorNode(_) => {
335
- continue;
336
- }
337
- }
338
- }
339
-
340
- Ok(files)
341
- }
342
-
343
270
  /// creates a new node and attaches it to the current tree.
344
271
  /// SPEC:
345
272
  /// - you are allowed to create a file with a node such that the