Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten return types #924

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .changeset/five-candles-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
4 changes: 2 additions & 2 deletions .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,8 @@ function rulesForPackagesWithChecKApiTask() {
options: {
devDependencies: {
"@osdk/monorepo.api-extractor": "workspace:~",
"@microsoft/api-documenter": "^7.25.3",
"@microsoft/api-extractor": "^7.47.0",
"@microsoft/api-documenter": "^7.25.21",
"@microsoft/api-extractor": "^7.47.11",
},
},
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"type-fest": "^4.18.2"
},
"devDependencies": {
"@microsoft/api-documenter": "^7.25.3",
"@microsoft/api-extractor": "^7.47.0",
"@microsoft/api-documenter": "^7.25.21",
"@microsoft/api-extractor": "^7.47.11",
"@osdk/monorepo.api-extractor": "workspace:~",
"@osdk/monorepo.tsconfig": "workspace:~",
"@osdk/monorepo.tsup": "workspace:~",
Expand Down
23 changes: 22 additions & 1 deletion packages/api/src/aggregate/WhereClause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,28 @@ export type PossibleWhereClauseFilters =

// the value side of this needs to match DistanceUnit from @osdk/internal.foundry but we don't
// want the dependency
export const DistanceUnitMapping = {
export const DistanceUnitMapping: {
centimeter: "CENTIMETERS";
centimeters: "CENTIMETERS";
cm: "CENTIMETERS";
meter: "METERS";
meters: "METERS";
m: "METERS";
kilometer: "KILOMETERS";
kilometers: "KILOMETERS";
km: "KILOMETERS";
inch: "INCHES";
inches: "INCHES";
foot: "FEET";
feet: "FEET";
yard: "YARDS";
yards: "YARDS";
mile: "MILES";
miles: "MILES";
nautical_mile: "NAUTICAL_MILES";
nauticalMile: "NAUTICAL_MILES";
"nautical miles": "NAUTICAL_MILES";
} = {
"centimeter": "CENTIMETERS",
"centimeters": "CENTIMETERS",
"cm": "CENTIMETERS",
Expand Down
25 changes: 24 additions & 1 deletion packages/api/src/groupby/GroupByClause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,30 @@ export type TimestampTimeUnits =
| "HOURS";

export type DateTimeUnits = "DAYS" | "WEEKS" | "MONTHS" | "YEARS" | "QUARTERS";
export const DurationMapping = {
export const DurationMapping: {
quarter: "QUARTERS";
quarters: "QUARTERS";
sec: "SECONDS";
seconds: "SECONDS";
min: "MINUTES";
minute: "MINUTES";
minutes: "MINUTES";
hr: "HOURS";
hrs: "HOURS";
hour: "HOURS";
hours: "HOURS";
day: "DAYS";
days: "DAYS";
wk: "WEEKS";
week: "WEEKS";
weeks: "WEEKS";
mos: "MONTHS";
month: "MONTHS";
months: "MONTHS";
yr: "YEARS";
year: "YEARS";
years: "YEARS";
} = {
...TimeDurationMapping,
"quarter": "QUARTERS",
"quarters": "QUARTERS",
Expand Down
23 changes: 22 additions & 1 deletion packages/api/src/mapping/DurationMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,28 @@
* limitations under the License.
*/

export const TimeDurationMapping = {
export const TimeDurationMapping: {
sec: "SECONDS";
seconds: "SECONDS";
min: "MINUTES";
minute: "MINUTES";
minutes: "MINUTES";
hr: "HOURS";
hrs: "HOURS";
hour: "HOURS";
hours: "HOURS";
day: "DAYS";
days: "DAYS";
wk: "WEEKS";
week: "WEEKS";
weeks: "WEEKS";
mos: "MONTHS";
month: "MONTHS";
months: "MONTHS";
yr: "YEARS";
year: "YEARS";
years: "YEARS";
} = {
"sec": "SECONDS",
"seconds": "SECONDS",
"min": "MINUTES",
Expand Down
25 changes: 24 additions & 1 deletion packages/api/src/timeseries/timeseries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,30 @@ export type TimeseriesDurationUnits =
| "SECONDS"
| "MILLISECONDS";

export const TimeseriesDurationMapping = {
export const TimeseriesDurationMapping: {
sec: "SECONDS";
seconds: "SECONDS";
min: "MINUTES";
minute: "MINUTES";
minutes: "MINUTES";
hr: "HOURS";
hrs: "HOURS";
hour: "HOURS";
hours: "HOURS";
day: "DAYS";
days: "DAYS";
wk: "WEEKS";
week: "WEEKS";
weeks: "WEEKS";
mos: "MONTHS";
month: "MONTHS";
months: "MONTHS";
yr: "YEARS";
year: "YEARS";
years: "YEARS";
ms: "MILLISECONDS";
milliseconds: "MILLISECONDS";
} = {
"ms": "MILLISECONDS",
"milliseconds": "MILLISECONDS",
...TimeDurationMapping,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli.cmd.typescript/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ExitProcessError, getYargsBase } from "@osdk/cli.common";
import { consola } from "consola";
import { generateCommand } from "./generate/generate.js";

export async function cli(args: string[] = process.argv) {
export async function cli(args: string[] = process.argv): Promise<unknown> {
consola.info(
`Palantir OSDK CLI ${process.env.PACKAGE_VERSION}\n`,
);
Expand Down
15 changes: 12 additions & 3 deletions packages/cli.cmd.typescript/src/generate/handleGenerate.mts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import type { TypescriptGenerateArgs } from "./TypescriptGenerateArgs.js";

const USER_AGENT = `osdk-cli.cmd.typescript/${process.env.PACKAGE_VERSION}`;

export async function handleGenerate(args: TypescriptGenerateArgs) {
export async function handleGenerate(
args: TypescriptGenerateArgs,
): Promise<void> {
let success = false;
if (args.ontologyPath) {
success = await generateFromLocalFile(args);
Expand Down Expand Up @@ -260,7 +262,7 @@ async function generateClientSdk(
export function updateVersionsIfTheyExist(
packageJson: any,
versions: Record<string, string>,
) {
): void {
for (const d of ["dependencies", "devDependencies", "peerDependencies"]) {
for (const [key, value] of Object.entries(versions)) {
if (packageJson?.[d]?.[key]) {
Expand All @@ -270,7 +272,14 @@ export function updateVersionsIfTheyExist(
}
}

export async function getDependencyVersions() {
export async function getDependencyVersions(): Promise<{
typescriptVersion: string;
tslibVersion: string;
areTheTypesWrongVersion: string;
osdkApiVersion: string;
osdkClientVersion: string;
osdkLegacyClientVersion: string;
}> {
const ourPackageJsonPath = await getOurPackageJsonPath();

const ourPackageJson = JSON.parse(
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import auth from "./commands/auth/index.js";
import site from "./commands/site/index.js";
import { logConfigFileMiddleware } from "./yargs/logConfigFileMiddleware.js";

export async function cli(args: string[] = process.argv) {
export async function cli(args: string[] = process.argv): Promise<
Record<string, unknown> | undefined
> {
consola.info(
`Palantir OSDK CLI ${process.env.PACKAGE_VERSION}\n`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { SiteDeployArgs } from "./SiteDeployArgs.js";
export async function logDeployCommandConfigFileOverride(
args: Arguments<SiteDeployArgs>,
config: SiteConfig | undefined,
) {
): Promise<void> {
if (
config?.autoVersion != null && args.autoVersion !== config.autoVersion.type
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default async function siteDeployCommand(
token,
tokenFile,
}: SiteDeployInternalArgs,
) {
): Promise<void> {
const loadedToken = await loadToken(token, tokenFile);
const tokenProvider = () => loadedToken;
const clientCtx = createInternalClientContext(foundryUrl, tokenProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { CommonSiteArgs } from "./CommonSiteArgs.js";
export async function logSiteCommandConfigFileOverride(
args: Arguments<CommonSiteArgs>,
config: FoundryConfig | undefined,
) {
): Promise<void> {
if (
config?.site.application != null
&& args.application !== config.site.application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { VersionDeleteArgs } from "./VersionDeleteArgs.js";
export default async function versionDeleteCommand(
{ version, yes, application, foundryUrl, token, tokenFile }:
VersionDeleteArgs,
) {
): Promise<void> {
if (!yes) {
const confirmed = await consola.prompt(
`Are you sure you want to delete the version ${version}?\n${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { VersionGetArgs } from "./VersionGetArgs.js";

export default async function versionGetCommand(
{ foundryUrl, application, token, tokenFile }: VersionGetArgs,
) {
): Promise<void> {
const loadedToken = await loadToken(token, tokenFile);
const tokenProvider = () => loadedToken;
const clientCtx = createInternalClientContext(foundryUrl, tokenProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { VersionListArgs } from "./VersionListArgs.js";

export default async function versionListCommand(
{ foundryUrl, application, token, tokenFile }: VersionListArgs,
) {
): Promise<void> {
const loadedToken = await loadToken(token, tokenFile);
const tokenProvider = () => loadedToken;
const clientCtx = createInternalClientContext(foundryUrl, tokenProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { VersionSetArgs } from "./VersionSetArgs.js";

export default async function versionSetCommand(
{ version, application, foundryUrl, token, tokenFile }: VersionSetArgs,
) {
): Promise<void> {
consola.start(`Setting live version`);
const loadedToken = await loadToken(token, tokenFile);
const tokenProvider = () => loadedToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { VersionUnsetArgs } from "./VersionUnsetArgs.js";

export default async function versionUnsetCommand(
{ yes, application, foundryUrl, token, tokenFile }: VersionUnsetArgs,
) {
): Promise<void> {
if (!yes) {
const confirmed = await consola.prompt(
`Are you sure you want to clear the live site version?\n${
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/consola/handlePromptCancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { consola } from "consola";

export function handlePromptCancel(promptResponse: any) {
export function handlePromptCancel(promptResponse: any): void {
const isFalse = typeof promptResponse === "boolean" && !promptResponse;
// https://github.com/unjs/consola/issues/251
const isSigInt = typeof promptResponse === "symbol"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/net/UserAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export const USER_AGENT = `osdk-cli/${process.env.PACKAGE_VERSION}`;
export const USER_AGENT: string = `osdk-cli/${process.env.PACKAGE_VERSION}`;
2 changes: 1 addition & 1 deletion packages/cli/src/net/createFetch.mts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { USER_AGENT } from "./UserAgent.js";
export function createFetch(
tokenProvider: () => Promise<string> | string,
fetchFn: typeof fetch = fetch,
) {
): typeof fetch {
return createFetchHeaderMutator(
createRequestLoggingFetch(
createErrorExitingFetch(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/yargs/logConfigFileMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { consola } from "consola";
import getConfig from "../util/configLoader.js";

let firstTime = true;
export async function logConfigFileMiddleware() {
export async function logConfigFileMiddleware(): Promise<void> {
if (firstTime) {
firstTime = false;
const config = getConfig();
Expand Down
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"ws": "^8.18.0"
},
"devDependencies": {
"@microsoft/api-documenter": "^7.25.3",
"@microsoft/api-extractor": "^7.47.0",
"@microsoft/api-documenter": "^7.25.21",
"@microsoft/api-extractor": "^7.47.11",
"@osdk/client.test.ontology": "workspace:~",
"@osdk/monorepo.api-extractor": "workspace:~",
"@osdk/monorepo.tsconfig": "workspace:~",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ export interface Client extends SharedClient, OldSharedClient {
}

// DO NOT EXPORT FROM PACKAGE
export const additionalContext = Symbol("additionalContext");
export const additionalContext: unique symbol = Symbol("additionalContext");

// BEGIN: THIS IS GENERATED CODE. DO NOT EDIT.
const MaxOsdkVersion = "2.1.0";
// END: THIS IS GENERATED CODE. DO NOT EDIT.
export type MaxOsdkVersion = typeof MaxOsdkVersion;
const ErrorMessage = Symbol("ErrorMessage");
const ErrorMessage: unique symbol = Symbol("ErrorMessage");
Loading
Loading