-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make blueprint async * Make createBlueprint and createCodeSample async * Add formatCode support
- Loading branch information
Showing
11 changed files
with
638 additions
and
100 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Code, Context } from './schema.js' | ||
|
||
type CodeEntries = Entries<Code> | ||
type CodeEntry = NonNullable<CodeEntries[number]> | ||
|
||
export const formatCodeRecords = async ( | ||
code: Code, | ||
context: Context, | ||
): Promise<Code> => { | ||
const entries = Object.entries(code) as unknown as CodeEntries | ||
const formattedEntries = await Promise.all( | ||
entries.map(async (entry): Promise<CodeEntry> => { | ||
if (entry == null) throw new Error('Unexpected null code entry') | ||
return await formatCodeEntry(entry, context) | ||
}), | ||
) | ||
return Object.fromEntries(formattedEntries) | ||
} | ||
|
||
const formatCodeEntry = async ( | ||
[key, code]: CodeEntry, | ||
{ formatCode }: Context, | ||
): Promise<CodeEntry> => { | ||
if (code == null) throw new Error(`Unexpected null in code object for ${key}`) | ||
const [request, response] = await Promise.all([ | ||
await formatCode(code.request, code.request_syntax), | ||
await formatCode(code.response, code.response_syntax), | ||
]) | ||
return [ | ||
key, | ||
{ | ||
...code, | ||
request, | ||
response, | ||
}, | ||
] | ||
} | ||
|
||
type Entries<T> = Array< | ||
{ | ||
[K in keyof T]: [K, T[K]] | ||
}[keyof T] | ||
> |
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
Oops, something went wrong.