Skip to content

Commit

Permalink
Fix primary key types (#500)
Browse files Browse the repository at this point in the history
* fix primary key types

* add changesets
  • Loading branch information
ssanjay1 authored Jul 19, 2024
1 parent dec005b commit d8edf10
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changeset/olive-tigers-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@osdk/generator-converters": minor
"@osdk/client.api": minor
"@osdk/api": minor
---

Fix primary key types
2 changes: 1 addition & 1 deletion etc/client.api.report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export type Osdk<Q extends ObjectTypeDefinition<any> | InterfaceDefinition<any,
__apiName: Q["apiName"] & {
__OsdkType?: Q["apiName"];
};
__primaryKey: Q extends ObjectTypeDefinition<any> ? OsdkObjectPrimaryKeyType<Q> : unknown;
__primaryKey: Q extends ObjectTypeDefinition<any> ? OsdkObjectPrimaryKeyType<Q> : string | number | boolean;
$link: Q extends ObjectTypeDefinition<any> ? OsdkObjectLinksObject<Q> : never;
$as: <NEW_Q extends ValidToFrom<Q>>(type: NEW_Q | string) => Osdk<NEW_Q, ConvertProps<Q, NEW_Q, P>, UnderlyingProps<Q, P, Z, NEW_Q>>;
} & (IsNever<P> extends true ? {} : string extends P ? {} : "$rid" extends P ? {
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/ontology/ObjectTypeDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -79,7 +80,7 @@ export interface ObjectTypeDefinition<
> extends ObjectInterfaceBaseDefinition<K, N> {
type: "object";
primaryKeyApiName: keyof this["properties"];
primaryKeyType: WirePropertyTypes;
primaryKeyType: PrimaryKeyTypes;

/**
* Optional because they may not exist on legacy.
Expand Down
26 changes: 26 additions & 0 deletions packages/api/src/ontology/PrimaryKeyTypes.ts
Original file line number Diff line number Diff line change
@@ -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";
2 changes: 1 addition & 1 deletion packages/client.api/src/OsdkObjectFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export type Osdk<
/** @deprecated use $primaryKey */
__primaryKey: Q extends ObjectTypeDefinition<any>
? OsdkObjectPrimaryKeyType<Q>
: unknown;
: string | number | boolean;

// $uniqueId: string; // will be dynamic

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}`,
);
Expand Down

0 comments on commit d8edf10

Please sign in to comment.