Skip to content

Commit 5841141

Browse files
committed
Remove tpf queries from atomic-cli #610
1 parent 4bccd89 commit 5841141

File tree

9 files changed

+15
-101
lines changed

9 files changed

+15
-101
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ By far most changes relate to `atomic-server`, so if not specified, assume the c
55
Changes to JS assets are not included here, but in [`atomic-data-browser`'s CHANGELOG](https://github.com/atomicdata-dev/atomic-data-browser/blob/main/CHANGELOG.md).
66
See [STATUS.md](server/STATUS.md) to learn more about which features will remain stable.
77

8+
## UNRELEASED
9+
10+
- Remove `tpf` queries from `atomic-cli` #610
11+
812
## [v0.34.2] - 2023-03-04
913

1014
- **Requires `--rebuild-index`**

cli/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ SUBCOMMANDS:
3232
new Create a Resource
3333
remove Remove a single Atom from a Resource.
3434
set Update a single Atom. Creates both the Resource if they don't exist. Overwrites existing.
35-
tpf Finds Atoms using Triple Pattern Fragments.
3635
3736
Visit https://atomicdata.dev for more info
3837
```

cli/src/main.rs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use colored::*;
66
use dirs::home_dir;
77
use std::{cell::RefCell, path::PathBuf, sync::Mutex};
88

9-
use crate::print::{print_resource, SERIALIZE_OPTIONS};
9+
use crate::print::SERIALIZE_OPTIONS;
1010

1111
mod commit;
1212
mod new;
@@ -115,35 +115,6 @@ fn main() -> AtomicResult<()> {
115115
.num_args(1)
116116
)
117117
)
118-
.subcommand(
119-
Command::new("tpf")
120-
.about("Finds Atoms using Triple Pattern Fragments.",
121-
)
122-
.after_help("\
123-
Filter the store by <subject> <property> and <value>. \
124-
Use a dot to indicate that you don't need to filter. \
125-
Subjects and properties need to be full URLs. \
126-
")
127-
.arg(Arg::new("subject")
128-
.help("The subject URL or bookmark to be filtered by. Use a dot '.' to indicate 'any'.")
129-
.required(true)
130-
)
131-
.arg(Arg::new("property")
132-
.help("The property URL or bookmark to be filtered by. Use a dot '.' to indicate 'any'.")
133-
.required(true)
134-
)
135-
.arg(Arg::new("value")
136-
.help("The value URL or bookmark to be filtered by. Use a dot '.' to indicate 'any'.")
137-
.required(true)
138-
)
139-
.arg(Arg::new("as")
140-
.long("as")
141-
.value_parser(SERIALIZE_OPTIONS)
142-
.default_value("pretty")
143-
.help("Serialization format")
144-
.num_args(1)
145-
)
146-
)
147118
.subcommand(
148119
Command::new("set")
149120
.about("Update a single Atom. Creates both the Resource if they don't exist. Overwrites existing.")
@@ -264,9 +235,6 @@ fn exec_command(context: &mut Context) -> AtomicResult<()> {
264235
Some("set") => {
265236
commit::set(context)?;
266237
}
267-
Some("tpf") => {
268-
tpf(context)?;
269-
}
270238
Some("validate") => {
271239
validate(context);
272240
}
@@ -291,30 +259,6 @@ fn list(context: &mut Context) {
291259
println!("{}", string)
292260
}
293261

294-
/// Triple Pattern Fragment Query
295-
fn tpf(context: &Context) -> AtomicResult<()> {
296-
let subcommand_matches = context.matches.subcommand_matches("tpf").unwrap();
297-
let subject = tpf_value(subcommand_matches.get_one::<String>("subject").unwrap());
298-
let property = tpf_value(subcommand_matches.get_one::<String>("property").unwrap());
299-
let value = tpf_value(subcommand_matches.get_one::<String>("value").unwrap());
300-
let endpoint = format!("{}/tpf", &context.get_write_context().server);
301-
let resources =
302-
atomic_lib::client::fetch_tpf(&endpoint, subject, property, value, &context.store)?;
303-
for r in resources {
304-
print_resource(context, &r, subcommand_matches)?;
305-
}
306-
Ok(())
307-
}
308-
309-
/// Converts dots to 'None'
310-
fn tpf_value(string: &str) -> Option<&str> {
311-
if string == "." {
312-
None
313-
} else {
314-
Some(string)
315-
}
316-
}
317-
318262
/// Validates the store
319263
fn validate(context: &mut Context) {
320264
let reportstring = context.store.validate().to_string();

lib/src/client.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,6 @@ pub fn fetch_body(url: &str, content_type: &str, for_agent: Option<Agent>) -> At
7878
Ok(body)
7979
}
8080

81-
/// Uses a TPF endpoint, returns a Vector of matching resources
82-
pub fn fetch_tpf(
83-
endpoint: &str,
84-
q_subject: Option<&str>,
85-
q_property: Option<&str>,
86-
q_value: Option<&str>,
87-
store: &impl Storelike,
88-
) -> AtomicResult<Vec<Resource>> {
89-
let mut url = Url::parse(endpoint)?;
90-
if let Some(val) = q_subject {
91-
url.query_pairs_mut().append_pair("subject", val);
92-
}
93-
if let Some(val) = q_property {
94-
url.query_pairs_mut().append_pair("property", val);
95-
}
96-
if let Some(val) = q_value {
97-
url.query_pairs_mut().append_pair("value", val);
98-
}
99-
let body = fetch_body(
100-
url.as_str(),
101-
"application/ad+json",
102-
store.get_default_agent().ok(),
103-
)?;
104-
crate::parse::parse_json_ad_string(&body, store, &ParseOpts::default())
105-
}
106-
10781
/// Posts a Commit to the endpoint of the Subject from the Commit
10882
pub fn post_commit(commit: &crate::Commit, store: &impl Storelike) -> AtomicResult<()> {
10983
let server_url = crate::utils::server_url(commit.get_subject())?;

lib/src/collections.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
//! Collections are dynamic resources that refer to multiple resources.
2-
//! They are constructed using a TPF query
2+
//! They are constructed using a [Query]
33
use crate::{
44
errors::AtomicResult,
55
storelike::{Query, ResourceCollection},
66
urls, Resource, Storelike, Value,
77
};
88

9-
#[derive(Debug)]
10-
pub struct TpfQuery {
11-
pub subject: Option<String>,
12-
pub property: Option<String>,
13-
pub value: Option<String>,
14-
}
15-
169
const DEFAULT_PAGE_SIZE: usize = 30;
1710

1811
/// Used to construct a Collection. Does not contain results / members.
@@ -21,9 +14,9 @@ const DEFAULT_PAGE_SIZE: usize = 30;
2114
pub struct CollectionBuilder {
2215
/// Full Subject URL of the resource, including query parameters
2316
pub subject: String,
24-
/// The TPF property which the results are to be filtered by
17+
/// The property which the results are to be filtered by
2518
pub property: Option<String>,
26-
/// The TPF value which the results are to be filtered by
19+
/// The value which the results are to be filtered by
2720
pub value: Option<String>,
2821
/// URL of the value to sort by
2922
pub sort_by: Option<String>,
@@ -128,9 +121,9 @@ impl CollectionBuilder {
128121
pub struct Collection {
129122
/// Full Subject URL of the resource, including query parameters
130123
pub subject: String,
131-
/// The TPF property which the results are to be filtered by
124+
/// The property which the results are to be filtered by
132125
pub property: Option<String>,
133-
/// The TPF value which the results are to be filtered by
126+
/// The value which the results are to be filtered by
134127
pub value: Option<String>,
135128
/// The actual items that you're interested in. List the member subjects of the current page.
136129
pub members: Vec<String>,

lib/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct Db {
6868
/// See [reference_index]
6969
reference_index: sled::Tree,
7070
/// Index sorted by property + value.
71-
/// Used for TPF queries where the property is known.
71+
/// Used for queries where the property is known.
7272
prop_val_sub_index: sled::Tree,
7373
/// Stores the members of Collections, easily sortable.
7474
query_index: sled::Tree,
@@ -579,7 +579,7 @@ impl Storelike for Db {
579579
// populate_base_models should be run in init, instead of here, since it will result in infinite loops without
580580
crate::populate::populate_default_store(self)
581581
.map_err(|e| format!("Failed to populate default store. {}", e))?;
582-
// This is a potentially expensive operation, but is needed to make TPF queries work with the models created in here
582+
// This is a potentially expensive operation, but is needed to make Queries work with the models created in here
583583
self.build_index(true)
584584
.map_err(|e| format!("Failed to build index. {}", e))?;
585585
crate::populate::create_drive(self)

lib/src/db/query_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub fn should_update_property<'a>(
271271
}
272272

273273
/// This is called when an atom is added or deleted.
274-
/// Check whether the Atom will be hit by a TPF query matching the [QueryFilter].
274+
/// Check whether the [Atom] will be hit by a [Query] matching the [QueryFilter].
275275
/// Updates the index accordingly.
276276
/// We need both the `index_atom` and the full `atom`.
277277
#[tracing::instrument(skip_all)]

lib/src/hierarchy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl fmt::Display for Right {
3030
}
3131
}
3232

33-
/// Looks for children relations, adds to the resource. Performs a TPF query, might be expensive.
33+
/// Looks for children relations, adds to the resource. Performs a Query, might be expensive.
3434
pub fn add_children(store: &impl Storelike, resource: &mut Resource) -> AtomicResult<Resource> {
3535
let results = store.query(&Query::new_prop_val(urls::PARENT, resource.get_subject()))?;
3636
let mut children = results.subjects;

server/src/appstate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn init(config: Config) -> AtomicServerResult<AppState> {
4646
tracing::info!("Initialize: creating and populating new Database");
4747
atomic_lib::populate::populate_default_store(&store)
4848
.map_err(|e| format!("Failed to populate default store. {}", e))?;
49-
// Building the index here is needed to perform TPF queries on imported resources
49+
// Building the index here is needed to perform Queries on imported resources
5050
tracing::info!("Building index (this could take a few minutes for larger databases)");
5151
store.build_index(true)?;
5252
tracing::info!("Building index finished!");

0 commit comments

Comments
 (0)