@tourmalinecore/koala-api-js-client 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +108 -0
- package/dist/index.js +147 -0
- package/package.json +25 -3
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export interface CreateToDoRequest {
|
|
2
|
+
/** @maxLength 256 */
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
export interface CreateToDoResponse {
|
|
6
|
+
/**
|
|
7
|
+
* @format int64
|
|
8
|
+
* @pattern ^-?(?:0|[1-9]\d*)$
|
|
9
|
+
*/
|
|
10
|
+
newToDoId: number | string;
|
|
11
|
+
}
|
|
12
|
+
export interface DeleteToDoResponse {
|
|
13
|
+
isDeleted: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface GetToDosResponse {
|
|
16
|
+
toDos: ToDoDto[];
|
|
17
|
+
}
|
|
18
|
+
export interface ToDoDto {
|
|
19
|
+
/**
|
|
20
|
+
* @format int64
|
|
21
|
+
* @pattern ^-?(?:0|[1-9]\d*)$
|
|
22
|
+
*/
|
|
23
|
+
id: number | string;
|
|
24
|
+
name: string;
|
|
25
|
+
status: ToDoStatus;
|
|
26
|
+
}
|
|
27
|
+
export type ToDoStatus = number;
|
|
28
|
+
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from "axios";
|
|
29
|
+
export type QueryParamsType = Record<string | number, any>;
|
|
30
|
+
export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "params" | "url" | "responseType"> {
|
|
31
|
+
/** set parameter to `true` for call `securityWorker` for this request */
|
|
32
|
+
secure?: boolean;
|
|
33
|
+
/** request path */
|
|
34
|
+
path: string;
|
|
35
|
+
/** content type of request body */
|
|
36
|
+
type?: ContentType;
|
|
37
|
+
/** query params */
|
|
38
|
+
query?: QueryParamsType;
|
|
39
|
+
/** format of response (i.e. response.json() -> format: "json") */
|
|
40
|
+
format?: ResponseType;
|
|
41
|
+
/** request body */
|
|
42
|
+
body?: unknown;
|
|
43
|
+
}
|
|
44
|
+
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
45
|
+
export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
|
|
46
|
+
securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
|
|
47
|
+
secure?: boolean;
|
|
48
|
+
format?: ResponseType;
|
|
49
|
+
}
|
|
50
|
+
export declare enum ContentType {
|
|
51
|
+
Json = "application/json",
|
|
52
|
+
JsonApi = "application/vnd.api+json",
|
|
53
|
+
FormData = "multipart/form-data",
|
|
54
|
+
UrlEncoded = "application/x-www-form-urlencoded",
|
|
55
|
+
Text = "text/plain"
|
|
56
|
+
}
|
|
57
|
+
export declare class HttpClient<SecurityDataType = unknown> {
|
|
58
|
+
instance: AxiosInstance;
|
|
59
|
+
private securityData;
|
|
60
|
+
private securityWorker?;
|
|
61
|
+
private secure?;
|
|
62
|
+
private format?;
|
|
63
|
+
constructor({ securityWorker, secure, format, ...axiosConfig }?: ApiConfig<SecurityDataType>);
|
|
64
|
+
setSecurityData: (data: SecurityDataType | null) => void;
|
|
65
|
+
protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig;
|
|
66
|
+
protected stringifyFormItem(formItem: unknown): string;
|
|
67
|
+
protected createFormData(input: Record<string, unknown>): FormData;
|
|
68
|
+
request: <T = any, _E = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<AxiosResponse<T, any, {}>>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @title koala-api
|
|
72
|
+
* @version 1.0.0
|
|
73
|
+
* @baseUrl http://localhost:6601/
|
|
74
|
+
*/
|
|
75
|
+
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
76
|
+
toDos: {
|
|
77
|
+
/**
|
|
78
|
+
* No description
|
|
79
|
+
*
|
|
80
|
+
* @tags ToDos
|
|
81
|
+
* @name CreateToDo
|
|
82
|
+
* @request POST:/to-dos
|
|
83
|
+
*/
|
|
84
|
+
createToDo: (data: CreateToDoRequest, params?: RequestParams) => Promise<AxiosResponse<CreateToDoResponse, any, {}>>;
|
|
85
|
+
/**
|
|
86
|
+
* No description
|
|
87
|
+
*
|
|
88
|
+
* @tags ToDos
|
|
89
|
+
* @name GetToDos
|
|
90
|
+
* @request GET:/to-dos
|
|
91
|
+
*/
|
|
92
|
+
getToDos: (params?: RequestParams) => Promise<AxiosResponse<GetToDosResponse, any, {}>>;
|
|
93
|
+
/**
|
|
94
|
+
* No description
|
|
95
|
+
*
|
|
96
|
+
* @tags ToDos
|
|
97
|
+
* @name DeleteToDo
|
|
98
|
+
* @request DELETE:/to-dos
|
|
99
|
+
*/
|
|
100
|
+
deleteToDo: (query: {
|
|
101
|
+
/**
|
|
102
|
+
* @format int64
|
|
103
|
+
* @pattern ^-?(?:0|[1-9]\d*)$
|
|
104
|
+
*/
|
|
105
|
+
toDoId: number | string;
|
|
106
|
+
}, params?: RequestParams) => Promise<AxiosResponse<DeleteToDoResponse, any, {}>>;
|
|
107
|
+
};
|
|
108
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* ---------------------------------------------------------------
|
|
7
|
+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
8
|
+
* ## ##
|
|
9
|
+
* ## AUTHOR: acacode ##
|
|
10
|
+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
11
|
+
* ---------------------------------------------------------------
|
|
12
|
+
*/
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
23
|
+
var t = {};
|
|
24
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
25
|
+
t[p] = s[p];
|
|
26
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
27
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
28
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
29
|
+
t[p[i]] = s[p[i]];
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
};
|
|
33
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
34
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.Api = exports.HttpClient = exports.ContentType = void 0;
|
|
38
|
+
const axios_1 = __importDefault(require("axios"));
|
|
39
|
+
var ContentType;
|
|
40
|
+
(function (ContentType) {
|
|
41
|
+
ContentType["Json"] = "application/json";
|
|
42
|
+
ContentType["JsonApi"] = "application/vnd.api+json";
|
|
43
|
+
ContentType["FormData"] = "multipart/form-data";
|
|
44
|
+
ContentType["UrlEncoded"] = "application/x-www-form-urlencoded";
|
|
45
|
+
ContentType["Text"] = "text/plain";
|
|
46
|
+
})(ContentType || (exports.ContentType = ContentType = {}));
|
|
47
|
+
class HttpClient {
|
|
48
|
+
constructor(_a = {}) {
|
|
49
|
+
var { securityWorker, secure, format } = _a, axiosConfig = __rest(_a, ["securityWorker", "secure", "format"]);
|
|
50
|
+
this.securityData = null;
|
|
51
|
+
this.setSecurityData = (data) => {
|
|
52
|
+
this.securityData = data;
|
|
53
|
+
};
|
|
54
|
+
this.request = (_b) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var { secure, path, type, query, format, body } = _b, params = __rest(_b, ["secure", "path", "type", "query", "format", "body"]);
|
|
56
|
+
const secureParams = ((typeof secure === "boolean" ? secure : this.secure) &&
|
|
57
|
+
this.securityWorker &&
|
|
58
|
+
(yield this.securityWorker(this.securityData))) ||
|
|
59
|
+
{};
|
|
60
|
+
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
61
|
+
const responseFormat = format || this.format || undefined;
|
|
62
|
+
if (type === ContentType.FormData &&
|
|
63
|
+
body &&
|
|
64
|
+
body !== null &&
|
|
65
|
+
typeof body === "object") {
|
|
66
|
+
body = this.createFormData(body);
|
|
67
|
+
}
|
|
68
|
+
if (type === ContentType.Text &&
|
|
69
|
+
body &&
|
|
70
|
+
body !== null &&
|
|
71
|
+
typeof body !== "string") {
|
|
72
|
+
body = JSON.stringify(body);
|
|
73
|
+
}
|
|
74
|
+
return this.instance.request(Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (requestParams.headers || {})), (type ? { "Content-Type": type } : {})), params: query, responseType: responseFormat, data: body, url: path }));
|
|
75
|
+
});
|
|
76
|
+
this.instance = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { baseURL: axiosConfig.baseURL || "http://localhost:6601/" }));
|
|
77
|
+
this.secure = secure;
|
|
78
|
+
this.format = format;
|
|
79
|
+
this.securityWorker = securityWorker;
|
|
80
|
+
}
|
|
81
|
+
mergeRequestParams(params1, params2) {
|
|
82
|
+
const method = params1.method || (params2 && params2.method);
|
|
83
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({}, this.instance.defaults), params1), (params2 || {})), { headers: Object.assign(Object.assign(Object.assign({}, ((method &&
|
|
84
|
+
this.instance.defaults.headers[method.toLowerCase()]) ||
|
|
85
|
+
{})), (params1.headers || {})), ((params2 && params2.headers) || {})) });
|
|
86
|
+
}
|
|
87
|
+
stringifyFormItem(formItem) {
|
|
88
|
+
if (typeof formItem === "object" && formItem !== null) {
|
|
89
|
+
return JSON.stringify(formItem);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return `${formItem}`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
createFormData(input) {
|
|
96
|
+
if (input instanceof FormData) {
|
|
97
|
+
return input;
|
|
98
|
+
}
|
|
99
|
+
return Object.keys(input || {}).reduce((formData, key) => {
|
|
100
|
+
const property = input[key];
|
|
101
|
+
const propertyContent = property instanceof Array ? property : [property];
|
|
102
|
+
for (const formItem of propertyContent) {
|
|
103
|
+
const isFileType = formItem instanceof Blob || formItem instanceof File;
|
|
104
|
+
formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem));
|
|
105
|
+
}
|
|
106
|
+
return formData;
|
|
107
|
+
}, new FormData());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.HttpClient = HttpClient;
|
|
111
|
+
/**
|
|
112
|
+
* @title koala-api
|
|
113
|
+
* @version 1.0.0
|
|
114
|
+
* @baseUrl http://localhost:6601/
|
|
115
|
+
*/
|
|
116
|
+
class Api extends HttpClient {
|
|
117
|
+
constructor() {
|
|
118
|
+
super(...arguments);
|
|
119
|
+
this.toDos = {
|
|
120
|
+
/**
|
|
121
|
+
* No description
|
|
122
|
+
*
|
|
123
|
+
* @tags ToDos
|
|
124
|
+
* @name CreateToDo
|
|
125
|
+
* @request POST:/to-dos
|
|
126
|
+
*/
|
|
127
|
+
createToDo: (data, params = {}) => this.request(Object.assign({ path: `/to-dos`, method: "POST", body: data, type: ContentType.Json, format: "json" }, params)),
|
|
128
|
+
/**
|
|
129
|
+
* No description
|
|
130
|
+
*
|
|
131
|
+
* @tags ToDos
|
|
132
|
+
* @name GetToDos
|
|
133
|
+
* @request GET:/to-dos
|
|
134
|
+
*/
|
|
135
|
+
getToDos: (params = {}) => this.request(Object.assign({ path: `/to-dos`, method: "GET", format: "json" }, params)),
|
|
136
|
+
/**
|
|
137
|
+
* No description
|
|
138
|
+
*
|
|
139
|
+
* @tags ToDos
|
|
140
|
+
* @name DeleteToDo
|
|
141
|
+
* @request DELETE:/to-dos
|
|
142
|
+
*/
|
|
143
|
+
deleteToDo: (query, params = {}) => this.request(Object.assign({ path: `/to-dos`, method: "DELETE", query: query, format: "json" }, params)),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.Api = Api;
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tourmalinecore/koala-api-js-client",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Client for koala-api that provides TypeScript types and client to make network calls from JavaScript.",
|
|
5
|
+
"homepage": "https://github.com/InternalTourmalineCore/koala#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/InternalTourmalineCore/koala/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/InternalTourmalineCore/koala.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "InternalTourmalineCore",
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5.2.2"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"axios": ">=1.8.2"
|
|
27
|
+
}
|
|
6
28
|
}
|
package/README.md
DELETED