Skip to content

Commit

Permalink
Merge pull request #205 from thinknimble/chore/prettier
Browse files Browse the repository at this point in the history
Chore: Add prettier to avoid formatting issues in the future
  • Loading branch information
lakardion authored Oct 18, 2024
2 parents 70311ba + e74780f commit d11a3a3
Show file tree
Hide file tree
Showing 24 changed files with 714 additions and 713 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
run: pnpm install --frozen-lockfile
- name: 🆎 TypeCheck
run: pnpm lint
- name: 🎨 Prettier
run: pnpm format:check
- name: 🧪 Run tests
run: pnpm test
- name: 🏗️ Build
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"test:dev": "vitest",
"ci": "pnpm run lint && pnpm run test && pnpm run build",
"release": "pnpm run ci && changeset publish",
"dev:watch": "tsup src/index.ts --format cjs,esm --dts --watch"
"dev:watch": "tsup src/index.ts --format cjs,esm --dts --watch",
"format:check": "prettier --check ./src",
"format:write": "prettier --write ./src"
},
"repository": {
"type": "git",
Expand Down
12 changes: 6 additions & 6 deletions src/api/create-custom-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ type ResolveCustomServiceCallback<
TOutputShape extends z.ZodRawShape | ZodPrimitives | z.ZodArray<z.ZodTypeAny> = never,
TFilters extends FiltersShape | z.ZodVoid = never,
TCallType extends string = "",
TShapeOrVoid extends ResolveShapeOrVoid<any, any, any> = ResolveShapeOrVoid<TInputShape, TOutputShape, TFilters>
TShapeOrVoid extends ResolveShapeOrVoid<any, any, any> = ResolveShapeOrVoid<TInputShape, TOutputShape, TFilters>,
> = CustomServiceCallback<TShapeOrVoid["input"], TShapeOrVoid["output"], TShapeOrVoid["filters"], TCallType>

type ResolveServiceCallFn<
TInputShape extends z.ZodRawShape | ZodPrimitives = never,
TOutputShape extends z.ZodRawShape | ZodPrimitives | z.ZodArray<z.ZodTypeAny> = never,
TFiltersShape extends FiltersShape | z.ZodVoid = never,
TShapeOrVoid extends ResolveShapeOrVoid<any, any, any> = ResolveShapeOrVoid<TInputShape, TOutputShape, TFiltersShape>
TShapeOrVoid extends ResolveShapeOrVoid<any, any, any> = ResolveShapeOrVoid<TInputShape, TOutputShape, TFiltersShape>,
> = ServiceCallFn<TShapeOrVoid["input"], TShapeOrVoid["output"], TShapeOrVoid["filters"]>

export const createCustomServiceCall = <
TInputShape extends z.ZodRawShape | ZodPrimitives = never,
TOutputShape extends z.ZodRawShape | ZodPrimitives | z.ZodArray<z.ZodTypeAny> = never,
TFiltersShape extends FiltersShape = never
TFiltersShape extends FiltersShape = never,
>(
args:
| ({
inputShape?: TInputShape
outputShape?: TOutputShape
cb: ResolveCustomServiceCallback<TInputShape, TOutputShape, TFiltersShape>
} & (IsNever<TOutputShape> extends true ? unknown : { filtersShape?: TFiltersShape }))
| ResolveCustomServiceCallback<z.ZodVoid, z.ZodVoid, z.ZodVoid>
| ResolveCustomServiceCallback<z.ZodVoid, z.ZodVoid, z.ZodVoid>,
): ResolveCustomServiceCallOpts<TInputShape, TOutputShape, TFiltersShape> => {
const inputShape = typeof args === "function" || !args.inputShape ? z.void() : args.inputShape
const outputShape = typeof args === "function" || !args.outputShape ? z.void() : args.outputShape
Expand All @@ -56,7 +56,7 @@ export const createCustomServiceCall = <
const standAlone = <
TInputShape extends z.ZodRawShape | ZodPrimitives = never,
TOutputShape extends z.ZodRawShape | ZodPrimitives | z.ZodArray<z.ZodTypeAny> = never,
TFiltersShape extends FiltersShape | z.ZodVoid = never
TFiltersShape extends FiltersShape | z.ZodVoid = never,
>(
args: {
client: AxiosLike
Expand All @@ -74,7 +74,7 @@ const standAlone = <
) &
(IsNever<TOutputShape> extends true ? unknown : { filtersShape?: TFiltersShape })
cb: ResolveCustomServiceCallback<TInputShape, TOutputShape, TFiltersShape, StandAloneCallType>
}
},
): ResolveServiceCallFn<TInputShape, TOutputShape, TFiltersShape> => {
//? Should I use zod to improve the types in here rather than any[] it?. We could probably do the same for the createCustomServiceCall
const inputShape = (args.models && "inputShape" in args.models ? args.models.inputShape : undefined) ?? z.void()
Expand Down
6 changes: 3 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./create-api"
export * from "./create-custom-call"
export * from "./create-paginated-call"
export * from "./create-api"
export * from "./create-custom-call"
export * from "./create-paginated-call"
20 changes: 10 additions & 10 deletions src/api/tests/create-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("createApi", async () => {
//@ts-expect-error should not include update method
ExpectedReturn["update"],
//@ts-expect-error should not include upsert method
ExpectedReturn["upsert"]
ExpectedReturn["upsert"],
]
const testApiNoModels = createApi({
baseUri: "",
Expand All @@ -77,7 +77,7 @@ describe("createApi", async () => {
//@ts-expect-error should not include customServiceCalls
ExpectedReturn["customServiceCalls"],
//@ts-expect-error should not include csc
ExpectedReturn["csc"]
ExpectedReturn["csc"],
]

const testApiOnlyEntity = createApi({
Expand Down Expand Up @@ -114,7 +114,7 @@ describe("createApi", async () => {
//@ts-expect-error should not show up custom calls
ExpectedReturn["customServiceCalls"],
//@ts-expect-error should not show up custom calls
ExpectedReturn["csc"]
ExpectedReturn["csc"],
]
})
})
Expand Down Expand Up @@ -484,7 +484,7 @@ describe("createApi", async () => {
Expect<Equals<UriParameter, typeof slashEndingBaseUri>>,
Expect<Extends<UriParameter, `slashEndingUri/`>>,
//@ts-expect-error non slash ending uri should error on ts
Expect<Extends<UriParameter, `nonSlashEnding`>>
Expect<Extends<UriParameter, `nonSlashEnding`>>,
]
//@ts-expect-error should error bc we're not ending the url with a slash
client.get(`${slashEndingBaseUri}/slashEndingUri`)
Expand Down Expand Up @@ -693,7 +693,7 @@ describe("TS Tests", () => {
input: InferShapeOrZod<tInputShape>
} & {
filters?: Partial<InferShapeOrZod<tFiltersShape>> | undefined
}
},
) => Promise<InferShapeOrZod<tOutputShape>>
>
>,
Expand All @@ -711,7 +711,7 @@ describe("TS Tests", () => {
) => Promise<InferShapeOrZod<tOutputShape>>
>
>,
Expect<Equals<result["justCallback"], () => Promise<void>>>
Expect<Equals<result["justCallback"], () => Promise<void>>>,
]
})

Expand All @@ -736,10 +736,10 @@ describe("TS Tests", () => {
(
args: {
input: InferShapeOrZod<inputShapeMock>
} & { filters?: Partial<InferShapeOrZod<filtersShapeMock>> }
} & { filters?: Partial<InferShapeOrZod<filtersShapeMock>> },
) => Promise<InferShapeOrZod<outputShapeMock>>
>
>
>,
]
})

