kubo-rpc-client-esm-cjs
Version:
A client library for the Kubo RPC API
25 lines (21 loc) • 612 B
JavaScript
import { CID } from 'multiformats/cid'
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
export const createNew = configure(api => {
/**
* @type {import('../types').ObjectAPI["new"]}
*/
async function newObject (options = {}) {
const res = await api.post('object/new', {
signal: options.signal,
searchParams: toUrlSearchParams({
arg: options.template,
...options
}),
headers: options.headers
})
const { Hash } = await res.json()
return CID.parse(Hash)
}
return newObject
})