@sfutureapps/db-sdk 0.3.12 → 0.3.13
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.mts +4 -8
- package/dist/index.d.ts +4 -8
- package/dist/index.js +36 -47
- package/dist/index.mjs +26 -47
- package/package.json +5 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
|
|
1
3
|
type FilterOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "notLike" | "between" | "notBetween" | "in" | "notIn" | "isNull" | "notNull" | "regexp" | "notRegexp" | "time" | "findInSet";
|
|
2
4
|
type Filter = {
|
|
3
5
|
col: string;
|
|
@@ -22,9 +24,7 @@ type DbResponse<T> = {
|
|
|
22
24
|
type ClientOptions = {
|
|
23
25
|
apiKey?: string;
|
|
24
26
|
accessToken?: () => string | null;
|
|
25
|
-
fetch?: typeof fetch;
|
|
26
27
|
headers?: Record<string, string>;
|
|
27
|
-
timeoutMs?: number;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
declare class HttpClient {
|
|
@@ -32,13 +32,9 @@ declare class HttpClient {
|
|
|
32
32
|
private apiKey?;
|
|
33
33
|
private accessToken?;
|
|
34
34
|
private extraHeaders;
|
|
35
|
+
private ax;
|
|
35
36
|
constructor(baseUrl: string, opts?: ClientOptions);
|
|
36
|
-
|
|
37
|
-
timeoutMs?: number;
|
|
38
|
-
}): Promise<any>;
|
|
39
|
-
post<T>(path: string, body: any, init?: RequestInit & {
|
|
40
|
-
timeoutMs?: number;
|
|
41
|
-
}): Promise<DbResponse<T>>;
|
|
37
|
+
post<T>(path: string, body: any, config?: AxiosRequestConfig): Promise<DbResponse<T>>;
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
type OrderOpts = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
|
|
1
3
|
type FilterOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like" | "notLike" | "between" | "notBetween" | "in" | "notIn" | "isNull" | "notNull" | "regexp" | "notRegexp" | "time" | "findInSet";
|
|
2
4
|
type Filter = {
|
|
3
5
|
col: string;
|
|
@@ -22,9 +24,7 @@ type DbResponse<T> = {
|
|
|
22
24
|
type ClientOptions = {
|
|
23
25
|
apiKey?: string;
|
|
24
26
|
accessToken?: () => string | null;
|
|
25
|
-
fetch?: typeof fetch;
|
|
26
27
|
headers?: Record<string, string>;
|
|
27
|
-
timeoutMs?: number;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
declare class HttpClient {
|
|
@@ -32,13 +32,9 @@ declare class HttpClient {
|
|
|
32
32
|
private apiKey?;
|
|
33
33
|
private accessToken?;
|
|
34
34
|
private extraHeaders;
|
|
35
|
+
private ax;
|
|
35
36
|
constructor(baseUrl: string, opts?: ClientOptions);
|
|
36
|
-
|
|
37
|
-
timeoutMs?: number;
|
|
38
|
-
}): Promise<any>;
|
|
39
|
-
post<T>(path: string, body: any, init?: RequestInit & {
|
|
40
|
-
timeoutMs?: number;
|
|
41
|
-
}): Promise<DbResponse<T>>;
|
|
37
|
+
post<T>(path: string, body: any, config?: AxiosRequestConfig): Promise<DbResponse<T>>;
|
|
42
38
|
}
|
|
43
39
|
|
|
44
40
|
type OrderOpts = {
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -25,72 +35,51 @@ __export(index_exports, {
|
|
|
25
35
|
module.exports = __toCommonJS(index_exports);
|
|
26
36
|
|
|
27
37
|
// src/client.ts
|
|
38
|
+
var import_axios = __toESM(require("axios"));
|
|
28
39
|
var HttpClient = class {
|
|
29
40
|
constructor(baseUrl, opts = {}) {
|
|
30
41
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
31
42
|
this.apiKey = opts.apiKey;
|
|
32
43
|
this.accessToken = opts.accessToken;
|
|
33
|
-
const g = globalThis;
|
|
34
|
-
const fetchImpl = opts.fetch ?? g.fetch ?? g.window?.fetch;
|
|
35
|
-
if (typeof fetchImpl !== "function") {
|
|
36
|
-
throw new Error("Fetch API is not available in this environment. Provide ClientOptions.fetch or a global fetch polyfill.");
|
|
37
|
-
}
|
|
38
44
|
this.extraHeaders = opts.headers ?? {};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const res = await fetch(input, { ...rest, signal: ac.signal });
|
|
46
|
-
const ct = res.headers.get("content-type") || "";
|
|
47
|
-
const payload = ct.includes("application/json") ? await res.json() : await res.text();
|
|
48
|
-
if (!res.ok) {
|
|
49
|
-
const err = new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
50
|
-
err.status = res.status;
|
|
51
|
-
err.body = payload;
|
|
52
|
-
throw err;
|
|
45
|
+
this.ax = import_axios.default.create({
|
|
46
|
+
baseURL: this.baseUrl,
|
|
47
|
+
timeout: 15e3,
|
|
48
|
+
headers: {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
...this.extraHeaders
|
|
53
51
|
}
|
|
54
|
-
|
|
55
|
-
} finally {
|
|
56
|
-
clearTimeout(id);
|
|
57
|
-
}
|
|
52
|
+
});
|
|
58
53
|
}
|
|
59
|
-
async post(path, body,
|
|
54
|
+
async post(path, body, config = {}) {
|
|
60
55
|
const headers = {
|
|
61
|
-
|
|
62
|
-
...
|
|
56
|
+
...this.extraHeaders,
|
|
57
|
+
...config.headers
|
|
63
58
|
};
|
|
64
59
|
if (this.apiKey) headers["x-api-key"] = this.apiKey;
|
|
65
60
|
const token = this.accessToken?.();
|
|
66
61
|
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
67
62
|
try {
|
|
68
|
-
const
|
|
69
|
-
...
|
|
70
|
-
|
|
71
|
-
headers: {
|
|
72
|
-
...headers,
|
|
73
|
-
...init.headers
|
|
74
|
-
},
|
|
75
|
-
body: JSON.stringify(body)
|
|
63
|
+
const res = await this.ax.post(path, body, {
|
|
64
|
+
...config,
|
|
65
|
+
headers
|
|
76
66
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
return { data: null, error: { status: 200, message: "Invalid JSON response", details: payload } };
|
|
67
|
+
const payload = res.data;
|
|
68
|
+
return {
|
|
69
|
+
data: payload?.data ?? null,
|
|
70
|
+
count: payload?.count ?? null,
|
|
71
|
+
meta: payload?.meta ?? null,
|
|
72
|
+
error: payload?.error ?? null
|
|
73
|
+
};
|
|
86
74
|
} catch (e) {
|
|
87
|
-
const
|
|
75
|
+
const status = e?.response?.status ?? 0;
|
|
76
|
+
const payload = e?.response?.data ?? null;
|
|
88
77
|
return {
|
|
89
78
|
data: null,
|
|
90
79
|
error: {
|
|
91
|
-
status
|
|
92
|
-
message:
|
|
93
|
-
details:
|
|
80
|
+
status,
|
|
81
|
+
message: payload?.error?.message ?? e?.message ?? "Network error",
|
|
82
|
+
details: payload ?? e
|
|
94
83
|
}
|
|
95
84
|
};
|
|
96
85
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,70 +1,49 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
+
import axios from "axios";
|
|
2
3
|
var HttpClient = class {
|
|
3
4
|
constructor(baseUrl, opts = {}) {
|
|
4
5
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
5
6
|
this.apiKey = opts.apiKey;
|
|
6
7
|
this.accessToken = opts.accessToken;
|
|
7
|
-
const g = globalThis;
|
|
8
|
-
const fetchImpl = opts.fetch ?? g.fetch ?? g.window?.fetch;
|
|
9
|
-
if (typeof fetchImpl !== "function") {
|
|
10
|
-
throw new Error("Fetch API is not available in this environment. Provide ClientOptions.fetch or a global fetch polyfill.");
|
|
11
|
-
}
|
|
12
8
|
this.extraHeaders = opts.headers ?? {};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const res = await fetch(input, { ...rest, signal: ac.signal });
|
|
20
|
-
const ct = res.headers.get("content-type") || "";
|
|
21
|
-
const payload = ct.includes("application/json") ? await res.json() : await res.text();
|
|
22
|
-
if (!res.ok) {
|
|
23
|
-
const err = new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
24
|
-
err.status = res.status;
|
|
25
|
-
err.body = payload;
|
|
26
|
-
throw err;
|
|
9
|
+
this.ax = axios.create({
|
|
10
|
+
baseURL: this.baseUrl,
|
|
11
|
+
timeout: 15e3,
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
...this.extraHeaders
|
|
27
15
|
}
|
|
28
|
-
|
|
29
|
-
} finally {
|
|
30
|
-
clearTimeout(id);
|
|
31
|
-
}
|
|
16
|
+
});
|
|
32
17
|
}
|
|
33
|
-
async post(path, body,
|
|
18
|
+
async post(path, body, config = {}) {
|
|
34
19
|
const headers = {
|
|
35
|
-
|
|
36
|
-
...
|
|
20
|
+
...this.extraHeaders,
|
|
21
|
+
...config.headers
|
|
37
22
|
};
|
|
38
23
|
if (this.apiKey) headers["x-api-key"] = this.apiKey;
|
|
39
24
|
const token = this.accessToken?.();
|
|
40
25
|
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
41
26
|
try {
|
|
42
|
-
const
|
|
43
|
-
...
|
|
44
|
-
|
|
45
|
-
headers: {
|
|
46
|
-
...headers,
|
|
47
|
-
...init.headers
|
|
48
|
-
},
|
|
49
|
-
body: JSON.stringify(body)
|
|
27
|
+
const res = await this.ax.post(path, body, {
|
|
28
|
+
...config,
|
|
29
|
+
headers
|
|
50
30
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
return { data: null, error: { status: 200, message: "Invalid JSON response", details: payload } };
|
|
31
|
+
const payload = res.data;
|
|
32
|
+
return {
|
|
33
|
+
data: payload?.data ?? null,
|
|
34
|
+
count: payload?.count ?? null,
|
|
35
|
+
meta: payload?.meta ?? null,
|
|
36
|
+
error: payload?.error ?? null
|
|
37
|
+
};
|
|
60
38
|
} catch (e) {
|
|
61
|
-
const
|
|
39
|
+
const status = e?.response?.status ?? 0;
|
|
40
|
+
const payload = e?.response?.data ?? null;
|
|
62
41
|
return {
|
|
63
42
|
data: null,
|
|
64
43
|
error: {
|
|
65
|
-
status
|
|
66
|
-
message:
|
|
67
|
-
details:
|
|
44
|
+
status,
|
|
45
|
+
message: payload?.error?.message ?? e?.message ?? "Network error",
|
|
46
|
+
details: payload ?? e
|
|
68
47
|
}
|
|
69
48
|
};
|
|
70
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sfutureapps/db-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
4
4
|
"description": "SfutureApps JS SDK for ThinkPHP DB Gateway (MySQL)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -35,5 +35,8 @@
|
|
|
35
35
|
"typescript",
|
|
36
36
|
"sFutureApps",
|
|
37
37
|
"sfutureapps.com"
|
|
38
|
-
]
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"axios": "^1.13.2"
|
|
41
|
+
}
|
|
39
42
|
}
|