Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

Convert existing REST /links/count endpoint to XRPC equivalent #8

closed opened by seoul.systems targeting main from seoul.systems/microcosm-rs: xrpc_backlinks_count

Add getCounts XRPC equivalent to REST /links/count

Simple conversion of the existing endpoint from REST to XRPC. Consequtively marked the pre-existing REST endpoint as deprecated.

In addition we now ignore rocks.test

Labels

None yet.

Participants 2
AT URI
at://did:plc:53wellrw53o7sw4zlpfenvuh/sh.tangled.repo.pull/3mcybnzocig22
+29 -118
Interdiff #4 #5
.gitignore

This file has not been changed.

.prettierrc

This file has not been changed.

constellation/src/server/mod.rs

This file has not been changed.

+1 -1
constellation/templates/hello.html.j2
··· 149 </ul> 150 151 <p style="margin-bottom: 0"><strong>Try it:</strong></p> 152 - {% call try_it::get_backlinks_count("did:plc:vc7f4oafdgxsihk4cry2xpze", "app.bsky.graph.block:subject.uri") %} 153 154 <h3 class="route"><code>GET /links/count/distinct-dids</code></h3> 155
··· 149 </ul> 150 151 <p style="margin-bottom: 0"><strong>Try it:</strong></p> 152 + {% call try_it::get_backlinks_count("did:plc:vc7f4oafdgxsihk4cry2xpze", "app.bsky.graph.block:subject") %} 153 154 <h3 class="route"><code>GET /links/count/distinct-dids</code></h3> 155
constellation/templates/try-it-macros.html.j2

This file has not been changed.

