1import UrbitApi from '@urbit/http-api';
2import type { ContactUpdate, Patp, Group, Contact, Rolodex } from '@urbit/api';
3import _get from 'lodash/get';
4import { compose } from 'lodash/fp';
6import { normalizeId } from './id';
8console.log(`Initializing Urbit API at ${Date()}`);
9const api: UrbitApi = new UrbitApi('', '', window.desk);
10api.ship = window.ship;
13export function scry<T = any>(path: string): Promise<T> {
14 return api.scry<T>({ app: 'astrolabe', path });
17export function getPoint(patp: string): Promise<any> {
18 return scry<any>(`/point/${patp}`);
21export function getSpawnedPoints(patp: string): Promise<any> {
22 return scry<any>(`/point/${patp}/spawned`);
25export function getPeers(): Promise<any> {
26 return scry<any>(`/peers`);
29export async function searchPoints(search: string): Promise<Patp[]> {
30 const { points } = await scry<any>(`/search/${search}`);
31 return points.map(normalizeId);
34export function getChartData(old = false): Promise<any> {
35 return scry<any>('/chart-data' + (old ? '-old' : ''));
38window['gcd'] = getChartData;
40export function getDoc(path: string): Promise<string> {
41 return scry<string>(`/doc/${path}`);
44export function initialContacts(json: ContactUpdate, contacts: Rolodex): Rolodex {
45 const data = _get(json, 'initial', false);
47 contacts = data.rolodex;
52export function addContact(json: ContactUpdate, contacts: Rolodex): Rolodex {
53 const data = _get(json, 'add', false);
55 contacts[data.ship] = data.contact;
60export function removeContact(json: ContactUpdate, contacts: Rolodex): Rolodex {
61 const data = _get(json, 'remove', false);
64 (data.ship in contacts)
66 delete contacts[data.ship];
71export function handleContactUpdateEvent(updateContacts) {
72 return ({ 'contact-update': contactUpdate }) => {
73 console.log(`received contact-update: ${Object.keys(contactUpdate)}`)
74 const reducers = [initialContacts, addContact, removeContact];
75 const reducer = compose(reducers.map(r => sta => r(contactUpdate, sta)));
76 updateContacts(reducer);
80export function subscribeToContacts(e: (data: any) => void): Promise<any> {
81 return api.subscribe({
84 event: handleContactUpdateEvent(e),
86 console.error(`Subscription to contact-store/all just get "err"`);
89 console.error(`Subscription to contact-store/all just get "quit"`)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list