-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- copied lib and types from @urbit/api repo to gear/ - migrated webterm types (see: urbit/webterm#3) - rename S3 --> Storage
- Loading branch information
1 parent
55366c3
commit 9228e89
Showing
39 changed files
with
3,213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './types'; | ||
export * from './lib'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
|
||
import { Patp, Poke, Scry } from '../lib'; | ||
import { | ||
Contact, | ||
ContactUpdateAdd, | ||
ContactUpdateEdit, | ||
ContactUpdateRemove, | ||
ContactEditField, | ||
ContactShare, | ||
ContactUpdate, | ||
ContactUpdateAllowShips, | ||
ContactUpdateAllowGroup, | ||
ContactUpdateSetPublic | ||
} from './types'; | ||
|
||
export const CONTACT_UPDATE_VERSION = 0; | ||
|
||
const storeAction = <T extends ContactUpdate>(data: T, version: number = CONTACT_UPDATE_VERSION): Poke<T> => ({ | ||
app: 'contact-store', | ||
mark: `contact-update-${version}`, | ||
json: data | ||
}); | ||
|
||
export { storeAction as contactStoreAction }; | ||
|
||
export const addContact = (ship: Patp, contact: Contact): Poke<ContactUpdateAdd> => { | ||
contact['last-updated'] = Date.now(); | ||
|
||
return storeAction({ | ||
add: { ship, contact } | ||
}); | ||
}; | ||
|
||
export const removeContact = (ship: Patp): Poke<ContactUpdateRemove> => | ||
storeAction({ | ||
remove: { ship } | ||
}); | ||
|
||
export const share = (recipient: Patp, version: number = CONTACT_UPDATE_VERSION): Poke<ContactShare> => ({ | ||
app: 'contact-push-hook', | ||
mark: 'contact-share', | ||
json: { share: recipient } | ||
}); | ||
|
||
export const editContact = ( | ||
ship: Patp, | ||
editField: ContactEditField | ||
): Poke<ContactUpdateEdit> => | ||
storeAction({ | ||
edit: { | ||
ship, | ||
'edit-field': editField, | ||
timestamp: Date.now() | ||
} | ||
}); | ||
|
||
export const allowShips = ( | ||
ships: Patp[] | ||
): Poke<ContactUpdateAllowShips> => storeAction({ | ||
allow: { | ||
ships | ||
} | ||
}); | ||
|
||
export const allowGroup = ( | ||
ship: string, | ||
name: string | ||
): Poke<ContactUpdateAllowGroup> => storeAction({ | ||
allow: { | ||
group: { ship, name } | ||
} | ||
}); | ||
|
||
export const setPublic = ( | ||
setPublic: any | ||
): Poke<ContactUpdateSetPublic> => { | ||
return storeAction({ | ||
'set-public': setPublic | ||
}); | ||
}; | ||
|
||
export const retrieve = ( | ||
ship: string | ||
) => { | ||
const resource = { ship, name: '' }; | ||
return { | ||
app: 'contact-pull-hook', | ||
mark: 'pull-hook-action', | ||
json: { | ||
add: { | ||
resource, | ||
ship | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
export const fetchIsAllowed = ( | ||
entity: string, | ||
name: string, | ||
ship: string, | ||
personal: boolean | ||
): Scry => { | ||
const isPersonal = personal ? 'true' : 'false'; | ||
return { | ||
app: 'contact-store', | ||
path: `/is-allowed/${entity}/${name}/${ship}/${isPersonal}` | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Path, Patp } from '../lib'; | ||
import { Resource } from '../groups'; | ||
|
||
export type ContactUpdate = | ||
| ContactUpdateAdd | ||
| ContactUpdateRemove | ||
| ContactUpdateEdit | ||
| ContactUpdateInitial | ||
| ContactUpdateAllowGroup | ||
| ContactUpdateAllowShips | ||
| ContactUpdateSetPublic; | ||
|
||
export interface ContactUpdateAdd { | ||
add: { | ||
ship: Patp; | ||
contact: Contact; | ||
}; | ||
} | ||
|
||
export interface ContactUpdateRemove { | ||
remove: { | ||
ship: Patp; | ||
}; | ||
} | ||
|
||
export interface ContactUpdateEdit { | ||
edit: { | ||
ship: Patp; | ||
'edit-field': ContactEditField; | ||
timestamp: number; | ||
}; | ||
} | ||
|
||
export interface ContactUpdateAllowShips { | ||
allow: { | ||
ships: Patp[]; | ||
} | ||
} | ||
|
||
export interface ContactUpdateAllowGroup { | ||
allow: { | ||
group: Resource; | ||
} | ||
} | ||
|
||
export interface ContactUpdateSetPublic { | ||
'set-public': boolean; | ||
} | ||
|
||
export interface ContactShare { | ||
share: Patp; | ||
} | ||
|
||
export interface ContactUpdateInitial { | ||
initial: Rolodex; | ||
} | ||
|
||
export type Rolodex = { | ||
[p in Patp]: Contact; | ||
}; | ||
|
||
export type Contacts = Rolodex; | ||
|
||
export interface Contact { | ||
nickname: string; | ||
bio: string; | ||
status: string; | ||
color: string; | ||
avatar: string | null; | ||
cover: string | null; | ||
groups: Path[]; | ||
'last-updated': number; | ||
} | ||
|
||
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
declare module 'urbit-ob' { | ||
|
||
/** | ||
* Convert a @p-encoded string to a decimal-encoded string. | ||
*/ | ||
function patp2dec(name: string): string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './lib'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Poke, Scry } from '../lib'; | ||
import { Chad } from './types'; | ||
|
||
export function chadIsRunning(chad: Chad) { | ||
return 'glob' in chad || 'site' in chad; | ||
} | ||
|
||
export const scryCharges: Scry = { | ||
app: 'docket', | ||
path: '/charges' | ||
}; | ||
|
||
export const scryDockets: Scry = { | ||
app: 'docket', | ||
path: '/dockets' | ||
}; | ||
|
||
export const scryTreaties: Scry = { | ||
app: 'treaty', | ||
path: '/treaties' | ||
}; | ||
|
||
export const scryDefaultAlly: Scry = { | ||
app: 'treaty', | ||
path: '/default-ally' | ||
}; | ||
|
||
export const scryAllies: Scry = { | ||
app: 'treaty', | ||
path: '/allies' | ||
}; | ||
|
||
export const scryAllyTreaties = (ship: string): Scry => ({ | ||
app: 'treaty', | ||
path: `/treaties/${ship}` | ||
}); | ||
|
||
/** | ||
* Uninstall a desk, and remove docket | ||
*/ | ||
export function docketUninstall(desk: string): Poke<string> { | ||
return { | ||
app: 'docket', | ||
mark: 'docket-uninstall', | ||
json: desk | ||
}; | ||
} | ||
|
||
export function docketInstall(ship: string, desk: string): Poke<any> { | ||
return { | ||
app: 'docket', | ||
mark: 'docket-install', | ||
json: `${ship}/${desk}` | ||
}; | ||
} | ||
|
||
export function allyShip(ship: string): Poke<any> { | ||
return { | ||
app: 'treaty', | ||
mark: 'ally-update-0', | ||
json: { | ||
add: ship | ||
} | ||
}; | ||
} |
Oops, something went wrong.