Skip to content

Commit

Permalink
docs: Add qs library types for in-page demos
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Jan 30, 2024
1 parent d4e6b3e commit 06d8c18
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/rest/api/RestEndpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class QSEndpoint<O extends RestGenerics = any> extends RestEndpoint<O> {

<EndpointPlayground input="/foo?a%5Bb%5D=c" init={{method: 'GET', headers: {'Content-Type': 'application/json'}}}>

```typescript title="QSEndpoint" collapsed {6}
```typescript title="QSEndpoint" collapsed {7}
import { RestEndpoint, RestGenerics } from '@data-client/rest';
import qs from 'qs';

Expand Down
57 changes: 57 additions & 0 deletions website/src/components/Playground/editor-types/qs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export = QueryString;
export as namespace qs;

declare namespace QueryString {
type defaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string;
type defaultDecoder = (str: string, decoder?: any, charset?: string) => string;

interface IStringifyOptions {
delimiter?: string | undefined;
strictNullHandling?: boolean | undefined;
skipNulls?: boolean | undefined;
encode?: boolean | undefined;
encoder?:
| ((str: any, defaultEncoder: defaultEncoder, charset: string, type: "key" | "value") => string)
| undefined;
filter?: Array<string | number> | ((prefix: string, value: any) => any) | undefined;
arrayFormat?: "indices" | "brackets" | "repeat" | "comma" | undefined;
indices?: boolean | undefined;
sort?: ((a: any, b: any) => number) | undefined;
serializeDate?: ((d: Date) => string) | undefined;
format?: "RFC1738" | "RFC3986" | undefined;
encodeValuesOnly?: boolean | undefined;
addQueryPrefix?: boolean | undefined;
allowDots?: boolean | undefined;
charset?: "utf-8" | "iso-8859-1" | undefined;
charsetSentinel?: boolean | undefined;
}

interface IParseOptions {
comma?: boolean | undefined;
delimiter?: string | RegExp | undefined;
depth?: number | false | undefined;
decoder?:
| ((str: string, defaultDecoder: defaultDecoder, charset: string, type: "key" | "value") => any)
| undefined;
arrayLimit?: number | undefined;
parseArrays?: boolean | undefined;
allowDots?: boolean | undefined;
plainObjects?: boolean | undefined;
allowPrototypes?: boolean | undefined;
allowSparse?: boolean | undefined;
parameterLimit?: number | undefined;
strictNullHandling?: boolean | undefined;
ignoreQueryPrefix?: boolean | undefined;
charset?: "utf-8" | "iso-8859-1" | undefined;
charsetSentinel?: boolean | undefined;
interpretNumericEntities?: boolean | undefined;
}

interface ParsedQs {
[key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];
}

function stringify(obj: any, options?: IStringifyOptions): string;
function parse(str: string, options?: IParseOptions & { decoder?: never | undefined }): ParsedQs;
function parse(str: string | Record<string, string>, options?: IParseOptions): { [key: string]: unknown };
}
9 changes: 8 additions & 1 deletion website/src/components/Playground/monaco-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ if (
import(
/* webpackChunkName: 'uuidDTS', webpackPreload: true */ '!!raw-loader?esModule=false!./editor-types/uuid.d.ts'
),
import(
/* webpackChunkName: 'qsDTS', webpackPreload: true */ '!!raw-loader?esModule=false!./editor-types/qs.d.ts'
),
...rhDeps.map(
dep =>
import(
Expand All @@ -221,7 +224,7 @@ if (
]).then(([mPromise, ...settles]) => {
if (mPromise.status !== 'fulfilled' || !mPromise.value) return;
const monaco = mPromise.value;
const [react, bignumber, temporal, uuid, ...rhLibs] = settles.map(
const [react, bignumber, temporal, uuid, qs, ...rhLibs] = settles.map(
result => (result.status === 'fulfilled' ? result.value.default : ''),
);

Expand Down Expand Up @@ -307,6 +310,10 @@ if (
`declare module "uuid" { ${uuid} }`,
'file:///node_modules/@types/uuid/index.d.ts',
);
monaco.languages.typescript.typescriptDefaults.addExtraLib(
`declare module "qs" { ${qs} }`,
'file:///node_modules/@types/qs/index.d.ts',
);
monaco.languages.typescript.typescriptDefaults.addExtraLib(
`declare globals { ${react} }`,
);
Expand Down

0 comments on commit 06d8c18

Please sign in to comment.