diff --git a/packages/core/src/core/pardon.ts b/packages/core/src/core/pardon.ts index 0b55ad3d..2f555a0f 100644 --- a/packages/core/src/core/pardon.ts +++ b/packages/core/src/core/pardon.ts @@ -159,6 +159,16 @@ export const PardonFetchExecution = pardonExecution({ async match({ context: { url, init, ...context } }) { const fetchObject = fetchIntoObject(url, init); + if (typeof context.values?.method === "string") { + fetchObject.method ??= context.values?.method; + + if (context.values?.method !== fetchObject.method) { + throw new Error( + "specified values method does not match reqeust method", + ); + } + } + // pathname undefined in some places is allowed (matches any template), // but we want to ensure it's set when matching requests. // but allow undefined origin and pathname for undefined URLs matched/rendered only by values. diff --git a/packages/core/src/entry/main/cli/options.ts b/packages/core/src/entry/main/cli/options.ts index 2c13d028..7eda781b 100644 --- a/packages/core/src/entry/main/cli/options.ts +++ b/packages/core/src/entry/main/cli/options.ts @@ -123,8 +123,15 @@ export async function processOptions( method = args.shift()!; } + if (values.method !== undefined && typeof values.method !== "string") { + throw new Error("method should be a string"); + } + if (!args.length) { - return { values, init: { method: method ?? "GET" } }; + return { + values, + init: { method: (method ?? values.method ?? "GET") as string }, + }; } const request = await parseMainArgument(args.shift()!); @@ -138,7 +145,15 @@ export async function processOptions( throw new PardonError("http method specified twice"); } - request.method ??= method; + if (typeof values.method !== "string") { + throw new Error("method in values must be a string."); + } + + request.method ??= method ?? values.method ?? "GET"; + + if (values.method && values.method && values.method !== request.method) { + throw new Error("method in input does not match method in request"); + } if (data !== undefined && dataRaw !== undefined) { throw new Error("both --data and --data-raw should not be specified"); @@ -160,10 +175,6 @@ export async function processOptions( request!.headers.append(key, value); } - if (!values.endpoint && !values.method) { - request.method ??= method ?? "GET"; - } - return { url: intoURL(request), init: request, values }; } diff --git a/packages/docs/src/components/Exercises.astro b/packages/docs/src/components/Exercises.astro index db1b9d68..59b41873 100644 --- a/packages/docs/src/components/Exercises.astro +++ b/packages/docs/src/components/Exercises.astro @@ -19,7 +19,7 @@ const props = Astro.props;
.pp-container { - @apply mt-4 overflow-hidden rounded-md border-8 border-transparent bg-[--astro-code-color-background] bg-clip-border p-2 pb-4; + @apply mt-4 overflow-clip rounded-md border-8 border-transparent bg-[--astro-code-color-background] bg-clip-border p-2 pb-4; } .pp-app-container { @apply border-0 border-t-2 border-dashed border-zinc-400 px-2 pt-5 dark:border-sky-700; diff --git a/packages/docs/src/components/playgrounds/pardon/PardonPlaygroundDataView.tsx b/packages/docs/src/components/playgrounds/pardon/PardonPlaygroundDataView.tsx index 358e9e2a..f4a8996d 100644 --- a/packages/docs/src/components/playgrounds/pardon/PardonPlaygroundDataView.tsx +++ b/packages/docs/src/components/playgrounds/pardon/PardonPlaygroundDataView.tsx @@ -55,18 +55,24 @@ export default function PardonPlaygroundDataView( } if (response?.result) { + const { + inbound: { values, secrets }, + } = response.result; return { - data: response.result?.inbound, + data: { values, secrets }, }; } const { execution } = executionHandle; try { - const request = await execution.outbound; + const { + request: { values: secrets }, + redacted: { values }, + } = await execution.outbound; return { - data: request, + data: { values, secrets }, }; } catch (error) { return { @@ -106,7 +112,7 @@ export default function PardonPlaygroundDataView( return ( +
{props.children}
diff --git a/packages/docs/src/content/docs/intro/collections.mdx b/packages/docs/src/content/docs/intro/collections.mdx index 72b90ef7..b932be84 100644 --- a/packages/docs/src/content/docs/intro/collections.mdx +++ b/packages/docs/src/content/docs/intro/collections.mdx @@ -297,6 +297,18 @@ endpoint=example/products/list you can try different endpoints, and/or `env=stage` if you like, for the get/update/delete endpoints, you'll need to specify a `product=...` value as well. + :::note + This only works for `GET` method endpoints. + + Non-GET endpoints need the `method` specified as well, this + adds a little friction to prevent accidental `POST` requests. + + +``` +endpoint=example/products/create method=POST name=thneed +``` + + ::: diff --git a/packages/docs/src/content/docs/intro/dataflow.mdx b/packages/docs/src/content/docs/intro/dataflow.mdx index ce61fbc1..ab7df8ba 100644 --- a/packages/docs/src/content/docs/intro/dataflow.mdx +++ b/packages/docs/src/content/docs/intro/dataflow.mdx @@ -99,12 +99,12 @@ You can reset the system with the reset button there too. ::: + { + "name": "abc" + } +`} config={serviceAndPingAndProductsWithConfigurableAuth}> Try changing the value of name in either the values or the input request here. See how pardon becomes confused @@ -189,13 +190,13 @@ Pardon interprets a single element array as a template for each item, and then evaluates each item in its own scope. Let's see how this works here @@ -275,14 +276,14 @@ This means replacing `{{product}}` with `{{items.product}}` and name for the scoped values. @@ -530,7 +531,7 @@ is clearly a new element based on the `id`. This mapping also affects export scopes. Feel free to experiment with the usual `env=stage`/`env=prod` changes, (notice that pardon takes a moment to update now.) @@ -216,7 +216,7 @@ This price script isn't editable here (it's hacked into the demo system). + { + "name": "sample", + "price": 9.99 + } +`} config={productsExample}> diff --git a/packages/docs/src/content/docs/intro/testcases.mdx b/packages/docs/src/content/docs/intro/testcases.mdx index e52b46e4..724bbcde 100644 --- a/packages/docs/src/content/docs/intro/testcases.mdx +++ b/packages/docs/src/content/docs/intro/testcases.mdx @@ -433,8 +433,8 @@ each `each`. We should explore this behavior interactively. { - set({ env: "stage", name: "pencils" }); -}); + cases(({ set }) => { + set({ env: "stage", name: "pencils" }); + }); -trial("%env/get-product-%name", ({ env, name }) => { - /* ... */ -}); + trial("%env/get-product-%name", ({ env, name }) => { + /* ... */ + }); `.trim()}> { - set({ - env: each("stage", "prod"), - name: each("pencils", "pens", "markers") + cases(({ set, each }) => { + set({ + env: each("stage", "prod"), + name: each("pencils", "pens", "markers") + }); }); -}); -trial("%env/get-product-%name", ({ env, name }) => { - /* ... */ -}); + trial("%env/get-product-%name", ({ env, name }) => { + /* ... */ + }); `.trim()}> { set("name", each("pencils", "pens")); }); - trial("%env/get-product-%name", () => { + trial("%env/get-product-%name", () => { /*...*/ }); }); @@ -784,19 +784,19 @@ There are many utilities defining transforms of the test case(s): - etc... { - defi("env", each("stage", "prod"), "local"); -}); - -gamut("%env", () => { - cases(({ set, each }) => { - set("name", each("pencils", "pens")); + cases(({ each, defi }) => { + defi("env", each("stage", "prod"), "local"); }); - trial("get-product-%name", () => { - /*...*/ + gamut("%env", () => { + cases(({ set, each }) => { + set("name", each("pencils", "pens")); + }); + + trial("get-product-%name", () => { + /*...*/ + }); }); -}); `.trim()}> @@ -824,12 +824,12 @@ And the shuffle is just `~2` or some other number, with a value of `~0` for not Understandably, this is best understood by experience: