diff --git a/.changeset/unlucky-oranges-peel.md b/.changeset/unlucky-oranges-peel.md new file mode 100644 index 000000000..bc4428e85 --- /dev/null +++ b/.changeset/unlucky-oranges-peel.md @@ -0,0 +1,6 @@ +--- +"@osdk/client.unstable": minor +"@osdk/maker": minor +--- + +Making interface type status configurable diff --git a/packages/client.unstable/src/index.ts b/packages/client.unstable/src/index.ts index 7d9f4f81a..614cce291 100644 --- a/packages/client.unstable/src/index.ts +++ b/packages/client.unstable/src/index.ts @@ -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, diff --git a/packages/maker/src/api/defineInterface.ts b/packages/maker/src/api/defineInterface.ts index c61cc51be..c807ff085 100644 --- a/packages/maker/src/api/defineInterface.ts +++ b/packages/maker/src/api/defineInterface.ts @@ -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 { @@ -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: { @@ -114,7 +132,7 @@ export function defineInterface( extendsInterfaces: extendsInterfaces, links: [], properties, - status: { type: "active", active: {} }, + status, }; return ontologyDefinition.interfaceTypes[apiName] = a; @@ -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}`); + } +} diff --git a/packages/maker/src/api/overall.test.ts b/packages/maker/src/api/overall.test.ts index a2cbd6640..a6d379743 100644 --- a/packages/maker/src/api/overall.test.ts +++ b/packages/maker/src/api/overall.test.ts @@ -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(() => { @@ -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); + }); }); diff --git a/packages/maker/src/api/types.ts b/packages/maker/src/api/types.ts index 30a51d557..d93d36c94 100644 --- a/packages/maker/src/api/types.ts +++ b/packages/maker/src/api/types.ts @@ -21,6 +21,10 @@ import type { ExampleValue, FailureMessage, ImportedTypes, + InterfaceTypeStatus, + InterfaceTypeStatus_active, + InterfaceTypeStatus_deprecated, + InterfaceTypeStatus_experimental, OntologyIrInterfaceType, SharedPropertyTypeGothamMapping, StructFieldType, @@ -44,6 +48,12 @@ export interface Ontology extends valueTypes: Record; importedTypes: ImportedTypes; } +export type { + InterfaceTypeStatus, + InterfaceTypeStatus_active, + InterfaceTypeStatus_deprecated, + InterfaceTypeStatus_experimental, +}; export interface InterfaceType extends Omit< @@ -57,6 +67,7 @@ export interface InterfaceType extends > { properties: Record; + status: InterfaceTypeStatus; } export interface PropertyType {