Skip to content

Commit

Permalink
WIP Queries (#379)
Browse files Browse the repository at this point in the history
* starting queries work

* first pass, no tests

* refactor

* progress

* Get objects working

* object set support

* add obejctset supoprt

* remove console logs

* remove newlines

* remove unsused endpoints file

* add 2d agg input support

* 3d agg test

* a little cleanup

* fix empty index files

* start addressing PR comments

* codegen cleanup

* only use provider for object defs

* clean up bucket types

* a little more codegen cleanup

* nullable checks

* add changeset
  • Loading branch information
ssanjay1 authored Jul 15, 2024
1 parent 116d848 commit 3ec7c38
Show file tree
Hide file tree
Showing 34 changed files with 1,584 additions and 55 deletions.
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,
},
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,
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

0 comments on commit 3ec7c38

Please sign in to comment.