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 getLockedSpawnedPoints(patp: string): Promise<any> {
28 return scry<any>(`/point/${patp}/spawned/locked`);
31export function getUnlockedSpawnedPoints(patp: string): Promise<any> {
32 return scry<any>(`/point/${patp}/spawned/unlocked`);
35export function getPeers(): Promise<any> {
36 return scry<any>(`/peers`);
39export async function searchPoints(search: string, mode: ('patp' | 'sigil')): Promise<Patp[]> {
40 const { points } = await scry<any>(`/search/${mode}/${search}`);
41 return points.map(normalizeId);
44export function getChartData(old = false): Promise<any> {
45 return scry<any>('/chart-data' + (old ? '-old' : ''));
48window['gcd'] = getChartData;
50export function getDoc(path: string): Promise<string> {
51 return scry<string>(`/doc/${path}`);
54export function initialContacts(json: ContactUpdate, contacts: Rolodex): Rolodex {
55 const data = _get(json, 'initial', false);
57 contacts = data.rolodex;
62export function addContact(json: ContactUpdate, contacts: Rolodex): Rolodex {
63 const data = _get(json, 'add', false);
65 contacts[data.ship] = data.contact;
70export function removeContact(json: ContactUpdate, contacts: Rolodex): Rolodex {
71 const data = _get(json, 'remove', false);
74 (data.ship in contacts)
76 delete contacts[data.ship];
81export function handleContactUpdateEvent(updateContacts) {
82 return ({ 'contact-update': contactUpdate }) => {
83 console.log(`received contact-update: ${Object.keys(contactUpdate)}`)
84 const reducers = [initialContacts, addContact, removeContact];
85 const reducer = compose(reducers.map(r => sta => r(contactUpdate, sta)));
86 updateContacts(reducer);
90export function subscribeToContacts(e: (data: any) => void): Promise<any> {
91 return api.subscribe({
94 event: handleContactUpdateEvent(e),
96 console.error(`Subscription to contact-store/all just get "err"`);
99 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