-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d6b859
commit 8750efa
Showing
5 changed files
with
69 additions
and
19 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
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
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
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 |
---|---|---|
@@ -1,18 +1,69 @@ | ||
/* eslint-disable */ | ||
// webrpc-sse-chat v1.0.0 e64bf9372e2faa45da9d449e8ea108dc0597a98d | ||
// webrpc-sse-chat v1.0.0 a799dc63b082644f5d003c8881424546aee23a2c | ||
// -- | ||
// Code generated by webrpc-gen@v0.19.3 with ../../ generator. DO NOT EDIT. | ||
// Code generated by webrpc-gen@v0.20.3-1-gf6584bc with ../../ generator. DO NOT EDIT. | ||
// | ||
// webrpc-gen -schema=service.ridl -target=../../ -client -out=./webapp/client.gen.ts | ||
|
||
export const WebrpcHeader = "Webrpc" | ||
|
||
export const WebrpcHeaderValue = "[email protected];@unknown;[email protected]" | ||
|
||
// WebRPC description and code-gen version | ||
export const WebRPCVersion = "v1" | ||
|
||
// Schema version of your RIDL schema | ||
export const WebRPCSchemaVersion = "v1.0.0" | ||
|
||
// Schema hash generated from your RIDL schema | ||
export const WebRPCSchemaHash = "e64bf9372e2faa45da9d449e8ea108dc0597a98d" | ||
export const WebRPCSchemaHash = "a799dc63b082644f5d003c8881424546aee23a2c" | ||
|
||
type WebrpcGenVersions = { | ||
webrpcGenVersion: string; | ||
codeGenName: string; | ||
codeGenVersion: string; | ||
schemaName: string; | ||
schemaVersion: string; | ||
}; | ||
|
||
export function VersionFromHeader(headers: Headers): WebrpcGenVersions | null { | ||
const headerValue = headers.get(WebrpcHeader); | ||
if (!headerValue) { | ||
throw new Error("header is empty or missing"); | ||
} | ||
|
||
return parseWebrpcGenVersions(headerValue); | ||
} | ||
|
||
function parseWebrpcGenVersions(header: string): WebrpcGenVersions { | ||
const versions = header.split(";"); | ||
if (versions.length < 3) { | ||
throw new Error(`expected at least 3 parts while parsing webrpc header: ${header}`); | ||
} | ||
|
||
const [_, webrpcGenVersion] = versions[0].split("@"); | ||
if (!webrpcGenVersion) { | ||
throw new Error(`webrpc gen version could not be parsed from: ${versions[0]}`); | ||
} | ||
|
||
const [tmplTarget, tmplVersion] = versions[1].split("@"); | ||
if (!tmplTarget || !tmplVersion) { | ||
throw new Error(`tmplTarget and tmplVersion could not be parsed from: ${versions[1]}`); | ||
} | ||
|
||
const [schemaName, schemaVersion] = versions[2].split("@"); | ||
if (!schemaName || !schemaVersion) { | ||
throw new Error(`schema name and schema version could not be parsed from: ${versions[2]}`); | ||
} | ||
|
||
return { | ||
webrpcGenVersion, | ||
codeGenName: tmplTarget, | ||
codeGenVersion: tmplVersion, | ||
schemaName, | ||
schemaVersion, | ||
}; | ||
} | ||
|
||
// | ||
// Types | ||
|
@@ -233,9 +284,12 @@ const sseResponse = async ( | |
|
||
|
||
const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { | ||
const headers = { ...headers, 'Content-Type': 'application/json' } | ||
headers[WebrpcHeader] = WebrpcHeaderValue | ||
|
||
return { | ||
method: 'POST', | ||
headers: { ...headers, 'Content-Type': 'application/json' }, | ||
headers: headers, | ||
body: JSON.stringify(body || {}), | ||
signal | ||
} | ||
|
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