+13 -3
lexicons/blue.microcosm/links/getBacklinks.json
··· 7 "description": "a list of records linking to any record, identity, or uri", 8 "parameters": { 9 "type": "params", 10 - "required": ["subject", "source"], 11 "properties": { 12 "subject": { 13 "type": "string", ··· 39 "encoding": "application/json", 40 "schema": { 41 "type": "object", 42 - "required": ["total", "records"], 43 "properties": { 44 "total": { 45 "type": "integer", ··· 62 }, 63 "linkRecord": { 64 "type": "object", 65 - "required": ["did", "collection", "rkey"], 66 "properties": { 67 "did": { 68 "type": "string",
··· 7 "description": "a list of records linking to any record, identity, or uri", 8 "parameters": { 9 "type": "params", 10 + "required": [ 11 + "subject", 12 + "source" 13 + ], 14 "properties": { 15 "subject": { 16 "type": "string", ··· 42 "encoding": "application/json", 43 "schema": { 44 "type": "object", 45 + "required": [ 46 + "total", 47 + "records" 48 + ], 49 "properties": { 50 "total": { 51 "type": "integer", ··· 68 }, 69 "linkRecord": { 70 "type": "object", 71 + "required": [ 72 + "did", 73 + "collection", 74 + "rkey" 75 + ], 76 "properties": { 77 "did": { 78 "type": "string",
lexicons/blue.microcosm/links/getBacklinksCount.json

This file has not been changed.

-109
lexicons/blue.microcosm/links/getManyToMany.json
··· 1 - { 2 - "lexicon": 1, 3 - "id": "blue.microcosm.links.getManyToMany", 4 - "defs": { 5 - "main": { 6 - "type": "query", 7 - "description": "Get records that link to a primary subject, grouped by the secondary subjects they also reference", 8 - "parameters": { 9 - "type": "params", 10 - "required": ["subject", "source", "pathToOther"], 11 - "properties": { 12 - "subject": { 13 - "type": "string", 14 - "format": "uri", 15 - "description": "the primary target being linked to (at-uri, did, or uri)" 16 - }, 17 - "source": { 18 - "type": "string", 19 - "description": "collection and path specification for the primary link (e.g., 'app.bsky.feed.like:subject.uri')" 20 - }, 21 - "pathToOther": { 22 - "type": "string", 23 - "description": "path to the secondary link in the many-to-many record (e.g., 'otherThing.uri')" 24 - }, 25 - "did": { 26 - "type": "array", 27 - "description": "filter links to those from specific users", 28 - "items": { 29 - "type": "string", 30 - "format": "did" 31 - } 32 - }, 33 - "otherSubject": { 34 - "type": "array", 35 - "description": "filter secondary links to specific subjects", 36 - "items": { 37 - "type": "string" 38 - } 39 - }, 40 - "limit": { 41 - "type": "integer", 42 - "minimum": 1, 43 - "maximum": 100, 44 - "default": 16, 45 - "description": "number of results to return" 46 - } 47 - } 48 - }, 49 - "output": { 50 - "encoding": "application/json", 51 - "schema": { 52 - "type": "object", 53 - "required": ["linking_records"], 54 - "properties": { 55 - "linking_records": { 56 - "type": "array", 57 - "items": { 58 - "type": "ref", 59 - "ref": "#recordsBySubject" 60 - } 61 - }, 62 - "cursor": { 63 - "type": "string", 64 - "description": "pagination cursor" 65 - } 66 - } 67 - } 68 - } 69 - }, 70 - "recordsBySubject": { 71 - "type": "object", 72 - "required": ["subject", "records"], 73 - "properties": { 74 - "subject": { 75 - "type": "string", 76 - "description": "the secondary subject that these records link to" 77 - }, 78 - "records": { 79 - "type": "array", 80 - "items": { 81 - "type": "ref", 82 - "ref": "#linkRecord" 83 - } 84 - } 85 - } 86 - }, 87 - "linkRecord": { 88 - "type": "object", 89 - "required": ["did", "collection", "rkey"], 90 - "description": "A record identifier consisting of a DID, collection, and record key", 91 - "properties": { 92 - "did": { 93 - "type": "string", 94 - "format": "did", 95 - "description": "the DID of the linking record's repository" 96 - }, 97 - "collection": { 98 - "type": "string", 99 - "format": "nsid", 100 - "description": "the collection of the linking record" 101 - }, 102 - "rkey": { 103 - "type": "string", 104 - "format": "record-key" 105 - } 106 - } 107 - } 108 - } 109 - }
···
+13 -3
lexicons/blue.microcosm/links/getManyToManyCounts.json
··· 7 "description": "count many-to-many relationships with secondary link paths", 8 "parameters": { 9 "type": "params", 10 - "required": ["subject", "source", "pathToOther"], 11 "properties": { 12 "subject": { 13 "type": "string", ··· 50 "encoding": "application/json", 51 "schema": { 52 "type": "object", 53 - "required": ["counts_by_other_subject"], 54 "properties": { 55 "counts_by_other_subject": { 56 "type": "array", ··· 69 }, 70 "countBySubject": { 71 "type": "object", 72 - "required": ["subject", "total", "distinct"], 73 "properties": { 74 "subject": { 75 "type": "string",
··· 7 "description": "count many-to-many relationships with secondary link paths", 8 "parameters": { 9 "type": "params", 10 + "required": [ 11 + "subject", 12 + "source", 13 + "pathToOther" 14 + ], 15 "properties": { 16 "subject": { 17 "type": "string", ··· 54 "encoding": "application/json", 55 "schema": { 56 "type": "object", 57 + "required": [ 58 + "counts_by_other_subject" 59 + ], 60 "properties": { 61 "counts_by_other_subject": { 62 "type": "array", ··· 75 }, 76 "countBySubject": { 77 "type": "object", 78 + "required": [ 79 + "subject", 80 + "total", 81 + "distinct" 82 + ], 83 "properties": { 84 "subject": { 85 "type": "string",
+1 -1
readme.md
··· 10 Tutorials, how-to guides, and client SDK libraries are all in the works for gentler on-ramps, but are not quite ready yet. But don't let that stop you! Hop in the [microcosm discord](https://discord.gg/tcDfe4PGVB), or post questions and tag [@bad-example.com](https://bsky.app/profile/bad-example.com) on Bluesky if you get stuck anywhere. 11 12 > [!tip] 13 - > This repository's primary home is moving to tangled: [@microcosm.blue/microcosm-rs](https://tangled.org/microcosm.blue/microcosm-rs). It will continue to be mirrored on [github](https://github.com/at-microcosm/microcosm-rs) for the forseeable future, and it's fine to open issues or pulls in either place! 14 15 16 🌌 [Constellation](./constellation/)
··· 10 Tutorials, how-to guides, and client SDK libraries are all in the works for gentler on-ramps, but are not quite ready yet. But don't let that stop you! Hop in the [microcosm discord](https://discord.gg/tcDfe4PGVB), or post questions and tag [@bad-example.com](https://bsky.app/profile/bad-example.com) on Bluesky if you get stuck anywhere. 11 12 > [!tip] 13 + > This repository's primary home is moving to tangled: [@microcosm.blue/microcosm-rs](https://tangled.sh/@microcosm.blue/microcosm-rs). It will continue to be mirrored on [github](https://github.com/at-microcosm/microcosm-rs) for the forseeable future, and it's fine to open issues or pulls in either place! 14 15 16 🌌 [Constellation](./constellation/)
+1 -1
slingshot/api-description.md
··· 90 - [🎇 Spacedust](https://spacedust.microcosm.blue/), a firehose of all social interactions 91 92 > [!success] 93 - > All microcosm projects are [open source](https://tangled.org/bad-example.com/microcosm-links). **You can help sustain Slingshot** and all of microcosm by becoming a [Github sponsor](https://github.com/sponsors/uniphil/) or a [Ko-fi supporter](https://ko-fi.com/bad_example)!
··· 90 - [🎇 Spacedust](https://spacedust.microcosm.blue/), a firehose of all social interactions 91 92 > [!success] 93 + > All microcosm projects are [open source](https://tangled.sh/@bad-example.com/microcosm-links). **You can help sustain Slingshot** and all of microcosm by becoming a [Github sponsor](https://github.com/sponsors/uniphil/) or a [Ko-fi supporter](https://ko-fi.com/bad_example)!

History

8 rounds 13 comments
sign up or login to add to the discussion
8 commits
expand
Add getCounts XRPC equivalent to REST /links/count
Modify backlinks counting XRPC endpoint name
Mark /links/count REST endpoint as deprecated
Remove .uri suffix
Reformat existing lexicons
Remove wrongly commited getManyToMany lexicon
Fix Git whitespace error in "hello" template
Format .prettierrc and fix Git whitespace error
expand 3 comments

I'm giving up on the whitespace issue...

max@max-mbpro ~/dev/microcosm-rs (xrpc_backlinks_count) $ git diff --check upstream/main
max@max-mbpro ~/dev/microcosm-rs (xrpc_backlinks_count) $

git-diff --checked doesn't indicate any errors either.

As far as I can tell this seems to be a confirmed Tangled issue

happy to do merging locally as needed!

merged. thanks!

closed without merging
7 commits
expand
Add getCounts XRPC equivalent to REST /links/count
Modify backlinks counting XRPC endpoint name
Mark /links/count REST endpoint as deprecated
Remove .uri suffix
Reformat existing lexicons
Remove wrongly commited getManyToMany lexicon
Fix Git whitespace error in "hello" template
expand 0 comments
6 commits
expand
Add getCounts XRPC equivalent to REST /links/count
Modify backlinks counting XRPC endpoint name
Mark /links/count REST endpoint as deprecated
Remove .uri suffix
Reformat existing lexicons
Remove wrongly commited getManyToMany lexicon
expand 0 comments
3 commits
expand
Add getCounts XRPC equivalent to REST /links/count
Modify backlinks counting XRPC endpoint name
Mark /links/count REST endpoint as deprecated
expand 4 comments

Tangled somehow complains about merge conflicts here, but I couldn't find any after rebasing on upstream/main again?!

very weird!

one tiny thing left: the source for blocks is app.bsky.graph.block:subject (no .uri suffix on the path) -- it's in the hello.html template.

i think some many-to-many order stuff ended up on this branch but i'm too tired for git rn.

if you don't get to it first i'm happy to fix the source and git stuff and merge when i can get to it :)

Sorry about the the m2m stuff that I didn't catch before opening the PR. I did clean this up again, and nothing belonging there should be remaining here; Addresses your above comment regarding the .uri suffix as well.

3 commits
expand
Add getCounts XRPC equivalent to REST /links/count
Modify backlinks counting XRPC endpoint name
Mark /links/count REST endpoint as deprecated
expand 0 comments
1 commit
expand
Add getCounts XRPC equivalent to REST /links/count
expand 6 comments

Had to do some rebasing and cleanup, but good to go now I think.

sweet!

(btw the local/ gitignore is there for doing local/rocks.test, but i'm fine adding it to the top-level gitignore too!)

i think links.getCounts is a little too broad -- what do you think of links.getBacklinksCount?

we also throw a deprecated warning under /links/count on the main page template, matching the one for /links.

it's weird but the whitespace in the forms in try-it-macros is significant (one of my moments of knowingly doing things the wrong way because i was bored, sorry!)

the new form for this endpoint needs little tweaking to match the others.

Ah got it. The rocks tests ended up cluttering the top-level directory so I just added them to .gitignore. I often keep a .local file in .gitignores to ignore whatever's supposed to stay in one's local copy and somehow assumed this had the same intent.

Changed the function and endpoint/method name as requested to get_backlinks_count/getBacklinksCount

The endpoint in the try-it-macro should now match the other existing ones down to how they're formatted with whitespace

3 commits
expand
Make metrics collection opt-in
Increase constellation response limits
Add getCounts XRPC equivalent to REST /links/count
expand 0 comments
7 commits
expand
Make metrics collection opt-in
Increase constellation response limits
wip: m2m
Add tests for new get_many_to_many query handler
Fix get_m2m_empty test
Replace tuple with RecordsBySubject struct
Add getCounts XRPC equivalent to REST /links/count
expand 0 comments