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

feat: adding functions and sessions apis #1159

Closed
wants to merge 26 commits into from

Conversation

bdimitrijoski
Copy link
Contributor

@bdimitrijoski bdimitrijoski commented Sep 24, 2024

This PR adds sessions API and partial support for functions API in the SDK.
I covered the APIs with unit tests and added code samples.

There were some problems (mostly, generated some types with any and later it failed on lint) with codegen when I tried to generate the types for functions so at the end I skipped codgen for this API.

bkuzma and others added 16 commits August 22, 2024 11:00
* fix: add sort properties to filter queries

* fix: fix typo
* test(alerts): skip flaky test temporarily

* chore(package): update yarn
* fix: release to override a bad release

* chore: skip validateDocLinks due to a bad release
* chore: re-enable temporary disabled ci check

* chore: update yarn.lock
* fix: create 50 alerts for cursor pagination test

* linting

* use nextCursor

* remove comment

* linting

* use int for limit

* add client and cogniterrors in test file

* linting

* remove unnecessary expectation
* fix: remove deprecated labels properties

* feat: add active property to integrations

* fix: remove deprecated lastUpdatedTime property

* fix: add missing versionNumber property

* fix: make filter optional
@bdimitrijoski bdimitrijoski self-assigned this Sep 25, 2024
@bdimitrijoski bdimitrijoski marked this pull request as ready for review September 30, 2024 07:20
@bdimitrijoski bdimitrijoski requested review from a team and BugGambit as code owners September 30, 2024 07:20
Comment on lines +14 to +19
AnnotationsCogmonoAnnotationTypesDiagramsAssetLink,
AnnotationsCogmonoAnnotationTypesDiagramsInstanceLink,
AnnotationsCogmonoAnnotationTypesImagesAssetLink,
AnnotationsCogmonoAnnotationTypesImagesInstanceLink,
AnnotationsCogmonoAnnotationTypesPrimitivesGeometry2DGeometry,
AnnotationsCogmonoAnnotationTypesPrimitivesGeometry3DGeometry,
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like a breaking change? any way possible to keep the old names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what annoys me the most, I don't have control over codegen and this is a change coming from the tool. How can I avoid this breaking change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

My advice is not to use it since you spend more time working around it than it requires writing a few type definitions.

but maybe @andersfylling or @BugGambit have a better idea

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a discussion about this specific breaking change here: #1120 (comment)
I suggest:

  1. Revert the breaking change.
  2. Change the base branch to release-v10 where we, in a few days, will release a new SDK major version where breaking changes are allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@polomani how can I keep the old names?

Copy link
Contributor

@BugGambit BugGambit left a comment

Choose a reason for hiding this comment

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

Nice PR. I left some comments.
In retro, I believe the PR should have been two PRs. One for Functions and one for Sessions.

Comment on lines +13 to +15
/**
* @hidden
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Why hidden?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Snippets or samples, one of those tools was failing

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, we should look into that. @hidden will hide this endpoint from the documentation.
I can look into it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just tested and this works:

  /**
   * [List function calls](https://api-docs.cognite.com/20230101/tag/Function-calls/operation/postFunctionsCall)
   *
   * ```js
   * client.functions.call(123, { nonce: 'abc' } )
   * ```
   */

🤷

code: 400,
message: 'Could not build function.',
},
} as CogniteFunction;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why as CogniteFunction vs const mockFunction: CogniteFunction = {}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't doing the same?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, not completely. Both will result in mockFunction being recognized as the type CogniteFunction, but as CogniteFunction will ignore type errors.

type Foo = {
    bar: number;
}

const a: Foo = {} // this will fail as `bar` is missing
const b = {} as Foo; // this will NOT fail

/**
* @hidden
*/
public get calls() {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this used for and why is it hidden?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is pointing to the function calls methods (API) example:
functionsApi.calls.list()

It is hidden because the snippets or samples tools were failing

/**
* @hidden
*/
async limits(): Promise<HttpResponse<FunctionsLimitsResponse>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it hidden?

export interface FunctionCallRequest {
// biome-ignore lint/suspicious/noExplicitAny: couldn't find correct type definition.
data?: any;
// biome-ignore lint/suspicious/noExplicitAny: couldn't find correct type definition.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these comments auto-generated 🤔 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

E.g. nonce here should be a string

Copy link
Contributor Author

@bdimitrijoski bdimitrijoski Oct 25, 2024

Choose a reason for hiding this comment

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

Heh, no, since I turned off the auto-generated types for this API I can update the types, thanks :)

@bdimitrijoski bdimitrijoski requested review from andersfylling and a team as code owners October 17, 2024 14:44
@bdimitrijoski bdimitrijoski requested review from a team October 17, 2024 14:44
@bdimitrijoski bdimitrijoski requested a review from a team as a code owner October 17, 2024 14:44
@bdimitrijoski bdimitrijoski changed the base branch from master to release-v10 October 25, 2024 00:52
@bdimitrijoski
Copy link
Contributor Author

Closing this PR as priorities changed and I unfortunately I have to work on something else and don't have time to finish this PR

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.

7 participants