-
Notifications
You must be signed in to change notification settings - Fork 17
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
WIP Queries #379
Changes from 16 commits
c5fd1e6
64fe1f5
e1d1969
df61560
3166a4e
4de0dc0
041f34d
ef866f4
7caaddb
3b0a0b0
173e4fc
373ef2b
8680c25
dd29ff3
0008a8b
5029221
0017f2b
ba7117e
73c2988
e64f0a2
5204063
9ecc601
b5ccec3
7acba23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: { type: 'integer', nullable: false }, | ||
} 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,73 @@ | ||
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', type: 'double', nullable: false }, | ||
float: { type: 'float', nullable: false }, | ||
integer: { type: 'integer', nullable: false }, | ||
long: { type: 'long', nullable: false }, | ||
attachment: { type: 'attachment', nullable: false }, | ||
boolean: { type: 'boolean', nullable: false }, | ||
date: { type: 'date', nullable: false }, | ||
string: { type: 'string', nullable: false }, | ||
timestamp: { type: 'timestamp', nullable: false }, | ||
object: { | ||
description: 'undefined', | ||
type: 'object', | ||
object: 'Todo', | ||
nullable: false, | ||
__OsdkTargetType: Todo, | ||
}, | ||
objectSet: { | ||
description: 'undefined', | ||
type: 'objectSet', | ||
objectSet: 'Todo', | ||
nullable: false, | ||
__OsdkTargetType: Todo, | ||
}, | ||
array: { description: 'an array of strings', type: 'string', nullable: false, multiplicity: true }, | ||
set: { description: 'a set of strings', type: 'set', set: { type: 'string', nullable: false }, nullable: false }, | ||
unionNonNullable: { | ||
description: 'a union of strings and integers', | ||
type: 'union', | ||
union: [ | ||
{ type: 'string', nullable: false }, | ||
{ type: 'integer', nullable: false }, | ||
], | ||
nullable: false, | ||
}, | ||
unionNullable: { | ||
description: 'a union of strings and integers but its optional', | ||
type: 'union', | ||
union: [ | ||
{ type: 'string', nullable: false }, | ||
{ type: 'integer', nullable: false }, | ||
], | ||
nullable: true, | ||
}, | ||
struct: { | ||
description: 'a struct with some fields', | ||
type: 'struct', | ||
struct: { name: { type: 'string', nullable: false }, id: { type: 'integer', nullable: false } }, | ||
nullable: false, | ||
}, | ||
twoDimensionalAggregation: { | ||
type: 'twoDimensionalAggregation', | ||
twoDimensionalAggregation: { keyType: 'string', valueType: 'double' }, | ||
}, | ||
threeDimensionalAggregation: { | ||
type: 'threeDimensionalAggregation', | ||
threeDimensionalAggregation: { | ||
keyType: 'range', | ||
keySubtype: 'date', | ||
valueType: { keyType: 'range', keySubtype: 'timestamp', valueType: 'date' }, | ||
}, | ||
}, | ||
}, | ||
output: { type: 'string', nullable: false }, | ||
} satisfies QueryDefinition<'queryTakesAllParameterTypes', 'Todo'>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, what does this string represent? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2024 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { | ||
ObjectQueryDataType, | ||
ObjectSetQueryDataType, | ||
OntologyDefinition, | ||
QueryDataTypeDefinition, | ||
QueryDefinition, | ||
} from "@osdk/api"; | ||
import type { | ||
BaseObjectSet, | ||
DataValueClientToWire, | ||
DataValueWireToClient, | ||
NOOP, | ||
ObjectSet, | ||
OsdkBase, | ||
OsdkObjectPrimaryKeyType, | ||
} from "../index.js"; | ||
import type { PartialByNotStrict } from "../util/PartialBy.js"; | ||
|
||
export type Queries<O extends OntologyDefinition<any>> = { | ||
[K in keyof O["queries"]]: QuerySignatureFromDef<O["queries"][K]>; | ||
}; | ||
|
||
export type QuerySignatureFromDef<T extends QueryDefinition<any, any>> = | ||
keyof T["parameters"] extends never | ||
? () => Promise<QueryReturnType<T["output"]>> | ||
: ( | ||
params: QueryParameterType<T["parameters"]>, | ||
) => Promise<QueryReturnType<T["output"]>>; | ||
|
||
export type QueryParameterType< | ||
T extends Record<any, QueryDataTypeDefinition<any, any>>, | ||
> = NOOP<PartialByNotStrict<NotOptionalParams<T>, OptionalQueryParams<T>>>; | ||
|
||
export type QueryReturnType<T extends QueryDataTypeDefinition<any, any>> = | ||
ssanjay1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
T extends ObjectQueryDataType<any, infer TTargetType> ? OsdkBase<TTargetType> | ||
: T extends ObjectSetQueryDataType<any, infer TTargetType> | ||
? ObjectSet<TTargetType> | ||
: T["type"] extends keyof DataValueWireToClient | ||
? DataValueWireToClient[T["type"]] | ||
: never; | ||
|
||
type OptionalQueryParams< | ||
T extends Record<any, QueryDataTypeDefinition<any, any>>, | ||
> = { | ||
[K in keyof T]: T[K] extends { nullable: true } ? never : K; | ||
}[keyof T]; | ||
|
||
type NotOptionalParams< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this exclude optionals? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the |
||
T extends Record<any, QueryDataTypeDefinition<any, any>>, | ||
> = { | ||
[K in keyof T]: MaybeArrayType<T[K]>; | ||
}; | ||
|
||
type MaybeArrayType<T extends QueryDataTypeDefinition<any, any>> = | ||
T["multiplicity"] extends true ? Array<BaseType<T>> | ||
: BaseType<T>; | ||
|
||
type BaseType<T extends QueryDataTypeDefinition<any, any>> = T extends | ||
ObjectQueryDataType<any, infer TTargetType> | ||
? OsdkBase<TTargetType> | OsdkObjectPrimaryKeyType<TTargetType> | ||
: T extends ObjectSetQueryDataType<any, infer TTargetType> | ||
? BaseObjectSet<TTargetType> | ||
: T["type"] extends keyof DataValueClientToWire | ||
? DataValueClientToWire[T["type"]] | ||
: never; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.