Skip to content

Commit

Permalink
feat: begin api client setup
Browse files Browse the repository at this point in the history
  • Loading branch information
alii committed May 17, 2022
1 parent 0e51083 commit 4c2d081
Show file tree
Hide file tree
Showing 12 changed files with 2,707 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.yarn/*
!.yarn/releases
!.yarn/sdks
!.yarn/plugins
.DS_Store
dist
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"singleQuote": true,
"semi": true,
"printWidth": 80,
"trailingComma": "all",
"arrowParens": "avoid",
"bracketSpacing": false,
"useTabs": true,
"quoteProps": "consistent"
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}
786 changes: 786 additions & 0 deletions .yarn/releases/yarn-3.2.1.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.2.1.cjs
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@onehop/js",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "https://github.com/hopinc/hop-js.git",
"author": "Alistair Smith <[email protected]>",
"license": "MIT",
"packageManager": "[email protected]",
"devDependencies": {
"prettier": "^2.6.2",
"tsup": "^5.12.8",
"typescript": "^4.6.4"
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {};
//
45 changes: 45 additions & 0 deletions src/rest/endpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {Method, Responses} from './types';

export type Endpoint<
M extends Method,
Path extends string,
Res,
Body = never,
> = {
method: M;
path: Path;
res: Res;
body: Body;
};

export type Endpoints =
| Endpoint<'GET', '/v1/pipe/rooms', Responses.PIPE.GET_ROOMS>
| Endpoint<
'POST',
'/v1/pipe/rooms',
Responses.PIPE.CREATE_ROOM,
{
/**
* The name of the room
*/
name: string;

/**
* Any information attatched to the room
*/
metadata: unknown;
}
>;

export type SuccessfulAPIResposne<T> = {
success: true;
data: T;
};

export type ErroredAPIResponse = {
success: false;
error: {
code: string;
message: string;
};
};
19 changes: 19 additions & 0 deletions src/rest/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';

export namespace Responses {
export namespace PIPE {
export interface Room {
id: string;
name: string;
created_at: number;
}

export interface GET_ROOMS {
rooms: Room[];
}

export interface CREATE_ROOM {
room: Room;
}
}
}
7 changes: 7 additions & 0 deletions src/util/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type ExtractRouteParams<T extends string> = string extends T
? string
: T extends `${string}:${infer Param}/${infer Rest}`
? Param | keyof ExtractRouteParams<Rest>
: T extends `${string}:${infer Param}`
? Param
: never;
6 changes: 6 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {defineConfig} from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
dts: true,
});
Loading

0 comments on commit 4c2d081

Please sign in to comment.