Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Queries #379

Merged
merged 24 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/plenty-berries-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@osdk/legacy-client": minor
"@osdk/shared.test": minor
"@osdk/client.api": minor
"@osdk/generator": minor
"@osdk/client": minor
"@osdk/api": minor
---

Add support for queries in 2.0
7 changes: 5 additions & 2 deletions examples-extra/basic/sdk/src/generatedNoCheck/Ontology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { OntologyDefinition } from '@osdk/api';
import * as Actions from './ontology/actions/index.js';
import * as Interfaces from './ontology/interfaces.js';
import * as Objects from './ontology/objects.js';
import * as Queries from './ontology/queries/index.js';
import { OntologyMetadata } from './OntologyMetadata.js';

export interface Ontology
Expand Down Expand Up @@ -32,7 +33,8 @@ export interface Ontology
createTodo: typeof Actions.createTodo;
};
queries: {
// TODO
getTodoCount: typeof Queries.getTodoCount;
queryTakesAllParameterTypes: typeof Queries.queryTakesAllParameterTypes;
};
interfaces: {
FooInterface: Interfaces.FooInterface;
Expand All @@ -57,7 +59,8 @@ export const Ontology: Ontology = {
createTodo: Actions.createTodo,
},
queries: {
// TODO
getTodoCount: Queries.getTodoCount,
queryTakesAllParameterTypes: Queries.queryTakesAllParameterTypes,
},
interfaces: {
FooInterface: Interfaces.FooInterface,
Expand Down
1 change: 1 addition & 0 deletions examples-extra/basic/sdk/src/generatedNoCheck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { Ontology } from './Ontology.js';
export * from './ontology/actions/index.js';
export * from './ontology/interfaces.js';
export * from './ontology/objects.js';
export * from './ontology/queries/index.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { QueryDefinition } from '@osdk/api';

export const getTodoCount = {
apiName: 'getTodoCount',
type: 'query',
version: '0.1.2',
parameters: {},
output: { nullable: false, type: 'integer' },
} satisfies QueryDefinition<'getTodoCount', never>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './getTodoCount.js';
export * from './queryTakesAllParameterTypes.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { QueryDefinition } from '@osdk/api';
import { Todo } from '../objects.js';
export const queryTakesAllParameterTypes = {
apiName: 'queryTakesAllParameterTypes',
description: 'description of the query that takes all parameter types',
displayName: 'qTAPT',
type: 'query',
version: 'version',
parameters: {
double: { description: 'a double parameter', nullable: false, type: 'double' },
float: { nullable: false, type: 'float' },
integer: { nullable: false, type: 'integer' },
long: { nullable: false, type: 'long' },
attachment: { nullable: false, type: 'attachment' },
boolean: { nullable: false, type: 'boolean' },
date: { nullable: false, type: 'date' },
string: { nullable: false, type: 'string' },
timestamp: { nullable: false, type: 'timestamp' },
object: {
nullable: false,
object: 'Todo',
type: 'object',

__OsdkTargetType: Todo,
},
objectSet: {
nullable: false,
objectSet: 'Todo',
type: 'objectSet',

__OsdkTargetType: Todo,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericanderson is this not codifying the target type here? I may be misunderstanding your comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Still wouldn't rely on it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give more color, I want the option to remove the runtime cost of these and reduce them to just compile time types (for the most part). In order to do that, we need to not rely on this from bundling but instead to get the latest from the server before execution.

},
array: { description: 'an array of strings', multiplicity: true, nullable: false, type: 'string' },
set: {
description: 'a set of strings',
nullable: false,
set: {
type: 'string',
nullable: false,
},
type: 'set',
},
unionNonNullable: {
description: 'a union of strings and integers',
nullable: false,
type: 'union',
union: [
{
type: 'string',
nullable: false,
},
{
type: 'integer',
nullable: false,
},
],
},
unionNullable: {
description: 'a union of strings and integers but its optional',
nullable: true,
type: 'union',
union: [
{
type: 'string',
nullable: false,
},
{
type: 'integer',
nullable: false,
},
],
},
struct: {
description: 'a struct with some fields',
nullable: false,
struct: {
name: {
type: 'string',
nullable: false,
},
id: {
type: 'integer',
nullable: false,
},
},
type: 'struct',
},
twoDimensionalAggregation: {
nullable: false,
twoDimensionalAggregation: {
keyType: 'string',
valueType: 'double',
},
type: 'twoDimensionalAggregation',
},
threeDimensionalAggregation: {
nullable: false,
threeDimensionalAggregation: {
keyType: 'range',
keySubtype: 'date',
valueType: {
keyType: 'range',
keySubtype: 'timestamp',
valueType: 'date',
},
},
type: 'threeDimensionalAggregation',
},
},
output: { nullable: false, type: 'string' },
} satisfies QueryDefinition<'queryTakesAllParameterTypes', 'Todo'>;
8 changes: 2 additions & 6 deletions examples-extra/docs_example/src/generatedNoCheck/Ontology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export interface Ontology extends OntologyDefinition<'Employee' | 'equipment' |
promoteEmployee: typeof Actions.promoteEmployee;
promoteEmployeeObject: typeof Actions.promoteEmployeeObject;
};
queries: {
// TODO
};
queries: {};
interfaces: {};
}

