melhorias de caches
This commit is contained in:
parent
29ae7400cf
commit
00e9c4d698
18 changed files with 210 additions and 66 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"$schema": "node_modules/@biomejs/biome/configuration_schema.json",
|
"$schema": "node_modules/@biomejs/biome/configuration_schema.json",
|
||||||
"extends": ["node_modules/p-comuns/Documentos/biome.json"],
|
"extends": [
|
||||||
"files": {
|
"node_modules/p-comuns/Documentos/biome.json"
|
||||||
|
],
|
||||||
}
|
"files": {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
bun.lock
8
bun.lock
|
|
@ -5,8 +5,10 @@
|
||||||
"name": "p-autenticacao-drive",
|
"name": "p-autenticacao-drive",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cross-fetch": "^4.1.0",
|
"cross-fetch": "^4.1.0",
|
||||||
|
"node-cache": "^5.1.2",
|
||||||
"p-comuns": "git+https://git2.idz.one/publico/_comuns.git#master",
|
"p-comuns": "git+https://git2.idz.one/publico/_comuns.git#master",
|
||||||
"p-respostas": "git+https://git2.idz.one/publico/_respostas.git#master",
|
"p-respostas": "git+https://git2.idz.one/publico/_respostas.git#master",
|
||||||
|
"uuid": "^11.1.0",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^2.0.6",
|
"@biomejs/biome": "^2.0.6",
|
||||||
|
|
@ -43,6 +45,8 @@
|
||||||
|
|
||||||
"check-node-version": ["check-node-version@4.2.1", "", { "dependencies": { "chalk": "^3.0.0", "map-values": "^1.0.1", "minimist": "^1.2.0", "object-filter": "^1.0.2", "run-parallel": "^1.1.4", "semver": "^6.3.0" }, "bin": { "check-node-version": "bin.js" } }, "sha512-YYmFYHV/X7kSJhuN/QYHUu998n/TRuDe8UenM3+m5NrkiH670lb9ILqHIvBencvJc4SDh+XcbXMR4b+TtubJiw=="],
|
"check-node-version": ["check-node-version@4.2.1", "", { "dependencies": { "chalk": "^3.0.0", "map-values": "^1.0.1", "minimist": "^1.2.0", "object-filter": "^1.0.2", "run-parallel": "^1.1.4", "semver": "^6.3.0" }, "bin": { "check-node-version": "bin.js" } }, "sha512-YYmFYHV/X7kSJhuN/QYHUu998n/TRuDe8UenM3+m5NrkiH670lb9ILqHIvBencvJc4SDh+XcbXMR4b+TtubJiw=="],
|
||||||
|
|
||||||
|
"clone": ["clone@2.1.2", "", {}, "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w=="],
|
||||||
|
|
||||||
"color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="],
|
"color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="],
|
||||||
|
|
||||||
"color-name": ["color-name@1.1.4", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="],
|
"color-name": ["color-name@1.1.4", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="],
|
||||||
|
|
@ -55,6 +59,8 @@
|
||||||
|
|
||||||
"minimist": ["minimist@1.2.8", "", {}, "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="],
|
"minimist": ["minimist@1.2.8", "", {}, "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="],
|
||||||
|
|
||||||
|
"node-cache": ["node-cache@5.1.2", "", { "dependencies": { "clone": "2.x" } }, "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg=="],
|
||||||
|
|
||||||
"node-fetch": ["node-fetch@2.7.0", "", { "dependencies": { "whatwg-url": "^5.0.0" }, "peerDependencies": { "encoding": "^0.1.0" }, "optionalPeers": ["encoding"] }, "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A=="],
|
"node-fetch": ["node-fetch@2.7.0", "", { "dependencies": { "whatwg-url": "^5.0.0" }, "peerDependencies": { "encoding": "^0.1.0" }, "optionalPeers": ["encoding"] }, "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A=="],
|
||||||
|
|
||||||
"object-filter": ["object-filter@1.0.2", "", {}, "sha512-NahvP2vZcy1ZiiYah30CEPw0FpDcSkSePJBMpzl5EQgCmISijiGuJm3SPYp7U+Lf2TljyaIw3E5EgkEx/TNEVA=="],
|
"object-filter": ["object-filter@1.0.2", "", {}, "sha512-NahvP2vZcy1ZiiYah30CEPw0FpDcSkSePJBMpzl5EQgCmISijiGuJm3SPYp7U+Lf2TljyaIw3E5EgkEx/TNEVA=="],
|
||||||
|
|
@ -77,6 +83,8 @@
|
||||||
|
|
||||||
"undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
|
"undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
|
||||||
|
|
||||||
|
"uuid": ["uuid@11.1.0", "", { "bin": { "uuid": "dist/esm/bin/uuid" } }, "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A=="],
|
||||||
|
|
||||||
"webidl-conversions": ["webidl-conversions@3.0.1", "", {}, "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="],
|
"webidl-conversions": ["webidl-conversions@3.0.1", "", {}, "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="],
|
||||||
|
|
||||||
"whatwg-url": ["whatwg-url@5.0.0", "", { "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" } }, "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw=="],
|
"whatwg-url": ["whatwg-url@5.0.0", "", { "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" } }, "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw=="],
|
||||||
|
|
|
||||||
4
dist-import/lista-vinculos.d.ts
vendored
4
dist-import/lista-vinculos.d.ts
vendored
|
|
@ -10,7 +10,9 @@ export type tipo_retorno_vinculo_listas = {
|
||||||
_inquilino_nome: string;
|
_inquilino_nome: string;
|
||||||
_inquilino_base_url: string;
|
_inquilino_base_url: string;
|
||||||
};
|
};
|
||||||
export declare const listarVinculos: ({ token, url_api_autenticacao, }: {
|
export declare const listarVinculos: ({ token, url_api_autenticacao, desativarCache, }: {
|
||||||
url_api_autenticacao: string;
|
url_api_autenticacao: string;
|
||||||
token: string;
|
token: string;
|
||||||
|
/** por padrão será 10 segundos */
|
||||||
|
desativarCache?: boolean;
|
||||||
}) => Promise<tipoResposta<tipo_retorno_vinculo_listas[]>>;
|
}) => Promise<tipoResposta<tipo_retorno_vinculo_listas[]>>;
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,45 @@
|
||||||
import cFetch from "cross-fetch";
|
import cFetch from "cross-fetch";
|
||||||
import { respostaComuns } from "p-respostas";
|
import { respostaComuns } from "p-respostas";
|
||||||
|
import { cacheAuDrive } from "./plugins/node-cache";
|
||||||
|
import { uuidV3 } from "./plugins/uuid";
|
||||||
export const tx_vinculos__listar = "vinculos__listar";
|
export const tx_vinculos__listar = "vinculos__listar";
|
||||||
export const listarVinculos = async ({ token, url_api_autenticacao, }) => {
|
export const listarVinculos = async ({ token, url_api_autenticacao, desativarCache, }) => {
|
||||||
const url = `${url_api_autenticacao}/api/${tx_vinculos__listar}`;
|
const chaveCache = uuidV3({ token, url_api_autenticacao });
|
||||||
return cFetch(url, {
|
// Buscar promeiro no cache
|
||||||
headers: { token, "Content-Type": "application/json" },
|
if (!desativarCache) {
|
||||||
body: "{}",
|
const valorCache = cacheAuDrive.get(chaveCache);
|
||||||
method: "post",
|
if (valorCache)
|
||||||
})
|
return valorCache;
|
||||||
.then(async (a) => {
|
}
|
||||||
const texto = await a.text();
|
const res = (async () => {
|
||||||
|
const url = `${url_api_autenticacao}/api/${tx_vinculos__listar}`;
|
||||||
|
return cFetch(url, {
|
||||||
|
headers: { token, "Content-Type": "application/json" },
|
||||||
|
body: "{}",
|
||||||
|
method: "post",
|
||||||
|
})
|
||||||
|
.then(async (a) => {
|
||||||
|
const texto = await a.text();
|
||||||
|
try {
|
||||||
|
const res = JSON.parse(texto);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [texto, error]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [
|
||||||
|
error,
|
||||||
|
]));
|
||||||
|
})();
|
||||||
|
cacheAuDrive.set(chaveCache, res.then((a) => {
|
||||||
try {
|
try {
|
||||||
const res = JSON.parse(texto);
|
if (a.eErro) {
|
||||||
return res;
|
cacheAuDrive.del(chaveCache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch { }
|
||||||
return respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [
|
return a;
|
||||||
texto,
|
}), 10);
|
||||||
error,
|
return res;
|
||||||
]);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [error]));
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
2
dist-import/plugins/node-cache.d.ts
vendored
Normal file
2
dist-import/plugins/node-cache.d.ts
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
import NodeCache from "node-cache";
|
||||||
|
export declare const cacheAuDrive: NodeCache;
|
||||||
2
dist-import/plugins/node-cache.js
Normal file
2
dist-import/plugins/node-cache.js
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
import NodeCache from "node-cache";
|
||||||
|
export const cacheAuDrive = new NodeCache();
|
||||||
3
dist-import/plugins/uuid.d.ts
vendored
Normal file
3
dist-import/plugins/uuid.d.ts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { v4 } from "uuid";
|
||||||
|
export declare const uuidV3: (qualquerCoisa: any) => string;
|
||||||
|
export declare const uuidV4: typeof v4;
|
||||||
7
dist-import/plugins/uuid.js
Normal file
7
dist-import/plugins/uuid.js
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { NIL, v3, v4 } from "uuid";
|
||||||
|
export const uuidV3 = (qualquerCoisa) => v3(typeof qualquerCoisa == "string"
|
||||||
|
? qualquerCoisa
|
||||||
|
: typeof qualquerCoisa == "number"
|
||||||
|
? String(qualquerCoisa)
|
||||||
|
: JSON.stringify(qualquerCoisa), NIL);
|
||||||
|
export const uuidV4 = v4;
|
||||||
4
dist-require/lista-vinculos.d.ts
vendored
4
dist-require/lista-vinculos.d.ts
vendored
|
|
@ -10,7 +10,9 @@ export type tipo_retorno_vinculo_listas = {
|
||||||
_inquilino_nome: string;
|
_inquilino_nome: string;
|
||||||
_inquilino_base_url: string;
|
_inquilino_base_url: string;
|
||||||
};
|
};
|
||||||
export declare const listarVinculos: ({ token, url_api_autenticacao, }: {
|
export declare const listarVinculos: ({ token, url_api_autenticacao, desativarCache, }: {
|
||||||
url_api_autenticacao: string;
|
url_api_autenticacao: string;
|
||||||
token: string;
|
token: string;
|
||||||
|
/** por padrão será 10 segundos */
|
||||||
|
desativarCache?: boolean;
|
||||||
}) => Promise<tipoResposta<tipo_retorno_vinculo_listas[]>>;
|
}) => Promise<tipoResposta<tipo_retorno_vinculo_listas[]>>;
|
||||||
|
|
|
||||||
|
|
@ -6,27 +6,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.listarVinculos = exports.tx_vinculos__listar = void 0;
|
exports.listarVinculos = exports.tx_vinculos__listar = void 0;
|
||||||
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
||||||
const p_respostas_1 = require("p-respostas");
|
const p_respostas_1 = require("p-respostas");
|
||||||
|
const node_cache_1 = require("./plugins/node-cache");
|
||||||
|
const uuid_1 = require("./plugins/uuid");
|
||||||
exports.tx_vinculos__listar = "vinculos__listar";
|
exports.tx_vinculos__listar = "vinculos__listar";
|
||||||
const listarVinculos = async ({ token, url_api_autenticacao, }) => {
|
const listarVinculos = async ({ token, url_api_autenticacao, desativarCache, }) => {
|
||||||
const url = `${url_api_autenticacao}/api/${exports.tx_vinculos__listar}`;
|
const chaveCache = (0, uuid_1.uuidV3)({ token, url_api_autenticacao });
|
||||||
return (0, cross_fetch_1.default)(url, {
|
// Buscar promeiro no cache
|
||||||
headers: { token, "Content-Type": "application/json" },
|
if (!desativarCache) {
|
||||||
body: "{}",
|
const valorCache = node_cache_1.cacheAuDrive.get(chaveCache);
|
||||||
method: "post",
|
if (valorCache)
|
||||||
})
|
return valorCache;
|
||||||
.then(async (a) => {
|
}
|
||||||
const texto = await a.text();
|
const res = (async () => {
|
||||||
|
const url = `${url_api_autenticacao}/api/${exports.tx_vinculos__listar}`;
|
||||||
|
return (0, cross_fetch_1.default)(url, {
|
||||||
|
headers: { token, "Content-Type": "application/json" },
|
||||||
|
body: "{}",
|
||||||
|
method: "post",
|
||||||
|
})
|
||||||
|
.then(async (a) => {
|
||||||
|
const texto = await a.text();
|
||||||
|
try {
|
||||||
|
const res = JSON.parse(texto);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
return p_respostas_1.respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [texto, error]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => p_respostas_1.respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [
|
||||||
|
error,
|
||||||
|
]));
|
||||||
|
})();
|
||||||
|
node_cache_1.cacheAuDrive.set(chaveCache, res.then((a) => {
|
||||||
try {
|
try {
|
||||||
const res = JSON.parse(texto);
|
if (a.eErro) {
|
||||||
return res;
|
node_cache_1.cacheAuDrive.del(chaveCache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch { }
|
||||||
return p_respostas_1.respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [
|
return a;
|
||||||
texto,
|
}), 10);
|
||||||
error,
|
return res;
|
||||||
]);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => p_respostas_1.respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [error]));
|
|
||||||
};
|
};
|
||||||
exports.listarVinculos = listarVinculos;
|
exports.listarVinculos = listarVinculos;
|
||||||
|
|
|
||||||
2
dist-require/plugins/node-cache.d.ts
vendored
Normal file
2
dist-require/plugins/node-cache.d.ts
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
import NodeCache from "node-cache";
|
||||||
|
export declare const cacheAuDrive: NodeCache;
|
||||||
8
dist-require/plugins/node-cache.js
Normal file
8
dist-require/plugins/node-cache.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.cacheAuDrive = void 0;
|
||||||
|
const node_cache_1 = __importDefault(require("node-cache"));
|
||||||
|
exports.cacheAuDrive = new node_cache_1.default();
|
||||||
3
dist-require/plugins/uuid.d.ts
vendored
Normal file
3
dist-require/plugins/uuid.d.ts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { v4 } from "uuid";
|
||||||
|
export declare const uuidV3: (qualquerCoisa: any) => string;
|
||||||
|
export declare const uuidV4: typeof v4;
|
||||||
11
dist-require/plugins/uuid.js
Normal file
11
dist-require/plugins/uuid.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.uuidV4 = exports.uuidV3 = void 0;
|
||||||
|
const uuid_1 = require("uuid");
|
||||||
|
const uuidV3 = (qualquerCoisa) => (0, uuid_1.v3)(typeof qualquerCoisa == "string"
|
||||||
|
? qualquerCoisa
|
||||||
|
: typeof qualquerCoisa == "number"
|
||||||
|
? String(qualquerCoisa)
|
||||||
|
: JSON.stringify(qualquerCoisa), uuid_1.NIL);
|
||||||
|
exports.uuidV3 = uuidV3;
|
||||||
|
exports.uuidV4 = uuid_1.v4;
|
||||||
|
|
@ -21,8 +21,10 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cross-fetch": "^4.1.0",
|
"cross-fetch": "^4.1.0",
|
||||||
|
"node-cache": "^5.1.2",
|
||||||
"p-comuns": "git+https://git2.idz.one/publico/_comuns.git#master",
|
"p-comuns": "git+https://git2.idz.one/publico/_comuns.git#master",
|
||||||
"p-respostas": "git+https://git2.idz.one/publico/_respostas.git#master"
|
"p-respostas": "git+https://git2.idz.one/publico/_respostas.git#master",
|
||||||
|
"uuid": "^11.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^2.0.6",
|
"@biomejs/biome": "^2.0.6",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import cFetch from "cross-fetch"
|
import cFetch from "cross-fetch"
|
||||||
import { respostaComuns, type tipoResposta } from "p-respostas"
|
import { respostaComuns, type tipoResposta } from "p-respostas"
|
||||||
|
import { cacheAuDrive } from "./plugins/node-cache"
|
||||||
|
import { uuidV3 } from "./plugins/uuid"
|
||||||
|
|
||||||
export const tx_vinculos__listar = "vinculos__listar" as const
|
export const tx_vinculos__listar = "vinculos__listar" as const
|
||||||
export type tipo_retorno_vinculo_listas = {
|
export type tipo_retorno_vinculo_listas = {
|
||||||
|
|
@ -16,33 +18,67 @@ export type tipo_retorno_vinculo_listas = {
|
||||||
export const listarVinculos = async ({
|
export const listarVinculos = async ({
|
||||||
token,
|
token,
|
||||||
url_api_autenticacao,
|
url_api_autenticacao,
|
||||||
|
desativarCache,
|
||||||
}: {
|
}: {
|
||||||
url_api_autenticacao: string
|
url_api_autenticacao: string
|
||||||
token: string
|
token: string
|
||||||
|
/** por padrão será 10 segundos */
|
||||||
|
desativarCache?: boolean
|
||||||
}): Promise<tipoResposta<tipo_retorno_vinculo_listas[]>> => {
|
}): Promise<tipoResposta<tipo_retorno_vinculo_listas[]>> => {
|
||||||
const url = `${url_api_autenticacao}/api/${tx_vinculos__listar}`
|
const chaveCache = uuidV3({ token, url_api_autenticacao })
|
||||||
|
|
||||||
return cFetch(url, {
|
// Buscar promeiro no cache
|
||||||
headers: { token, "Content-Type": "application/json" },
|
if (!desativarCache) {
|
||||||
body: "{}",
|
const valorCache =
|
||||||
method: "post",
|
cacheAuDrive.get<Promise<tipoResposta<tipo_retorno_vinculo_listas[]>>>(
|
||||||
})
|
chaveCache,
|
||||||
.then(async (a) => {
|
)
|
||||||
const texto = await a.text()
|
if (valorCache) return valorCache
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
const res = (async () => {
|
||||||
const res: tipoResposta<tipo_retorno_vinculo_listas[]> =
|
const url = `${url_api_autenticacao}/api/${tx_vinculos__listar}`
|
||||||
JSON.parse(texto)
|
|
||||||
|
|
||||||
return res
|
return cFetch(url, {
|
||||||
} catch (error: any) {
|
headers: { token, "Content-Type": "application/json" },
|
||||||
return respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [
|
body: "{}",
|
||||||
texto,
|
method: "post",
|
||||||
error,
|
|
||||||
])
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((error) =>
|
.then(async (a) => {
|
||||||
respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [error]),
|
const texto = await a.text()
|
||||||
)
|
|
||||||
|
try {
|
||||||
|
const res: tipoResposta<tipo_retorno_vinculo_listas[]> =
|
||||||
|
JSON.parse(texto)
|
||||||
|
|
||||||
|
return res
|
||||||
|
} catch (error: any) {
|
||||||
|
return respostaComuns.erro(
|
||||||
|
`Erro ao listar cidades: ${error.message}`,
|
||||||
|
[texto, error],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) =>
|
||||||
|
respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [
|
||||||
|
error,
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
})()
|
||||||
|
|
||||||
|
cacheAuDrive.set(
|
||||||
|
chaveCache,
|
||||||
|
res.then((a) => {
|
||||||
|
try {
|
||||||
|
if (a.eErro) {
|
||||||
|
cacheAuDrive.del(chaveCache)
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}),
|
||||||
|
10,
|
||||||
|
)
|
||||||
|
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
src/plugins/node-cache.ts
Normal file
3
src/plugins/node-cache.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import NodeCache from "node-cache"
|
||||||
|
|
||||||
|
export const cacheAuDrive = new NodeCache()
|
||||||
13
src/plugins/uuid.ts
Normal file
13
src/plugins/uuid.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { NIL, v3, v4 } from "uuid"
|
||||||
|
|
||||||
|
export const uuidV3 = (qualquerCoisa: any) =>
|
||||||
|
v3(
|
||||||
|
typeof qualquerCoisa == "string"
|
||||||
|
? qualquerCoisa
|
||||||
|
: typeof qualquerCoisa == "number"
|
||||||
|
? String(qualquerCoisa)
|
||||||
|
: JSON.stringify(qualquerCoisa),
|
||||||
|
NIL,
|
||||||
|
)
|
||||||
|
|
||||||
|
export const uuidV4 = v4
|
||||||
Loading…
Add table
Add a link
Reference in a new issue