-
Notifications
You must be signed in to change notification settings - Fork 138
feat: add minimal implementation of changesStream for registry mirroring #1025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
elrrrrrrr
wants to merge
7
commits into
jsr-io:main
Choose a base branch
from
elrrrrrrr:changes-stream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5caa86f
feat: changes query
elrrrrrrr 4502b08
feat: create change
elrrrrrrr 09d0571
fix: lint
elrrrrrrr 52dcee6
refact: split scope & name
elrrrrrrr c1e44d9
feat: testcase
elrrrrrrr 5171d1e
chore: ci
elrrrrrrr 850314d
chore: lint
elrrrrrrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CREATE TYPE change_type AS ENUM ( | ||
'PACKAGE_VERSION_ADDED', | ||
'PACKAGE_TAG_ADDED' | ||
); | ||
|
||
CREATE TABLE changes ( | ||
seq BIGSERIAL PRIMARY KEY, | ||
change_type change_type NOT NULL, | ||
package_id VARCHAR(255) NOT NULL, | ||
data TEXT NOT NULL, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
); | ||
|
||
CREATE INDEX changes_package_id_idx ON changes (package_id); | ||
CREATE INDEX changes_created_at_idx ON changes (created_at); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 the JSR authors. All rights reserved. MIT license. | ||
use hyper::{Body, Request}; | ||
use routerify::prelude::*; | ||
use serde::Serialize; | ||
|
||
use crate::{ | ||
db::{Change, Database}, | ||
util::{pagination, ApiResult}, | ||
}; | ||
|
||
|
||
#[derive(Serialize)] | ||
pub struct ApiChange { | ||
pub seq: i64, | ||
pub r#type: String, | ||
pub id: String, | ||
pub changes: serde_json::Value, | ||
} | ||
|
||
impl From<Change> for ApiChange { | ||
fn from(change: Change) -> Self { | ||
Self { | ||
seq: change.seq, | ||
r#type: change.change_type.to_string(), | ||
id: change.package_id, | ||
changes: serde_json::from_str(&change.data).unwrap(), | ||
} | ||
} | ||
} | ||
|
||
pub async fn list_changes(req: Request<Body>) -> ApiResult<Vec<ApiChange>> { | ||
let db = req.data::<Database>().unwrap(); | ||
let (start, limit) = pagination(&req); | ||
let changes = db.list_changes(start, limit).await?; | ||
Ok(changes.into_iter().map(ApiChange::from).collect()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.