Skip to content

Commit

Permalink
feat(api): update via SDK Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Apr 30, 2024
1 parent b32333e commit 85b3685
Show file tree
Hide file tree
Showing 20 changed files with 174 additions and 136 deletions.
1 change: 1 addition & 0 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
configured_endpoints: 35
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-c82b75f0715aa0661db0a946fb7927b3d9ac528be46532fe0f2dd3152572ea55.yml
9 changes: 2 additions & 7 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ Types:
Methods:

- <code title="post /apps">client.apps.<a href="./src/resources/apps/apps.ts">create</a>({ ...params }) -> App</code>
- <code title="get /apps/{app_id}">client.apps.<a href="./src/resources/apps/apps.ts">retrieve</a>(appId) -> App</code>
- <code title="put /apps/{app_id}">client.apps.<a href="./src/resources/apps/apps.ts">update</a>(appId, { ...params }) -> App</code>
- <code title="get /apps/{app_id}">client.apps.<a href="./src/resources/apps/apps.ts">get</a>(appId) -> App</code>
- <code title="get /apps/name/{name}">client.apps.<a href="./src/resources/apps/apps.ts">getByName</a>(name) -> App</code>
- <code title="get /apps/get_or_create/{name}">client.apps.<a href="./src/resources/apps/apps.ts">getOrCreate</a>(name) -> App</code>

## Name

Methods:

- <code title="get /apps/name/{name}">client.apps.name.<a href="./src/resources/apps/name.ts">retrieve</a>(name) -> App</code>

## Users

Types:
Expand Down
50 changes: 0 additions & 50 deletions bin/check-test-server

This file was deleted.

1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const config: JestConfigWithTsJest = {
'<rootDir>/deno/',
'<rootDir>/deno_tests/',
],
testPathIgnorePatterns: ['scripts'],
};

export default config;
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "honcho",
"version": "0.0.1-alpha.0",
"description": "The official TypeScript library for the Honcho API",
"author": "Honcho <dev-feedback@honcho.com>",
"author": "Honcho <hello@plasticlabs.ai>",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"type": "commonjs",
Expand All @@ -14,14 +14,14 @@
],
"private": false,
"scripts": {
"test": "bin/check-test-server && yarn jest",
"build": "bash ./build",
"test": "./scripts/test",
"build": "./scripts/build",
"prepack": "echo 'to pack, run yarn build && (cd dist; yarn pack)' && exit 1",
"prepublishOnly": "echo 'to publish, run yarn build && (cd dist; yarn publish)' && exit 1",
"format": "prettier --write --cache --cache-strategy metadata . !dist",
"prepare": "if ./scripts/check-is-in-git-install.sh; then npm run build; fi",
"prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build; fi",
"tsn": "ts-node -r tsconfig-paths/register",
"lint": "eslint --ext ts,js .",
"lint": "./scripts/lint",
"fix": "eslint --fix --ext ts,js ."
},
"dependencies": {
Expand Down
9 changes: 9 additions & 0 deletions scripts/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

PACKAGE_MANAGER=$(command -v yarn >/dev/null 2>&1 && echo "yarn" || echo "npm")

$PACKAGE_MANAGER install
15 changes: 9 additions & 6 deletions build → scripts/build
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env bash

set -exuo pipefail

node scripts/check-version.cjs
cd "$(dirname "$0")/.."

node scripts/utils/check-version.cjs

# Build into dist and will publish the package from there,
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
Expand All @@ -22,7 +25,7 @@ if [ -e "bin/cli" ]; then
fi
# this converts the export map paths for the dist directory
# and does a few other minor things
node scripts/make-dist-package-json.cjs > dist/package.json
node scripts/utils/make-dist-package-json.cjs > dist/package.json

# build to .js/.mjs/.d.ts files
npm exec tsc-multi
Expand All @@ -32,22 +35,22 @@ cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto
# we need to add exports = module.exports = Honcho Node to index.js;
# No way to get that from index.ts because it would cause compile errors
# when building .mjs
node scripts/fix-index-exports.cjs
node scripts/utils/fix-index-exports.cjs
# with "moduleResolution": "nodenext", if ESM resolves to index.d.ts,
# it'll have TS errors on the default import. But if it resolves to
# index.d.mts the default import will work (even though both files have
# the same export default statement)
cp dist/index.d.ts dist/index.d.mts
cp tsconfig.dist-src.json dist/src/tsconfig.json

node scripts/postprocess-files.cjs
node scripts/utils/postprocess-files.cjs

# make sure that nothing crashes when we require the output CJS or
# import the output ESM
(cd dist && node -e 'require("honcho")')
(cd dist && node -e 'import("honcho")' --input-type=module)

if command -v deno &> /dev/null && [ -e ./build-deno ]
if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
then
./build-deno
./scripts/build-deno
fi
7 changes: 7 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

./node_modules/.bin/eslint --ext ts,js .
38 changes: 38 additions & 0 deletions scripts/mock
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

if [ -n "$1" ]; then
URL="$1"
shift
else
URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)"
fi

# Check if the URL is empty
if [ -z "$URL" ]; then
echo "Error: No OpenAPI spec path/url provided or found in .stats.yml"
exit 1
fi

# Run prism mock on the given spec
if [ "$1" == "--daemon" ]; then
npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock "$URL" &> .prism.log &

# Wait for server to come online
while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do
echo -n "."
sleep 0.1
done

if grep -q "✖ fatal" ".prism.log"; then
cat .prism.log
exit 1
fi

echo
else
npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock "$URL"
fi
53 changes: 53 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

function prism_is_running() {
curl --silent "http://localhost:4010" >/dev/null 2>&1
}

kill_server_on_port() {
pids=$(lsof -t -i tcp:"$1" || echo "")
if [ "$pids" != "" ]; then
kill "$pids"
echo "Stopped $pids."
fi
}

function is_overriding_api_base_url() {
[ -n "$TEST_API_BASE_URL" ]
}

if ! is_overriding_api_base_url && ! prism_is_running ; then
# When we exit this script, make sure to kill the background mock server process
trap 'kill_server_on_port 4010' EXIT

# Start the dev server
./scripts/mock --daemon &> /dev/null
fi

if ! prism_is_running ; then
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server"
echo -e "running against your OpenAPI spec."
echo
echo -e "To run the server, pass in the path or url of your OpenAPI"
echo -e "spec to the prism command:"
echo
echo -e " \$ ${YELLOW}npm exec prism mock path/to/your.openapi.yml${NC}"
echo

exit 1
else
echo -e "${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}"
echo
fi

# Run tests
./node_modules/.bin/jest
File renamed without changes.
4 changes: 2 additions & 2 deletions scripts/check-version.cjs → scripts/utils/check-version.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const fs = require('fs');
const path = require('path');

const main = () => {
const pkg = require('../package.json');
const pkg = require('../../package.json');
const version = pkg['version'];
if (!version) throw 'The version property is not set in the package.json file';
if (typeof version !== 'string') {
throw `Unexpected type for the package.json version field; got ${typeof version}, expected string`;
}

const versionFile = path.resolve(__dirname, '..', 'src', 'version.ts');
const versionFile = path.resolve(__dirname, '..', '..', 'src', 'version.ts');
const contents = fs.readFileSync(versionFile, 'utf8');
const output = contents.replace(/(export const VERSION = ')(.*)(')/g, `$1${version}$3`);
fs.writeFileSync(versionFile, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const indexJs =
process.env['DIST_PATH'] ?
path.resolve(process.env['DIST_PATH'], 'index.js')
: path.resolve(__dirname, '..', 'dist', 'index.js');
: path.resolve(__dirname, '..', '..', 'dist', 'index.js');

let before = fs.readFileSync(indexJs, 'utf8');
let after = before.replace(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const pkgJson = require(process.env['PKG_JSON_PATH'] || '../package.json');
const pkgJson = require(process.env['PKG_JSON_PATH'] || '../../package.json');

function processExportMap(m) {
for (const key in m) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const fs = require('fs');
const path = require('path');
const { parse } = require('@typescript-eslint/parser');

const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'honcho/'
const pkgImportPath = process.env['PKG_IMPORT_PATH'] ?? 'honcho/';

const distDir =
process.env['DIST_PATH'] ?
path.resolve(process.env['DIST_PATH'])
: path.resolve(__dirname, '..', 'dist');
: path.resolve(__dirname, '..', '..', 'dist');
const distSrcDir = path.join(distDir, 'src');

/**
Expand Down Expand Up @@ -103,7 +103,7 @@ async function* walk(dir) {
}

async function postprocess() {
for await (const file of walk(path.resolve(__dirname, '..', 'dist'))) {
for await (const file of walk(path.resolve(__dirname, '..', '..', 'dist'))) {
if (!/\.([cm]?js|(\.d)?[cm]?ts)$/.test(file)) continue;

const code = await fs.promises.readFile(file, 'utf8');
Expand Down
28 changes: 18 additions & 10 deletions src/resources/apps/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import * as Core from 'honcho/core';
import { APIResource } from 'honcho/resource';
import * as AppsAPI from 'honcho/resources/apps/apps';
import * as NameAPI from 'honcho/resources/apps/name';
import * as UsersAPI from 'honcho/resources/apps/users/users';

export class Apps extends APIResource {
name: NameAPI.Name = new NameAPI.Name(this._client);
users: UsersAPI.Users = new UsersAPI.Users(this._client);

/**
Expand All @@ -21,27 +19,38 @@ export class Apps extends APIResource {
return this._client.post('/apps', { body, ...options });
}

/**
* Update an App
*
* Args: app_id (uuid.UUID): The ID of the app to update app (schemas.AppUpdate):
* The App object containing any new metadata
*
* Returns: schemas.App: The App object of the updated App
*/
update(appId: string, body: AppUpdateParams, options?: Core.RequestOptions): Core.APIPromise<App> {
return this._client.put(`/apps/${appId}`, { body, ...options });
}

/**
* Get an App by ID
*
* Args: app_id (uuid.UUID): The ID of the app
*
* Returns: schemas.App: App object
*/
retrieve(appId: string, options?: Core.RequestOptions): Core.APIPromise<App> {
get(appId: string, options?: Core.RequestOptions): Core.APIPromise<App> {
return this._client.get(`/apps/${appId}`, options);
}

/**
* Update an App
* Get an App by Name
*
* Args: app_id (uuid.UUID): The ID of the app to update app (schemas.AppUpdate):
* The App object containing any new metadata
* Args: app_name (str): The name of the app
*
* Returns: schemas.App: The App object of the updated App
* Returns: schemas.App: App object
*/
update(appId: string, body: AppUpdateParams, options?: Core.RequestOptions): Core.APIPromise<App> {
return this._client.put(`/apps/${appId}`, { body, ...options });
getByName(name: string, options?: Core.RequestOptions): Core.APIPromise<App> {
return this._client.get(`/apps/name/${name}`, options);
}

/**
Expand Down Expand Up @@ -82,7 +91,6 @@ export namespace Apps {
export import App = AppsAPI.App;
export import AppCreateParams = AppsAPI.AppCreateParams;
export import AppUpdateParams = AppsAPI.AppUpdateParams;
export import Name = NameAPI.Name;
export import Users = UsersAPI.Users;
export import PageUser = UsersAPI.PageUser;
export import User = UsersAPI.User;
Expand Down
1 change: 0 additions & 1 deletion src/resources/apps/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export { App, AppCreateParams, AppUpdateParams, Apps } from './apps';
export { Name } from './name';
export { PageUser, User, UserCreateParams, UserUpdateParams, UserListParams, Users } from './users/index';
Loading

0 comments on commit 85b3685

Please sign in to comment.