Expand All @@ -43,8 +41,6 @@ export const Ontology: Ontology = {
promoteEmployee: Actions.promoteEmployee,
promoteEmployeeObject: Actions.promoteEmployeeObject,
},
queries: {
// TODO
},
queries: {},
interfaces: {},
};
1 change: 1 addition & 0 deletions examples-extra/docs_example/src/generatedNoCheck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { Ontology } from './Ontology';
export * from './ontology/actions/index';
export * from './ontology/interfaces';
export * from './ontology/objects';
export * from './ontology/queries/index';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const queryTakesAllParameterTypes = {
twoDimensionalAggregation: {
type: 'twoDimensionalAggregation',
twoDimensionalAggregation: { keyType: 'string', valueType: 'double' },
nullable: false,
},
threeDimensionalAggregation: {
type: 'threeDimensionalAggregation',
Expand All @@ -55,6 +56,7 @@ export const queryTakesAllParameterTypes = {
keySubtype: 'date',
valueType: { keyType: 'range', keySubtype: 'timestamp', valueType: 'date' },
},
nullable: false,
},
},
output: { type: 'string', nullable: false },
Expand Down
8 changes: 2 additions & 6 deletions examples-extra/todoapp/src/generatedNoCheck2/Ontology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export interface Ontology extends OntologyDefinition<'Todo'> {
completeTodo: typeof Actions.completeTodo;
createTodo: typeof Actions.createTodo;
};
queries: {
// TODO
};
queries: {};
interfaces: {};
}

Expand All @@ -27,8 +25,6 @@ export const Ontology: Ontology = {
completeTodo: Actions.completeTodo,
createTodo: Actions.createTodo,
},
queries: {
// TODO
},
queries: {},
interfaces: {},
};
1 change: 1 addition & 0 deletions examples-extra/todoapp/src/generatedNoCheck2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { Ontology } from './Ontology';
export * from './ontology/actions/index';
export * from './ontology/interfaces';
export * from './ontology/objects';
export * from './ontology/queries/index';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
45 changes: 31 additions & 14 deletions packages/api/src/ontology/QueryDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,37 @@
* limitations under the License.
*/

export interface QueryDefinition<Q extends string, K extends string> {
import type { OsdkMetadata } from "../OsdkMetadata.js";
import type { ObjectTypeDefinition } from "./ObjectTypeDefinition.js";

export interface QueryDefinition<
Q extends string,
K extends string,
> {
type: "query";
apiName: Q;
description?: string;
displayName?: string;
version: string;
parameters: Record<string, QueryParameterDefinition<K>>;
output: QueryDataTypeDefinition<K>;
parameters: Record<string, QueryParameterDefinition<K, any>>;
output: QueryDataTypeDefinition<K, any>;
osdkMetadata?: OsdkMetadata;
}

export type QueryParameterDefinition<K extends string> = {
export type QueryParameterDefinition<
K extends string,
T_Target extends ObjectTypeDefinition<any> = never,
> = {
description?: string;
} & QueryDataTypeDefinition<K>;
} & QueryDataTypeDefinition<K, T_Target>;

export type QueryDataTypeDefinition<K extends string> =
export type QueryDataTypeDefinition<
K extends string,
T_Target extends ObjectTypeDefinition<any> = never,
> =
| PrimitiveDataType
| ObjectQueryDataType<K>
| ObjectSetQueryDataType<K>
| ObjectQueryDataType<K, T_Target>
| ObjectSetQueryDataType<K, T_Target>
| SetQueryDataType<K>
| UnionQueryDataType<K>
| StructQueryDataType<K>
Expand Down Expand Up @@ -59,16 +72,20 @@ export type PrimitiveDataType<
Q extends WireQueryDataTypes = WireQueryDataTypes,
> = BaseQueryDataTypeDefinition<Q>;

export interface ObjectQueryDataType<K extends string>
extends BaseQueryDataTypeDefinition<"object">
{
export interface ObjectQueryDataType<
K extends string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, what does this string represent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just represents the object API name

T_Target extends ObjectTypeDefinition<any> = never,
> extends BaseQueryDataTypeDefinition<"object"> {
object: K;
__OsdkTargetType?: T_Target;
}

export interface ObjectSetQueryDataType<K extends string>
extends BaseQueryDataTypeDefinition<"objectSet">
{
export interface ObjectSetQueryDataType<
K extends string,
T_Target extends ObjectTypeDefinition<any> = never,
> extends BaseQueryDataTypeDefinition<"objectSet"> {
objectSet: K;
__OsdkTargetType?: T_Target;
}

export interface SetQueryDataType<K extends string>
Expand Down
Loading