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;
15export function scry<T = any>(path: string): Promise<T> {
16 return api.scry<T>({ app: 'astrolabe', path });
19export function getPoint(patp: string): Promise<any> {
20 return scry<any>(`/point/${patp}`);
23export function getSpawnedPoints(patp: string): Promise<any> {
24 return scry<any>(`/point/${patp}/spawned`);
27export function getPeers(): Promise<any> {
28 return scry<any>(`/peers`);
31export async function searchPoints(search: string, mode: ('patp' | 'sigil')): Promise<Patp[]> {
32 const { points } = await scry<any>(`/search/${mode}/${search}`);
33 return points.map(normalizeId);
36export function getChartData(old = false): Promise<any> {
37 return scry<any>('/chart-data' + (old ? '-old' : ''));
40window['gcd'] = getChartData;
42export function getDoc(path: string): Promise<string> {
43 return scry<string>(`/doc/${path}`);
46export function initialContacts(json: ContactUpdate, contacts: Rolodex): Rolodex {
47 const data = _get(json, 'initial', false);
49 contacts = data.rolodex;
54export function addContact(json: ContactUpdate, contacts: Rolodex): Rolodex {
55 const data = _get(json, 'add', false);
57 contacts[data.ship] = data.contact;
62export function removeContact(json: ContactUpdate, contacts: Rolodex): Rolodex {
63 const data = _get(json, 'remove', false);
66 (data.ship in contacts)
68 delete contacts[data.ship];
73export function handleContactUpdateEvent(updateContacts) {
74 return ({ 'contact-update': contactUpdate }) => {
75 console.log(`received contact-update: ${Object.keys(contactUpdate)}`)
76 const reducers = [initialContacts, addContact, removeContact];
77 const reducer = compose(reducers.map(r => sta => r(contactUpdate, sta)));
78 updateContacts(reducer);
82export function subscribeToContacts(e: (data: any) => void): Promise<any> {
83 return api.subscribe({
86 event: handleContactUpdateEvent(e),
88 console.error(`Subscription to contact-store/all just get "err"`);
91 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