HelloZeroNet / HelloZeroNet/ZeroNet

fileQuery: does the implementation match the documentation?

Open
#1,689 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
18.8k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

[The documentation](https://github.com/HelloZeroNet/Documentation/blob/master/docs/site_development/zeroframe_api_reference.md) states:

> ### fileQuery _dir_inner_path, query_
> Simple json file query command
>
> Parameter | Description
> --- | ---
> **dir_inner_path** | Pattern of queried files
> **query** | Query command (optional)
>
> **Return**: Matched content
>
> **Query examples:**
>
> - `["data/users/*/data.json", "topics"]`: Returns all topics node from all user files
> - `["data/users/*/data.json", "comments.1@2"]`: Returns `user_data["comments"]["1@2"]` value from all user files
> - `["data/users/*/data.json", ""]`: Returns all data from users files
> - `["data/users/*/data.json"]`: Returns all data from users files (same as above)
>
> **Example:**
> ```coffeescript
> @cmd "fileQuery", ["data/users/*/data.json", "topics"], (topics) =>
> topics.sort (a, b) -> # Sort by date
> return a.added - b.added
> for topic in topics
> @log topic.topic_id, topic.inner_path, topic.title
> ```

Since there is no definition there, what the "pattern of queried files" is, it is logical to assume that the pattern works similar to the usual wildcard file pattern. So, if one queries "folder/data.json", she should get back exactly 1 result. In fact it is not so:

```
Page.cmd("fileQuery", "data/users/content.json", function(r) {console.log(r.length);})
7
```
The result contains files from the whole `data/users/` subtree.

If the pattern has no `/*/` part, the implementation silently assumes it before the last part of the file path:

```
if "/*/" in path_pattern: # Wildcard search
root_dir, file_pattern = path_pattern.replace("\\", "/").split("/*/")
else: # No wildcard
root_dir, file_pattern = re.match("(.*)/(.*?)$", path_pattern.replace("\\", "/")).groups()
```

Is it actually how it is supposed to work? What is wrong: the documentation or the implementation?

Contributor guide

No contributing guide indexed for this repository

Research direction

Read docs/site_development/zeroframe_api_reference.md and compare its fileQuery examples with the implementation logic shown in the issue. Reproduce the Page.cmd("fileQuery", "data/users/content.json", ...) case, then determine whether the documented pattern or the implementation defines the intended behavior. Done means the documentation and behavior agree, with the discrepancy resolved and covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, python
Domain
api, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.