Skip to content

Conversation

@BrayanDSO
Copy link
Member

@BrayanDSO BrayanDSO commented Aug 28, 2025

Purpose / Description

https://github.com/BrayanDSO/AnkiDroid-JS-API in a PR. Not sure if it's better placed in this repo or on a separate one.

This is basically the typescript source for generating ankidroid-js-api.js, js-api-endpoints.json and all the docs, used in #19152

package-lock.json is 3100 lines of the PR, so don't get too afraid

Pending tasks (for other PRs) are:

  • Auto publish typedoc pages
  • Publish workflow
  • Lint/format before commiting/building

@BrayanDSO BrayanDSO force-pushed the api branch 2 times, most recently from ab15560 to 5de449e Compare August 31, 2025 21:58
@BrayanDSO BrayanDSO force-pushed the api branch 2 times, most recently from bf8a82e to b3d453b Compare September 20, 2025 20:26
Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Wow! Looks solid

const match = returnType.match(API_METHOD_RETURN_TYPE_REGEX);

if (!match) {
continue;
Copy link
Member

Choose a reason for hiding this comment

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

We should probably log here

const callExpressions = method.getDescendantsOfKind(SyntaxKind.CallExpression);
for (const callExpr of callExpressions) {
const expression = callExpr.getExpression();
if (Node.isPropertyAccessExpression(expression)) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I prefer to invert & continue; to reduce nesting

* Whether the card is New (0), Learning (1), Review (2), Relearning (3)
* @returns The card `type` property
*/
public getType(): Promise<Result<number>> {
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 return this as a union/branded type

/**
* @returns The card ID.
*/
public getId(): Promise<Result<number>> {
Copy link
Member

Choose a reason for hiding this comment

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

For a number of these: do we want branded types?

Or at least aliasing CardId to number

* Gets the card remaining steps
* @returns The card `left` property
*/
public getLeft(): Promise<Result<number>> {
Copy link
Member

Choose a reason for hiding this comment

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

Is this true? It's been a long while, but I believe it's more complex, depending on whether the card has inter or intra-day steps

throw new Error(`Request failed with status ${response.status}`);
}

const responseData = await response.text();
Copy link
Member

Choose a reason for hiding this comment

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

unusual to not use response.json() is there a reason? (old WebViews?)

/**
* @param error Error message.
*/
export type Failure = { success: false; error: string };
Copy link
Member

Choose a reason for hiding this comment

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

Explain if this is translated or not

Do we want a (string) error code which users can Google?

interval: number;
ease: number;
takenSecs: number;
memoryState?: FsrsMemoryState;
Copy link
Member

Choose a reason for hiding this comment

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

Be aware that this will likely be extended, and how we handle this

@@ -0,0 +1,13 @@
Copyright (year) (author)
Copy link
Member

Choose a reason for hiding this comment

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

Intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you mean (year) and (author), they are part of the eslint-plugin-headers template syntax.

@@ -0,0 +1,28 @@
{
"name": "ankidroid-js-api",
"private": false,
Copy link
Member

Choose a reason for hiding this comment

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

How is this going to be published/updated/pushed to consumers?

@david-allison
Copy link
Member

We probably want a longer discussion over architecture

I'd prefer this as a separate repo:

  • Different tech stack
  • Different focus (issues/reporters will have significantly more in-depth/tech knowledge)

  • I would prefer if examples were in a usable apkg/csv
  • api.studyScreen.answer(3) - can we have constants?
  • getNid or getNId (or even noteId)
  • getReviewLogs - Is this confirmed to be what revlog stands for?

@BrayanDSO BrayanDSO added the Needs Author Reply Waiting for a reply from the original author label Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants