Skip to content

Commit

Permalink
Merge pull request #13 from novuhq/speakeasy-sdk-regen-1719793018
Browse files Browse the repository at this point in the history
chore: 🐝 Update SDK - Generate 0.0.1-alpha.10
  • Loading branch information
rifont authored Sep 3, 2024
2 parents e87cf93 + 54959ec commit 8cf7586
Show file tree
Hide file tree
Showing 656 changed files with 39,618 additions and 25,209 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/funcs
/core.*
/esm
/dist
/.tshy
/.tshy-*
/models
/models/errors
/types
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@

/.eslintrc.js
/cjs
/.tshy
/.tshy-*
228 changes: 139 additions & 89 deletions .speakeasy/gen.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
typescript:
version: 0.0.1-alpha.9
version: 0.0.1-alpha.10
additionalDependencies:
dependencies: {}
devDependencies: {}
Expand All @@ -32,6 +32,7 @@ typescript:
inputModelSuffix: input
maxMethodParams: 2
methodArguments: require-security-and-request
moduleFormat: commonjs
outputModelSuffix: output
packageName: '@novu/api'
responseFormat: flat
Expand Down
12 changes: 6 additions & 6 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
speakeasyVersion: 1.322.3
speakeasyVersion: 1.386.0
sources:
json-development:
sourceNamespace: json-development
sourceRevisionDigest: sha256:9aaa2cefb426a15cee5a49a925f699de098a471674151d8e4ff677c3c9ce0da3
sourceBlobDigest: sha256:be824c6647996617fb6fd7ea6b234c66f101d67d28a79402f53258bbd957c404
sourceRevisionDigest: sha256:6bd29dd911f0d002ed01f7e6c2f88aaa3fff6eea08e8b6b9f66a888a6dc340e4
sourceBlobDigest: sha256:02d801ab167023e73aeda8504c864217ba40f5f0f52f04ce3696f9034664a819
tags:
- latest
- main
targets:
my-first-target:
source: json-development
sourceNamespace: json-development
sourceRevisionDigest: sha256:9aaa2cefb426a15cee5a49a925f699de098a471674151d8e4ff677c3c9ce0da3
sourceBlobDigest: sha256:be824c6647996617fb6fd7ea6b234c66f101d67d28a79402f53258bbd957c404
sourceRevisionDigest: sha256:6bd29dd911f0d002ed01f7e6c2f88aaa3fff6eea08e8b6b9f66a888a6dc340e4
sourceBlobDigest: sha256:02d801ab167023e73aeda8504c864217ba40f5f0f52f04ce3696f9034664a819
codeSamplesNamespace: code-samples-typescript
codeSamplesRevisionDigest: sha256:33324b9421a6105c75147afd9d70c354c7a6ad0f5e48327905d8171c613522a8
codeSamplesRevisionDigest: sha256:d6206d9d099c5ec737dacbf0c1f20ff93bb60a9df7f4b86e2d8a68e7f205b671
outLocation: /github/workspace/repo
workflow:
workflowVersion: 1.0.0
Expand Down
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing to This Repository

Thank you for your interest in contributing to this repository. Please note that this repository contains generated code. As such, we do not accept direct changes or pull requests. Instead, we encourage you to follow the guidelines below to report issues and suggest improvements.

## How to Report Issues

If you encounter any bugs or have suggestions for improvements, please open an issue on GitHub. When reporting an issue, please provide as much detail as possible to help us reproduce the problem. This includes:

- A clear and descriptive title
- Steps to reproduce the issue
- Expected and actual behavior
- Any relevant logs, screenshots, or error messages
- Information about your environment (e.g., operating system, software versions)
- For example can be collected using the `npx envinfo` command from your terminal if you have Node.js installed

## Issue Triage and Upstream Fixes

We will review and triage issues as quickly as possible. Our goal is to address bugs and incorporate improvements in the upstream source code. Fixes will be included in the next generation of the generated code.

## Contact

If you have any questions or need further assistance, please feel free to reach out by opening an issue.

Thank you for your understanding and cooperation!

The Maintainers
104 changes: 104 additions & 0 deletions FUNCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Standalone Functions

> [!NOTE]
> This section is useful if you are using a bundler and targetting browsers and
> runtimes where the size of an application affects performance and load times.
Every method in this SDK is also available as a standalone function. This
alternative API is suitable when targetting the browser or serverless runtimes
and using a bundler to build your application since all unused functionality
will be tree-shaken away. This includes code for unused methods, Zod schemas,
encoding helpers and response handlers. The result is dramatically smaller
impact on the application's final bundle size which grows very slowly as you use
more and more functionality from this SDK.

Calling methods through the main SDK class remains a valid and generally more
more ergonomic option. Standalone functions represent an optimisation for a
specific category of applications.

## Example

```typescript
import { NovuCore } from "@novu/api/core.js";
import { cancel } from "@novu/api/funcs/cancel.js";
import { SDKValidationError } from "@novu/api/models/errors/sdkvalidationerror.js";

// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
apiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
const res = await cancel(novu, "<value>");

switch (true) {
case res.ok:
// The success case will be handled outside of the switch block
break;
case res.error instanceof SDKValidationError:
// Pretty-print validation errors.
return console.log(res.error.pretty());
case res.error instanceof Error:
return console.log(res.error);
default:
// TypeScript's type checking will fail on the following line if the above
// cases were not exhaustive.
res.error satisfies never;
throw new Error("Assertion failed: expected error checks to be exhaustive: " + res.error);
}


const { value: result } = res;

// Handle the result
console.log(result)
}

run();
```

## Result types

Standalone functions differ from SDK methods in that they return a
`Result<Value, Error>` type to capture _known errors_ and document them using
the type system. By avoiding throwing errors, application code maintains clear
control flow and error-handling become part of the regular flow of application
code.

> We use the term "known errors" because standalone functions, and JavaScript
> code in general, can still throw unexpected errors such as `TypeError`s,
> `RangeError`s and `DOMException`s. Exhaustively catching all errors may be
> something this SDK addresses in the future. Nevertheless, there is still a lot
> of benefit from capturing most errors and turning them into values.
The second reason for this style of programming is because these functions will
typically be used in front-end applications where exception throwing is
sometimes discouraged or considered unidiomatic. React and similar ecosystems
and libraries tend to promote this style of programming so that components
render useful content under all states (loading, success, error and so on).

The general pattern when calling standalone functions looks like this:

```typescript
import { Core } from "<sdk-package-name>";
import { fetchSomething } from "<sdk-package-name>/funcs/fetchSomething.js";

const client = new Core();

async function run() {
const result = await fetchSomething(client, { id: "123" });
if (!result.ok) {
// You can throw the error or handle it. It's your choice now.
throw result.error;
}

console.log(result.value);
}

run();
```

Notably, `result.error` above will have an explicit type compared to a try-catch
variation where the error in the catch block can only be of type `unknown` (or
`any` depending on your TypeScript settings).
Loading

0 comments on commit 8cf7586

Please sign in to comment.