Skip to content

Commit

Permalink
Make interface type status configurable (#1069)
Browse files Browse the repository at this point in the history
* adding the ability to set interface type status

* removing example and exporting types

* handling deprecated case

* adding deprecated typed test

* changeset

* removing interfacetyperid

* dont expose raw InterfaceTypeStatus

* nit

---------

Co-authored-by: Katie Kauffman <[email protected]>
  • Loading branch information
kkauff and Katie Kauffman authored Dec 19, 2024
1 parent b773513 commit 06e66dc
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/unlucky-oranges-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@osdk/client.unstable": minor
"@osdk/maker": minor
---

Making interface type status configurable
8 changes: 8 additions & 0 deletions packages/client.unstable/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ export type { ValueTypeDisplayMetadata } from "./generated/type-registry/api/Val
export type { ValueTypeStatus } from "./generated/type-registry/api/ValueTypeStatus.js";
export type { ValueTypeVersion } from "./generated/type-registry/api/ValueTypeVersion.js";

export type { InterfaceTypeRid } from "./generated/ontology-metadata/api/InterfaceTypeRid.js";
export type {
InterfaceTypeStatus,
InterfaceTypeStatus_active,
InterfaceTypeStatus_deprecated,
InterfaceTypeStatus_experimental,
} from "./generated/ontology-metadata/api/InterfaceTypeStatus.js";

export type {
ApiNameValueTypeReference,
ImportedSharedPropertyTypes,
Expand Down
48 changes: 47 additions & 1 deletion packages/maker/src/api/defineInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,28 @@ import { defineSharedPropertyType } from "./defineSpt.js";
import type { BlueprintIcon } from "./iconNames.js";
import type {
InterfaceType,
InterfaceTypeStatus,
PropertyTypeType,
SharedPropertyType,
} from "./types.js";

type SimplifiedInterfaceTypeStatus =
| { type: "deprecated"; message: string; deadline: string }
| { type: "active" }
| { type: "experimental" };

export function defineInterface(
opts: {
apiName: string;
displayName?: string;
description?: string;
icon?: { locator: BlueprintIcon; color: string };
status?: SimplifiedInterfaceTypeStatus;
properties?: Record<
string,
SharedPropertyType | PropertyTypeType
>;

extends?: InterfaceType | InterfaceType[] | string | string[];
},
): InterfaceType {
Expand Down Expand Up @@ -99,6 +107,16 @@ export function defineInterface(
}
}

const status: InterfaceTypeStatus = mapSimplifiedStatusToInterfaceTypeStatus(
opts.status ?? { type: "active" },
);

invariant(
status.type !== "deprecated"
|| (status.deprecated.message && status.deprecated.deadline),
`Deprecated status must include message and deadline properties.`,
);

const a: InterfaceType = {
apiName,
displayMetadata: {
Expand All @@ -114,7 +132,7 @@ export function defineInterface(
extendsInterfaces: extendsInterfaces,
links: [],
properties,
status: { type: "active", active: {} },
status,
};

return ontologyDefinition.interfaceTypes[apiName] = a;
Expand All @@ -131,3 +149,31 @@ function isPropertyTypeType(
|| v === "short" || v === "string"
|| v === "timestamp";
}

function mapSimplifiedStatusToInterfaceTypeStatus(
status: SimplifiedInterfaceTypeStatus,
): InterfaceTypeStatus {
switch (status.type) {
case "deprecated":
return {
type: "deprecated",
deprecated: {
message: status.message,
deadline: status.deadline,
replacedBy: undefined,
},
};
case "active":
return {
type: "active",
active: {},
};
case "experimental":
return {
type: "experimental",
experimental: {},
};
default:
throw new Error(`Invalid status type: ${(status as any).type}`);
}
}
38 changes: 37 additions & 1 deletion packages/maker/src/api/overall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
} from "./defineOntology.js";
import { defineSharedPropertyType } from "./defineSpt.js";
import { defineValueType } from "./defineValueType.js";
import type { InterfaceType } from "./types.js";
import type {
InterfaceType,
InterfaceTypeStatus_deprecated,
InterfaceTypeStatus_experimental,
} from "./types.js";

describe("Ontology Defining", () => {
beforeEach(() => {
Expand Down Expand Up @@ -1307,4 +1311,36 @@ describe("Ontology Defining", () => {
}
`);
});

it("defaults interface status to active", () => {
const result = defineInterface({ apiName: "Foo" });
expect(result.status).toEqual({ type: "active", active: {} });
});

it("sets interface status as experimental from opts as typed", () => {
const experimentalStatus = {
type: "experimental",
experimental: {},
} as InterfaceTypeStatus_experimental;
const result = defineInterface({
apiName: "Foo",
status: { type: "experimental" },
});
expect(result.status).toEqual(experimentalStatus);
});

it("sets interface status as deprecated from opts as typed", () => {
const deprecatedStatus = {
type: "deprecated",
deprecated: {
message: "foo",
deadline: "foo",
},
} as InterfaceTypeStatus_deprecated;
const result = defineInterface({
apiName: "Foo",
status: { type: "deprecated", message: "foo", deadline: "foo" },
});
expect(result.status).toEqual(deprecatedStatus);
});
});
11 changes: 11 additions & 0 deletions packages/maker/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import type {
ExampleValue,
FailureMessage,
ImportedTypes,
InterfaceTypeStatus,
InterfaceTypeStatus_active,
InterfaceTypeStatus_deprecated,
InterfaceTypeStatus_experimental,
OntologyIrInterfaceType,
SharedPropertyTypeGothamMapping,
StructFieldType,
Expand All @@ -44,6 +48,12 @@ export interface Ontology extends
valueTypes: Record<string, ValueTypeDefinitionVersion[]>;
importedTypes: ImportedTypes;
}
export type {
InterfaceTypeStatus,
InterfaceTypeStatus_active,
InterfaceTypeStatus_deprecated,
InterfaceTypeStatus_experimental,
};

export interface InterfaceType extends
Omit<
Expand All @@ -57,6 +67,7 @@ export interface InterfaceType extends
>
{
properties: Record<string, SharedPropertyType>;
status: InterfaceTypeStatus;
}

export interface PropertyType {
Expand Down

0 comments on commit 06e66dc

Please sign in to comment.