Skip to content

Commit

Permalink
Merge pull request #5 from ryan-timothy-albert/speakeasy-sdk-regen-17…
Browse files Browse the repository at this point in the history
…24898421

chore: 🐝 Update SDK - Generate 0.0.1
  • Loading branch information
ryan-timothy-albert authored Aug 29, 2024
2 parents 0e4e74a + 7bcfa40 commit 05ed6dc
Show file tree
Hide file tree
Showing 70 changed files with 8,116 additions and 7 deletions.
15 changes: 8 additions & 7 deletions package/.speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
speakeasyVersion: 1.378.0
speakeasyVersion: 1.382.0
sources:
petstore-oas:
sourceNamespace: petstore-oas
sourceRevisionDigest: sha256:b49d6adb32fea5d5acb70aa5f84d16b8a020a565bf1020dbb7d7759290e0300c
sourceBlobDigest: sha256:9480cf4cfe4bec2b7aebbca1acc70012d890dc26bf83a293e6f9e682952509fb
sourceRevisionDigest: sha256:77de452f4e600a9581257750f45f6ae4613f056f13c25b33814f5c5c6a9e65a5
sourceBlobDigest: sha256:ea345c5fff9396f9d26f06eb40051420eb8f4754000693080ce1ac6f4d44a179
tags:
- latest
- main
targets:
petstore:
source: petstore-oas
sourceNamespace: petstore-oas
sourceRevisionDigest: sha256:b49d6adb32fea5d5acb70aa5f84d16b8a020a565bf1020dbb7d7759290e0300c
sourceBlobDigest: sha256:9480cf4cfe4bec2b7aebbca1acc70012d890dc26bf83a293e6f9e682952509fb
outLocation: /github/workspace/repo/package
sourceRevisionDigest: sha256:77de452f4e600a9581257750f45f6ae4613f056f13c25b33814f5c5c6a9e65a5
sourceBlobDigest: sha256:ea345c5fff9396f9d26f06eb40051420eb8f4754000693080ce1ac6f4d44a179
outLocation: sdk
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
sources:
petstore-oas:
inputs:
- location: openapi.yaml
- location: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.yaml
registry:
location: registry.speakeasyapi.dev/ryan-local/ryan-telemetry/petstore-oas
targets:
petstore:
target: typescript
source: petstore-oas
output: sdk
publish:
npm:
token: $npm_token
28 changes: 28 additions & 0 deletions package/sdk/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-env node */
module.exports = {
root: true,
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
settings: {
"import/resolver": {
typescript: true,
node: true,
},
},
rules: {
// Handled by typescript compiler
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-explicit-any": "off",
"import/no-named-as-default-member": "off",

"import/no-default-export": "error",
},
};
2 changes: 2 additions & 0 deletions package/sdk/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This allows generated code to be indexed correctly
*.ts linguist-generated=false
16 changes: 16 additions & 0 deletions package/sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/models
/models/errors
/types
/node_modules
/lib
/sdk
/funcs
/hooks
/index.*
/core.*
/cjs
/esm
/dist
/.tsbuildinfo
/.tshy
/.tshy-*
9 changes: 9 additions & 0 deletions package/sdk/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**/*
!/**/*.ts
!/**/*.js
!/**/*.map

