urbit/api: bring inline with current userspace

This commit is contained in:
Liam Fitzgerald 2021-02-17 12:23:49 +10:00
parent 9d8be26fea
commit ad035b54f1
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
14 changed files with 147 additions and 181 deletions

View File

@ -1,25 +1,14 @@
import { Path, Patp } from "..";
import {Resource} from "groups/update";
export type ContactUpdate =
| ContactUpdateCreate
| ContactUpdateDelete
| ContactUpdateAdd
| ContactUpdateRemove
| ContactUpdateEdit
| ContactUpdateInitial
| ContactUpdateContacts;
interface ContactUpdateCreate {
create: Path;
}
interface ContactUpdateDelete {
delete: Path;
}
interface ContactUpdateAdd {
add: {
path: Path;
ship: Patp;
contact: Contact;
};
@ -27,7 +16,6 @@ interface ContactUpdateAdd {
interface ContactUpdateRemove {
remove: {
path: Path;
ship: Patp;
};
}
@ -36,50 +24,55 @@ interface ContactUpdateEdit {
edit: {
path: Path;
ship: Patp;
"edit-field": ContactEdit;
"edit-field": ContactEditField;
timestamp: number;
};
}
interface ContactUpdateAllowShips {
allow: {
ships: Patp[];
}
}
interface ContactUpdateAllowGroup {
allow: {
group: Path;
}
}
interface ContactUpdateSetPublic {
'set-public': boolean;
}
export interface ContactShare {
share: Patp;
}
interface ContactUpdateInitial {
initial: Rolodex;
}
interface ContactUpdateContacts {
contacts: {
path: Path;
contacts: Contacts;
};
}
//
type ContactAvatar = ContactAvatarUrl | ContactAvatarOcts;
export type Rolodex = {
[p in Path]: Contacts;
};
export type Contacts = {
[p in Patp]: Contact;
};
interface ContactAvatarUrl {
url: string;
}
interface ContactAvatarOcts {
octs: string;
}
export interface Contact {
nickname: string;
email: string;
phone: string;
website: string;
notes: string;
bio: string;
status: string;
color: string;
avatar: string | null;
cover: string | null;
groups: Path[];
'last-updated': number;
}
export type ContactEdit = {
[k in keyof Contact]: Contact[k];
type ContactKeys = keyof Contact;
export type ContactEditFieldPrim = Exclude<ContactKeys, "groups" | "last-updated">;
export type ContactEditField = Partial<Pick<Contact, ContactEditFieldPrim>> & {
'add-group'?: Resource;
'remove-group'?: Resource;
};

View File

@ -1,83 +1,50 @@
import { Enc, Path, Patp, Poke } from "..";
import { Contact, ContactEdit, ContactUpdateCreate, ContactUpdateEdit, ContactUpdateRemove } from "./index.d";
import { GroupPolicy, Resource } from "../groups/index.d"
import {
Contact,
ContactUpdateAdd,
ContactUpdateEdit,
ContactUpdateRemove,
ContactEditField,
ContactShare,
ContactUpdate,
} from "./index.d";
export const viewAction = <T>(data: T): Poke<T> => ({
app: 'contact-view',
mark: 'json',
json: data
export const storeAction = <T extends ContactUpdate>(data: T): Poke<T> => ({
app: "contact-store",
mark: "contact-action",
json: data,
});
export const hookAction = <T>(data: T): Poke<T> => ({
app: 'contact-hook',
mark: 'contact-action',
json: data
});
export const add = (ship: Patp, contact: Contact): Poke<ContactUpdateAdd> => {
contact["last-updated"] = Date.now();
export const create = (
name: string,
policy: Enc<GroupPolicy>,
title: string,
description: string
): Poke<ContactUpdateCreate> => viewAction({ // TODO which type is correct?
create: {
name,
policy,
title,
description
}
});
return storeAction({
add: { ship, contact },
});
};
export const share = (
recipient: Patp,
path: Patp,
ship: Patp,
contact: Contact
): Poke<any> => viewAction({ // TODO type
share: {
recipient,
path,
ship,
contact
}
});
export const remove = (ship: Patp): Poke<ContactUpdateRemove> =>
storeAction({
remove: { ship },
});
export const remove = (
path: Path,
ship: Patp
): Poke<ContactUpdateRemove> => viewAction({
remove: {
path,
ship
}
export const share = (recipient: Patp): Poke<ContactShare> => ({
app: "contact-push-hook",
mark: "contact-action",
json: { share: recipient },
});
export const edit = (
path: Path,
ship: Patp,
editField: ContactEdit
): Poke<ContactUpdateEdit> => hookAction({
edit: {
path,
ship,
'edit-field': editField
}
});
editField: ContactEditField
): Poke<ContactUpdateEdit> =>
storeAction({
edit: {
path,
ship,
"edit-field": editField,
timestamp: Date.now(),
},
});
export const invite = (
resource: Resource,
ship: Patp,
text: string = ''
): Poke<any> => viewAction({ // TODO type
invite: {
resource,
ship,
text
}
});
export const join = (
resource: Resource
): Poke<any> => viewAction({ // TODO type
join: resource
});

View File

@ -37,6 +37,15 @@ export interface Post {
"time-sent": number;
}
export interface GraphNodePoke {
post: Post;
children: GraphChildrenPoke | null;
}
export interface GraphChildrenPoke {
[k: string]: GraphNodePoke;
}
export interface GraphNode {
children: Graph;
post: Post;

View File

@ -1,20 +1,20 @@
import _ from 'lodash';
import { PatpNoSig, Patp, Poke, Thread, Path, Enc } from '..';
import { Content, GraphNode, Post } from './index.d';
import { Content, GraphNode, Post, GraphNodePoke, GraphChildrenPoke } from './index.d';
import { deSig, unixToDa } from '../lib/util';
import { makeResource, resourceFromPath } from '../groups/index';
import { GroupPolicy } from '../groups';
import { GroupPolicy } from '../groups/update.d';
export const createBlankNodeWithChildPost = (
ship: PatpNoSig,
parentIndex: string = '',
childIndex: string = '',
contents: Content[]
): GraphNode => {
): GraphNodePoke => {
const date = unixToDa(Date.now()).toString();
const nodeIndex = parentIndex + '/' + date;
const childGraph = {};
const childGraph: GraphChildrenPoke = {};
childGraph[childIndex] = {
post: {
author: `~${ship}`,
@ -253,7 +253,7 @@ export const addNode = (
let nodes = {};
nodes[node.post.index] = node;
return this.addNodes(ship, name, nodes);
return addNodes(ship, name, nodes);
}
export const addNodes = (

View File

@ -12,6 +12,7 @@ import {
Resource,
Tag
} from "./index.d";
import { GroupPolicy } from "./update";
export const proxyAction = <T>(data: T): Poke<T> => ({
app: 'group-push-hook',
@ -106,6 +107,11 @@ export function makeResource(ship: string, name:string) {
return { ship, name };
}
export const groupBunts = {
group: (): Group => ({ members: new Set(), tags: { role: {} }, hidden: false, policy: groupBunts.policy() }),
policy: (): GroupPolicy => ({ open: { banned: new Set(), banRanks: new Set() } })
};
export const joinError = ['no-perms', 'strange'] as const;
export const joinResult = ['done', ...joinError] as const;
export const joinProgress = ['start', 'added', ...joinResult] as const;

View File

@ -133,7 +133,7 @@ interface GroupUpdateRemoveTag {
removeTag: {
tag: Tag;
resource: Resource;
ships: PatpNoSig;
ships: PatpNoSig[];
};
}
@ -174,7 +174,4 @@ export type GroupUpdate =
export type GroupAction = Omit<GroupUpdate, 'initialGroup' | 'initial'>;
export const groupBunts = {
group: (): Group => ({ members: new Set(), tags: { role: {} }, hidden: false, policy: groupBunts.policy() }),
policy: (): GroupPolicy => ({ open: { banned: new Set(), banRanks: new Set() } })
};

View File

@ -1,6 +1,6 @@
import { Post } from "../graph/index.d";
import { GroupUpdate } from "../groups/index.d";
import { BigIntOrderedMap } from "~/logic/lib/BigIntOrderedMap";
import BigIntOrderedMap from "../lib/BigIntOrderedMap";
export type GraphNotifDescription = "link" | "comment" | "note" | "mention";

View File

@ -1,14 +1,21 @@
import { Serial, PatpNoSig, Path } from '..';
import { Resource } from '../groups';
import { Resource } from "../groups/update.d";
export type InviteUpdate =
InviteUpdateInitial
| InviteUpdateCreate
| InviteUpdateDelete
| InviteUpdateInvite
| InviteUpdateAccept
| InviteUpdateAccepted
| InviteUpdateDecline;
interface InviteUpdateAccept {
accept: {
term: string;
uid: Serial;
}
}
interface InviteUpdateInitial {
initial: Invites;
@ -16,19 +23,19 @@ interface InviteUpdateInitial {
interface InviteUpdateCreate {
create: {
path: Path;
term: string;
};
}
interface InviteUpdateDelete {
delete: {
path: Path;
term: string;
};
}
interface InviteUpdateInvite {
invite: {
path: Path;
term: string;
uid: Serial;
invite: Invite;
};
@ -36,14 +43,14 @@ interface InviteUpdateInvite {
interface InviteUpdateAccepted {
accepted: {
path: Path;
term: string;
uid: Serial;
};
}
interface InviteUpdateDecline {
decline: {
path: Path;
term: string;
uid: Serial;
};
}

View File

@ -1,7 +1,7 @@
import { InviteAction, InviteActionAccept, InviteActionDecline } from "./index.d";
import { InviteUpdate, InviteUpdateAccept, InviteUpdateDecline } from "./index.d";
import { Poke, Serial } from "..";
export const action = <T>(data: T): Poke<T> => ({
export const action = <T extends InviteUpdate>(data: T): Poke<T> => ({
app: 'invite-store',
mark: 'invite-action',
json: data
@ -10,7 +10,7 @@ export const action = <T>(data: T): Poke<T> => ({
export const accept = (
app: string,
uid: Serial
): Poke<InviteActionAccept> => action({
): Poke<InviteUpdateAccept> => action({
accept: {
term: app,
uid
@ -20,7 +20,7 @@ export const accept = (
export const decline = (
app: string,
uid: Serial
): Poke<InviteActionDecline> => action({
): Poke<InviteUpdateDecline> => action({
decline: {
term: app,
uid

View File

@ -2,6 +2,8 @@
* Martian embassy
*/
import BigIntOrderedMap from "./BigIntOrderedMap";
// an urbit style path rendered as string
export type Path = string;
@ -20,15 +22,6 @@ export type Jug<K,V> = Map<K,Set<V>>;
// name of app
export type AppName = 'chat' | 'link' | 'contacts' | 'publish' | 'graph';
export function getTagFromFrond<O>(frond: O): keyof O {
const tags = Object.keys(frond) as Array<keyof O>;
const tag = tags[0];
if(!tag) {
throw new Error("bad frond");
}
return tag;
}
export type ShipRank = 'czar' | 'king' | 'duke' | 'earl' | 'pawn';
export type Action = 'poke' | 'subscribe' | 'ack' | 'unsubscribe' | 'delete';
@ -48,6 +41,8 @@ export type Enc<S> =
{ [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;

View File

@ -140,7 +140,7 @@ export function cite(ship: string): string {
let patp = ship,
shortened = "";
if (patp === null || patp === "") {
return null;
return "";
}
if (patp.startsWith("~")) {
patp = patp.substr(1);

View File

@ -15,15 +15,15 @@ type ResourceAssociations = {
}
type MetadataUpdateAdd = {
add: Association;
add: AssociationPoke;
}
type MetadataUpdateUpdate = {
update: Association;
update: AssociationPoke;
}
type MetadataUpdateRemove = {
remove: Resource & {
remove: MdResource & {
group: Path;
}
}
@ -42,16 +42,22 @@ export type AppAssociations = {
[p in Path]: Association;
}
interface Resource {
interface MdResource {
resource: Path;
'app-name': AppName;
}
export type Association = Resource & {
export type Association = MdResource & {
group: Path;
metadata: Metadata;
};
export interface AssociationPoke {
group: Path;
resource: MdResource;
metadata: Metadata;
}
export interface Metadata {
color: string;
creator: Patp;

View File

@ -8,32 +8,19 @@ export const action = <T>(data: T): Poke<T> => ({
});
export const add = (
ship: PatpNoSig,
appName: AppName,
appPath: Path,
groupPath: Path,
title: string,
description: string,
dateCreated: string,
color: string,
moduleName: string
resource: string,
group: string,
metadata: Metadata,
): Poke<MetadataUpdateAdd> => {
const creator = `~${ship}`;
return action({
add: {
'group-path': groupPath,
group,
resource: {
'app-path': appPath,
resource,
'app-name': appName
},
metadata: {
title,
description,
color,
'date-created': dateCreated,
creator,
'module': moduleName
}
metadata
}
});
}
@ -41,15 +28,16 @@ export const add = (
export const update = (
association: Association,
newMetadata: Partial<Metadata>
): Poke<MetadataUpdateUpdate> => {
): Poke<MetadataUpdateAdd> => {
const { resource, metadata, group } = association;
return action({
add: {
'group-path': association['group-path'],
group,
resource: {
'app-path': association['app-path'],
resource,
'app-name': association['app-name'],
},
metadata: {...association.metadata, ...newMetadata }
metadata: {...metadata, ...newMetadata }
}
});
}

View File

@ -19,9 +19,7 @@
}
},
"include": [
"src/**/*"
"**/*"
],
"exclude": [
"node_modules",
]
"exclude": [ "node_modules" ]
}