mirror of
https://github.com/urbit/shrub.git
synced 2024-12-24 20:47:27 +03:00
63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
/**
|
|
* Martian embassy
|
|
*/
|
|
|
|
import BigIntOrderedMap from "./BigIntOrderedMap";
|
|
|
|
// an urbit style path rendered as string
|
|
export type Path = string;
|
|
|
|
// patp including leading sig
|
|
export type Patp = string;
|
|
|
|
// patp excluding leading sig
|
|
export type PatpNoSig = string;
|
|
|
|
// @uvH encoded string
|
|
export type Serial = string;
|
|
|
|
// jug from hoon
|
|
export type Jug<K,V> = Map<K,Set<V>>;
|
|
|
|
// name of app
|
|
export type AppName = 'chat' | 'link' | 'contacts' | 'publish' | 'graph';
|
|
|
|
export type ShipRank = 'czar' | 'king' | 'duke' | 'earl' | 'pawn';
|
|
|
|
export type Action = 'poke' | 'subscribe' | 'ack' | 'unsubscribe' | 'delete';
|
|
|
|
|
|
export type SetElement<S> = S extends Set<(infer T)> ? T : never;
|
|
export type MapKey<M> = M extends Map<(infer K), any> ? K : never;
|
|
export type MapValue<M> = M extends Map<any, (infer V)> ? V : never;
|
|
|
|
/**
|
|
* Turns sets into arrays and maps into objects so we can send them over the wire
|
|
*/
|
|
export type Enc<S> =
|
|
S extends Set<any> ?
|
|
Enc<SetElement<S>>[] :
|
|
S extends Map<string, any> ?
|
|
{ [s: string]: Enc<MapValue<S>> } :
|
|
S extends object ?
|
|
{ [K in keyof S]: Enc<S[K]> } :
|
|
S extends BigIntOrderedMap<infer T> ?
|
|
{ [index: string]: T } :
|
|
S;
|
|
|
|
export type Mark = string;
|
|
|
|
export interface Poke<Action> {
|
|
ship?: string; // This should be handled by the http library, but is part of the spec
|
|
app: string;
|
|
mark: Mark;
|
|
json: Action;
|
|
}
|
|
|
|
export interface Thread<Action> {
|
|
inputMark: string;
|
|
outputMark: string;
|
|
threadName: string;
|
|
body: Action;
|
|
}
|