@platformatic/client
Advanced tools
Comparing version 1.19.0 to 1.20.0
@@ -24,2 +24,3 @@ import { FastifyPluginAsync, FastifyReply, FastifyRequest } from 'fastify' | ||
validateResponse?: boolean; | ||
queryParser?: (query: URLSearchParams) => string | ||
} | ||
@@ -26,0 +27,0 @@ |
63
index.js
@@ -18,3 +18,11 @@ 'use strict' | ||
function generateOperationId (path, method, methodMeta, all) { | ||
let operationId = methodMeta.operationId | ||
let operationId = null | ||
// use methodMeta.operationId only if it's present AND it is a valid string that can be | ||
// concatenated without converting it | ||
// i.e | ||
// operationId = "MyOperationId123" is valid | ||
// operationId = "/v3/accounts/{id}" is NOT valid and sholuld be converted in "V3AccountsId" | ||
if (methodMeta.operationId && methodMeta.operationId.match(/^[a-zA-z0-9]+$/)) { | ||
operationId = methodMeta.operationId | ||
} | ||
if (!operationId) { | ||
@@ -31,3 +39,3 @@ const pathParams = methodMeta.parameters?.filter(p => p.in === 'path') || [] | ||
.map((token) => { | ||
const sanitized = token.replace(/[^a-zA-z0-9]/, '') | ||
const sanitized = token.replace(/[^a-zA-z0-9]/g, '') | ||
return capitalize(sanitized) | ||
@@ -66,3 +74,3 @@ }).join('') | ||
const { validateResponse } = options | ||
const { validateResponse, queryParser } = options | ||
// this is tested, not sure why c8 is not picking it up | ||
@@ -112,3 +120,3 @@ if (!options.url) { | ||
client[kOperationIdMap][operationId] = { path, method } | ||
client[operationId] = await buildCallFunction(spec, baseUrl, path, method, methodMeta, throwOnError, openTelemetry, fullRequest, fullResponse, validateResponse) | ||
client[operationId] = await buildCallFunction(spec, baseUrl, path, method, methodMeta, throwOnError, openTelemetry, fullRequest, fullResponse, validateResponse, queryParser) | ||
} | ||
@@ -136,3 +144,7 @@ } | ||
async function buildCallFunction (spec, baseUrl, path, method, methodMeta, throwOnError, openTelemetry, fullRequest, fullResponse, validateResponse) { | ||
function whereOrClauseIsComplexObject (orClause) { | ||
return (Array.isArray(orClause) && typeof orClause[0] !== 'string') | ||
} | ||
async function buildCallFunction (spec, baseUrl, path, method, methodMeta, throwOnError, openTelemetry, fullRequest, fullResponse, validateResponse, queryParser) { | ||
await $RefParser.dereference(spec) | ||
@@ -175,3 +187,20 @@ const ajv = new Ajv() | ||
if (isArrayQueryParam(param)) { | ||
args.query[param.name].forEach((p) => query.append(param.name, p)) | ||
if (param.name === 'where.or' && whereOrClauseIsComplexObject(args.query[param.name])) { | ||
// parse the object from | ||
// [ | ||
// { id: { eq: 1 }, | ||
// { title: { eq: 'Matrix' }, | ||
// ] | ||
// to ['id.eq=1|title.eq=Matrix'] | ||
const stringArray = [] | ||
for (const c of args.query[param.name]) { | ||
const field = Object.keys(c)[0] | ||
const [op, value] = Object.entries(c[field])[0] | ||
stringArray.push(`${field}.${op}=${value}`) | ||
} | ||
query.append(param.name, `(${stringArray.join('|')})`) | ||
} else { | ||
args.query[param.name].forEach((p) => query.append(param.name, p)) | ||
} | ||
} else { | ||
@@ -196,3 +225,20 @@ query.append(param.name, args.query[param.name]) | ||
if (isArrayQueryParam(param)) { | ||
body[param.name].forEach((p) => query.append(param.name, p)) | ||
if (param.name === 'where.or' && whereOrClauseIsComplexObject(body['where.or'])) { | ||
// parse the object from | ||
// [ | ||
// { id: { eq: 1 }, | ||
// { title: { eq: 'Matrix' }, | ||
// ] | ||
// to ['id.eq=1|title.eq=Matrix'] | ||
const stringArray = [] | ||
for (const c of body[param.name]) { | ||
const field = Object.keys(c)[0] | ||
const [op, value] = Object.entries(c[field])[0] | ||
stringArray.push(`${field}.${op}=${value}`) | ||
} | ||
query.append(param.name, `(${stringArray.join('|')})`) | ||
} else { | ||
body[param.name].forEach((p) => query.append(param.name, p)) | ||
} | ||
} else { | ||
@@ -212,3 +258,4 @@ query.append(param.name, body[param.name]) | ||
} | ||
urlToCall.search = query.toString() | ||
urlToCall.search = queryParser ? queryParser(query) : query.toString() | ||
urlToCall.pathname = pathToCall | ||
@@ -215,0 +262,0 @@ |
@@ -65,2 +65,3 @@ import { expectError, expectType } from 'tsd' | ||
}, | ||
queryParser: (query) => `${query.toString()}[]` | ||
}, openTelemetry) | ||
@@ -67,0 +68,0 @@ |
{ | ||
"name": "@platformatic/client", | ||
"version": "1.19.0", | ||
"version": "1.20.0", | ||
"description": "A client for all platformatic backends", | ||
@@ -17,6 +17,7 @@ "main": "index.js", | ||
"devDependencies": { | ||
"c8": "^9.0.0", | ||
"desm": "^1.3.0", | ||
"borp": "^0.9.0", | ||
"c8": "^9.1.0", | ||
"desm": "^1.3.1", | ||
"execa": "^8.0.1", | ||
"fastify": "^4.23.2", | ||
"fastify": "^4.26.0", | ||
"glob": "^10.3.10", | ||
@@ -26,9 +27,9 @@ "snazzy": "^9.0.0", | ||
"standard": "^17.1.0", | ||
"tsd": "^0.30.0", | ||
"typescript": "^5.2.2", | ||
"@platformatic/telemetry": "1.19.0" | ||
"tsd": "^0.30.4", | ||
"typescript": "^5.3.3", | ||
"@platformatic/telemetry": "1.20.0" | ||
}, | ||
"dependencies": { | ||
"@apidevtools/json-schema-ref-parser": "^11.1.0", | ||
"@fastify/error": "^3.3.0", | ||
"@fastify/error": "^3.4.1", | ||
"abstract-logging": "^2.0.1", | ||
@@ -38,9 +39,9 @@ "ajv": "^8.12.0", | ||
"jsonpointer": "^5.0.1", | ||
"undici": "^6.0.0" | ||
"undici": "^6.6.0" | ||
}, | ||
"scripts": { | ||
"lint": "standard", | ||
"test": "pnpm run lint && c8 node ./test/runner.js && tsd", | ||
"nocov": "pnpm run lint && node ./test/runner.js && tsd" | ||
"test": "pnpm run lint && borp --concurrency=1 --timeout 120000 && tsd", | ||
"cov": "pnpm run lint && borp --concurrency=1 --coverage --timeout 120000 && tsd" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34223
592
12
Updated@fastify/error@^3.4.1
Updatedundici@^6.6.0