MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / createFromUrl

Function createFromUrl

app/jsonDoc.server.ts:50–81  ·  view source on GitHub ↗
(
  url: URL,
  title?: string,
  options?: CreateJsonOptions
)

Source from the content-addressed store, hash-verified

48}
49
50export async function createFromUrl(
51 url: URL,
52 title?: string,
53 options?: CreateJsonOptions
54): Promise<JSONDocument> {
55 if (options?.injest) {
56 const response = await safeFetch(url.href);
57
58 if (!response.ok) {
59 throw new Error(`Failed to injest ${url.href}`);
60 }
61
62 return createFromRawJson(title || url.href, await response.text(), options);
63 }
64
65 const docId = createId();
66
67 const doc: JSONDocument = {
68 id: docId,
69 type: <const>"url",
70 url: url.href,
71 title: title ?? url.hostname,
72 readOnly: options?.readOnly ?? false,
73 };
74
75 await DOCUMENTS.put(docId, JSON.stringify(doc), {
76 expirationTtl: options?.ttl ?? undefined,
77 metadata: options?.metadata ?? undefined,
78 });
79
80 return doc;
81}
82
83export async function createFromRawJson(
84 filename: string,

Callers 3

loaderFunction · 0.90
loaderFunction · 0.90
createFromUrlOrRawJsonFunction · 0.85

Calls 3

safeFetchFunction · 0.85
createFromRawJsonFunction · 0.85
createIdFunction · 0.85

Tested by

no test coverage detected