var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/dataSourceComponents/dataSourceForm/serve.ts
var serve_exports = {};
__export(serve_exports, {
  createNocobaseData: () => createNocobaseData,
  customApi: () => customApi,
  deleteNocobaseData: () => deleteNocobaseData,
  getNocobaseData: () => getNocobaseData,
  getNocobaseDataList: () => getNocobaseDataList,
  getNocobaseDataSource: () => getNocobaseDataSource,
  getNocobaseDataSourceOptions: () => getNocobaseDataSourceOptions,
  getNocobaseMainDataSource: () => getNocobaseMainDataSource,
  updateNocobaseData: () => updateNocobaseData
});
module.exports = __toCommonJS(serve_exports);
var import_utils = require("../../table/utils");
var getNocobaseDataSource = async () => {
  return import_utils.request.getRequest().post(
    "/dataSources:listEnabled?paginate=false&appends%5B%5D=collections",
    {},
    {
      isNocobase: true
    }
  );
};
var getNocobaseMainDataSource = async () => {
  return import_utils.request.getRequest().post(
    "/collections:list?paginate=false&appends%5B%5D=fields&sort%5B%5D=sort&filter=%7B%7D",
    {},
    {
      isNocobase: true
    }
  );
};
var getNocobaseDataSourceOptions = async () => {
  return import_utils.request.getRequest().post(
    "/dataSources:list?appends=collections",
    {},
    {
      isNocobase: true
    }
  );
};
var createNocobaseData = async (params) => {
  const { key, data, headers } = params;
  return import_utils.request.getRequest().post(`/${key}:create`, data, {
    isNocobase: true,
    headers
  });
};
var getNocobaseData = async (params) => {
  const { key, id } = params;
  return import_utils.request.getRequest().get(
    `/${key}:get?filterByTk=${id}`,
    {},
    {
      isNocobase: true
    }
  );
};
var methodMap = {
  GET: "get",
  POST: "post",
  PUT: "put",
  DELETE: "remove"
};
var formatHeaders = (headers) => {
  return headers == null ? void 0 : headers.reduce((acc, curr) => {
    acc[curr.name] = curr.value;
    return acc;
  }, {});
};
var formatQueryString = (params = []) => params.map(
  ({ name, value }) => `${encodeURIComponent(name)}=${encodeURIComponent(value)}`
).join("&");
var formatRequestUrl = (url, baseUrl, queryString) => {
  const baseRequestUrl = baseUrl ? `${baseUrl}${url}` : url;
  return queryString ? `${baseRequestUrl}${baseRequestUrl.includes("?") ? "&" : "?"}${queryString}` : baseRequestUrl;
};
var customApi = async (url, data, options) => {
  const { method, baseUrl, headers = [], params = [], body = {} } = options;
  const requestHeaders = formatHeaders(headers);
  const queryString = formatQueryString(params);
  const requestUrl = formatRequestUrl(url, baseUrl, queryString);
  const requestData = method === "GET" ? data : { ...body, ...data };
  const requestMethod = methodMap[method];
  return import_utils.request.getRequest()[requestMethod](requestUrl, requestData, { headers: requestHeaders, isCustomApi: true });
};
var updateNocobaseData = async (params) => {
  const { key, id, data, headers } = params;
  return import_utils.request.getRequest().post(`/${key}:update?filterByTk=${id}`, data, {
    isNocobase: true,
    headers
  });
};
var getNocobaseDataList = async (allParams) => {
  const { key, params, headers } = allParams;
  return import_utils.request.getRequest().get(`/${key}:list`, params, {
    isNocobase: true,
    fullResult: true,
    headers
  });
};
var deleteNocobaseData = async (key, id, headers) => {
  return import_utils.request.getRequest().post(
    `/${key}:destroy?filterByTk=${id}`,
    {},
    {
      isNocobase: true,
      headers
    }
  );
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createNocobaseData,
  customApi,
  deleteNocobaseData,
  getNocobaseData,
  getNocobaseDataList,
  getNocobaseDataSource,
  getNocobaseDataSourceOptions,
  getNocobaseMainDataSource,
  updateNocobaseData
});
