Skip to content

Commit

Permalink
added: popsicle into speakeasy
Browse files Browse the repository at this point in the history
  • Loading branch information
SayanKar committed Aug 13, 2024
1 parent 6cb93a1 commit da16a4a
Show file tree
Hide file tree
Showing 421 changed files with 18,831 additions and 540 deletions.
284 changes: 258 additions & 26 deletions .speakeasy/gen.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
typescript:
version: 0.0.2
version: 0.5.0
additionalDependencies:
dependencies: {}
devDependencies: {}
Expand Down
16 changes: 8 additions & 8 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
speakeasyVersion: 1.358.0
speakeasyVersion: 1.361.1
sources:
AvalancheSDK-OAS:
sourceNamespace: avalanche-sdk-oas
sourceRevisionDigest: sha256:5546bf02ad6a2b5208766448ab6a445d063466da22118bd4685a156cb5ce84ca
sourceBlobDigest: sha256:4c93f7608f5511312e2fcbcdd658ed51c9292d47d7b1548c218818b576daee05
sourceRevisionDigest: sha256:df5ede97c87fa9ae15088257f01d3ea7f03a491aa924f3c0476150ad78da77bc
sourceBlobDigest: sha256:19288be87bfa93e83d436d3165f4d3599a0053d7b114aba0b38a35775c43df5f
tags:
- latest
- main
targets:
avalanche-sdk:
source: AvalancheSDK-OAS
sourceNamespace: avalanche-sdk-oas
sourceRevisionDigest: sha256:5546bf02ad6a2b5208766448ab6a445d063466da22118bd4685a156cb5ce84ca
sourceBlobDigest: sha256:4c93f7608f5511312e2fcbcdd658ed51c9292d47d7b1548c218818b576daee05
outLocation: /github/workspace/repo
sourceRevisionDigest: sha256:df5ede97c87fa9ae15088257f01d3ea7f03a491aa924f3c0476150ad78da77bc
sourceBlobDigest: sha256:19288be87bfa93e83d436d3165f4d3599a0053d7b114aba0b38a35775c43df5f
outLocation: /Users/sayan.kar/avalabs/avalanche-sdk-typescript
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
sources:
AvalancheSDK-OAS:
inputs:
- location: https://ad39-2405-201-3027-2887-d9b-fc28-c7ec-5133.ngrok-free.app/api-json
- location: https://1573-2405-201-3027-2887-ada2-ca7a-fa63-8ab5.ngrok-free.app/api-json
- location: https://515a-2405-201-3027-2887-ada2-ca7a-fa63-8ab5.ngrok-free.app/api-json
registry:
location: registry.speakeasyapi.dev/avalabs/avalabs/avalanche-sdk-oas
targets:
Expand Down
3 changes: 2 additions & 1 deletion .speakeasy/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ speakeasyVersion: latest
sources:
AvalancheSDK-OAS:
inputs:
- location: https://ad39-2405-201-3027-2887-d9b-fc28-c7ec-5133.ngrok-free.app/api-json
- location: https://1573-2405-201-3027-2887-ada2-ca7a-fa63-8ab5.ngrok-free.app/api-json
- location: https://515a-2405-201-3027-2887-ada2-ca7a-fa63-8ab5.ngrok-free.app/api-json
registry:
location: registry.speakeasyapi.dev/avalabs/avalabs/avalanche-sdk-oas
targets:
Expand Down
102 changes: 102 additions & 0 deletions FUNCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# 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 { AvalancheSDKCore } from "@avalabs/avalanche-sdk/core.js";
import { metricsHealthCheckHealthCheckV1 } from "@avalabs/avalanche-sdk/funcs/metricsHealthCheckHealthCheckV1.js";
import { SDKValidationError } from "@avalabs/avalanche-sdk/models/errors/sdkvalidationerror.js";

// Use `AvalancheSDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const avalancheSDK = new AvalancheSDKCore();

async function run() {
const res = await metricsHealthCheckHealthCheckV1(avalancheSDK);

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 da16a4a

Please sign in to comment.