zudoku 0.3.0-dev.77 → 0.3.0-dev.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/validators/validate.d.ts +130 -130
- package/dist/lib/components/DevPortal.js +11 -2
- package/dist/lib/components/DevPortal.js.map +1 -1
- package/dist/lib/components/Heading.d.ts +1 -1
- package/dist/lib/core/plugins.d.ts +3 -0
- package/dist/lib/core/plugins.js +1 -0
- package/dist/lib/core/plugins.js.map +1 -1
- package/dist/lib/plugins/openapi/PlaygroundDialogWrapper.d.ts +2 -1
- package/dist/lib/plugins/openapi/PlaygroundDialogWrapper.js +8 -16
- package/dist/lib/plugins/openapi/PlaygroundDialogWrapper.js.map +1 -1
- package/dist/lib/plugins/openapi/Sidecar.js +18 -1
- package/dist/lib/plugins/openapi/Sidecar.js.map +1 -1
- package/dist/lib/plugins/openapi/graphql/gql.d.ts +6 -6
- package/dist/lib/plugins/openapi/graphql/gql.js +1 -1
- package/dist/lib/plugins/openapi/graphql/gql.js.map +1 -1
- package/dist/lib/plugins/openapi/graphql/graphql.d.ts +15 -15
- package/dist/lib/plugins/openapi/graphql/graphql.js +67 -67
- package/dist/lib/plugins/openapi/graphql/graphql.js.map +1 -1
- package/dist/lib/plugins/openapi/index.js +8 -0
- package/dist/lib/plugins/openapi/index.js.map +1 -1
- package/dist/lib/plugins/openapi/playground/PathParams.d.ts +2 -3
- package/dist/lib/plugins/openapi/playground/PathParams.js +3 -4
- package/dist/lib/plugins/openapi/playground/PathParams.js.map +1 -1
- package/dist/lib/plugins/openapi/playground/Playground.d.ts +22 -10
- package/dist/lib/plugins/openapi/playground/Playground.js +37 -25
- package/dist/lib/plugins/openapi/playground/Playground.js.map +1 -1
- package/dist/lib/plugins/openapi/playground/PlaygroundDialog.d.ts +2 -1
- package/dist/lib/plugins/openapi/playground/PlaygroundDialog.js +1 -1
- package/dist/lib/plugins/openapi/playground/PlaygroundDialog.js.map +1 -1
- package/dist/lib/plugins/openapi/playground/QueryParams.d.ts +3 -2
- package/dist/lib/plugins/openapi/playground/QueryParams.js +10 -5
- package/dist/lib/plugins/openapi/playground/QueryParams.js.map +1 -1
- package/dist/lib/util/fetchTimeout.d.ts +1 -0
- package/dist/lib/util/fetchTimeout.js +14 -0
- package/dist/lib/util/fetchTimeout.js.map +1 -0
- package/lib/{CategoryHeading-D0V23fMT.js → CategoryHeading-DCmchnA1.js} +2 -2
- package/lib/{CategoryHeading-D0V23fMT.js.map → CategoryHeading-DCmchnA1.js.map} +1 -1
- package/lib/{Combination-CgxP9BB4.js → Combination-BIdpLnWg.js} +27 -33
- package/lib/Combination-BIdpLnWg.js.map +1 -0
- package/lib/DeveloperHint-DQVwIery.js +10 -0
- package/lib/DeveloperHint-DQVwIery.js.map +1 -0
- package/lib/{Input-BcZoDid4.js → Input-qyZciIJp.js} +3 -3
- package/lib/{Input-BcZoDid4.js.map → Input-qyZciIJp.js.map} +1 -1
- package/lib/{Markdown-IsabnbGN.js → Markdown-QsZ-PHET.js} +3 -3
- package/lib/{Markdown-IsabnbGN.js.map → Markdown-QsZ-PHET.js.map} +1 -1
- package/lib/{MdxPage-B1B2Inj5.js → MdxPage-V4FCB0C_.js} +3 -3
- package/lib/{MdxPage-B1B2Inj5.js.map → MdxPage-V4FCB0C_.js.map} +1 -1
- package/lib/OperationList-qfNEBPAx.js +4397 -0
- package/lib/OperationList-qfNEBPAx.js.map +1 -0
- package/lib/{Route-D0Ub80Oa.js → Route-CogU1ofM.js} +2 -2
- package/lib/{Route-D0Ub80Oa.js.map → Route-CogU1ofM.js.map} +1 -1
- package/lib/{SlotletProvider-CJXWb2gw.js → SlotletProvider-D_Vz-7c_.js} +4 -4
- package/lib/{SlotletProvider-CJXWb2gw.js.map → SlotletProvider-D_Vz-7c_.js.map} +1 -1
- package/lib/Spinner-yPSFgoZ8.js +244 -0
- package/lib/Spinner-yPSFgoZ8.js.map +1 -0
- package/lib/index-BpO_SgPQ.js +124 -0
- package/lib/index-BpO_SgPQ.js.map +1 -0
- package/lib/index-DccqEFTy.js +1878 -0
- package/lib/index-DccqEFTy.js.map +1 -0
- package/lib/{urql-DMlBWUKL.js → urql-DrBfkb92.js} +2 -3
- package/lib/{urql-DMlBWUKL.js.map → urql-DrBfkb92.js.map} +1 -1
- package/lib/zudoku.components.js +352 -348
- package/lib/zudoku.components.js.map +1 -1
- package/lib/zudoku.openapi-worker.js +1 -1
- package/lib/zudoku.plugin-api-keys.js +7 -6
- package/lib/zudoku.plugin-api-keys.js.map +1 -1
- package/lib/zudoku.plugin-custom-page.js +1 -1
- package/lib/zudoku.plugin-markdown.js +1 -1
- package/lib/zudoku.plugin-openapi.js +5 -4
- package/lib/zudoku.plugin-openapi.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/components/DevPortal.tsx +14 -5
- package/src/lib/core/plugins.ts +7 -0
- package/src/lib/plugins/openapi/PlaygroundDialogWrapper.tsx +9 -17
- package/src/lib/plugins/openapi/Sidecar.tsx +23 -1
- package/src/lib/plugins/openapi/graphql/gql.ts +8 -8
- package/src/lib/plugins/openapi/graphql/graphql.ts +80 -80
- package/src/lib/plugins/openapi/index.tsx +15 -0
- package/src/lib/plugins/openapi/playground/PathParams.tsx +14 -20
- package/src/lib/plugins/openapi/playground/Playground.tsx +69 -45
- package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +8 -6
- package/src/lib/plugins/openapi/playground/QueryParams.tsx +86 -72
- package/src/lib/util/fetchTimeout.tsx +21 -0
- package/lib/Combination-CgxP9BB4.js.map +0 -1
- package/lib/OperationList-B2nsuf1v.js +0 -5471
- package/lib/OperationList-B2nsuf1v.js.map +0 -1
- package/lib/Spinner-BhtSoFka.js +0 -359
- package/lib/Spinner-BhtSoFka.js.map +0 -1
- package/lib/index-BC2Ob2BR.js +0 -727
- package/lib/index-BC2Ob2BR.js.map +0 -1
|
@@ -57,7 +57,7 @@ export type MediaTypeObject = {
|
|
|
57
57
|
encoding?: Maybe<Array<EncodingItem>>;
|
|
58
58
|
examples?: Maybe<Array<ExampleItem>>;
|
|
59
59
|
mediaType: Scalars["String"]["output"];
|
|
60
|
-
schema
|
|
60
|
+
schema?: Maybe<Scalars["JSON"]["output"]>;
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
export type OperationItem = {
|
|
@@ -163,16 +163,6 @@ export type TagItem = {
|
|
|
163
163
|
name: Scalars["String"]["output"];
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
-
export type GetServerQueryQueryVariables = Exact<{
|
|
167
|
-
input: Scalars["JSON"]["input"];
|
|
168
|
-
type: SchemaType;
|
|
169
|
-
}>;
|
|
170
|
-
|
|
171
|
-
export type GetServerQueryQuery = {
|
|
172
|
-
__typename?: "Query";
|
|
173
|
-
schema: { __typename?: "Schema"; url: string };
|
|
174
|
-
};
|
|
175
|
-
|
|
176
166
|
export type OperationsFragmentFragment = {
|
|
177
167
|
__typename?: "OperationItem";
|
|
178
168
|
slug: string;
|
|
@@ -206,7 +196,7 @@ export type OperationsFragmentFragment = {
|
|
|
206
196
|
content?: Array<{
|
|
207
197
|
__typename?: "MediaTypeObject";
|
|
208
198
|
mediaType: string;
|
|
209
|
-
schema
|
|
199
|
+
schema?: any | null;
|
|
210
200
|
encoding?: Array<{ __typename?: "EncodingItem"; name: string }> | null;
|
|
211
201
|
}> | null;
|
|
212
202
|
} | null;
|
|
@@ -218,7 +208,7 @@ export type OperationsFragmentFragment = {
|
|
|
218
208
|
content?: Array<{
|
|
219
209
|
__typename?: "MediaTypeObject";
|
|
220
210
|
mediaType: string;
|
|
221
|
-
schema
|
|
211
|
+
schema?: any | null;
|
|
222
212
|
encoding?: Array<{ __typename?: "EncodingItem"; name: string }> | null;
|
|
223
213
|
}> | null;
|
|
224
214
|
}>;
|
|
@@ -252,6 +242,16 @@ export type AllOperationsQuery = {
|
|
|
252
242
|
};
|
|
253
243
|
};
|
|
254
244
|
|
|
245
|
+
export type GetServerQueryQueryVariables = Exact<{
|
|
246
|
+
input: Scalars["JSON"]["input"];
|
|
247
|
+
type: SchemaType;
|
|
248
|
+
}>;
|
|
249
|
+
|
|
250
|
+
export type GetServerQueryQuery = {
|
|
251
|
+
__typename?: "Query";
|
|
252
|
+
schema: { __typename?: "Schema"; url: string };
|
|
253
|
+
};
|
|
254
|
+
|
|
255
255
|
export type GetCategoriesQueryVariables = Exact<{
|
|
256
256
|
input: Scalars["JSON"]["input"];
|
|
257
257
|
type: SchemaType;
|
|
@@ -423,73 +423,6 @@ export const OperationsFragmentFragmentDoc = {
|
|
|
423
423
|
},
|
|
424
424
|
],
|
|
425
425
|
} as unknown as DocumentNode<OperationsFragmentFragment, unknown>;
|
|
426
|
-
export const GetServerQueryDocument = {
|
|
427
|
-
kind: "Document",
|
|
428
|
-
definitions: [
|
|
429
|
-
{
|
|
430
|
-
kind: "OperationDefinition",
|
|
431
|
-
operation: "query",
|
|
432
|
-
name: { kind: "Name", value: "getServerQuery" },
|
|
433
|
-
variableDefinitions: [
|
|
434
|
-
{
|
|
435
|
-
kind: "VariableDefinition",
|
|
436
|
-
variable: {
|
|
437
|
-
kind: "Variable",
|
|
438
|
-
name: { kind: "Name", value: "input" },
|
|
439
|
-
},
|
|
440
|
-
type: {
|
|
441
|
-
kind: "NonNullType",
|
|
442
|
-
type: { kind: "NamedType", name: { kind: "Name", value: "JSON" } },
|
|
443
|
-
},
|
|
444
|
-
},
|
|
445
|
-
{
|
|
446
|
-
kind: "VariableDefinition",
|
|
447
|
-
variable: { kind: "Variable", name: { kind: "Name", value: "type" } },
|
|
448
|
-
type: {
|
|
449
|
-
kind: "NonNullType",
|
|
450
|
-
type: {
|
|
451
|
-
kind: "NamedType",
|
|
452
|
-
name: { kind: "Name", value: "SchemaType" },
|
|
453
|
-
},
|
|
454
|
-
},
|
|
455
|
-
},
|
|
456
|
-
],
|
|
457
|
-
selectionSet: {
|
|
458
|
-
kind: "SelectionSet",
|
|
459
|
-
selections: [
|
|
460
|
-
{
|
|
461
|
-
kind: "Field",
|
|
462
|
-
name: { kind: "Name", value: "schema" },
|
|
463
|
-
arguments: [
|
|
464
|
-
{
|
|
465
|
-
kind: "Argument",
|
|
466
|
-
name: { kind: "Name", value: "input" },
|
|
467
|
-
value: {
|
|
468
|
-
kind: "Variable",
|
|
469
|
-
name: { kind: "Name", value: "input" },
|
|
470
|
-
},
|
|
471
|
-
},
|
|
472
|
-
{
|
|
473
|
-
kind: "Argument",
|
|
474
|
-
name: { kind: "Name", value: "type" },
|
|
475
|
-
value: {
|
|
476
|
-
kind: "Variable",
|
|
477
|
-
name: { kind: "Name", value: "type" },
|
|
478
|
-
},
|
|
479
|
-
},
|
|
480
|
-
],
|
|
481
|
-
selectionSet: {
|
|
482
|
-
kind: "SelectionSet",
|
|
483
|
-
selections: [
|
|
484
|
-
{ kind: "Field", name: { kind: "Name", value: "url" } },
|
|
485
|
-
],
|
|
486
|
-
},
|
|
487
|
-
},
|
|
488
|
-
],
|
|
489
|
-
},
|
|
490
|
-
},
|
|
491
|
-
],
|
|
492
|
-
} as unknown as DocumentNode<GetServerQueryQuery, GetServerQueryQueryVariables>;
|
|
493
426
|
export const AllOperationsDocument = {
|
|
494
427
|
kind: "Document",
|
|
495
428
|
definitions: [
|
|
@@ -735,6 +668,73 @@ export const AllOperationsDocument = {
|
|
|
735
668
|
},
|
|
736
669
|
],
|
|
737
670
|
} as unknown as DocumentNode<AllOperationsQuery, AllOperationsQueryVariables>;
|
|
671
|
+
export const GetServerQueryDocument = {
|
|
672
|
+
kind: "Document",
|
|
673
|
+
definitions: [
|
|
674
|
+
{
|
|
675
|
+
kind: "OperationDefinition",
|
|
676
|
+
operation: "query",
|
|
677
|
+
name: { kind: "Name", value: "getServerQuery" },
|
|
678
|
+
variableDefinitions: [
|
|
679
|
+
{
|
|
680
|
+
kind: "VariableDefinition",
|
|
681
|
+
variable: {
|
|
682
|
+
kind: "Variable",
|
|
683
|
+
name: { kind: "Name", value: "input" },
|
|
684
|
+
},
|
|
685
|
+
type: {
|
|
686
|
+
kind: "NonNullType",
|
|
687
|
+
type: { kind: "NamedType", name: { kind: "Name", value: "JSON" } },
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
kind: "VariableDefinition",
|
|
692
|
+
variable: { kind: "Variable", name: { kind: "Name", value: "type" } },
|
|
693
|
+
type: {
|
|
694
|
+
kind: "NonNullType",
|
|
695
|
+
type: {
|
|
696
|
+
kind: "NamedType",
|
|
697
|
+
name: { kind: "Name", value: "SchemaType" },
|
|
698
|
+
},
|
|
699
|
+
},
|
|
700
|
+
},
|
|
701
|
+
],
|
|
702
|
+
selectionSet: {
|
|
703
|
+
kind: "SelectionSet",
|
|
704
|
+
selections: [
|
|
705
|
+
{
|
|
706
|
+
kind: "Field",
|
|
707
|
+
name: { kind: "Name", value: "schema" },
|
|
708
|
+
arguments: [
|
|
709
|
+
{
|
|
710
|
+
kind: "Argument",
|
|
711
|
+
name: { kind: "Name", value: "input" },
|
|
712
|
+
value: {
|
|
713
|
+
kind: "Variable",
|
|
714
|
+
name: { kind: "Name", value: "input" },
|
|
715
|
+
},
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
kind: "Argument",
|
|
719
|
+
name: { kind: "Name", value: "type" },
|
|
720
|
+
value: {
|
|
721
|
+
kind: "Variable",
|
|
722
|
+
name: { kind: "Name", value: "type" },
|
|
723
|
+
},
|
|
724
|
+
},
|
|
725
|
+
],
|
|
726
|
+
selectionSet: {
|
|
727
|
+
kind: "SelectionSet",
|
|
728
|
+
selections: [
|
|
729
|
+
{ kind: "Field", name: { kind: "Name", value: "url" } },
|
|
730
|
+
],
|
|
731
|
+
},
|
|
732
|
+
},
|
|
733
|
+
],
|
|
734
|
+
},
|
|
735
|
+
},
|
|
736
|
+
],
|
|
737
|
+
} as unknown as DocumentNode<GetServerQueryQuery, GetServerQueryQueryVariables>;
|
|
738
738
|
export const GetCategoriesDocument = {
|
|
739
739
|
kind: "Document",
|
|
740
740
|
definitions: [
|
|
@@ -11,10 +11,14 @@ import {
|
|
|
11
11
|
fetchExchange,
|
|
12
12
|
} from "./util/urql.js";
|
|
13
13
|
|
|
14
|
+
import { CirclePlayIcon } from "lucide-react";
|
|
14
15
|
import { createClient } from "zudoku/openapi-worker";
|
|
15
16
|
import { ErrorPage } from "../../components/ErrorPage.js";
|
|
16
17
|
import { SyntaxHighlight } from "../../components/SyntaxHighlight.js";
|
|
18
|
+
import { Button } from "../../ui/Button.js";
|
|
17
19
|
import { OasPluginConfig } from "./interfaces.js";
|
|
20
|
+
import type { PlaygroundContentProps } from "./playground/Playground.js";
|
|
21
|
+
import { PlaygroundDialog } from "./playground/PlaygroundDialog.js";
|
|
18
22
|
|
|
19
23
|
const GetCategoriesQuery = graphql(`
|
|
20
24
|
query GetCategories($input: JSON!, $type: SchemaType!) {
|
|
@@ -81,6 +85,17 @@ export const openApiPlugin = (
|
|
|
81
85
|
return <link rel="preconnect" href={config.server} />;
|
|
82
86
|
}
|
|
83
87
|
},
|
|
88
|
+
getMdxComponents: () => ({
|
|
89
|
+
OpenPlaygroundButton: (props: PlaygroundContentProps) => {
|
|
90
|
+
return (
|
|
91
|
+
<PlaygroundDialog {...props}>
|
|
92
|
+
<Button className="gap-2 items-center" variant="outline">
|
|
93
|
+
Open in Playground <CirclePlayIcon size={16} />
|
|
94
|
+
</Button>
|
|
95
|
+
</PlaygroundDialog>
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
84
99
|
getNavigation: async (path: string) => {
|
|
85
100
|
if (!matchPath({ path: basePath, end: false }, path)) {
|
|
86
101
|
return [];
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { EraserIcon } from "lucide-react";
|
|
2
|
-
import {
|
|
3
|
-
Control,
|
|
4
|
-
Controller,
|
|
5
|
-
useFieldArray,
|
|
6
|
-
useFormContext,
|
|
7
|
-
UseFormRegister,
|
|
8
|
-
} from "react-hook-form";
|
|
2
|
+
import { Control, Controller, useFieldArray } from "react-hook-form";
|
|
9
3
|
import { Button } from "../../../ui/Button.js";
|
|
10
4
|
import { Input } from "../../../ui/Input.js";
|
|
11
5
|
import { cn } from "../../../util/cn.js";
|
|
@@ -14,12 +8,9 @@ import type { PlaygroundForm } from "./Playground.js";
|
|
|
14
8
|
|
|
15
9
|
export const PathParams = ({
|
|
16
10
|
control,
|
|
17
|
-
register,
|
|
18
11
|
}: {
|
|
19
|
-
register: UseFormRegister<PlaygroundForm>;
|
|
20
12
|
control: Control<PlaygroundForm>;
|
|
21
13
|
}) => {
|
|
22
|
-
const form = useFormContext<PlaygroundForm>();
|
|
23
14
|
const { fields } = useFieldArray<PlaygroundForm>({
|
|
24
15
|
control,
|
|
25
16
|
name: "pathParams",
|
|
@@ -35,16 +26,19 @@ export const PathParams = ({
|
|
|
35
26
|
control={control}
|
|
36
27
|
name={`pathParams.${i}.value`}
|
|
37
28
|
render={({ field }) => (
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
29
|
+
<div>
|
|
30
|
+
<ColorizedParam
|
|
31
|
+
slug={part.name}
|
|
32
|
+
name={part.name}
|
|
33
|
+
backgroundOpacity="25%"
|
|
34
|
+
borderOpacity={field.value ? "100%" : "0"}
|
|
35
|
+
className={cn(
|
|
36
|
+
"font-mono text-xs m-2",
|
|
37
|
+
!field.value && "opacity-60",
|
|
38
|
+
)}
|
|
39
|
+
/>
|
|
40
|
+
*
|
|
41
|
+
</div>
|
|
48
42
|
)}
|
|
49
43
|
/>
|
|
50
44
|
</td>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { Fragment } from "react";
|
|
2
|
+
import { Fragment, useEffect, useRef } from "react";
|
|
3
3
|
import { FormProvider, useForm } from "react-hook-form";
|
|
4
|
-
import { useQuery } from "urql";
|
|
5
4
|
import { useApiIdentities } from "../../../components/context/DevPortalProvider.js";
|
|
6
5
|
import {
|
|
7
6
|
Select,
|
|
@@ -15,9 +14,8 @@ import { SyntaxHighlight } from "../../../components/SyntaxHighlight.js";
|
|
|
15
14
|
import { Button } from "../../../ui/Button.js";
|
|
16
15
|
import { Card } from "../../../ui/Card.js";
|
|
17
16
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "../../../ui/Tabs.js";
|
|
17
|
+
import { fetchTimeout } from "../../../util/fetchTimeout.js";
|
|
18
18
|
import { ColorizedParam } from "../ColorizedParam.js";
|
|
19
|
-
import { useOasConfig } from "../context.js";
|
|
20
|
-
import { graphql } from "../graphql/index.js";
|
|
21
19
|
import { createUrl } from "./createUrl.js";
|
|
22
20
|
import { Headers } from "./Headers.js";
|
|
23
21
|
import { PathParams } from "./PathParams.js";
|
|
@@ -25,14 +23,6 @@ import { QueryParams } from "./QueryParams.js";
|
|
|
25
23
|
|
|
26
24
|
export const NO_IDENTITY = "__none";
|
|
27
25
|
|
|
28
|
-
const GetServerQuery = graphql(/* GraphQL */ `
|
|
29
|
-
query getServerQuery($input: JSON!, $type: SchemaType!) {
|
|
30
|
-
schema(input: $input, type: $type) {
|
|
31
|
-
url
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
`);
|
|
35
|
-
|
|
36
26
|
function mimeTypeToLanguage(mimeType: string) {
|
|
37
27
|
const mimeTypeMapping = {
|
|
38
28
|
"application/json": "json",
|
|
@@ -65,63 +55,83 @@ const statusCodeMap: Record<number, string> = {
|
|
|
65
55
|
|
|
66
56
|
export type Header = {
|
|
67
57
|
name: string;
|
|
68
|
-
|
|
58
|
+
defaultValue?: string;
|
|
69
59
|
};
|
|
70
60
|
export type QueryParam = {
|
|
71
61
|
name: string;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
isRequired
|
|
62
|
+
defaultValue?: string;
|
|
63
|
+
defaultActive?: boolean;
|
|
64
|
+
isRequired?: boolean;
|
|
75
65
|
};
|
|
76
66
|
export type PathParam = {
|
|
77
67
|
name: string;
|
|
78
|
-
|
|
68
|
+
defaultValue?: string;
|
|
69
|
+
isRequired?: boolean;
|
|
79
70
|
};
|
|
80
71
|
|
|
81
72
|
export type PlaygroundForm = {
|
|
82
73
|
body: string;
|
|
83
|
-
queryParams:
|
|
84
|
-
pathParams:
|
|
85
|
-
headers:
|
|
74
|
+
queryParams: Array<{ name: string; value: string; active: boolean }>;
|
|
75
|
+
pathParams: Array<{ name: string; value: string }>;
|
|
76
|
+
headers: Array<{ name: string; value: string }>;
|
|
86
77
|
identity?: string;
|
|
87
78
|
};
|
|
88
79
|
|
|
89
80
|
export type PlaygroundContentProps = {
|
|
81
|
+
server: string;
|
|
90
82
|
url: string;
|
|
91
83
|
method: string;
|
|
92
84
|
headers?: Header[];
|
|
93
85
|
queryParams?: QueryParam[];
|
|
94
86
|
pathParams?: PathParam[];
|
|
95
|
-
|
|
87
|
+
defaultBody?: string;
|
|
96
88
|
};
|
|
97
89
|
|
|
98
90
|
export const Playground = ({
|
|
91
|
+
server,
|
|
99
92
|
url,
|
|
100
93
|
method,
|
|
101
|
-
headers = [
|
|
94
|
+
headers = [],
|
|
102
95
|
queryParams = [],
|
|
103
96
|
pathParams = [],
|
|
104
|
-
|
|
97
|
+
defaultBody = "",
|
|
105
98
|
}: PlaygroundContentProps) => {
|
|
106
|
-
const
|
|
107
|
-
const [server] = useQuery({ query: GetServerQuery, variables });
|
|
108
|
-
|
|
109
|
-
const { register, control, handleSubmit, watch, ...form } =
|
|
99
|
+
const { register, control, handleSubmit, watch, setValue, ...form } =
|
|
110
100
|
useForm<PlaygroundForm>({
|
|
111
101
|
defaultValues: {
|
|
112
|
-
body:
|
|
113
|
-
queryParams
|
|
114
|
-
|
|
115
|
-
|
|
102
|
+
body: defaultBody,
|
|
103
|
+
queryParams: queryParams.map((param) => ({
|
|
104
|
+
name: param.name,
|
|
105
|
+
value: param.defaultValue ?? "",
|
|
106
|
+
active: param.defaultActive ?? false,
|
|
107
|
+
})),
|
|
108
|
+
pathParams: pathParams.map((param) => ({
|
|
109
|
+
name: param.name,
|
|
110
|
+
value: param.defaultValue ?? "",
|
|
111
|
+
})),
|
|
112
|
+
headers: headers.map((header) => ({
|
|
113
|
+
name: header.name,
|
|
114
|
+
value: header.defaultValue ?? "",
|
|
115
|
+
})),
|
|
116
116
|
identity: NO_IDENTITY,
|
|
117
117
|
},
|
|
118
118
|
});
|
|
119
119
|
const formState = watch();
|
|
120
120
|
const identities = useApiIdentities();
|
|
121
121
|
|
|
122
|
+
const setOnce = useRef(false);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (setOnce.current) return;
|
|
125
|
+
const firstIdentity = identities.data?.at(0);
|
|
126
|
+
if (firstIdentity) {
|
|
127
|
+
setValue("identity", firstIdentity.id);
|
|
128
|
+
setOnce.current = true;
|
|
129
|
+
}
|
|
130
|
+
}, [setValue, identities.data]);
|
|
131
|
+
|
|
122
132
|
const queryMutation = useMutation({
|
|
123
133
|
mutationFn: async (data: PlaygroundForm) => {
|
|
124
|
-
const requestUrl = createUrl(server
|
|
134
|
+
const requestUrl = createUrl(server, url, data);
|
|
125
135
|
const start = performance.now();
|
|
126
136
|
|
|
127
137
|
const request = new Request(requestUrl, {
|
|
@@ -138,7 +148,8 @@ export const Playground = ({
|
|
|
138
148
|
?.find((i) => i.id === data.identity)
|
|
139
149
|
?.authorizeRequest(request);
|
|
140
150
|
}
|
|
141
|
-
const response = await
|
|
151
|
+
const response = await fetchTimeout(request);
|
|
152
|
+
const time = performance.now() - start;
|
|
142
153
|
|
|
143
154
|
const body = await response.text();
|
|
144
155
|
|
|
@@ -147,7 +158,7 @@ export const Playground = ({
|
|
|
147
158
|
headers: response.headers,
|
|
148
159
|
size: body.length,
|
|
149
160
|
body,
|
|
150
|
-
time
|
|
161
|
+
time,
|
|
151
162
|
};
|
|
152
163
|
},
|
|
153
164
|
});
|
|
@@ -159,7 +170,7 @@ export const Playground = ({
|
|
|
159
170
|
|
|
160
171
|
const pathParamValue = value ? (
|
|
161
172
|
<ColorizedParam backgroundOpacity="25%" name={part} slug={part}>
|
|
162
|
-
{value}
|
|
173
|
+
{encodeURIComponent(value)}
|
|
163
174
|
</ColorizedParam>
|
|
164
175
|
) : (
|
|
165
176
|
<span
|
|
@@ -195,8 +206,11 @@ export const Playground = ({
|
|
|
195
206
|
<wbr />
|
|
196
207
|
</Fragment>
|
|
197
208
|
));
|
|
209
|
+
|
|
198
210
|
return (
|
|
199
|
-
<FormProvider
|
|
211
|
+
<FormProvider
|
|
212
|
+
{...{ register, control, handleSubmit, watch, setValue, ...form }}
|
|
213
|
+
>
|
|
200
214
|
<form onSubmit={handleSubmit((data) => queryMutation.mutateAsync(data))}>
|
|
201
215
|
<div className="grid grid-cols-2 text-sm h-full">
|
|
202
216
|
<div className="flex flex-col gap-4 p-8 bg-muted/50 after:bg-muted-foreground/20 relative after:absolute after:w-px after:inset-0 after:left-auto">
|
|
@@ -215,10 +229,12 @@ export const Playground = ({
|
|
|
215
229
|
Send
|
|
216
230
|
</Button>
|
|
217
231
|
</div>
|
|
218
|
-
<Tabs
|
|
232
|
+
<Tabs
|
|
233
|
+
defaultValue={pathParams.length > 0 ? "parameters" : "headers"}
|
|
234
|
+
>
|
|
219
235
|
<div className="flex justify-between">
|
|
220
236
|
<TabsList>
|
|
221
|
-
{
|
|
237
|
+
{pathParams.length > 0 && (
|
|
222
238
|
<TabsTrigger value="parameters">Parameters</TabsTrigger>
|
|
223
239
|
)}
|
|
224
240
|
<TabsTrigger value="headers">
|
|
@@ -228,9 +244,11 @@ export const Playground = ({
|
|
|
228
244
|
</TabsTrigger>
|
|
229
245
|
<TabsTrigger
|
|
230
246
|
value="body"
|
|
231
|
-
disabled={
|
|
232
|
-
|
|
233
|
-
|
|
247
|
+
disabled={
|
|
248
|
+
!["POST", "PUT", "PATCH", "DELETE"].includes(
|
|
249
|
+
method.toUpperCase(),
|
|
250
|
+
)
|
|
251
|
+
}
|
|
234
252
|
>
|
|
235
253
|
Body
|
|
236
254
|
</TabsTrigger>
|
|
@@ -238,7 +256,8 @@ export const Playground = ({
|
|
|
238
256
|
<div className="flex gap-2 items-center">
|
|
239
257
|
Auth:
|
|
240
258
|
<Select
|
|
241
|
-
onValueChange={(value) =>
|
|
259
|
+
onValueChange={(value) => setValue("identity", value)}
|
|
260
|
+
value={formState.identity}
|
|
242
261
|
defaultValue={formState.identity}
|
|
243
262
|
>
|
|
244
263
|
<SelectTrigger className="w-[180px] flex">
|
|
@@ -262,13 +281,13 @@ export const Playground = ({
|
|
|
262
281
|
{pathParams.length > 0 && (
|
|
263
282
|
<div className="flex flex-col gap-4 my-4">
|
|
264
283
|
<span className="font-semibold">Path Parameters</span>
|
|
265
|
-
<PathParams control={control}
|
|
284
|
+
<PathParams control={control} />
|
|
266
285
|
</div>
|
|
267
286
|
)}
|
|
268
287
|
{queryParams.length > 0 && (
|
|
269
288
|
<div className="flex flex-col gap-4 my-4">
|
|
270
289
|
<span className="font-semibold">Query Parameters</span>
|
|
271
|
-
<QueryParams control={control} />
|
|
290
|
+
<QueryParams control={control} queryParams={queryParams} />
|
|
272
291
|
</div>
|
|
273
292
|
)}
|
|
274
293
|
</TabsContent>
|
|
@@ -282,7 +301,12 @@ export const Playground = ({
|
|
|
282
301
|
</div>
|
|
283
302
|
<div className="flex flex-col gap-4 p-8 bg-muted/70">
|
|
284
303
|
{queryMutation.error ? (
|
|
285
|
-
<div>
|
|
304
|
+
<div>
|
|
305
|
+
Error:{" "}
|
|
306
|
+
{queryMutation.error.message ||
|
|
307
|
+
String(queryMutation.error) ||
|
|
308
|
+
"Unexpected error"}
|
|
309
|
+
</div>
|
|
286
310
|
) : queryMutation.data ? (
|
|
287
311
|
<div className="flex flex-col gap-2">
|
|
288
312
|
<div className="flex gap-2">
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
|
|
2
2
|
import { CirclePlayIcon } from "lucide-react";
|
|
3
|
-
import { useState } from "react";
|
|
3
|
+
import { type PropsWithChildren, useState } from "react";
|
|
4
4
|
import {
|
|
5
5
|
Dialog,
|
|
6
6
|
DialogContent,
|
|
@@ -9,15 +9,17 @@ import {
|
|
|
9
9
|
} from "../../../components/Dialog.js";
|
|
10
10
|
import { Playground, type PlaygroundContentProps } from "./Playground.js";
|
|
11
11
|
|
|
12
|
-
const PlaygroundDialog = (props: PlaygroundContentProps) => {
|
|
12
|
+
const PlaygroundDialog = (props: PropsWithChildren<PlaygroundContentProps>) => {
|
|
13
13
|
const [open, setOpen] = useState(false);
|
|
14
14
|
return (
|
|
15
15
|
<Dialog onOpenChange={(open) => setOpen(open)}>
|
|
16
16
|
<DialogTrigger asChild>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
{props.children ?? (
|
|
18
|
+
<CirclePlayIcon
|
|
19
|
+
className="cursor-pointer text-primary hover:text-primary/80"
|
|
20
|
+
size={16}
|
|
21
|
+
/>
|
|
22
|
+
)}
|
|
21
23
|
</DialogTrigger>
|
|
22
24
|
|
|
23
25
|
<DialogContent
|