This commit is contained in:
2025-12-22 07:18:57 +01:00
parent 0d9f313dc0
commit cfcd08680f
46 changed files with 1338 additions and 98 deletions
+10
View File
@@ -0,0 +1,10 @@
import { APIResponseObject, ClientCrudFetchParams, PostInsertReturn } from "../../package-shared/types";
export default function clientCrudFetch<T extends {
[k: string]: any;
} = {
[k: string]: any;
}, P = string, R extends {
[k: string]: any;
} = {
[k: string]: any;
}>({ table, basePath, body, query, targetId, method, apiOrigin, }: ClientCrudFetchParams<T, P>): Promise<APIResponseObject<PostInsertReturn | R[]>>;
+46
View File
@@ -0,0 +1,46 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = clientCrudFetch;
const path_1 = __importDefault(require("path"));
const serialize_query_1 = __importDefault(require("../../package-shared/utils/serialize-query"));
const fetch_1 = __importDefault(require("../fetch"));
function clientCrudFetch(_a) {
return __awaiter(this, arguments, void 0, function* ({ table, basePath, body, query, targetId, method = "GET", apiOrigin, }) {
try {
let pathname = basePath || ``;
pathname = path_1.default.join(pathname, String(table));
if (targetId) {
pathname = path_1.default.join(pathname, String(targetId));
}
if (query) {
pathname = `${pathname}${(0, serialize_query_1.default)(query)}`;
}
pathname = apiOrigin
? `${apiOrigin}/${pathname}`.replace(/([^:]\/)\/+/g, "$1")
: pathname;
const res = yield (0, fetch_1.default)(pathname, {
method,
body,
});
return res;
}
catch (error) {
return {
success: false,
msg: `API ERROR => ${error.message}`,
};
}
});
}
+2
View File
@@ -12,6 +12,7 @@ import slugify from "../package-shared/utils/slugify";
import postLogin from "./auth/post-login";
import deserializeQuery from "../package-shared/utils/deserialize-query";
import debugLog from "../package-shared/utils/logging/debug-log";
import clientCrudFetch from "./crud-fetch";
/**
* Main Export
*/
@@ -51,5 +52,6 @@ declare const datasquirelClient: {
slugify: typeof slugify;
debugLog: typeof debugLog;
};
clientCrudFetch: typeof clientCrudFetch;
};
export default datasquirelClient;
+8 -1
View File
@@ -19,6 +19,7 @@ const slugify_1 = __importDefault(require("../package-shared/utils/slugify"));
const post_login_1 = __importDefault(require("./auth/post-login"));
const deserialize_query_1 = __importDefault(require("../package-shared/utils/deserialize-query"));
const debug_log_1 = __importDefault(require("../package-shared/utils/logging/debug-log"));
const crud_fetch_1 = __importDefault(require("./crud-fetch"));
const media = {
imageInputToBase64: imageInputToBase64_1.default,
imageInputFileToBase64: imageInputFileToBase64_1.default,
@@ -56,5 +57,11 @@ const fetch = {
/**
* Main Export
*/
const datasquirelClient = { media, auth, fetch, utils };
const datasquirelClient = {
media,
auth,
fetch,
utils,
clientCrudFetch: crud_fetch_1.default,
};
exports.default = datasquirelClient;