Skip to content

Commit

Permalink
feat: validate bookmark files (#42)
Browse files Browse the repository at this point in the history
The JSON structure supported by this extension was never explictly documented
and only explained by examples. Due to upcoming features and knowing how manipulating
(deeply) nested JSON by hand is error-prone it makes sense to perform validation
before attempting to import the bookmark files.

I defined a JSON schema and additionally published it to a public location.
JSON Schema for Bookmarks:
https://frederikb.github.io/bookmarksync/schemas/bookmarks.1-0-0.schema.json
In the (rare) case that the schema is updated we need to ensure that the new version is published
as well.
The schema is versioned according to SchemaVer.

As a side benefit, users may also reference the schema in their bookmark JSON files,
via a $schema entry on the root and gain immediate validation in their editor (if supported).

Fixes #29
  • Loading branch information
frederikb authored Feb 11, 2024
1 parent 84e5203 commit 1123cc8
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 42 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"xo": "^0.57.0"
},
"dependencies": {
"@hyperjump/json-schema": "^1.7.2",
"@hyperjump/browser": "^1.1.3",
"@octokit/plugin-retry": "^6.0.1",
"@octokit/rest": "^20.0.2",
"@webext-core/job-scheduler": "^1.0.0",
Expand Down
109 changes: 74 additions & 35 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Structure your JSON file for bookmarks as per the schema defined at [https://fre

```json
{
"$schema": "https://frederikb.github.io/bookmarksync/schemas/bookmarks.1-0-0.schema.json",
"name": "Bookmarks 1",
"bookmarks": [
{
Expand Down Expand Up @@ -149,4 +150,5 @@ Distributed under the MIT License. See [`LICENSE`](LICENSE) for more information
## 📣 Acknowledgements

- [Octokit](https://github.com/octokit/core.js): Seamless GitHub API integration.
- [Hyperjump - JSON Schema](https://github.com/hyperjump-io/json-schema): JSON Schema tooling.
- This project was bootstrapped with [Web Extension Toolkit (wxt.dev)](https://wxt.dev).
1 change: 1 addition & 0 deletions src/entrypoints/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default defineBackground({

main() {
registerSyncBookmarks(new GitHubBookmarksLoader());

const syncBookmarks = getSyncBookmarks();

const jobs = defineJobScheduler();
Expand Down
Loading

0 comments on commit 1123cc8

Please sign in to comment.