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

Simplifying DBOS TypeScript Syntax #656

Merged
merged 128 commits into from
Dec 4, 2024
Merged

Simplifying DBOS TypeScript Syntax #656

merged 128 commits into from
Dec 4, 2024

Conversation

chuck-dbos
Copy link
Collaborator

@chuck-dbos chuck-dbos commented Nov 4, 2024

Main Change - New API
In addition to supporting all prior API constructs, DBOS Transact Typescript has a new API that does not require passing contexts around between functions. (This was inspired by the relative simplicity of the Python API.) Instead, functionality is accessed by DBOS.<thing>, such as @DBOS.workflow or DBOS.knexClient or DBOS.authenticatedUser. You can mix old and new code.

Second Big Change - Library Usage
DBOS can now be used as a library, or within Express.js or other frameworks, rather than just as serverless Koa-based entrypoints. Examples and guidance are evolving.

Other Items
Recovery has been moved to after init.

Co-authored-by: Harry Pierson <harrypierson@hotmail.com>
Signed-off-by: chuck-dbos <134347445+chuck-dbos@users.noreply.github.com>
@chuck-dbos
Copy link
Collaborator Author

Do we still need entrypoints? Or do we need a startup command like in Python? Or both?

Both are useful

100%. The entrypoints way has huge advantages for people building new apps that want the features we started with... and there are some. There's a lot less code for something that does just scheduled workflows, say. But we will need the startup command for some of the new usecases.

@chuck-dbos chuck-dbos marked this pull request as ready for review November 27, 2024 17:37
Copy link
Member

@kraftp kraftp left a comment

Choose a reason for hiding this comment

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

I think this is ready to merge--the core functionality is fully working. @qianl15 should also review. Next step is templates + docs, then we can officially release it.

async function main() {
await DBOS.launch({expressApp: app});

const PORT = DBOS.runtimeConfig?.port ?? 9000;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: The default port for Express.js is 3000. Why do we use 9000 here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What port does the DBOS Cloud forward?

Copy link
Member

Choose a reason for hiding this comment

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

DBOS Cloud forwards to 3000 for node.js apps and 8000 for Python apps.

// DBOS uses TypeScript decorators to automatically make your functions reliable, so they need to be static.
export class Hello {
// Serve this function from HTTP GET requests at the /greeting endpoint with 'user' as a path parameter
@DBOS.getApi("/greeting/:user")
Copy link
Member

Choose a reason for hiding this comment

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

If we want to eventually get rid of getApi and other HTTP verbs, we should use Koa directly here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Disagree strongly.

Copy link
Member

Choose a reason for hiding this comment

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

We can discuss this some other time -- maintaining a thin wrapper around Koa is pretty annoying. Remember the times we wanted to support CORS and preflight requests :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree with one part of the Koa point (features have to be added in the framework), strong disagree on the CORS part, baking that into your code is bad and should be managed by the deployment, which we can do better if we help you in a "serverless" way.

src/context.ts Outdated
idAssignedForNextWorkflow?: string;
queueAssignedForWorkflows?: string;
parentWorkflowId?: string;
parentWorkflowFid?: number;
Copy link
Member

@qianl15 qianl15 Dec 3, 2024

Choose a reason for hiding this comment

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

What is this? This field is not used anywhere. Same as parentWorkflowId

If we can already access parentCtx, then these fields are not necessary.

src/context.ts Show resolved Hide resolved
Copy link
Member

@qianl15 qianl15 left a comment

Choose a reason for hiding this comment

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

A general question: does it still use Stage 2 decorators?

@chuck-dbos
Copy link
Collaborator Author

A general question: does it still use Stage 2 decorators?

Yeah, this is permits an incremental upgrade without having file-specific TS compiler settings.

Have they made a better decorator scheme for TS? A year ago, the successor was neither better nor final.

src/dbos.ts Show resolved Hide resolved
Copy link
Member

@qianl15 qianl15 left a comment

Choose a reason for hiding this comment

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

Nice work on TS v2!

@chuck-dbos chuck-dbos merged commit 6cceb36 into main Dec 4, 2024
2 checks passed
@chuck-dbos chuck-dbos deleted the chuck/als branch December 4, 2024 02:35
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.

5 participants