/.eslintrc.js
/cjs
/.tshy
/.tshy-*
87 changes: 87 additions & 0 deletions package/sdk/.speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
lockVersion: 2.0.0
id: e5719915-891a-4412-9667-6e3a010360fc
management:
docChecksum: 1bdb7a6f8bf3995d4b40475228403253
docVersion: 1.0.0
speakeasyVersion: 1.382.0
generationVersion: 2.404.11
releaseVersion: 0.0.1
configChecksum: a4e81b731eaa5742879d8054adb52f6d
repoURL: https://github.com/ryan-timothy-albert/test_nested_repo.git
repoSubDirectory: package/sdk
installationURL: https://gitpkg.now.sh/ryan-timothy-albert/test_nested_repo/package/sdk
published: true
features:
typescript:
additionalDependencies: 0.1.0
core: 3.14.1
defaultEnabledRetries: 0.1.0
envVarSecurityUsage: 0.1.1
globalSecurityCallbacks: 0.1.0
globalServerURLs: 2.82.4
responseFormat: 0.2.3
retries: 2.83.0
sdkHooks: 0.1.0
generatedFiles:
- src/funcs/petsListPets.ts
- src/funcs/petsCreatePets.ts
- src/funcs/petsShowPetById.ts
- src/sdk/pets.ts
- src/sdk/sdk.ts
- .eslintrc.cjs
- .npmignore
- FUNCTIONS.md
- RUNTIMES.md
- jsr.json
- package.json
- src/core.ts
- src/index.ts
- src/lib/base64.ts
- src/lib/config.ts
- src/lib/dlv.ts
- src/lib/encodings.ts
- src/lib/http.ts
- src/lib/is-plain-object.ts
- src/lib/logger.ts
- src/lib/matchers.ts
- src/lib/primitives.ts
- src/lib/retries.ts
- src/lib/schemas.ts
- src/lib/sdks.ts
- src/lib/security.ts
- src/lib/url.ts
- src/sdk/index.ts
- src/models/errors/httpclienterrors.ts
- src/models/errors/sdkerror.ts
- src/models/errors/sdkvalidationerror.ts
- src/types/blobs.ts
- src/types/constdatetime.ts
- src/types/enums.ts
- src/types/fp.ts
- src/types/index.ts
- src/types/operations.ts
- src/types/rfcdate.ts
- tsconfig.json
- src/models/operations/listpets.ts
- src/models/operations/showpetbyid.ts
- src/models/components/pet.ts
- src/models/components/error.ts
- src/models/errors/index.ts
- src/models/operations/index.ts
- src/models/components/index.ts
- docs/models/operations/listpetsrequest.md
- docs/models/operations/listpetsresponseresult.md
- docs/models/operations/listpetsresponse.md
- docs/models/operations/showpetbyidrequest.md
- docs/models/operations/showpetbyidresponse.md
- docs/models/components/pet.md
- docs/models/components/errort.md
- docs/sdks/sdk/README.md
- docs/lib/utils/retryconfig.md
- docs/sdks/pets/README.md
- USAGE.md
- .gitattributes
- src/hooks/hooks.ts
- src/hooks/types.ts
- src/hooks/index.ts
- CONTRIBUTING.md
41 changes: 41 additions & 0 deletions package/sdk/.speakeasy/gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
configVersion: 2.0.0
generation:
sdkClassName: SDK
maintainOpenAPIOrder: true
usageSnippets:
optionalPropertyRendering: withExample
useClassNamesForArrayFields: true
fixes:
nameResolutionDec2023: true
parameterOrderingFeb2024: true
requestResponseComponentNamesFeb2024: true
auth:
oAuth2ClientCredentialsEnabled: true
typescript:
version: 0.0.1
additionalDependencies:
dependencies: {}
devDependencies: {}
peerDependencies: {}
additionalPackageJSON: {}
author: Speakeasy
clientServerStatusCodesAsErrors: true
enumFormat: union
flattenGlobalSecurity: true
imports:
option: openapi
paths:
callbacks: models/callbacks
errors: models/errors
operations: models/operations
shared: models/components
webhooks: models/webhooks
inputModelSuffix: input
maxMethodParams: 0
methodArguments: require-security-and-request
moduleFormat: commonjs
outputModelSuffix: output
packageName: openapi
responseFormat: flat
templateVersion: v2
useIndexModules: true
26 changes: 26 additions & 0 deletions package/sdk/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
102 changes: 102 additions & 0 deletions package/sdk/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 { SDKCore } from "openapi/core.js";
import { petsListPets } from "openapi/funcs/petsListPets.js";
import { SDKValidationError } from "openapi/models/errors/sdkvalidationerror.js";

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

async function run() {
const res = await petsListPets(sdk, {});

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 05ed6dc

Please sign in to comment.