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

WIP Queries #379

merged 24 commits into from
Jul 15, 2024

Conversation

ssanjay1
Copy link
Contributor

@ssanjay1 ssanjay1 commented Jun 6, 2024

WIP: Do not merge

* limitations under the License.
*/

import type {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to delete this, ignore

>;
}
case "object": {
const def = definitions.get(responseDataType.object);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reading through this again, I'm not sure I actually need to do this since I should have captured the objectDef in OsdkTargetType

Copy link
Member

Choose a reason for hiding this comment

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

See my other comment about why I don't want to rely on the definitions in the outputted sdk at runtime.

return responseValue as QueryReturnType<typeof responseDataType>;
}
case "twoDimensionalAggregation": {
const result: { key: any; value: any }[] = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are any's right now, once I clean up the 2d/3d aggs type can clean this up

query: Q,
): QuerySignatureFromDef<Q> {
return function(...args: any[]) {
return applyQuery(client, query, ...args);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just kept consistent with what actions does for now, can switch over later

Copy link
Member

Choose a reason for hiding this comment

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

Yeah we can optimize later. I agree with getting it functionally correct for now.

}

switch (desiredType.type) {
case "attachment": {
Copy link
Contributor Author

@ssanjay1 ssanjay1 Jun 26, 2024

Choose a reason for hiding this comment

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

Now that we have the metadata of the query to help us convert to the right wire type, I'm not sure if we should throw if we don't get the right types. E.g. if the desiredType is an object, but what we got is not an OsdkBaseObject, should we throw here, or just pass through the value to the wire and rely on the backend to tell us something went wrong? I'm leaning on the side of us throwing here, but not sure

Copy link
Member

Choose a reason for hiding this comment

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

Behaviorally I think they will both result in an error thrown, it is just a question of how useful the error is. This might be a situation where in production we just pass through but in development we provide a lot of details. Once you get to production this type of logical error shouldnt exist.

packages/client/tsup.config.bundled_xnzkd6wirio.mjs Outdated Show resolved Hide resolved
>;
}
case "object": {
const def = responseDataType.__OsdkTargetType
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if for some reason the objectDef wasn't capture in the type, I also just try manually loading the def from the ontologyProvider and then throw if both times I can't find it. Not sure if this is overkill though...

Copy link
Member

Choose a reason for hiding this comment

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

That capture of the type is just for typing, we dont actually codify it right? I think you always want to go to the provider

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to just use provider

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

packages/client.api/src/queries/Queries.ts Show resolved Hide resolved
[K in keyof T]: T[K] extends { nullable: true } ? never : K;
}[keyof T];

type NotOptionalParams<
Copy link
Member

Choose a reason for hiding this comment

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

Should this exclude optionals?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the PartialByNotStrict above should handle removing any optional param overlap for us right?

) {
const withoutMultiplicity = { ...responseDataType, multiplicity: false };
for (let i = 0; i < responseValue.length; i++) {
responseValue[i] = remapQueryResponse(
Copy link
Member

Choose a reason for hiding this comment

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

Its okay that this doesnt await?

Copy link
Member

Choose a reason for hiding this comment

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

Actually this function doesnt have any awaits? is responseValue[i] an any? This code is confusing me without looking at in in an IDE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch, the tests for some of the nested types seemed to work fine without it, but addd the awaits in case. (Should also add a test for arrays I guess)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea responseValue[i] is any, because it's typed as DataValue which is just any

>;
}
case "object": {
const def = responseDataType.__OsdkTargetType
Copy link
Member

Choose a reason for hiding this comment

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

That capture of the type is just for typing, we dont actually codify it right? I think you always want to go to the provider

key: "Q-AFO",
groups: [],
},
]);
Copy link
Member

Choose a reason for hiding this comment

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

It would probably be good to check that it makes sense with unkown return types

import type { OntologyObjectV2 } from "@osdk/internal.foundry";

export function isOntologyObjectV2(o: any): o is OntologyObjectV2 {
return o && typeof o === "object" && typeof o.__apiName === "string"
&& o.__primaryKey != null;
}

export function isOsdkBaseObject(o: any): o is OsdkBase<any> {
Copy link
Member

Choose a reason for hiding this comment

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

Can we put this in another file? I dont think its related to the other function at all

}

switch (desiredType.type) {
case "attachment": {
Copy link
Member

Choose a reason for hiding this comment

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

Behaviorally I think they will both result in an error thrown, it is just a question of how useful the error is. This might be a situation where in production we just pass through but in development we provide a lot of details. Once you get to production this type of logical error shouldnt exist.

packages/client/tsup.config.bundled_xnzkd6wirio.mjs Outdated Show resolved Hide resolved
type: 'objectSet',
objectSet: 'Todo',
nullable: false,
__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.

Copy link
Member

@ericanderson ericanderson left a comment

Choose a reason for hiding this comment

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

Only remaining thing is to be sure we arent using the runtime values for the definitions and loading from the server instead.

type: 'objectSet',
objectSet: 'Todo',
nullable: false,
__OsdkTargetType: Todo,
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.

>;
}
case "object": {
const def = definitions.get(responseDataType.object);
Copy link
Member

Choose a reason for hiding this comment

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

See my other comment about why I don't want to rely on the definitions in the outputted sdk at runtime.

@ssanjay1 ssanjay1 marked this pull request as ready for review July 14, 2024 18:02
@ssanjay1 ssanjay1 merged commit 3ec7c38 into main Jul 15, 2024
6 checks passed
@ssanjay1 ssanjay1 deleted the ssanjay/queries branch July 15, 2024 15:04
bryantpark04 added a commit that referenced this pull request Jul 15, 2024
* Bump @typescript-eslint/parser from 7.9.0 to 7.16.0 (#445)

* Bump @typescript-eslint/parser from 7.9.0 to 7.16.0

Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 7.9.0 to 7.16.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v7.16.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fix example generation and group eslint-parser in the future

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Eric Anderson <[email protected]>

* Bump pino-pretty from 11.0.0 to 11.2.1 (#471)

Bumps [pino-pretty](https://github.com/pinojs/pino-pretty) from 11.0.0 to 11.2.1.
- [Release notes](https://github.com/pinojs/pino-pretty/releases)
- [Commits](pinojs/pino-pretty@v11.0.0...v11.2.1)

---
updated-dependencies:
- dependency-name: pino-pretty
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Version Packages (beta) (#463)

* Add api-extractor, fix turbo, fix refactor (#415)

* Add api-extractor, fix turbo, fix refactor

* Add docs and allow CI to work

* Fix action params issue with objects (#458)

* fix

* added changeset

* Add more logging to legacy-client oauth (#479)

* Change default VSCode formatter back to dprint (#482)

* MRL enforces tilde not caret for internal deps (#464)

* MRL enforces tilde not caret for internal deps

* Cleanup

* Interface inherited properties are now generated (#441)

Fix mrl

* WIP Queries (#379)

* 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

* Beta generation initial work (#469)

* Speed up build, fix dts generation for all, primitive --beta

* Add empty changeset

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Eric Anderson <[email protected]>
Co-authored-by: ssanjay1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants