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

Refactor JS lib to use our new codegen #1700

Merged
merged 14 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/javascript-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ jobs:
node-version: 'latest'
registry-url: 'https://registry.npmjs.org'

- name: Regen openapi libs
run: |
yarn
./regen_openapi.sh

- name: Install modules
run: |
cd javascript
Expand All @@ -32,3 +27,8 @@ jobs:
run: |
cd javascript
yarn run lint

- name: Test
run: |
cd javascript
yarn run test
5 changes: 0 additions & 5 deletions .github/workflows/javascript-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ jobs:
node-version: 'latest'
registry-url: 'https://registry.npmjs.org'

- name: Regen openapi libs
run: |
yarn
./regen_openapi.sh

- name: Install modules
run: |
cd javascript
Expand Down
87 changes: 0 additions & 87 deletions javascript/.eslintrc.cjs

This file was deleted.

1 change: 0 additions & 1 deletion javascript/.lintignore

This file was deleted.

13 changes: 13 additions & 0 deletions javascript/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";

/** @type {import('eslint').Linter.Config[]} */
export default [
{
files: ["**/*.{js,mjs,cjs,ts}"],
languageOptions: { globals: { ...globals.browser, ...globals.node } },
},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
5 changes: 0 additions & 5 deletions javascript/openapi-generator-config.json

This file was deleted.

17 changes: 9 additions & 8 deletions javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"prepare": "yarn run build",
"test": "jest",
"prepublishOnly": "yarn lint",
"lint:eslint": "eslint --ignore-path .lintignore --ext .js,.jsx,.ts,.tsx src",
"lint:prettier": "prettier --ignore-path .lintignore src",
"lint:eslint": "eslint src",
"lint:prettier": "prettier src",
"lint": "yarn run lint:prettier --check && yarn run lint:eslint --max-warnings=0",
"lint:fix": "yarn run lint:prettier --write && yarn run lint:eslint --fix"
"lint:fix": "yarn run lint:eslint --fix && yarn run lint:prettier --write"
},
"dependencies": {
"@stablelib/base64": "^1.0.0",
Expand All @@ -37,16 +37,17 @@
"url-parse": "^1.5.10"
},
"devDependencies": {
"@eslint/js": "^9.20.0",
"@stablelib/utf8": "^2.0.0",
"@types/jest": "^29.5.13",
"@types/url-parse": "1.4.11",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"@typescript-eslint/typescript-estree": "^4.15.2",
"eslint": "^7.20.0",
"eslint": "^9.20.1",
"globals": "^15.15.0",
"jest": "^29.7.0",
"mockttp": "^3.15.5",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"typescript": "^4.0"
"typescript": "^4.0",
"typescript-eslint": "^8.24.0"
}
}
110 changes: 110 additions & 0 deletions javascript/src/HttpErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
export class HttpErrorOut {
"code": string;
"detail": string;

static readonly discriminator: string | undefined = undefined;

static readonly mapping: { [index: string]: string } | undefined = undefined;

static readonly attributeTypeMap: Array<{
name: string;
baseName: string;
type: string;
format: string;
}> = [
{
name: "code",
baseName: "code",
type: "string",
format: "",
},
{
name: "detail",
baseName: "detail",
type: "string",
format: "",
},
];

static getAttributeTypeMap() {
return HttpErrorOut.attributeTypeMap;
}
}

/**
* Validation errors have their own schema to provide context for invalid requests eg. mismatched types and out of bounds values. There may be any number of these per 422 UNPROCESSABLE ENTITY error.
*/
export class ValidationError {
/**
* The location as a [`Vec`] of [`String`]s -- often in the form `[\"body\", \"field_name\"]`, `[\"query\", \"field_name\"]`, etc. They may, however, be arbitrarily deep.
*/
"loc": Array<string>;
/**
* The message accompanying the validation error item.
*/
"msg": string;
/**
* The type of error, often \"type_error\" or \"value_error\", but sometimes with more context like as \"value_error.number.not_ge\"
*/
"type": string;

static readonly discriminator: string | undefined = undefined;

static readonly mapping: { [index: string]: string } | undefined = undefined;

static readonly attributeTypeMap: Array<{
name: string;
baseName: string;
type: string;
format: string;
}> = [
{
name: "loc",
baseName: "loc",
type: "Array<string>",
format: "",
},
{
name: "msg",
baseName: "msg",
type: "string",
format: "",
},
{
name: "type",
baseName: "type",
type: "string",
format: "",
},
];

static getAttributeTypeMap() {
return ValidationError.attributeTypeMap;
}
}

export class HTTPValidationError {
"detail": Array<ValidationError>;

static readonly discriminator: string | undefined = undefined;

static readonly mapping: { [index: string]: string } | undefined = undefined;

static readonly attributeTypeMap: Array<{
name: string;
baseName: string;
type: string;
format: string;
}> = [
{
name: "detail",
baseName: "detail",
type: "Array<ValidationError>",
format: "",
},
];

static getAttributeTypeMap() {
return HTTPValidationError.attributeTypeMap;
}
}
4 changes: 3 additions & 1 deletion javascript/src/KitchenSink.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ApiException, HttpErrorOut, Svix } from ".";
import { Svix } from ".";
import { HttpErrorOut } from "./HttpErrors";
import { ApiException } from "./util";

function getTestClient(): Svix | null {
const token = process.env.SVIX_TOKEN;
Expand Down
34 changes: 19 additions & 15 deletions javascript/src/api/application.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// this file is @generated
import { ApplicationIn, ApplicationInSerializer } from "../models/applicationIn";
import { ApplicationOut, ApplicationOutSerializer } from "../models/applicationOut";
import { ApplicationPatch, ApplicationPatchSerializer } from "../models/applicationPatch";
import {
ApplicationIn,
ApplicationOut,
ApplicationPatch,
ListResponseApplicationOut,
Ordering,
} from "../openapi";
ListResponseApplicationOutSerializer,
} from "../models/listResponseApplicationOut";
import { Ordering } from "../models/ordering";
import { HttpMethod, SvixRequest, SvixRequestContext } from "../request";

export interface ApplicationListOptions {
Expand All @@ -32,7 +33,10 @@ export class Application {
request.setQueryParam("iterator", options?.iterator);
request.setQueryParam("order", options?.order);

return request.send(this.requestCtx, "ListResponseApplicationOut");
return request.send(
this.requestCtx,
ListResponseApplicationOutSerializer._fromJsonObject
);
}

/** Create a new application. */
Expand All @@ -43,9 +47,9 @@ export class Application {
const request = new SvixRequest(HttpMethod.POST, "/api/v1/app");

request.setHeaderParam("idempotency-key", options?.idempotencyKey);
request.setBody(applicationIn, "ApplicationIn");
request.setBody(ApplicationInSerializer._toJsonObject(applicationIn));

return request.send(this.requestCtx, "ApplicationOut");
return request.send(this.requestCtx, ApplicationOutSerializer._fromJsonObject);
}

/** Get the application with the UID from `applicationIn`, or create it if it doesn't exist yet. */
Expand All @@ -57,9 +61,9 @@ export class Application {

request.setQueryParam("get_if_exists", true);
request.setHeaderParam("idempotency-key", options?.idempotencyKey);
request.setBody(applicationIn, "ApplicationIn");
request.setBody(ApplicationInSerializer._toJsonObject(applicationIn));

return request.send(this.requestCtx, "ApplicationOut");
return request.send(this.requestCtx, ApplicationOutSerializer._fromJsonObject);
}

/** Get an application. */
Expand All @@ -68,17 +72,17 @@ export class Application {

request.setPathParam("app_id", appId);

return request.send(this.requestCtx, "ApplicationOut");
return request.send(this.requestCtx, ApplicationOutSerializer._fromJsonObject);
}

/** Update an application. */
public update(appId: string, applicationIn: ApplicationIn): Promise<ApplicationOut> {
const request = new SvixRequest(HttpMethod.PUT, "/api/v1/app/{app_id}");

request.setPathParam("app_id", appId);
request.setBody(applicationIn, "ApplicationIn");
request.setBody(ApplicationInSerializer._toJsonObject(applicationIn));

return request.send(this.requestCtx, "ApplicationOut");
return request.send(this.requestCtx, ApplicationOutSerializer._fromJsonObject);
}

/** Delete an application. */
Expand All @@ -98,8 +102,8 @@ export class Application {
const request = new SvixRequest(HttpMethod.PATCH, "/api/v1/app/{app_id}");

request.setPathParam("app_id", appId);
request.setBody(applicationPatch, "ApplicationPatch");
request.setBody(ApplicationPatchSerializer._toJsonObject(applicationPatch));

return request.send(this.requestCtx, "ApplicationOut");
return request.send(this.requestCtx, ApplicationOutSerializer._fromJsonObject);
}
}
Loading