-
Notifications
You must be signed in to change notification settings - Fork 117
feat(laboratory/preflight-script): set request headers #6378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
cb800d3
fac4434
4084026
0c6d465
a21ea80
cd12274
fc2f8c9
b5f21b0
e24df4d
fbe7eee
998c566
28b8bbb
557bc4e
6db0e1c
52222f0
1212fc8
c890264
04a96fd
0b79e9f
09f15c6
e3c253b
15b7666
2622f99
525cb4e
3541df7
dfce1c4
c8a62a4
231f7ad
8f36d86
f806027
a9dbd2a
51290a6
9c13ef6
14329fc
4e0d1df
c963e46
960714e
f2e2ba8
e3692b8
285bf4d
d6bf9ad
51308fb
8c3606a
8e949f6
07b24e8
9ccb39f
5061b30
6f42223
8c75db9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export namespace Headers { | ||
/** | ||
* Take given HeadersInit and append it (mutating) into given Headers. | ||
* | ||
* @param headers - The Headers object to append to. | ||
* @param headersInit - The HeadersInit object to append from. | ||
*/ | ||
export const appendInit = (headers: Headers, headersInit: HeadersInit): void => { | ||
const newHeaders = new globalThis.Headers(headersInit); | ||
newHeaders.forEach((value, key) => { | ||
headers.append(key, value); | ||
}); | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * as Kit from './index'; | ||
|
||
export * from './never'; | ||
export * from './headers'; | ||
export * from './types/json'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* This case is impossible. | ||
* If it is, then there is a bug in our code. | ||
*/ | ||
export const neverCase = (value: never): never => { | ||
never(`Unhandled case: ${String(value)}`); | ||
}; | ||
|
||
/** | ||
* This code cannot be reached. | ||
* If it can be, then there is a bug in our code. | ||
*/ | ||
export const never: (contextMessage?: string) => never = contextMessage => { | ||
contextMessage = contextMessage ?? '(no additional context provided)'; | ||
throw new Error(`Something that should be impossible happened: ${contextMessage}`); | ||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have only just discovered https://github.com/graphql-hive/console/blob/231f7ad4af64342efde5cc14fb1a4baf73f9a6fc/packages/web/app/src/lib/preflight-sandbox/json.ts I will refactor this PR to use that instead of the one I introduced in the Also though, I propose the value of a centralized place for easily discoverable standard library like functionality. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export namespace JSON { | ||
export const encode = <value extends Value>(value: value): string => { | ||
jasonkuhrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return globalThis.JSON.stringify(value); | ||
}; | ||
|
||
export const encodePretty = <value extends Value>(value: value): string => { | ||
return globalThis.JSON.stringify(value, null, 2); | ||
jasonkuhrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export const decode = (value: string): Value => { | ||
return globalThis.JSON.parse(value); | ||
jasonkuhrt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export type Value = PrimitiveValue | NonPrimitiveValue; | ||
|
||
export type NonPrimitiveValue = { [key: string]: Value } | Array<Value>; | ||
|
||
export type PrimitiveValue = string | number | boolean | null; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.