diff --git a/.changeset/olive-tigers-sniff.md b/.changeset/olive-tigers-sniff.md new file mode 100644 index 000000000..e1052a64a --- /dev/null +++ b/.changeset/olive-tigers-sniff.md @@ -0,0 +1,7 @@ +--- +"@osdk/generator-converters": minor +"@osdk/client.api": minor +"@osdk/api": minor +--- + +Fix primary key types diff --git a/etc/client.api.report.api.md b/etc/client.api.report.api.md index 6675d053b..8cb8ea24b 100644 --- a/etc/client.api.report.api.md +++ b/etc/client.api.report.api.md @@ -483,7 +483,7 @@ export type Osdk | InterfaceDefinition ? OsdkObjectPrimaryKeyType : unknown; + __primaryKey: Q extends ObjectTypeDefinition ? OsdkObjectPrimaryKeyType : string | number | boolean; $link: Q extends ObjectTypeDefinition ? OsdkObjectLinksObject : never; $as: >(type: NEW_Q | string) => Osdk, UnderlyingProps>; } & (IsNever

extends true ? {} : string extends P ? {} : "$rid" extends P ? { diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 4d6df50c7..fa50c0a5d 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -58,6 +58,7 @@ export type { } from "./ontology/ObjectTypeDefinition.js"; export type { OntologyDefinition } from "./ontology/OntologyDefinition.js"; export type { OntologyMetadata } from "./ontology/OntologyMetadata.js"; +export type { PrimaryKeyTypes } from "./ontology/PrimaryKeyTypes.js"; export type { AggregationKeyDataType, ObjectQueryDataType, diff --git a/packages/api/src/ontology/ObjectTypeDefinition.ts b/packages/api/src/ontology/ObjectTypeDefinition.ts index 8622078c1..3798e6d4b 100644 --- a/packages/api/src/ontology/ObjectTypeDefinition.ts +++ b/packages/api/src/ontology/ObjectTypeDefinition.ts @@ -17,6 +17,7 @@ import type { ObjectOrInterfaceDefinition } from "../index.js"; import type { OsdkMetadata } from "../OsdkMetadata.js"; import type { OntologyDefinition } from "./OntologyDefinition.js"; +import type { PrimaryKeyTypes } from "./PrimaryKeyTypes.js"; import type { VersionString } from "./VersionString.js"; import type { WirePropertyTypes } from "./WirePropertyTypes.js"; @@ -79,7 +80,7 @@ export interface ObjectTypeDefinition< > extends ObjectInterfaceBaseDefinition { type: "object"; primaryKeyApiName: keyof this["properties"]; - primaryKeyType: WirePropertyTypes; + primaryKeyType: PrimaryKeyTypes; /** * Optional because they may not exist on legacy. diff --git a/packages/api/src/ontology/PrimaryKeyTypes.ts b/packages/api/src/ontology/PrimaryKeyTypes.ts new file mode 100644 index 000000000..546c71832 --- /dev/null +++ b/packages/api/src/ontology/PrimaryKeyTypes.ts @@ -0,0 +1,26 @@ +/* + * Copyright 2023 Palantir Technologies, Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export type PrimaryKeyTypes = + | "string" + | "datetime" + | "double" + | "boolean" + | "integer" + | "timestamp" + | "short" + | "long" + | "byte"; diff --git a/packages/client.api/src/OsdkObjectFrom.ts b/packages/client.api/src/OsdkObjectFrom.ts index ac24d3ac9..97ceb8ca8 100644 --- a/packages/client.api/src/OsdkObjectFrom.ts +++ b/packages/client.api/src/OsdkObjectFrom.ts @@ -139,7 +139,7 @@ export type Osdk< /** @deprecated use $primaryKey */ __primaryKey: Q extends ObjectTypeDefinition ? OsdkObjectPrimaryKeyType - : unknown; + : string | number | boolean; // $uniqueId: string; // will be dynamic diff --git a/packages/generator-converters/src/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts b/packages/generator-converters/src/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts index d520fa7b5..fa4e72dc3 100644 --- a/packages/generator-converters/src/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts +++ b/packages/generator-converters/src/wirePropertyV2ToSdkPrimaryKeyTypeDefinition.ts @@ -14,23 +14,18 @@ * limitations under the License. */ -import type { WirePropertyTypes } from "@osdk/api"; +import type { PrimaryKeyTypes } from "@osdk/api"; import type { PropertyV2 } from "@osdk/gateway/types"; export function wirePropertyV2ToSdkPrimaryKeyTypeDefinition( input: PropertyV2, -): WirePropertyTypes { +): PrimaryKeyTypes { switch (input.dataType.type) { case "integer": case "double": case "string": case "boolean": - case "attachment": case "byte": - case "decimal": - case "float": - case "geopoint": - case "geoshape": case "long": case "short": { return input.dataType.type; @@ -41,9 +36,14 @@ export function wirePropertyV2ToSdkPrimaryKeyTypeDefinition( case "timestamp": { return "timestamp"; } + case "geopoint": + case "geoshape": + case "decimal": + case "attachment": case "timeseries": case "array": case "marking": + case "float": throw new Error( `Type not supported for primaryKey: ${input.dataType.type}`, );