mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-13 08:38:43 +03:00
@urbit/api: update graph pokes, scries
This commit is contained in:
parent
fb36238d07
commit
94bc24de5b
8
pkg/npm/api/deps.d.ts
vendored
Normal file
8
pkg/npm/api/deps.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
declare module "urbit-ob" {
|
||||
|
||||
/**
|
||||
* Convert a @p-encoded string to a decimal-encoded string.
|
||||
*/
|
||||
function patp2dec(name: string): string
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
import _ from 'lodash';
|
||||
import { GroupPolicy, makeResource, Resource, resourceFromPath } from '../groups';
|
||||
|
||||
import { deSig, unixToDa } from '../lib';
|
||||
import { decToUd, deSig, unixToDa, Scry } from '../lib';
|
||||
import { Enc, Path, Patp, PatpNoSig, Poke, Thread } from '../lib/types';
|
||||
import { Content, Graph, GraphChildrenPoke, GraphNode, GraphNodePoke, Post } from './types';
|
||||
import { patp2dec } from 'urbit-ob';
|
||||
|
||||
export const GRAPH_UPDATE_VERSION: number = 2;
|
||||
|
||||
@ -108,6 +109,12 @@ const hookAction = <T>(data: T, version: number = GRAPH_UPDATE_VERSION): Poke<T>
|
||||
json: data
|
||||
});
|
||||
|
||||
const dmAction = <T>(data: T): Poke<T> => ({
|
||||
app: 'dm-hook',
|
||||
mark: 'dm-hook-action',
|
||||
json: data
|
||||
});
|
||||
|
||||
export { hookAction as graphHookAction };
|
||||
|
||||
|
||||
@ -292,7 +299,35 @@ export const disableGroupFeed = (
|
||||
}
|
||||
});
|
||||
|
||||
export const removeNodes = (
|
||||
/**
|
||||
* Set dm-hook to screen new DMs or not
|
||||
*
|
||||
*/
|
||||
export const setScreen = (screen: boolean): Poke<any> => dmAction({ screen });
|
||||
|
||||
/**
|
||||
* Accept a pending DM request
|
||||
*
|
||||
* @param ship the ship to accept
|
||||
*/
|
||||
export const acceptDm = (ship: string) => dmAction({
|
||||
accept: ship
|
||||
});
|
||||
|
||||
/**
|
||||
* Decline a pending DM request
|
||||
*
|
||||
* @param ship the ship to accept
|
||||
*/
|
||||
export const declineDm = (ship: string) => dmAction({
|
||||
decline: ship
|
||||
});
|
||||
|
||||
/**
|
||||
* Remove posts from a set of indices
|
||||
*
|
||||
*/
|
||||
export const removePosts = (
|
||||
ship: Patp,
|
||||
name: string,
|
||||
indices: string[]
|
||||
@ -302,3 +337,172 @@ export const removeNodes = (
|
||||
indices
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Send a DM to a ship
|
||||
*
|
||||
* @param our sender
|
||||
* @param ship recipient
|
||||
* @param contents contents of message
|
||||
*/
|
||||
export const addDmMessage = (our: Patp, ship: Patp, contents: Content[]): Poke<any> => {
|
||||
const post = createPost(our, contents, `/${patp2dec(ship)}`);
|
||||
const node: GraphNode = {
|
||||
post,
|
||||
children: null
|
||||
};
|
||||
return {
|
||||
app: 'dm-hook',
|
||||
mark: `graph-update-${GRAPH_UPDATE_VERSION}`,
|
||||
json: {
|
||||
'add-nodes': {
|
||||
resource: { ship: our, name: 'dm-inbox' },
|
||||
nodes: {
|
||||
[post.index]: node
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const encodeIndex = (idx: string) => idx.split('/').map(decToUd).join('/');
|
||||
|
||||
/**
|
||||
* Fetch newest (larger keys) nodes in a graph under some index
|
||||
*
|
||||
* @param ship ship of graph
|
||||
* @param name name of graph
|
||||
* @param count number of nodes to load
|
||||
* @param index index to query
|
||||
*/
|
||||
export const getNewest = (
|
||||
ship: string,
|
||||
name: string,
|
||||
count: number,
|
||||
index = ''
|
||||
): Scry => ({
|
||||
app: 'graph-store',
|
||||
path: `/newest/${ship}/${name}/${count}/${encodeIndex(index)}`
|
||||
});
|
||||
|
||||
/**
|
||||
* Fetch nodes in a graph that are older (key is smaller) and direct
|
||||
* siblings of some index
|
||||
*
|
||||
* @param ship ship of graph
|
||||
* @param name name of graph
|
||||
* @param count number of nodes to load
|
||||
* @param index index to query
|
||||
*/
|
||||
export const getOlderSiblings = (
|
||||
ship: string,
|
||||
name: string,
|
||||
count: number,
|
||||
index: string
|
||||
): Scry => ({
|
||||
app: 'graph-store',
|
||||
path: `/node-siblings/older/${ship}/${name}/${count}${encodeIndex(index)}`
|
||||
});
|
||||
|
||||
/**
|
||||
* Fetch nodes in a graph that are younger (key is larger) and direct
|
||||
* siblings of some index
|
||||
*
|
||||
* @param ship ship of graph
|
||||
* @param name name of graph
|
||||
* @param count number of nodes to load
|
||||
* @param index index to query
|
||||
*/
|
||||
export const getYoungerSiblings = (
|
||||
ship: string,
|
||||
name: string,
|
||||
count: number,
|
||||
index: string
|
||||
): Scry => ({
|
||||
app: 'graph-store',
|
||||
path: `/node-siblings/younger/${ship}/${name}/${count}${encodeIndex(index)}`
|
||||
});
|
||||
|
||||
/**
|
||||
* Fetch all nodes in a graph under some index, without loading children
|
||||
*
|
||||
* @param ship ship of graph
|
||||
* @param name name of graph
|
||||
* @param index index to query
|
||||
*/
|
||||
export const getShallowChildren = (ship: string, name: string, index = '') => ({
|
||||
app: 'graph-store',
|
||||
path: `/shallow-children/${ship}/${name}${encodeIndex(index)}`
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Fetch newest nodes in a graph as a flat map, including children,
|
||||
* optionally starting at a specified key
|
||||
*
|
||||
* @param ship ship of graph
|
||||
* @param name name of graph
|
||||
* @param count number of nodes to load
|
||||
* @param start key to start at
|
||||
*
|
||||
*/
|
||||
export const getDeepOlderThan = (
|
||||
ship: string,
|
||||
name: string,
|
||||
count: number,
|
||||
start?: string
|
||||
) => ({
|
||||
app: 'graph-store',
|
||||
path: `/deep-nodes-older-than/${ship}/${name}/${count}/${start ? decToUd(start) : 'null'}`
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a flat map of a nodes ancestors and firstborn children
|
||||
*
|
||||
* @param ship ship of graph
|
||||
* @param name name of graph
|
||||
* @param index index to query
|
||||
*
|
||||
*/
|
||||
export const getFirstborn = (
|
||||
ship: string,
|
||||
name: string,
|
||||
index: string
|
||||
): Scry => ({
|
||||
app: 'graph-store',
|
||||
path: `/firstborn/${ship}/${name}/${encodeIndex(index)}`
|
||||
});
|
||||
|
||||
/**
|
||||
* Fetch a single node, and all it's children
|
||||
*
|
||||
* @param ship ship of graph
|
||||
* @param name name of graph
|
||||
* @param index index to query
|
||||
*
|
||||
*/
|
||||
export const getNode = (
|
||||
ship: string,
|
||||
name: string,
|
||||
index: string
|
||||
): Scry => ({
|
||||
app: 'graph-store',
|
||||
path: `/node/${ship}/${name}/${encodeIndex(index)}`
|
||||
});
|
||||
|
||||
/**
|
||||
* Fetch entire graph
|
||||
*
|
||||
* @param ship ship of graph
|
||||
* @param name name of graph
|
||||
*
|
||||
*/
|
||||
export const getGraph = (
|
||||
ship: string,
|
||||
name: string
|
||||
): Scry => ({
|
||||
app: 'graph-store',
|
||||
path: `/graph/${ship}/${name}`
|
||||
});
|
||||
|
31
pkg/npm/api/package-lock.json
generated
31
pkg/npm/api/package-lock.json
generated
@ -61,6 +61,11 @@
|
||||
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
|
||||
"dev": true
|
||||
},
|
||||
"bn.js": {
|
||||
"version": "4.12.0",
|
||||
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz",
|
||||
"integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA=="
|
||||
},
|
||||
"braces": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
|
||||
@ -174,6 +179,16 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
},
|
||||
"lodash.chunk": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz",
|
||||
"integrity": "sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw="
|
||||
},
|
||||
"lodash.isequal": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
|
||||
"integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
|
||||
},
|
||||
"normalize-path": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
||||
@ -251,6 +266,22 @@
|
||||
"integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==",
|
||||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.2.tgz",
|
||||
"integrity": "sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==",
|
||||
"dev": true
|
||||
},
|
||||
"urbit-ob": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/urbit-ob/-/urbit-ob-5.0.1.tgz",
|
||||
"integrity": "sha512-qGNAwu87XNkW3g8ah4fUwmh2EKXtsdhEbyEiE5qX4Op17rhLH3HSkvu8g9z+MhqX51Uz9sf8ktvqJj/IRwETIQ==",
|
||||
"requires": {
|
||||
"bn.js": "^4.11.8",
|
||||
"lodash.chunk": "^4.2.0",
|
||||
"lodash.isequal": "^4.5.0"
|
||||
}
|
||||
},
|
||||
"which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
|
@ -12,7 +12,8 @@
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"watch": "onchange './**/*.ts' -e './dist/**' -- npm run build",
|
||||
"build": "npm run clean && tsc -p tsconfig.json",
|
||||
"build": "npm run clean && npm run tsc",
|
||||
"tsc": "tsc -p tsconfig.json",
|
||||
"clean": "rm -rf dist/*"
|
||||
},
|
||||
"author": "",
|
||||
@ -23,9 +24,11 @@
|
||||
"@urbit/eslint-config": "^1.0.0",
|
||||
"big-integer": "^1.6.48",
|
||||
"immer": "^9.0.1",
|
||||
"lodash": "^4.17.20"
|
||||
"lodash": "^4.17.20",
|
||||
"urbit-ob": "^5.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"onchange": "^7.1.0"
|
||||
"onchange": "^7.1.0",
|
||||
"typescript": "^4.3.2"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user