MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / postCommit

Function postCommit

lib/src/client.ts:90–113  ·  view source on GitHub ↗
(
  commit: Commit,
  /** URL to post to, e.g. https://atomicdata.dev/commit */
  endpoint: string,
)

Source from the content-addressed store, hash-verified

88
89/** Posts a Commit to some endpoint */
90export async function postCommit(
91 commit: Commit,
92 /** URL to post to, e.g. https://atomicdata.dev/commit */
93 endpoint: string,
94): Promise<string> {
95 const serialized = serializeDeterministically(commit);
96 const requestHeaders: HeadersInit = new Headers();
97 requestHeaders.set('Content-Type', 'application/ad+json');
98 let response = null;
99 try {
100 response = await fetch(endpoint, {
101 headers: requestHeaders,
102 method: 'POST',
103 body: serialized,
104 });
105 } catch (e) {
106 throw new Error(`Posting Commit to ${endpoint} failed: ${e}`);
107 }
108 const body = await response.text();
109 if (response.status !== 200) {
110 throw new Error(body);
111 }
112 return body;
113}
114
115/** Throws an error if the URL is not valid */
116export function tryValidURL(subject: string): void {

Callers 2

destroyMethod · 0.90
saveMethod · 0.90

Calls 2

setMethod · 0.80

Tested by

no test coverage detected