Skip to content

Commit

Permalink
Generate ontology in ts 5.5-beta safe way (#355)
Browse files Browse the repository at this point in the history
* Generate ontology in ts 5.5-beta safe way

* Add changeset
  • Loading branch information
ericanderson authored May 29, 2024
1 parent e3f900e commit 0ecd42b
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-peaches-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/generator": minor
---

Generates 2.0's Ontology.ts in a typescript 5.5.0-beta safe way
52 changes: 37 additions & 15 deletions examples-extra/basic/sdk/src/generatedNoCheck/Ontology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,42 @@ import * as Actions from './ontology/actions/index.js';
import * as Interfaces from './ontology/interfaces.js';
import * as Objects from './ontology/objects.js';

const _Ontology = {
export interface Ontology
extends OntologyDefinition<
| 'BoundariesUsState'
| 'BuilderDeploymentState'
| 'Employee'
| 'ObjectTypeWithAllPropertyTypes'
| 'Person'
| 'Todo'
| 'Venture'
| 'WeatherStation'
> {
metadata: OntologyMetadata;
objects: {
BoundariesUsState: Objects.BoundariesUsState;
BuilderDeploymentState: Objects.BuilderDeploymentState;
Employee: Objects.Employee;
ObjectTypeWithAllPropertyTypes: Objects.ObjectTypeWithAllPropertyTypes;
Person: Objects.Person;
Todo: Objects.Todo;
Venture: Objects.Venture;
WeatherStation: Objects.WeatherStation;
};
actions: {
actionTakesAllParameterTypes: typeof Actions.actionTakesAllParameterTypes;
assignEmployee1: typeof Actions.assignEmployee1;
createTodo: typeof Actions.createTodo;
};
queries: {
// TODO
};
interfaces: {
FooInterface: Interfaces.FooInterface;
};
}

export const Ontology: Ontology = {
metadata: OntologyMetadata,
objects: {
BoundariesUsState: Objects.BoundariesUsState,
Expand All @@ -27,17 +62,4 @@ const _Ontology = {
interfaces: {
FooInterface: Interfaces.FooInterface,
},
} satisfies OntologyDefinition<
| 'BoundariesUsState'
| 'BuilderDeploymentState'
| 'Employee'
| 'ObjectTypeWithAllPropertyTypes'
| 'Person'
| 'Todo'
| 'Venture'
| 'WeatherStation'
>;

type _Ontology = typeof _Ontology;
export interface Ontology extends _Ontology {}
export const Ontology = _Ontology as Ontology;
};
31 changes: 25 additions & 6 deletions examples-extra/docs_example/src/generatedNoCheck/Ontology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,30 @@ import { OntologyMetadata } from './OntologyMetadata';
import * as Actions from './ontology/actions/index';
import * as Objects from './ontology/objects';

const _Ontology = {
export interface Ontology extends OntologyDefinition<'Employee' | 'equipment' | 'Office' | 'Todo'> {
metadata: OntologyMetadata;
objects: {
Employee: Objects.Employee;
equipment: Objects.equipment;
Office: Objects.Office;
Todo: Objects.Todo;
};
actions: {
completeTodo: typeof Actions.completeTodo;
createOffice: typeof Actions.createOffice;
createOfficeAndEmployee: typeof Actions.createOfficeAndEmployee;
createTodo: typeof Actions.createTodo;
moveOffice: typeof Actions.moveOffice;
promoteEmployee: typeof Actions.promoteEmployee;
promoteEmployeeObject: typeof Actions.promoteEmployeeObject;
};
queries: {
// TODO
};
interfaces: {};
}

export const Ontology: Ontology = {
metadata: OntologyMetadata,
objects: {
Employee: Objects.Employee,
Expand All @@ -24,8 +47,4 @@ const _Ontology = {
// TODO
},
interfaces: {},
} satisfies OntologyDefinition<'Employee' | 'equipment' | 'Office' | 'Todo'>;

type _Ontology = typeof _Ontology;
export interface Ontology extends _Ontology {}
export const Ontology = _Ontology as Ontology;
};
23 changes: 17 additions & 6 deletions examples-extra/todoapp/src/generatedNoCheck2/Ontology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@ import { OntologyMetadata } from './OntologyMetadata';
import * as Actions from './ontology/actions/index';
import * as Objects from './ontology/objects';

const _Ontology = {
export interface Ontology extends OntologyDefinition<'Todo'> {
metadata: OntologyMetadata;
objects: {
Todo: Objects.Todo;
};
actions: {
completeTodo: typeof Actions.completeTodo;
createTodo: typeof Actions.createTodo;
};
queries: {
// TODO
};
interfaces: {};
}

export const Ontology: Ontology = {
metadata: OntologyMetadata,
objects: {
Todo: Objects.Todo,
Expand All @@ -16,8 +31,4 @@ const _Ontology = {
// TODO
},
interfaces: {},
} satisfies OntologyDefinition<'Todo'>;

type _Ontology = typeof _Ontology;
export interface Ontology extends _Ontology {}
export const Ontology = _Ontology as Ontology;
};
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,37 @@ export async function generateClientSdkVersionTwoPointZero(
import * as Interfaces from "./ontology/interfaces${importExt}";
import { OntologyMetadata } from "./OntologyMetadata${importExt}";
const _Ontology = {
export interface Ontology extends OntologyDefinition<${
stringUnionFrom(objectNames)
}> {
metadata: OntologyMetadata,
objects: {
${
objectNames.map((objectName) => {
return `${objectName}: Objects.${objectName}`;
}).join(",\n")
}
},
actions: {
${
actionNames.map((actionName) => {
return `${actionName}: typeof Actions.${actionName}`;
}).join(",\n")
}
},
queries: {
// TODO
},
interfaces: {
${
interfaceNames.map((objectName) => {
return `${objectName}: Interfaces.${objectName}`;
}).join(",\n")
}
}
}
export const Ontology: Ontology = {
metadata: OntologyMetadata,
objects: {
${
Expand Down Expand Up @@ -106,11 +136,8 @@ export async function generateClientSdkVersionTwoPointZero(
}
}
} satisfies OntologyDefinition<${stringUnionFrom(objectNames)}>;
};
type _Ontology = typeof _Ontology;
export interface Ontology extends _Ontology {}
export const Ontology = _Ontology as Ontology;
`,
),
);
Expand Down

0 comments on commit 0ecd42b

Please sign in to comment.