Expand Down Expand Up @@ -772,7 +772,7 @@ describe("TS Tests", () => {
Expect<Equals<Parameters<apiStrId["remove"]>[0], string>>,
Expect<Equals<Parameters<apiNumId["remove"]>[0], number>>,
Expect<Equals<Parameters<apiStrId["retrieve"]>[0], string>>,
Expect<Equals<Parameters<apiNumId["retrieve"]>[0], number>>
Expect<Equals<Parameters<apiNumId["retrieve"]>[0], number>>,
]
})

Expand Down Expand Up @@ -801,7 +801,7 @@ describe("TS Tests", () => {
Expect<Equals<Awaited<ReturnType<api["create"]>>, unwrappedReadonlyBrands>>,
Expect<Equals<Awaited<ReturnType<api["update"]>>, unwrappedReadonlyBrands>>,
Expect<Equals<Awaited<ReturnType<api["update"]["replace"]>>, unwrappedReadonlyBrands>>,
Expect<Equals<Awaited<ReturnType<api["update"]["replace"]["asPartial"]>>, unwrappedReadonlyBrands>>
Expect<Equals<Awaited<ReturnType<api["update"]["replace"]["asPartial"]>>, unwrappedReadonlyBrands>>,
]
})
it("should not show up any built-in method if there is no `models` passed", () => {
Expand Down
12 changes: 6 additions & 6 deletions src/api/tests/create-custom-call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe("createCustomServiceCall", () => {
(typeof utils)["toApi"],
(obj: object) => SnakeCasedPropertiesDeep<GetInferredFromRawWithBrand<typeof inputShape>>
>
>
>,
]
return {
givenInput: input.myInput,
Expand Down Expand Up @@ -199,7 +199,7 @@ describe("createCustomServiceCall", () => {
utils,
}) => {
return
}
},
)
type testNoInputNorOutput = typeof testNoInputNorOutput
const baseUri = "noInputNorOutputOverload"
Expand All @@ -222,7 +222,7 @@ describe("createCustomServiceCall", () => {
utils,
}) => {
return
}
},
)
const testInputOutputPlainZods = (() => {
const inputShape = z.string()
Expand Down Expand Up @@ -253,7 +253,7 @@ describe("createCustomServiceCall", () => {
testApi.customServiceCalls.nonExisting

type tests = [
Expect<Equals<string, Parameters<(typeof testApi)["customServiceCalls"]["testInputOutputPlainZods"]>[0]>>
Expect<Equals<string, Parameters<(typeof testApi)["customServiceCalls"]["testInputOutputPlainZods"]>[0]>>,
]
})
it("works well if no models are passed", async () => {
Expand Down Expand Up @@ -822,7 +822,7 @@ describe("createCustomServiceCall", () => {
params: {
test_filter: testFilter,
},
}
},
)
expect(result).toEqual({ testData: mockResult.test_data })
})
Expand Down Expand Up @@ -860,7 +860,7 @@ describe("createCustomServiceCall", () => {
expect(postSpy).toHaveBeenLastCalledWith(
`${callName}/`,
{ test_input: testNumberInput },
{ params: { test_filter: testFilter } }
{ params: { test_filter: testFilter } },
)
expect(result).toEqual(mockResult)
})
Expand Down
6 changes: 3 additions & 3 deletions src/api/tests/create-paginated-call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("createPaginatedServiceCall", () => {
page: pagination.page.toString(),
page_size: pagination.size.toString(),
},
}
},
)
})
it("calls api with the right uri even if uri param is empty", async () => {
Expand Down Expand Up @@ -85,7 +85,7 @@ describe("createPaginatedServiceCall", () => {
page: pagination.page.toString(),
page_size: pagination.size.toString(),
},
}
},
)
})

Expand Down Expand Up @@ -220,7 +220,7 @@ describe("createPaginatedServiceCall", () => {
page: "1",
page_size: "25",
},
}
},
)
})
it("calls api with right pagination params", async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/api/tests/filters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("parseFilters", () => {
expect(parseFilters({ shape, filters })).toEqual({
company_category: filters.companyCategory,
})
})
})
it("includes boolean", () => {
const shape = {
niceOnly: z.boolean(),
Expand All @@ -23,7 +23,7 @@ describe("parseFilters", () => {
niceOnly: false,
}
expect(parseFilters({ shape, filters })).toEqual({
nice_only: filters.niceOnly.toString()
nice_only: filters.niceOnly.toString(),
})
})
it("Throws error if passing a wrong type filter", () => {
Expand All @@ -37,4 +37,4 @@ describe("parseFilters", () => {
parseFilters({ shape, filters })
}).toThrow()
})
})
})
2 changes: 1 addition & 1 deletion src/api/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ export const listResponse: ListResponse = {
}
export const [mockEntity1Snaked, mockEntity2Snaked] = listResponse.results as [
ListResponse["results"][0],
ListResponse["results"][0]
ListResponse["results"][0],
]
Loading

0 comments on commit d11a3a3

Please sign in to comment.