Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,21 @@ export class HTTPSnippet {
): Request & {
allHeaders: Record<string, string[] | string>;
fullUrl: string;
url: any;
uriObj: any;
url: string;
uriObj: {
query: ReducedHelperObject;
search: string;
path: string | null;
auth: string | null;
hash: string | null;
host: string | null;
hostname: string | null;
href: string;
pathname: string | null;
protocol: string | null;
slashes: boolean | null;
port: string | null;
};
} {
const request: Request = {
...harRequest,
Expand Down
6 changes: 3 additions & 3 deletions src/targets/php/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { escapeString } from '../../helpers/escape.js';

export const convertType = (obj: any[] | any, indent?: string, lastIndent?: string): unknown => {
export const convertType = (obj: any[] | any, indent?: string, lastIndent?: string): string | 'null' => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just type this to string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i kinda like when return types explicitly mention a value that's likely to show up, in case a downstream function wants to act on that value accordingly. no strong preferences on this though

lastIndent = lastIndent || '';
indent = indent || '';

Expand Down Expand Up @@ -41,7 +41,7 @@ export const convertType = (obj: any[] | any, indent?: string, lastIndent?: stri
}
};

export const supportedMethods: string[] = [
export const supportedMethods = [
'ACL',
'BASELINE_CONTROL',
'CHECKIN',
Expand Down Expand Up @@ -69,4 +69,4 @@ export const supportedMethods: string[] = [
'UNLOCK',
'UPDATE',
'VERSION_CONTROL',
];
] as const;
4 changes: 2 additions & 2 deletions src/targets/php/http1/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ export const http1: Client<Http1Options> = {
blank();
}

if (!supportedMethods.includes(method.toUpperCase())) {
if (!supportedMethods.includes(method.toUpperCase() as (typeof supportedMethods)[number])) {
push(`HttpRequest::methodRegister('${method}');`);
}

push('$request = new HttpRequest();');
push(`$request->setUrl(${convertType(url)});`);

if (supportedMethods.includes(method.toUpperCase())) {
if (supportedMethods.includes(method.toUpperCase() as (typeof supportedMethods)[number])) {
push(`$request->setMethod(HTTP_METH_${method.toUpperCase()});`);
} else {
push(`$request->setMethod(HttpRequest::HTTP_METH_${method.toUpperCase()});`);
Expand Down
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"compilerOptions": {
"declaration": true,
"downlevelIteration": true,
"esModuleInterop": true,
"isolatedDeclarations": true,
"lib": ["DOM", "ES2020"],
Expand All @@ -10,13 +9,12 @@
"noEmit": true,
"outDir": "dist",
"resolveJsonModule": true,
"strict": true,
"target": "ES2020",

// Allows us to not have to typeguard in catches.
// https://bobbyhadz.com/blog/typescript-object-is-of-type-unknown
"useUnknownInCatchVariables": false,

"strict": true
"verbatimModuleSyntax": true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haven't seen this one before, what's it do?

Copy link
Member Author

@kanadgupta kanadgupta Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably enable it everywhere we can. it ensures that type imports use import type SomeType and not import SomeType, which will help us with treeshaking. as always mr. pocock has a good write-up on the subject in his cheat sheet: https://www.totaltypescript.com/tsconfig-cheat-sheet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh cool

},
"exclude": ["dist/", "./src/fixtures/", "**/*.test.ts"],
"include": ["./src/**/*"]
Expand Down
Loading