From 96d2237e5ed16c8d5b105208da306d38cb205421 Mon Sep 17 00:00:00 2001 From: Leonardo Muniz Date: Mon, 26 Feb 2024 21:08:07 -0300 Subject: [PATCH] feat: add query type without middleware cache --- packages/sdk-api-client/package.json | 2 +- packages/sdk/package.json | 2 +- packages/sdk/src/connector.ts | 12 +++++++++++- packages/sdk/src/methods/index.ts | 1 + packages/sdk/src/methods/query-no-cache/index.ts | 12 ++++++++++++ packages/sdk/src/methods/query/index.ts | 1 - 6 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 packages/sdk/src/methods/query-no-cache/index.ts diff --git a/packages/sdk-api-client/package.json b/packages/sdk-api-client/package.json index 18c278ad..aa7568ef 100644 --- a/packages/sdk-api-client/package.json +++ b/packages/sdk-api-client/package.json @@ -1,6 +1,6 @@ { "name": "@erpgap/odoo-sdk-api-client", - "version": "0.5.0", + "version": "0.6.0", "private": false, "sideEffects": false, "server": "server/index.js", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index d8825a77..5a88a15b 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@erpgap/odoo-sdk", - "version": "0.5.0", + "version": "0.6.0", "private": false, "main": "lib/index.cjs.js", "module": "lib/index.es.js", diff --git a/packages/sdk/src/connector.ts b/packages/sdk/src/connector.ts index 20c55dc4..eab4c700 100644 --- a/packages/sdk/src/connector.ts +++ b/packages/sdk/src/connector.ts @@ -16,6 +16,7 @@ type Methods = typeof methods; export const odooConnector = (options: Options): Methods => { let mutation = null; let query = null; + let queryNoCache = null; mutation = async (metadata: MutationMetadataParams, params?: ApiParams): Promise => { return await client.post('mutation', [metadata, params]); @@ -25,6 +26,10 @@ export const odooConnector = (options: Options): Methods => { return await client.post('query', [metadata, params]); }; + queryNoCache = async (metadata: QueryMetadataParams, params?: ApiParams): Promise =>{ + return await client.post('query=no-cache', [metadata, params]); + }; + if (options.ofetch) { mutation = async (metadata: MutationMetadataParams, params?: ApiParams): Promise => { return await options.ofetch('/api/odoo/mutation', { method: 'POST', body: [metadata, params], cache: 'no-cache' }); @@ -34,9 +39,14 @@ export const odooConnector = (options: Options): Methods => { const cacheKey = metadata.cacheKey || hash({ ...metadata, ...params }); return await options.ofetch('/api/odoo/query', { method: 'POST', body: [metadata, params], cache: 'no-cache', key: cacheKey } as any); }; + + queryNoCache = async (metadata: QueryMetadataParams, params?: ApiParams): Promise =>{ + const cacheKey = metadata.cacheKey || hash({ ...metadata, ...params }); + return await options.ofetch('/api/odoo/query-no-cache', { method: 'POST', body: [metadata, params], cache: 'no-cache', key: cacheKey } as any); + }; } client.defaults.baseURL = options.apiUrl; - return { query, mutation }; + return { query, mutation, queryNoCache }; }; diff --git a/packages/sdk/src/methods/index.ts b/packages/sdk/src/methods/index.ts index 28b90465..2f5a15a1 100644 --- a/packages/sdk/src/methods/index.ts +++ b/packages/sdk/src/methods/index.ts @@ -1,2 +1,3 @@ export * from './query'; +export * from './query-no-cache'; export * from './mutation'; diff --git a/packages/sdk/src/methods/query-no-cache/index.ts b/packages/sdk/src/methods/query-no-cache/index.ts new file mode 100644 index 00000000..25f4c49e --- /dev/null +++ b/packages/sdk/src/methods/query-no-cache/index.ts @@ -0,0 +1,12 @@ +import { ApolloQueryResult } from '@apollo/client'; +import { QueryMetadataParams, Endpoints } from '@erpgap/odoo-sdk-api-client'; +import { client } from '../../client'; + +/** + * Make the query + * + * @example + */ +export async function queryNoCache(metadata: QueryMetadataParams, params?: ApiParams): Promise { + return await client.post('query-no-cache', [metadata, params]); +} diff --git a/packages/sdk/src/methods/query/index.ts b/packages/sdk/src/methods/query/index.ts index ff4955d7..5eeaa34e 100644 --- a/packages/sdk/src/methods/query/index.ts +++ b/packages/sdk/src/methods/query/index.ts @@ -1,4 +1,3 @@ -import { ApolloQueryResult } from '@apollo/client'; import { QueryMetadataParams, Endpoints } from '@erpgap/odoo-sdk-api-client'; import { client } from '../../client';